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

:root {
    --sq-light: #f0d9b5;
    --sq-dark: #b58863;
    --sq-selected: rgba(20, 85, 200, 0.45);
    --sq-legal: rgba(20, 85, 30, 0.4);
    --sq-last-move: rgba(155, 199, 0, 0.41);
    --sq-check: rgba(255, 0, 0, 0.5);
    --sq-correct: rgba(50, 200, 50, 0.5);
    --sq-wrong: rgba(255, 50, 50, 0.5);
    --bg: #302e2b;
    --bg-panel: #272522;
    --text: #e0d6c2;
    --text-dim: #9b9488;
    --accent: #81b64c;
    --danger: #e05555;
    --header-h: 44px;
    --nav-h: 44px;
}

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    touch-action: manipulation;
}

.hidden { display: none !important; }
.desktop-only { display: none; }

/* ── Login ─────────────────────────────────────────── */

.login-screen {
    position: fixed;
    inset: 0;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.login-card {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 2.5rem;
    background: var(--bg-panel);
    border-radius: 14px;
    width: min(340px, 90vw);
}

.login-card h1 { font-size: 2rem; font-weight: 700; }
.login-card p  { color: var(--text-dim); font-size: 0.95rem; }

.login-error {
    width: 100%;
    padding: 0.5rem 0.7rem;
    background: rgba(224,85,85,0.15);
    border: 1px solid rgba(224,85,85,0.3);
    border-radius: 6px;
    font-size: 0.82rem;
    color: var(--danger);
    text-align: left;
}

.login-form { display: flex; flex-direction: column; gap: 0.6rem; width: 100%; }

.login-input {
    width: 100%;
    padding: 0.65rem 0.8rem;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 7px;
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
}
.login-input:focus { outline: none; border-color: rgba(255,255,255,0.35); }
.login-input::placeholder { color: var(--text-dim); }

.login-btn {
    width: 100%;
    padding: 0.7rem;
    background: var(--accent);
    color: #1a1a1a;
    font-weight: 700;
    font-size: 0.95rem;
    border: none;
    border-radius: 7px;
    cursor: pointer;
    margin-top: 0.2rem;
}
.login-btn:hover:not(:disabled) { background: #93c95e; }
.login-btn:disabled { opacity: 0.6; cursor: default; }

.token-help { font-size: 0.78rem; color: var(--text-dim); line-height: 1.5; }
.token-help a { color: var(--accent); text-decoration: none; }
.token-help a:hover { text-decoration: underline; }

/* ── Loading ───────────────────────────────────────── */

.loading-screen {
    position: fixed;
    inset: 0;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(255,255,255,0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Menu overlay ──────────────────────────────────── */

.menu-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 150;
}

.menu-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(300px, 85vw);
    background: var(--bg-panel);
    z-index: 160;
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 20px rgba(0,0,0,0.4);
}

.menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.8rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.menu-title { font-weight: 700; font-size: 1rem; }

.menu-close {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    transition: background 0.15s;
}
.menu-close:hover { background: rgba(255,255,255,0.08); color: var(--text); }

.menu-body {
    flex: 1;
    overflow-y: auto;
    padding: 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

.menu-section { display: flex; flex-direction: column; gap: 0.5rem; }

.menu-section-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-dim);
}

.menu-toggle-group {
    display: flex;
    gap: 0.3rem;
    background: rgba(255,255,255,0.05);
    padding: 3px;
    border-radius: 7px;
}

.menu-toggle {
    flex: 1;
    padding: 0.35rem 0.5rem;
    border: none;
    border-radius: 5px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    background: transparent;
    color: var(--text-dim);
    transition: background 0.15s, color 0.15s;
}

.menu-toggle.active { background: var(--bg); color: var(--text); }

.menu-action-btn {
    width: 100%;
    padding: 0.5rem 0.7rem;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
}
.menu-action-btn:hover { background: rgba(255,255,255,0.12); }
.menu-action-btn.active {
    background: rgba(255, 140, 30, 0.18);
    border-color: rgba(255, 140, 30, 0.45);
    color: rgba(255, 160, 50, 1);
}
.menu-action-btn.flagged {
    background: rgba(255, 140, 30, 0.18);
    border-color: rgba(255, 140, 30, 0.45);
    color: rgba(255, 160, 50, 1);
}

.menu-logout-section { margin-top: auto; }

.menu-logout {
    display: block;
    padding: 0.5rem 0.7rem;
    color: var(--danger);
    font-size: 0.85rem;
    text-decoration: none;
    border: 1px solid rgba(224,85,85,0.25);
    border-radius: 6px;
    text-align: center;
    transition: background 0.15s;
}
.menu-logout:hover { background: rgba(224,85,85,0.1); }

/* ── App shell ─────────────────────────────────────── */

.app {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0.4rem 0.5rem 0.3rem;
}

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-h);
    flex-shrink: 0;
}

header h1 {
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.username { font-size: 0.82rem; color: var(--text-dim); }

.menu-btn {
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0.2rem 0.4rem;
    border-radius: 5px;
    transition: background 0.15s;
    line-height: 1;
}
.menu-btn:hover { background: rgba(255,255,255,0.08); }

/* ── Main layout (mobile) ──────────────────────────── */

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: hidden;
    gap: 0.3rem;
    min-height: 0;
}

.board-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
    width: 100%;
}

/* Board size: square fitting the narrower of width vs remaining height */
:root {
    --board-size: min(calc(100vw - 2rem), calc(100dvh - var(--header-h) - var(--nav-h) - 160px));
}

.board-wrapper {
    display: grid;
    grid-template-columns: 0.9rem var(--board-size);
    grid-template-rows: var(--board-size) 1.4rem;
    user-select: none;
    -webkit-user-select: none;
    flex-shrink: 0;
}

.board {
    width: var(--board-size);
    height: var(--board-size);
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    border: 2px solid #1a1917;
    border-radius: 2px;
    overflow: hidden;
    position: relative;
    touch-action: none;   /* prevents scroll hijacking during drag */
}

.arrow-layer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

.coords {
    display: flex;
    color: var(--text-dim);
    font-size: 0.6rem;
    font-weight: 600;
}
.coords-ranks {
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
    padding-right: 2px;
}
.coords-files {
    grid-column: 2;
    flex-direction: row;
    justify-content: space-around;
    align-items: flex-start;
    padding-top: 3px;
}

/* ── Nav bar ───────────────────────────────────────── */

.nav-bar {
    display: flex;
    gap: 0.3rem;
    padding: 0.3rem 0;
    width: var(--board-size);
    flex-shrink: 0;
}

.nav-btn {
    flex: 1;
    height: var(--nav-h);
    border: none;
    border-radius: 7px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    background: rgba(255,255,255,0.08);
    color: var(--text);
    transition: background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.nav-btn:hover { background: rgba(255,255,255,0.14); }
.nav-btn:active { background: rgba(255,255,255,0.05); }

.nav-btn-flip {
    font-size: 1.3rem;
    max-width: 52px;
}

/* ── Panel (mobile = flat info area) ──────────────── */

.panel {
    flex: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
    gap: 0.3rem;
}

/* ── Squares ───────────────────────────────────────── */

.square {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: default;
}

.square.light { background: var(--sq-light); }
.square.dark  { background: var(--sq-dark); }

.square.selected.light { background: color-mix(in srgb, var(--sq-light), var(--sq-selected)); }
.square.selected.dark  { background: color-mix(in srgb, var(--sq-dark),  var(--sq-selected)); }

.square.last-move.light { background: color-mix(in srgb, var(--sq-light), var(--sq-last-move)); }
.square.last-move.dark  { background: color-mix(in srgb, var(--sq-dark),  var(--sq-last-move)); }

.square.check.light { background: radial-gradient(ellipse at center, var(--sq-check), transparent 80%), var(--sq-light); }
.square.check.dark  { background: radial-gradient(ellipse at center, var(--sq-check), transparent 80%), var(--sq-dark); }

.square.correct.light { background: color-mix(in srgb, var(--sq-light), var(--sq-correct)); }
.square.correct.dark  { background: color-mix(in srgb, var(--sq-dark),  var(--sq-correct)); }

.square.wrong.light { background: color-mix(in srgb, var(--sq-light), var(--sq-wrong)); }
.square.wrong.dark  { background: color-mix(in srgb, var(--sq-dark),  var(--sq-wrong)); }

.square.legal-move::after {
    content: '';
    position: absolute;
    width: 30%;
    height: 30%;
    border-radius: 50%;
    background: var(--sq-legal);
    pointer-events: none;
}
.square.legal-move.has-piece::after {
    width: 90%;
    height: 90%;
    background: transparent;
    border: 5px solid var(--sq-legal);
    border-radius: 50%;
}

/* ── Pieces ────────────────────────────────────────── */

.piece {
    width: 85%;
    height: 85%;
    z-index: 1;
    pointer-events: none;
}
.square.has-piece { cursor: grab; }

.piece.dragging {
    width: calc(var(--board-size) / 8 * 0.9);
    height: calc(var(--board-size) / 8 * 0.9);
    cursor: grabbing;
    filter: drop-shadow(0 6px 12px rgba(0,0,0,0.5));
}
.piece.ghost { opacity: 0.3; }

/* ── Opening name ──────────────────────────────────── */

.opening-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--accent);
    min-height: 1.1em;
    flex-shrink: 0;
}

.cache-indicator {
    font-size: 0.7rem;
    font-weight: 600;
    min-height: 0.9em;
    flex-shrink: 0;
    letter-spacing: 0.04em;
}
.cache-indicator.hit { color: #4ade80; }
.cache-indicator.miss { color: #fb923c; }
.cache-indicator.stale { color: #facc15; }

/* ── Status ────────────────────────────────────────── */

.status {
    font-size: 0.9rem;
    font-weight: 600;
    padding: 0.45rem 0.7rem;
    border-radius: 6px;
    background: rgba(255,255,255,0.05);
    text-align: center;
    flex-shrink: 0;
}
.status.correct { background: rgba(50,200,50,0.15); color: var(--accent); }
.status.wrong   { background: rgba(255,50,50,0.15);  color: var(--danger); }
.status.info    { background: rgba(100,150,255,0.12); color: #8bb4ff; }
.status-link-btn {
    display: block;
    margin: 0.4rem auto 0;
    background: none;
    border: 1px solid currentColor;
    border-radius: 4px;
    padding: 0.2rem 0.5rem;
    font: inherit;
    color: inherit;
    cursor: pointer;
    opacity: 0.85;
}
.status-link-btn:hover { opacity: 1; }

/* ── Build prompt ──────────────────────────────────── */

.build-prompt {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
    padding: 0.4rem 0.6rem;
    background: rgba(129,182,76,0.12);
    border: 1px solid rgba(129,182,76,0.25);
    border-radius: 6px;
    font-size: 0.82rem;
    flex-shrink: 0;
}
.build-prompt-btns { display: flex; gap: 0.3rem; flex-shrink: 0; }

.build-prompt-btn {
    padding: 0.2rem 0.55rem;
    border: none;
    border-radius: 4px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
}
.build-prompt-btn.add  { background: var(--accent); color: #1a1a1a; }
.build-prompt-btn.add:hover { background: #93c95e; }
.build-prompt-btn.skip { background: rgba(255,255,255,0.08); color: var(--text-dim); }
.build-prompt-btn.skip:hover { background: rgba(255,255,255,0.14); }

/* ── Explorer ──────────────────────────────────────── */

.section-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-shrink: 0;
    margin-bottom: 2px;
}

.explorer-level-toggle {
    display: inline-flex;
    gap: 0;
    border: 1px solid var(--border, #444);
    border-radius: 4px;
    overflow: hidden;
}

.explorer-level-btn {
    font: inherit;
    font-size: 0.62rem;
    letter-spacing: 0.05em;
    padding: 2px 8px;
    background: transparent;
    color: var(--text-dim);
    border: none;
    cursor: pointer;
    text-transform: uppercase;
}

.explorer-level-btn:hover {
    color: var(--text, #ddd);
}

.explorer-level-btn.active {
    background: var(--accent, #4a7);
    color: #fff;
}

#explorer-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.explorer-moves {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}
.explorer-moves::-webkit-scrollbar { width: 4px; }
.explorer-moves::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.18);
    border-radius: 4px;
}
.explorer-moves::-webkit-scrollbar-track { background: transparent; }

.explorer-loading,
.explorer-empty {
    font-size: 0.82rem;
    color: var(--text-dim);
    padding: 0.3rem 0;
}

.move-row {
    display: grid;
    grid-template-columns: auto 1fr auto auto auto;
    align-items: center;
    gap: 0.3rem;
    padding: 5px 6px;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.1s;
    flex-shrink: 0;
}
.move-row:hover  { background: rgba(255,255,255,0.07); }
.move-row.in-rep { background: rgba(129,182,76,0.1); }
.move-row.dimmed { opacity: 0.45; }
.move-row.dimmed:hover { opacity: 0.75; }

.move-san { font-weight: 700; font-size: 0.88rem; font-family: 'Georgia', serif; position: relative; }
.top-star {
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 2px;
    color: #6fcf3f;
    font-size: 0.72rem;
    font-weight: 700;
    pointer-events: none;
    line-height: 1;
}
.move-num { font-weight: 400; color: var(--text-dim); font-size: 0.78rem; margin-right: 1px; }

.move-stats { display: flex; font-size: 0.72rem; font-variant-numeric: tabular-nums; }
.pct { width: 1.8rem; text-align: right; }
.pct-w { color: #8bc16a; }
.pct-d { color: #9b9488; }
.pct-l { color: #c47458; }

.best-move .pct     { font-weight: 700; }
.best-move .pct-w   { color: #a8e06a; }
.best-move .pct-d   { color: #c8c0b4; }
.best-move .pct-l   { color: #e08060; }

.move-games { font-size: 0.72rem; color: var(--text-dim); text-align: right; }

.rep-mark { font-size: 0.8rem; color: var(--accent); font-weight: 700; min-width: 1rem; text-align: center; display: flex; align-items: center; gap: 0.15rem; }
.rep-mark.hidden { visibility: hidden; }
.rep-warn { font-size: 0.8rem; color: #e0b040; min-width: 1rem; text-align: center; }
.rep-line-count { font-size: 0.7rem; font-weight: 600; opacity: 0.85; }

.rep-btn {
    width: 1.3rem;
    height: 1.3rem;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 3px;
    font-size: 0.85rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    background: transparent;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    justify-content: center;
}
.rep-btn-add:hover    { background: rgba(129,182,76,0.3); color: var(--accent); }
.rep-btn-remove:hover { background: rgba(224,85,85,0.3);  color: var(--danger); }

/* ── Out of prep ───────────────────────────────────── */

.out-of-prep {
    padding: 0.35rem 0.5rem;
    background: rgba(224,176,64,0.12);
    border: 1px solid rgba(224,176,64,0.25);
    border-radius: 5px;
    font-size: 0.78rem;
    font-weight: 600;
    color: #e0b040;
    margin-bottom: 3px;
}

/* ── Practice ──────────────────────────────────────── */

.practice-info {
    padding: 0.4rem 0.6rem;
    background: rgba(100,150,255,0.08);
    border-radius: 6px;
    font-size: 0.82rem;
    flex-shrink: 0;
}
.practice-meta { font-size: 0.72rem; color: var(--text-dim); margin-top: 0.15rem; }

.stats {
    display: flex;
    justify-content: space-around;
    flex-shrink: 0;
    padding: 0.2rem 0;
}
.stat { text-align: center; }
.stat-value { display: block; font-size: 1.2rem; font-weight: 700; }
.stat-label { font-size: 0.7rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }

/* ── Captured pieces ───────────────────────────────── */

.captured-display {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0.3rem 0;
    border-top: 1px solid rgba(255,255,255,0.06);
    margin-top: 0.25rem;
}
.captured-display:empty { display: none; }

.cap-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0;
    min-height: 18px;
}

.cap-icon {
    width: 20px;
    height: 20px;
    opacity: 0.85;
}

.cap-score {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-dim);
    margin-left: 5px;
    align-self: center;
}

/* ── Notes / Trash (menu & desktop panel) ──────────── */

.notes-area {
    width: 100%;
    min-height: 100px;
    max-height: 180px;
    resize: vertical;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.82rem;
    font-family: inherit;
    padding: 0.5rem;
    line-height: 1.4;
}
.notes-area:focus { outline: none; border-color: rgba(255,255,255,0.25); }

.token-toggle {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 0 0.3rem;
    margin-left: 0.3rem;
    opacity: 0.6;
}
.token-toggle:hover { opacity: 1; }

.trash-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 160px;
    overflow-y: auto;
}
.trash-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.5rem;
    background: rgba(255,255,255,0.03);
    border-radius: 4px;
    font-size: 0.78rem;
}
.trash-desc { flex: 1; color: var(--text); }
.trash-ago  { color: var(--text-dim); font-size: 0.7rem; flex-shrink: 0; }
.trash-restore {
    padding: 0.15rem 0.5rem;
    border: 1px solid rgba(129,182,76,0.3);
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    background: transparent;
    color: var(--accent);
    flex-shrink: 0;
}
.trash-restore:hover { background: rgba(129,182,76,0.15); }

.flagged-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 200px;
    overflow-y: auto;
    margin-top: 2px;
}
.flagged-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.5rem;
    background: rgba(255,255,255,0.03);
    border-radius: 4px;
    font-size: 0.78rem;
}
.flagged-line-moves {
    flex: 1;
    color: var(--text);
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.flagged-line-moves:hover { color: var(--accent); }
.flagged-unflag {
    padding: 0.15rem 0.5rem;
    border: 1px solid rgba(255,180,60,0.3);
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    background: transparent;
    color: #ffb43c;
    flex-shrink: 0;
}
.flagged-unflag:hover { background: rgba(255,180,60,0.15); }

.data-management { display: flex; gap: 0.4rem; padding-top: 0.4rem; }
.data-btn {
    padding: 0.2rem 0.5rem;
    border: none;
    border-radius: 3px;
    font-size: 0.65rem;
    cursor: pointer;
    background: transparent;
    color: var(--text-dim);
    opacity: 0.5;
}
.data-btn:hover { opacity: 1; }

/* ── Promotion modal ───────────────────────────────── */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}
.modal.hidden { display: none; }
.modal-content { background: var(--bg-panel); padding: 1.2rem; border-radius: 10px; text-align: center; }
.modal-content h3 { margin-bottom: 0.8rem; font-size: 1rem; }
.promotion-choices { display: flex; gap: 0.5rem; justify-content: center; }
.promotion-choices button {
    width: 3.5rem;
    height: 3.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid rgba(255,255,255,0.15);
    border-radius: 8px;
    background: rgba(255,255,255,0.05);
    cursor: pointer;
}
.promotion-choices button:hover { background: rgba(255,255,255,0.15); }

/* ── Animations ────────────────────────────────────── */

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60%  { transform: translateX(-4px); }
    40%, 80%  { transform: translateX(4px); }
}
.shake { animation: shake 0.3s; }

@keyframes hint-pulse {
    0%, 100% { box-shadow: inset 0 0 0 4px rgba(100, 200, 255, 0.95); }
    50% { box-shadow: inset 0 0 0 4px rgba(100, 200, 255, 0.3); }
}
.square.hint-square { animation: hint-pulse 0.9s ease-in-out infinite; }

.practice-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    flex-wrap: wrap;
}

.hint-btn {
    padding: 0.3rem 0.9rem;
    border: 1px solid rgba(100, 200, 255, 0.3);
    border-radius: 5px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    background: rgba(100, 200, 255, 0.08);
    color: rgba(100, 200, 255, 0.9);
    transition: background 0.15s;
}
.hint-btn:hover { background: rgba(100, 200, 255, 0.18); }

.flag-btn {
    padding: 0.3rem 0.9rem;
    border: 1px solid rgba(255, 180, 60, 0.3);
    border-radius: 5px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    background: rgba(255, 180, 60, 0.06);
    color: rgba(255, 180, 60, 0.8);
    transition: background 0.15s, border-color 0.15s;
}
.flag-btn:hover { background: rgba(255, 180, 60, 0.18); }
.flag-btn-compact {
    padding: 2px 6px;
    font-size: 0.85rem;
    line-height: 1;
    min-width: 26px;
}
.flag-btn.flagged {
    background: rgba(255, 140, 30, 0.22);
    border-color: rgba(255, 140, 30, 0.6);
    color: rgba(255, 160, 50, 1);
}

.practice-line-num {
    font-size: 0.72rem;
    color: var(--text-dim);
    font-family: monospace;
}


.filter-btn {
    padding: 0.25rem 0.65rem;
    border: 1px solid rgba(255, 180, 60, 0.3);
    border-radius: 5px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    background: rgba(255, 180, 60, 0.06);
    color: rgba(255, 180, 60, 0.7);
    transition: background 0.15s, border-color 0.15s;
    margin-left: 0.3rem;
}
.filter-btn:hover { background: rgba(255, 180, 60, 0.15); }
.filter-btn-compact {
    padding: 2px 6px;
    font-size: 0.85rem;
    line-height: 1;
    min-width: 26px;
    margin-left: 0.3rem;
}
.filter-btn.active {
    background: rgba(255, 140, 30, 0.22);
    border-color: rgba(255, 140, 30, 0.6);
    color: rgba(255, 160, 50, 1);
}

.practice-review-btns {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 0 0.1rem;
}
.review-line-btn {
    width: 100%;
    padding: 0.35rem 0.9rem;
    border: 1px solid rgba(180, 220, 140, 0.35);
    border-radius: 6px;
    background: rgba(180, 220, 140, 0.06);
    cursor: pointer;
    font-size: 0.8rem;
    color: rgba(180, 220, 140, 0.9);
    transition: background 0.15s;
    text-align: left;
}
.review-line-btn:hover { background: rgba(180, 220, 140, 0.18); }

.review-line-prompt {
    padding: 0.35rem 0.5rem;
    border: 1px solid rgba(180, 220, 140, 0.35);
    border-radius: 6px;
    background: rgba(180, 220, 140, 0.06);
}
.review-prompt-label {
    display: block;
    font-size: 0.75rem;
    color: rgba(180, 220, 140, 0.7);
    margin-bottom: 0.3rem;
}
.review-prompt-btns {
    display: flex;
    gap: 0.3rem;
}
.review-prompt-btns button {
    flex: 1;
    padding: 0.25rem 0.4rem;
    border: 1px solid rgba(180, 220, 140, 0.3);
    border-radius: 5px;
    background: rgba(180, 220, 140, 0.1);
    cursor: pointer;
    font-size: 0.78rem;
    color: rgba(180, 220, 140, 0.9);
    transition: background 0.15s;
}
.review-prompt-btns button:hover { background: rgba(180, 220, 140, 0.22); }
.review-prompt-cancel { flex: 0 0 auto !important; color: var(--text-dim) !important; border-color: transparent !important; background: transparent !important; }
.review-prompt-cancel:hover { background: rgba(255,255,255,0.08) !important; }

.notes-wrapper { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.notes-toolbar { display: flex; gap: 4px; justify-content: space-between; align-items: center; }
.notes-actions { display: flex; gap: 4px; justify-content: flex-end; }
.notes-gen-btn {
    font: inherit;
    font-size: 0.72rem;
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid rgba(180, 140, 255, 0.35);
    background: rgba(180, 140, 255, 0.08);
    color: rgba(200, 170, 255, 0.9);
    cursor: pointer;
}
.notes-gen-btn:hover:not(:disabled) { background: rgba(180, 140, 255, 0.18); }
.notes-gen-btn:disabled { opacity: 0.5; cursor: progress; }
.notes-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.notes-cancel { background: rgba(224, 85, 85, 0.18); color: var(--danger); }
.notes-cancel:hover { background: rgba(224, 85, 85, 0.35); }
.notes-save { background: rgba(129, 182, 76, 0.18); color: var(--accent); }
.notes-save:hover { background: rgba(129, 182, 76, 0.35); }

/* ── Desktop layout (≥700px) ───────────────────────── */

@media (min-width: 700px) {
    :root {
        --board-size: min(calc(100vw - 340px), calc(100dvh - var(--header-h) - 2rem));
    }

    .desktop-only { display: flex; }
    .nav-bar { display: none; }  /* desktop uses panel nav */

    .app { padding: 0.6rem 1rem; }

    main {
        flex-direction: row;
        align-items: flex-start;
        justify-content: center;
        gap: 1rem;
        overflow: hidden;
    }

    .board-col {
        flex-shrink: 0;
        width: auto;
        align-items: flex-start;
    }

    .panel {
        width: 270px;
        flex-shrink: 0;
        background: var(--bg-panel);
        border-radius: 8px;
        padding: 0.9rem 1rem;
        gap: 0.75rem;
        overflow-y: auto;
        height: fit-content;
        max-height: calc(100dvh - var(--header-h) - 2rem);
    }

    /* Restore desktop panel elements */
    .sub-tabs {
        display: flex;
        gap: 0.2rem;
        background: rgba(255,255,255,0.05);
        padding: 3px;
        border-radius: 7px;
    }

    .sub-tab-btn {
        flex: 1;
        padding: 0.3rem 0.5rem;
        border: none;
        border-radius: 5px;
        font-size: 0.8rem;
        font-weight: 600;
        cursor: pointer;
        background: transparent;
        color: var(--text-dim);
        transition: background 0.15s, color 0.15s;
    }
    .sub-tab-btn.active { background: var(--bg); color: var(--text); }

    .color-selector {
        display: flex;
        align-items: center;
        gap: 0.4rem;
        font-size: 0.85rem;
    }
    .color-sel-label { color: var(--text-dim); flex-shrink: 0; }

    .color-btn {
        padding: 0.25rem 0.7rem;
        border: 1px solid rgba(255,255,255,0.15);
        border-radius: 5px;
        font-size: 0.8rem;
        font-weight: 600;
        cursor: pointer;
        background: transparent;
        color: var(--text-dim);
        transition: background 0.15s, color 0.15s;
    }
    .color-btn.active { background: var(--accent); color: #1a1a1a; border-color: transparent; }

    .opening-nav {
        display: flex;
        gap: 0.4rem;
    }
    .opening-nav button {
        flex: 1;
        padding: 0.4rem;
        border: none;
        border-radius: 6px;
        font-size: 0.8rem;
        font-weight: 600;
        cursor: pointer;
        background: rgba(255,255,255,0.08);
        color: var(--text);
    }
    .opening-nav button:hover { background: rgba(255,255,255,0.14); }

    #explorer-section {
        flex: none;
        overflow: visible;
    }
    .explorer-moves {
        flex: none;
        max-height: 200px;
        overflow-y: auto;
    }
}
