/* =============================================================================
   AETHER CHESS — DESIGN SYSTEM & THEME TOKENS
   Modern, portfolio-grade chess platform.
   Original visual identity: Clean obsidian & teal aesthetic, 8pt spacing grid,
   accessible contrast, dark/light themes, and selectable board palettes.
   ============================================================================= */

/* ---------- Core Design System (Dark Theme Default) ---------- */
:root {
    --bg-base:          #2d2a27;
    --bg-surface-1:     #262522;
    --bg-surface-2:     #2f2c2a;
    --bg-surface-3:     #393530;
    --bg-elevated:      #201e1c;

    --border-subtle:    rgba(255, 255, 255, 0.06);
    --border-default:   rgba(255, 255, 255, 0.12);
    --border-strong:    rgba(255, 255, 255, 0.18);

    --text-primary:     #f3f1ee;
    --text-secondary:   #c3c2c1;
    --text-muted:       #989795;
    --text-inverse:     #121110;

    --accent:           #81b64c;
    --accent-hover:     #93c75d;
    --accent-active:    #5c8a36;
    --accent-subtle:    rgba(129, 182, 76, 0.14);
    --accent-ring:      rgba(129, 182, 76, 0.32);

    --color-green:      #81b64c;
    --color-green-hover:#94c95e;
    --color-green-subtle:rgba(129, 182, 76, 0.15);

    --color-amber:      #f1c26f;
    --color-amber-subtle:rgba(241, 194, 111, 0.12);

    --color-red:        #d9544d;
    --color-red-hover:  #ef6b62;
    --color-red-subtle: rgba(217, 84, 77, 0.12);

    --color-purple:     #c7b0f6;
    --color-purple-subtle:rgba(199, 176, 246, 0.12);

    --sq-light:         #f0efe9;
    --sq-dark:          #7a9a58;
    --hl-last-light:    rgba(129, 182, 76, 0.28);
    --hl-last-dark:     rgba(129, 182, 76, 0.28);

    /* Evaluation bar: fixed piece colours stay legible in both themes. */
    --eval-white:       #ffffff;
    --eval-black:       #1b1a18;

    --space-1:          4px;
    --space-2:          8px;
    --space-3:          12px;
    --space-4:          16px;
    --space-5:          24px;
    --space-6:          32px;
    --space-7:          48px;
    --space-8:          64px;

    --radius-xs:        4px;
    --radius-sm:        8px;
    --radius-md:        12px;
    --radius-lg:        16px;
    --radius-full:      9999px;

    --shadow-xs:        0 1px 2px rgba(0, 0, 0, 0.15);
    --shadow-sm:        0 2px 6px rgba(0, 0, 0, 0.24);
    --shadow-md:        0 8px 18px rgba(0, 0, 0, 0.26);
    --shadow-lg:        0 18px 36px rgba(0, 0, 0, 0.34);

    --font-family:      'Noto Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-size-xs:     11px;
    --font-size-sm:     13px;
    --font-size-base:   14px;
    --font-size-md:     16px;
    --font-size-lg:     18px;
    --font-size-xl:     22px;
    --font-size-xxl:    28px;

    --board:            640px;
    --panel-w:          400px;
    --sidebar-w:        200px;
}

/* ---------- Light Theme System ---------- */
[data-theme="light"] {
    --bg-base:          #f4f6f8;
    --bg-surface-1:     #ffffff;
    --bg-surface-2:     #f8fafc;
    --bg-surface-3:     #eef2f6;
    --bg-elevated:      #ffffff;

    --border-subtle:    rgba(0, 0, 0, 0.06);
    --border-default:   rgba(0, 0, 0, 0.12);
    --border-strong:    rgba(0, 0, 0, 0.22);

    --text-primary:     #0f172a;
    --text-secondary:   #475569;
    --text-muted:       #94a3b8;
    --text-inverse:     #ffffff;

    --accent:           #0284c7;
    --accent-hover:     #0369a1;
    --accent-active:    #075985;
    --accent-subtle:    rgba(2, 132, 199, 0.10);
    --accent-ring:      rgba(2, 132, 199, 0.30);

    --sq-light:         #f1f5f9;
    --sq-dark:          #475569;
    --hl-last-light:    rgba(2, 132, 199, 0.30);
    --hl-last-dark:     rgba(2, 132, 199, 0.45);

    /* Evaluation bar: fixed piece colours stay legible in both themes. */
    --eval-white:       #ffffff;
    --eval-black:       #262522;

    --shadow-xs:        0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-sm:        0 2px 6px rgba(0, 0, 0, 0.08);
    --shadow-md:        0 6px 18px rgba(0, 0, 0, 0.12);
    --shadow-lg:        0 12px 32px rgba(0, 0, 0, 0.16);
}

/* ---------- Selectable Board Color Palettes ---------- */
[data-board-theme="emerald"] {
    --sq-light: #e2e8f0;
    --sq-dark:  #047857;
}

[data-board-theme="walnut"] {
    --sq-light: #f5ebe0;
    --sq-dark:  #b08968;
}

[data-board-theme="midnight"] {
    --sq-light: #cbd5e1;
    --sq-dark:  #1e293b;
}

[data-board-theme="classic"] {
    --sq-light: #eeeed2;
    --sq-dark:  #769656;
}

/* ---------- Global CSS Reset ---------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background: var(--bg-base);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: 1.5;
    overflow: hidden;
    transition: background 0.25s ease, color 0.25s ease;
}

body, button, input, select {
    letter-spacing: -0.01em;
}

button, input, select, textarea {
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    color: inherit;
}

button {
    cursor: pointer;
    background: none;
    border: none;
}

a {
    color: inherit;
    text-decoration: none;
}

/* Accessible focus ring */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
:focus:not(:focus-visible) {
    outline: none;
}

/* =============================================================================
   APP LAYOUT
   ============================================================================= */
.app {
    display: flex;
    width: 100%;
    height: 100vh;
    background: var(--bg-base);
}

/* ---------- Sidebar Navigation ---------- */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: linear-gradient(180deg, rgba(38, 37, 34, 0.98), rgba(32, 30, 28, 0.98));
    display: flex;
    flex-direction: column;
    padding: 18px 12px 16px;
    border-right: 1px solid rgba(255,255,255,0.04);
    user-select: none;
    box-shadow: inset -1px 0 0 rgba(255,255,255,0.02);
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) var(--space-3) var(--space-4);
    font-weight: 700;
    font-size: 19px;
    letter-spacing: -0.4px;
    color: var(--text-primary);
}

.logo-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-subtle);
    border: 1px solid var(--accent-ring);
    border-radius: var(--radius-sm);
    color: var(--accent);
}

.logo-icon svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.logo-badge {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 1px 5px;
    background: var(--accent-subtle);
    color: var(--accent);
    border-radius: var(--radius-xs);
    border: 1px solid var(--accent-ring);
    margin-left: 2px;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.nav a,
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease, transform 0.12s ease;
    letter-spacing: -0.02em;
}

.nav a i,
.nav-item i {
    font-size: 19px;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
    color: inherit;
    opacity: 0.8;
}

.nav a:hover,
.nav-item:hover {
    background: var(--bg-surface-3);
    color: var(--text-primary);
}

.nav a:hover i,
.nav-item:hover i { opacity: 1; }

.nav a.active,
.nav-item.active {
    background: rgba(129, 182, 76, 0.08);
    color: var(--accent);
    border-left: 3px solid var(--accent);
    padding-left: 9px;
    box-shadow: inset 0 0 0 1px rgba(129, 182, 76, 0.08);
}

.nav a.active i,
.nav-item.active i { opacity: 1; }

.side-spacer {
    flex: 1;
    min-height: var(--space-3);
}

/* Sidebar Theme Toggle & Action Controls */
.side-theme-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-2);
    border-radius: var(--radius-sm);
    background: var(--bg-surface-2);
    border: 1px solid var(--border-subtle);
}

.theme-toggle-label {
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.theme-switch-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-xs);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface-3);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    transition: background 0.15s, color 0.15s, transform 0.1s;
}

.theme-switch-btn:hover {
    background: var(--accent-subtle);
    color: var(--accent);
}

.theme-switch-btn:active { transform: scale(0.95); }

.side-user {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    font-weight: 600;
    font-size: var(--font-size-sm);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    background: var(--bg-surface-2);
    border: 1px solid var(--border-subtle);
    cursor: pointer;
}

.side-user .mini-avatar {
    width: 26px;
    height: 26px;
    border-radius: var(--radius-xs);
    background: var(--accent-subtle);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.side-user span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* =============================================================================
   MAIN CANVAS & SCREENS
   ============================================================================= */
.main {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: stretch;
    justify-content: center;
    padding: 14px 18px 18px 0;
    background: var(--bg-base);
}

/* ---------- Setup Screen ---------- */
.setup-screen {
    display: none;
    align-items: center;
    justify-content: center;
    width: 100%;
}
.setup-screen.active { display: flex; }

.setup-card {
    width: 520px;
    max-width: 95vw;
    max-height: calc(100vh - 30px);
}

.setup-body {
    max-height: calc(100vh - var(--space-6) - 76px);
    overflow-y: auto;
    overflow-x: hidden;
}

.setup-body::-webkit-scrollbar { width: 6px; }
.setup-body::-webkit-scrollbar-thumb {
    background: var(--bg-surface-3);
    border-radius: var(--radius-full);
}

/* ---------- Game Screen Layout ---------- */
.game-screen {
    display: none;
    width: 100%;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 8px 8px 8px 12px;
}
.game-screen.active { display: flex; }

/* ---------- Board Stack & Evaluation Bar ---------- */
.board-area {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

/* Evaluation Bar — narrow vertical bar + score column, board height */
.eval-bar-wrap {
    --eval-pct: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: var(--board);
    flex-shrink: 0;
    user-select: none;
}

.eval-bar-track {
    position: relative;
    width: 16px;
    flex: 1;
    min-height: 0;
    border-radius: 8px;
    overflow: hidden;
    background: var(--eval-black);
    border: 1px solid var(--border-default);
    box-shadow: var(--shadow-xs);
}

/* White advantage grows up from the bottom of the track. */
.eval-bar-fill {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--eval-pct);
    background: linear-gradient(180deg, #ffffff 0%, #e8e6e3 100%);
    transition: height 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Equilibrium marker at the midpoint. */
.eval-bar-mid {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 1px;
    background: var(--border-strong);
    opacity: 0.55;
    pointer-events: none;
}

.eval-bar-score {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
    font-size: 12px;
    font-weight: 700;
    letter-spacing: -0.2px;
    line-height: 1;
    color: var(--text-primary);
    transition: color 0.2s ease;
}

/* Subtle "calculating" state; never flashes on fast evaluations. */
.eval-bar-wrap.is-loading .eval-bar-track {
    border-color: var(--accent-ring);
}
.eval-bar-wrap.is-loading .eval-bar-fill {
    opacity: 0.55;
}
.eval-bar-wrap.is-loading .eval-bar-score {
    color: var(--text-muted);
}

.board-stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    flex-shrink: 0;
}

/* Player Bar & Clocks */
.player-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    width: var(--board);
    min-width: 0;
    padding: 12px 10px;
    border-radius: 12px;
    background: rgba(38, 37, 34, 0.88);
    border: 1px solid rgba(255,255,255,0.04);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.02), 0 6px 18px rgba(0,0,0,0.12);
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    background: var(--bg-surface-2);
    border: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--text-muted);
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: var(--shadow-xs);
}

.avatar svg {
    width: 100%;
    height: 100%;
    display: block;
}

.pinfo {
    min-width: 0;
    flex: 1;
}

.pname {
    display: block;
    font-weight: 700;
    font-size: var(--font-size-base);
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.pnote {
    display: block;
    color: var(--text-muted);
    font-size: var(--font-size-xs);
    font-weight: 500;
    line-height: 1.2;
}

/* Captured Pieces & Material */
.captured-box {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    margin-left: auto;
}

.captured-pieces {
    font-size: 15px;
    line-height: 1;
    letter-spacing: -3px;
    opacity: 0.85;
    user-select: none;
}

.material-advantage {
    font-size: var(--font-size-xs);
    font-weight: 700;
    color: var(--accent);
    background: var(--accent-subtle);
    border: 1px solid var(--accent-ring);
    padding: 1px 6px;
    border-radius: var(--radius-full);
    display: none;
    line-height: 1.4;
}
.material-advantage.visible { display: inline-block; }

/* Chessboard Wrapper */
.board-wrapper {
    position: relative;
    width: var(--board);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 18px 28px rgba(0, 0, 0, 0.22), 0 2px 0 rgba(255,255,255,0.03) inset;
    border: 1px solid rgba(255,255,255,0.05);
    background: rgba(0,0,0,0.18);
}

/* Chessboard.js overrides */
#myBoard {
    width: var(--board);
}

#myBoard .board-b72b1 {
    border: 0 !important;
}

#myBoard .white-1e1d7 {
    background-color: var(--sq-light);
    color: var(--sq-dark);
}

#myBoard .black-3c85d {
    background-color: var(--sq-dark);
    color: var(--sq-light);
}

/* Last-move and Tap Highlights */
#myBoard .white-1e1d7.hl-last {
    background-color: var(--hl-last-light) !important;
}

#myBoard .black-3c85d.hl-last {
    background-color: var(--hl-last-dark) !important;
}

#myBoard .square-55d63 {
    position: relative;
    cursor: pointer;
}

#myBoard .hl-select {
    box-shadow: inset 0 0 0 3px var(--accent) !important;
}

/* Radial Legal Move Dots */
#myBoard .hl-move::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 26%;
    height: 26%;
    background: rgba(14, 165, 233, 0.45);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    box-shadow: 0 0 6px rgba(14, 165, 233, 0.5);
}

#myBoard .hl-capture::after {
    content: '';
    position: absolute;
    inset: 7%;
    border-radius: 50%;
    box-shadow: inset 0 0 0 4px rgba(239, 68, 68, 0.65);
    pointer-events: none;
}

/* King In Check Radial Glow */
#myBoard .square-55d63.hl-check {
    background: radial-gradient(circle at center,
        rgba(239, 68, 68, 0.95) 0%,
        rgba(220, 38, 38, 0.60) 50%,
        transparent 80%) !important;
}

#myBoard .notation-322f9 {
    font-family: var(--font-family);
    font-size: 11px;
    font-weight: 700;
    pointer-events: none;
    opacity: 0.8;
}

/* Smooth Piece Transitions */
#myBoard .piece-417db {
    transition: transform 0.15s ease-out;
}

/* =============================================================================
   GAME OVER MODAL OVERLAY
   ============================================================================= */
.game-over-overlay {
    position: absolute;
    inset: 0;
    background: rgba(14, 17, 23, 0.85);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.game-over-overlay.active {
    display: flex;
    animation: fadeIn 0.2s ease-out;
}

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

.game-over-card {
    background: var(--bg-surface-1);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    padding: var(--space-6) var(--space-5) var(--space-5);
    text-align: center;
    width: 300px;
    box-shadow: var(--shadow-lg);
    animation: scaleIn 0.2s ease-out;
}

@keyframes scaleIn {
    from { transform: scale(0.96); opacity: 0; }
    to   { transform: scale(1); opacity: 1; }
}

.game-over-icon {
    font-size: 44px;
    color: var(--color-amber);
    margin-bottom: var(--space-2);
    line-height: 1;
}

.game-over-title {
    font-size: var(--font-size-xl);
    font-weight: 700;
    letter-spacing: -0.3px;
    margin-bottom: var(--space-1);
}

.game-over-subtitle {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    margin-bottom: var(--space-3);
}

.game-over-stats {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    margin-bottom: var(--space-5);
    padding: var(--space-2) var(--space-3);
    background: var(--bg-surface-2);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    display: inline-block;
}

.game-over-actions {
    display: flex;
    gap: var(--space-2);
}

.game-over-actions .btn {
    font-size: var(--font-size-sm);
    padding: 10px var(--space-3);
}

/* =============================================================================
   SHARED SIDE PANELS (SETUP & GAME)
   ============================================================================= */
.panel {
    width: var(--panel-w);
    flex-shrink: 0;
    height: calc(100vh - 52px);
    background: linear-gradient(180deg, rgba(38, 37, 34, 0.98), rgba(30, 28, 25, 0.98));
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18), inset 0 1px 0 rgba(255,255,255,0.02);
    border: 1px solid rgba(255,255,255,0.04);
}

.panel-head {
    background: rgba(45, 43, 40, 0.94);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    position: relative;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}

.panel-head h1 {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.2px;
    color: var(--text-primary);
}

.head-icon {
    font-size: 20px;
    color: var(--accent);
    flex-shrink: 0;
}

.back-btn {
    position: absolute;
    left: var(--space-3);
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: none;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 18px;
    transition: background 0.12s, color 0.12s;
}

.back-btn:hover {
    background: var(--bg-surface-3);
    color: var(--text-primary);
}
.back-btn.visible { display: flex; }

.panel-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.panel-body::-webkit-scrollbar { width: 6px; }
.panel-body::-webkit-scrollbar-thumb {
    background: var(--bg-surface-3);
    border-radius: var(--radius-full);
}

/* =============================================================================
   SETUP VIEWS (HOME / BOTS / FRIEND / SETTINGS)
   ============================================================================= */
.view {
    display: none;
    flex-direction: column;
    gap: var(--space-3);
}
.view.active { display: flex; }

/* Home Menu Cards */
.menu-card {
    display: flex;
    align-items: center;
    gap: 16px;
    width: 100%;
    text-align: left;
    padding: 16px 16px;
    background: rgba(45, 43, 40, 0.8);
    border: 1px solid rgba(255,255,255,0.04);
    border-radius: 12px;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.12s ease, box-shadow 0.12s ease;
}

.menu-card:hover {
    background: rgba(54, 50, 47, 0.92);
    border-color: rgba(255,255,255,0.08);
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.12);
}

.menu-card:active {
    transform: translateY(0);
}

.menu-card .ico {
    font-size: 36px;
    width: 44px;
    text-align: center;
    flex-shrink: 0;
    line-height: 1;
}

.menu-card .t {
    display: block;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 2px;
}

.menu-card .s {
    display: block;
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    line-height: 1.35;
}

/* =============================================================================
   BOT ROSTER & HERO COMPONENT
   ============================================================================= */
.bot-hero {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(45,43,40,0.9);
    border: 1px solid rgba(255,255,255,0.04);
    border-radius: 12px;
    padding: 14px 16px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.02);
}

.hero-avatar {
    width: 58px;
    height: 58px;
    border-radius: var(--radius-md);
    overflow: hidden;
    flex-shrink: 0;
    background: var(--bg-surface-3);
    border: 1px solid var(--border-subtle);
}

.hero-avatar svg {
    width: 100%;
    height: 100%;
    display: block;
}

.hero-info {
    flex: 1;
    min-width: 0;
}

.hero-title-row {
    display: flex;
    align-items: baseline;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.hero-name {
    font-weight: 700;
    font-size: var(--font-size-md);
    color: var(--text-primary);
    letter-spacing: -0.2px;
}

.hero-elo {
    font-weight: 600;
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

.hero-badge {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 1px 6px;
    border-radius: var(--radius-xs);
    background: var(--accent-subtle);
    color: var(--accent);
    border: 1px solid var(--accent-ring);
}

.hero-quote {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    margin-top: 3px;
    line-height: 1.35;
    font-style: italic;
}

/* Bot Category Tabs */
.bot-category-tabs {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
}
.bot-category-tabs::-webkit-scrollbar { display: none; }

.cat-tab {
    font-size: var(--font-size-xs);
    font-weight: 600;
    padding: 5px 10px;
    border-radius: var(--radius-full);
    background: var(--bg-surface-2);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: all 0.12s ease;
    flex-shrink: 0;
}

.cat-tab:hover {
    background: var(--bg-surface-3);
    color: var(--text-primary);
}

.cat-tab.active {
    background: var(--accent-subtle);
    border-color: var(--accent-ring);
    color: var(--accent);
}

/* Bots Grid */
.bots-grid-wrapper {
    background: var(--bg-surface-2);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-2);
}

.bots-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-2);
    max-height: 220px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-surface-3) transparent;
}

.bots-grid::-webkit-scrollbar { width: 4px; }
.bots-grid::-webkit-scrollbar-thumb {
    background: var(--bg-surface-3);
    border-radius: var(--radius-full);
}

.bot-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(38,37,34,0.9);
    border: 1px solid rgba(255,255,255,0.04);
    border-radius: 10px;
    padding: 8px 4px 6px;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease, transform 0.1s ease, box-shadow 0.12s ease;
    user-select: none;
    text-align: center;
    gap: 3px;
}

.bot-card:hover {
    background: rgba(54, 50, 47, 0.96);
    border-color: rgba(255,255,255,0.08);
    transform: translateY(-1px);
}

.bot-card.active {
    border-color: var(--accent);
    background: rgba(129, 182, 76, 0.08);
    box-shadow: 0 0 0 1px rgba(129, 182, 76, 0.28), 0 0 16px rgba(129, 182, 76, 0.12);
}

.bot-card-avatar {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-xs);
    overflow: hidden;
    background: var(--bg-surface-2);
    flex-shrink: 0;
}

.bot-card-avatar svg {
    width: 100%;
    height: 100%;
    display: block;
}

.bot-card-name {
    font-size: var(--font-size-xs);
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    line-height: 1.2;
}

.bot-card-elo {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    line-height: 1;
}

.bot-card-badge {
    font-size: 8px;
    font-weight: 700;
    padding: 1px 4px;
    border-radius: var(--radius-xs);
    background: var(--bg-surface-3);
    color: var(--text-secondary);
    white-space: nowrap;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Controls Bar (Options Toggle & Color Picker) */
.bot-bottom-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
}

.options-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    background: var(--bg-surface-2);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: var(--font-size-xs);
    font-weight: 600;
    padding: 7px var(--space-3);
    transition: background 0.12s, color 0.12s;
}

.options-toggle-btn:hover {
    background: var(--bg-surface-3);
    color: var(--text-primary);
}

#options-caret { transition: transform 0.2s ease; }
.options-toggle-btn.open #options-caret { transform: rotate(180deg); }

.bot-color-picker {
    display: flex;
    gap: 4px;
}

.color-btn {
    width: 36px;
    height: 32px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    background: var(--bg-surface-2);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.12s ease;
}

.color-btn:hover {
    background: var(--bg-surface-3);
    color: var(--text-primary);
}

.color-btn.active {
    border-color: var(--accent);
    background: var(--accent-subtle);
    color: var(--accent);
}

.chess-icon {
    font-size: 17px;
    line-height: 1;
}

.bot-options-panel {
    display: none;
    flex-direction: column;
    gap: var(--space-2);
    background: var(--bg-surface-2);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: var(--space-3);
}
.bot-options-panel.open { display: flex; }

/* =============================================================================
   FORM CONTROLS & BUTTONS
   ============================================================================= */
.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.field > label {
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

input[type="text"],
select {
    width: 100%;
    padding: 9px var(--space-3);
    background: var(--bg-surface-2);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: var(--font-size-sm);
    transition: border-color 0.15s, background 0.15s;
    appearance: none;
    -webkit-appearance: none;
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7684' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 30px;
    cursor: pointer;
}

input[type="text"]:focus,
select:focus {
    border-color: var(--accent);
    background: var(--bg-surface-1);
    outline: none;
}

select option {
    background: var(--bg-surface-1);
    color: var(--text-primary);
}

.id-box {
    background: var(--bg-surface-2);
    padding: var(--space-3);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: var(--font-size-xs);
    border-radius: var(--radius-sm);
    user-select: all;
    color: var(--accent);
    text-align: center;
    border: 1px dashed var(--border-default);
    cursor: pointer;
    word-break: break-all;
    transition: background 0.12s;
}
.id-box:hover { background: var(--bg-surface-3); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    width: 100%;
    border-radius: var(--radius-sm);
    padding: 11px var(--space-4);
    font-size: var(--font-size-sm);
    font-weight: 700;
    color: #fff;
    cursor: pointer;
    transition: all 0.12s ease;
    line-height: 1;
}

.btn:active { transform: translateY(1px); }

.btn-green {
    background: var(--accent);
    border: 1px solid var(--accent-ring);
    box-shadow: 0 2px 0 var(--accent-active);
}
.btn-green:hover { background: var(--accent-hover); }

.btn-gray {
    background: var(--bg-surface-3);
    border: 1px solid var(--border-default);
    color: var(--text-primary);
}
.btn-gray:hover { background: var(--bg-surface-2); }

/* =============================================================================
   GAME PANEL: STATUS, THEORY, MOVES, CONTROLS
   ============================================================================= */
.game-panel .panel-body {
    gap: var(--space-2);
}

/* Status Box */
.status-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(45, 43, 40, 0.9);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 10px;
    padding: 10px 12px;
    font-weight: 600;
    font-size: 12px;
    color: var(--accent);
    min-height: 42px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.03);
}

.status-box i { font-size: 16px; flex-shrink: 0; }
.status-box.check,
.status-box.over { color: var(--color-red); }
.status-box.draw { color: var(--color-amber); }

/* Skeleton Loading State for Engine */
.status-box.loading {
    background: linear-gradient(90deg, var(--bg-surface-2) 25%, var(--bg-surface-3) 50%, var(--bg-surface-2) 75%);
    background-size: 200% 100%;
    animation: skeletonShimmer 1.5s infinite;
}

@keyframes skeletonShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Opening Theory Box */
.opening-box {
    background: var(--bg-surface-2);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 10px var(--space-3);
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.opening-name-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 700;
    font-size: var(--font-size-xs);
    color: var(--accent);
}

.help-text {
    font-size: 10px;
    color: var(--text-muted);
}

.book-chips-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.book-chip {
    background: var(--bg-surface-3);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xs);
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    transition: background 0.1s, border-color 0.1s;
}

.book-chip:hover {
    background: var(--accent-subtle);
    border-color: var(--accent);
    color: var(--accent);
}

.out-of-book {
    font-size: 10px;
    color: var(--text-muted);
    font-style: italic;
}

/* Moves History Table */
.moves-container {
    background: rgba(45, 43, 40, 0.74);
    border: 1px solid rgba(255,255,255,0.04);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 100px;
    overflow: hidden;
}

.moves-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--border-subtle);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    flex-shrink: 0;
}

.move-count-badge {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg-surface-3);
    padding: 1px 6px;
    border-radius: var(--radius-full);
}

.moves-table-wrap {
    overflow-y: auto;
    flex: 1;
    padding: var(--space-1) 0;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-surface-3) transparent;
}

.moves-table-wrap::-webkit-scrollbar { width: 4px; }
.moves-table-wrap::-webkit-scrollbar-thumb {
    background: var(--bg-surface-3);
    border-radius: var(--radius-full);
}

.moves-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-xs);
}

.moves-table tr {
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

.moves-table td {
    padding: 3px var(--space-1);
    vertical-align: middle;
}

.move-num {
    color: var(--text-muted);
    width: 30px;
    font-weight: 600;
    font-size: 11px;
    padding-left: var(--space-3) !important;
    user-select: none;
}

.move-cell {
    border-radius: var(--radius-xs);
    cursor: pointer;
    font-weight: 600;
    padding: 3px 6px;
    width: 44%;
    transition: background 0.1s, box-shadow 0.1s;
    user-select: none;
}

.move-cell:hover {
    background: rgba(255,255,255,0.03);
}

.move-cell.active {
    background: rgba(129, 182, 76, 0.14);
    color: var(--accent);
    box-shadow: inset 0 0 0 1px rgba(129, 182, 76, 0.18);
}

/* Game Actions Bar */
.game-actions-bar {
    display: flex;
    gap: 4px;
    padding-top: var(--space-1);
    flex-shrink: 0;
}

.action-btn {
    flex: 1;
    background: rgba(45, 43, 40, 0.9);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 10px;
    color: var(--text-secondary);
    padding: 8px 3px;
    font-size: 10px;
    font-weight: 600;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    transition: all 0.12s ease;
    line-height: 1;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.02);
}

.action-btn i { font-size: 16px; }

.action-btn:hover {
    background: var(--bg-surface-3);
    color: var(--text-primary);
    border-color: var(--border-default);
}

.action-btn.danger:hover {
    background: var(--color-red-subtle);
    border-color: var(--color-red);
    color: var(--color-red);
}

.action-btn.primary {
    background: linear-gradient(180deg, var(--accent) 0%, var(--accent-active) 100%);
    border-color: rgba(86, 112, 57, 0.8);
    color: #fff;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.08), 0 2px 0 rgba(0,0,0,0.18);
}

.action-btn.primary:hover {
    background: linear-gradient(180deg, var(--accent-hover) 0%, var(--accent) 100%);
    border-color: rgba(86, 112, 57, 0.9);
}

/* =============================================================================
   RESPONSIVE DESIGN SYSTEM
   ============================================================================= */
@media (max-width: 1100px) {
    .sidebar { display: none; }
}

@media (max-width: 900px) {
    :root {
        --panel-w: 340px;
    }
}

@media (max-width: 820px) {
    body {
        overflow-y: auto;
        overflow-x: hidden;
    }

    .app {
        height: auto;
        min-height: 100vh;
        flex-direction: column;
    }

    .main {
        flex-direction: column;
        justify-content: flex-start;
        align-items: stretch;
        padding: var(--space-3);
        gap: var(--space-3);
        min-height: 100vh;
    }

    .setup-screen.active {
        display: flex;
        min-height: calc(100vh - 24px);
    }

    .setup-card {
        width: 100%;
        max-width: 460px;
        margin: 0 auto;
    }

    .setup-body { max-height: none; }

    .game-screen {
        flex-direction: column;
        align-items: center;
        gap: var(--space-3);
    }
    .game-screen.active { display: flex; }

    /* Narrow screens: lay the evaluation bar out horizontally above the
       board so it stays useful without squeezing the board. */
    .board-area {
        flex-direction: column;
        align-items: center;
        gap: var(--space-2);
    }

    .eval-bar-wrap {
        flex-direction: row;
        width: var(--board);
        height: auto;
        gap: var(--space-3);
    }

    .eval-bar-track {
        width: auto;
        height: 12px;
        flex: 1;
    }

    .eval-bar-fill {
        top: 0;
        bottom: 0;
        left: 0;
        right: auto;
        width: var(--eval-pct);
        height: 100%;
        background: linear-gradient(90deg, #e8e6e3 0%, #ffffff 100%);
        transition: width 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .eval-bar-mid {
        top: 0;
        bottom: 0;
        left: 50%;
        right: auto;
        width: 1px;
        height: auto;
    }

    .eval-bar-score { min-width: 46px; text-align: right; }

    .panel,
    .panel.game-panel {
        width: 100%;
        max-width: 560px;
        height: auto;
        min-height: auto;
        margin: 0 auto;
    }

    .panel-head { padding: var(--space-3) var(--space-4); }
    .panel-body { overflow: visible; padding: var(--space-3); }

    .bots-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 480px) {
    .main { padding: var(--space-2); gap: var(--space-2); }

    .bot-hero { padding: var(--space-2) var(--space-3); }
    .hero-avatar { width: 48px; height: 48px; }
    .hero-name { font-size: 14px; }

    .bots-grid {
        grid-template-columns: repeat(3, 1fr);
        max-height: 190px;
    }
    .bot-card-avatar { width: 38px; height: 38px; }

    .menu-card { padding: var(--space-3); gap: var(--space-3); }
    .menu-card .ico { font-size: 30px; width: 36px; }

    .btn { font-size: var(--font-size-xs); padding: 10px; }
    .game-actions-bar { display: grid; grid-template-columns: repeat(5, 1fr); }
}

/* =============================================================================
   ACCESSIBILITY & PREFERENCES
   ============================================================================= */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* =============================================================================
   PHASE 2 UX: CLOCKS, MODALS, NOTIFICATIONS, NAVIGATION & HISTORY
   ============================================================================= */

/* Sidebar Shortcuts Trigger */
.side-action-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-2);
    border-radius: var(--radius-sm);
    background: var(--bg-surface-2);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    font-size: var(--font-size-xs);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.side-action-btn:hover {
    background: var(--bg-surface-3);
    color: var(--text-primary);
    border-color: var(--border-default);
}

.side-action-btn kbd {
    background: var(--bg-surface-1);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xs);
    padding: 1px 5px;
    font-size: 10px;
    font-family: inherit;
    color: var(--text-muted);
}

/* Player Name Row & Thinking Indicator */
.pname-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.thinking-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--accent-subtle);
    border: 1px solid var(--accent-ring);
    color: var(--accent);
    padding: 1px 7px;
    border-radius: var(--radius-full);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.2px;
    animation: thinkingPulse 1.4s ease-in-out infinite;
}

.thinking-dot {
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    animation: pulseDot 0.8s ease-in-out infinite alternate;
}

@keyframes thinkingPulse {
    0%, 100% { opacity: 0.85; }
    50% { opacity: 1; }
}

@keyframes pulseDot {
    from { transform: scale(0.7); opacity: 0.6; }
    to { transform: scale(1.3); opacity: 1; }
}

/* Digital Chess Clocks */
.player-clock {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 15px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.4px;
    padding: 6px 10px;
    border-radius: 10px;
    background: rgba(24, 23, 22, 0.92);
    color: var(--text-secondary);
    border: 1px solid rgba(255,255,255,0.04);
    min-width: 70px;
    text-align: center;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
    user-select: none;
}

.player-clock.active {
    background: rgba(30, 30, 27, 0.96);
    color: var(--text-primary);
    border-color: rgba(129, 182, 76, 0.55);
    box-shadow: inset 0 0 0 1px rgba(129, 182, 76, 0.18), 0 0 10px rgba(129, 182, 76, 0.08);
}

.player-clock.low-time {
    background: var(--color-red-subtle) !important;
    color: var(--color-red) !important;
    border-color: var(--color-red) !important;
    animation: clockAlert 0.8s ease-in-out infinite alternate;
}

@keyframes clockAlert {
    from { opacity: 0.7; transform: scale(0.98); }
    to { opacity: 1; transform: scale(1.02); }
}

/* Moves Step Navigation Bar */
.moves-nav-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: var(--space-2) var(--space-3);
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-surface-2);
}

.mnav-btn {
    width: 32px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface-1);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xs);
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.mnav-btn:hover {
    background: var(--bg-surface-3);
    color: var(--text-primary);
    border-color: var(--border-default);
}

/* Reviewing Banner */
.review-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-3);
    background: var(--color-amber-subtle);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: var(--radius-sm);
    color: var(--color-amber);
    font-size: var(--font-size-xs);
    font-weight: 600;
    margin-bottom: var(--space-2);
}

.btn-text-link {
    background: none;
    border: none;
    color: var(--accent);
    text-decoration: underline;
    font-size: var(--font-size-xs);
    font-weight: 700;
    cursor: pointer;
    padding: 0;
}

/* Game Utility Bar (FEN / PGN / Keys) */
.game-utility-bar {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-top: var(--space-2);
}

.util-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px var(--space-2);
    background: var(--bg-surface-2);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: var(--font-size-xs);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.util-btn:hover {
    background: var(--bg-surface-3);
    color: var(--text-primary);
    border-color: var(--border-default);
}

.util-btn i { font-size: 14px; }

/* Pawn Promotion Overlay */
.promotion-overlay {
    position: absolute;
    inset: 0;
    background: rgba(14, 17, 23, 0.8);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 120;
}

.promotion-overlay.active {
    display: flex;
    animation: fadeIn 0.15s ease-out;
}

.promotion-card {
    background: var(--bg-surface-1);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    box-shadow: var(--shadow-lg);
    text-align: center;
    min-width: 260px;
}

.promotion-title {
    font-size: var(--font-size-sm);
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-3);
}

.promotion-choices {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-2);
}

.promo-choice-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: var(--bg-surface-2);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    padding: var(--space-2) var(--space-1);
    cursor: pointer;
    transition: background 0.12s, transform 0.12s, border-color 0.12s;
}

.promo-choice-btn:hover {
    background: var(--accent-subtle);
    border-color: var(--accent);
    transform: translateY(-2px);
}

.promo-glyph {
    font-size: 28px;
    line-height: 1;
    color: var(--text-primary);
}

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

/* Generic Modal Overlay & Confirmation Dialogs */
.confirm-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(14, 17, 23, 0.85);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.confirm-modal-overlay.active {
    display: flex;
    animation: fadeIn 0.18s ease-out;
}

.confirm-modal-card {
    background: var(--bg-surface-1);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    padding: var(--space-6) var(--space-5) var(--space-5);
    text-align: center;
    max-width: 360px;
    width: 90%;
    box-shadow: var(--shadow-lg);
    animation: scaleIn 0.18s ease-out;
}

.confirm-modal-icon {
    font-size: 38px;
    margin-bottom: var(--space-2);
    line-height: 1;
}

.confirm-modal-icon.warning { color: var(--color-red); }

.confirm-modal-title {
    font-size: var(--font-size-lg);
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-1);
}

.confirm-modal-desc {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    margin-bottom: var(--space-5);
    line-height: 1.4;
}

.confirm-modal-actions {
    display: flex;
    gap: var(--space-2);
}

.confirm-modal-actions .btn { flex: 1; }

/* Keyboard Shortcuts Dialog */
.shortcuts-card {
    background: var(--bg-surface-1);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    max-width: 460px;
    width: 92%;
    box-shadow: var(--shadow-lg);
    animation: scaleIn 0.18s ease-out;
}

.shortcuts-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--border-subtle);
}

.shortcuts-title-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--accent);
    font-size: 18px;
}

.shortcuts-title-row h2 {
    font-size: var(--font-size-md);
    font-weight: 700;
    color: var(--text-primary);
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-xs);
    transition: color 0.12s;
}

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

.shortcuts-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
}

.shortcut-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px var(--space-3);
    background: var(--bg-surface-2);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
}

.shortcut-keys kbd {
    background: var(--bg-surface-1);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xs);
    padding: 2px 7px;
    font-size: 12px;
    font-family: inherit;
    font-weight: 700;
    color: var(--accent);
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.shortcut-desc {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    font-weight: 500;
}

/* Match History View */
.history-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--border-subtle);
}

.history-count {
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--text-muted);
}

.btn-text-danger {
    background: none;
    border: none;
    color: var(--color-red);
    font-size: var(--font-size-xs);
    font-weight: 600;
    cursor: pointer;
}

.btn-text-danger:hover { text-decoration: underline; }

.history-list-wrap {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    max-height: 480px;
    overflow-y: auto;
}

.history-empty {
    text-align: center;
    padding: var(--space-6) var(--space-4);
    color: var(--text-muted);
}

.history-empty i {
    font-size: 38px;
    margin-bottom: var(--space-2);
    color: var(--text-muted);
}

.history-empty p {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--space-1);
}

.history-empty span {
    font-size: var(--font-size-xs);
    line-height: 1.4;
}

.history-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-surface-2);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: var(--space-3);
    transition: border-color 0.12s;
}

.history-card:hover {
    border-color: var(--border-default);
}

.history-main-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.history-opponent {
    font-size: var(--font-size-sm);
    font-weight: 700;
    color: var(--text-primary);
}

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

.history-right-col {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.result-badge {
    padding: 3px 8px;
    border-radius: var(--radius-xs);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.result-badge.win {
    background: var(--color-green-subtle);
    color: var(--color-green);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.result-badge.loss {
    background: var(--color-red-subtle);
    color: var(--color-red);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.result-badge.draw {
    background: var(--color-amber-subtle);
    color: var(--color-amber);
    border: 1px solid rgba(245, 158, 11, 0.3);
}

/* Post-Game Accuracy Breakdown Card */
.accuracy-card {
    background: var(--bg-surface-2);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: var(--space-3);
    margin-bottom: var(--space-3);
    text-align: left;
}

.acc-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-2);
}

.acc-label {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    font-weight: 600;
}

.acc-value {
    font-size: var(--font-size-sm);
    font-weight: 800;
    color: var(--accent);
}

.acc-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.acc-pill {
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: var(--radius-xs);
}

.pill-best { background: rgba(16, 185, 129, 0.15); color: var(--color-green); }
.pill-good { background: rgba(14, 165, 233, 0.15); color: var(--accent); }
.pill-inacc { background: rgba(245, 158, 11, 0.15); color: var(--color-amber); }
.pill-mistake { background: rgba(249, 115, 22, 0.15); color: #f97316; }
.pill-blunder { background: rgba(239, 68, 68, 0.15); color: var(--color-red); }

/* Floating Toast Notifications */
.toast-container {
    position: fixed;
    bottom: var(--space-5);
    right: var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    z-index: 300;
    pointer-events: none;
}

.toast {
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    color: var(--text-primary);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    font-size: var(--font-size-xs);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    pointer-events: auto;
    animation: slideToast 0.2s ease-out;
}

.toast.success i { color: var(--color-green); }
.toast.info i { color: var(--accent); }

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