/* ==========================================================================
   Grandmaster 1v1 Chess Design System
   Aesthetic: Dark Luxury Glassmorphism & High-Precision Sports Clock UI
   ========================================================================== */

:root {
    --bg-primary: #090d16;
    --bg-secondary: #0f172a;
    --bg-card: rgba(19, 29, 50, 0.75);
    --bg-card-hover: rgba(28, 42, 70, 0.85);
    --border-card: rgba(255, 255, 255, 0.08);
    --border-card-highlight: rgba(56, 189, 248, 0.4);

    --accent-cyan: #38bdf8;
    --accent-emerald: #10b981;
    --accent-gold: #f59e0b;
    --accent-crimson: #ef4444;

    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --font-ui: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
    --font-heading: 'Outfit', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;

    --shadow-subtle: 0 4px 20px rgba(0, 0, 0, 0.35);
    --shadow-glow-cyan: 0 0 25px rgba(56, 189, 248, 0.25);
    --shadow-glow-emerald: 0 0 25px rgba(16, 185, 129, 0.25);
    --shadow-glow-crimson: 0 0 25px rgba(239, 68, 68, 0.35);
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-ui);
    min-height: 100vh;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
}

/* Ambient Radial Mesh Background */
.app-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: 
        radial-gradient(circle at 15% 15%, rgba(56, 189, 248, 0.07) 0%, transparent 45%),
        radial-gradient(circle at 85% 85%, rgba(16, 185, 129, 0.07) 0%, transparent 45%),
        radial-gradient(circle at 50% 50%, rgba(15, 23, 42, 0.95) 0%, #080c14 100%);
    z-index: -1;
    pointer-events: none;
}

.game-container {
    max-width: 1440px;
    margin: 0 auto;
    padding: 16px 24px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    gap: 16px;
    width: 100%;
}

/* ==========================================================================
   Header & Action Bar
   ========================================================================== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--bg-card);
    backdrop-filter: blur(18px);
    border: 1px solid var(--border-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-subtle);
    gap: 16px;
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-logo {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, #1e293b, #0f172a);
    border: 1px solid rgba(255, 255, 255, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.logo-icon {
    font-size: 26px;
    color: #f8fafc;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4));
}

.brand-text h1 {
    font-family: var(--font-heading);
    font-size: 20px;
    font-weight: 800;
    letter-spacing: 0.5px;
    color: var(--text-primary);
}

.brand-text h1 span {
    color: var(--accent-cyan);
    font-size: 16px;
    padding: 2px 7px;
    background: rgba(56, 189, 248, 0.15);
    border-radius: 6px;
    border: 1px solid rgba(56, 189, 248, 0.3);
}

.brand-text .tagline {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
    display: block;
    letter-spacing: 0.3px;
}

.header-actions,
.action-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* Reusable Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 16px;
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, #0284c7, #0369a1);
    color: #ffffff;
    border-color: rgba(56, 189, 248, 0.3);
    box-shadow: 0 4px 14px rgba(2, 132, 199, 0.35);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #0369a1, #075985);
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(2, 132, 199, 0.45);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.1);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border-color: rgba(255, 255, 255, 0.12);
}

.btn-outline:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.25);
}

.btn-danger {
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.2);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
    border-color: rgba(239, 68, 68, 0.4);
}

.btn-icon-only {
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 15px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon-only:hover {
    background: rgba(255, 255, 255, 0.14);
}

.btn-lg {
    padding: 12px 24px;
    font-size: 15px;
    border-radius: var(--radius-md);
}

.btn-block {
    width: 100%;
}

/* ==========================================================================
   Arena 3-Column Layout
   ========================================================================== */
.arena-layout {
    display: grid;
    grid-template-columns: 290px 1fr 280px;
    gap: 20px;
    flex: 1;
    align-items: center;
}

.panel {
    background: var(--bg-card);
    backdrop-filter: blur(18px);
    border: 1px solid var(--border-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-subtle);
    padding: 18px;
    display: flex;
    flex-direction: column;
}

/* ==========================================================================
   Left Panel: Players & Clocks
   ========================================================================== */
.panel-players {
    gap: 16px;
    justify-content: space-between;
    height: 100%;
    max-height: 680px;
}

.player-card {
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: relative;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.player-card.active-turn {
    background: rgba(14, 165, 233, 0.08);
    border-color: rgba(56, 189, 248, 0.5);
    box-shadow: 0 0 20px rgba(56, 189, 248, 0.15);
}

.player-header {
    display: flex;
    align-items: center;
    gap: 12px;
}

.player-avatar {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 700;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.white-avatar {
    background: linear-gradient(135deg, #f8fafc, #cbd5e1);
    color: #0f172a;
    border: 1px solid rgba(255, 255, 255, 0.8);
}

.black-avatar {
    background: linear-gradient(135deg, #334155, #0f172a);
    color: #f8fafc;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.player-info {
    flex: 1;
    overflow: hidden;
}

.player-role {
    font-size: 11px;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.6px;
    color: var(--text-muted);
}

.player-name {
    font-family: var(--font-heading);
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.score-diff {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 700;
    background: rgba(16, 185, 129, 0.18);
    color: var(--accent-emerald);
    padding: 3px 8px;
    border-radius: 6px;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

/* Digital Clock Readout */
.clock-container {
    background: #060911;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    position: relative;
    overflow: hidden;
}

.clock-display-wrap {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.digital-clock {
    font-family: var(--font-mono);
    font-size: 32px;
    font-weight: 800;
    color: #f8fafc;
    letter-spacing: 1px;
    text-align: right;
    transition: color 0.2s;
}

.shot-clock-badge {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 700;
    color: var(--accent-cyan);
    background: rgba(56, 189, 248, 0.14);
    border: 1px solid rgba(56, 189, 248, 0.35);
    border-radius: 4px;
    padding: 2px 7px;
    white-space: nowrap;
    align-items: center;
    line-height: 1.2;
}

.shot-clock-badge.warning {
    color: var(--accent-gold);
    background: rgba(245, 158, 11, 0.15);
    border-color: rgba(245, 158, 11, 0.4);
}

.shot-clock-badge.critical {
    color: var(--accent-crimson);
    background: rgba(239, 68, 68, 0.18);
    border-color: rgba(239, 68, 68, 0.45);
    animation: pulseCritical 0.8s infinite alternate;
}

.player-card.active-turn .digital-clock {
    color: var(--accent-cyan);
    text-shadow: 0 0 12px rgba(56, 189, 248, 0.3);
}

.digital-clock.timer-warning {
    color: var(--accent-gold) !important;
    text-shadow: 0 0 14px rgba(245, 158, 11, 0.4) !important;
}

.digital-clock.timer-critical {
    color: var(--accent-crimson) !important;
    text-shadow: 0 0 16px rgba(239, 68, 68, 0.6) !important;
    animation: pulseCritical 0.8s infinite alternate;
}

@keyframes pulseCritical {
    from { opacity: 0.75; transform: scale(0.99); }
    to { opacity: 1; transform: scale(1.02); }
}

/* Per-Move Shot Clock Depleting Bar */
.move-timer-track {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.07);
    border-radius: 2px;
    margin-top: 6px;
    overflow: hidden;
}

.move-timer-bar {
    height: 100%;
    width: 100%;
    background: var(--accent-cyan);
    border-radius: 2px;
    transition: width 0.1s linear, background-color 0.3s;
}

.move-timer-bar.warning {
    background: var(--accent-gold);
}

.move-timer-bar.critical {
    background: var(--accent-crimson);
}

/* Captured Pieces */
.captured-tray {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    min-height: 24px;
}

.mini-captured-piece {
    width: 22px;
    height: 22px;
    opacity: 0.85;
    filter: drop-shadow(0 2px 3px rgba(0,0,0,0.4));
}

/* Match Status Banner in Middle of Left Panel */
.match-status-banner {
    background: rgba(15, 23, 42, 0.75);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.turn-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    font-weight: 600;
}

.turn-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    box-shadow: 0 0 8px currentColor;
}

.turn-dot.white {
    background-color: #ffffff;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.8);
}

.turn-dot.black {
    background-color: #0f172a;
    border: 2px solid #64748b;
    box-shadow: 0 0 8px rgba(100, 116, 139, 0.6);
}

.check-badge {
    background: rgba(239, 68, 68, 0.2);
    color: var(--accent-crimson);
    border: 1px solid rgba(239, 68, 68, 0.4);
    font-size: 10px;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: auto;
    animation: checkBlink 0.7s infinite alternate;
}

@keyframes checkBlink {
    from { opacity: 0.7; }
    to { opacity: 1; filter: drop-shadow(0 0 6px rgba(239, 68, 68, 0.8)); }
}

.match-meta {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ==========================================================================
   Center Panel: The Chess Board
   ========================================================================== */
.panel-board {
    padding: 12px;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.board-frame {
    width: 100%;
    max-width: 620px;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chess-board-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: var(--radius-md);
    padding: 12px; /* Sleek bezel without text clutter */
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6), inset 0 0 0 1px rgba(255, 255, 255, 0.1);
    background: #090e1b;
    transition: background 0.3s;
}

/* Board Themes */
/* Signature Theme: Black & Blue (Color Psychology: High Contrast, Strategic Calm & Focus) */
.blue-theme {
    background: #090e1b;
    border: 2px solid rgba(56, 189, 248, 0.35);
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.8), 0 0 35px rgba(14, 165, 233, 0.25), inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}
.blue-theme .square.light {
    background-color: #b8d4f0; /* Frosted Glacial Blue: reduces cognitive fatigue while ensuring high contrast */
}
.blue-theme .square.dark {
    background-color: #1e3352; /* Deep Obsidian Cobalt: anchors the board with calm luxury and zero glare */
}
.blue-theme .board-coords {
    color: rgba(184, 212, 240, 0.7);
}
.blue-theme .square.highlight-selected {
    background-color: rgba(0, 229, 255, 0.42) !important;
    box-shadow: inset 0 0 0 3px #00e5ff, 0 0 18px rgba(0, 229, 255, 0.6) !important;
}
.blue-theme .square.highlight-last-move {
    background-color: rgba(14, 165, 233, 0.35) !important;
    box-shadow: inset 0 0 0 2px rgba(56, 189, 248, 0.6) !important;
}
.blue-theme .legal-dot {
    background: rgba(14, 165, 233, 0.75);
    box-shadow: 0 0 10px rgba(14, 165, 233, 0.6);
}
.blue-theme .capture-ring {
    border: 4px solid rgba(14, 165, 233, 0.8);
    box-shadow: 0 0 14px rgba(14, 165, 233, 0.6);
}

/* 1. Emerald (Classic Tournament) */
.emerald-theme {
    background: #1b263b;
}
.emerald-theme .square.light {
    background-color: #eeeed2;
}
.emerald-theme .square.dark {
    background-color: #769656;
}

/* 2. Classic Walnut Wood */
.wood-theme {
    background: #2b1f14;
}
.wood-theme .square.light {
    background-color: #f0d9b5;
}
.wood-theme .square.dark {
    background-color: #b58863;
}

/* 3. Cyber Midnight */
.cyber-theme {
    background: #0b132b;
}
.cyber-theme .square.light {
    background-color: #d1d5db;
}
.cyber-theme .square.dark {
    background-color: #374151;
}

/* 4. Obsidian Gold */
.obsidian-theme {
    background: #18181b;
}
.obsidian-theme .square.light {
    background-color: #e4e4e7;
}
.obsidian-theme .square.dark {
    background-color: #52525b;
}

.chess-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 100%;
    height: 100%;
    border-radius: 6px;
    overflow: hidden;
    position: relative;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.square {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    touch-action: none;
}

/* Condition 1: No text show on board */
.board-coords {
    display: none !important;
}

.btn.active-hint-btn {
    background: rgba(56, 189, 248, 0.15);
    border-color: rgba(56, 189, 248, 0.4);
    color: var(--accent-cyan);
}

.btn.hint-disabled {
    opacity: 0.7;
    color: var(--text-muted);
    border-color: rgba(255, 255, 255, 0.08);
}

/* Chess Pieces */
.chess-piece {
    width: 86%;
    height: 86%;
    object-fit: contain;
    z-index: 2;
    transition: transform 0.15s ease-out;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.35));
    pointer-events: none;
}

.chess-piece-ghost {
    position: fixed;
    z-index: 1000;
    pointer-events: none;
    opacity: 0.95;
    transform: scale(1.12);
    filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.6));
}

/* Move & State Highlights */
.square.highlight-selected {
    box-shadow: inset 0 0 0 3px var(--accent-cyan);
    background-color: rgba(56, 189, 248, 0.3) !important;
}

.square.highlight-last-move {
    background-color: rgba(245, 158, 11, 0.32) !important;
}

.square.highlight-check {
    background: radial-gradient(circle, rgba(239, 68, 68, 0.85) 0%, rgba(239, 68, 68, 0.25) 85%) !important;
    box-shadow: inset 0 0 10px rgba(239, 68, 68, 0.9);
    animation: pulseCheck 1s infinite alternate ease-in-out;
}

@keyframes pulseCheck {
    from { box-shadow: inset 0 0 6px rgba(239, 68, 68, 0.6); }
    to { box-shadow: inset 0 0 14px rgba(239, 68, 68, 1); }
}

/* Legal Move Dot Marker */
.legal-dot {
    width: 28%;
    height: 28%;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.25);
    z-index: 3;
    pointer-events: none;
    transition: transform 0.15s;
}

.square:hover .legal-dot {
    transform: scale(1.2);
    background: rgba(0, 0, 0, 0.35);
}

/* Capture Target Ring */
.capture-ring {
    position: absolute;
    width: 85%;
    height: 85%;
    border-radius: 50%;
    border: 4px solid rgba(0, 0, 0, 0.3);
    z-index: 3;
    pointer-events: none;
    box-sizing: border-box;
}

.square:hover .capture-ring {
    border-color: rgba(239, 68, 68, 0.6);
}

/* Historical Review Notice (Inside Sidebar Move History Panel - NOT on board) */
.history-view-banner {
    background: rgba(245, 158, 11, 0.15);
    border: 1px solid rgba(245, 158, 11, 0.4);
    color: var(--accent-gold);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.btn-live {
    background: var(--accent-gold);
    color: #0f172a;
    border: none;
    padding: 5px 12px;
    font-size: 11px;
    font-weight: 800;
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-live:hover {
    background: #fbbf24;
    transform: scale(1.05);
}

/* Pawn Promotion Selector (Pure Piece Icons, Zero Text) */
.promotion-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(9, 14, 27, 0.96);
    backdrop-filter: blur(20px);
    border: 2px solid rgba(56, 189, 248, 0.5);
    border-radius: var(--radius-md);
    padding: 8px;
    z-index: 100;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.8), 0 0 25px rgba(56, 189, 248, 0.3);
}

.promotion-modal.hidden {
    display: none !important;
}

.promotion-pieces {
    display: flex;
    gap: 8px;
}

.promotion-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--radius-sm);
    padding: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    width: 58px;
    height: 58px;
}

.promotion-btn:hover {
    background: rgba(56, 189, 248, 0.25);
    border-color: var(--accent-cyan);
    transform: scale(1.1);
    box-shadow: 0 0 16px rgba(56, 189, 248, 0.5);
}

.promotion-btn img {
    width: 46px;
    height: 46px;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.5));
}

/* ==========================================================================
   Right Panel: Move History & Controls
   ========================================================================== */
.panel-moves {
    gap: 14px;
    height: 100%;
    max-height: 680px;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.panel-header h3 {
    font-family: var(--font-heading);
    font-size: 16px;
    font-weight: 700;
}

.badge {
    font-size: 11px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 6px;
}

.badge-accent {
    background: rgba(56, 189, 248, 0.12);
    color: var(--accent-cyan);
    border: 1px solid rgba(56, 189, 248, 0.25);
}

.move-list-wrapper {
    flex: 1;
    overflow-y: auto;
    background: #060911;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-sm);
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.move-row {
    display: grid;
    grid-template-columns: 36px 1fr 1fr;
    align-items: center;
    padding: 4px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 13px;
}

.move-row:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

.move-num {
    color: var(--text-muted);
    font-size: 11px;
}

.move-item {
    background: none;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 13px;
    padding: 4px 8px;
    border-radius: 4px;
    text-align: left;
    cursor: pointer;
    transition: all 0.15s;
}

.move-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.move-item.selected,
.move-item.latest-move {
    background: rgba(56, 189, 248, 0.22);
    color: var(--accent-cyan);
    font-weight: 700;
    box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.45);
}

.in-game-actions {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
}

/* Desktop: move Resign button slightly farther outside the chessboard area while keeping it fully visible and aligned */
@media (min-width: 901px) {
    .in-game-actions {
        display: flex;
        gap: 8px;
    }
    #btnUndoMove,
    #btnOfferDraw {
        flex: 1;
    }
    #btnResign {
        flex: 1;
        margin-left: 10px;
    }
}

/* ==========================================================================
   Modals
   ========================================================================== */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(4, 7, 14, 0.8);
    backdrop-filter: blur(12px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    transition: opacity 0.2s;
}

.hidden,
.modal-backdrop.hidden,
.history-view-banner.hidden {
    display: none !important;
}

.modal-card {
    background: #0f172a;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
    width: 100%;
    animation: modalScaleUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalScaleUp {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.setup-modal-card {
    max-width: 540px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.modal-header h2 {
    font-family: var(--font-heading);
    font-size: 18px;
    font-weight: 700;
}

.modal-close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
}

.modal-close-btn:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 20px 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.setup-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.section-heading {
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
}

.sub-heading {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}

.section-hint {
    font-size: 11px;
    color: var(--text-muted);
}

.player-input-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.input-group label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
}

.input-group input,
.styled-select {
    background: #070b14;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
}

.input-group input:focus,
.styled-select:focus {
    border-color: var(--accent-cyan);
}

/* Switch Toggle */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.12);
    border-radius: 24px;
    transition: 0.25s;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.slider::before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    border-radius: 50%;
    transition: 0.25s;
}

input:checked + .slider {
    background-color: var(--accent-cyan);
}

input:checked + .slider::before {
    transform: translateX(22px);
}

/* Timer Config Panel */
.timer-config-panel {
    background: rgba(7, 11, 20, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-md);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

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

.theme-buttons {
    grid-template-columns: repeat(2, 1fr);
}

.preset-btn,
.theme-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.preset-btn:hover,
.theme-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.preset-btn.active,
.theme-btn.active {
    background: rgba(56, 189, 248, 0.15);
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
}

.timer-mode-select-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.compact-select {
    width: 100%;
    height: 38px;
    padding: 8px 34px 8px 12px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    background-color: #070b14;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

.compact-select:focus {
    border-color: var(--accent-cyan);
}

.compact-select option {
    background-color: #0f172a;
    color: var(--text-primary);
    padding: 8px 10px;
    font-size: 13px;
}

.timer-inputs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(125px, 1fr));
    gap: 10px;
}

/* Alert Modal */
.alert-modal-card {
    max-width: 420px;
    padding: 24px;
    text-align: center;
}

.alert-modal-card h3 {
    font-family: var(--font-heading);
    font-size: 18px;
    margin-bottom: 8px;
}

.alert-modal-card p {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.5;
}

.modal-actions-row {
    display: flex;
    justify-content: center;
    gap: 12px;
}

/* Game Over Modal */
.game-over-card {
    max-width: 460px;
    padding: 30px;
    text-align: center;
}

.trophy-badge {
    font-size: 54px;
    margin-bottom: 8px;
    filter: drop-shadow(0 6px 12px rgba(245, 158, 11, 0.4));
}

.game-over-card h2 {
    font-family: var(--font-heading);
    font-size: 24px;
    font-weight: 800;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.game-over-desc {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.game-over-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    background: #070b14;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-md);
    padding: 14px;
    margin-bottom: 24px;
}

.stat-box {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-label {
    font-size: 10px;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--text-muted);
}

.stat-value {
    font-family: var(--font-mono);
    font-size: 15px;
    font-weight: 700;
    color: var(--accent-cyan);
}

/* ==========================================================================
   Desktop / Mobile Visibility Helpers
   ========================================================================== */
.mobile-only-btn {
    display: none !important;
}

.mobile-controls-bar {
    display: none !important;
}

#mobileMenuModal {
    display: none;
}

.mobile-header-actions,
.mob-header-btn,
.exit-fullscreen-btn {
    display: none !important;
}

/* ==========================================================================
   Tablet Responsive Adaptations (901px to 1100px)
   ========================================================================== */
@media (max-width: 1100px) and (min-width: 901px) {
    .arena-layout {
        grid-template-columns: 260px 1fr 240px;
        gap: 14px;
    }
}

/* ==========================================================================
   Mobile Full Experience Architecture (<= 900px)
   Layout:
   [Compact Header + Settings]
   [Black Player Name + Black Timer]
   [CHESSBOARD]
   [White Player Name + White Timer]
   [Compact Essential Controls]
   [Expandable Additional Options]
   ========================================================================== */
@media (max-width: 900px) {
    /* Hide desktop-only controls and reveal mobile controls */
    .desktop-only-actions {
        display: none !important;
    }

    .mobile-header-actions {
        display: flex !important;
        align-items: center;
        gap: 6px;
    }

    .mob-header-btn {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        border-radius: var(--radius-sm);
        padding: 0;
        background: rgba(255, 255, 255, 0.08);
        border: 1px solid rgba(255, 255, 255, 0.12);
        color: var(--text-primary);
        font-size: 15px;
        cursor: pointer;
        touch-action: manipulation;
        transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    }

    .mob-header-btn:hover,
    .mob-header-btn:active {
        background: rgba(56, 189, 248, 0.2);
        border-color: var(--accent-cyan);
        color: var(--accent-cyan);
    }

    .mobile-only-btn {
        display: inline-flex !important;
    }

    #mobileMenuModal:not(.hidden) {
        display: flex !important;
    }

    /* Mobile Full Screen / Focus Mode: Only Board and Timers Visible */
    .game-container.fullscreen-focus {
        padding: max(4px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
        justify-content: center;
        overflow: hidden;
    }

    .game-container.fullscreen-focus .app-header {
        display: none !important;
    }

    .game-container.fullscreen-focus .mobile-controls-bar {
        display: none !important;
    }

    .game-container.fullscreen-focus .panel-moves {
        display: none !important;
    }

    .game-container.fullscreen-focus .arena-layout {
        justify-content: center;
        gap: 8px;
        height: 100%;
        max-height: 100%;
    }

    .game-container.fullscreen-focus .panel-board {
        max-width: min(calc(100vw - 8px), calc(100dvh - 105px), 600px);
        margin: 0 auto;
    }

    .game-container.fullscreen-focus .player-card {
        max-width: min(calc(100vw - 8px), calc(100dvh - 105px), 600px);
        margin: 0 auto;
        padding: 5px 12px;
        min-height: 44px;
    }

    .exit-fullscreen-btn {
        display: none;
        position: fixed;
        top: max(8px, env(safe-area-inset-top));
        right: max(8px, env(safe-area-inset-right));
        z-index: 1000;
        align-items: center;
        gap: 6px;
        background: rgba(15, 23, 42, 0.92);
        backdrop-filter: blur(16px);
        border: 1px solid rgba(56, 189, 248, 0.45);
        color: var(--accent-cyan);
        font-family: var(--font-ui);
        font-size: 11px;
        font-weight: 700;
        padding: 6px 14px;
        border-radius: 20px;
        cursor: pointer;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.75), 0 0 14px rgba(56, 189, 248, 0.3);
        touch-action: manipulation;
        transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    }

    .exit-fullscreen-btn:hover,
    .exit-fullscreen-btn:active {
        background: rgba(14, 165, 233, 0.25);
        border-color: var(--accent-cyan);
        color: #ffffff;
        transform: scale(1.04);
    }

    .game-container.fullscreen-focus .exit-fullscreen-btn {
        display: flex !important;
    }

    /* Container & Header */
    .game-container {
        padding: max(4px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
        gap: 4px;
        min-height: 100dvh;
        height: 100dvh;
        max-height: 100dvh;
        max-width: 100%;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        overflow-x: hidden;
        overflow-y: auto;
    }

    .app-header {
        padding: 4px 10px;
        gap: 8px;
        min-height: 38px;
        margin-bottom: 0;
        border-radius: var(--radius-sm);
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-shrink: 0;
    }

    .brand {
        gap: 8px;
    }

    .brand-logo {
        width: 30px;
        height: 30px;
    }

    .logo-icon {
        font-size: 16px;
    }

    .brand-text h1 {
        font-size: 15px;
        letter-spacing: 0.3px;
    }

    .brand-text h1 span {
        font-size: 12px;
        padding: 1px 5px;
    }

    .brand-text .tagline {
        display: none;
    }

    /* Vertical Hierarchy on Mobile */
    .arena-layout {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        width: 100%;
        margin: 0 auto;
        gap: 4px;
    }

    .arena-layout.moves-hidden {
        justify-content: center;
        gap: 6px;
    }

    .arena-layout.moves-hidden .panel-moves {
        display: none !important;
        margin: 0 !important;
        padding: 0 !important;
        height: 0 !important;
        max-height: 0 !important;
        overflow: hidden !important;
    }

    /* Unwrap players container so Black & White cards are independent flex items */
    .panel-players {
        display: contents !important;
    }

    /* Standard Orientation: Black on Top, White on Bottom */
    #blackPlayerCard {
        order: 1;
    }

    .panel-board {
        order: 2;
    }

    #whitePlayerCard {
        order: 3;
    }

    .mobile-controls-bar {
        order: 4;
    }

    .panel-moves {
        order: 5;
    }

    .match-status-banner {
        display: none !important;
    }

    /* Auto-Flip Orientation: White on Top, Black on Bottom */
    .arena-layout.orientation-black #whitePlayerCard {
        order: 1;
    }

    .arena-layout.orientation-black .panel-board {
        order: 2;
    }

    .arena-layout.orientation-black #blackPlayerCard {
        order: 3;
    }

    .arena-layout.orientation-black .mobile-controls-bar {
        order: 4;
    }

    .arena-layout.orientation-black .panel-moves {
        order: 5;
    }

    /* Symmetrical Mobile Player Bars */
    .player-card {
        width: 100%;
        max-width: min(calc(100vw - 12px), 520px, calc(100dvh - 190px));
        margin: 0 auto;
        box-sizing: border-box;
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 4px 10px;
        min-height: 42px;
        border-radius: var(--radius-sm);
        background: rgba(15, 23, 42, 0.75);
        backdrop-filter: blur(14px);
        border: 1px solid rgba(255, 255, 255, 0.08);
        transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
        gap: 6px;
        flex-shrink: 0;
    }

    .player-header {
        display: flex;
        align-items: center;
        gap: 8px;
        flex: 1;
        min-width: 0;
        overflow: hidden;
    }

    .player-avatar {
        width: 30px;
        height: 30px;
        font-size: 16px;
        border-radius: 6px;
        flex-shrink: 0;
    }

    .player-info {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 6px;
        min-width: 0;
        overflow: hidden;
    }

    .player-role {
        display: none;
    }

    .player-name {
        font-size: 13px;
        font-weight: 700;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 130px;
        color: var(--text-primary);
    }

    .score-diff {
        font-size: 10px;
        padding: 1px 5px;
        border-radius: 4px;
        flex-shrink: 0;
    }

    .captured-tray {
        display: flex;
        align-items: center;
        gap: 1px;
        min-height: auto;
        margin-left: 4px;
        overflow: hidden;
    }

    .mini-captured-piece {
        width: 16px;
        height: 16px;
    }

    /* Timers: Aligned, readable countdown without taking excessive space */
    .clock-container {
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        justify-content: center;
        gap: 2px;
        padding: 0;
        background: transparent;
        border: none;
        overflow: visible;
        flex-shrink: 0;
    }

    .clock-display-wrap {
        display: flex;
        align-items: center;
        gap: 6px;
    }

    .digital-clock {
        font-size: 18px;
        font-weight: 800;
        font-family: var(--font-mono);
        padding: 2px 8px;
        border-radius: 6px;
        background: rgba(7, 11, 20, 0.9);
        border: 1px solid rgba(255, 255, 255, 0.12);
        color: var(--text-primary);
        line-height: 1.2;
        letter-spacing: 0.5px;
        min-width: 66px;
        text-align: center;
    }

    .shot-clock-badge {
        font-size: 11px;
        padding: 2px 5px;
    }

    .move-timer-track {
        width: 100%;
        height: 3px;
        margin-top: 2px;
        background: rgba(255, 255, 255, 0.08);
        border-radius: 2px;
    }

    /* Turn Highlights */
    .player-card.active-turn {
        border-color: rgba(56, 189, 248, 0.65);
        background: rgba(14, 165, 233, 0.1);
        box-shadow: 0 0 16px rgba(56, 189, 248, 0.25);
        opacity: 1;
    }

    .player-card.active-turn .digital-clock {
        border-color: rgba(56, 189, 248, 0.6);
        color: #ffffff;
        text-shadow: 0 0 8px rgba(56, 189, 248, 0.5);
    }

    .player-card:not(.active-turn) {
        opacity: 0.82;
        border-color: rgba(255, 255, 255, 0.06);
    }

    /* Symmetrical Center Chessboard - Maximized */
    .panel-board {
        padding: 0;
        margin: 0 auto;
        width: 100%;
        max-width: min(calc(100vw - 12px), 520px, calc(100dvh - 190px));
        background: transparent;
        border: none;
        box-shadow: none;
        display: flex;
        align-items: center;
        justify-content: center;
        box-sizing: border-box;
        flex-shrink: 0;
    }

    .board-frame {
        width: 100%;
        max-width: 100%;
        aspect-ratio: 1 / 1;
        margin: 0 auto;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .chess-board-wrapper {
        width: 100%;
        height: 100%;
        padding: 4px;
        box-sizing: border-box;
        border-radius: var(--radius-sm);
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
    }

    /* Compact Essential Controls Bar */
    .mobile-controls-bar {
        width: 100%;
        max-width: min(calc(100vw - 12px), 520px, calc(100dvh - 190px));
        margin: 0 auto;
        display: grid !important;
        grid-template-columns: repeat(5, 1fr);
        gap: 4px;
        box-sizing: border-box;
        flex-shrink: 0;
    }

    .mob-btn {
        background: rgba(15, 23, 42, 0.7);
        border: 1px solid rgba(255, 255, 255, 0.08);
        border-radius: var(--radius-sm);
        color: var(--text-secondary);
        padding: 5px 3px;
        font-family: var(--font-ui);
        font-size: 11px;
        font-weight: 600;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        cursor: pointer;
        transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
        min-height: 42px;
        touch-action: manipulation;
    }

    .mob-btn:hover,
    .mob-btn:active {
        background: rgba(255, 255, 255, 0.1);
        color: var(--text-primary);
        border-color: rgba(255, 255, 255, 0.2);
    }

    .mob-btn.active {
        background: rgba(56, 189, 248, 0.18);
        border-color: var(--accent-cyan);
        color: var(--accent-cyan);
    }

    .mob-btn-primary {
        background: linear-gradient(135deg, rgba(2, 132, 199, 0.4), rgba(3, 105, 161, 0.3));
        border-color: rgba(56, 189, 248, 0.35);
        color: #ffffff;
    }

    .mob-icon {
        font-size: 15px;
        line-height: 1;
    }

    .mob-label {
        font-size: 10px;
        font-weight: 700;
        letter-spacing: 0.2px;
    }

    /* Move History Panel - Intelligent vertical expansion */
    .panel-moves {
        width: 100%;
        max-width: min(calc(100vw - 12px), 520px, calc(100dvh - 190px));
        margin: 0 auto;
        padding: 6px 10px;
        border-radius: var(--radius-sm);
        box-sizing: border-box;
        background: rgba(15, 23, 42, 0.7);
        border: 1px solid rgba(255, 255, 255, 0.08);
        display: flex !important;
        flex-direction: column;
        flex: 1 1 0;
        min-height: 70px;
        max-height: 100%;
        overflow: hidden;
    }

    .panel-moves .panel-header {
        padding-bottom: 4px;
        margin-bottom: 4px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.06);
        flex-shrink: 0;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .panel-moves .panel-header h3 {
        font-size: 12px;
        letter-spacing: 0.3px;
    }

    .panel-moves .badge {
        font-size: 10px;
        padding: 1px 6px;
    }

    .panel-moves .history-view-banner {
        margin-bottom: 4px;
        padding: 4px 8px;
        font-size: 11px;
        flex-shrink: 0;
    }

    .panel-moves .move-list-wrapper {
        flex: 1;
        min-height: 35px;
        max-height: 100%;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        background: rgba(6, 9, 17, 0.6);
        padding: 4px 6px;
        gap: 1px;
    }

    .panel-moves .move-row {
        padding: 2px 4px;
        font-size: 12px;
        grid-template-columns: 28px 1fr 1fr;
    }

    .panel-moves .move-item {
        font-size: 12px;
        padding: 2px 6px;
        min-height: 28px;
    }

    .panel-moves .in-game-actions {
        display: none !important;
    }

    /* Mobile Menu Modal / Action Sheet */
    .mobile-menu-card {
        max-width: min(440px, calc(100vw - 24px));
        border-radius: var(--radius-lg);
        background: #0f172a;
        border: 1px solid rgba(255, 255, 255, 0.12);
        box-shadow: 0 20px 50px rgba(0, 0, 0, 0.85);
    }

    .mobile-menu-body {
        padding: 16px 20px;
        display: flex;
        flex-direction: column;
        gap: 16px;
    }

    .mobile-menu-section {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .mobile-actions-grid {
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
        gap: 8px;
    }

    .mobile-actions-grid .btn {
        padding: 10px 6px;
        font-size: 12px;
        min-height: 44px;
        justify-content: center;
    }

    .mobile-options-list {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .mobile-options-list .btn {
        justify-content: flex-start;
        padding: 11px 14px;
        min-height: 44px;
        font-size: 13px;
    }

    /* Modals Responsive Behavior */
    .modal-backdrop {
        padding: 8px;
    }

    .modal-card {
        max-width: min(540px, calc(100vw - 16px));
        max-height: 94vh;
        border-radius: var(--radius-md);
    }

    .modal-header {
        padding: 12px 16px;
    }

    .modal-header h2 {
        font-size: 16px;
    }

    .modal-body {
        padding: 14px 16px;
        gap: 14px;
        max-height: 75vh;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .modal-footer {
        padding: 12px 16px;
    }

    .preset-buttons {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
    }

    .preset-btn {
        padding: 7px 6px;
        font-size: 11px;
    }

    .theme-buttons {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
    }

    .theme-btn {
        padding: 7px 6px;
        font-size: 11px;
    }

    .player-input-row {
        gap: 8px;
    }

    .timer-inputs-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }
}

/* ==========================================================================
   Small Mobile Screens (<= 360px)
   ========================================================================== */
@media (max-width: 360px) {
    .game-container {
        padding: max(2px, env(safe-area-inset-top)) max(4px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left));
        gap: 2px;
    }

    .arena-layout {
        gap: 2px;
    }

    .panel-board,
    .player-card,
    .mobile-controls-bar,
    .panel-moves {
        max-width: min(calc(100vw - 8px), 520px);
    }

    .player-card {
        padding: 2px 6px;
        min-height: 38px;
    }

    .player-avatar {
        width: 26px;
        height: 26px;
        font-size: 14px;
    }

    .player-name {
        max-width: 85px;
        font-size: 11px;
    }

    .digital-clock {
        font-size: 16px;
        padding: 2px 5px;
        min-width: 58px;
    }

    .mob-btn {
        min-height: 38px;
        padding: 3px 2px;
    }

    .mob-label {
        font-size: 8.5px;
    }

    .mob-icon {
        font-size: 13px;
    }

    .mobile-controls-bar {
        gap: 3px;
    }

    .player-input-row {
        grid-template-columns: 1fr;
    }
}

/* ==========================================================================
   Mobile Landscape Support
   ========================================================================== */
@media (max-height: 520px) and (orientation: landscape) {
    .game-container {
        padding: max(2px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
        min-height: 100dvh;
        height: 100dvh;
        max-height: 100dvh;
        gap: 2px;
    }

    .app-header {
        padding: 2px 8px;
        min-height: 30px;
    }

    .arena-layout {
        display: grid !important;
        grid-template-columns: minmax(150px, 195px) 1fr minmax(150px, 195px);
        gap: 6px;
        align-items: center;
        flex-direction: row !important;
        height: calc(100% - 34px);
    }

    .panel-players {
        display: flex !important;
        flex-direction: column;
        gap: 6px;
        order: 1 !important;
        max-height: 90vh;
        justify-content: center;
    }

    .panel-players .player-card {
        padding: 3px 6px !important;
        min-height: 36px !important;
        gap: 4px !important;
    }

    .panel-players .player-avatar {
        width: 24px !important;
        height: 24px !important;
        font-size: 13px !important;
    }

    .panel-players .player-name {
        font-size: 11px !important;
        max-width: 80px !important;
    }

    .panel-players .digital-clock {
        font-size: 15px !important;
        padding: 2px 5px !important;
        min-width: 52px !important;
    }

    #blackPlayerCard {
        order: 1 !important;
        max-width: 100% !important;
    }

    #whitePlayerCard {
        order: 2 !important;
        max-width: 100% !important;
    }

    .panel-board {
        order: 2 !important;
        max-height: 90vh;
        max-width: min(85vh, 400px) !important;
    }

    .board-frame {
        max-width: min(85vh, 400px);
    }

    .panel-moves {
        display: flex !important;
        flex-direction: column;
        order: 3 !important;
        max-height: 90vh;
        max-width: 100% !important;
        flex: 1;
    }

    .mobile-controls-bar {
        display: none !important;
    }
}
