/* OnlineChess — design tokens, layout and components. Dark theme by default. */
:root {
  --bg: #13151b;
  --surface: #1c1f27;
  --surface-2: #252935;
  --surface-3: #2f3442;
  --border: #343a49;
  --text: #e9ebf1;
  --muted: #9ba2b4;
  --accent: #7cc4a4;
  --accent-strong: #5fb08c;
  --accent-ink: #0f2a1f;
  --gold: #f2b84b;
  --danger: #ef6b6b;
  --info: #79a8f2;
  --radius: 14px;
  --radius-sm: 9px;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 24px; --space-6: 36px;
  --line: color-mix(in srgb, var(--border) 70%, transparent);
  --shadow: 0 10px 30px rgb(0 0 0 / 0.35);
  --square-light: #eedcb8;
  --square-dark: #b88762;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f3ee; --surface: #ffffff; --surface-2: #f0ede6; --surface-3: #e6e1d6; --border: #ddd6c8;
    --text: #1f2330; --muted: #5f6577; --accent: #2f8f68; --accent-strong: #267a58; --accent-ink: #ffffff;
    --shadow: 0 10px 30px rgb(40 30 10 / 0.12); color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f5f3ee; --surface: #ffffff; --surface-2: #f0ede6; --surface-3: #e6e1d6; --border: #ddd6c8;
  --text: #1f2330; --muted: #5f6577; --accent: #2f8f68; --accent-strong: #267a58; --accent-ink: #ffffff;
  --shadow: 0 10px 30px rgb(40 30 10 / 0.12); color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background: radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--accent) 10%, transparent), transparent), var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  overflow-x: hidden;
}
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.15; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.skip-link { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 8px; z-index: 50; }
.skip-link:focus { left: 8px; }
.file-banner { background: var(--danger); color: #fff; padding: 10px 16px; text-align: center; font-weight: 600; }

/* ------------------------------------------------------------------ top bar */
/* Room for the phone's status bar and rounded corners when installed full screen (zero in a
   browser tab). */
:root {
  --inset-top: env(safe-area-inset-top, 0px);
  --inset-bottom: env(safe-area-inset-bottom, 0px);
}
body { padding-bottom: var(--inset-bottom); }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: calc(12px + var(--inset-top)) clamp(16px, 4vw, 32px) 12px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.brand { color: var(--text); text-decoration: none; font: 700 1.2rem var(--font-display); display: flex; align-items: center; gap: 8px; }
.brand-mark { color: var(--accent); font-size: 1.5rem; }
.topnav { display: flex; gap: 4px; }
.topnav a { color: var(--muted); text-decoration: none; padding: 6px 12px; border-radius: 999px; font-weight: 600; }
.topnav a:hover, .topnav a.active { color: var(--text); background: var(--surface-2); }
.topnav { align-items: center; }
.site-foot { text-align: center; padding: 8px 16px calc(24px + env(safe-area-inset-bottom)); font-size: 0.875rem; }
.site-foot a { color: var(--muted); text-decoration: none; }
.site-foot a:hover { color: var(--text); }
.icon-btn { font-size: 1.2rem; line-height: 1; color: var(--muted); background: none; border: 0; border-radius: 999px; padding: 6px 10px; cursor: pointer; }
.icon-btn:hover { color: var(--text); background: var(--surface-2); }
main:focus { outline: none; }

/* ------------------------------------------------------------------ pages */
.page { max-width: 1040px; margin: 0 auto; padding: clamp(20px, 5vw, 48px) 16px; }
.page.doc { max-width: 720px; line-height: 1.6; }
.page.doc h2 { margin-top: var(--space-5); }
.page.doc ul { padding-left: 1.2em; }
.lede { color: var(--muted); font-size: 1.05rem; margin: 0; }

.crumbs { color: var(--muted); font-size: .9rem; margin-bottom: 8px; }
.menu h1 { font-size: clamp(1.7rem, 4vw, 2.1rem); margin-bottom: var(--space-5); }
.menu-section { margin-bottom: var(--space-6); }
.menu-section h2 { font-size: 1.15rem; color: var(--muted); }
.option-list { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.option-card {
  position: relative;
  display: flex; align-items: center; gap: 14px; padding: 16px 18px;
  border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border);
  color: var(--text); text-decoration: none; transition: border-color .15s, transform .15s;
}
a.option-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.option-card.disabled { opacity: .62; }
.option-icon { font-size: 1.8rem; width: 2.2rem; text-align: center; flex: none; }
.option-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.option-card .badge { position: absolute; top: 10px; right: 12px; }
.option-card.disabled .option-text > :first-child { padding-right: 96px; }
.badge { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; padding: 3px 8px; border-radius: 999px; background: var(--surface-3); color: var(--muted); white-space: nowrap; }

/* ------------------------------------------------------------------ buttons */
.btn {
  font: 600 .95rem var(--font); color: var(--text); cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 14px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover:not(:disabled) { background: var(--surface-3); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: var(--accent-strong); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-small { padding: 5px 10px; font-size: .85rem; }
.btn-danger-text { color: var(--danger); }
label.check { display: flex; align-items: center; gap: var(--space-2); margin: var(--space-2) 0; }
.btn-report { padding: 2px 8px; font-size: .78rem; }
.btn.attention { border-color: var(--gold); box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 30%, transparent); }

/* ------------------------------------------------------------------ game */
.game {
  display: grid; gap: 24px; justify-content: center; align-items: start;
  grid-template-columns: minmax(0, min(76vh, 640px)) minmax(280px, 380px);
  padding: 20px 16px 32px; max-width: 1100px; margin: 0 auto;
}
.game-board-col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.board-host { width: 100%; aspect-ratio: 1; touch-action: none; user-select: none; border-radius: 6px; overflow: hidden; box-shadow: var(--shadow); }
.game-side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.game-side-head { display: flex; flex-direction: column; gap: 8px; }
.game-title { font-size: 1.3rem; margin: 0; }

.player-card { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); min-height: 54px; }
.player-card.to-move { border-color: var(--accent); }
.avatar { font-size: 1.6rem; width: 2rem; text-align: center; }
.player-info { flex: 1; min-width: 0; }
.player-line { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.turn-dot { width: 8px; height: 8px; border-radius: 50%; background: transparent; }
.to-move .turn-dot { background: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 25%, transparent); }
.player-material { display: flex; align-items: center; gap: 6px; min-height: 1.2em; color: var(--muted); font-size: .95rem; }
.captured { display: flex; flex-wrap: wrap; letter-spacing: -2px; }
.no-captures { letter-spacing: normal; font-size: .82rem; opacity: .75; }
.material-adv { font-weight: 700; font-size: .8rem; color: var(--muted); }
.clock {
  font: 700 1.35rem ui-monospace, SFMono-Regular, Menlo, monospace; font-variant-numeric: tabular-nums;
  padding: 4px 12px; border-radius: 8px; background: var(--surface-2); color: var(--muted); min-width: 5.2ch; text-align: center;
}
.clock[hidden] { display: none; }
.clock.running { background: var(--text); color: var(--bg); }
.clock.low { color: #fff; background: #b42318; } /* 6.5:1 with white */
.clock.low.running { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { filter: brightness(1.25); } }

/* ------------------------------------------------------------------ settings & setup */
.setting-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding: 10px 0; border: 0; border-bottom: 1px solid var(--border); margin: 0; min-width: 0; }
.setting-row > * { min-width: 0; }
.setting-row > :first-child { flex: 1 1 10rem; } /* the label takes the room; controls wrap below only when it runs out */
.setting-row > :last-child { flex: none; max-width: 100%; }
.setting-row:last-child { border-bottom: 0; }
.setting-row.inline { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; background: var(--surface); margin: 8px 0 20px; }
.setting-text { display: flex; flex-direction: column; font-size: .95rem; padding: 0; }
.setting-text .muted { font-size: .82rem; }
.segmented { flex-wrap: wrap; }
.segments { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; }
.segment input { position: absolute; opacity: 0; pointer-events: none; }
.segment span { display: block; padding: 5px 12px; border-radius: 999px; font-size: .85rem; font-weight: 600; cursor: pointer; color: var(--muted); }
.segment input:checked + span { background: var(--accent); color: var(--accent-ink); }
.segment input:focus-visible + span { outline: 3px solid var(--gold); }
.switch { position: relative; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; width: 100%; height: 100%; }
.switch-track { display: block; width: 44px; height: 26px; border-radius: 999px; background: var(--surface-3); transition: background .15s; position: relative; }
.switch-track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--gold); outline-offset: 2px; }
.modal.settings { width: min(480px, 100%); }
@media (max-width: 520px) { .modal { padding: 18px 16px; } }

.tc-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 560px; }
.tc-option:first-child { grid-column: 1 / -1; flex-direction: row; justify-content: center; gap: 10px; }
.setup { max-width: 640px; }
@media (max-width: 420px) { .tc-grid { grid-template-columns: repeat(2, 1fr); } }
.tc-option { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 14px 8px; border-radius: var(--radius); background: var(--surface); border: 2px solid var(--border); cursor: pointer; }
.tc-option input { position: absolute; opacity: 0; pointer-events: none; }
.tc-option:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.tc-option:has(input:focus-visible) { outline: 3px solid var(--gold); }
.tc-label { font: 700 1.15rem var(--font); }
.tc-kind { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.setup-actions { display: flex; justify-content: flex-end; }
.setup.setup-wide { max-width: 1040px; }
.persona-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 180px), 1fr)); gap: 12px; }
.persona-card {
  position: relative; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px;
  padding: 18px 12px 16px; border-radius: var(--radius); background: var(--surface); border: 2px solid var(--border);
  cursor: pointer; transition: border-color .15s, transform .15s;
}
.persona-card:hover { transform: translateY(-2px); }
.persona-card input { position: absolute; opacity: 0; pointer-events: none; }
.persona-card:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.persona-card:has(input:focus-visible) { outline: 3px solid var(--gold); }
.persona-avatar { font-size: 2.6rem; line-height: 1.2; }
.persona-level { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }
.persona-name { font-size: 1.05rem; }
.persona-rating { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.persona-tagline { font-size: .85rem; color: var(--muted); margin-top: 4px; }
.credits { text-align: center; font-size: .85rem; margin-top: 40px; }

.text-input {
  width: min(360px, 100%); font: 1rem var(--font); color: var(--text); background: var(--surface);
  border: 2px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px;
}
.text-input:focus { border-color: var(--accent); outline: none; }
.join-form { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.session-extras { display: flex; flex-direction: column; gap: 10px; }
.session-extras:empty { display: none; }
.invite { display: flex; flex-direction: column; gap: 6px; padding: 12px; border-radius: var(--radius-sm); border: 1px dashed var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.invite-row { display: flex; gap: 6px; }
.room-link { flex: 1; min-width: 0; font: .85rem ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; }
.emotes { display: flex; flex-wrap: wrap; gap: 6px; }
.abandon { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--gold); }
.feed-emote { background: color-mix(in srgb, var(--info) 14%, var(--surface-2)); }
.feed-coach { background: color-mix(in srgb, var(--info) 10%, var(--surface-2)); }

.coach-panel { display: flex; flex-direction: column; gap: 6px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--info); }
.coach-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.coach-avatar { font-size: 1.4rem; }
.coach-grade { margin-left: auto; font-size: .82rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--surface-3); }
.coach-grade[data-grade="great"], .coach-grade[data-grade="best"] { background: #1f7a4d; color: #fff; }
.coach-grade[data-grade="excellent"], .coach-grade[data-grade="good"] { background: color-mix(in srgb, var(--accent) 30%, var(--surface-3)); }
.coach-grade[data-grade="inaccuracy"] { background: #f2b84b; color: #2b1d00; }
.coach-grade[data-grade="mistake"] { background: #e8833a; color: #2b1300; }
.coach-grade[data-grade="blunder"] { background: #b42318; color: #fff; }
.coach-headline { margin: 0; font-weight: 600; }
.coach-points { margin: 0; padding-left: 1.1rem; display: flex; flex-direction: column; gap: 4px; font-size: .93rem; }
.coach-points li[data-kind="allowed"], .coach-points li[data-kind="warning"] { color: color-mix(in srgb, var(--danger) 70%, var(--text)); }
.coach-points li[data-kind="praise"]::marker { content: '✓ '; }
.coach-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.coach-threat { margin: 0; padding: 6px 10px; border-radius: 8px; background: color-mix(in srgb, var(--gold) 18%, var(--surface)); font-weight: 600; }
.summary { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); text-align: center; }
.summary-accuracy { font-size: 1.1rem; }
.summary-grades { list-style: none; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; font-size: .9rem; color: var(--muted); }
@media (max-width: 900px) { .session-extras { order: 3; } }

.feed-bot { background: color-mix(in srgb, var(--accent) 14%, var(--surface-2)); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); border-radius: 12px 12px 12px 4px; }
.feed-bot .feed-text { font-weight: 500; }
.feed-taunt {
  background: color-mix(in srgb, var(--gold) 16%, var(--surface-2));
  border: 1px solid color-mix(in srgb, var(--gold) 45%, transparent);
  border-radius: 12px 12px 12px 4px;
  animation: pop-in .25s ease-out;
}
.feed-taunt .feed-text { font-weight: 600; }
@keyframes pop-in { from { transform: scale(.92); opacity: 0; } to { transform: none; opacity: 1; } }
.btn-large { padding: 12px 28px; font-size: 1.05rem; }

.status-banner { padding: 10px 14px; border-radius: var(--radius-sm); background: var(--surface-2); font-weight: 700; border-left: 4px solid var(--accent); }
.status-banner.check { border-left-color: var(--danger); }
.status-banner.over { border-left-color: var(--gold); }
.draw-offer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-radius: var(--radius-sm); background: color-mix(in srgb, var(--gold) 16%, var(--surface)); border: 1px solid var(--gold); }
.draw-offer[hidden] { display: none; }
.draw-actions { display: flex; gap: 6px; }

.moves-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.move-list { list-style: none; margin: 0; padding: 6px; max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; }
.move-list:empty::before { content: 'No moves yet.'; color: var(--muted); font-size: .9rem; padding: 4px 8px; }
.move-row { display: grid; grid-template-columns: 2.6rem 1fr 1fr; align-items: center; }
.move-num { color: var(--muted); font-size: .85rem; text-align: right; padding-right: 8px; }
.move-item { font: 600 .95rem var(--font); color: var(--text); background: none; border: 0; text-align: left; padding: 4px 8px; border-radius: 6px; cursor: pointer; }
.move-item:hover { background: var(--surface-2); }
.move-item.active { background: color-mix(in srgb, var(--accent) 24%, transparent); }
.move-item.placeholder { color: var(--muted); cursor: default; }
.review-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; background: color-mix(in srgb, var(--info) 15%, var(--surface)); border-top: 1px solid var(--border); font-size: .9rem; }
.review-bar[hidden] { display: none; }

.feed { list-style: none; margin: 0; padding: 8px; display: flex; flex-direction: column; gap: 6px; max-height: 200px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.feed:empty { display: none; }
.feed-item { display: flex; gap: 8px; align-items: flex-start; font-size: .92rem; padding: 6px 8px; border-radius: 8px; background: var(--surface-2); }
.feed-system { color: var(--muted); background: transparent; }
.feed-avatar { font-size: 1.2rem; line-height: 1.2; }

.controls { display: flex; flex-direction: column; gap: 8px; }
.control-group { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
.btn-control { white-space: nowrap; padding: 9px 8px; }
.btn-control .icon { font-size: 1rem; }

/* Narrow screens: status above the board, controls right below it, history after. */
@media (max-width: 900px) {
  .topbar { position: static; }
  .game { display: flex; flex-direction: column; align-items: stretch; gap: 10px; max-width: 640px; padding: 10px 16px 24px; }
  .game-side { display: contents; }
  .game-side-head { order: 0; }
  .game-title { display: none; }
  .game-board-col { order: 1; gap: 6px; }
  .draw-offer { order: 2; }
  .controls { order: 3; }
  .moves-panel { order: 4; }
  .feed { order: 5; max-height: 140px; }
  .move-list { flex-direction: row; flex-wrap: wrap; max-height: 120px; }
  .move-row { display: flex; }
  .move-num { padding-right: 2px; }
  .player-card { min-height: 44px; padding: 6px 10px; }
  .control-group { gap: 6px; }
  .btn-control { flex-direction: column; gap: 0; font-size: .78rem; padding: 6px 4px; }
}
html { scroll-padding-top: 72px; }

/* ------------------------------------------------------------------ board theme */
.cm-chessboard.oc .board .square.white { fill: var(--square-light); }
.cm-chessboard.oc .board .square.black { fill: var(--square-dark); }
.cm-chessboard.oc .board .border { fill: var(--square-dark); stroke: none; }
.cm-chessboard.oc .coordinates .coordinate { font-weight: 700; font-size: 7px; }
.cm-chessboard.oc .coordinates .coordinate.white { fill: var(--square-dark); }
.cm-chessboard.oc .coordinates .coordinate.black { fill: var(--square-light); }
.cm-chessboard .markers .marker.marker-selected { fill: #7cc4a4; opacity: .55; }
.cm-chessboard .markers .marker.marker-last-move { fill: #f7d354; opacity: .42; }
.cm-chessboard .markers .marker.marker-check { fill: #e5484d; opacity: .62; }
.cm-chessboard .markers .marker.marker-hint { fill: #79a8f2; opacity: .55; }
.cm-chessboard .markers .marker.marker-dot { fill: #1a1a1a; opacity: .28; }
.cm-chessboard .markers .marker.marker-bevel { fill: #1a1a1a; opacity: .28; }

/* ------------------------------------------------------------------ modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  padding: max(16px, var(--inset-top)) 16px max(16px, var(--inset-bottom));
  background: rgb(5 8 12 / .55); opacity: 0; transition: opacity .15s ease;
}
.modal-backdrop.show { opacity: 1; }
.modal-backdrop:not(.show) { pointer-events: none; } /* a closing dialog must not swallow clicks */
.modal {
  width: min(440px, 100%); min-width: 0; box-sizing: border-box; background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  padding: 22px; box-shadow: var(--shadow); transform: translateY(8px) scale(.98); transition: transform .18s ease;
  /* Never larger than the screen: a tall dialog (Settings on a phone) scrolls inside itself. */
  max-height: 100%; overflow-y: auto; overscroll-behavior: contain;
}
.modal-backdrop.show .modal { transform: none; }
.modal-title { font-size: 1.5rem; }
.modal-body p { margin: .4rem 0; }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.game-over .modal-title { text-align: center; font-size: 2rem; }
.result-score { text-align: center; font: 700 2.4rem var(--font-display); margin: .2rem 0 !important; }
.result-reason { text-align: center; font-weight: 700; }
.rule-note { text-align: center; font-size: .92rem; }
.game-over .modal-actions { justify-content: center; }
.promotion .modal-actions { display: grid; grid-template-columns: repeat(4, 1fr); }
.promo-choice { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .78rem; }
.promo-choice .glyph { font-size: 2.2rem; line-height: 1.1; }
.copy-area { width: 100%; font: .85rem ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px; }

/* ------------------------------------------------------------------ toast */
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 200; width: min(420px, calc(100% - 32px)); }
.toast { padding: 10px 14px; border-radius: 10px; background: var(--surface-3); border: 1px solid var(--border); box-shadow: var(--shadow); opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: none; }
.toast-warn { border-color: var(--gold); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
}

/* ------------------------------------------------------------------ lessons & rules */
.track-progress { font: 600 .9rem var(--font); color: var(--accent); }
.lesson-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); gap: 10px; }
.lesson-card { position: relative; display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); color: var(--text); text-decoration: none; transition: border-color .15s, transform .15s; }
.lesson-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.lesson-card.done { border-color: color-mix(in srgb, var(--accent) 60%, var(--border)); }
.lesson-kind { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.lesson-done { position: absolute; top: 10px; right: 12px; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.lesson-panel { display: flex; flex-direction: column; gap: 12px; padding: 14px 16px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); }
.lesson-text { font-size: 1.05rem; margin: 0; }
.lesson-to-move { margin: 0; font-weight: 700; }
.lesson-feedback { margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); }
.lesson-wrong { background: color-mix(in srgb, var(--danger) 16%, var(--surface)); }
.lesson-good { background: color-mix(in srgb, var(--accent) 16%, var(--surface)); }
.lesson-success { background: color-mix(in srgb, var(--accent) 24%, var(--surface)); font-weight: 600; }
.lesson-hint { margin: 0; }
.lesson-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.lesson-step-count { margin: 0; font-size: .85rem; }
.rules-toc { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 20px; }
.rules-section { display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 20px; align-items: start; padding: 18px 0; border-top: 1px solid var(--border); }
.rules-section h2 { font-size: 1.3rem; }
.rules-board { width: 220px; aspect-ratio: 1; border-radius: 6px; overflow: hidden; }
.rules-practice { font-weight: 600; }
@media (max-width: 700px) { .rules-section { grid-template-columns: minmax(0, 1fr); } .rules-board { width: min(260px, 100%); } }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Lessons and openings on narrow screens: title, then the board, then the instructions. */
@media (max-width: 900px) {
  .game.lesson .crumbs { order: 0; }
  .game.lesson .game-title { display: block; order: 0; font-size: 1.15rem; margin: 0; }
  .game.lesson .opening-side, .game.lesson .tabs { order: 0; }
  .game.lesson .lesson-panel { order: 2; }
}
.tabs { display: flex; gap: 6px; }
.tab { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.tab.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.opening-side { margin: 0; }
.opening-ideas { margin: 8px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.opening-badge { margin: 0; font-size: .85rem; color: var(--muted); }
.opening-badge a { color: inherit; }
.playout-moves { margin: 0; font-size: .9rem; }

/* Progress: dashboard, rank, profile, achievements, confetti */
.rank-block { display: flex; align-items: center; gap: 12px; }
.rank-icon { font-size: 2.2rem; line-height: 1; }
.rank-info { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.xp-bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.xp-bar > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.records { width: 100%; border-collapse: collapse; }
.records th, .records td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
.achievements { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 10px; }
.achievement { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); opacity: .6; }
.achievement.unlocked { opacity: 1; border-color: color-mix(in srgb, var(--gold) 60%, var(--border)); }
.achievement > span:last-child { display: flex; flex-direction: column; gap: 2px; }
.ach-icon { font-size: 1.5rem; line-height: 1; }
.daily-streak { margin: 0; }
.toast-xp { border-color: var(--accent); font-weight: 600; }
.toast-achievement { border-color: var(--gold); font-weight: 600; }
.confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 300; }
.toasts { pointer-events: none; }
@media (max-width: 440px) {
  .topbar { padding-left: 12px; padding-right: 12px; gap: 6px; }
  .brand { font-size: 1rem; gap: 4px; }
  .brand-mark { font-size: 1.25rem; }
  .topnav { gap: 0; }
  .topnav a { padding: 6px 7px; }
}

/* Game review */
.review-panel { display: flex; flex-direction: column; gap: 12px; }
.review-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.acc-card { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); }
.acc-card.you { border-color: var(--accent); }
.acc-card strong { font-size: 1.6rem; }
.acc-counts { display: flex; flex-wrap: wrap; gap: 6px; font-size: .8rem; color: var(--muted); }
.eval-graph { width: 100%; height: 70px; border-radius: 8px; cursor: pointer; display: block; }
.eg-bg { fill: #2b2b2b; }
.eg-white { fill: #e9e6df; }
.eg-mid { stroke: var(--muted); stroke-width: .5; stroke-dasharray: 3 3; }
.eg-key { fill: var(--danger); }
.eg-cursor { stroke: var(--accent); stroke-width: 2; }
.key-moments { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.review-current { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); }
.review-current p { margin: 0; }
.review-nav { display: flex; gap: 6px; }
.review-moves { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; max-height: 220px; overflow: auto; }
.rv-move { font: inherit; padding: 3px 7px; border-radius: 6px; border: 1px solid transparent; background: none; color: var(--text); cursor: pointer; }
.rv-move.current { background: var(--accent); color: var(--accent-ink); }
.rv-move[data-grade="blunder"], .rv-move[data-grade="mistake"] { color: var(--danger); }
.rv-move.current[data-grade] { color: var(--accent-ink); }
.game-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.game-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); color: var(--text); text-decoration: none; }
.game-row:hover { border-color: var(--accent); }
.game-row-main { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.game-row-result { font-weight: 700; }
@media (max-width: 900px) { .game.review .review-panel { order: 2; } .game.review .crumbs { order: 0; } }

/* Puzzles and Rush */
.puzzle-rating { margin: 0; }
.rating-change { font-weight: 700; margin-left: 4px; }
.rating-change.up { color: var(--accent); }
.rating-change.down { color: var(--danger); }
.theme-filter summary { cursor: pointer; color: var(--muted); }
.theme-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.rush-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 1.1rem; }
.rush-timer { font: 700 1.6rem var(--font-mono, ui-monospace, monospace); }
.rush-strikes { letter-spacing: 4px; color: var(--danger); }
.small { font-size: .8rem; }

/* Campaign and cosmetics */
.campaign-path { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; position: relative; }
.campaign-stop { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 14px 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); }
.campaign-stop.locked { opacity: .65; }
.stop-avatar { font-size: 2rem; line-height: 1; width: 44px; text-align: center; }
.stop-info { display: flex; flex-direction: column; gap: 2px; flex: 1 1 160px; min-width: 0; }
.campaign-stop > .muted.small { flex-basis: 100%; }
.stop-stars { font-size: 1.2rem; letter-spacing: 2px; }
.star { color: var(--muted); }
.star.on { color: var(--gold); }
.setting-row select { font: inherit; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); max-width: 55%; }

/* Weekly quests */
.quest-list { list-style: none; padding: 0; margin: 4px 0; display: flex; flex-direction: column; gap: 8px; }
.quest { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; }
.quest .xp-bar { grid-column: 1 / -1; height: 6px; }
.quest.done .quest-text { color: var(--muted); }

/* Install and update banners */
.update-banner { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 210; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; border-radius: 12px; background: var(--surface-3); border: 1px solid var(--accent); box-shadow: var(--shadow); width: min(520px, calc(100% - 32px)); }
.update-banner span { flex: 1; min-width: 180px; }

/* Account */
.account-form { display: flex; flex-direction: column; gap: 10px; max-width: 360px; }
.field { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
.field .muted.small { font-weight: 400; }
.btn-link { background: none; border: 0; padding: 4px 0; color: var(--accent); font: inherit; text-decoration: underline; cursor: pointer; }
.btn-link:hover { color: var(--accent-strong, var(--accent)); }
.account-alt { margin: var(--space-2) 0 0; color: var(--muted); }
.account-nudge { padding: var(--space-3); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px; }
.auth-link .btn { margin-top: var(--space-3); }
.btn-google { display: inline-flex; align-items: center; gap: 10px; background: #fff; color: #1f1f1f; border: 1px solid #747775; font-weight: 600; text-decoration: none; max-width: 360px; justify-content: center; }
.btn-google:hover { background: #f2f2f2; }
.btn-google:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.account-start .btn-google { width: 100%; box-sizing: border-box; }
.or-line { display: flex; align-items: center; gap: var(--space-2); max-width: 360px; color: var(--muted); margin: var(--space-3) 0; }
.or-line::before, .or-line::after { content: ''; flex: 1; border-top: 1px solid var(--line); }
.form-error { margin: 0; color: var(--danger); }
.field.inline { flex-direction: row; align-items: center; gap: 8px; }

/* Weekly challenge */
.puzzle-tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.puzzle-tile { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 4px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.puzzle-tile.right { border-color: var(--accent); }
.puzzle-tile.wrong { border-color: var(--danger); opacity: .8; }
.weekly-solver { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; max-width: 480px; }
.weekly-board { max-width: 480px; }
.records tr.me { background: color-mix(in srgb, var(--accent) 14%, transparent); }

/* ------------------------------------------------------------ calmer layout (declutter pass) */
.section-label { font: 700 .74rem/1.2 var(--font); text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 0 0 var(--space-3); }
.menu-section h2.section-label { font-size: .74rem; }

/* Home */
.home { max-width: 760px; }
.home-head { margin: var(--space-4) 0 var(--space-5); }
.home-head h1 { font-size: clamp(1.9rem, 5vw, 2.6rem); margin-bottom: var(--space-2); }
.home-actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); margin-bottom: var(--space-6); }
.mode-btn { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-radius: var(--radius); background: var(--accent); color: var(--accent-ink); text-decoration: none; transition: background .15s, transform .15s; }
.mode-btn:hover { background: var(--accent-strong); transform: translateY(-1px); }
.mode-btn > span:last-child { display: flex; flex-direction: column; }
.mode-btn strong { font-size: 1.15rem; }
.mode-btn .muted { color: inherit; opacity: .85; font-size: .88rem; }
.mode-btn.training { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.mode-btn.training:hover { background: var(--surface-2); }
.mode-btn.training .muted { color: var(--muted); opacity: 1; }
.mode-btn-icon { font-size: 2rem; line-height: 1; }
.today-panel { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-5); border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.today-row { display: flex; align-items: center; gap: var(--space-3); color: var(--text); text-decoration: none; padding: var(--space-2) 0; }
.today-row:hover strong { color: var(--accent); }
.today-icon { width: 2rem; text-align: center; font-size: 1.3rem; flex: none; }
.today-row.done .today-icon { color: var(--accent); font-weight: 700; }
.today-main { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.today-main .muted { font-size: .9rem; }
.today-side { font-size: .9rem; color: var(--muted); white-space: nowrap; }
.today-quests { border-top: 1px solid var(--line); padding-top: var(--space-3); }
.today-quests-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-2); }
.today-quests .quest-list { gap: var(--space-2); }
.today-quests .quest { font-size: .92rem; }
.today-cta { align-self: flex-start; margin-top: var(--space-1); }
.shortcuts { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: var(--space-4) 0 var(--space-6); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--text); text-decoration: none; font: inherit; font-size: .9rem; cursor: pointer; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip:hover { border-color: var(--accent); }
.credits { font-size: .82rem; text-align: center; }
@media (max-width: 520px) {
  .home-actions { grid-template-columns: 1fr; }
  .today-panel { padding: var(--space-4); }
  .today-side { display: none; }
}

/* Menus: tiles in groups */
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); gap: var(--space-2); }
.tile { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--line); color: var(--text); text-decoration: none; min-height: 64px; transition: border-color .15s; }
.tile:hover { border-color: var(--accent); }
.tile-icon { font-size: 1.4rem; width: 1.8rem; text-align: center; flex: none; }
.tile-text { display: flex; flex-direction: column; min-width: 0; }
.tile-text .muted { font-size: .86rem; }
.tile-eyebrow { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* Top bar: the profile link shows rank and XP */
.nav-rank { display: inline-flex; align-items: center; gap: 6px; }
.nav-rank-icon { font-size: 1.05rem; }
.nav-rank-xp { color: var(--muted); font-weight: 500; }
@media (max-width: 440px) { .nav-rank-name { display: none; } }

/* Game screen: slimmer player bars, a More menu */
.player-card { min-height: 44px; padding: 6px 12px; border-color: var(--line); }
.more-menu { position: relative; display: flex; }
.more-menu > summary { list-style: none; cursor: pointer; flex: 1; }
.more-menu > summary::-webkit-details-marker { display: none; }
.more-items { position: absolute; right: 0; bottom: calc(100% + 6px); z-index: 30; display: flex; flex-direction: column; gap: 4px; padding: 6px; min-width: 160px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); }
.more-items .btn-control { justify-content: flex-start; }

/* Lighter cards everywhere */
.option-card, .lesson-card, .achievement, .campaign-stop, .game-row, .acc-card, .review-current, .lesson-panel { border-color: var(--line); }

/* Profile */
.profile { max-width: 860px; }
.profile-overview { display: flex; flex-direction: column; gap: var(--space-4); padding: var(--space-5); border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: var(--space-3); }
.stat { display: flex; flex-direction: column; }
.stat strong { font-size: 1.35rem; }
.stat .muted { font-size: .8rem; }
.locked-achievements { margin-top: var(--space-3); }
.locked-achievements summary { cursor: pointer; color: var(--muted); padding: var(--space-2) 0; }
.locked-achievements .achievements { margin-top: var(--space-2); }
a.btn { text-decoration: none; }
.quest-text { display: inline-flex; align-items: center; gap: 8px; }
.quest-check { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 4px; border: 1.5px solid var(--border); font-size: .7rem; font-weight: 800; flex: none; }
.quest-check.done { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.player-material:empty { display: none; }
.player-material:has(.captured:empty):has(.material-adv:empty) { display: none; }

/* ------------------------------------------------------------------ friends */
.friend-list { list-style: none; padding: 0; margin: 0; }
.friend-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.friend-row:last-child { border-bottom: 0; }
.friend-name { display: flex; flex-direction: column; min-width: 0; }
.friend-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.friend-code { display: flex; align-items: center; gap: 12px; font-size: 1.4rem; letter-spacing: .06em; margin: 4px 0; }
.presence { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--muted); }
.presence-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.presence.online .presence-dot { background: #2fb36b; }
.presence.playing .presence-dot { background: #e0a526; }
.nav-friends { position: relative; display: inline-flex; align-items: center; text-decoration: none; font-size: 1.1rem; padding: 4px 6px; }
.nav-badge { position: absolute; top: -2px; right: -4px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: #d9493a; color: #fff; font: 700 .7rem/16px system-ui, sans-serif; text-align: center; }
