/* ============================================
   CSS Variables - Clean Professional Theme
   ============================================ */
:root {
    /* Dark Theme */
    --bg-base: #1a1d21;
    --bg-surface: #22262b;
    --bg-elevated: #2a2f35;
    --bg-card: #2d3238;
    --bg-hover: #363c44;
    
    --text-primary: #f4f5f6;
    --text-secondary: #a8adb5;
    --text-muted: #6b7280;
    
    --accent: #4f9d69;
    --accent-hover: #5bb377;
    --accent-glow: rgba(79, 157, 105, 0.3);
    
    --gold: #f5a623;
    --gold-glow: rgba(245, 166, 35, 0.3);
    
    --danger: #e74c3c;
    --warning: #f39c12;
    --success: #27ae60;
    
    --border: rgba(255, 255, 255, 0.08);
    --border-active: rgba(79, 157, 105, 0.5);
    
    /* Board Colors - Classic Wood */
    --board-light: #f0d9b5;
    --board-dark: #b58863;
    --board-selected: #829769;
    --board-move-hint: rgba(0, 0, 0, 0.12);
    --board-capture-hint: rgba(231, 76, 60, 0.6);
    --board-last-move: rgba(255, 255, 100, 0.4);
    --board-check: #e74c3c;
    
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    
    --transition: 0.2s ease;
}

[data-theme="light"] {
    --bg-base: #e8e8e8;
    --bg-surface: #f5f5f5;
    --bg-elevated: #ffffff;
    --bg-card: #ffffff;
    --bg-hover: #f0f0f0;
    
    --text-primary: #1a1d21;
    --text-secondary: #4a5568;
    --text-muted: #9ca3af;
    
    --border: rgba(0, 0, 0, 0.1);
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.12);
}

/* ============================================
   Reset & Base
   ============================================ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
    overflow-x: hidden;
}

/* ============================================
   Background Pattern
   ============================================ */
.app-wrapper {
    min-height: 100vh;
    position: relative;
}

.bg-pattern {
    position: fixed;
    inset: 0;
    background: 
        radial-gradient(circle at 20% 20%, rgba(79, 157, 105, 0.05) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(245, 166, 35, 0.03) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

.main-container {
    position: relative;
    z-index: 1;
    max-width: 1440px;
    margin: 0 auto;
    padding: 16px 24px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ============================================
   Header
   ============================================ */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    margin-bottom: 20px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Mobile Quick Actions - Hidden on desktop */
.mobile-quick-actions {
    display: none;
    align-items: center;
    gap: 6px;
    margin-left: 10px;
}

.mobile-quick-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.mobile-quick-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.mobile-quick-btn:active {
    transform: scale(0.95);
    background: var(--accent-hover);
}

.brand-icon {
    width: 44px;
    height: 44px;
    background: var(--bg-elevated);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
}

.brand-icon svg {
    width: 32px;
    height: 32px;
}

.brand-text {
    display: flex;
    flex-direction: column;
}

.brand-name {
    font-family: 'Playfair Display', serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
    letter-spacing: -0.5px;
}

.brand-accent {
    color: var(--accent);
}

.brand-tagline {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

/* Install App Button */
.install-app-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    margin-left: 12px;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px var(--accent-glow);
    white-space: nowrap;
    animation: installPulse 2s infinite;
}

.install-app-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.install-app-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px var(--accent-glow);
}

.install-app-btn:active {
    transform: scale(0.95);
}

@keyframes installPulse {
    0%, 100% { box-shadow: 0 2px 8px var(--accent-glow); }
    50% { box-shadow: 0 4px 20px var(--accent-glow); }
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-stats {
    display: flex;
    gap: 12px;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.stat-icon {
    font-size: 1rem;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.header-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.header-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.header-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--accent);
}

/* ============================================
   Game Layout
   ============================================ */
.game-wrapper {
    min-height: 90vh;
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    gap: 20px;
}

/* ============================================
   Sidebar & Cards
   ============================================ */
.sidebar {
    width: 280px;
    height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
}

.card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    overflow: hidden;
    transition: var(--transition);
}

.card:hover {
    border-color: var(--border-active);
}

.card-title {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.15);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.card-title svg {
    width: 18px;
    height: 18px;
    fill: var(--accent);
}

.card-content {
    padding: 14px 16px;
}

/* ============================================
   Mode Buttons
   ============================================ */
.btn-group.vertical {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.btn-mode {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.btn-mode:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    color: var(--text-primary);
}

.btn-mode.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.btn-mode-icon {
    font-size: 1.2rem;
}

/* ============================================
   Difficulty Grid
   ============================================ */
.difficulty-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.btn-difficulty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 6px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.btn-difficulty:hover {
    background: var(--bg-hover);
    border-color: var(--gold);
}

.btn-difficulty.active {
    background: linear-gradient(135deg, var(--gold), #e59400);
    border-color: var(--gold);
    color: #1a1d21;
}

.diff-stars {
    font-size: 0.65rem;
    letter-spacing: -2px;
}

/* ============================================
   Switch Toggle
   ============================================ */
.switch {
    position: relative;
    width: 40px;
    height: 22px;
    margin-left: auto;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: absolute;
    inset: 0;
    background: var(--bg-elevated);
    border-radius: 22px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: var(--transition);
}

.switch-slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 2px;
    bottom: 2px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: var(--transition);
}

.switch input:checked + .switch-slider {
    background: var(--accent);
    border-color: var(--accent);
}

.switch input:checked + .switch-slider::before {
    transform: translateX(18px);
    background: white;
}

.timer-content {
    transition: var(--transition);
}

.timer-content.disabled {
    opacity: 0.4;
    pointer-events: none;
}

.timer-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.btn-timer {
    padding: 8px 4px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-timer:hover {
    background: var(--bg-hover);
}

.btn-timer.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* ============================================
   Control Buttons
   ============================================ */
.btn-control {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.btn-control:last-child {
    margin-bottom: 0;
}

.btn-control svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.btn-control:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--accent);
}

.btn-control.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.btn-control.primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 0 20px var(--accent-glow);
}

.btn-control:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-control:disabled:hover {
    background: var(--bg-elevated);
    border-color: var(--border);
    box-shadow: none;
}

/* ============================================
   Checkbox Items
   ============================================ */
.checkbox-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-secondary);
    transition: var(--transition);
}

.checkbox-item:hover {
    color: var(--text-primary);
}

.checkbox-item input {
    display: none;
}

.checkbox-box {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
}

.checkbox-item input:checked + .checkbox-box {
    background: var(--accent);
    border-color: var(--accent);
}

.checkbox-item input:checked + .checkbox-box::after {
    content: '✓';
    color: white;
    font-size: 0.75rem;
    font-weight: bold;
}


/* ============================================
   Board Area
   ============================================ */
.board-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 12px;
    position: relative;
}

/* ============================================
   Player Bar
   ============================================ */
.player-bar {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    max-width: 540px;
    padding: 10px 16px;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 2px solid transparent;
    transition: var(--transition);
    position: relative;
}

.player-bar.active {
    border-color: var(--accent);
    box-shadow: 0 0 20px var(--accent-glow);
}

.player-avatar {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    flex-shrink: 0;
}

.player-avatar.white {
    background: linear-gradient(135deg, #fff, #e8e8e8);
    color: #333;
    box-shadow: var(--shadow-sm);
}

.player-avatar.black {
    background: linear-gradient(135deg, #444, #222);
    color: #fff;
    box-shadow: var(--shadow-sm);
}

.player-details {
    flex: 1;
    min-width: 0;
}

.player-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
}

.player-captured {
    font-size: 0.9rem;
    min-height: 1.2rem;
    opacity: 0.8;
    display: flex;
    gap: 1px;
    flex-wrap: wrap;
}

.player-meta {
    display: flex;
    align-items: center;
    gap: 10px;
}

.player-timer-box {
    padding: 6px 12px;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    min-width: 60px;
    text-align: center;
}

.player-timer-box.active {
    background: var(--accent);
    color: white;
}

.player-timer-box.low-time {
    background: var(--danger);
    animation: timerPulse 1s infinite;
}

@keyframes timerPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.player-score-box {
    padding: 4px 10px;
    background: var(--gold);
    border-radius: 20px;
    font-weight: 700;
    font-size: 0.85rem;
    color: #1a1d21;
    min-width: 32px;
    text-align: center;
}

.player-score-box .score-value::before {
    content: '+';
}

.player-score-box.zero {
    background: var(--text-muted);
    color: white;
}

.player-score-box.zero .score-value::before {
    content: '';
}

.turn-dot {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: var(--transition);
}

.turn-dot.active {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
    animation: dotPulse 1.5s infinite;
}

@keyframes dotPulse {
    0%, 100% { transform: translateY(-50%) scale(1); }
    50% { transform: translateY(-50%) scale(1.3); }
}

/* ============================================
   Chess Board
   ============================================ */
.board-frame {
    display: flex;
    gap: 8px;
}

.coord-rank {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    height: 480px;
    padding-right: 4px;
}

.coord-rank span {
    height: 60px;
    display: flex;
    align-items: center;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
}

.coord-file {
    display: flex;
    justify-content: space-around;
    width: 480px;
    margin-left: 28px;
    padding-top: 4px;
}

.coord-file span {
    width: 60px;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
}

.coord-rank.hidden,
.coord-file.hidden {
    opacity: 0;
}

.board-wrapper {
    position: relative;
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.chessboard {
    display: grid;
    grid-template-columns: repeat(8, 60px);
    grid-template-rows: repeat(8, 60px);
    border: 3px solid var(--board-dark);
}

.chessboard.flipped {
    transform: rotate(180deg);
}

.chessboard.flipped .piece {
    transform: rotate(180deg);
}

/* ============================================
   Chess Squares
   ============================================ */
.square {
    width: 60px;
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    position: relative;
    transition: filter 0.1s;
}

.square.light {
    background: var(--board-light);
}

.square.dark {
    background: var(--board-dark);
}

.square:hover {
    filter: brightness(1.08);
}

.square.selected {
    background: var(--board-selected) !important;
}

.square.valid-move::after {
    content: '';
    position: absolute;
    width: 26px;
    height: 26px;
    background: var(--board-move-hint);
    border-radius: 50%;
    pointer-events: none;
}

.square.valid-move.has-piece::after {
    width: 100%;
    height: 100%;
    background: transparent;
    border-radius: 0;
    border: 5px solid var(--board-capture-hint);
    box-sizing: border-box;
}

.square.last-move {
    background: var(--board-last-move) !important;
}

.square.check {
    background: var(--board-check) !important;
    animation: checkGlow 0.8s infinite;
}

@keyframes checkGlow {
    0%, 100% { box-shadow: inset 0 0 20px rgba(231, 76, 60, 0.5); }
    50% { box-shadow: inset 0 0 30px rgba(231, 76, 60, 0.8); }
}

.chessboard.no-hints .square.valid-move::after {
    display: none;
}

/* ============================================
   Chess Pieces
   ============================================ */
.piece {
    font-size: 46px;
    line-height: 1;
    cursor: grab;
    transition: transform 0.1s;
    z-index: 10;
    user-select: none;
}

.piece:active {
    cursor: grabbing;
}

.piece.white {
    color: #fff;
    text-shadow: 
        1px 1px 0 #000,
        -1px -1px 0 #000,
        1px -1px 0 #000,
        -1px 1px 0 #000,
        2px 2px 4px rgba(0, 0, 0, 0.4);
}

.piece.black {
    color: #1a1a1a;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.2);
}

.piece.dragging {
    opacity: 0.5;
}

.piece.moving {
    animation: pieceMove 0.2s ease-out;
}

@keyframes pieceMove {
    from { transform: scale(1.2); }
    to { transform: scale(1); }
}

/* ============================================
   Board Overlay
   ============================================ */
.board-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    padding: 14px 28px;
    background: rgba(0, 0, 0, 0.9);
    border-radius: var(--radius-md);
    border: 2px solid var(--gold);
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
    z-index: 100;
}

.board-overlay.visible {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}

.overlay-content {
    display: flex;
    align-items: center;
    gap: 10px;
    color: white;
    font-weight: 600;
    font-size: 1.1rem;
}

/* ============================================
   Advantage Bar
   ============================================ */
.advantage-container {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 540px;
    margin-top: 8px;
}

.adv-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    width: 36px;
}

.advantage-track {
    flex: 1;
    height: 8px;
    background: var(--bg-elevated);
    border-radius: 8px;
    position: relative;
    overflow: hidden;
}

.advantage-white,
.advantage-black {
    position: absolute;
    top: 0;
    height: 100%;
    transition: width 0.3s ease;
}

.advantage-white {
    left: 0;
    background: linear-gradient(90deg, #fff, #ccc);
    width: 50%;
}

.advantage-black {
    right: 0;
    background: linear-gradient(90deg, #444, #222);
    width: 50%;
}

.advantage-marker {
    position: absolute;
    left: 50%;
    top: -2px;
    width: 3px;
    height: 12px;
    background: var(--accent);
    transform: translateX(-50%);
    border-radius: 2px;
}

.adv-value {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent);
    min-width: 70px;
    text-align: right;
}

/* ============================================
   Status Card
   ============================================ */
.turn-display {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    font-weight: 600;
}

.turn-display.white {
    background: linear-gradient(135deg, #fff, #e0e0e0);
    color: #1a1d21;
}

.turn-display.black {
    background: linear-gradient(135deg, #444, #222);
    color: #fff;
}

.turn-icon {
    font-size: 1.5rem;
}

.turn-label {
    font-size: 0.95rem;
}

.game-state {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    margin-bottom: 10px;
}

.game-state.check {
    background: var(--warning);
    color: #1a1d21;
}

.game-state.checkmate {
    background: var(--gold);
    color: #1a1d21;
    font-weight: 600;
}

.game-state.draw {
    background: var(--text-muted);
    color: white;
}

.move-count {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.move-count span:last-child {
    font-weight: 700;
    color: var(--accent);
}

/* ============================================
   Score Card
   ============================================ */
.score-grid {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.score-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    flex: 1;
}

.score-piece {
    font-size: 1.8rem;
}

.score-num {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--accent);
}

.score-lbl {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.score-vs {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    padding: 0 12px;
}

/* ============================================
   Move History
   ============================================ */
.history-header {
    display: grid;
    grid-template-columns: 0.4fr 1fr 1fr;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
}

.history-header span {
    text-align: center;
}

.history-list {
    max-height: 220px;
    overflow-y: auto;
    padding-right: 4px;
}

.history-list::-webkit-scrollbar {
    width: 5px;
}

.history-list::-webkit-scrollbar-track {
    background: var(--bg-elevated);
    border-radius: 3px;
}

.history-list::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 3px;
}

.move-row {
    display: grid;
    grid-template-columns: 0.4fr 1fr 1fr;
    padding: 6px 4px;
    border-radius: 4px;
    transition: var(--transition);
}

.move-row:hover {
    background: var(--bg-hover);
}

.move-row.current {
    background: rgba(79, 157, 105, 0.15);
    border-left: 3px solid var(--accent);
}

.move-number {
    text-align: center;
    color: var(--accent);
    font-weight: 700;
    font-size: 0.8rem;
}

.move-white,
.move-black {
    text-align: center;
    font-size: 0.9rem;
    font-family: 'Consolas', monospace;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
    transition: var(--transition);
}

.move-white:hover,
.move-black:hover {
    background: var(--bg-hover);
}

/* ============================================
   Thinking Indicator
   ============================================ */
.thinking {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 14px 24px;
    background: var(--accent);
    color: white;
    border-radius: var(--radius-md);
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: thinkingPulse 1.5s infinite;
}

.thinking::before {
    content: '🤔';
    font-size: 1.2rem;
}

@keyframes thinkingPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(0.98); }
}

/* ============================================
   Promotion Modal
   ============================================ */
.promotion-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.promotion-modal-content {
    background: var(--bg-surface);
    padding: 30px 40px;
    border-radius: var(--radius-lg);
    text-align: center;
    border: 2px solid var(--accent);
    box-shadow: var(--shadow-lg);
}

.promotion-modal-content h3 {
    color: var(--accent);
    margin-bottom: 20px;
    font-size: 1.3rem;
}

.promotion-pieces {
    display: flex;
    gap: 14px;
    justify-content: center;
}

.promotion-piece {
    width: 70px;
    height: 70px;
    font-size: 48px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    border-radius: var(--radius-md);
    background: var(--bg-card);
    border: 2px solid var(--border);
    transition: var(--transition);
}

.promotion-piece:hover {
    background: var(--accent);
    border-color: var(--accent);
    transform: scale(1.1);
}

/* ============================================
   Game Over Modal
   ============================================ */
.game-over-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.game-over-content {
    background: var(--bg-surface);
    padding: 40px 50px;
    border-radius: var(--radius-lg);
    text-align: center;
    border: 3px solid var(--gold);
    box-shadow: 0 0 40px var(--gold-glow);
}

.game-over-icon {
    font-size: 4rem;
    margin-bottom: 16px;
    animation: iconBounce 2s ease-in-out infinite;
}

@keyframes iconBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.game-over-title {
    font-family: 'Playfair Display', serif;
    font-size: 2rem;
    color: var(--gold);
    margin-bottom: 8px;
}

.game-over-subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.game-over-btn {
    padding: 14px 40px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--accent);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.game-over-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

/* ============================================
   Footer
   ============================================ */
.footer {
    text-align: center;
    padding: 16px;
    margin-top: auto;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.footer-sep {
    margin: 0 8px;
}

/* ============================================
   SEO Article Section
   ============================================ */
.seo-article {
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    margin-top: 40px;
    padding: 60px 24px;
}

.article-container {
    max-width: 900px;
    margin: 0 auto;
}

.article-header {
    text-align: center;
    margin-bottom: 50px;
    padding-bottom: 40px;
    border-bottom: 1px solid var(--border);
}

.article-title {
    font-family: 'Playfair Display', serif;
    font-size: 2.5rem;
    color: var(--text-primary);
    margin-bottom: 24px;
    line-height: 1.2;
}

.article-intro {
    font-size: 1.1rem;
    color: var(--text-secondary);
    line-height: 1.8;
    margin-bottom: 16px;
}

.article-content {
    color: var(--text-secondary);
}

.article-section {
    margin-bottom: 48px;
}

.article-section h2 {
    font-family: 'Playfair Display', serif;
    font-size: 1.8rem;
    color: var(--text-primary);
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--accent);
    display: inline-block;
}

.article-section h3 {
    font-size: 1.2rem;
    color: var(--text-primary);
    margin: 24px 0 12px;
    font-weight: 600;
}

.article-section h4 {
    font-size: 1rem;
    color: var(--accent);
    margin-bottom: 8px;
    font-weight: 600;
}

.article-section p {
    font-size: 1rem;
    line-height: 1.8;
    margin-bottom: 16px;
}

.article-section ul {
    margin: 16px 0;
    padding-left: 24px;
}

.article-section ul li {
    font-size: 1rem;
    line-height: 1.8;
    margin-bottom: 8px;
}

.article-section strong {
    color: var(--text-primary);
}

/* Chess Quote */
.chess-quote {
    background: var(--bg-elevated);
    border-left: 4px solid var(--accent);
    padding: 16px 24px;
    margin: 20px 0;
    font-style: italic;
    font-size: 1.1rem;
    color: var(--accent);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* Piece List */
.piece-list {
    list-style: none;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin: 20px 0;
}

.piece-list li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.piece-icon {
    font-size: 1.4rem;
}

/* Rules Grid */
.rules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
    margin: 24px 0;
}

.rule-card {
    background: var(--bg-elevated);
    padding: 20px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    text-align: center;
    transition: var(--transition);
}

.rule-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}

.rule-piece {
    font-size: 3rem;
    display: block;
    margin-bottom: 12px;
}

.rule-card p {
    margin-bottom: 0;
    font-size: 0.95rem;
}

/* Outcome List */
.outcome-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin: 24px 0;
}

.outcome-item {
    background: var(--bg-elevated);
    padding: 20px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.outcome-item h3 {
    color: var(--accent);
    margin: 0 0 8px;
    font-size: 1.1rem;
}

.outcome-item p {
    margin: 0;
    font-size: 0.95rem;
}

/* Tips Grid */
.tips-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin: 24px 0;
}

.tip-card {
    background: var(--bg-card);
    padding: 24px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    text-align: center;
    transition: var(--transition);
}

.tip-card:hover {
    border-color: var(--gold);
    box-shadow: 0 4px 20px rgba(245, 166, 35, 0.1);
}

.tip-icon {
    font-size: 2.5rem;
    display: block;
    margin-bottom: 16px;
}

.tip-card h3 {
    color: var(--gold);
    margin: 0 0 12px;
    font-size: 1.1rem;
}

.tip-card p {
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.6;
}

/* Final Section */
.final-section {
    text-align: center;
    padding: 40px;
    background: var(--bg-elevated);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}

.final-section h2 {
    display: block;
    border-bottom: none;
    padding-bottom: 0;
}

.final-section h2::after {
    content: '';
    display: block;
    width: 80px;
    height: 3px;
    background: var(--accent);
    margin: 16px auto 0;
}

/* CTA Box */
.cta-box {
    margin-top: 24px;
    padding: 20px 30px;
    background: linear-gradient(135deg, var(--accent), var(--gold));
    border-radius: var(--radius-md);
    color: #1a1d21;
}

.cta-box p {
    margin: 0;
    font-size: 1.1rem;
}

.cta-box strong {
    color: #1a1d21;
}

/* Article Footer */
.article-footer {
    text-align: center;
    padding-top: 40px;
    margin-top: 40px;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ============================================
   Fullscreen Mode
   ============================================ */

/* Fullscreen Button */
.btn-fullscreen-game {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    max-width: 540px;
    margin-top: 12px;
    padding: 12px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.btn-fullscreen-game svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.btn-fullscreen-game:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* Fullscreen Status Bar (hidden by default) */
.fullscreen-status {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 20px;
    width: 100%;
    max-width: 600px;
    padding: 12px 20px;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    margin-top: 16px;
}

.fs-turn {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.fs-turn-icon {
    font-size: 1.4rem;
}

.fs-turn.white {
    color: #fff;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

.fs-turn.black {
    color: var(--text-primary);
}

.fs-game-status {
    padding: 6px 16px;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
}

.fs-game-status.check {
    background: var(--warning);
    color: #1a1d21;
}

.fs-game-status.checkmate {
    background: var(--gold);
    color: #1a1d21;
}

.fs-exit-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--danger);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    min-height: 44px;
    box-shadow: 0 4px 12px rgba(231, 76, 60, 0.4);
}

.fs-exit-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.fs-exit-btn:hover {
    background: #c0392b;
    transform: scale(1.02);
}

.fs-exit-btn:active {
    transform: scale(0.95);
}

/* Fullscreen Active State */
.fullscreen-active {
    overflow: hidden !important;
    position: fixed;
    width: 100%;
    height: 100%;
}

.fullscreen-active body {
    overflow: hidden !important;
}

.fullscreen-active .header,
.fullscreen-active .sidebar,
.fullscreen-active .seo-article,
.fullscreen-active .bg-pattern,
.fullscreen-active .mobile-controls,
.fullscreen-active .mobile-quick-actions {
    display: none !important;
}

.fullscreen-active .main-container {
    padding: 0;
    max-width: none;
    height: 100vh;
    height: 100dvh;
}

.fullscreen-active .game-wrapper {
    min-height: 100vh;
    min-height: 100dvh;
    justify-content: center;
    align-items: center;
    background: var(--bg-base);
    margin: 0;
    padding: 0;
}

.fullscreen-active .board-area {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    padding: 10px;
    justify-content: center;
    gap: 8px;
}

.fullscreen-active .btn-fullscreen-game {
    display: none;
}

.fullscreen-active .fullscreen-status {
    display: flex;
}

/* Scale board in fullscreen */
.fullscreen-active .board-frame {
    transform-origin: center;
}

.fullscreen-active .chessboard {
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
}

/* Player bars in fullscreen */
.fullscreen-active .player-bar {
    max-width: 600px;
    background: var(--bg-card);
    box-shadow: var(--shadow-md);
}

/* Advantage bar in fullscreen */
.fullscreen-active .advantage-container {
    max-width: 600px;
}

/* Auto-scale board based on viewport */
@media (max-height: 800px) {
    .fullscreen-active .chessboard {
        grid-template-columns: repeat(8, 50px);
        grid-template-rows: repeat(8, 50px);
    }
    
    .fullscreen-active .square {
        width: 50px;
        height: 50px;
    }
    
    .fullscreen-active .piece {
        font-size: 38px;
    }
    
    .fullscreen-active .coord-rank {
        height: 400px;
    }
    
    .fullscreen-active .coord-rank span {
        height: 50px;
    }
    
    .fullscreen-active .coord-file {
        width: 400px;
    }
    
    .fullscreen-active .coord-file span {
        width: 50px;
    }
}

@media (min-height: 900px) {
    .fullscreen-active .chessboard {
        grid-template-columns: repeat(8, 70px);
        grid-template-rows: repeat(8, 70px);
    }
    
    .fullscreen-active .square {
        width: 70px;
        height: 70px;
    }
    
    .fullscreen-active .piece {
        font-size: 54px;
    }
    
    .fullscreen-active .coord-rank {
        height: 560px;
    }
    
    .fullscreen-active .coord-rank span {
        height: 70px;
    }
    
    .fullscreen-active .coord-file {
        width: 560px;
    }
    
    .fullscreen-active .coord-file span {
        width: 70px;
    }
    
    .fullscreen-active .player-bar {
        max-width: 700px;
    }
    
    .fullscreen-active .advantage-container {
        max-width: 700px;
    }
}

@media (min-height: 1000px) {
    .fullscreen-active .chessboard {
        grid-template-columns: repeat(8, 80px);
        grid-template-rows: repeat(8, 80px);
    }
    
    .fullscreen-active .square {
        width: 80px;
        height: 80px;
    }
    
    .fullscreen-active .piece {
        font-size: 62px;
    }
    
    .fullscreen-active .coord-rank {
        height: 640px;
    }
    
    .fullscreen-active .coord-rank span {
        height: 80px;
    }
    
    .fullscreen-active .coord-file {
        width: 640px;
    }
    
    .fullscreen-active .coord-file span {
        width: 80px;
    }
}

/* ============================================
   Mobile Floating Fullscreen Button - CRITICAL FIX
   ============================================ */
.mobile-fullscreen-float {
    display: none;
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 9999 !important;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 18px;
    min-width: 50px;
    min-height: 50px;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: var(--radius-lg);
    color: white;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.4), 0 0 0 3px rgba(79, 157, 105, 0.3);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: auto !important;
    isolation: isolate;
}

.mobile-fullscreen-float:active {
    transform: scale(0.9) !important;
    box-shadow: 0 3px 15px rgba(0, 0, 0, 0.3);
}

.mobile-fullscreen-float .fs-icon-enter,
.mobile-fullscreen-float .fs-icon-exit {
    font-size: 1.3rem;
    line-height: 1;
    pointer-events: none;
}

.mobile-fullscreen-float .fs-text-enter,
.mobile-fullscreen-float .fs-text-exit {
    white-space: nowrap;
    pointer-events: none;
}

.mobile-fullscreen-float span {
    pointer-events: none;
}

/* Show floating button only on mobile */
@media (max-width: 768px) {
    .mobile-fullscreen-float {
        display: flex !important;
    }
}

/* Hide floating button in fullscreen - use the exit button in status bar */
.fullscreen-active .mobile-fullscreen-float {
    display: none !important;
}

/* ============================================
   Mobile Controls Bar
   ============================================ */
.mobile-controls {
    display: none;
    justify-content: center;
    gap: 10px;
    padding: 12px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    margin-top: 12px;
    width: 100%;
    max-width: 450px;
}

.mobile-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    flex: 1;
    min-height: 65px;
    padding: 10px 8px;
    background: var(--bg-elevated);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
}

.mobile-btn svg {
    width: 26px;
    height: 26px;
    fill: currentColor;
}

.mobile-btn:active {
    transform: scale(0.92);
    background: var(--bg-hover);
}

.mobile-btn.primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    border-color: var(--accent);
    color: white;
    box-shadow: 0 3px 15px var(--accent-glow);
}

.mobile-btn.primary:active {
    background: var(--accent-hover);
}

.mobile-btn.active {
    background: linear-gradient(135deg, var(--gold), #e59400);
    border-color: var(--gold);
    color: #1a1d21;
    box-shadow: 0 3px 15px var(--gold-glow);
}

/* ============================================
   Mobile Options Panel (Below Game) - STYLISH
   ============================================ */
.mobile-options-panel {
    display: none;
    flex-direction: column;
    gap: 16px;
    width: 100%;
    max-width: 500px;
    padding: 20px;
    margin-top: 12px;
    background: linear-gradient(145deg, var(--bg-card), var(--bg-elevated));
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    position: relative;
    z-index: 50;
}

.mobile-options-panel.active {
    display: flex;
    animation: slideUp 0.3s ease;
    pointer-events: auto;
}

.mobile-options-panel * {
    pointer-events: auto;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.mobile-option-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.mobile-option-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

.mobile-option-label svg {
    width: 16px;
    height: 16px;
    fill: var(--accent);
    flex-shrink: 0;
}

.mobile-option-label .switch {
    margin-left: auto;
}

.mobile-option-btns {
    display: grid;
    gap: 10px;
    pointer-events: auto;
}

.mobile-option-btns.mode-btns {
    grid-template-columns: 1fr 1fr;
}

.mobile-option-btns.difficulty-btns {
    grid-template-columns: repeat(3, 1fr);
}

.mobile-option-btns.timer-btns {
    grid-template-columns: repeat(4, 1fr);
}

.mobile-option-btns.timer-btns.disabled {
    opacity: 0.3;
    pointer-events: none;
}

/* Stylish Option Buttons - BIG & CLICKABLE */
.mobile-opt-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 16px 12px;
    background: var(--bg-elevated);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    min-height: 75px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    position: relative;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: auto !important;
    z-index: 10;
}

.mobile-opt-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent, rgba(255,255,255,0.05));
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}

.mobile-opt-btn:hover::before,
.mobile-opt-btn:active::before {
    opacity: 1;
}

.mobile-opt-btn svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.mobile-opt-btn span {
    font-size: 0.75rem;
    font-weight: 600;
}

.mobile-opt-btn:active {
    transform: scale(0.95);
}

/* Mode buttons */
.mobile-opt-btn.mode {
    min-height: 80px;
    flex-direction: row;
    gap: 10px;
}

.mobile-opt-btn.mode svg {
    width: 28px;
    height: 28px;
}

.mobile-opt-btn.mode span {
    font-size: 0.95rem;
    font-weight: 700;
}

.mobile-opt-btn.mode.active {
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    border-color: var(--accent);
    color: white;
    box-shadow: 0 4px 20px var(--accent-glow);
    transform: scale(1.02);
}

/* Difficulty buttons */
.mobile-opt-btn.diff {
    min-height: 85px;
}

.mobile-opt-btn.diff .diff-icon {
    font-size: 2rem;
    line-height: 1;
}

.mobile-opt-btn.diff span:last-child {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.mobile-opt-btn.diff.active {
    background: linear-gradient(135deg, var(--gold), #e59400);
    border-color: var(--gold);
    color: #1a1d21;
    box-shadow: 0 4px 20px var(--gold-glow);
    transform: scale(1.02);
}

.mobile-opt-btn.diff.active .diff-icon {
    animation: bounce 0.5s ease;
}

@keyframes bounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.3); }
}

/* Timer buttons */
.mobile-opt-btn.time {
    min-height: 70px;
    padding: 12px 8px;
}

.mobile-opt-btn.time .time-val {
    font-size: 1.6rem;
    font-weight: 800;
    line-height: 1;
    color: var(--text-primary);
}

.mobile-opt-btn.time .time-unit {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.7;
}

.mobile-opt-btn.time.active {
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    border-color: var(--accent);
    box-shadow: 0 4px 20px var(--accent-glow);
    transform: scale(1.02);
}

.mobile-opt-btn.time.active .time-val,
.mobile-opt-btn.time.active .time-unit {
    color: white;
    opacity: 1;
}

/* Mobile Checkboxes - BIG & STYLISH */
.mobile-option-checks {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    pointer-events: auto;
}

.mobile-check {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-elevated);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    min-height: 60px;
    pointer-events: auto !important;
    position: relative;
    z-index: 10;
}

.mobile-check:active {
    transform: scale(0.95);
    background: var(--bg-hover);
}

.mobile-check input {
    display: none;
}

.mobile-check .checkmark {
    width: 26px;
    height: 26px;
    border: 2px solid var(--border);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    flex-shrink: 0;
    background: var(--bg-base);
}

.mobile-check input:checked + .checkmark {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 2px 10px var(--accent-glow);
}

.mobile-check input:checked + .checkmark::after {
    content: '✓';
    color: white;
    font-size: 1rem;
    font-weight: bold;
}

.mobile-check span:last-child {
    font-size: 0.9rem;
}

.mobile-check:has(input:checked) {
    border-color: var(--accent);
    background: rgba(79, 157, 105, 0.1);
}

.mobile-check:has(input:checked) span:last-child {
    color: var(--text-primary);
}

/* Small switch for timer */
.switch.small {
    width: 40px;
    height: 22px;
}

.switch.small .switch-slider::before {
    width: 16px;
    height: 16px;
    left: 2px;
    bottom: 2px;
}

.switch.small input:checked + .switch-slider::before {
    transform: translateX(18px);
}

/* ============================================
   Mobile Menu Overlay
   ============================================ */
.mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.mobile-overlay.active {
    display: block;
    opacity: 1;
}

/* Mobile-only button visibility */
.mobile-only {
    display: none !important;
}

/* ============================================
   Responsive Design - Mobile First
   ============================================ */

/* Tablet & Desktop (>768px) - HIDE MOBILE ELEMENTS */
@media (min-width: 769px) {
    .mobile-controls {
        display: none !important;
    }
    
    .mobile-only {
        display: none !important;
    }
    
    .mobile-options-panel {
        display: none !important;
    }
    
    .mobile-fullscreen-float {
        display: none !important;
    }
}

/* Tablet (768px - 1200px) */
@media (max-width: 1200px) and (min-width: 769px) {
    .game-wrapper {
        flex-direction: column;
        max-width: 600px;
        margin: 0 auto;
        min-height: auto;
    }
    
    .sidebar {
        width: 100%;
        height: auto;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 12px;
    }
    
    .sidebar .card {
        flex: 1 1 200px;
        min-width: 200px;
    }
    
    .sidebar-right {
        order: -1;
    }
    
    .board-area {
        order: 0;
    }
    
    .sidebar-left {
        order: 1;
    }
}

/* Mobile (<=768px) - CRITICAL MOBILE OPTIMIZATION */
@media (max-width: 768px) {
    /* Base Mobile Resets */
    html {
        font-size: 14px;
    }
    
    body {
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        background: var(--bg-base);
    }
    
    /* Hide background pattern for performance */
    .bg-pattern {
        display: none;
    }
    
    /* App wrapper - ensure full height */
    .app-wrapper {
        min-height: 100vh;
        min-height: 100dvh;
    }
    
    /* Main Container - minimal padding */
    .main-container {
        padding: 0;
        max-width: 100%;
    }
    
    /* Header - Clean Professional Mobile Header */
    .header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        padding: 12px 16px;
        gap: 12px;
        background: var(--bg-surface);
        border-bottom: 1px solid var(--border);
        border-radius: 0;
        margin-bottom: 0;
        position: sticky;
        top: 0;
        z-index: 100;
    }
    
    .header-stats {
        display: none;
    }
    
    .header-left {
        flex: 1;
        gap: 10px;
    }
    
    .brand {
        gap: 10px;
    }
    
    /* Hide mobile quick actions - use bottom controls instead */
    .mobile-quick-actions {
        display: none !important;
    }
    
    /* Install button on mobile */
    .install-app-btn {
        padding: 6px 10px;
        margin-left: 8px;
        font-size: 0.7rem;
        border-radius: var(--radius-sm);
    }
    
    .install-app-btn svg {
        width: 14px;
        height: 14px;
    }
    
    .install-app-btn span {
        display: inline;
    }
    
    .brand-icon {
        width: 40px;
        height: 40px;
        background: linear-gradient(135deg, var(--accent), var(--accent-hover));
        border: none;
        box-shadow: 0 2px 8px var(--accent-glow);
    }
    
    .brand-icon svg {
        width: 28px;
        height: 28px;
    }
    
    .brand-icon svg path,
    .brand-icon svg rect {
        fill: white;
    }
    
    .brand-icon svg circle {
        fill: var(--gold);
    }
    
    .brand-name {
        font-size: 1.25rem;
    }
    
    .brand-tagline {
        display: block;
        font-size: 0.6rem;
        letter-spacing: 1px;
    }
    
    .header-btn {
        width: 38px;
        height: 38px;
        min-width: 38px;
        min-height: 38px;
    }
    
    .header-actions {
        gap: 6px;
    }
    
    /* Show mobile menu button */
    .mobile-only {
        display: flex !important;
    }
    
    /* Game Wrapper - Board First! */
    .game-wrapper {
        flex-direction: column;
        min-height: auto;
        gap: 0;
        max-width: 100%;
        padding: 0;
    }
    
    /* Sidebar - HIDDEN on mobile, use bottom options instead */
    .sidebar {
        display: none !important;
    }
    
    /* Hide menu button on mobile - no sidebar */
    .mobile-only {
        display: none !important;
    }
    
    /* Show mobile options panel */
    .mobile-options-panel {
        display: none;
        width: calc(100vw - 20px);
        max-width: 100%;
    }
    
    .mobile-options-panel.active {
        display: flex;
    }
    
    .sidebar .card {
        width: 100%;
        min-width: unset;
        margin-bottom: 10px;
        overflow: visible;
    }
    
    /* Card titles - full text visible */
    .sidebar .card-title {
        font-size: 0.85rem;
        padding: 10px 12px;
        white-space: nowrap;
    }
    
    .sidebar .card-title svg {
        flex-shrink: 0;
        width: 16px;
        height: 16px;
    }
    
    .sidebar .card-content {
        padding: 10px 12px;
        overflow: visible;
    }
    
    /* Mode buttons - ensure BOTH show clearly */
    .sidebar .btn-group.vertical {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px;
        width: 100%;
    }
    
    .sidebar .btn-mode {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        align-items: center;
        gap: 12px;
        padding: 14px 16px;
        font-size: 0.95rem;
        width: 100%;
        min-height: 54px;
        background: var(--bg-elevated);
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
    }
    
    .sidebar .btn-mode.active {
        background: var(--accent);
        border-color: var(--accent);
        color: white;
    }
    
    .sidebar .btn-mode-icon {
        font-size: 1.4rem;
        flex-shrink: 0;
    }
    
    .sidebar .btn-mode-text {
        font-size: 0.95rem;
        font-weight: 600;
    }
    
    /* Difficulty buttons - FULL TEXT visible */
    .sidebar .difficulty-grid {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 10px;
        width: 100%;
    }
    
    .sidebar .btn-difficulty {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 12px 8px;
        min-height: 70px;
        width: 100%;
        overflow: visible;
        background: var(--bg-elevated);
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
    }
    
    .sidebar .btn-difficulty.active {
        background: linear-gradient(135deg, var(--gold), #e59400);
        border-color: var(--gold);
    }
    
    .sidebar .btn-difficulty .diff-stars {
        display: block !important;
        visibility: visible !important;
        font-size: 0.85rem !important;
        letter-spacing: 0px;
        margin-bottom: 6px;
    }
    
    .sidebar .btn-difficulty span:last-child {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        font-size: 0.8rem;
        font-weight: 600;
        color: var(--text-secondary);
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }
    
    .sidebar .btn-difficulty.active span:last-child {
        color: #1a1d21;
    }
    
    /* Timer section - make sure it shows */
    .sidebar .timer-content {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    .sidebar .timer-content.disabled {
        opacity: 0.4 !important;
        pointer-events: none;
    }
    
    /* Timer buttons - FULL TEXT visible */
    .sidebar .timer-buttons {
        display: grid !important;
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 8px;
        width: 100%;
    }
    
    .sidebar .btn-timer {
        display: flex !important;
        align-items: center;
        justify-content: center;
        padding: 12px 6px;
        font-size: 0.9rem;
        font-weight: 700;
        min-height: 46px;
        text-align: center;
        width: 100%;
        background: var(--bg-elevated);
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
    }
    
    .sidebar .btn-timer.active {
        background: var(--accent);
        border-color: var(--accent);
        color: white;
    }
    
    
    /* Control buttons - full text */
    .sidebar .btn-control {
        display: flex !important;
        visibility: visible !important;
        align-items: center;
        justify-content: center;
        gap: 10px;
        padding: 14px 16px;
        font-size: 0.95rem;
        font-weight: 500;
        margin-bottom: 8px;
        width: 100%;
        min-height: 50px;
    }
    
    .sidebar .btn-control svg {
        width: 20px;
        height: 20px;
    }
    
    /* Checkbox items - full text */
    .sidebar .checkbox-item {
        display: flex !important;
        visibility: visible !important;
        align-items: center;
        gap: 12px;
        font-size: 0.9rem;
        min-height: 46px;
        padding: 10px 0;
        border-bottom: 1px solid var(--border);
    }
    
    .sidebar .checkbox-item:last-child {
        border-bottom: none;
    }
    
    .sidebar .checkbox-box {
        width: 24px;
        height: 24px;
        flex-shrink: 0;
    }
    
    .sidebar .checkbox-text {
        display: inline !important;
        visibility: visible !important;
        font-size: 0.9rem;
        font-weight: 500;
    }
    
    /* Switch toggle in card title */
    .sidebar .card-title .switch {
        flex-shrink: 0;
        margin-left: auto;
    }
    
    
    /* Board Area - FIRST & CENTERED */
    .board-area {
        width: 100%;
        padding: 10px;
        order: 0 !important;
        flex: none;
        display: flex;
        flex-direction: column;
        align-items: center;
        background: var(--bg-base);
        position: relative;
    }
    
    /* Dynamic Board Scaling - Use fixed calc for reliability */
    .chessboard {
        grid-template-columns: repeat(8, calc((100vw - 20px) / 8));
        grid-template-rows: repeat(8, calc((100vw - 20px) / 8));
        border-width: 2px;
        max-width: calc(100vw - 20px);
    }
    
    .square {
        width: calc((100vw - 20px) / 8);
        height: calc((100vw - 20px) / 8);
    }
    
    .piece {
        font-size: calc((100vw - 20px) / 8 * 0.7);
    }
    
    /* Hide coordinates on mobile for bigger board */
    .coord-rank,
    .coord-file {
        display: none;
    }
    
    .board-frame {
        gap: 0;
    }
    
    /* Player Bars - Clean & compact */
    .player-bar {
        width: calc(100vw - 20px);
        max-width: 100%;
        padding: 10px 12px;
        gap: 10px;
        border-radius: var(--radius-md);
        margin: 6px 0;
        background: var(--bg-card);
    }
    
    .player-avatar {
        width: 36px;
        height: 36px;
        font-size: 1.3rem;
    }
    
    .player-name {
        font-size: 0.9rem;
        font-weight: 600;
    }
    
    .player-captured {
        font-size: 0.7rem;
    }
    
    .player-timer-box {
        padding: 6px 10px;
        font-size: 0.85rem;
        font-weight: 600;
    }
    
    .player-score-box {
        padding: 4px 12px;
        font-size: 0.8rem;
    }
    
    .turn-dot {
        width: 10px;
        height: 10px;
        right: 10px;
    }
    
    /* Advantage Bar - Compact */
    .advantage-container {
        width: calc(100vw - 20px);
        max-width: 100%;
        padding: 8px 12px;
        gap: 8px;
        margin-top: 6px;
        border-radius: var(--radius-md);
    }
    
    .adv-label {
        font-size: 0.7rem;
    }
    
    .adv-value {
        font-size: 0.75rem;
        padding: 3px 10px;
    }
    
    /* Mobile Controls - Show on mobile */
    .mobile-controls {
        display: flex;
        width: calc(100vw - 20px);
        max-width: 100%;
        margin-top: 10px;
        background: var(--bg-card);
        border-radius: var(--radius-md);
        padding: 10px;
        gap: 8px;
    }
    
    .mobile-btn {
        flex: 1;
        min-width: auto;
        min-height: 50px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        padding: 8px;
        background: var(--bg-elevated);
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        color: var(--text-secondary);
        font-size: 0.7rem;
        font-weight: 500;
        cursor: pointer;
    }
    
    .mobile-btn svg {
        width: 20px;
        height: 20px;
        fill: currentColor;
    }
    
    .mobile-btn:active {
        background: var(--accent);
        color: white;
    }
    
    /* Hide fullscreen game button on mobile - use floating button */
    .btn-fullscreen-game {
        display: none;
    }
    
    /* Floating fullscreen button positioning */
    .mobile-fullscreen-float {
        top: 12px;
        right: 12px;
        padding: 14px 18px;
        font-size: 0.9rem;
        min-width: 50px;
        min-height: 50px;
    }
    
    /* Article - Mobile optimized */
    .seo-article {
        padding: 32px 16px;
        margin-top: 20px;
    }
    
    .article-container {
        padding: 0;
    }
    
    .article-title {
        font-size: 1.5rem;
    }
    
    .article-intro {
        font-size: 0.95rem;
    }
    
    .article-section h2 {
        font-size: 1.25rem;
    }
    
    .article-section h3 {
        font-size: 1rem;
    }
    
    .rules-grid,
    .tips-grid,
    .outcome-list {
        grid-template-columns: 1fr;
    }
    
    .piece-list {
        grid-template-columns: 1fr;
    }
    
    .final-section {
        padding: 20px 16px;
    }
    
    .cta-box {
        padding: 14px 16px;
    }
    
    /* Touch-friendly button sizes - minimum 44px */
    .btn-mode,
    .btn-control,
    .btn-difficulty,
    .btn-timer {
        min-height: 44px;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    
    /* Move history - compact */
    .move-list {
        max-height: 150px;
    }
    
    .move-row {
        padding: 4px 6px;
        font-size: 0.75rem;
    }
}

/* Small Mobile (<480px) */
@media (max-width: 480px) {
    .header {
        padding: 10px 12px;
    }
    
    .brand-icon {
        width: 36px;
        height: 36px;
    }
    
    .brand-icon svg {
        width: 24px;
        height: 24px;
    }
    
    .brand-name {
        font-size: 1.1rem;
    }
    
    .brand-tagline {
        font-size: 0.55rem;
    }
    
    .header-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
    }
    
    /* Board - Maximized for small screens */
    .board-area {
        padding: 8px;
    }
    
    .chessboard {
        grid-template-columns: repeat(8, calc((100vw - 16px) / 8));
        grid-template-rows: repeat(8, calc((100vw - 16px) / 8));
        max-width: calc(100vw - 16px);
    }
    
    .square {
        width: calc((100vw - 16px) / 8);
        height: calc((100vw - 16px) / 8);
    }
    
    .piece {
        font-size: calc((100vw - 16px) / 8 * 0.7);
    }
    
    /* Player bars - fit board width */
    .player-bar {
        width: calc(100vw - 16px);
        padding: 8px 10px;
        gap: 8px;
        margin: 4px 0;
    }
    
    .player-avatar {
        width: 32px;
        height: 32px;
        font-size: 1.2rem;
    }
    
    .player-name {
        font-size: 0.85rem;
    }
    
    .player-timer-box {
        padding: 4px 8px;
        font-size: 0.8rem;
    }
    
    /* Advantage bar - fit board width */
    .advantage-container {
        width: calc(100vw - 16px);
    }
    
    /* Mobile controls - fit board width */
    .mobile-controls {
        width: calc(100vw - 16px);
        padding: 8px;
        gap: 6px;
    }
    
    .mobile-btn {
        min-height: 48px;
        padding: 8px 6px;
        font-size: 0.65rem;
    }
    
    .mobile-btn svg {
        width: 18px;
        height: 18px;
    }
    
    /* Floating fullscreen button */
    .mobile-fullscreen-float {
        padding: 12px 16px;
        font-size: 0.85rem;
        min-width: 48px;
        min-height: 48px;
    }
}

/* Extra Small Mobile (<380px) */
@media (max-width: 380px) {
    .header {
        padding: 8px 10px;
    }
    
    .brand-icon {
        width: 32px;
        height: 32px;
    }
    
    .brand-icon svg {
        width: 22px;
        height: 22px;
    }
    
    .brand-name {
        font-size: 1rem;
    }
    
    .brand-tagline {
        display: none;
    }
    
    .header-btn {
        width: 34px;
        height: 34px;
        min-width: 34px;
    }
    
    .board-area {
        padding: 6px;
    }
    
    .chessboard {
        grid-template-columns: repeat(8, calc((100vw - 12px) / 8));
        grid-template-rows: repeat(8, calc((100vw - 12px) / 8));
        max-width: calc(100vw - 12px);
    }
    
    .square {
        width: calc((100vw - 12px) / 8);
        height: calc((100vw - 12px) / 8);
    }
    
    .piece {
        font-size: calc((100vw - 12px) / 8 * 0.7);
    }
    
    .player-bar {
        width: calc(100vw - 12px);
        padding: 6px 8px;
    }
    
    .player-avatar {
        width: 28px;
        height: 28px;
        font-size: 1rem;
    }
    
    .player-details {
        flex: 1;
        min-width: 0;
    }
    
    .player-name {
        font-size: 0.8rem;
    }
    
    .player-captured {
        display: none;
    }
    
    .player-timer-box {
        padding: 3px 6px;
        font-size: 0.75rem;
    }
    
    .player-score-box {
        padding: 3px 8px;
        font-size: 0.7rem;
    }
    
    .advantage-container {
        width: calc(100vw - 12px);
        padding: 6px 8px;
    }
    
    .mobile-controls {
        width: calc(100vw - 12px);
        padding: 6px;
        gap: 4px;
    }
    
    .mobile-btn {
        min-width: 44px;
        min-height: 44px;
        padding: 6px 4px;
    }
    
    .mobile-btn span {
        display: none;
    }
    
    /* Floating button - still big enough for touch */
    .mobile-fullscreen-float {
        padding: 10px 14px;
        font-size: 0.8rem;
        top: 8px;
        right: 8px;
        min-width: 46px;
        min-height: 46px;
    }
    
    .mobile-fullscreen-float .fs-text-enter,
    .mobile-fullscreen-float .fs-text-exit {
        display: none;
    }
}

/* Mobile Fullscreen Optimizations */
@media (max-width: 768px) {
    .fullscreen-active .board-area {
        padding: 10px;
        height: 100vh;
        height: 100dvh;
        justify-content: center;
    }
    
    .fullscreen-active .chessboard {
        grid-template-columns: repeat(8, calc((min(100vw, 100vh - 200px)) / 8));
        grid-template-rows: repeat(8, calc((min(100vw, 100vh - 200px)) / 8));
    }
    
    .fullscreen-active .square {
        width: calc((min(100vw, 100vh - 200px)) / 8);
        height: calc((min(100vw, 100vh - 200px)) / 8);
    }
    
    .fullscreen-active .piece {
        font-size: calc((min(100vw, 100vh - 200px)) / 8 * 0.7);
    }
    
    .fullscreen-active .player-bar {
        width: calc(min(100vw, 100vh - 200px));
        max-width: calc(100vw - 20px);
    }
    
    .fullscreen-active .advantage-container {
        width: calc(min(100vw, 100vh - 200px));
        max-width: calc(100vw - 20px);
    }
    
    .fullscreen-active .fullscreen-status {
        flex-direction: column;
        gap: 10px;
        padding: 12px 16px;
        width: calc(min(100vw, 100vh - 200px));
        max-width: calc(100vw - 20px);
    }
    
    /* Turn and status in a row */
    .fullscreen-active .fullscreen-status > .fs-turn,
    .fullscreen-active .fullscreen-status > .fs-game-status {
        display: inline-flex;
    }
    
    .fullscreen-active .fs-exit-btn {
        width: 100%;
        justify-content: center;
        padding: 14px 20px;
        min-height: 50px;
        font-size: 1rem;
        border-radius: var(--radius-md);
        background: var(--danger);
        box-shadow: 0 4px 15px rgba(231, 76, 60, 0.5);
    }
    
    .fullscreen-active .fs-exit-btn span {
        display: inline;
    }
    
    .fullscreen-active .fs-exit-btn svg {
        width: 22px;
        height: 22px;
    }
    
    /* Hide mobile controls in fullscreen */
    .fullscreen-active .mobile-controls {
        display: none;
    }
    
    /* Hide floating button in fullscreen */
    .fullscreen-active .mobile-fullscreen-float {
        display: none !important;
    }
}

/* Landscape Mobile */
@media (max-width: 900px) and (orientation: landscape) {
    .game-wrapper {
        flex-direction: row;
        align-items: flex-start;
        gap: 12px;
    }
    
    .board-area {
        flex: 0 0 auto;
    }
    
    .chessboard {
        --square-size: calc((100vh - 100px) / 8);
        --square-size: calc((100dvh - 100px) / 8);
    }
    
    .sidebar {
        position: relative;
        right: 0;
        width: auto;
        min-width: 200px;
        height: auto;
        padding: 8px;
        padding-top: 8px;
    }
    
    .mobile-controls {
        display: none;
    }
    
    /* Fullscreen in landscape */
    .fullscreen-active .chessboard {
        --square-size: calc((100vh - 120px) / 8);
        --square-size: calc((100dvh - 120px) / 8);
    }
}
