:root {
            --bg: #f4f7f6;
            --card: #ffffff;
            --primary: #0071E3;
            --accent: #00cec9;
            --text: #2d3436;
            --radius: 15px;
        }

        body {
            margin: 0;
            padding: 20px;
            font-family: 'Segoe UI', sans-serif;
            background: var(--bg);
            color: var(--text);
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            min-height: 100vh;
        }

        .card {
            background: var(--card);
            width: 100%;
            max-width: 600px;
            border-radius: var(--radius);
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.05);
            padding: 40px;
            text-align: center;
            display: none;
            overflow-y: auto; /* Allow scrolling for calculator */
            max-height: 90vh; /* Don't exceed screen height */
            position: relative;
        }

        .card.active {
            display: block;
        }

        h1 {
            color: var(--primary);
            margin: 0 0 10px 0;
        }

        input {
            width: 100%;
            padding: 15px;
            margin-bottom: 15px;
            border: 2px solid var(--primary);
            border-radius: 10px;
            font-size: 1.1rem;
            text-align: center;
            box-sizing: border-box;
        }

        button {
            width: 100%;
            padding: 15px;
            border: none;
            border-radius: 10px;
            font-size: 1.2rem;
            font-weight: bold;
            color: white;
            cursor: pointer;
            margin-bottom: 10px;
        }

        .btn-join {
            background: var(--primary);
        }

        .btn-answer {
            background: #ffffff;
            border: 2px solid var(--primary);
            color: var(--text);
            text-align: left;
            border: 2px solid transparent;
            width: 100%;
            margin-bottom: 8px;
        }

        .btn-answer:hover {
            filter: brightness(0.95);
            transform: scale(1.01);
        }

        .btn-answer:disabled {
            opacity: 0.6;
            cursor: not-allowed;
        }

        .timer-bar {
            width: 100%;
            height: 10px;
            background: #ffffff;
            border: 1px solid var(--primary);
            border-radius: 5px;
            margin: 20px 0;
            overflow: hidden;
            position: relative;
        }

        .timer-fill {
            height: 100%;
            background: var(--accent);
            width: 100%;
            position: absolute;
            left: 0;
            top: 0;
        }

        .q-image {
            max-width: 100%;
            max-height: 250px;
            border-radius: 10px;
            margin: 15px 0;
            display: none;
        }

        .ranking-item {
            display: flex;
            justify-content: space-between;
            padding: 10px;
            border-bottom: 1px solid var(--primary);
        }

        .myself {
            background: #eef1ff;
            border-left: 5px solid var(--primary);
        }

        /* 4-Color Scheme for Buttons (WCAG 4.5:1 contrast minimum) */
        .color-0 {
            background-color: #fad4d4;
            color: #1a1a2e;
            border: 2px solid #e74c3c;
        }

        /* Red */
        .color-1 {
            background-color: #d0e7fb;
            color: #1a1a2e;
            border: 2px solid #2980b9;
        }

        /* Blue */
        .color-2 {
            background-color: #fef3cd;
            color: #1a1a2e;
            border: 2px solid #d4a017;
        }

        /* Yellow */
        .color-3 {
            background-color: #d0f5e0;
            color: #1a1a2e;
            border: 2px solid #27ae60;
        }

        /* Green */

        /* Focus visible for keyboard navigation */
        .btn-answer:focus-visible {
            outline: 3px solid #1155D6;
            outline-offset: 2px;
        }

        /* Selected state */
        .btn-answer.selected {
            transform: scale(0.97);
            box-shadow: 0 0 0 3px rgba(17, 85, 214, 0.4);
        }

        .btn-answer {
            width: 100%;
            padding: 20px;
            margin-bottom: 10px;
            border-radius: 10px;
            font-size: 1.2rem;
            font-weight: bold;
            cursor: pointer;
            transition: transform 0.1s;
            display: block;
        }

        .btn-answer:active {
            transform: scale(0.98);
        }

        .logo-top-left {
            position: absolute;
            top: 20px;
            left: 20px;
            width: 45px;
            height: 45px;
            overflow: hidden;
            border-radius: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: transform 0.3s ease;
        }

        .logo-top-left img {
            width: 145%; /* Zoom pour masquer le fond gris */
            height: 145%;
            object-fit: cover;
        }

        .logo-top-left:hover {
            transform: scale(1.05);
        }
        
        .top-right-tools {
            position: absolute;
            top: 20px;
            right: 20px;
            display: flex;
            gap: 12px;
            z-index: 10;
        }

        .tool-btn {
            width: 50px !important;
            height: 50px !important;
            border-radius: 8px;
            display: flex !important;
            align-items: center;
            justify-content: center;
            font-size: 1.5rem;
            color: white;
            cursor: pointer;
            transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
            border: 2px solid rgba(255, 255, 255, 0.2);
            padding: 0 !important;
            margin: 0 !important;
            box-sizing: border-box !important;
            overflow: hidden;
        }

        .tool-btn i {
            filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
        }

        .tool-btn:hover {
            transform: translateY(-4px) scale(1.08);
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
        }

        .tool-btn:active {
            transform: translateY(0) scale(0.95);
        }

        .calc-btn {
            background: linear-gradient(135deg, #0984e3 0%, #076ad1 100%);
            box-shadow: 0 6px 15px rgba(9, 132, 227, 0.35);
        }

        .calc-btn.active {
            transform: scale(0.9) translateY(2px);
            background: linear-gradient(135deg, #076ad1 0%, #0984e3 100%);
            box-shadow: inset 0 2px 8px rgba(0,0,0,0.3);
            border-color: rgba(255,255,255,0.4);
        }

        .help-btn {
            background: linear-gradient(135deg, #d63031 0%, #b32d2e 100%);
            box-shadow: 0 6px 15px rgba(214, 48, 49, 0.35);
        }

        .help-btn.sent {
            background: linear-gradient(135deg, #f1c40f 0%, #d4ac0d 100%);
            box-shadow: 0 0 20px rgba(241, 196, 15, 0.5);
            cursor: default;
            border-color: rgba(255, 255, 255, 0.5);
            animation: pulse-sos 2s infinite ease-in-out;
        }

        @keyframes pulse-sos {
            0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(241, 196, 15, 0.6); }
            50% { transform: scale(1.08); box-shadow: 0 0 0 12px rgba(241, 196, 15, 0); }
            100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(241, 196, 15, 0); }
        }

        .help-btn.sent:hover {
            transform: scale(1);
        }
        
        @media (max-width: 600px) {
            .top-right-tools {
                top: 12px;
                right: 12px;
                gap: 8px;
            }
            .tool-btn {
                width: 38px !important;
                height: 38px !important;
                border-radius: 6px;
                font-size: 1.2rem;
                display: flex !important;
            }
        }

        .floating-room-code {
            position: fixed;
            bottom: 10px;
            left: 10px;
            background: rgba(45, 52, 54, 0.9);
            color: white;
            padding: 5px 10px;
            border-radius: 5px;
            font-size: 0.8rem;
            font-weight: bold;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
            z-index: 9999;
            letter-spacing: 1px;
            display: none;
        }

        /* New Scientific Calculator Panel */
        .calc-panel {
            margin-top: 30px;
            border-top: 2px solid #edeff2;
            padding-top: 20px;
            display: none; /* Controlled by JS */
            text-align: left;
            animation: slideUp 0.3s ease-out;
        }

        @keyframes slideUp {
            from { transform: translateY(20px); opacity: 0; }
            to { transform: translateY(0); opacity: 1; }
        }

        .calc-panel.active {
            display: block;
        }

        .calc-panel-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 15px;
        }

        .calc-panel-header h3 {
            margin: 0;
            font-size: 1.1rem;
            color: var(--primary);
        }

        .calc-controls {
            display: flex;
            gap: 10px;
            align-items: center;
        }

        .calc-unit-btn {
            background: #dfe6e9;
            color: #2d3436;
            border: none;
            padding: 5px 10px;
            border-radius: 5px;
            font-size: 0.75rem;
            font-weight: bold;
            cursor: pointer;
            width: 50px;
        }

        .calc-close-btn {
            background: none;
            border: none;
            color: #636e72;
            font-size: 1.2rem;
            cursor: pointer;
            padding: 0;
            width: auto;
            margin: 0;
        }

        .calc-container-new {
            background: #2d3436;
            padding: 15px;
            border-radius: 15px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.2);
        }

        .calc-display-container {
            background: #f4f7f6;
            border-radius: 10px;
            padding: 10px;
            margin-bottom: 15px;
            text-align: right;
            min-height: 60px;
            display: flex;
            flex-direction: column;
            justify-content: center;
        }

        .calc-display-history {
            font-size: 0.85rem;
            color: #636e72;
            min-height: 1.2em;
            overflow-x: auto;
            white-space: nowrap;
        }

        .calc-display-input {
            font-size: 1.6rem;
            font-weight: bold;
            color: #2d3436;
            overflow-x: auto;
            white-space: nowrap;
            margin-top: 2px;
        }

        .calc-buttons-grid {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 8px;
        }

        .calc-btn {
            background: #636e72;
            color: white;
            border: none;
            border-radius: 8px;
            padding: 12px 5px;
            font-size: 1rem;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.1s;
            margin-bottom: 0;
            width: 100%;
        }

        .calc-btn:active {
            transform: scale(0.95);
            filter: brightness(1.2);
        }

        .calc-btn.btn-sci {
            background: #4b5563;
            font-size: 0.9rem;
            font-style: italic;
        }

        .calc-btn.btn-op {
            background: #0984e3;
        }

        .calc-btn.btn-clear {
            background: #d63031;
        }

        .calc-btn.btn-del {
            background: #e17055;
        }

        .calc-btn.btn-equal {
            background: #00b894;
            grid-column: span 1;
        }

        @media (max-width: 480px) {
            .card {
                padding: 20px;
            }
            .calc-btn {
                padding: 10px 5px;
                font-size: 0.9rem;
            }
            .calc-display-input {
                font-size: 1.3rem;
            }
        }

        @media (max-width: 600px) {
            .logo-top-left {
                width: 30px;
                height: 30px;
                top: 12px;
                left: 12px;
                border-radius: 6px;
            }
        }

        /* Feedback Stars */
        .rate-star {
            cursor: pointer;
            color: #dfe6e9;
            transition: transform 0.2s, color 0.2s;
        }

        .rate-star:hover {
            transform: scale(1.2);
        }

        .rate-star.selected {
            color: #f1c40f;
        }

        .rate-star.selected i {
            font-weight: 900;
        }

        /* Mode Selection Buttons (Legacy) */
        .btn-mode {
            background: #dfe6e9 !important;
            color: #636e72 !important;
            border: 2px solid #b2bec3;
            transition: all 0.2s;
            width: auto;
            min-width: 100px;
        }

        .btn-mode.active {
            background: var(--primary) !important;
            color: white !important;
            border-color: var(--primary);
            box-shadow: 0 4px 10px rgba(0, 113, 227, 0.3);
        }

        /* Ensure answer buttons are opaque to stay legible over the background */
        .btn-answer {
            opacity: 1 !important;
            z-index: 10;
            position: relative;
        }

        .avatar-picker {
            margin: 15px 0;
            text-align: center;
        }

        .avatar-label {
            display: block;
            font-size: 0.85rem;
            font-weight: 600;
            color: var(--text);
            opacity: 0.6;
            margin-bottom: 10px;
            text-transform: uppercase;
            letter-spacing: 1px;
        }

        .avatar-grid {
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            gap: 8px;
            margin-bottom: 5px;
        }

        .avatar-option {
            width: 52px;
            height: 52px;
            border-radius: 50%;
            border: 3px solid transparent;
            cursor: pointer;
            padding: 3px;
            background: #f4f7f6;
            transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
            display: flex;
            align-items: center;
            justify-content: center;
            overflow: hidden;
        }

        .avatar-option svg, .avatar-option img {
            width: 42px;
            height: 42px;
            display: block;
        }

        .avatar-option:hover {
            transform: scale(1.15);
            border-color: var(--primary);
            box-shadow: 0 4px 12px rgba(0, 113, 227, 0.3);
        }

        .avatar-option.selected {
            border-color: var(--primary);
            background: var(--primary);
            transform: scale(1.1);
            box-shadow: 0 4px 15px rgba(0, 113, 227, 0.4);
        }

        .avatar-option.selected svg {
            filter: brightness(1.1);
        }

        .avatar-preview {
            width: 28px;
            height: 28px;
            display: inline-block;
            vertical-align: middle;
            margin-right: 6px;
            border-radius: 50%;
            overflow: hidden;
            flex-shrink: 0;
        }

        .avatar-preview svg, .avatar-preview img {
            width: 100%;
            height: 100%;
            display: block;
        }

        .avatar-badge-sm {
            width: 22px;
            height: 22px;
            display: inline-block;
            vertical-align: middle;
            margin-right: 4px;
            border-radius: 50%;
            overflow: hidden;
            flex-shrink: 0;
        }

        .avatar-badge-sm svg, .avatar-badge-sm img {
            width: 100%;
            height: 100%;
            display: block;
        }

        .anti-cheat-warning {
            margin-top: 25px;
            padding: 15px 20px;
            background: rgba(214, 48, 49, 0.08);
            border: 2px solid #d63031;
            border-radius: 12px;
            color: #d63031;
            font-size: 1.05rem;
            line-height: 1.4;
            text-align: left;
            display: flex;
            align-items: center;
            gap: 15px;
        }

        .anti-cheat-warning i {
            font-size: 1.8rem;
            flex-shrink: 0;
        }

        .anti-cheat-content {
            flex: 1;
        }

        .anti-cheat-title {
            display: block;
            font-weight: 900;
            font-size: 0.85rem;
            text-transform: uppercase;
            letter-spacing: 1px;
            margin-bottom: 2px;
            opacity: 0.9;
        }

        /* Reading Phase Overlay */
        .reading-overlay {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(255, 255, 255, 0.7);
            backdrop-filter: blur(5px);
            -webkit-backdrop-filter: blur(5px);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 20;
            border-radius: var(--radius);
            animation: fadeIn 0.4s ease-out;
        }

        /* Dark mode compatibility for overlay background */
        body[class*="dark"] .reading-overlay,
        .dark-mode .reading-overlay {
            background: rgba(45, 52, 54, 0.7);
        }

        .reading-overlay-exit {
            animation: fadeOut 0.4s ease-out forwards;
        }

        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }

        @keyframes fadeOut {
            from { opacity: 1; }
            to { opacity: 0; }
        }

        .reading-overlay-content {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 15px;
            background: var(--card);
            padding: 30px;
            border-radius: 20px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            max-width: 80%;
            text-align: center;
            border: 2px solid #6c5ce7;
            position: relative;
        }

        .reading-icon {
            font-size: 3rem;
            color: #6c5ce7;
            animation: pulse-icon 2s infinite ease-in-out;
        }

        @keyframes pulse-icon {
            0% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(108, 92, 231, 0.4)); }
            50% { transform: scale(1.1); filter: drop-shadow(0 4px 12px rgba(108, 92, 231, 0.6)); }
            100% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(108, 92, 231, 0.4)); }
        }

        .reading-label {
            font-size: 1.2rem;
            font-weight: 700;
            color: var(--text);
        }

        .reading-countdown {
            font-size: 2.2rem;
            font-weight: 900;
            color: #6c5ce7;
            position: absolute;
            top: 56%;
            left: 50%;
            transform: translate(-50%, -50%);
            z-index: 2;
        }

        .reading-progress-ring {
            width: 80px;
            height: 80px;
            position: relative;
        }

        .reading-progress-ring svg {
            width: 100%;
            height: 100%;
            transform: rotate(-90deg);
        }

        .reading-ring-bg {
            fill: none;
            stroke: #edeff2;
            stroke-width: 4px;
        }

        .reading-ring-fill {
            fill: none;
            stroke: #6c5ce7;
            stroke-width: 4px;
            stroke-linecap: round;
            transition: stroke-dashoffset 0.1s linear;
        }