:root {
  --bg: #0d1410;
  --surface: #162019;
  --raised: #1f2d23;
  --raised-2: #26372b;
  --line: #27362b;
  --line-strong: #3a4f40;
  --text: #e8ede5;
  --muted: #a9bbac;
  --dim: #7f9585;
  --accent: #6fd08a;
  --accent-ink: #0d1a11;
  --good: #6fd08a;
  --bad: #ea7d6f;

  --board-light: #e9e3cc;
  --board-dark: #5c7d5e;
  --board-last: rgba(255, 224, 110, 0.55);
  --board-sel: rgba(111, 208, 138, 0.55);
  --board-hl: rgba(255, 190, 70, 0.6);
  --arrow: rgba(255, 190, 70, 0.9);

  --c-inaccuracy: #e9c74d;
  --c-mistake: #f29a4a;
  --c-blunder: #e6503f;

  --radius: 12px;
  --shadow: 0 1px 0 rgba(255, 255, 255, .035) inset, 0 6px 20px rgba(0, 0, 0, .28);
  /* The board is as tall as the viewport allows; the coach column matches it. */
  --board-size: max(280px, min(calc(100vh - 230px), calc(100vw - 32px), 640px));
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: Inter, system-ui, sans-serif; font-size: 15px; }
h1, h2, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--bad); font-size: 13px; min-height: 1em; }

/* buttons */
button { cursor: pointer; border-radius: 8px; padding: 8px 14px; border: 1px solid var(--line-strong); background: var(--raised); }
button:hover { background: var(--raised-2); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: .55; cursor: progress; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.06); }
button.quiet { background: transparent; border-color: var(--line); color: var(--muted); }
button.quiet:hover { color: var(--text); border-color: var(--line-strong); background: transparent; }
button.quiet[aria-pressed="false"] { color: var(--dim); text-decoration: line-through; }
button.danger { background: transparent; border-color: var(--bad); color: var(--bad); }
button.danger:hover { background: rgba(234, 125, 111, .12); }
button.small { padding: 5px 10px; font-size: 12.5px; }

input, select, textarea { background: var(--bg); border: 1px solid var(--line-strong); border-radius: 8px; padding: 9px 11px; }

/* top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 24px; border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 9px; }
.logo { color: var(--accent); font-size: 20px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.quiet-link { color: var(--muted); font-size: 13px; text-decoration: none; margin-right: 6px; }
.quiet-link:hover { color: var(--text); }
.topbar-actions button { padding: 6px 12px; font-size: 13px; }

/* layout: coach on the left, board on the right, both the same height */
.layout { display: grid; grid-template-columns: minmax(320px, 440px) var(--board-size); gap: 28px; justify-content: center; align-items: start; padding: 24px 16px 40px; }
/* One column: the board first, then the moves and step buttons that drive it, then the coach. */
@media (max-width: 1020px) {
  .layout { grid-template-columns: min(100%, var(--board-size)); row-gap: 12px; }
  .coach-col { display: contents; }
  .board-col { order: -2; }
  #gamePanel { order: -1; }
}

/* coach column */
.coach-col { display: flex; flex-direction: column; gap: 12px; }
.stage { position: relative; aspect-ratio: 4 / 3; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.stage > * { display: none; }
.stage[data-state="lobby"] { aspect-ratio: auto; }
.stage[data-state="lobby"] > .lobby { display: flex; }
.stage[data-state="connecting"] > .connecting { display: grid; }
.stage[data-state="live"] > .live { display: block; }

.lobby { flex-direction: column; gap: 10px; padding: 20px; }
.lobby .primary { padding: 11px 14px; }
.coaches { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.coach { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 6px 4px 8px; border-color: transparent; background: transparent; color: var(--muted); font-size: 13px; }
.coach img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; display: block; filter: saturate(.6) brightness(.8); }
.coach:hover { background: var(--raised); }
.coach[aria-checked="true"] { color: var(--text); font-weight: 600; background: var(--raised); border-color: var(--accent); }
.coach[aria-checked="true"] img, .coach:hover img { filter: none; }
.coach-style { margin: -2px 0 4px; }
.lobby .error:empty { display: none; }
.lobby-hint { margin: 0; font-size: 12.5px; line-height: 1.45; color: var(--dim); }
.connecting .lobby-hint { text-align: center; max-width: 260px; }
#stuckHint { margin-top: 10px; }
body.in-call #stuckHint { display: none; }

.connecting { position: absolute; inset: 0; place-content: center; justify-items: center; gap: 14px; color: var(--muted); }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line-strong); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.live { position: absolute; inset: 0; background: #000; }
.coach-video { width: 100%; height: 100%; object-fit: cover; display: block; }
.self-video { position: absolute; right: 10px; top: 10px; width: 24%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; border: 1px solid rgba(255, 255, 255, .25); transform: scaleX(-1); background: #111; box-shadow: 0 4px 14px rgba(0, 0, 0, .45); }
.self-video.off { display: none; }
.caption { position: absolute; left: 0; right: 0; bottom: 0; padding: 28px 16px 12px; font-size: 14.5px; line-height: 1.4; text-shadow: 0 1px 2px rgba(0, 0, 0, .8); background: linear-gradient(transparent, rgba(0, 0, 0, .78)); }
.caption:empty { display: none; }
.stage-note { position: absolute; left: 10px; top: 10px; max-width: 64%; padding: 6px 10px; border-radius: 8px; font-size: 12.5px; background: rgba(0, 0, 0, .65); }
.stage-note:empty { display: none; }

.call-bar { display: flex; gap: 8px; }
.call-bar { align-items: center; }
.call-time { margin-left: auto; font-size: 13px; color: var(--dim); font-variant-numeric: tabular-nums; }
.call-time.low { color: var(--bad); }

/* notebook */
.notebook { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.notebook header { display: flex; align-items: baseline; gap: 8px; }
.notebook h2 { font-size: 14px; }
.notebook ul:empty { display: none; }
.notebook ul { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-direction: column; gap: 8px; }
.notebook li { font-size: 13px; line-height: 1.45; padding-left: 10px; border-left: 2px solid var(--accent); }
.notebook li.learned { border-left-color: var(--line-strong); color: var(--muted); }
.nb-key { margin-top: 12px; font-size: 12.5px; color: var(--muted); }
.nb-key summary { cursor: pointer; }
.nb-key-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.nb-key code { font-family: 'JetBrains Mono', monospace; color: var(--text); user-select: all; }
.nb-key form { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.nb-key input { flex: 1; min-width: 150px; padding: 5px 9px; font-size: 12.5px; }
.nb-key .error { flex-basis: 100%; min-height: 0; }

/* board column */
.board-col { width: var(--board-size); max-width: 100%; }
.tabs { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.tabs button { border: 0; background: transparent; color: var(--muted); padding: 6px 14px; }
.tabs button.active { background: var(--raised-2); color: var(--text); }
.board-head { display: flex; justify-content: space-between; align-items: end; gap: 12px; margin: 14px 0 10px; }
.eyebrow { font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); }
h1 { font-size: 21px; margin-top: 2px; }
.status { font-weight: 600; font-size: 14px; text-align: right; }
.head-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.hud { display: flex; gap: 14px; font-size: 12.5px; color: var(--dim); }
.hud .stat { position: relative; }
.hud b { font-size: 15px; color: var(--text); font-variant-numeric: tabular-nums; margin-right: 2px; }
.hud .stat.hot b { color: #f2c14e; }
.delta { position: absolute; left: 0; top: -2px; font-style: normal; font-weight: 700; font-size: 13px; opacity: 0; pointer-events: none; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.delta.show { animation: delta 1.6s ease-out; }
@keyframes delta { 0% { opacity: 0; transform: translateY(0); } 15% { opacity: 1; } 100% { opacity: 0; transform: translateY(-22px); } }
.status.good { color: var(--good); }
.status.bad { color: var(--bad); }

/* board (ported from a-review) */
.board {
  width: var(--board-size); height: var(--board-size); max-width: 100%;
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  border-radius: 6px; overflow: hidden; position: relative; user-select: none; touch-action: none;
  box-shadow: 0 0 0 1px var(--line-strong), 0 10px 30px rgba(0, 0, 0, .35);
}
.sq { position: relative; }
.sq:focus { outline: none; }
.sq:focus-visible { box-shadow: inset 0 0 0 3px var(--accent); z-index: 1; }
.sq.light { background: var(--board-light); }
.sq.dark { background: var(--board-dark); }
.sq.last { box-shadow: inset 0 0 0 100px var(--board-last); }
.sq.sel { box-shadow: inset 0 0 0 100px var(--board-sel); }
.sq.hl { box-shadow: inset 0 0 0 100px var(--board-hl), inset 0 0 0 4px rgba(255, 170, 0, .95); animation: hl-in .5s ease-out; }
@keyframes hl-in { 0% { box-shadow: inset 0 0 0 100px rgba(255, 190, 70, 0), inset 0 0 0 4px rgba(255, 170, 0, 0); } }
.sq.wrong { animation: wrong .7s ease-out; }
@keyframes wrong { 0%, 40% { box-shadow: inset 0 0 0 100px rgba(230, 80, 63, .7); } 100% { box-shadow: inset 0 0 0 100px rgba(230, 80, 63, 0); } }
.sq.check { background: radial-gradient(circle, rgba(255, 60, 40, .95) 0%, rgba(255, 60, 40, .55) 45%, rgba(255, 60, 40, 0) 75%); }
.sq.check.light { background-color: var(--board-light); }
.sq.check.dark { background-color: var(--board-dark); }
.sq .coord { position: absolute; font-size: 10px; font-weight: 700; opacity: .75; pointer-events: none; }
.sq.light .coord { color: var(--board-dark); }
.sq.dark .coord { color: var(--board-light); }
.sq .coord.file { right: 3px; bottom: 1px; }
.sq .coord.rank { left: 3px; top: 1px; }
.sq .dot { position: absolute; inset: 0; margin: auto; width: 28%; height: 28%; border-radius: 50%; background: rgba(20, 30, 22, .35); pointer-events: none; }
.sq .dot.capture { width: 100%; height: 100%; background: none; border: 6px solid rgba(20, 30, 22, .35); }
.piece {
  position: absolute; left: 0; top: 0; width: 12.5%; height: 12.5%;
  background-size: 88%; background-position: center; background-repeat: no-repeat;
  transition: transform .18s ease, opacity .2s; will-change: transform; pointer-events: none; z-index: 2;
}
.piece.fade { opacity: 0; z-index: 1; }
.board.interactive .piece.own { pointer-events: auto; cursor: grab; }
.piece.dragging { transition: none; z-index: 5; cursor: grabbing; }
.badge { position: absolute; z-index: 3; border-radius: 50%; display: grid; place-items: center; font-weight: 900; font-size: 11px; color: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .45); pointer-events: none; }
.badge.pop { animation: pop .28s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { 0% { transform: scale(.3); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.board svg.arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 4; }
.board svg.arrows path.draw { animation: arrow-in .22s ease-out; transform-box: fill-box; transform-origin: center; }
@keyframes arrow-in { 0% { opacity: 0; transform: scale(.85); } 100% { opacity: 1; transform: scale(1); } }
.promo { position: absolute; inset: 0; background: rgba(15, 23, 18, .55); z-index: 6; display: none; place-items: center; }
.promo.show { display: grid; }
.promo div { display: flex; gap: 6px; background: var(--surface); padding: 8px; border-radius: 10px; border: 1px solid var(--line-strong); box-shadow: 0 8px 30px rgba(0, 0, 0, .5); }
.promo button { width: 64px; height: 64px; padding: 0; background-size: 86%; background-position: center; background-repeat: no-repeat; border: 1px solid var(--line); background-color: var(--raised); }
.promo button:hover, .promo button:focus-visible { border-color: var(--accent); background-color: var(--raised-2); }

.controls { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.moves { font-family: 'JetBrains Mono', monospace; font-size: 13px; color: var(--muted); margin-left: auto; }
label.inline { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
label.inline select { padding: 6px 8px; color: var(--text); }

/* modes */
body:not([data-mode="puzzle"]) .puzzle-only { display: none; }
body:not([data-mode="review"]) .review-only { display: none; }
body:not([data-mode="play"]) .play-only { display: none; }

/* play the coach */
.play { margin-top: 12px; }
.game-setup { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.strength { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; color: var(--muted); }
.strength output { font-size: 20px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
#strength { width: 100%; padding: 0; border: 0; background: transparent; accent-color: var(--accent); cursor: pointer; }
.ticks { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--dim); font-variant-numeric: tabular-nums; }
.game-setup .controls { margin-top: 8px; }
.game-setup .primary { margin-left: auto; }

/* review */
.review { margin-top: 12px; display: flex; flex-direction: column; gap: 12px; }
.review textarea { width: 100%; margin-top: 8px; font-family: 'JetBrains Mono', monospace; font-size: 12px; resize: vertical; }
.review summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.nav { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.moments { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 4px 10px; font-size: 12px; border-radius: 99px; font-family: 'JetBrains Mono', monospace; background: transparent; }
.chip.blunder { border-color: var(--c-blunder); color: var(--c-blunder); }
.chip.mistake { border-color: var(--c-mistake); color: var(--c-mistake); }
.chip.inaccuracy { border-color: var(--c-inaccuracy); color: var(--c-inaccuracy); }
/* game panel: move list, evaluation timeline, navigation (ported from a-review) */
.game-panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.move-list { max-height: 232px; overflow: auto; padding: 2px; scrollbar-width: thin; }
.mv-row { display: grid; grid-template-columns: 34px minmax(0, 1fr) minmax(0, 1fr); align-items: center; border-radius: 6px; }
.mv-row:nth-child(even) { background: rgba(255, 255, 255, .025); }
.mv-row .no { color: var(--dim); font-size: 13px; text-align: right; padding-right: 8px; font-variant-numeric: tabular-nums; }
.mv { display: flex; align-items: center; gap: 6px; width: 100%; padding: 3px 7px; border: 0; border-radius: 6px; background: transparent; text-align: left; font-weight: 600; font-size: 14px; color: var(--text); }
.mv:hover:not(:disabled) { background: var(--raised); }
.mv:disabled { opacity: 1; cursor: default; }
.mv.cur { background: var(--raised-2); box-shadow: inset 0 0 0 1px var(--line-strong); }
.mini { width: 16px; height: 16px; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: 8.5px; font-weight: 900; color: #fff; visibility: hidden; }
.mini.inaccuracy, .mini.mistake, .mini.blunder { visibility: visible; box-shadow: 0 1px 3px rgba(0, 0, 0, .4); }
.mini.inaccuracy { background: var(--c-inaccuracy); color: #2a2206; }
.mini.mistake { background: var(--c-mistake); }
.mini.blunder { background: var(--c-blunder); }
.graph-wrap { position: relative; }
.graph { width: 100%; height: 62px; display: block; cursor: pointer; border-radius: 7px; }
.graph-tip { position: absolute; top: 4px; transform: translateX(-50%); pointer-events: none; z-index: 3; padding: 3px 8px; border-radius: 6px; font-size: 12px; white-space: pre; background: var(--raised-2); border: 1px solid var(--line-strong); box-shadow: 0 4px 12px rgba(0, 0, 0, .4); }
.game-panel .nav { margin-top: 8px; }
.game-panel .nav button { flex: 1; padding: 7px 4px; display: grid; place-items: center; }
.game-panel .nav button[aria-pressed="false"] { color: var(--muted); text-decoration: none; }
.game-panel .nav button[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }

/* players and the evaluation bar around the board */
/* The player lines take room above and below the board, so it is a little smaller in these modes. */
body[data-mode="review"], body[data-mode="play"] { --board-size: max(280px, min(calc(100vh - 300px), calc(100vw - 32px), 640px)); }
.player-line { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 5px 6px; font-size: 13.5px; color: var(--muted); border-radius: 6px; }
.player-line .name { display: flex; align-items: center; gap: 7px; min-width: 0; }
.player-line .name b { color: var(--text); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-line .you { color: var(--accent); font-size: 12px; font-weight: 600; background: rgba(111, 208, 138, .12); border-radius: 99px; padding: 0 7px; }
.avatar { width: 20px; height: 20px; border-radius: 6px; display: grid; place-items: center; flex: none; font-size: 11px; font-weight: 800; }
.avatar.w { background: #f3f0e6; color: #1a1a1a; }
.avatar.b { background: #2b2b2b; color: #f3f0e6; border: 1px solid var(--line-strong); }
.player-line .right { display: inline-flex; align-items: center; gap: 10px; flex: none; }
.player-line .acc { color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; display: inline-flex; align-items: baseline; gap: 4px; }
.player-line .acc small { color: var(--muted); font-weight: 500; }
.player-line .turn .dot { display: block; width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); }
.player-line .turn.active .dot { background: var(--accent); box-shadow: 0 0 0 3px rgba(111, 208, 138, .25); }
.player-line.active { background: linear-gradient(90deg, rgba(111, 208, 138, .14), transparent 55%); box-shadow: inset 3px 0 0 var(--accent); padding-left: 9px; }
.board-wrap { position: relative; }
.evalbar { position: absolute; left: -24px; top: 0; bottom: 0; width: 18px; border-radius: 5px; overflow: hidden; background: #2b2b2b; border: 1px solid var(--line-strong); }
.evalbar .white { position: absolute; left: 0; right: 0; bottom: 0; background: #f3f0e6; transition: height .35s ease; }
.evalbar.flipped .white { bottom: auto; top: 0; }
.evalbar .label { position: absolute; left: 0; right: 0; text-align: center; font-size: 7.5px; font-weight: 800; padding: 3px 0; letter-spacing: -.03em; }
.evalbar .label.on-white { color: #1a1a1a; }
.evalbar .label.on-black { color: #f3f0e6; }
@media (max-width: 1020px) { .evalbar { display: none; } }

/* games to review */
.history { margin-top: 12px; }
.recent { display: grid; gap: 2px; max-height: 240px; overflow: auto; scrollbar-width: thin; }
.recent:empty { display: none; }
.recent button { display: grid; grid-template-columns: 8px minmax(0, auto) minmax(0, 1fr) auto; gap: 10px; align-items: baseline; text-align: left; background: transparent; border: 1px solid transparent; border-radius: 8px; padding: 7px 10px; }
.recent button:hover { background: var(--raised); border-color: var(--line); }
.recent .pip { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); align-self: center; }
.recent .pip.win { background: var(--good); }
.recent .pip.loss { background: var(--bad); }
.recent .who { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent .meta { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent .res { font-weight: 700; font-size: 13px; color: var(--muted); }
.recent .res.win { color: var(--good); }
.recent .res.loss { color: var(--bad); }
.history .controls input { flex: 1; min-width: 150px; padding: 6px 10px; font-size: 13px; }
.history .error { flex-basis: 100%; min-height: 0; }
.history .error:empty { display: none; }

/* under the hood: a drawer, closed unless asked for */
.hood { position: fixed; top: 0; right: 0; bottom: 0; width: min(400px, 100vw); z-index: 20; display: flex; flex-direction: column; gap: 8px; padding: 16px; background: var(--surface); border-left: 1px solid var(--line-strong); box-shadow: -12px 0 40px rgba(0, 0, 0, .45); overflow: auto; }
.hood header { display: flex; align-items: center; gap: 12px; }
.hood header h2 { margin-right: auto; }
.hood h2 { font-size: 15px; }
.sim { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px; border: 1px dashed var(--line-strong); border-radius: 10px; }
.log { list-style: none; padding: 0; margin: 4px 0 0; display: flex; flex-direction: column; gap: 8px; }
.log li { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 12.5px; line-height: 1.45; background: var(--raised); }
.log .kind { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--accent); display: block; margin-bottom: 2px; }
.log li.out .kind { color: #f2c14e; }
.log li.say .kind { color: #9ab8ff; }
.log li.err .kind { color: var(--bad); }
.log pre { margin: 4px 0 0; white-space: pre-wrap; word-break: break-word; font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--muted); }

