/* ============ Chess Coach — modern dark theme ============ */
:root {
    --bg0: #070b16;
    --bg1: #0c1226;
    --panel: rgba(17, 24, 46, 0.72);
    --panel-solid: #11182e;
    --card: #151d38;
    --line: rgba(148, 163, 255, 0.14);
    --txt: #e8ecf8;
    --muted: #8b94b3;
    --accent: #22c55e;
    --accent2: #34d399;
    --violet: #8b5cf6;
    --gold: #facc15;
    --danger: #ef4444;
    --radius: 16px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body.app-shell {
    margin: 0;
    font-family: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
    color: var(--txt);
    background:
        radial-gradient(1100px 500px at 15% -10%, rgba(34, 197, 94, 0.10), transparent 60%),
        radial-gradient(900px 500px at 90% 0%, rgba(139, 92, 246, 0.14), transparent 60%),
        radial-gradient(800px 600px at 50% 110%, rgba(56, 130, 246, 0.08), transparent 60%),
        linear-gradient(180deg, var(--bg1), var(--bg0));
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.font-display, .brand-name, h1, h2, h3 { font-family: "Sora", "Manrope", sans-serif; }

/* ---------- Topbar ---------- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    padding: 12px 20px;
    background: rgba(10, 15, 32, 0.75);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
    z-index: 20;
}

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

.logo-mark {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #06130c;
    background: linear-gradient(135deg, var(--accent2), var(--accent) 60%, #15803d);
    box-shadow: 0 4px 18px rgba(34, 197, 94, 0.45);
}

.brand-name { font-size: 20px; font-weight: 800; letter-spacing: 0.04em; margin: 0; }
.brand-name span {
    background: linear-gradient(90deg, var(--accent2), #7ef0c1);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

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

/* Top nav (moved out of the coach panel) */
.topbar-nav { display: flex; align-items: center; gap: 6px; }
.topbar-nav .nav-btn { width: 38px; height: 38px; }
.topbar-nav .move-counter { margin-left: 8px; }

/* Settings panel: inline on desktop, slide-in drawer on phones */
.settings-panel { display: flex; align-items: center; gap: 10px; }
.settings-title, .settings-label { display: none; }
#settingsToggleBtn { display: none; }
.settings-backdrop { display: none; }

.seg {
    display: flex;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 3px;
}
.seg-btn {
    border: 0;
    background: transparent;
    color: var(--muted);
    font: 700 12px "Manrope", sans-serif;
    padding: 7px 14px;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.15s;
}
.seg-btn.seg-on, .seg-btn.bg-green-600 {
    background: linear-gradient(135deg, var(--accent), #15803d);
    color: #fff;
    box-shadow: 0 2px 10px rgba(34, 197, 94, 0.4);
}

.search {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 3px 3px 3px 12px;
}
.search-icon { color: var(--muted); font-size: 12px; }
.search input {
    background: transparent;
    border: 0;
    outline: 0;
    color: var(--txt);
    font: 600 13px "Manrope", sans-serif;
    width: 150px;
}
.search input::placeholder { color: var(--muted); }
.search button {
    border: 0;
    border-radius: 999px;
    padding: 7px 16px;
    font: 800 12px "Manrope", sans-serif;
    color: #fff;
    cursor: pointer;
    background: linear-gradient(135deg, var(--accent), #15803d);
    transition: filter 0.15s;
}
.search button:hover { filter: brightness(1.12); }
.search button:disabled { opacity: 0.6; cursor: default; }

.select {
    background: var(--card);
    color: var(--txt);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 8px 12px;
    font: 600 12px "Manrope", sans-serif;
    outline: none;
    cursor: pointer;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.05);
    color: var(--muted);
    cursor: pointer;
    transition: all 0.15s;
}
.icon-btn:hover { color: #fff; border-color: rgba(52, 211, 153, 0.5); transform: translateY(-1px); }

/* ---------- Layout ---------- */
.layout { flex: 1; display: flex; min-height: 0; }

/* ---------- Sidebar ---------- */
.sidebar {
    width: 300px;
    flex-shrink: 0;
    background: var(--panel);
    backdrop-filter: blur(10px);
    border-right: 1px solid var(--line);
}
.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    font: 800 11px "Manrope", sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
    border-bottom: 1px solid var(--line);
}
.sidebar-head i { margin-right: 6px; color: var(--accent2); }
.count-pill {
    background: rgba(52, 211, 153, 0.12);
    color: var(--accent2);
    border-radius: 999px;
    padding: 2px 10px;
    font-size: 10px;
}
.games-list { flex: 1; overflow-y: auto; padding: 10px; }
.game-item {
    border-radius: 12px !important;
    border: 1px solid transparent !important;
    margin-bottom: 6px;
}
.game-item:hover { border-color: var(--line) !important; }

/* ---------- Stage ---------- */
.stage {
    flex: 1;
    position: relative;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 22px;
    overflow-y: auto;
    min-width: 0;
}
.board-row { display: flex; align-items: stretch; gap: 14px; }

.evalbar {
    width: 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid var(--line);
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    min-height: 400px;
    align-self: stretch;
    margin-top: 34px;
}
#evalBarFill {
    width: 100%;
    background: linear-gradient(180deg, #fff, #c9d4f5);
    transition: height 0.3s ease-out;
    border-radius: 999px;
}
#evalText {
    position: absolute;
    top: -32px;
    left: 50%;
    transform: translateX(-50%);
    font: 800 12px "Manrope", sans-serif;
    color: var(--txt);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 2px 8px;
    white-space: nowrap;
}

.board-col { display: flex; flex-direction: column; align-items: center; gap: 12px; }

.board-frame {
    position: relative;
    padding: 12px;
    border-radius: 20px;
    background: linear-gradient(135deg, rgba(52, 211, 153, 0.35), rgba(139, 92, 246, 0.35));
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.06);
}
.flip-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 20;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: rgba(5, 8, 18, 0.75);
    backdrop-filter: blur(6px);
    color: var(--muted);
    cursor: pointer;
    transition: all 0.15s;
}
.flip-btn:hover { color: #fff; border-color: rgba(52, 211, 153, 0.6); transform: rotate(40deg); }
#board {
    width: 600px !important;
    border-radius: 12px;
    overflow: hidden;
}
@media (max-width: 1500px) { #board { width: 520px !important; } }
@media (max-width: 1300px) { #board { width: 460px !important; } }
@media (max-width: 1180px) { #board { width: min(560px, 88vw) !important; } }
/* Chessboard square colors: pale blue light squares, dark blue dark squares */
.white-1e1d7 { background-color: #d3e3f5; color: #31597d; }
.black-3c85d { background-color: #35618e; color: #d3e3f5; }

.moves-card {
    width: 100%;
    max-width: 624px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px 14px;
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
    font-size: 14px;
    line-height: 1.9;
    max-height: 130px;
    overflow-y: auto;
    backdrop-filter: blur(10px);
}
.moves-empty { font-family: "Manrope", sans-serif; font-size: 12px; color: var(--muted); }

/* Move tokens: always tinted by classification (chess.com style) */
.move-token { border-radius: 6px; padding: 1px 5px; transition: background 0.12s; color: #dbe2f5; }
.move-token.tok-brilliant { background: rgba(20, 184, 166, 0.45); color: #fff; }
.move-token.tok-great { background: rgba(59, 130, 246, 0.45); color: #fff; }
.move-token.tok-best { background: rgba(34, 197, 94, 0.38); color: #fff; }
.move-token.tok-excellent { background: rgba(163, 230, 53, 0.32); color: #f2ffd6; }
.move-token.tok-good { background: rgba(159, 179, 200, 0.28); }
.move-token.tok-book { background: rgba(176, 141, 95, 0.38); color: #fff; }
.move-token.tok-inaccuracy { background: rgba(245, 197, 66, 0.4); color: #ffedbe; }
.move-token.tok-mistake { background: rgba(240, 140, 30, 0.48); color: #fff; }
.move-token.tok-blunder { background: rgba(224, 69, 54, 0.52); color: #fff; }
.move-token.tok-missed_win { background: rgba(198, 120, 221, 0.48); color: #fff; }
/* Current move: white outline so the class color stays visible */
.move-token.bg-green-700 { outline: 2px solid #f8fafc; outline-offset: 1px; }

/* ---------- Subtitles ---------- */
.subtitles {
    position: absolute;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
    max-width: min(680px, 92%);
    max-height: 120px;
    overflow-y: auto;
    background: rgba(3, 6, 16, 0.82);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 10px 18px;
    z-index: 15;
    backdrop-filter: blur(8px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.subtitles p { margin: 0; font-size: 16px; line-height: 1.65; color: #f1f5ff; text-align: center; }
.sub-word { border-radius: 4px; padding: 0 1px; transition: color 0.1s; }
.sub-word.active { color: var(--gold); font-weight: 800; }

/* ---------- Loader ---------- */
.loader-overlay {
    position: absolute;
    inset: 0;
    z-index: 30;
    background: rgba(5, 8, 18, 0.82);
    backdrop-filter: blur(6px);
    align-items: center;
    justify-content: center;
    gap: 14px;
    text-align: center;
    border-radius: 12px;
}
.loader-overlay h3 { margin: 0; font-size: 18px; }
.loader-sub { margin: 0; color: var(--muted); font-size: 13px; }
.spinner {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    border: 4px solid rgba(52, 211, 153, 0.2);
    border-top-color: var(--accent2);
    animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Coach panel ---------- */
.coach {
    width: 380px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--panel);
    backdrop-filter: blur(10px);
    border-left: 1px solid var(--line);
    min-height: 0;
}

.match-card {
    padding: 16px 18px 14px;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(180deg, rgba(139, 92, 246, 0.08), transparent);
}
.match-card h2 { margin: 0; font-size: 16px; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; }
.dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; flex-shrink: 0; border: 2px solid rgba(255, 255, 255, 0.35); }
.dot-w { background: #f1f5ff; }
.dot-b { background: #151515; }
.vs { color: var(--muted); font-size: 12px; font-weight: 800; }
.you-tag {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.06em;
    color: var(--accent2);
    background: rgba(52, 211, 153, 0.15);
    border: 1px solid rgba(52, 211, 153, 0.45);
    border-radius: 999px;
    padding: 2px 8px;
    white-space: nowrap;
}
.acc-row { align-items: center; justify-content: space-between; margin-top: 12px; }
.acc { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.acc-name {
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.acc-ring {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 14px;
    background: var(--card);
}
.acc-ring.light { border: 3px solid #e8ecf8; box-shadow: 0 0 14px rgba(232, 236, 248, 0.25); }
.acc-ring.dark { border: 3px solid var(--violet); box-shadow: 0 0 14px rgba(139, 92, 246, 0.4); }
.acc-vs { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }

.coach-scroll { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }

.move-status {
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 10px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px 12px;
    text-align: center;
}
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.move-san {
    font-family: "Sora", ui-monospace, Consolas, monospace;
    font-weight: 800;
    font-size: 38px;
    line-height: 1;
    letter-spacing: 0.02em;
}
.move-status .badge { font-size: 13px; padding: 8px 18px; }

/* Classification badge colors (set from JS) — distinct hue per label */
.bg-brilliant { background: linear-gradient(135deg, #14b8a6, #0b6e63); color: #fff; }
.bg-great { background: linear-gradient(135deg, #3b82f6, #1d4fa1); color: #fff; }
.bg-best { background: linear-gradient(135deg, #22c55e, #14632e); color: #fff; }
.bg-excellent { background: linear-gradient(135deg, #a3e635, #5c8a12); color: #16220a; }
.bg-good { background: linear-gradient(135deg, #9fb3c8, #5b6b82); color: #fff; }
.bg-book { background: linear-gradient(135deg, #b08d5f, #6f5636); color: #fff; }
.bg-inaccuracy { background: linear-gradient(135deg, #f5c542, #c08f14); color: #241a03; }
.bg-mistake { background: linear-gradient(135deg, #f08c1e, #b25a08); color: #fff; }
.bg-blunder { background: linear-gradient(135deg, #e04536, #961811); color: #fff; }
.bg-missed_win { background: linear-gradient(135deg, #c678dd, #7e3296); color: #fff; }

.coach-msg { gap: 10px; align-items: flex-start; }
.avatar {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 18px;
    background: linear-gradient(135deg, #38bdf8, var(--violet));
    box-shadow: 0 6px 18px rgba(139, 92, 246, 0.45);
}
.bubble {
    flex: 1;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 4px 16px 16px 16px;
    padding: 12px 14px;
    font-size: 14px;
    line-height: 1.55;
}
.bubble p { margin: 0; }
.best-line {
    gap: 8px;
    align-items: flex-start;
    margin-top: 10px;
    padding: 9px 11px;
    background: rgba(34, 197, 94, 0.08);
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-radius: 10px;
    font-family: ui-monospace, Consolas, monospace;
    font-size: 12.5px;
    line-height: 1.6;
}
.best-line-tag {
    flex-shrink: 0;
    font-family: "Manrope", sans-serif;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--accent2);
    background: rgba(52, 211, 153, 0.15);
    border-radius: 6px;
    padding: 2px 7px;
}
.audio-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
}
.play-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 0;
    cursor: pointer;
    color: #fff;
    background: linear-gradient(135deg, #38bdf8, var(--violet));
    transition: transform 0.12s;
}
.play-btn:hover { transform: scale(1.08); }
.play-btn:disabled { opacity: 0.5; cursor: default; }
.audio-hint { font-size: 12px; color: var(--muted); }
.auto-voice {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--muted);
    cursor: pointer;
}
.auto-voice input { accent-color: var(--accent); cursor: pointer; }

.btn-summary {
    border: 0;
    border-radius: 14px;
    padding: 13px;
    font: 800 13px "Manrope", sans-serif;
    color: #fff;
    cursor: pointer;
    background: linear-gradient(135deg, var(--violet), #6d28d9);
    box-shadow: 0 8px 22px rgba(139, 92, 246, 0.4);
    transition: filter 0.15s, transform 0.12s;
}
.btn-summary:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn-summary i { margin-right: 8px; }

.qa-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
}
.qa-title { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 8px; }
.qa-title i { color: var(--accent2); margin-right: 6px; }
.qa-answer {
    font-size: 13.5px;
    line-height: 1.55;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 8px;
}
.qa-input-row { display: flex; gap: 8px; }
.qa-suggestions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.qa-suggestions:empty { display: none; }
.qa-chip {
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.05);
    color: var(--txt);
    border-radius: 999px;
    padding: 5px 10px;
    font: 600 11.5px "Manrope", sans-serif;
    cursor: pointer;
    transition: all 0.15s;
}
.qa-chip:hover { border-color: rgba(52, 211, 153, 0.5); color: #fff; }
.qa-input-row input {
    flex: 1;
    min-width: 0;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--txt);
    font: 600 13px "Manrope", sans-serif;
    padding: 9px 12px;
    outline: none;
}
.qa-input-row input:focus { border-color: rgba(52, 211, 153, 0.6); }
.qa-input-row button {
    border: 0;
    border-radius: 10px;
    padding: 0 14px;
    color: #fff;
    cursor: pointer;
    background: linear-gradient(135deg, var(--accent), #15803d);
}

/* Nav dock */
.navdock { padding: 14px; border-top: 1px solid var(--line); background: rgba(0, 0, 0, 0.2); }
.navdock-btns { display: flex; justify-content: center; gap: 12px; margin-bottom: 8px; }
.nav-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--line);
    background: var(--card);
    color: #c6cdea;
    cursor: pointer;
    font-size: 15px;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.nav-btn:hover:not(:disabled) {
    border-color: rgba(52, 211, 153, 0.6);
    color: #fff;
    transform: translateY(-2px);
    box-shadow: 0 8px 18px rgba(34, 197, 94, 0.25);
}
.nav-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.move-counter { text-align: center; font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--muted); }

/* ---------- Modal ---------- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(3, 5, 12, 0.7);
    backdrop-filter: blur(6px);
    align-items: center;
    justify-content: center;
}
.modal-card {
    width: min(520px, 92vw);
    background: var(--panel-solid);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 24px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.modal-card h3 { margin: 0 0 14px; font-size: 17px; }
.modal-card h3 i { color: var(--accent2); margin-right: 8px; }
.modal-card textarea {
    width: 100%;
    height: 160px;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--line);
    border-radius: 12px;
    color: var(--txt);
    font-family: ui-monospace, Consolas, monospace;
    font-size: 13px;
    padding: 12px;
    outline: none;
    resize: vertical;
}
.modal-card textarea:focus { border-color: rgba(52, 211, 153, 0.6); }
.about-body { font-size: 13.5px; line-height: 1.6; color: var(--txt); }
.about-body p { margin: 0 0 10px; }
.about-body ul { margin: 0 0 10px; padding-left: 20px; }
.about-body li { margin-bottom: 5px; }
.about-fine { font-size: 11.5px; color: var(--muted); }
.about-fine code { font-size: 11px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }
.btn-ghost {
    border: 1px solid var(--line);
    background: transparent;
    color: var(--txt);
    border-radius: 10px;
    padding: 9px 18px;
    font: 700 13px "Manrope", sans-serif;
    cursor: pointer;
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.06); }
.btn-primary {
    border: 0;
    border-radius: 10px;
    padding: 9px 20px;
    font: 800 13px "Manrope", sans-serif;
    color: #fff;
    cursor: pointer;
    background: linear-gradient(135deg, var(--accent), #15803d);
    box-shadow: 0 6px 18px rgba(34, 197, 94, 0.35);
}

/* ---------- Best-move arrow overlay ---------- */
/* NOTE: no line-height hacks on the wrap — chessboard coordinate labels
   inherit it, and zero line-height displaces their glyphs off the corners. */
#boardWrap { position: relative; display: inline-block; }
#board .square-55d63 { line-height: normal; }
#arrowLayer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(148, 163, 255, 0.22); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: rgba(148, 163, 255, 0.35); }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
    .coach { width: 320px; }
    .sidebar { width: 250px; }
}
@media (max-width: 960px) {
    body.app-shell { overflow: auto; height: auto; }
    .layout { flex-direction: column; }
    /* Board first, then coach panel, then games list */
    .stage { order: 1; }
    .coach { order: 2; }
    .sidebar { order: 3; }
    .sidebar { width: 100%; border-right: 0; border-bottom: 1px solid var(--line); }
    .coach { width: 100%; border-left: 0; border-top: 1px solid var(--line); }
    #board { min-width: 0; }
    .topbar { padding: 10px 12px; gap: 10px; }
    .brand-name { font-size: 17px; }
    .logo-mark { width: 34px; height: 34px; font-size: 17px; }
    .stage { padding: 14px 12px; }
    .evalbar { margin-top: 0; min-height: 0; }
    .move-san { font-size: 30px; }
}

/* Phones (iPhone and similar) */
@media (max-width: 640px) {
    body.app-shell { overflow-x: hidden; }

    /* Sticky top bar: brand + action icons on row 1, nav on row 2.
       No backdrop-filter on phones: it would make the topbar the containing
       block for the fixed settings drawer/backdrop (clipping them to the bar
       and trapping them in this stacking context), which put the board on top
       of the open menu. The opaque background keeps the bar readable instead. */
    .topbar {
        position: sticky;
        top: 0;
        z-index: 30;
        flex-wrap: wrap;
        row-gap: 8px;
        padding: 10px 12px;
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
        background: rgba(10, 15, 32, 0.96);
    }
    .brand { order: 1; }
    .topbar-controls { order: 2; margin-left: auto; gap: 6px; }
    .topbar-nav { order: 3; width: 100%; justify-content: center; flex-wrap: wrap; }
    .topbar-nav .nav-btn { width: 40px; height: 40px; }
    .topbar-nav .move-counter { margin-left: 4px; }

    .brand-name { font-size: 15px; }
    .logo-mark { width: 32px; height: 32px; font-size: 16px; }
    .seg-btn { padding: 6px 10px; font-size: 11px; }
    .icon-btn { width: 34px; height: 34px; }

    #settingsToggleBtn { display: inline-flex; align-items: center; justify-content: center; }

    /* Settings drawer */
    .settings-panel {
        position: fixed;
        top: 0;
        right: 0;
        height: 100%;
        width: min(86vw, 340px);
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 18px 16px;
        background: var(--panel-solid);
        border-left: 1px solid var(--line);
        box-shadow: -20px 0 60px rgba(0, 0, 0, 0.5);
        transform: translateX(105%);
        transition: transform 0.25s ease;
        z-index: 60;
        overflow-y: auto;
    }
    .settings-panel.open { transform: translateX(0); }
    .settings-panel .seg { justify-content: center; }
    .settings-panel .search { width: 100%; }
    .settings-panel .search input { width: 100%; }
    .settings-panel .select { width: 100%; }
    .settings-title { display: block; font: 800 13px "Manrope", sans-serif; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
    .settings-label { display: block; font: 700 11px "Manrope", sans-serif; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: -6px; }
    .settings-backdrop { display: block; position: fixed; inset: 0; background: rgba(3, 5, 12, 0.6); z-index: 55; }
    .settings-backdrop.hidden { display: none; }

    /* Board takes the width, eval bar gets a slim strip */
    .stage { padding: 12px 10px; }
    .board-frame { padding: 8px; border-radius: 14px; }
    #board { width: min(440px, 84vw) !important; }
    .evalbar { width: 10px; }
    #evalText { font-size: 10px; padding: 1px 6px; top: -26px; }

    .moves-card { font-size: 12.5px; max-height: 110px; padding: 10px 12px; }
    .move-san { font-size: 28px; }

    /* Games list must not eat the screen: cap it and scroll inside */
    .sidebar { max-height: 42vh; }
    .games-list { max-height: 36vh; }

    .coach-scroll { padding: 12px; gap: 12px; }
    .bubble { font-size: 13.5px; }
    .match-card h2 { font-size: 14px; }
    .qa-input-row input { font-size: 13px; }

    .subtitles { max-width: 94%; padding: 8px 12px; bottom: 10px; }
    .subtitles p { font-size: 14px; }
}

/* Board square coordinates (faint labels on every square) */
#board .square-55d63 { position: relative; }
#board .square-55d63::after {
    content: attr(data-coord);
    position: absolute;
    right: 2px;
    bottom: 0;
    font: 700 9px "Manrope", sans-serif;
    line-height: 1.2;
    pointer-events: none;
    opacity: 0.5;
}
#board .white-1e1d7::after { color: #31597d; }
#board .black-3c85d::after { color: #d3e3f5; }

