        * { margin: 0; padding: 0; box-sizing: border-box; }

        :root {
            --bg-dark: #0a0f1a;
            --bg-card: #151d2e;
            --bg-hover: #1e2a3f;
            --accent: #4f8cff;
            --accent-hover: #3b7aed;
            --accent-glow: rgba(79, 140, 255, 0.3);
            --text: #e8edf5;
            --text-muted: #8b95a5;
            --border: #2a3548;
            --danger: #ff5757;
            --success: #4ade80;
            --warning: #fbbf24;
            --purple: #a78bfa;
        }

        body {
            font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
            background: linear-gradient(135deg, var(--bg-dark) 0%, #0d1525 100%);
            color: var(--text);
            min-height: 100vh;
            overflow-x: hidden;
        }

        /* Navigation */
        nav {
            background: rgba(21, 29, 46, 0.95);
            backdrop-filter: blur(10px);
            padding: 0.75rem 2rem;
            border-bottom: 1px solid var(--border);
            display: flex;
            justify-content: space-between;
            align-items: center;
            position: sticky;
            top: 0;
            z-index: 100;
        }

        .logo {
            font-size: 1.4rem;
            font-weight: 700;
            background: linear-gradient(135deg, var(--accent), var(--purple));
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            display: flex;
            align-items: center;
            gap: 0.5rem;
            cursor: pointer;
        }

        .nav-links { display: flex; gap: 0.5rem; align-items: center; }
        .nav-links a {
            color: var(--text-muted);
            text-decoration: none;
            padding: 0.5rem 1rem;
            border-radius: 8px;
            transition: all 0.2s;
            cursor: pointer;
            font-size: 0.9rem;
        }
        .nav-links a:hover, .nav-links a.active { color: var(--text); background: var(--bg-hover); }

        /* Buttons */
        .btn {
            padding: 0.6rem 1.25rem;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            font-size: 0.9rem;
            font-weight: 500;
            transition: all 0.2s;
            display: inline-flex;
            align-items: center;
            gap: 0.5rem;
        }
        .btn:disabled { opacity: 0.5; cursor: not-allowed; }
        .btn-primary { background: var(--accent); color: white; }
        .btn-primary:hover:not(:disabled) { background: var(--accent-hover); box-shadow: 0 0 20px var(--accent-glow); }
        .btn-secondary { background: var(--border); color: var(--text); }
        .btn-secondary:hover:not(:disabled) { background: var(--bg-hover); }
        .btn-danger { background: var(--danger); color: white; }
        .btn-icon { padding: 0.5rem; font-size: 1.1rem; }

        .container { max-width: 1500px; width: 100%; margin: 0 auto; padding: 1.5rem; }

        .panel {
            background: var(--bg-card);
            border-radius: 12px;
            border: 1px solid var(--border);
            padding: 1.25rem;
            margin-bottom: 1rem;
        }
        .panel h3 {
            margin-bottom: 1rem;
            font-size: 0.95rem;
            color: var(--text-muted);
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .game-layout {
            display: grid;
            grid-template-columns: 280px auto 280px;
            gap: 1.5rem;
            align-items: start;
            justify-content: center;
            max-width: 100%;
        }
        .side-panel {
            width: 280px;
            max-width: 100%;
            min-width: 280px;
            max-width: 280px;
            flex-shrink: 0;
        }
        @media (max-width: 1200px) {
            .game-layout { grid-template-columns: 1fr; }
            .side-panel { order: 2; width: 100%; min-width: auto; max-width: 600px; margin: 0 auto; }
            .board-area { order: 1; width: auto; min-width: auto; max-width: 100%; }
        }

        .board-area {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 0.75rem;
            width: 640px;
            max-width: 100%;
        }

        /* ============================================ */
        /* PREMIUM BOARD STYLING */
        /* ============================================ */
        .board-container {
            position: relative;
            background: linear-gradient(145deg, #1a1a2e 0%, #16213e 100%);
            border-radius: 16px;
            padding: 12px;
            border: 3px solid #2d3a4f;
            box-shadow:
                0 20px 60px rgba(0, 0, 0, 0.5),
                0 0 0 1px rgba(255,255,255,0.05) inset,
                0 2px 0 rgba(255,255,255,0.1) inset;
            width: 630px;
            max-width: 100%;
            flex-shrink: 0;
        }

        .board-frame {
            background: linear-gradient(135deg, #3d2b1f 0%, #5d4037 50%, #3d2b1f 100%);
            border-radius: 8px;
            padding: 20px;
            box-shadow:
                inset 0 2px 4px rgba(0,0,0,0.3),
                inset 0 -2px 4px rgba(255,255,255,0.1),
                0 4px 8px rgba(0,0,0,0.3);
            position: relative;
            width: 600px;
            height: 600px;
            max-width: 100%;
            box-sizing: border-box;
        }

        .board-frame::before {
            content: '';
            position: absolute;
            inset: 4px;
            border: 2px solid rgba(139, 90, 43, 0.5);
            border-radius: 6px;
            pointer-events: none;
        }

        .eval-bar {
            position: absolute;
            left: -28px;
            top: 12px;
            bottom: 12px;
            width: 14px;
            background: linear-gradient(180deg, #1a1a1a 0%, #2d2d2d 100%);
            border-radius: 7px;
            overflow: hidden;
            border: 1px solid #444;
            box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
        }
        .eval-fill {
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            background: linear-gradient(180deg, #f5f5f5 0%, #e0e0e0 100%);
            transition: height 0.5s ease;
            border-radius: 0 0 6px 6px;
        }
        .eval-bar::after {
            content: '';
            position: absolute;
            left: 0;
            right: 0;
            top: 50%;
            height: 2px;
            background: #666;
            transform: translateY(-50%);
        }

        /* Eval Info Display */
        .eval-info {
            position: absolute;
            left: -54px;
            top: 50%;
            transform: translateY(-50%);
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 2px;
            width: 22px;
        }
        .eval-score {
            font-family: 'JetBrains Mono', monospace;
            font-size: 0.65rem;
            font-weight: 700;
            color: var(--text);
            white-space: nowrap;
        }
        .eval-depth {
            font-family: 'JetBrains Mono', monospace;
            font-size: 0.55rem;
            color: var(--text-muted);
        }

        /* PV Line */
        .eval-pv-line {
            width: 600px;
            max-width: 100%;
            min-height: 1.4em;
            font-family: 'JetBrains Mono', monospace;
            font-size: 0.8rem;
            color: var(--text-muted);
            text-align: center;
            padding: 0.2rem 0.5rem;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        #chessboard {
            display: grid;
            grid-template-columns: repeat(8, 1fr);
            grid-template-rows: repeat(8, 1fr);
            width: 560px;
            height: 560px;
            max-width: 100%;
            aspect-ratio: 1 / 1;
            border-radius: 4px;
            overflow: hidden;
            box-shadow:
                0 0 0 2px rgba(0,0,0,0.3),
                0 8px 24px rgba(0, 0, 0, 0.4);
            position: relative;
            box-sizing: border-box;
        }
        /* Mobile board sizing moved to comprehensive mobile section at bottom */

        .square {
            position: relative;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            user-select: none;
            transition: all 0.1s ease;
        }

        /* Premium Board Themes with Gradients */
        .theme-classic .square.light {
            background: linear-gradient(135deg, #f5e6d3 0%, #f0d9b5 50%, #e8cda5 100%);
        }
        .theme-classic .square.dark {
            background: linear-gradient(135deg, #c9a86c 0%, #b58863 50%, #a67b5b 100%);
        }
        .theme-blue .square.light {
            background: linear-gradient(135deg, #e8eef3 0%, #dee3e6 50%, #d0d8dd 100%);
        }
        .theme-blue .square.dark {
            background: linear-gradient(135deg, #9eb3bf 0%, #8ca2ad 50%, #7a929d 100%);
        }
        .theme-green .square.light {
            background: linear-gradient(135deg, #ffffdd 0%, #ebecd0 50%, #e0e2c0 100%);
        }
        .theme-green .square.dark {
            background: linear-gradient(135deg, #86a666 0%, #769656 50%, #688648 100%);
        }
        .theme-purple .square.light {
            background: linear-gradient(135deg, #f0e8f5 0%, #e8e0f0 50%, #ddd5e8 100%);
        }
        .theme-purple .square.dark {
            background: linear-gradient(135deg, #9080b0 0%, #7b61a8 50%, #6a5090 100%);
        }
        .theme-wood .square.light {
            background: linear-gradient(135deg, #f5dfc5 0%, #e8c8a0 50%, #ddb890 100%);
            background-image:
                linear-gradient(135deg, #f5dfc5 0%, #e8c8a0 50%, #ddb890 100%),
                url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.08'/%3E%3C/svg%3E");
        }
        .theme-wood .square.dark {
            background: linear-gradient(135deg, #a06830 0%, #8b5a2b 50%, #754d24 100%);
            background-image:
                linear-gradient(135deg, #a06830 0%, #8b5a2b 50%, #754d24 100%),
                url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.1'/%3E%3C/svg%3E");
        }
        .theme-midnight .square.light {
            background: linear-gradient(135deg, #d5dce3 0%, #c8d3de 50%, #bcc8d5 100%);
        }
        .theme-midnight .square.dark {
            background: linear-gradient(135deg, #586575 0%, #4a5568 50%, #3d4855 100%);
        }

        /* Square Highlights */
        .square.selected {
            background: linear-gradient(135deg, rgba(100, 200, 100, 0.7) 0%, rgba(80, 180, 80, 0.7) 100%) !important;
            box-shadow: inset 0 0 0 3px rgba(255,255,255,0.3);
        }
        .square.premove {
            background: linear-gradient(135deg, rgba(100, 150, 255, 0.6) 0%, rgba(80, 120, 220, 0.6) 100%) !important;
            box-shadow: inset 0 0 0 3px rgba(100, 150, 255, 0.5);
            animation: premovePulse 1.5s ease-in-out infinite;
        }
        @keyframes premovePulse {
            0%, 100% { opacity: 0.7; }
            50% { opacity: 1; }
        }
        .square.last-move {
            background: linear-gradient(135deg, rgba(255, 255, 120, 0.5) 0%, rgba(220, 220, 80, 0.5) 100%) !important;
        }
        .square.check {
            background: radial-gradient(ellipse at center,
                rgba(255, 50, 50, 0.95) 0%,
                rgba(255, 0, 0, 0.6) 30%,
                rgba(200, 0, 0, 0.3) 60%,
                transparent 80%) !important;
            animation: checkPulse 1s ease-in-out infinite;
        }
        @keyframes checkPulse {
            0%, 100% { box-shadow: inset 0 0 20px rgba(255,0,0,0.5); }
            50% { box-shadow: inset 0 0 30px rgba(255,0,0,0.8); }
        }

        .square:hover:not(.selected):not(.last-move) {
            filter: brightness(1.1);
        }

        /* Coordinate Labels on Board */
        .square .coord-label {
            position: absolute;
            font-size: 10px;
            font-weight: 700;
            opacity: 0.7;
            pointer-events: none;
            font-family: 'Arial', sans-serif;
        }
        .square .coord-file {
            bottom: 2px;
            right: 4px;
        }
        .square .coord-rank {
            top: 2px;
            left: 4px;
        }
        .square.light .coord-label { color: #8b7355; }
        .square.dark .coord-label { color: #d4c4b0; }
        .theme-green .square.dark .coord-label { color: #c5d4a5; }
        .theme-blue .square.dark .coord-label { color: #c8d4dc; }
        .theme-purple .square.dark .coord-label { color: #c8b8d8; }
        .theme-midnight .square.dark .coord-label { color: #a0b0c0; }

        /* Move Hints */
        .square .move-hint {
            width: 32%;
            height: 32%;
            background: radial-gradient(circle, rgba(0, 0, 0, 0.2) 0%, rgba(0, 0, 0, 0.15) 100%);
            border-radius: 50%;
            position: absolute;
            z-index: 5;
            pointer-events: none;
        }
        .square .capture-hint {
            width: 100%;
            height: 100%;
            position: absolute;
            z-index: 5;
            pointer-events: none;
            border-radius: 50%;
            box-shadow: inset 0 0 0 6px rgba(0, 0, 0, 0.15);
        }

        /* ============================================ */
        /* SVG CHESS PIECES */
        /* ============================================ */
        .piece {
            width: 90%;
            height: 90%;
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 10;
            transition: transform 0.08s ease;
            filter: drop-shadow(2px 4px 3px rgba(0,0,0,0.35));
        }
        .piece:hover {
            transform: scale(1.05);
        }
        .piece.sliding {
            transition: transform 0.15s ease-out;
            z-index: 50;
        }
        .piece.dragging {
            position: fixed;
            pointer-events: none;
            z-index: 1000;
            transform: scale(1.15);
            filter: drop-shadow(4px 8px 6px rgba(0,0,0,0.4));
        }
        .piece svg {
            width: 100%;
            height: 100%;
        }

        /* Arrows SVG */
        .arrows-layer {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            pointer-events: none;
            z-index: 20;
        }

        /* Player Bar */
        .player-bar {
            display: flex;
            align-items: center;
            gap: 1rem;
            padding: 0.75rem 1rem;
            background: var(--bg-card);
            border-radius: 10px;
            border: 2px solid var(--border);
            width: 600px;
            max-width: 100%;
            transition: all 0.3s;
            box-sizing: border-box;
        }
        .player-bar.active {
            border-color: var(--accent);
            box-shadow: 0 0 25px var(--accent-glow);
        }
        .player-avatar {
            width: 42px;
            height: 42px;
            border-radius: 50%;
            background: linear-gradient(135deg, var(--accent), var(--purple));
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            font-size: 1.3rem;
        }
        .player-details { flex: 1; }
        .player-name { font-weight: 600; font-size: 1rem; }
        .player-rating { font-size: 0.8rem; color: var(--text-muted); }
        .captured-pieces {
            display: flex;
            flex-wrap: wrap;
            gap: 1px;
            font-size: 0.9rem;
            width: 120px;
            flex-shrink: 1;
            opacity: 0.9;
            overflow: hidden;
        }
        .player-timer {
            font-family: 'JetBrains Mono', 'Courier New', monospace;
            font-size: 1.5rem;
            font-weight: 700;
            padding: 0.4rem 0.8rem;
            background: var(--bg-dark);
            border-radius: 8px;
            border: 2px solid var(--border);
            min-width: 90px;
            text-align: center;
        }
        .player-timer.low-time { color: var(--warning); border-color: var(--warning); }
        .player-timer.critical { color: var(--danger); border-color: var(--danger); animation: pulse 0.5s infinite; }
        @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

        /* Move History */
        .move-history {
            height: 280px;
            min-height: 280px;
            max-height: 280px;
            overflow-y: auto;
            font-family: 'JetBrains Mono', monospace;
            font-size: 0.85rem;
        }
        .move-history::-webkit-scrollbar { width: 6px; }
        .move-history::-webkit-scrollbar-track { background: var(--bg-dark); }
        .move-history::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
        .move-row {
            display: flex;
            gap: 0.5rem;
            padding: 0.35rem 0;
            border-bottom: 1px solid rgba(255,255,255,0.05);
        }
        .move-number { color: var(--text-muted); width: 30px; }
        .move-white, .move-black {
            flex: 1;
            cursor: pointer;
            padding: 0.2rem 0.4rem;
            border-radius: 4px;
            transition: background 0.15s;
        }
        .move-white:hover, .move-black:hover { background: var(--bg-hover); }
        .move-current { background: var(--accent) !important; color: white; }
        .nav-controls { display: flex; gap: 0.5rem; justify-content: center; margin-top: 1rem; }
        .game-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin-top: 1rem; }

        .status-message {
            text-align: center;
            padding: 0.75rem 1.5rem;
            background: var(--bg-card);
            border-radius: 10px;
            border: 1px solid var(--border);
            font-weight: 600;
            width: 600px;
            max-width: 100%;
            box-sizing: border-box;
        }
        .status-message.check {
            background: rgba(255, 87, 87, 0.15);
            border-color: var(--danger);
            color: #fca5a5;
        }

        /* Home Screen */
        .home-screen { text-align: center; padding: 2rem; }
        .home-screen h1 {
            font-size: 3rem;
            margin-bottom: 0.5rem;
            background: linear-gradient(135deg, var(--accent), var(--purple), var(--success));
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        .home-screen p { color: var(--text-muted); margin-bottom: 2rem; }
        .setup-container {
            max-width: 750px;
            margin: 0 auto;
            background: var(--bg-card);
            padding: 2rem;
            border-radius: 16px;
            border: 1px solid var(--border);
            text-align: left;
        }
        .setup-section { margin-bottom: 1.75rem; }
        .setup-section h3 { margin-bottom: 0.75rem; color: var(--text); font-size: 1rem; }
        .game-modes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
        .game-mode-card {
            background: var(--bg-dark);
            border: 2px solid var(--border);
            border-radius: 12px;
            padding: 1.25rem;
            cursor: pointer;
            transition: all 0.25s;
            text-align: center;
        }
        .game-mode-card:hover, .game-mode-card.selected {
            border-color: var(--accent);
            background: rgba(79, 140, 255, 0.08);
            transform: translateY(-2px);
        }
        .game-mode-card h4 { font-size: 1.5rem; margin-bottom: 0.5rem; }
        .game-mode-card p { color: var(--text-muted); font-size: 0.85rem; }
        .timer-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.6rem; }
        .timer-btn {
            padding: 0.75rem 0.5rem;
            border: 1px solid var(--border);
            background: var(--bg-dark);
            color: var(--text);
            border-radius: 8px;
            cursor: pointer;
            text-align: center;
            transition: all 0.2s;
        }
        .timer-btn:hover { border-color: var(--accent); }
        .timer-btn.selected { border-color: var(--accent); background: var(--accent); color: white; }
        .timer-btn small { display: block; font-size: 0.7rem; color: var(--text-muted); margin-top: 2px; }
        .timer-btn.selected small { color: rgba(255,255,255,0.8); }
        .difficulty-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem; }
        .difficulty-btn {
            padding: 0.75rem;
            border: 1px solid var(--border);
            background: var(--bg-dark);
            color: var(--text);
            border-radius: 8px;
            cursor: pointer;
            text-align: center;
            transition: all 0.2s;
        }
        .difficulty-btn:hover { border-color: var(--accent); }
        .difficulty-btn.selected { border-color: var(--accent); background: var(--accent); color: white; }
        .theme-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 0.6rem; }
        .theme-option {
            cursor: pointer;
            border-radius: 8px;
            overflow: hidden;
            border: 2px solid transparent;
            transition: all 0.2s;
        }
        .theme-option:hover { transform: scale(1.05); }
        .theme-option.selected { border-color: var(--accent); box-shadow: 0 0 10px var(--accent-glow); }
        .theme-preview { height: 40px; display: grid; grid-template-columns: 1fr 1fr; }
        .theme-label { font-size: 0.7rem; text-align: center; padding: 4px; background: var(--bg-dark); }
        .tools-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; }
        .tool-btn {
            padding: 0.6rem;
            border: 1px solid var(--border);
            background: var(--bg-dark);
            color: var(--text-muted);
            border-radius: 6px;
            cursor: pointer;
            font-size: 1.1rem;
            transition: all 0.2s;
        }
        .tool-btn:hover { background: var(--bg-hover); color: var(--text); }

        /* Modal */
        .modal-overlay {
            display: none;
            position: fixed;
            top: 0; left: 0;
            width: 100%; height: 100%;
            background: rgba(0, 0, 0, 0.85);
            backdrop-filter: blur(4px);
            z-index: 1000;
            align-items: center;
            justify-content: center;
        }
        .modal-overlay.active { display: flex; }
        .modal-content {
            background: var(--bg-card);
            padding: 2.5rem;
            border-radius: 16px;
            border: 1px solid var(--border);
            max-width: 450px;
            width: 90%;
            text-align: center;
            animation: modalIn 0.3s ease;
        }
        @keyframes modalIn { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
        .modal-content h2 { font-size: 1.75rem; margin-bottom: 0.5rem; }
        .modal-content p { color: var(--text-muted); margin-bottom: 1.5rem; }
        .modal-buttons { display: flex; gap: 1rem; justify-content: center; }

        .promotion-modal {
            position: fixed;
            background: var(--bg-card);
            border: 2px solid var(--border);
            border-radius: 12px;
            padding: 8px;
            display: flex;
            gap: 4px;
            z-index: 1001;
            box-shadow: 0 10px 40px rgba(0,0,0,0.6);
        }
        .promotion-piece {
            width: 65px;
            height: 65px;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            border-radius: 8px;
            transition: all 0.15s;
            background: var(--bg-dark);
        }
        .promotion-piece:hover { background: var(--accent); transform: scale(1.1); }

        .thinking-badge {
            display: inline-flex;
            align-items: center;
            gap: 0.4rem;
            background: rgba(79, 140, 255, 0.15);
            color: var(--accent);
            padding: 0.3rem 0.8rem;
            border-radius: 6px;
            font-size: 0.85rem;
            font-weight: 600;
            animation: thinkingPulse 1.5s ease-in-out infinite;
            margin-left: 0.5rem;
        }
        @keyframes thinkingPulse {
            0%, 100% { opacity: 0.6; }
            50% { opacity: 1; }
        }
        .thinking-badge::before {
            content: '';
            width: 8px;
            height: 8px;
            background: var(--accent);
            border-radius: 50%;
            animation: thinkingDot 1s ease-in-out infinite;
        }
        @keyframes thinkingDot {
            0%, 100% { transform: scale(0.8); }
            50% { transform: scale(1.2); }
        }

        .difficulty-btn small { display: block; font-size: 0.7rem; color: var(--text-muted); margin-top: 2px; }
        .difficulty-btn.selected small { color: rgba(255,255,255,0.8); }

        .auth-container {
            max-width: 400px;
            margin: 3rem auto;
            background: var(--bg-card);
            padding: 2.5rem;
            border-radius: 16px;
            border: 1px solid var(--border);
        }
        .auth-container h2 { margin-bottom: 1.5rem; text-align: center; font-size: 1.75rem; }
        .form-group { margin-bottom: 1.25rem; }
        .form-group label { display: block; margin-bottom: 0.5rem; color: var(--text-muted); font-size: 0.9rem; }
        .form-group input, .form-group select, .form-group textarea {
            width: 100%;
            padding: 0.75rem;
            border: 1px solid var(--border);
            border-radius: 8px;
            background: var(--bg-dark);
            color: var(--text);
            font-size: 1rem;
        }
        .form-group input:focus { outline: none; border-color: var(--accent); }
        .auth-switch { text-align: center; margin-top: 1.5rem; color: var(--text-muted); }
        .auth-switch a { color: var(--accent); cursor: pointer; font-weight: 500; }
        .pgn-textarea { width: 100%; height: 200px; font-family: monospace; font-size: 0.85rem; resize: vertical; }
        .shortcuts-list { text-align: left; font-size: 0.85rem; }
        .shortcuts-list div { display: flex; justify-content: space-between; padding: 0.4rem 0; border-bottom: 1px solid var(--border); }
        .shortcuts-list kbd { background: var(--bg-dark); padding: 0.2rem 0.5rem; border-radius: 4px; font-family: monospace; }
        .toast {
            position: fixed;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);
            background: var(--bg-card);
            border: 1px solid var(--border);
            padding: 1rem 1.5rem;
            border-radius: 10px;
            z-index: 2000;
            animation: toastIn 0.3s ease;
        }
        @keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(20px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

        /* ============================================ */
        /* MOBILE RESPONSIVE STYLES */
        /* ============================================ */
        @media (max-width: 768px) {
            body { overflow-x: hidden; }
            nav {
                padding: 0.5rem 1rem;
                flex-wrap: wrap;
                gap: 0.5rem;
            }
            .logo { font-size: 1.1rem; }
            .nav-links {
                order: 3;
                width: 100%;
                justify-content: center;
                gap: 0.25rem;
            }
            .nav-links a { padding: 0.4rem 0.6rem; font-size: 0.8rem; }
            .container { padding: 0.5rem; overflow-x: hidden; }
            .home-screen h1 { font-size: 1.8rem; }
            .setup-container { padding: 1rem; }
            .game-modes { grid-template-columns: 1fr; }
            .timer-grid { grid-template-columns: repeat(3, 1fr); }
            .difficulty-grid { grid-template-columns: repeat(2, 1fr); }
            .theme-grid { grid-template-columns: repeat(3, 1fr); }
        }

        @media (max-width: 680px) {
            .container { padding: 0.25rem; }
            .game-layout {
                display: flex !important;
                flex-direction: column !important;
                align-items: center !important;
                gap: 0.5rem !important;
                padding: 0 !important;
                width: 100% !important;
                max-width: 100vw !important;
                overflow-x: hidden !important;
            }
            .side-panel {
                width: 96vw !important;
                min-width: unset !important;
                max-width: 96vw !important;
                order: 2;
            }
            .board-area {
                width: 100% !important;
                min-width: unset !important;
                max-width: 100vw !important;
                order: 1;
                display: flex !important;
                flex-direction: column !important;
                align-items: center !important;
            }
            .board-container {
                width: 96vw !important;
                min-width: unset !important;
                max-width: 96vw !important;
                padding: 6px !important;
                margin: 0 auto !important;
                box-sizing: border-box !important;
            }
            .board-frame {
                width: calc(96vw - 12px) !important;
                height: calc(96vw - 12px) !important;
                min-width: unset !important;
                max-width: calc(96vw - 12px) !important;
                padding: 8px !important;
                box-sizing: border-box !important;
            }
            #chessboard {
                width: calc(96vw - 28px) !important;
                height: calc(96vw - 28px) !important;
                min-width: unset !important;
                min-height: unset !important;
                max-width: calc(96vw - 28px) !important;
                max-height: calc(96vw - 28px) !important;
                grid-template-columns: repeat(8, 1fr) !important;
                grid-template-rows: repeat(8, 1fr) !important;
                box-sizing: border-box !important;
            }
            .eval-bar { display: none !important; }
            .eval-info { display: none !important; }
            .eval-pv-line { font-size: 0.7rem !important; width: 96vw !important; }
            .player-bar {
                width: 96vw !important;
                min-width: unset !important;
                max-width: 96vw !important;
                padding: 0.4rem 0.5rem !important;
                gap: 0.4rem !important;
                box-sizing: border-box !important;
            }
            .player-avatar {
                width: 30px !important;
                height: 30px !important;
                font-size: 0.9rem !important;
                flex-shrink: 0 !important;
            }
            .player-details { min-width: 0; }
            .player-name { font-size: 0.8rem !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
            .player-rating { font-size: 0.65rem !important; }
            .captured-pieces {
                width: auto !important;
                min-width: 40px !important;
                max-width: 70px !important;
                font-size: 0.7rem !important;
                flex-shrink: 1 !important;
            }
            .player-timer {
                font-size: 1rem !important;
                padding: 0.25rem 0.4rem !important;
                min-width: 58px !important;
                flex-shrink: 0 !important;
            }
            .status-message {
                width: 96vw !important;
                min-width: unset !important;
                max-width: 96vw !important;
                font-size: 0.8rem !important;
                padding: 0.4rem 0.75rem !important;
                box-sizing: border-box !important;
            }
            .panel { padding: 0.6rem; }
            .panel h3 { font-size: 0.8rem; margin-bottom: 0.5rem; }
            .move-history {
                height: 120px !important;
                min-height: 120px !important;
                max-height: 120px !important;
                font-size: 0.7rem !important;
            }
            .nav-controls { gap: 0.2rem; margin-top: 0.5rem; }
            .nav-controls .btn { padding: 0.35rem; font-size: 0.9rem; }
            .game-controls { grid-template-columns: 1fr 1fr; gap: 0.4rem; margin-top: 0.5rem; }
            .game-controls .btn { padding: 0.4rem; font-size: 0.75rem; }
            .tools-grid { grid-template-columns: repeat(4, 1fr); gap: 0.2rem; }
            .tool-btn { padding: 0.4rem; font-size: 0.9rem; }
            .piece { width: 88% !important; height: 88% !important; }
            .square .coord-label { font-size: 7px !important; }
            .modal-content { padding: 1.25rem; margin: 0.75rem; max-width: 95vw; }
            .modal-content h2 { font-size: 1.2rem; }
            .promotion-piece { width: 45px; height: 45px; }
        }

        @media (max-width: 400px) {
            .logo { font-size: 0.9rem; }
            .nav-links a { padding: 0.25rem 0.35rem; font-size: 0.7rem; }
            .board-container { padding: 4px !important; }
            .board-frame { padding: 5px !important; width: calc(96vw - 8px) !important; height: calc(96vw - 8px) !important; }
            #chessboard { width: calc(96vw - 18px) !important; height: calc(96vw - 18px) !important; }
            .player-bar { padding: 0.3rem 0.4rem !important; gap: 0.25rem !important; }
            .player-avatar { width: 26px !important; height: 26px !important; font-size: 0.8rem !important; }
            .captured-pieces { min-width: 30px !important; max-width: 50px !important; font-size: 0.6rem !important; }
            .player-timer { font-size: 0.9rem !important; min-width: 50px !important; padding: 0.2rem 0.3rem !important; }
            .status-message { font-size: 0.75rem !important; padding: 0.3rem 0.5rem !important; }
            .piece { width: 90% !important; height: 90% !important; }
            .square .coord-label { font-size: 6px !important; }
        }

        /* Share Buttons */
        .share-btn-copy {
            background: var(--accent);
            color: white;
            justify-content: center;
        }
        .share-btn-copy:hover { background: var(--accent-hover); }
        .share-btn-whatsapp {
            background: #25D366;
            color: white;
        }
        .share-btn-whatsapp:hover { background: #1da851; }
        .share-btn-twitter {
            background: #1DA1F2;
            color: white;
        }
        .share-btn-twitter:hover { background: #0d8ddb; }

        /* ── Database Section ────────────────────────── */
        .db-breadcrumb { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 1.25rem; flex-wrap: wrap; font-size: 0.9rem; }
        .db-breadcrumb a { color: var(--accent); cursor: pointer; }
        .db-breadcrumb a:hover { text-decoration: underline; }
        .db-breadcrumb .sep { color: var(--text-muted); }

        .db-back-btn { background: var(--bg-hover); border: 1px solid var(--border); color: var(--text); padding: 0.35rem 0.75rem; border-radius: 6px; cursor: pointer; font-size: 0.85rem; margin-right: 0.5rem; transition: all 0.2s; white-space: nowrap; }
        .db-back-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

        .db-search { display: flex; gap: 0.75rem; margin-bottom: 1.5rem; }
        .db-search input { flex: 1; padding: 0.7rem 1rem; background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 0.95rem; }
        .db-search input:focus { border-color: var(--accent); outline: none; }
        .db-search button { padding: 0.7rem 1.25rem; }

        .db-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
        .db-card { background: var(--bg-card); border: 2px solid var(--border); border-radius: 12px; padding: 1.25rem; cursor: pointer; transition: all 0.25s; }
        .db-card:hover { border-color: var(--accent); background: rgba(79, 140, 255, 0.08); transform: translateY(-2px); }
        .db-card h4 { font-size: 1.1rem; margin-bottom: 0.5rem; }
        .db-card .db-count { color: var(--accent); font-weight: 700; font-size: 1.5rem; }
        .db-card .db-label { color: var(--text-muted); font-size: 0.85rem; }

        .db-game-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
        .db-game-table th, .db-game-table td { padding: 0.6rem 0.8rem; text-align: left; border-bottom: 1px solid var(--border); }
        .db-game-table th { color: var(--text-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; }
        .db-game-table tr { cursor: pointer; transition: background 0.15s; }
        .db-game-table tr:hover { background: var(--bg-hover); }

        .db-pagination { display: flex; gap: 0.5rem; justify-content: center; margin-top: 1.25rem; }
        .db-pagination button { padding: 0.4rem 0.8rem; border: 1px solid var(--border); background: var(--bg-card); color: var(--text-muted); border-radius: 6px; cursor: pointer; font-size: 0.85rem; }
        .db-pagination button:hover { background: var(--bg-hover); }
        .db-pagination button.active { background: var(--accent); color: white; border-color: var(--accent); }
        .db-pagination button:disabled { opacity: 0.4; cursor: default; }

        .db-viewer { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
        .db-viewer-board { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; }
        .db-viewer-info { display: flex; flex-direction: column; gap: 1rem; }
        .db-viewer .move-list { background: var(--bg-dark); border-radius: 8px; padding: 1rem; max-height: 350px; overflow-y: auto; font-family: monospace; font-size: 0.85rem; line-height: 1.8; }
        .db-viewer .move-list .move-pair { display: flex; gap: 0.5rem; }
        .db-viewer .move-list .move-num { color: var(--text-muted); min-width: 2rem; text-align: right; }
        .db-viewer .move-list .move { cursor: pointer; padding: 0.1rem 0.3rem; border-radius: 3px; }
        .db-viewer .move-list .move:hover { background: var(--bg-hover); }
        .db-viewer .move-list .move.current { background: var(--accent); color: white; }
        .db-viewer .theme-badges { display: flex; flex-wrap: wrap; gap: 0.4rem; }
        .db-viewer .theme-badge { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 4px; font-size: 0.75rem; font-weight: 600; }
        .theme-badge-tactical { background: rgba(255,87,87,0.2); color: var(--danger); }
        .theme-badge-strategic { background: rgba(79,140,255,0.2); color: var(--accent); }
        .theme-badge-endgame { background: rgba(251,191,36,0.2); color: var(--warning); }
        .theme-badge-opening { background: rgba(74,222,128,0.2); color: var(--success); }

        .db-empty { text-align: center; padding: 3rem; color: var(--text-muted); }
        .db-stat-bar { display: flex; gap: 1.5rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
        .db-stat { text-align: center; }
        .db-stat .num { font-size: 1.5rem; font-weight: 700; color: var(--accent); }
        .db-stat .label { font-size: 0.8rem; color: var(--text-muted); }

        /* ── Study Room ──────────────────────────────── */
        .study-tools { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
        .study-btn { padding: 0.35rem 0.7rem; border: 1px solid var(--border); background: var(--bg-hover); color: var(--text); border-radius: 6px; cursor: pointer; font-size: 0.8rem; transition: all 0.2s; white-space: nowrap; }
        .study-btn:hover { border-color: var(--accent); }
        .study-btn.active { background: var(--accent); color: white; border-color: var(--accent); }
        .study-btn-save { background: rgba(74,222,128,0.15); border-color: var(--success); color: var(--success); }
        .study-btn-save.saved { background: var(--success); color: white; }
        .study-btn-guess { background: rgba(251,191,36,0.12); border-color: var(--warning); color: var(--warning); }
        .study-btn-guess.active { background: var(--warning); color: #1a1a1a; }

        .study-markers { display: flex; gap: 0.35rem; }
        .marker-btn { padding: 0.2rem 0.5rem; border-radius: 4px; border: 1px solid var(--border); background: var(--bg-dark); color: var(--text-muted); cursor: pointer; font-size: 0.7rem; transition: all 0.2s; }
        .marker-btn:hover { border-color: var(--text); }
        .marker-btn.active-mistake { background: rgba(255,87,87,0.25); color: var(--danger); border-color: var(--danger); }
        .marker-btn.active-critical { background: rgba(251,191,36,0.25); color: var(--warning); border-color: var(--warning); }
        .marker-btn.active-key_idea { background: rgba(74,222,128,0.25); color: var(--success); border-color: var(--success); }

        .move-marker { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-left: 3px; vertical-align: middle; }
        .move-marker-mistake { background: var(--danger); }
        .move-marker-critical { background: var(--warning); }
        .move-marker-key_idea { background: var(--success); }

        .study-note-area { margin-top: 0.5rem; }
        .study-note-area textarea { width: 100%; min-height: 60px; padding: 0.5rem; background: var(--bg-dark); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 0.8rem; resize: vertical; font-family: inherit; }
        .study-note-area textarea:focus { border-color: var(--accent); outline: none; }
        .study-note-label { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.25rem; }
        .study-note-indicator { color: var(--accent); font-size: 0.7rem; margin-left: 3px; }

        .study-room-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.25rem; flex-wrap: wrap; gap: 0.75rem; }
        .study-resume-btn { padding: 0.6rem 1.2rem; background: var(--accent); color: white; border: none; border-radius: 8px; cursor: pointer; font-size: 0.9rem; transition: background 0.2s; }
        .study-resume-btn:hover { background: var(--accent-hover); }
        .study-game-card .study-meta { display: flex; gap: 0.75rem; font-size: 0.75rem; color: var(--text-muted); margin-top: 0.5rem; }

        .guess-overlay { position: absolute; top: 0; left: 0; right: 0; bottom: 0; display: flex; align-items: center; justify-content: center; background: rgba(10,15,26,0.7); z-index: 10; border-radius: 8px; }
        .guess-prompt { text-align: center; color: white; }
        .guess-prompt h3 { font-size: 1.1rem; margin-bottom: 0.5rem; }
        .guess-reveal-btn { padding: 0.5rem 1.5rem; background: var(--warning); color: #1a1a1a; border: none; border-radius: 8px; cursor: pointer; font-size: 1rem; font-weight: 600; }

        @media (max-width: 768px) {
            .db-viewer { grid-template-columns: 1fr; }
            .db-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
            .study-tools { font-size: 0.75rem; }
        }

        /* Database viewer board — override 96vw to fit inside card padding */
        .db-viewer-board {
            overflow: hidden;
            box-sizing: border-box;
        }
        @media (max-width: 680px) {
            .db-viewer-board { padding: 0.25rem !important; }
            .db-viewer-board .board-container {
                width: 100% !important;
                max-width: 100% !important;
                min-width: unset !important;
                padding: 3px !important;
                box-sizing: border-box !important;
            }
            .db-viewer-board .board-frame {
                width: 100% !important;
                max-width: 100% !important;
                min-width: unset !important;
                height: unset !important;
                aspect-ratio: 1 !important;
                padding: 6px !important;
                box-sizing: border-box !important;
            }
            .db-viewer-board #chessboard {
                width: 100% !important;
                max-width: 100% !important;
                min-width: unset !important;
                height: unset !important;
                max-height: unset !important;
                min-height: unset !important;
                aspect-ratio: 1 !important;
            }
        }

        /* Player Profile */
        .player-link {
            color: var(--accent);
            cursor: pointer;
            text-decoration: none;
        }
        .player-link:hover {
            text-decoration: underline;
        }
        .player-profile {
            max-width: 900px;
            margin: 0 auto;
        }
        .player-stats-grid {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 0.75rem;
            margin-bottom: 1rem;
        }
        .player-stat-card {
            background: var(--bg-card);
            border: 1px solid var(--border);
            border-radius: 10px;
            padding: 1rem;
            text-align: center;
        }
        .player-stat-num {
            font-size: 1.5rem;
            font-weight: 700;
        }
        .player-stat-label {
            font-size: 0.8rem;
            color: var(--text-muted);
            margin-top: 0.25rem;
        }
        .player-result-bar {
            display: flex;
            height: 8px;
            border-radius: 4px;
            overflow: hidden;
            margin-bottom: 1.25rem;
            font-size: 0.7rem;
            line-height: 8px;
            color: white;
            text-align: center;
        }
        .result-bar-win { background: var(--success); }
        .result-bar-draw { background: #6b7280; }
        .result-bar-loss { background: var(--danger); }
        .player-details {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 1rem;
        }

        /* Opening Stats */
        .opening-filters {
            display: flex;
            gap: 0.5rem;
            flex-wrap: wrap;
            margin-bottom: 1rem;
        }
        .opening-filters select {
            background: var(--bg-card);
            color: var(--text);
            border: 1px solid var(--border);
            border-radius: 6px;
            padding: 0.5rem 0.75rem;
            font-size: 0.85rem;
            cursor: pointer;
        }
        .mini-result-bar {
            display: flex;
            height: 6px;
            border-radius: 3px;
            overflow: hidden;
            min-width: 60px;
        }
        .mini-result-bar > div {
            height: 100%;
        }

        /* Study Analysis */
        .study-btn-analyze {
            background: var(--bg-hover);
            border: 1px solid var(--border);
        }
        .study-btn-analyze.active {
            background: var(--success);
            color: #000;
            border-color: var(--success);
        }
        .eval-bar-container {
            display: flex;
            flex-direction: column;
            align-items: center;
            width: 28px;
            flex-shrink: 0;
        }
        .eval-bar {
            width: 20px;
            height: 100%;
            min-height: 200px;
            background: #333;
            border-radius: 4px;
            overflow: hidden;
            position: relative;
            border: 1px solid var(--border);
        }
        .eval-fill {
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            background: white;
            transition: height 0.3s ease;
        }
        .eval-info {
            display: flex;
            flex-direction: column;
            align-items: center;
            margin-top: 0.25rem;
        }
        .eval-score {
            font-size: 0.75rem;
            font-weight: 700;
            color: var(--text);
        }
        .eval-depth {
            font-size: 0.6rem;
            color: var(--text-muted);
        }
        .eval-pv-line {
            font-size: 0.75rem;
            color: var(--text-muted);
            padding: 0.3rem 0;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            font-family: monospace;
        }
        .square.selected {
            box-shadow: inset 0 0 0 3px var(--accent) !important;
        }
        .square.legal-target {
            position: relative;
        }
        .square.legal-target::after {
            content: '';
            position: absolute;
            width: 30%;
            height: 30%;
            background: rgba(79, 140, 255, 0.5);
            border-radius: 50%;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            pointer-events: none;
        }
        .variation-line {
            padding: 0.4rem 0;
            font-size: 0.8rem;
            line-height: 1.6;
            background: var(--bg-card);
            border: 1px solid var(--accent);
            border-radius: 6px;
            padding: 0.5rem 0.75rem;
            margin-top: 0.5rem;
        }
        .var-move-num {
            color: var(--text-muted);
            font-size: 0.75rem;
        }
        .var-move {
            cursor: pointer;
            padding: 0.1rem 0.2rem;
            border-radius: 3px;
        }
        .var-move:hover {
            background: var(--bg-hover);
        }
        .var-move.current {
            background: var(--accent);
            color: white;
            border-radius: 3px;
        }

        /* Collections */
        .collection-card {
            position: relative;
            text-align: center;
        }
        .collection-category-badge {
            display: inline-block;
            font-size: 0.65rem;
            color: white;
            padding: 0.15rem 0.5rem;
            border-radius: 10px;
            margin-top: 0.5rem;
            text-transform: capitalize;
        }

        /* Coach Picks */
        .coach-pick-card {
            border-left: 3px solid var(--accent);
        }

        @media (max-width: 640px) {
            .player-stats-grid {
                grid-template-columns: repeat(2, 1fr);
            }
            .player-stat-num {
                font-size: 1.2rem;
            }
            .player-details {
                grid-template-columns: 1fr;
            }
            .player-result-bar {
                height: 12px;
                font-size: 0.65rem;
                line-height: 12px;
            }
            .opening-filters {
                flex-direction: column;
            }
            .opening-filters select {
                width: 100%;
            }
            .opening-table th:nth-child(5),
            .opening-table td:nth-child(5),
            .opening-table th:nth-child(6),
            .opening-table td:nth-child(6) {
                display: none;
            }
            .player-link {
                padding: 0.15rem 0;
                display: inline-block;
            }
            .db-game-table td, .db-game-table th {
                padding: 0.5rem 0.4rem;
                font-size: 0.8rem;
            }
        }
