:root {
  --accent: #4f6675; --accent-dark: #3d505c; --bg: #eef1f3; --card: #fff; --fg: #1c1c1e; --muted: #6e6e73;
  --line: #e5e5ea; --light: #dee3e6; --dark: #8ca2ad; --sel: rgba(79, 102, 117, 0.45);
  --last: rgba(255, 190, 40, 0.55); --last-engine: rgba(220, 60, 60, 0.32); --dot: rgba(0, 0, 0, 0.5);
  --mark-mistake: #9c5d00; --mark-blunder: #c0392b;
  --arrow-suggestion: rgba(23, 138, 61, 0.85); --arrow-reply: rgba(211, 47, 47, 0.85); --arrow-edge: rgba(255, 255, 255, 0.75);
  --last-mistake: rgba(156, 93, 0, 0.45); --last-blunder: rgba(192, 57, 43, 0.5);
}
/* The pages are light only today; a dark theme sets data-theme="dark" on
   the root and these keep the analysis marks readable on dark cards. */
:root[data-theme="dark"] { --mark-mistake: #f0a640; --mark-blunder: #ff7b6b; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 16px/1.45 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--fg); }
a { color: var(--accent); }
main { max-width: 1100px; margin: 0 auto; padding: 1rem; display: grid; gap: 1rem; }
.foot { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 1.5rem 1rem; }

/* header + tabs */
.top { background: var(--card); border-bottom: 1px solid var(--line); padding: 0.5rem 1rem; display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; font-size: 1.1rem; text-decoration: none; color: var(--fg); }
.brand-logo { width: 28px; height: 28px; border-radius: 7px; }
.tabs { display: flex; gap: 0.25rem; }
.tab { padding: 0.45rem 0.9rem; border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 600; }
.tab.active { background: var(--accent); color: #fff; }
.tab:hover:not(.active) { background: var(--bg); }
.account-link { margin-left: auto; font-weight: 600; }
.account-link a { color: var(--accent); text-decoration: none; }
.code-input { font-size: 32px; letter-spacing: 8px; font-family: ui-monospace, Menlo, monospace; width: 9ch; text-align: center; padding: 0.4rem 0.6rem; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.card input[type=email] { font: inherit; padding: 0.55rem 0.7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.row { display: flex; gap: 1rem; margin: 0; align-items: baseline; }
.muted { color: var(--muted); min-width: 6rem; }
.sessions, .games { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.sessions th, .games th { text-align: left; color: var(--muted); font-weight: 600; padding: 0.3rem 0.4rem; }
.sessions td, .games td { padding: 0.4rem; border-top: 1px solid var(--line); }
.badge { font-size: 0.75rem; background: var(--accent); color: #fff; border-radius: 999px; padding: 0.1rem 0.5rem; margin-left: 0.3rem; }
.actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.danger { background: #b3261e; }

/* hero */
.hero { display: flex; align-items: center; gap: 1rem; padding: 0.5rem 0.25rem 0; }
.hero-logo { width: 64px; height: 64px; border-radius: 14px; box-shadow: 0 2px 6px rgba(0,0,0,0.15); }
.hero h1 { margin: 0; font-size: 1.5rem; }
.hero p { margin: 0.1rem 0 0; color: var(--muted); }

/* cards + controls */
.card { background: var(--card); border-radius: 16px; padding: 1.1rem 1.1rem 1.2rem; display: flex; flex-direction: column; gap: 0.9rem; max-width: 640px; width: 100%; }
.card h2 { margin: 0; font-size: 1.05rem; }
.card label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; color: var(--muted); }
.card label.option { flex-direction: row; align-items: center; gap: 0.5rem; color: var(--fg); font-size: 1rem; }
.card input[type=number], .card input[type=text] { font: inherit; padding: 0.55rem 0.7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.code-input { text-transform: uppercase; letter-spacing: 0.25em; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.2rem; }
.fields { display: flex; flex-direction: column; gap: 0.75rem; }
.hint { margin: 0; font-size: 0.85rem; color: var(--muted); }
.error { background: #fde8e8; border: 1px solid #f5b5b5; padding: 0.6rem 1rem; border-radius: 12px; max-width: 640px; margin: 0; }
.notice { background: #fff; background: color-mix(in srgb, var(--accent) 10%, #fff); border: 1px solid var(--line); border-color: color-mix(in srgb, var(--accent) 35%, #fff); padding: 0.6rem 1rem; border-radius: 12px; max-width: 640px; margin: 0; }

.segmented { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; }
.segmented label { flex: 1; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; width: 0; height: 0; }
.segmented span { display: block; text-align: center; padding: 0.4rem 0; border-radius: 8px; font-weight: 600; color: var(--fg); }
.segmented input:checked + span { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,0.15); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }

.strength { display: flex; justify-content: space-between; align-items: baseline; }
.strength-label { color: var(--muted); }
.strength-value { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); }
.range-ends { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--muted); }

button { font: inherit; padding: 0.5rem 0.9rem; border-radius: 10px; border: 1px solid var(--accent); background: var(--accent); color: #fff; cursor: pointer; }
button.primary { width: 100%; padding: 0.75rem; font-weight: 700; font-size: 1.05rem; border-radius: 12px; }
button.secondary { background: var(--card); color: var(--accent); }
button:disabled { opacity: 0.5; cursor: default; }
button:hover:not(:disabled) { filter: brightness(1.08); }
@supports (color: color-mix(in srgb, red, blue)) { :root { --sel: color-mix(in srgb, var(--accent) 45%, transparent); } }

/* game */
.game { display: grid; gap: 1rem; grid-template-columns: minmax(280px, 640px) minmax(240px, 1fr); align-items: start; }
@media (max-width: 760px) { .game { grid-template-columns: 1fr; } .tabs { width: 100%; justify-content: space-between; } }
.board-wrap { display: flex; flex-direction: column; gap: 0.5rem; }
.board { position: relative; display: grid; grid-template-columns: repeat(8, 1fr); aspect-ratio: 1 / 1; width: 100%; border-radius: 8px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.15); user-select: none; }
.sq { position: relative; aspect-ratio: 1 / 1; display: flex; align-items: center; justify-content: center; }
.sq.light { background: var(--light); }
.sq.dark { background: var(--dark); }
.sq.last { box-shadow: inset 0 0 0 100px var(--last); }
.sq.last.engine { box-shadow: inset 0 0 0 100px var(--last-engine); }
.sq.selected { box-shadow: inset 0 0 0 100px var(--sel); }
.sq.legal::after { content: ""; width: 28%; height: 28%; border-radius: 50%; background: var(--dot); position: absolute; }
.sq.legal.capture::after { width: 90%; height: 90%; background: none; border: 5px solid rgba(0,0,0,0.35); box-sizing: border-box; }
.sq.blocked::after { content: "\00d7"; position: absolute; font-size: 2em; line-height: 1; color: rgba(120, 0, 0, 0.5); font-weight: 700; }
.sq img { width: 92%; height: 92%; pointer-events: none; }
.sq.mine { cursor: pointer; }
.sq .coord { position: absolute; font-size: 0.6rem; opacity: 0.7; }
.sq .coord.file { right: 2px; bottom: 1px; }
.sq .coord.rank { left: 2px; top: 1px; }
.player-bar { display: flex; justify-content: space-between; align-items: center; padding: 0.4rem 0.7rem; background: var(--card); border-radius: 12px; }
.player-bar .name { font-weight: 600; }
.player-bar .material { margin-left: 0.5rem; font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.player-bar .dot { display: inline-block; width: 0.6em; height: 0.6em; border-radius: 50%; background: #bbb; margin-right: 0.4em; }
.player-bar .dot.on { background: var(--accent); }
.clock { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.3rem; padding: 0.1rem 0.6rem; border-radius: 8px; background: var(--bg); }
.clock.running { background: var(--bg); background: color-mix(in srgb, var(--accent) 18%, #fff); }
.clock.low { background: #fde8e8; color: #a00; }
.history { display: flex; align-items: center; justify-content: center; gap: 0.6rem; font-size: 0.9rem; color: var(--muted); }
.history button { padding: 0.25rem 0.7rem; }
.history .viewing { font-weight: 600; color: var(--fg); }
.option { font-size: 0.9rem; color: var(--muted); display: flex; gap: 0.4rem; align-items: center; }

.panel { background: var(--card); border-radius: 16px; padding: 1rem; display: flex; flex-direction: column; gap: 0.75rem; }
.banner { background: var(--bg); background: color-mix(in srgb, var(--accent) 8%, #fff); border: 1px solid var(--line); border-color: color-mix(in srgb, var(--accent) 30%, #fff); padding: 0.75rem; border-radius: 12px; }
.banner .code-row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.banner .join-link { overflow-wrap: anywhere; }
.banner .code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.8rem; letter-spacing: 0.25em; }
.status { font-weight: 600; min-height: 1.4em; }
.moves { margin: 0; padding: 0 0 0 3rem; max-height: 40vh; overflow-y: auto; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.95rem; }
.moves li span { display: inline-block; min-width: 4em; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.message { color: #a00; min-height: 1.4em; margin: 0; }
.promo { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 0.5rem; }
.promo-choices { display: flex; gap: 0.5rem; }
/* one-time sign-in card on a guest's first game (issue #80) */
.nudge { gap: 0.6rem; }
.nudge p { margin: 0; }
.nudge-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
a.button { display: inline-block; text-decoration: none; padding: 0.5rem 0.9rem; border-radius: 10px; font-weight: 600; }
a.button.primary { background: var(--accent); color: #fff; }
a.button.secondary { background: var(--card); color: var(--accent); border: 1px solid var(--accent); }

/* board colour themes (issue #31); ids match auth.BoardThemes and the
   iOS BoardTheme */
[data-board="slate"] { --accent: #4f6675; --accent-dark: #3d505c; --bg: #eef1f3; --light: #dee3e6; --dark: #8ca2ad; }
[data-board="wood"] { --accent: #7f5535; --accent-dark: #64422a; --bg: #f5f0e9; --light: #f0d9b5; --dark: #b58863; }
[data-board="green"] { --accent: #2a6240; --accent-dark: #1b3f2e; --bg: #f2f2f7; --light: #eeeed2; --dark: #769656; }
[data-board="sage"] { --accent: #56664c; --accent-dark: #424f3a; --bg: #f0f2ec; --light: #e6e9dc; --dark: #8f9e84; }
[data-board="walnut"] { --accent: #6b4426; --accent-dark: #523319; --bg: #f4eee6; --light: #e2c39b; --dark: #8b5e3c; }
[data-board="coral"] { --accent: #a14a30; --accent-dark: #7e3925; --bg: #f8efe8; --light: #f3e3cf; --dark: #cf8a6c; }
.themes { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.5rem; }
.themes legend { font-size: 0.9rem; color: var(--muted); margin-bottom: 0.4rem; }
.card label.theme { flex-direction: row; align-items: center; gap: 0.5rem; color: var(--fg); font-size: 0.95rem; }
.swatch { display: inline-grid; grid-template-columns: 1fr 1fr; width: 2.2rem; height: 1.1rem; border-radius: 4px; overflow: hidden; border: 1px solid var(--line); }
.swatch i:first-child { background: var(--light); }
.swatch i:last-child { background: var(--dark); }

/* friends */
.friend-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 6px 0; }
.friend-row .name { flex: 1 1 auto; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--accent); }
.badge { display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 0.75em; line-height: 1.5; }
.banner-float { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); width: calc(100% - 32px); max-width: 640px; box-sizing: border-box; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 16px; background: var(--card, #fff); border-radius: 12px; box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25); z-index: 10; }
.banner-float[hidden] { display: none; }

/* puzzles */
.puzzle .puzzle-head h2 { margin: 0; font-size: 1.2rem; }
.puzzle .puzzle-head p { margin: 0.15rem 0 0; }
.sq.hint { box-shadow: inset 0 0 0 4px #2a9d4a; }
.board.wrong { animation: puzzle-shake 0.35s; }
@keyframes puzzle-shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.result { margin: 0; font-weight: 700; }
.story p { margin: 0 0 0.6rem; }
.solution-line { margin: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.rating-line { margin: 0; display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; }
.rating-line strong { font-size: 2rem; }
.card select { font: inherit; padding: 0.55rem 0.7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--fg); }
#start-form { margin-bottom: 1rem; }
.classic-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.classic-list li + li { border-top: 1px solid var(--line); }
a.classic { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.7rem 0.25rem; text-decoration: none; color: var(--fg); }
a.classic:hover { background: var(--bg); }
.classic-main { display: flex; flex-direction: column; }
.classic-side { display: flex; align-items: center; gap: 0.6rem; }
.classic-rating { color: var(--muted); font-variant-numeric: tabular-nums; }
.solved-tick { color: var(--accent); font-weight: 700; }

.analysis { display: flex; flex-direction: column; gap: 0.5rem; align-items: flex-start; }
.analysis-result p, .analysis-note { margin: 0.2rem 0; }
.analysis-note { text-align: center; font-size: 0.95rem; }
.moves li span.mark-mistake, .moves li span.mark-blunder { font-weight: 600; }
.moves li span.mark-mistake { color: var(--mark-mistake); }
.moves li span.mark-blunder { color: var(--mark-blunder); }

/* Review with Sara: the card under the board, the arrows, the finding's tint.
   The arrows sit on the squares, which keep their colours in dark mode, so
   one set of tokens serves both; the white edge keeps them clear on dark
   squares of every board theme. */
.board .arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.arrow { stroke: var(--arrow-edge); stroke-width: 0.03; stroke-linejoin: round; }
.arrow-suggestion { fill: var(--arrow-suggestion); }
.arrow-reply { fill: var(--arrow-reply); }
.sq.last.mark-mistake { box-shadow: inset 0 0 0 100px var(--last-mistake); }
.sq.last.mark-blunder { box-shadow: inset 0 0 0 100px var(--last-blunder); }
.review-card { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 0.6rem 2.6rem 0.7rem 0.8rem; display: flex; flex-direction: column; gap: 0.35rem; }
.review-card p { margin: 0; }
.review-heading { font-weight: 700; }
.review-stop { position: absolute; top: 0.4rem; right: 0.4rem; padding: 0.1rem 0.55rem; line-height: 1.2; }
.review-card .actions button { padding: 0.35rem 0.7rem; }
