/* Ocheckers PWA — lamplit-wood identity, carried from the strategy guide. */
:root{
  color-scheme: light dark;
  --bg:#efe8da; --bg2:#f6f1e6; --bg3:#e7dfcd;
  --ink:#241c12; --ink-mut:#6a5f4c;
  --line:#d8cdb6; --line-strong:#c3b393;
  --gold:#a9700f; --gold-bright:#c88a1c;
  --indigo:#3b48a0; --clay:#ad4526; --good:#2f7d4f;
  --board-light:#d8c297; --board-dark:#7a5834;
  --wm:#f4ede1; --bm:#231b13;
  --shadow: 0 1px 2px rgba(50,35,10,.08), 0 10px 34px rgba(50,35,10,.12);
  --radius:14px;
}
@media (prefers-color-scheme: dark){
  :root{
    --bg:#15110c; --bg2:#1d1810; --bg3:#26200f;
    --ink:#ede2cf; --ink-mut:#a89c85;
    --line:#352c1e; --line-strong:#4a3d28;
    --gold:#e3a63a; --gold-bright:#f2be5a;
    --indigo:#8e9ceb; --clay:#e07a54; --good:#68c58c;
    --board-light:#cab083; --board-dark:#6b4e30;
    --wm:#efe7d6; --bm:#1c1610;
    --shadow: 0 1px 2px rgba(0,0,0,.45), 0 16px 44px rgba(0,0,0,.5);
  }
}
:root[data-theme="light"]{
  color-scheme:light;
  --bg:#efe8da; --bg2:#f6f1e6; --bg3:#e7dfcd;
  --ink:#241c12; --ink-mut:#6a5f4c;
  --line:#d8cdb6; --line-strong:#c3b393;
  --gold:#a9700f; --gold-bright:#c88a1c;
  --indigo:#3b48a0; --clay:#ad4526; --good:#2f7d4f;
  --board-light:#d8c297; --board-dark:#7a5834;
  --wm:#f4ede1; --bm:#231b13;
  --shadow: 0 1px 2px rgba(50,35,10,.08), 0 10px 34px rgba(50,35,10,.12);
}
:root[data-theme="dark"]{
  color-scheme:dark;
  --bg:#15110c; --bg2:#1d1810; --bg3:#26200f;
  --ink:#ede2cf; --ink-mut:#a89c85;
  --line:#352c1e; --line-strong:#4a3d28;
  --gold:#e3a63a; --gold-bright:#f2be5a;
  --indigo:#8e9ceb; --clay:#e07a54; --good:#68c58c;
  --board-light:#cab083; --board-dark:#6b4e30;
  --wm:#efe7d6; --bm:#1c1610;
  --shadow: 0 1px 2px rgba(0,0,0,.45), 0 16px 44px rgba(0,0,0,.5);
}

*{box-sizing:border-box}
/* The [hidden] attribute must beat component display rules (.result-overlay,
   .thinking, etc. set display, which would otherwise override [hidden]). */
[hidden]{display:none !important}
html,body{margin:0}
body{
  background:
    radial-gradient(130% 90% at 50% -20%, color-mix(in srgb, var(--gold) 10%, var(--bg)) 0%, var(--bg) 55%);
  color:var(--ink);
  font-family:system-ui,-apple-system,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  min-height:100vh;
  -webkit-font-smoothing:antialiased;
}
h1,h2,h3{
  font-family:"Iowan Old Style","Palatino Linotype",Palatino,"Book Antiqua",Georgia,serif;
  letter-spacing:-.01em; margin:0;
}
a{color:var(--indigo); text-underline-offset:3px}
:focus-visible{outline:3px solid var(--indigo); outline-offset:2px; border-radius:6px}

.app{max-width:1080px; margin:0 auto; padding:14px 16px 40px; position:relative}

/* topbar */
/* The header is lifted above the panel so its sound popover opens over the
   cards. A backdrop blur on the header used to seal the popover inside it, and
   the translucent cards that came later in the page painted straight over it. */
.topbar{display:flex; align-items:center; justify-content:space-between; gap:12px; padding:8px 4px 18px;
  position:relative; z-index:30}
.brand{display:flex; align-items:center; gap:12px}
.brand .crown{font-size:1.8rem; color:var(--gold-bright); filter:drop-shadow(0 2px 3px rgba(0,0,0,.3))}
/* Drawn icons (index.html): the size and colour of the text they sit in. */
.ico{width:1.1em; height:1.1em; vertical-align:-.2em; fill:none; stroke:currentColor;
  stroke-width:2; stroke-linecap:round; stroke-linejoin:round}
.brand .crown .ico{width:1em; height:1em; display:block}
.brand h1{font-size:1.5rem; line-height:1}
.brand-text p{margin:2px 0 0; font-size:.74rem; color:var(--ink-mut); letter-spacing:.04em}
.topbar-actions{display:flex; gap:8px}

/* buttons */
.btn{
  font:600 .9rem system-ui; color:var(--ink); background:var(--bg2);
  border:1px solid var(--line-strong); border-radius:10px; padding:9px 14px;
  cursor:pointer; transition:transform .08s ease, background .15s, border-color .15s;
}
.btn:hover{border-color:var(--gold); background:var(--bg3)}
.btn:active{transform:translateY(1px)}
.btn.ghost{background:transparent; border-color:var(--line)}
.btn.primary{background:var(--gold); border-color:var(--gold); color:#1a1206; font-weight:700}
.btn.primary:hover{background:var(--gold-bright); border-color:var(--gold-bright)}
.btn.block{width:100%; padding:12px; margin-top:4px}
.btn[disabled]{opacity:.45; cursor:not-allowed; transform:none}

/* layout */
.layout{display:grid; grid-template-columns:minmax(0,1fr) 320px; gap:26px; align-items:start}
@media (max-width:880px){ .layout{grid-template-columns:1fr; gap:18px} }

/* status strip */
.status{display:flex; align-items:center; gap:12px; min-height:34px; margin-bottom:12px; flex-wrap:wrap}
.turn{display:inline-flex; align-items:center; gap:9px; font-weight:650; font-size:.95rem}
.swatch{width:16px; height:16px; border-radius:50%; border:1px solid var(--line-strong);
  background:radial-gradient(circle at 38% 32%,#fff,var(--wm) 62%,#cbbfa6)}
.swatch.black{background:radial-gradient(circle at 38% 32%,#4a4038,var(--bm) 62%,#0d0a07)}
.badge{font-size:.76rem; font-weight:700; letter-spacing:.03em; padding:4px 10px; border-radius:999px}
.badge.forced{background:color-mix(in srgb,var(--clay) 18%,transparent); color:var(--clay)}
.thinking{display:inline-flex; align-items:center; gap:8px; font-size:.86rem; color:var(--ink-mut)}

/* board */
.board-frame{position:relative; border-radius:16px}
.board{position:relative; z-index:1}
.board{
  display:grid; grid-template-columns:repeat(var(--dim,8),1fr); aspect-ratio:1/1; width:100%;
  border-radius:9px; overflow:hidden;
  touch-action:manipulation; user-select:none;
}
.sq{position:relative; display:grid; place-items:center}
.sq.light{background:var(--board-light)}
.sq.dark{background:var(--board-dark)}
.sq.play{cursor:pointer}
.sq .coord{position:absolute; bottom:2px; right:3px; font:600 .5rem ui-monospace,monospace; color:rgba(0,0,0,.3)}
.sq.last{box-shadow:inset 0 0 0 4px color-mix(in srgb,var(--gold) 70%,transparent)}
.sq.sel{box-shadow:inset 0 0 0 4px var(--indigo)}
.sq.hintsq{box-shadow:inset 0 0 0 4px var(--good)}
.sq.dest::after{content:""; width:30%; height:30%; border-radius:50%;
  background:color-mix(in srgb,var(--indigo) 75%,transparent); opacity:.8}
.sq.dest.cap::after{width:64%; height:64%; background:transparent;
  border:3px solid color-mix(in srgb,var(--clay) 80%,transparent)}
.sq.mustmove .piece{outline:3px solid color-mix(in srgb,var(--clay) 70%,transparent); outline-offset:-2px}

.piece{
  width:74%; height:74%; border-radius:50%; position:relative;
  transition:transform .12s ease;
  box-shadow:inset 0 -3px 6px rgba(0,0,0,.3), inset 0 3px 5px rgba(255,255,255,.22), 0 3px 5px rgba(0,0,0,.4);
}
.piece.w{background:radial-gradient(circle at 38% 30%,#fff,var(--wm) 60%,#c7bca2)}
.piece.b{background:radial-gradient(circle at 38% 30%,#4c4239,var(--bm) 60%,#0c0906)}
.piece.king::after{content:"♛"; position:absolute; inset:0; display:grid; place-items:center;
  font-size:1.05em; color:var(--gold-bright); text-shadow:0 1px 2px rgba(0,0,0,.55)}
@media (hover: hover) and (pointer: fine) { .sq.play:hover .piece{transform:scale(1.06)} }
.piece.pop{animation:pop .28s ease}
@keyframes pop{0%{transform:scale(.4);opacity:.2}70%{transform:scale(1.12)}100%{transform:scale(1)}}

.board-hint{margin-top:12px; text-align:center; font-size:.86rem; color:var(--ink-mut); min-height:1.2em}

/* result overlay */
.result-overlay{position:absolute; inset:0; display:grid; place-items:center;
  background:color-mix(in srgb,var(--bg) 90%,transparent); border-radius:12px; z-index:5}
.result-card{background:var(--bg2); border:1px solid var(--line-strong); border-radius:18px;
  padding:26px 30px; text-align:center; box-shadow:var(--shadow); animation:pop .3s ease}
.result-emblem{font-size:2.6rem; color:var(--gold-bright)}
.result-card h2{font-size:1.7rem; margin:.1em 0 .1em}
.result-card p{margin:0 0 16px; color:var(--ink-mut)}

/* panel */
.panel{display:flex; flex-direction:column; gap:16px}
.panel-card{background:var(--bg2); border:1px solid var(--line); border-radius:var(--radius);
  padding:16px 18px; box-shadow:var(--shadow)}
.panel-card h3{font-size:1.05rem; margin:0 0 12px}
/* A card that is off the screen is not laid out until it is scrolled to. On a
   phone that is most of the panel, and its buttons are labelled with symbols —
   ↶, ⇅, a light bulb — that no text face carries: each one sends the browser
   looking through the system's fonts for a fallback, the first time it is
   drawn. That search was the biggest single part of the first frame. The room
   card is left alone: it is the one that can open things over its edges. */
.panel-card:not(.room-card){content-visibility:auto; contain-intrinsic-size:auto 320px}
.field{margin-bottom:14px}
.field label{display:block; font-size:.72rem; text-transform:uppercase; letter-spacing:.12em;
  color:var(--ink-mut); font-weight:700; margin-bottom:7px}
.segmented{display:flex; gap:4px; background:var(--bg3); border-radius:10px; padding:4px}
.segmented button{flex:1; border:0; background:transparent; color:var(--ink-mut);
  font:600 .85rem system-ui; padding:8px 6px; border-radius:7px; cursor:pointer; transition:.15s}
.segmented button.on{background:var(--bg); color:var(--ink); box-shadow:0 1px 3px rgba(0,0,0,.18)}

/* tally */
.tally{display:flex; flex-direction:column; gap:8px; margin-bottom:14px}
.tally-row{display:flex; justify-content:space-between; align-items:center; font-size:.9rem}
.tally-name{display:inline-flex; align-items:center; gap:8px; font-weight:600}
.tally-val{font-variant-numeric:tabular-nums; color:var(--ink-mut)}
.disc{width:14px; height:14px; border-radius:50%; display:inline-block; border:1px solid var(--line-strong)}
.disc.w{background:radial-gradient(circle at 38% 32%,#fff,var(--wm) 62%,#cbbfa6)}
.disc.b{background:radial-gradient(circle at 38% 32%,#4a4038,var(--bm) 62%,#0d0a07)}
.tally-bar{height:8px; border-radius:999px; background:var(--bm); overflow:hidden}
.tally-bar i{display:block; height:100%; background:linear-gradient(90deg,var(--wm),#cbbfa6); transition:width .4s ease}
.controls{display:grid; grid-template-columns:repeat(3,1fr); gap:8px}
.controls .btn{padding:9px 4px; font-size:.82rem}

/* history */
.history-card{max-height:280px; display:flex; flex-direction:column}
.history{list-style:none; margin:0; padding:0; overflow-y:auto; display:flex; flex-direction:column; gap:2px;
  font-family:ui-monospace,"SF Mono",Menlo,monospace; font-size:.82rem}
.history li{display:flex; gap:10px; padding:5px 8px; border-radius:6px}
.history li .no{color:var(--ink-mut); min-width:22px; text-align:right}
.history li .wm{flex:1; color:var(--ink)}
.history li .bm{flex:1; color:var(--ink)}
.history li.empty{color:var(--ink-mut); font-family:system-ui; justify-content:center}
.history li.cur{background:color-mix(in srgb,var(--gold) 14%,transparent)}

.panel-foot{font-size:.82rem; color:var(--ink-mut); line-height:1.5; margin:0; padding:0 2px}

/* spinners */
.spinner{width:14px; height:14px; border-radius:50%; border:2px solid var(--line-strong);
  border-top-color:var(--gold); display:inline-block; animation:spin .7s linear infinite}
.spinner.big{width:34px; height:34px; border-width:3px}
@keyframes spin{to{transform:rotate(360deg)}}

/* boot cover */
.boot{position:fixed; inset:0; display:grid; place-items:center; gap:10px; text-align:center;
  background:var(--bg); z-index:50; transition:opacity .4s}
.boot p{color:var(--ink-mut); margin:0}
.boot.hide{opacity:0; pointer-events:none; visibility:hidden; transition:opacity .4s, visibility 0s .4s}
/* A faded cover is still there, and so was its spinner, turning for the rest of
   the session under everything else and asking for a frame every refresh. */
.boot.hide .spinner{animation:none}

/* ===========================================================================
   Sound popover
   ======================================================================== */
.sound-wrap{position:relative}
.sound-pop{
  position:absolute; right:0; top:calc(100% + 8px); z-index:40; width:250px;
  background:var(--bg2); border:1px solid var(--line-strong); border-radius:var(--radius);
  padding:14px 16px; box-shadow:var(--shadow); animation:pop .18s ease;
}
.sound-pop h4{font:700 .72rem system-ui; text-transform:uppercase; letter-spacing:.12em;
  color:var(--ink-mut); margin:0 0 10px}
.switch{display:flex; align-items:center; gap:9px; font-size:.88rem; padding:6px 0; cursor:pointer}
.switch input{width:16px; height:16px; accent-color:var(--gold)}
.sound-pop .field{margin:10px 0 4px}
.sound-pop input[type=range]{width:100%; accent-color:var(--gold)}
.sound-note{font-size:.72rem; color:var(--ink-mut); margin:10px 0 0; line-height:1.45}
.segmented.tiny button{font-size:.75rem; padding:6px 4px}
#soundBtn.on{border-color:var(--gold); color:var(--gold)}

.result-actions{display:flex; flex-direction:column; gap:8px; align-items:stretch}

/* ===========================================================================
   Replay theater

   Euclid first: the board is the axiom, and everything else is constructed
   from it. The overlay is a size container, so 100cqw × 100cqh is exactly the
   room below the site's menu bar. The board's side --s is the largest square
   that still leaves the rest its minimum, and whatever height is left under
   the rows of fixed height is cut in the golden ratio, φ parts commentary to
   one part transport (grid fractions 1.618fr : 1fr).

   Nothing here is sized by its content. That is the whole cure for the old
   theater, which was one tall column that grew a little with every note and
   scrolled to the move list on every step, until the board had left the top
   of the phone. Now a step changes words inside boxes that do not move.

   Portrait, top to bottom:
     head 48 · board s · strip 44 · caption 44 · commentary φr · transport r
     s = min(W − 2g,  H − 48 − 44 − 44 − gaps − pad − (1 + φ)·tmin)
   so the transport never has less than tmin (a 56 px play button with room
   round it) and the commentary never less than φ·tmin; when the phone is tall
   enough for a full-width board, the spare height is shared by the same rule.

   Landscape or desktop (the @media below): the board on the left at the full
   height, s = H − 2p, and a column beside it of s/φ, so the board and its
   column stand in the golden ratio as well, unless that column would be under
   340 px, the least the transport and a sentence need.
   ======================================================================== */
body.modal-open{overflow:hidden}

.replay{
  position:fixed; inset:0; z-index:60; container-type:size;
  display:grid; place-items:center; overscroll-behavior:contain;
  background:color-mix(in srgb, #0b0805 88%, transparent);
  animation:fadein .2s ease;
}
@keyframes fadein{from{opacity:0}to{opacity:1}}

.replay-sheet{
  --phi:1.618; --g:12px; --gap:6px; --hd:48px; --strip:44px; --cap:44px; --tmin:60px;
  --pl:max(var(--g), env(safe-area-inset-left, 0px));
  --pr:max(var(--g), env(safe-area-inset-right, 0px));
  --pb:max(var(--g), env(safe-area-inset-bottom, 0px));
  --s:min(100cqw - var(--pl) - var(--pr),
          100cqh - var(--hd) - var(--strip) - var(--cap) - 5 * var(--gap) - var(--pb)
                 - (1 + var(--phi)) * var(--tmin));
  width:100cqw; height:100cqh; overflow:hidden;
  display:grid; grid-template-columns:minmax(0, 1fr);
  grid-template-rows:var(--hd) var(--s) var(--strip) var(--cap) minmax(0, 1.618fr) minmax(var(--tmin), 1fr);
  grid-template-areas:"head" "board" "strip" "cap" "coach" "trans";
  row-gap:var(--gap); padding:0 var(--pr) var(--pb) var(--pl);
  background:var(--bg); animation:rise .28s cubic-bezier(.2,.9,.3,1);
}
@keyframes rise{from{transform:translateY(18px) scale(.985); opacity:0}to{transform:none; opacity:1}}

@media (min-width:900px), (orientation:landscape){
  .replay-sheet{
    --pt:var(--g);
    --s:min(100cqh - var(--pt) - var(--pb),
            (100cqw - var(--pl) - var(--pr) - var(--g)) / var(--phi),
            100cqw - var(--pl) - var(--pr) - var(--g) - 340px);
    --side:max(340px, var(--s) / var(--phi));
    width:auto; padding-top:var(--pt); column-gap:var(--g);
    grid-template-columns:var(--s) var(--side);
    grid-template-rows:var(--hd) var(--cap) minmax(0, 1.618fr) var(--strip) minmax(var(--tmin), 1fr);
    grid-template-areas:"board head" "board cap" "board coach" "board strip" "board trans";
    border-left:1px solid var(--line); border-right:1px solid var(--line);
  }
}
@media (min-width:900px){ .replay-sheet{--g:20px} }

/* The rows the stage lays out belong to the sheet's grid, and the library
   takes their place: one column, a readable measure. */
#rStage{display:contents}
#rStage[hidden]{display:none}
.replay-sheet.lib{grid-template-columns:minmax(0, 1fr); grid-template-rows:var(--hd) minmax(0, 1fr);
  grid-template-areas:"head" "lib"; width:min(100cqw, 760px)}

/* Da Vinci: one focal point. The chrome is a single quiet row. */
.replay-top{grid-area:head; display:flex; align-items:center; gap:2px; min-width:0; margin:0 -6px}
.replay-title{flex:1; min-width:0; margin:0 4px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
  font-size:.95rem; color:var(--ink)}
.replay-title b{font-weight:700}
.replay-title span{color:var(--ink-mut)}
.replay-title span:not(:empty)::before{content:" · "}
.ricon{flex:none; width:44px; height:44px; border-radius:50%; border:0; background:transparent; color:var(--ink);
  display:grid; place-items:center; font-size:1.15rem; cursor:pointer; -webkit-tap-highlight-color:transparent}
.ricon:hover{background:var(--bg3)}
#rLibraryBtn.on{color:var(--gold); background:color-mix(in srgb,var(--gold) 14%,transparent)}
/* in the library there is no board to turn */
.replay-sheet.lib #rFlip{visibility:hidden}
.replay-library .lib-head .btn{white-space:nowrap}

/* the replay board — pieces live in their own absolute layer so they can glide */
.rboard-frame{
  grid-area:board; justify-self:center; align-self:center;
  width:var(--s); height:var(--s); position:relative; touch-action:none;
}
.rboard{position:absolute; inset:var(--bezel,12px); border-radius:10px; overflow:hidden; user-select:none;
  background-image: var(--board-inlay, none), var(--board-wood, none);
  background-size: 78% 78%, 100% 100%;
  background-position: center center, center;
  background-repeat: no-repeat, no-repeat;
  box-shadow: inset 0 2px 5px rgba(0,0,0,.45), inset 0 -2px 4px rgba(255,255,255,.06)}
.rboard-frame{
  --bezel:12px; padding:var(--bezel); border-radius:14px;
  background:
    linear-gradient(158deg,
      color-mix(in srgb, var(--frame,#8a6a3e) 82%, #fff) 0%,
      var(--frame,#8a6a3e) 34%,
      color-mix(in srgb, var(--frame,#8a6a3e) 78%, #000) 76%,
      color-mix(in srgb, var(--frame,#8a6a3e) 58%, #000) 100%),
    var(--frame-wood, none);
  background-blend-mode: multiply, normal;
  background-size: 100% 100%, 42% 42%;
  box-shadow: 0 1px 0 rgba(255,255,255,.25) inset, 0 -2px 6px rgba(0,0,0,.35) inset,
    0 16px 34px rgba(0,0,0,.45)}
.rsq.light{background:color-mix(in srgb, var(--board-light) 76%, transparent)}
.rsq.dark{background:color-mix(in srgb, var(--board-dark) 82%, transparent)}
.rsq{box-shadow:inset 0 0 0 .5px rgba(0,0,0,.18)}
.rsquares{position:absolute; inset:0; display:grid; grid-template-columns:repeat(var(--dim,8),1fr)}
.rsq.light{background:var(--board-light)}
.rsq.dark{background:var(--board-dark)}
.rsq.from{box-shadow:inset 0 0 0 3px color-mix(in srgb,var(--gold) 45%,transparent)}
.rsq.to{box-shadow:inset 0 0 0 4px color-mix(in srgb,var(--gold) 85%,transparent)}

.rtrail{position:absolute; inset:0; width:100%; height:100%; pointer-events:none; overflow:visible}
.rtrail .trailline{fill:none; stroke:var(--gold-bright); stroke-width:.06; stroke-dasharray:.18 .16;
  opacity:.85; stroke-linecap:round; animation:dash 6s linear 1}
.rtrail circle{fill:var(--gold-bright); opacity:.6}
@keyframes dash{to{stroke-dashoffset:-6.8}}

.rpieces{position:absolute; inset:0; pointer-events:none}
.rpiece{position:absolute; width:12.5%; height:12.5%; display:grid; place-items:center; z-index:1}
.rpiece .rdisc{
  width:76%; height:76%; border-radius:50%; position:relative;
  transition:transform .25s cubic-bezier(.2,1.3,.4,1), box-shadow .2s;
  box-shadow:inset 0 -3px 6px rgba(0,0,0,.3), inset 0 3px 5px rgba(255,255,255,.22), 0 3px 5px rgba(0,0,0,.4);
}
.rpiece.w .rdisc{background:radial-gradient(circle at 38% 30%,#fff,var(--wm) 60%,#c7bca2)}
.rpiece.b .rdisc{background:radial-gradient(circle at 38% 30%,#4c4239,var(--bm) 60%,#0c0906)}
.rpiece.king .rdisc::after{content:"♛"; position:absolute; inset:0; display:grid; place-items:center;
  font-size:1.5vmin; color:var(--gold-bright); text-shadow:0 1px 2px rgba(0,0,0,.55)}
@media (min-width:700px){ .rpiece.king .rdisc::after{font-size:1.35rem} }

/* lifted: the travelling piece rides above the others with a longer shadow */
.rpiece.lifted{z-index:4}
.rpiece.lifted .rdisc{transform:scale(1.14); box-shadow:0 12px 18px rgba(0,0,0,.5),
  inset 0 -3px 6px rgba(0,0,0,.3), inset 0 3px 5px rgba(255,255,255,.25)}
.rpiece.landed .rdisc{animation:land .32s cubic-bezier(.2,1.5,.4,1)}
@keyframes land{0%{transform:scale(1.14)}55%{transform:scale(.92)}100%{transform:scale(1)}}

.rpiece.gone{z-index:3}
.rpiece.gone .rdisc{animation:takeout .45s ease forwards}
@keyframes takeout{
  0%{transform:scale(1) rotate(0); opacity:1}
  35%{transform:scale(1.25) rotate(-14deg); opacity:1; box-shadow:0 0 0 6px color-mix(in srgb,var(--clay) 50%,transparent)}
  100%{transform:scale(.1) rotate(50deg) translateY(-30%); opacity:0}
}
.rpiece.crowning .rdisc{animation:crown .9s ease}
@keyframes crown{
  0%{transform:scale(1)}
  30%{transform:scale(1.3); box-shadow:0 0 0 10px color-mix(in srgb,var(--gold) 55%,transparent)}
  100%{transform:scale(1)}
}

/* full-board flash on a heavy capture or a coronation */
.rflash{position:absolute; inset:0; border-radius:12px; pointer-events:none; opacity:0}
.rflash.show{animation:flash .5s ease}
.rflash.big{background:radial-gradient(circle,color-mix(in srgb,var(--clay) 45%,transparent),transparent 70%)}
.rflash.crown{background:radial-gradient(circle,color-mix(in srgb,var(--gold) 45%,transparent),transparent 70%)}
@keyframes flash{0%{opacity:0}25%{opacity:1}100%{opacity:0}}

.rcaption{margin:2px 0 0; text-align:center; font-size:.9rem; color:var(--ink); min-height:1.3em;
  font-variant-numeric:tabular-nums}

/* finale card */
.rfinale{position:absolute; inset:0; display:grid; place-items:center; z-index:6;
  background:color-mix(in srgb,var(--bg) 90%,transparent); border-radius:12px}
.rfinale-card{background:var(--bg2); border:1px solid var(--line-strong); border-radius:18px;
  padding:22px 26px; text-align:center; box-shadow:var(--shadow); animation:pop .3s ease; max-width:88%}
.rfinale-card h3{font-size:1.4rem; margin:.1em 0}
.rfinale-card p{margin:0 0 14px; color:var(--ink-mut); font-size:.88rem}
.rfinale-actions{display:flex; gap:8px; justify-content:center; flex-wrap:wrap}
/* The rim and the finale are measured against the board, which on a small
   phone is a third smaller than on a desktop. */
.replay .rboard-frame{--bezel:clamp(8px, calc(var(--s) * .032), 14px)}
.rfinale-card{padding:clamp(12px, calc(var(--s) * .05), 22px) clamp(14px, calc(var(--s) * .06), 26px)}
.rfinale .result-emblem{font-size:clamp(1.6rem, calc(var(--s) * .08), 2.6rem); line-height:1.1}
.rfinale-card h3{font-size:clamp(1.05rem, calc(var(--s) * .05), 1.4rem)}
.rfinale-card p{font-size:clamp(.78rem, calc(var(--s) * .03), .88rem); margin-bottom:12px}

/* The eval is a thread in the frame's lower rim: it says who is ahead without
   taking a row from the board. Its words go in the caption. */
.reval{position:absolute; z-index:2; left:var(--bezel); right:var(--bezel); height:4px;
  bottom:calc(var(--bezel) / 2 - 2px); border-radius:2px; overflow:hidden; background:var(--bm);
  box-shadow:0 0 0 1px rgba(0,0,0,.28)}
.reval[hidden]{display:none}
.reval i{display:block; height:100%; background:linear-gradient(90deg,var(--wm),#cbbfa6);
  transition:width .6s cubic-bezier(.3,.9,.3,1)}

/* One timeline, the moves as a strip. It is the scrubber and the move list at
   once, and it only ever scrolls sideways; its edges fade rather than cut. */
.rstrip{grid-area:strip; list-style:none; margin:0; padding:0 14px; min-width:0;
  display:flex; align-items:center; gap:4px; position:relative;
  overflow-x:auto; overflow-y:hidden; scrollbar-width:none; overscroll-behavior-x:contain;
  -webkit-mask-image:linear-gradient(90deg,transparent,#000 14px,#000 calc(100% - 14px),transparent);
          mask-image:linear-gradient(90deg,transparent,#000 14px,#000 calc(100% - 14px),transparent)}
.rstrip::-webkit-scrollbar{display:none}
.rstrip li{flex:none; display:flex}
.rstrip li.empty{color:var(--ink-mut); font-size:.8rem; margin:auto}
.rstrip button{height:36px; padding:0 10px; border-radius:99px; border:1px solid var(--line);
  background:var(--bg2); color:var(--ink); font:600 .78rem ui-monospace,monospace; white-space:nowrap;
  cursor:pointer; -webkit-tap-highlight-color:transparent; touch-action:manipulation}
.rstrip .no{color:var(--ink-mut); margin-right:5px; font-weight:500}
.rstrip .grade{font-size:.74rem; margin-left:4px}
.rstrip button.gold{border-color:color-mix(in srgb,var(--gold) 60%,transparent);
  background:color-mix(in srgb,var(--gold) 12%,var(--bg2))}
.rstrip button.good{border-color:color-mix(in srgb,var(--good) 45%,transparent)}
.rstrip button.warn{border-color:color-mix(in srgb,var(--gold) 40%,transparent)}
.rstrip button.bad{border-color:color-mix(in srgb,var(--clay) 50%,transparent)}
.rstrip button.on{background:var(--gold); border-color:var(--gold); color:#1a1206}
.rstrip button.on .no, .rstrip button.on .grade{color:inherit}

/* What happened, in two lines: the move and its grade, then the engine's
   verdict and the men taken so far. */
.rcaption{grid-area:cap; min-width:0; display:flex; flex-direction:column; justify-content:center;
  text-align:center; font-variant-numeric:tabular-nums}
.rcaption p{margin:0; white-space:nowrap; overflow:hidden; text-overflow:ellipsis}
.rcap-move{font-size:.9rem; color:var(--ink)}
.rcap-sub{margin-top:2px !important; font-size:.76rem; color:var(--ink-mut);
  display:flex; justify-content:center; align-items:center; gap:14px}
.rcap-sub > span:first-child:empty{display:none}
#rEbText{display:inline-block}
#rEbText::first-letter{text-transform:uppercase}
.rtaken{display:inline-flex; align-items:center; gap:4px}
.rtaken[hidden]{display:none}
.rtaken .disc{width:10px; height:10px}
.rtaken b{font:600 .74rem ui-monospace,monospace; color:var(--ink); margin-right:5px}

/* The commentary has a fixed size; the words change inside it. A long note is
   faded at the foot (sfumato, not a hard cut) and "more" opens it where it
   stands, to scroll inside its own pane. */
.rcoach{grid-area:coach; position:relative; min-height:0; overflow:hidden; border-radius:14px;
  background:var(--bg2); border:1px solid var(--line); border-left:3px solid var(--gold)}
.rcoach.empty{border-left-color:var(--line)}
.rcoach-body{height:100%; overflow:hidden; padding:10px 14px 12px}
.rcoach-body[hidden], .rcoach-empty[hidden], .rmore[hidden]{display:none}
.rcoach.clamped .rcoach-body{
  -webkit-mask-image:linear-gradient(#000 calc(100% - 44px), transparent);
          mask-image:linear-gradient(#000 calc(100% - 44px), transparent)}
.rcoach.open .rcoach-body{overflow-y:auto; overscroll-behavior:contain; padding-bottom:40px;
  -webkit-mask-image:none; mask-image:none}
.rcoach .coach-head b{font-size:.98rem}
.rcoach .coach-why{margin-top:6px; font-size:.86rem; line-height:1.5}
.rcoach .coach-better{font-size:.82rem}
.rcoach .coach-watch{font-size:.8rem}
/* "more" sits on the headline's row, which reserves room for it: at the foot
   it lay over the last readable line on a short phone. */
.rcoach.clamped .coach-head, .rcoach.open .coach-head{padding-right:64px}
.rmore{position:absolute; right:8px; top:8px; height:26px; padding:0 12px; border-radius:99px;
  border:1px solid var(--line-strong); background:var(--bg); color:var(--ink); font:600 .76rem system-ui;
  cursor:pointer}
.rcoach-empty{height:100%; display:flex; flex-direction:column; align-items:center; justify-content:center;
  gap:8px; padding:10px 14px; text-align:center; font-size:.84rem; color:var(--ink-mut)}
.rcoach-empty p{margin:0}

/* round transport buttons, here and in the Watch bar */
.tbtn{
  width:42px; height:42px; border-radius:50%; border:1px solid var(--line-strong);
  background:var(--bg2); color:var(--ink); font-size:.9rem; cursor:pointer;
  display:grid; place-items:center; transition:transform .08s, background .15s, border-color .15s;
}
.tbtn:hover{border-color:var(--gold); background:var(--bg3)}
.tbtn:active{transform:scale(.94)}
.tbtn.big{width:56px; height:56px; font-size:1.1rem; background:var(--gold); border-color:var(--gold); color:#1a1206}
.tbtn.big:hover{background:var(--gold-bright)}
.tbtn[disabled]{opacity:.35; cursor:not-allowed}

/* The thumb zone: the transport at the foot, the play button largest, every
   target at least 44 px. The count and the speed flank it, small. */
.replay .transport{grid-area:trans; display:grid; grid-template-columns:1fr auto 1fr; align-items:center;
  gap:4px; min-width:0}
.replay .transport-buttons{display:flex; align-items:center; gap:2px}
.replay .tbtn{width:44px; height:44px; border:0; background:transparent; color:var(--ink); font-size:1.15rem}
.replay .tbtn:hover{background:var(--bg3)}
.replay .tbtn.big:hover{background:var(--gold-bright)}
.replay .tbtn.big{width:56px; height:56px; margin:0 4px; border:0; background:var(--gold); color:#1a1206; font-size:1.35rem;
  box-shadow:0 6px 16px color-mix(in srgb,var(--gold) 35%,transparent)}
.replay .tbtn .ico{fill:currentColor; stroke-width:1.6}
.rcounter{justify-self:start; font:600 .74rem ui-monospace,monospace; color:var(--ink-mut); white-space:nowrap}
.rspeed{justify-self:end; min-width:44px; height:44px; padding:0 8px; border-radius:22px; border:1px solid var(--line);
  background:transparent; color:var(--ink); font:600 .8rem ui-monospace,monospace; cursor:pointer;
  touch-action:manipulation}
/* A 360 px phone has just room for all seven if they stand shoulder to shoulder. */
@container (max-width:380px){
  .replay .transport-buttons{gap:0}
  .replay .tbtn.big{margin:0 2px}
  .rcounter{font-size:.66rem}
}

/* library */
.replay-library{grid-area:lib; overflow:auto; overscroll-behavior:contain; padding:8px 0 12px}
.lib-head{display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:12px}
.lib-head p{margin:0; font-size:.82rem; color:var(--ink-mut)}
.btn.small{padding:6px 10px; font-size:.8rem; border-radius:8px}
.lib-list{display:grid; gap:10px}
.gamecard{
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  background:var(--bg2); border:1px solid var(--line); border-left:4px solid var(--line-strong);
  border-radius:12px; padding:12px 14px; cursor:pointer; transition:border-color .15s, transform .08s;
}
.gamecard:hover{border-color:var(--gold); transform:translateX(2px)}
.gamecard.won{border-left-color:var(--good)}
.gamecard.lost{border-left-color:var(--clay)}
.gamecard.draw{border-left-color:var(--indigo)}
.gamecard.live{border-left-color:var(--gold-bright)}
.gc-top{display:flex; align-items:baseline; gap:10px; flex-wrap:wrap}
.gc-res{font-weight:700; font-size:.95rem}
.gc-when{font-size:.75rem; color:var(--ink-mut)}
.gc-sub{margin:3px 0 0; font-size:.8rem; color:var(--ink-mut)}
.gc-actions{display:flex; gap:6px; flex-shrink:0}
.lib-list .empty{color:var(--ink-mut); font-size:.9rem; text-align:center; padding:30px 10px}

/* ---- touch niceties: no tap flash, no double-tap zoom, no text selection --- */
@media (pointer:coarse){
  .btn, .tbtn, .segmented button, .gamecard{-webkit-tap-highlight-color:transparent}
  .btn, .tbtn{touch-action:manipulation}
  .app{user-select:none; -webkit-user-select:none}
  .tbtn{width:48px; height:48px}
  .tbtn.big{width:60px; height:60px}
}
/* the app is a standalone PWA on iPad — respect the notch and home indicator */
@supports(padding:max(0px)){
  .app{
    padding-left:max(16px, env(safe-area-inset-left));
    padding-right:max(16px, env(safe-area-inset-right));
    padding-bottom:max(40px, env(safe-area-inset-bottom));
  }
}

/* ===========================================================================
   Move verdicts — the badge, the ring, the board's reaction
   ======================================================================== */
.verdict-layer{position:absolute; inset:0; pointer-events:none; overflow:hidden;
  border-radius:12px; z-index:7}

.verdict{
  position:absolute; left:50%; top:11%; transform:translate(-50%,0);
  display:flex; align-items:center; gap:11px; white-space:nowrap;
  padding:10px 18px 10px 14px; border-radius:999px;
  background:color-mix(in srgb, var(--bg2) 97%, transparent);
  border:1px solid var(--line-strong); box-shadow:0 10px 30px rgba(0,0,0,.45);
  animation:verdictin .42s cubic-bezier(.16,1.3,.3,1);
}
.verdict.out{animation:verdictout .4s ease forwards}
@keyframes verdictin{
  0%{opacity:0; transform:translate(-50%,-14px) scale(.72); filter:blur(6px)}
  60%{opacity:1; transform:translate(-50%,3px) scale(1.06); filter:blur(0)}
  100%{opacity:1; transform:translate(-50%,0) scale(1)}
}
@keyframes verdictout{to{opacity:0; transform:translate(-50%,-10px) scale(.94)}}

.verdict .v-sym{font-size:1.5rem; line-height:1; display:grid; place-items:center;
  width:34px; height:34px; border-radius:50%; flex:0 0 auto}
.verdict .v-text{display:flex; flex-direction:column; gap:1px; line-height:1.15}
.verdict .v-text b{font-family:"Iowan Old Style",Palatino,Georgia,serif; font-size:1.05rem; letter-spacing:-.01em}
.verdict .v-text i{font-style:normal; font-size:.74rem; color:var(--ink-mut)}
.verdict .v-who{font-size:.68rem; text-transform:uppercase; letter-spacing:.1em;
  color:var(--ink-mut); font-weight:700; padding-left:6px; border-left:1px solid var(--line)}

.verdict.gold{border-color:var(--gold)}
.verdict.gold .v-sym{background:color-mix(in srgb,var(--gold) 26%,transparent); color:var(--gold-bright)}
.verdict.gold .v-text b{color:var(--gold-bright)}
.verdict.gold::after{content:""; position:absolute; inset:-2px; border-radius:999px;
  border:1px solid color-mix(in srgb,var(--gold) 55%,transparent); animation:haloring 1.1s ease-out infinite}
@keyframes haloring{0%{opacity:.85; transform:scale(1)}100%{opacity:0; transform:scale(1.16)}}
.verdict.good{border-color:color-mix(in srgb,var(--good) 60%,var(--line-strong))}
.verdict.good .v-sym{background:color-mix(in srgb,var(--good) 20%,transparent); color:var(--good)}
.verdict.warn .v-sym{background:color-mix(in srgb,var(--gold) 18%,transparent); color:var(--gold)}
.verdict.bad{border-color:color-mix(in srgb,var(--clay) 60%,var(--line-strong))}
.verdict.bad .v-sym{background:color-mix(in srgb,var(--clay) 20%,transparent); color:var(--clay)}
.verdict.bad .v-text b{color:var(--clay)}

/* the ring that breaks out of the landing square */
.shockwave{position:absolute; transform:translate(-50%,-50%); border-radius:50%;
  border:3px solid var(--gold-bright); animation:wave .95s cubic-bezier(.15,.7,.3,1) forwards}
.shockwave.bad{border-color:var(--clay)}
@keyframes wave{
  0%{opacity:.95; transform:translate(-50%,-50%) scale(.6); border-width:4px}
  100%{opacity:0; transform:translate(-50%,-50%) scale(6); border-width:1px}
}

/* gold motes, brilliance only */
.spark{position:absolute; width:6px; height:6px; margin:-3px 0 0 -3px; border-radius:50%;
  background:var(--gold-bright); box-shadow:0 0 8px var(--gold-bright);
  animation:spark 1.3s ease-out forwards}
@keyframes spark{
  0%{opacity:0; transform:translate(0,0) scale(.4)}
  20%{opacity:1}
  100%{opacity:0; transform:translate(var(--dx),var(--dy)) scale(.2)}
}

/* the board itself reacts */
.board.react-gold, .rboard.react-gold{animation:reactgold .7s ease}
.board.react-good, .rboard.react-good{animation:reactgood .55s ease}
.board.react-bad,  .rboard.react-bad{animation:reactbad .5s ease}
@keyframes reactgold{
  0%{box-shadow:var(--shadow)}
  30%{box-shadow:0 0 0 5px color-mix(in srgb,var(--gold) 75%,transparent), 0 0 46px color-mix(in srgb,var(--gold) 55%,transparent)}
  100%{box-shadow:var(--shadow)}
}
@keyframes reactgood{
  0%{box-shadow:var(--shadow)}
  35%{box-shadow:0 0 0 3px color-mix(in srgb,var(--good) 60%,transparent)}
  100%{box-shadow:var(--shadow)}
}
@keyframes reactbad{
  0%,100%{transform:translateX(0); box-shadow:var(--shadow)}
  15%{transform:translateX(-6px)} 32%{transform:translateX(5px)}
  50%{transform:translateX(-4px); box-shadow:0 0 0 4px color-mix(in srgb,var(--clay) 60%,transparent)}
  70%{transform:translateX(3px)} 85%{transform:translateX(-2px)}
}

/* grades in the move lists */
.grade{font-weight:800; font-size:.78rem; margin-left:5px; vertical-align:baseline}
.grade.gold{color:var(--gold-bright)}
.grade.good{color:var(--good)}
.grade.warn{color:var(--gold)}
.grade.bad{color:var(--clay)}

@media (max-width:520px){
  .verdict{padding:8px 13px 8px 10px; gap:8px}
  .verdict .v-sym{width:28px; height:28px; font-size:1.2rem}
  .verdict .v-text b{font-size:.92rem}
  .verdict .v-text i{display:none}
  .verdict .v-who{display:none}
}

@media (prefers-reduced-motion:reduce){
  *{animation-duration:.001ms !important; transition-duration:.001ms !important}
}

/* a captured man's square flares as it goes */
.capflash{position:absolute; inset:8%; border-radius:50%; pointer-events:none;
  border:3px solid var(--clay); animation:capflash .55s ease-out forwards}
@keyframes capflash{
  0%{opacity:0; transform:scale(.5)}
  30%{opacity:1; transform:scale(1)}
  100%{opacity:0; transform:scale(1.5)}
}
.switch.commentary{margin:2px 0 10px; align-items:flex-start}
.switch.commentary small{display:block; font-size:.72rem; color:var(--ink-mut); font-weight:400}

/* ===========================================================================
   Stage select + the now-playing announcement
   ======================================================================== */
.sound-pop{width:286px}
.mode-note{margin:7px 0 8px; font-size:.72rem; color:var(--ink-mut); line-height:1.4}
.stagelist{max-height:216px; overflow-y:auto; display:flex; flex-direction:column; gap:3px;
  border:1px solid var(--line); border-radius:10px; padding:5px; background:var(--bg)}
.stagelist button{
  display:flex; flex-direction:column; gap:1px; text-align:left; width:100%;
  background:transparent; border:1px solid transparent; border-radius:7px;
  padding:7px 9px; cursor:pointer; color:var(--ink); font:600 .84rem system-ui;
}
.stagelist button i{font-style:normal; font-size:.7rem; color:var(--ink-mut); font-weight:400; line-height:1.3}
.stagelist button:hover{background:var(--bg3)}
.stagelist button.on{background:color-mix(in srgb,var(--gold) 18%,transparent); border-color:var(--gold)}
.stagelist button.on::after{content:"♫"; position:absolute; right:10px; color:var(--gold-bright)}
.stagelist button{position:relative}

.stage-toast{
  position:fixed; left:50%; bottom:26px; transform:translateX(-50%); z-index:70;
  display:flex; align-items:center; gap:11px; padding:10px 18px 10px 14px;
  border-radius:999px; background:color-mix(in srgb,var(--bg2) 97%,transparent);
  border:1px solid var(--gold); box-shadow:0 12px 34px rgba(0,0,0,.45);
  animation:toastin .45s cubic-bezier(.16,1.2,.3,1);
}
.stage-toast.out{animation:toastout .45s ease forwards}
@keyframes toastin{from{opacity:0; transform:translate(-50%,18px) scale(.9)}to{opacity:1; transform:translate(-50%,0) scale(1)}}
@keyframes toastout{to{opacity:0; transform:translate(-50%,14px) scale(.96)}}
.stage-toast .st-note{color:var(--gold-bright); font-size:1.15rem; animation:notepulse 1.4s ease-in-out infinite}
@keyframes notepulse{0%,100%{opacity:.65; transform:scale(1)}50%{opacity:1; transform:scale(1.14)}}
.stage-toast .st-text{display:flex; flex-direction:column; line-height:1.2}
.stage-toast .st-text b{font-family:"Iowan Old Style",Palatino,Georgia,serif; font-size:1rem}
.stage-toast .st-text i{font-style:normal; font-size:.72rem; color:var(--ink-mut)}

/* ===========================================================================
   Immersive mode — the board takes the whole screen
   ======================================================================== */
#panelBtn{display:none}
body.immersive #panelBtn{display:inline-block}
body.immersive #fsBtn{color:var(--gold)}

body.immersive .app{max-width:none; padding:0; height:100dvh; display:flex; flex-direction:column}
body.immersive .topbar{
  padding:8px 14px; background:color-mix(in srgb,var(--bg2) 96%,transparent);
  border-bottom:1px solid var(--line); flex:0 0 auto;
  padding-top:max(8px, env(safe-area-inset-top));
}
body.immersive .brand-text p{display:none}
body.immersive .brand h1{font-size:1.1rem}

body.immersive .layout{
  flex:1 1 auto; display:flex; align-items:center; justify-content:center;
  min-height:0; padding:10px 12px; gap:0;
}
body.immersive .board-col{
  display:flex; flex-direction:column; justify-content:center;
  width:min(100%, calc(100dvh - 190px)); max-width:min(96vw, 860px);
}
body.immersive .status{justify-content:center; margin-bottom:8px}
body.immersive .board-hint{margin-top:8px}

/* the panel becomes a drawer you pull in when you need it */
body.immersive .panel{
  position:fixed; top:0; right:0; bottom:0; width:min(340px, 88vw); z-index:45;
  background:var(--bg2); border-left:1px solid var(--line-strong);
  box-shadow:-18px 0 50px rgba(0,0,0,.4);
  padding:16px; padding-top:max(16px, env(safe-area-inset-top));
  overflow-y:auto; transform:translateX(100%); transition:transform .3s cubic-bezier(.2,.9,.3,1);
}
body.immersive.panel-open .panel{transform:none}
body.immersive .panel-card{box-shadow:none}
.scrim{position:fixed; inset:0; z-index:44; background:rgba(8,6,4,.62);
  animation:fadein .25s ease}

/* short landscape (an iPad on its side): trade vertical chrome for board */
@media (max-height:620px){
  body.immersive .board-hint{display:none}
  body.immersive .board-col{width:min(100%, calc(100dvh - 120px))}
  body.immersive .status{margin-bottom:4px}
}

/* the topbar carries a lot of buttons now — let it shrink gracefully */
.topbar-actions{flex-wrap:wrap; justify-content:flex-end}
@media (max-width:560px){
  .topbar{padding-bottom:12px}
  .brand-text p{display:none}
  .brand h1{font-size:1.25rem}
  .btn{padding:8px 11px}
  #replayBtn{font-size:0; padding:8px 10px}
  #replayBtn::before{content:"▶"; font-size:.9rem}
}

/* ===========================================================================
   Two-player: the board turns, the clocks tick, the room waits
   ======================================================================== */
/* The board rotates rather than re-laying out, and each square rotates back so
   crowns and numbers stay the right way up. */
.board{transition:transform .55s cubic-bezier(.4,.05,.2,1)}
.board.flipped{transform:rotate(180deg)}
.board.flipped .sq{transform:rotate(180deg)}
.sq{transition:transform .55s cubic-bezier(.4,.05,.2,1)}

.clockbar{display:flex; flex-direction:column; gap:6px; margin-bottom:10px}
.clockbar .clock:last-child{order:2}
.clock{
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  padding:8px 14px; border-radius:12px; background:var(--bg2);
  border:1px solid var(--line); transition:border-color .2s, background .2s, transform .2s;
}
.clock.inverted{transform:rotate(180deg)}
.clock .cl-name{font-weight:650; font-size:.9rem}
.clock .cl-time{font:700 1.3rem ui-monospace,"SF Mono",Menlo,monospace; font-variant-numeric:tabular-nums}
.clock.on{border-color:var(--gold); background:color-mix(in srgb,var(--gold) 12%,var(--bg2))}
.clock.on .cl-time{color:var(--gold-bright)}
.clock.low .cl-time{color:var(--clay)}
.clock.low.on{border-color:var(--clay); animation:lowtime 1s ease-in-out infinite}
@keyframes lowtime{0%,100%{box-shadow:none}50%{box-shadow:0 0 0 3px color-mix(in srgb,var(--clay) 35%,transparent)}}
.clock.flagged{opacity:.55}
.clock.flagged .cl-time::after{content:" ⚑"; color:var(--clay)}
/* side by side once there is room for it */
@media (min-width:700px){
  .clockbar{flex-direction:row; gap:10px}
  .clockbar .clock{flex:1}
  .clockbar .clock:last-child{order:0}
  .clock.inverted{transform:none}
}

/* names + room panel */
.namerow{display:flex; align-items:center; gap:8px; margin-bottom:6px}
.namerow input, .room-card input{
  flex:1; min-width:0; font:600 .88rem system-ui; color:var(--ink);
  background:var(--bg); border:1px solid var(--line-strong); border-radius:9px; padding:8px 10px;
}
.room-card .or{text-align:center; font-size:.75rem; color:var(--ink-mut); margin:12px 0 8px}
.joinrow{display:flex; gap:8px}
.joinrow input{text-transform:uppercase; letter-spacing:.22em; font-weight:700; text-align:center}
.roomcode{display:flex; align-items:center; justify-content:space-between; gap:10px;
  background:var(--bg3); border-radius:12px; padding:10px 14px}
.roomcode span{font-size:.7rem; text-transform:uppercase; letter-spacing:.12em; color:var(--ink-mut); font-weight:700}
.roomcode b{font:800 1.5rem ui-monospace,monospace; letter-spacing:.16em; color:var(--gold-bright)}
.roomseat{margin:10px 0; font-size:.85rem; color:var(--ink-mut)}
.roomseat b{color:var(--ink)}
.controls.two{grid-template-columns:1fr 1fr}
.roomstatus{margin:10px 0 0; font-size:.76rem; color:var(--ink-mut); line-height:1.45}
.roomstatus.good{color:var(--good)}
.roomstatus.warn{color:var(--clay)}

/* waiting for the other side */
.waitveil{position:absolute; inset:0; display:grid; place-items:center; z-index:4;
  background:color-mix(in srgb,var(--bg) 86%,transparent); border-radius:12px}
.waitveil p{margin:0; font-size:.9rem; color:var(--ink-mut); text-align:center; padding:0 20px}

/* ===========================================================================
   Music dock — always visible, one tap to play, no menu to hunt through
   ======================================================================== */
.musicdock{
  position:fixed; left:14px; bottom:14px; z-index:55;
  left:max(14px, env(safe-area-inset-left)); bottom:max(14px, env(safe-area-inset-bottom));
  display:flex; align-items:center; gap:6px; padding:6px;
  border-radius:999px; background:color-mix(in srgb,var(--bg2) 97%, transparent);
  border:1px solid var(--line-strong); box-shadow:0 10px 30px rgba(0,0,0,.4);
  max-width:calc(100vw - 28px);
  transition:border-color .3s, box-shadow .3s;
}
.musicdock.playing{border-color:var(--gold)}
.musicdock.announce{animation:dockflare 2.6s ease}
@keyframes dockflare{
  0%{box-shadow:0 10px 30px rgba(0,0,0,.4)}
  12%{box-shadow:0 0 0 4px color-mix(in srgb,var(--gold) 45%,transparent), 0 12px 36px rgba(0,0,0,.45)}
  100%{box-shadow:0 10px 30px rgba(0,0,0,.4)}
}

.md-face{
  display:flex; align-items:center; gap:9px; min-width:0;
  background:transparent; border:0; cursor:pointer; color:var(--ink);
  padding:4px 8px 4px 6px; border-radius:999px; text-align:left;
}
.md-face:hover{background:var(--bg3)}
.md-note{
  width:30px; height:30px; flex:0 0 auto; border-radius:50%; display:grid; place-items:center;
  background:color-mix(in srgb,var(--gold) 22%,transparent); color:var(--gold-bright); font-size:1rem;
}
/* The note beats a few times when the music starts and then rests: the gold rim
   already says it is playing, and a pulse for the length of a session is a
   frame asked for at every refresh of the display for as long as it plays. */
.musicdock.playing .md-note{animation:notepulse 1.5s ease-in-out 3}
.md-text{display:flex; flex-direction:column; line-height:1.2; min-width:0}
.md-text b{font:650 .85rem system-ui; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:34vw}
.md-text i{font-style:normal; font-size:.68rem; color:var(--ink-mut); white-space:nowrap;
  overflow:hidden; text-overflow:ellipsis; max-width:34vw}

/* the transport unfurls when the dock is opened */
/* Folded, it is not laid out at all: its ⏮ ⏭ ☰ come from a fallback font,
   and finding one is a cost the opening frame need not pay for buttons nobody
   can see. allow-discrete keeps them drawn until the fold has finished. */
.md-controls{
  display:flex; align-items:center; gap:4px; overflow:hidden;
  max-width:0; opacity:0; content-visibility:hidden;
  transition:max-width .32s cubic-bezier(.2,.9,.3,1), opacity .22s, content-visibility .32s allow-discrete;
}
.musicdock.open .md-controls{max-width:280px; opacity:1; padding-right:4px; content-visibility:visible}
.md-btn{
  width:32px; height:32px; flex:0 0 auto; border-radius:50%; border:1px solid var(--line);
  background:var(--bg); color:var(--ink); cursor:pointer; display:grid; place-items:center; font-size:.76rem;
  transition:transform .08s, border-color .15s, background .15s;
}
.md-btn:hover{border-color:var(--gold); background:var(--bg3)}
.md-btn:active{transform:scale(.92)}
.md-btn.play{background:var(--gold); border-color:var(--gold); color:#1a1206; font-size:.85rem}
#mdVol{width:74px; accent-color:var(--gold)}
@media (max-width:560px){ #mdVol{display:none} .musicdock.open .md-controls{max-width:150px} }

/* the dock steps aside for the replay theater */
.replay:not([hidden]) ~ .musicdock{opacity:.25; pointer-events:none}

/* ===========================================================================
   Live-board animation
   ======================================================================== */
/* A travelling piece rides above the board with a longer shadow under it. */
.piece.travelling{z-index:6; position:relative}
.piece.travelling{box-shadow:0 14px 20px rgba(0,0,0,.5),
  inset 0 -3px 6px rgba(0,0,0,.3), inset 0 3px 5px rgba(255,255,255,.25)}
.sq:has(.piece.travelling){z-index:6}
.piece.landing{animation:landing .34s cubic-bezier(.2,1.5,.4,1)}
@keyframes landing{0%{transform:scale(1.12)}55%{transform:scale(.93)}100%{transform:scale(1)}}

/* the ghost of a man that has just been taken */
.piece.ghost{position:absolute; width:74%; height:74%; pointer-events:none; z-index:5;
  animation:ghostout .5s ease forwards}
@keyframes ghostout{
  0%{transform:scale(1) rotate(0); opacity:1}
  30%{transform:scale(1.22) rotate(-12deg); opacity:1;
      box-shadow:0 0 0 6px color-mix(in srgb,var(--clay) 50%,transparent)}
  100%{transform:scale(.1) rotate(52deg) translateY(-34%); opacity:0}
}

.piece.crowning{animation:crownlive .9s ease}
@keyframes crownlive{
  0%{transform:scale(1)}
  30%{transform:scale(1.3); box-shadow:0 0 0 10px color-mix(in srgb,var(--gold) 55%,transparent)}
  100%{transform:scale(1)}
}

/* pieces settle onto a fresh board */
.piece.dealt{animation:deal .5s cubic-bezier(.2,1.3,.4,1) backwards}
@keyframes deal{
  0%{transform:translateY(-34px) scale(.5); opacity:0}
  70%{transform:translateY(0) scale(1.08); opacity:1}
  100%{transform:none}
}

/* the winner's pieces light up one after another */
.piece.victor{animation:victor .9s ease backwards}
@keyframes victor{
  0%,100%{box-shadow:inset 0 -3px 6px rgba(0,0,0,.3), inset 0 3px 5px rgba(255,255,255,.22), 0 3px 5px rgba(0,0,0,.4)}
  45%{box-shadow:0 0 0 5px color-mix(in srgb,var(--gold) 70%,transparent), 0 0 26px var(--gold-bright);
      transform:scale(1.1)}
}

/* a selected man breathes, and its destinations beckon */
.sq.sel .piece{animation:breathe 1.5s ease-in-out infinite}
@keyframes breathe{0%,100%{transform:scale(1)}50%{transform:scale(1.07)}}
.sq.dest::after{animation:beckon 1.5s ease-in-out infinite}
@keyframes beckon{0%,100%{transform:scale(.85); opacity:.65}50%{transform:scale(1.1); opacity:1}}
.sq.mustmove .piece{animation:mustmove 1.4s ease-in-out infinite}
@keyframes mustmove{0%,100%{outline-color:color-mix(in srgb,var(--clay) 40%,transparent)}
  50%{outline-color:color-mix(in srgb,var(--clay) 95%,transparent)}}

/* ===========================================================================
   Online: invitation, scoreboard, link health
   ======================================================================== */
.invite{display:flex; gap:14px; align-items:center; margin:14px 0; padding:12px;
  background:var(--bg3); border-radius:12px}
.inviteqr{width:120px; height:120px; flex:0 0 auto; border-radius:8px; background:#fff;
  padding:4px; box-shadow:0 2px 8px rgba(0,0,0,.25)}
.invitetext{min-width:0; display:flex; flex-direction:column; gap:7px}
.invitetext p{margin:0; font-size:.8rem; color:var(--ink-mut); line-height:1.4}
.invitetext code{font-size:.72rem; word-break:break-all; background:var(--bg);
  padding:5px 7px; border-radius:6px; color:var(--ink-mut)}
.invitetext .btn{align-self:flex-start}

.scoreboard{display:grid; grid-template-columns:1fr auto 1fr; align-items:center; gap:10px;
  margin:14px 0; padding:12px 10px; background:var(--bg3); border-radius:12px}
.sb-side{display:flex; align-items:center; gap:7px; min-width:0}
.sb-side:last-child{justify-content:flex-end}
.sb-side .sb-name{font-size:.82rem; font-weight:650; white-space:nowrap; overflow:hidden;
  text-overflow:ellipsis; max-width:8ch}
.sb-side .sb-score{font:800 1.5rem ui-monospace,monospace; font-style:normal; color:var(--ink)}
.sb-side.lead .sb-score{color:var(--gold-bright)}
.sb-side.offline{opacity:.45}
.sb-side.offline .sb-name::after{content:" ·offline"; font-size:.62rem; color:var(--clay)}
.sb-mid{font:800 .68rem system-ui; text-transform:uppercase; letter-spacing:.1em;
  color:var(--ink-mut); text-align:center; line-height:1.3}
.sb-mid b{display:block; color:var(--gold-bright); font-size:.8rem; letter-spacing:.04em}

.linkinfo{display:flex; align-items:center; gap:7px; margin:8px 0 0; font-size:.74rem; color:var(--ink-mut)}
.linkinfo .dot{width:8px; height:8px; border-radius:50%; background:var(--good); flex:0 0 auto}
.linkinfo .dot.warn{background:var(--gold)}
.linkinfo .dot.bad{background:var(--clay)}

.matchbanner{margin:0 0 14px; padding:10px 14px; border-radius:10px; text-align:center;
  background:color-mix(in srgb,var(--gold) 20%,transparent); border:1px solid var(--gold);
  font-weight:700; font-size:.92rem; color:var(--gold-bright)}

/* ===========================================================================
   Stages: the drawn scene behind the board, and the gallery that picks it
   ======================================================================== */
.stage-art{position:fixed; inset:0; z-index:-2; overflow:hidden; pointer-events:none}
.stage-art svg{position:absolute; inset:0; width:100%; height:100%; display:block}
/* A glowing scene arrives as three stacked sheets (skins.js liftGlow); the
   middle one is blurred by the compositor, so it gets a layer of its own. */
.stage-art svg.halo, .sr-art svg.halo{will-change:filter}

/* A scrim keeps the interface readable over a busy painting: strongest at the
   edges where the text lives, clearest in the middle where the board sits. */
/* Only as much veil as the text needs. The painting is the point; the scrim
   exists to keep the top and bottom strips readable, not to hide the middle. */
.stage-scrim{position:fixed; inset:0; z-index:-1; pointer-events:none;
  background:
    linear-gradient(to bottom,
      color-mix(in srgb,var(--bg) 52%,transparent) 0%,
      color-mix(in srgb,var(--bg) 10%,transparent) 22%,
      transparent 46%,
      transparent 62%,
      color-mix(in srgb,var(--bg) 22%,transparent) 84%,
      color-mix(in srgb,var(--bg) 52%,transparent) 100%);
}
/* The stage stands still. It used to drift, fifty-four seconds each way for
   ever, and that one animation was the freeze: a full-screen painting moving
   under every translucent surface kept the display redrawing a hundred and
   twenty times a second on a page nobody was touching (docs/DESKTOP.md §3). */
body{background:var(--bg)}

/* The board grows a frame in the stage's own timber. */
.board{border-color:var(--frame,var(--line-strong))}
.board-frame::after{content:""; position:absolute; inset:-9px; border-radius:18px;
  border:1px solid color-mix(in srgb,var(--frame,var(--line-strong)) 55%,transparent);
  pointer-events:none}

/* Panels lift off the art rather than sitting flat on it. */
/* No backdrop blur, on anything (docs/DESKTOP.md §3). A backdrop filter
   re-rasterises whatever is behind it whenever that changes, and behind every
   one of these was a painting that never stopped moving: a dozen blurred
   surfaces redrawn at the display's full rate, for ever, on a page nobody was
   touching. Near-opaque paint reads the same and costs nothing to keep. */
.board-hint{background:color-mix(in srgb,var(--bg) 45%,transparent); border-radius:10px}
.panel-card{background:color-mix(in srgb,var(--bg2) 94%,transparent);
  border-color:color-mix(in srgb,var(--line-strong) 60%,transparent)}
.topbar{background:color-mix(in srgb,var(--bg2) 94%,transparent);
  border-radius:0 0 14px 14px}
.btn{background:color-mix(in srgb,var(--bg2) 90%,transparent)}
.btn.primary{background:var(--gold)}
/* the board sits in the scene rather than on top of it */
.board{box-shadow:0 24px 60px rgba(0,0,0,.4), 0 2px 0 color-mix(in srgb,#fff 12%,transparent) inset}
.turn, .board-hint{text-shadow:0 1px 3px color-mix(in srgb,var(--bg) 70%,transparent)}

/* ---- the gallery ---- */
.stagesel{position:fixed; inset:0; z-index:62; display:grid; place-items:center; padding:16px;
  padding:max(16px,env(safe-area-inset-top)) max(16px,env(safe-area-inset-right))
          max(16px,env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left));
  background:color-mix(in srgb,#080604 88%,transparent);
  animation:fadein .2s ease}
.ss-sheet{width:min(1120px,100%); max-height:100%; display:flex; flex-direction:column;
  background:var(--bg); border:1px solid var(--line-strong); border-radius:20px;
  overflow:hidden; box-shadow:0 30px 90px rgba(0,0,0,.6); animation:rise .28s cubic-bezier(.2,.9,.3,1)}
.ss-top{display:flex; align-items:center; justify-content:space-between; gap:14px;
  padding:14px 18px; border-bottom:1px solid var(--line); background:var(--bg2)}
.ss-top h2{font-size:1.2rem}
.ss-top p{margin:2px 0 0; font-size:.78rem; color:var(--ink-mut)}
.ss-actions{display:flex; align-items:center; gap:12px}
.ss-actions .switch{font-size:.8rem; white-space:nowrap}

.ss-grid{display:grid; grid-template-columns:repeat(auto-fill,minmax(190px,1fr)); gap:14px;
  padding:18px; overflow-y:auto}
.ss-card{position:relative; display:flex; flex-direction:column; border:2px solid var(--line);
  border-radius:14px; overflow:hidden; cursor:pointer; background:var(--bg2); padding:0;
  text-align:left; color:var(--ink); font:inherit;
  transition:transform .16s cubic-bezier(.2,1.2,.4,1), border-color .16s, box-shadow .16s}
.ss-card:hover{transform:translateY(-3px); border-color:var(--gold); box-shadow:0 12px 28px rgba(0,0,0,.35)}
.ss-card.on{border-color:var(--gold-bright); box-shadow:0 0 0 3px color-mix(in srgb,var(--gold) 40%,transparent)}
.ss-thumb{position:relative; display:block; aspect-ratio:16/10; overflow:hidden; background:#000; flex:0 0 auto}
.ss-thumb svg{width:100%; height:100%; display:block}
/* a miniature board floating on the thumbnail, in that stage's own colours */
.ss-mini{position:absolute; right:9%; bottom:10%; width:38%; aspect-ratio:1/1;
  display:grid; grid-template-columns:repeat(4,1fr); border-radius:4px; overflow:hidden;
  box-shadow:0 4px 12px rgba(0,0,0,.5); border:1.5px solid var(--mini-frame,#0006)}
.ss-mini i{display:block}
.ss-meta{display:block; padding:10px 12px 12px; flex:1 1 auto}
.ss-meta b{display:block; font-family:"Iowan Old Style",Palatino,Georgia,serif; font-size:1rem}
.ss-meta b span{font-family:system-ui; font-size:.78rem; color:var(--ink-mut); margin-left:6px}
.ss-meta i{display:block; font-style:normal; font-size:.72rem; color:var(--ink-mut); line-height:1.35; margin-top:2px}
.ss-card.on .ss-meta b{color:var(--gold-bright)}
.ss-now{position:absolute; top:8px; left:8px; font:800 .6rem system-ui; letter-spacing:.12em;
  text-transform:uppercase; background:var(--gold); color:#1a1206; padding:3px 7px; border-radius:99px}

/* the announcement when a stage is chosen */
.stage-name{position:fixed; inset:0; z-index:58; display:grid; place-items:center; pointer-events:none}
.stage-name div{text-align:center; animation:stagein 2.2s ease forwards}
.stage-name b{display:block; font-family:"Iowan Old Style",Palatino,Georgia,serif;
  font-size:clamp(2rem,7vw,3.6rem); color:var(--gold-bright);
  text-shadow:0 4px 30px rgba(0,0,0,.75), 0 1px 0 rgba(0,0,0,.4)}
.stage-name i{display:block; font-style:normal; font-size:clamp(1.1rem,3vw,1.7rem);
  color:var(--ink); opacity:.9; letter-spacing:.3em; margin-top:4px}
@keyframes stagein{
  0%{opacity:0; transform:scale(.86) translateY(14px); filter:blur(10px)}
  18%{opacity:1; transform:scale(1) translateY(0); filter:blur(0)}
  72%{opacity:1}
  100%{opacity:0; transform:scale(1.04)}
}

@media (max-width:520px){ .ss-grid{grid-template-columns:repeat(auto-fill,minmax(150px,1fr)); gap:10px; padding:12px} }

/* ===========================================================================
   Watching the engine: the evaluation bar and the coach
   ======================================================================== */
.evalbar{margin-top:12px}
.eb-track{height:10px; border-radius:99px; overflow:hidden; background:var(--bm);
  border:1px solid var(--line-strong)}
.eb-track i{display:block; height:100%; background:linear-gradient(90deg,var(--wm),#cbbfa6);
  transition:width .6s cubic-bezier(.3,.9,.3,1)}
.eb-label{display:flex; align-items:center; justify-content:space-between; gap:10px; margin-top:5px;
  font-size:.74rem; color:var(--ink-mut)}
.eb-label b{font-weight:700; color:var(--ink); font-size:.8rem; text-align:center; flex:1}

.coach{margin-top:14px; padding:14px 16px; border-radius:14px;
  background:color-mix(in srgb,var(--bg2) 96%,transparent); border:1px solid var(--line);
  border-left:4px solid var(--gold); box-shadow:var(--shadow);
  animation:coachin .35s cubic-bezier(.2,1.1,.4,1)}
@keyframes coachin{from{opacity:0; transform:translateY(6px)}to{opacity:1; transform:none}}
.coach-head{display:flex; align-items:center; gap:9px}
.coach-head b{font-family:"Iowan Old Style",Palatino,Georgia,serif; font-size:1.02rem; line-height:1.3}
.coach-badge{flex:0 0 auto; width:26px; height:26px; border-radius:50%; display:grid; place-items:center;
  font-weight:800; font-size:.82rem; background:var(--bg3); color:var(--ink-mut)}
.coach-badge.gold{background:color-mix(in srgb,var(--gold) 26%,transparent); color:var(--gold-bright)}
.coach-badge.good{background:color-mix(in srgb,var(--good) 22%,transparent); color:var(--good)}
.coach-badge.warn{background:color-mix(in srgb,var(--gold) 18%,transparent); color:var(--gold)}
.coach-badge.bad{background:color-mix(in srgb,var(--clay) 22%,transparent); color:var(--clay)}
.coach-why{margin:8px 0 0; font-size:.88rem; line-height:1.55}
.coach-watch{margin:7px 0 0; font-size:.82rem; color:var(--ink-mut); line-height:1.5;
  padding-top:7px; border-top:1px dashed var(--line)}
.coach-watch:empty, .coach-why:empty{display:none}
body.mode-watch .board{cursor:default}

/* In Watch mode the commentary is the point, so keep the board small enough
   that the evaluation bar and the coach stay on screen with it. */
body.mode-watch .board-frame{max-width:min(100%, calc(100dvh - 360px)); margin:0 auto}
body.mode-watch .evalbar, body.mode-watch .coach{max-width:min(100%, calc(100dvh - 360px));
  margin-left:auto; margin-right:auto}


/* ---- the twenty-man board -------------------------------------------------
   A hundred squares in the same space means smaller pieces and smaller
   numbers; the crown glyph has to shrink with them or it overflows its man. */
.board.big .piece{width:78%; height:78%}
.board.big .piece.king::after{font-size:.85em}
.board.big .sq .coord{font-size:.4rem; bottom:1px; right:2px}
.board.big .sq.last, .board.big .sq.sel, .board.big .sq.hintsq{box-shadow:inset 0 0 0 3px currentColor}
.rpiece{width:calc(100% / var(--dim,8)); height:calc(100% / var(--dim,8))}

/* the coach's extra lines */
.coach-swing{margin-left:auto; font:700 .74rem ui-monospace,monospace; color:var(--clay);
  background:color-mix(in srgb,var(--clay) 14%,transparent); padding:2px 7px; border-radius:99px}
.coach-swing:empty{display:none}
.coach-better{margin:6px 0 0; font-size:.84rem; color:var(--gold-bright); font-weight:600}
.coach-better:empty{display:none}
.coach-head{align-items:flex-start}

/* ===========================================================================
   The best move, drawn on the board
   ======================================================================== */
.bestlayer{position:absolute; inset:var(--bezel,14px); pointer-events:none; z-index:4; overflow:visible;
  transition:transform .55s cubic-bezier(.4,.05,.2,1)}
.board.flipped ~ .bestlayer{transform:rotate(180deg)}
/* Widths are set as SVG attributes, not here: a bare stroke-width in CSS is
   resolved in screen pixels rather than the viewBox's user units, which made
   the arrow a sixth of a pixel wide and invisible. */
.bestlayer .barrow{fill:none; stroke:var(--good); stroke-linecap:round;
  stroke-linejoin:round; opacity:.95}
.bestlayer .bhead{fill:var(--good); opacity:.95}
.bestlayer .bfrom{fill:none; stroke:var(--good); opacity:.8}
/* Pulses when the answer arrives, then holds still while you think about it. */
.bestlayer .bpulse{animation:bpulse 1.8s ease-in-out 3}
@keyframes bpulse{0%,100%{opacity:.55}50%{opacity:1}}

.bestchip{display:inline-flex; align-items:center; gap:7px; margin-left:10px;
  font:700 .78rem ui-monospace,monospace; color:var(--good);
  background:color-mix(in srgb,var(--good) 14%,transparent); padding:3px 9px; border-radius:99px}
.bestchip.thinking{color:var(--ink-mut); background:var(--bg3)}
.bestchip:empty{display:none}

/* ---- the watch transport, always with the board ---- */
.watchbar{display:flex; align-items:center; gap:10px; margin-bottom:12px}
.wb-label{font:600 .82rem system-ui; color:var(--ink-mut)}
.fieldnote{margin:8px 0 0; font-size:.76rem; color:var(--ink-mut)}
body.mode-watch .board-hint{display:none}
body.immersive.mode-watch .watchbar{justify-content:center}
/* in immersive Watch the board yields a little so the coach stays on screen */
body.immersive.mode-watch .board-col{width:min(100%, calc(100dvh - 330px))}


/* ===========================================================================
   Stage reveal — the painting, full bleed, before it settles behind the board
   ======================================================================== */
.stage-reveal{position:fixed; inset:0; z-index:64; pointer-events:none;
  opacity:0; transition:opacity 320ms ease}
.stage-reveal.in{opacity:1}
.stage-reveal.out{opacity:0; transition:opacity 620ms ease}
.sr-art{position:absolute; inset:0; overflow:hidden}
.sr-art svg{position:absolute; inset:0; width:100%; height:100%; display:block; transform:scale(1.14);
  transition:transform 2400ms cubic-bezier(.2,.7,.25,1)}
.stage-reveal.in .sr-art svg{transform:scale(1)}
.sr-scrim{position:absolute; inset:0;
  background:radial-gradient(120% 90% at 50% 62%, transparent 30%,
    color-mix(in srgb,#05080f 72%,transparent) 100%)}
.sr-name{position:absolute; left:0; right:0; bottom:14%; text-align:center; padding:0 24px}
.sr-name b{display:block; font-family:"Iowan Old Style",Palatino,Georgia,serif;
  font-size:clamp(2.2rem,8vw,4.4rem); color:var(--gold-bright); line-height:1.05;
  text-shadow:0 6px 40px rgba(0,0,0,.85), 0 1px 0 rgba(0,0,0,.5);
  opacity:0; transform:translateY(18px); transition:opacity 500ms ease 180ms, transform 620ms cubic-bezier(.2,1,.3,1) 180ms}
.sr-name i{display:block; font-style:normal; font-size:clamp(1.1rem,3.4vw,1.9rem);
  letter-spacing:.42em; color:#fff; opacity:0; margin-top:2px;
  transition:opacity 500ms ease 340ms; text-shadow:0 3px 22px rgba(0,0,0,.9)}
.sr-name em{display:block; font-style:normal; font-size:clamp(.8rem,2vw,.98rem);
  color:rgba(255,255,255,.72); margin-top:12px; opacity:0;
  transition:opacity 500ms ease 520ms; text-shadow:0 2px 14px rgba(0,0,0,.9)}
.stage-reveal.in .sr-name b{opacity:1; transform:none}
.stage-reveal.in .sr-name i, .stage-reveal.in .sr-name em{opacity:1}

/* ===========================================================================
   The board as an object: timber, a bevelled frame, and the mark inlaid in it
   ======================================================================== */
/* The playing surface is the wood plus the stage's motif. The squares sit on
   top of it as translucent tints, so the grain and the inlay read *through*
   them — the art is in the board, not behind the page. */
/* The playing surface is the wood plus the stage's motif — and neither ever
   changes while a game is played, whereas the squares above them change on
   every tap. Painted onto the board itself, a single highlight forced the
   timber and the motif to be re-rasterised with it; tilted, at the scale
   perspective demands, that is most of the cost of a tap on the 3D board.
   So the art gets a layer of its own, underneath, and is left alone. */
.board{
  border:0;
  box-shadow:
    inset 0 2px 5px rgba(0,0,0,.45),
    inset 0 -2px 4px rgba(255,255,255,.06);
}
.board::before{
  content:""; position:absolute; inset:0; z-index:0; pointer-events:none;
  border-radius:inherit;
  background-image: var(--board-inlay, none), var(--board-wood, none);
  background-size: 78% 78%, 100% 100%;
  background-position: center center, center;
  background-repeat: no-repeat, no-repeat;
}
/* The squares sit above the art, and are the only part that repaints. */
.board > .sq{z-index:1}
/* Squares stop being solid paint and become a stain over the timber. */
.sq.light{background:color-mix(in srgb, var(--board-light) 76%, transparent)}
.sq.dark{background:color-mix(in srgb, var(--board-dark) 82%, transparent)}
/* a hairline between squares, the way a real inlaid board has */
.sq{box-shadow:inset 0 0 0 .5px rgba(0,0,0,.18)}

/* The frame: a raised rim with a lit top edge and a shadowed underside, and a
   dark bevel falling away into the playing surface. */
.board-frame{
  --bezel:14px;
  padding:var(--bezel);
  border-radius:16px;
  background:
    linear-gradient(158deg,
      color-mix(in srgb, var(--frame, #8a6a3e) 82%, #fff) 0%,
      var(--frame, #8a6a3e) 34%,
      color-mix(in srgb, var(--frame, #8a6a3e) 78%, #000) 76%,
      color-mix(in srgb, var(--frame, #8a6a3e) 58%, #000) 100%),
    var(--frame-wood, none);
  background-blend-mode: multiply, normal;
  background-size: 100% 100%, 42% 42%;
  box-shadow:
    0 1px 0 rgba(255,255,255,.28) inset,
    0 -2px 6px rgba(0,0,0,.35) inset,
    0 18px 40px rgba(0,0,0,.45),
    0 3px 10px rgba(0,0,0,.35);
}
/* the bevel where the frame meets the field */
.board-frame::before{
  content:""; position:absolute; inset:9px; border-radius:12px; pointer-events:none; z-index:2;
  box-shadow:
    0 2px 3px rgba(0,0,0,.5),
    0 0 0 1px rgba(0,0,0,.35);
}
.board-frame::after{inset:-1px; border-radius:17px;
  border:1px solid color-mix(in srgb, var(--frame,#8a6a3e) 60%, #000)}
@media (max-width:520px){ .board-frame{--bezel:9px} .board-frame::before{inset:6px} }

/* ---- pieces that read on any timber ------------------------------------- */
/* Every piece gets a rim in the opposite tone and a contact shadow, so light
   men stay visible on pale squares and dark men on dark ones. */
.piece, .rpiece .rdisc{
  box-shadow:
    inset 0 -3px 7px rgba(0,0,0,.42),
    inset 0 3px 6px rgba(255,255,255,.30),
    0 0 0 1.5px var(--piece-rim, rgba(0,0,0,.35)),
    0 4px 7px rgba(0,0,0,.55);
}
.piece.w, .rpiece.w .rdisc{--piece-rim:rgba(30,22,10,.55)}
.piece.b, .rpiece.b .rdisc{--piece-rim:rgba(255,246,225,.42)}
/* A soft contact shadow under each man, so it sits on the board rather than
   floating over it. Drawn as a gradient, not as a blurred box: filter:blur()
   makes every piece its own compositing layer, and twenty-four of those
   re-rasterise on every move — which a tablet feels as a stutter. */
.sq .piece::before{content:""; position:absolute; left:4%; right:4%; bottom:-11%; height:28%;
  z-index:-1;
  background:radial-gradient(closest-side, rgba(0,0,0,.42), rgba(0,0,0,.26) 55%, transparent 100%)}
.piece{isolation:isolate}

/* ===========================================================================
   Identity, matchmaking and ranks
   ======================================================================== */
.me{background:var(--bg3); border-radius:12px; padding:12px 14px; margin-bottom:14px}
.me-id{display:flex; gap:8px; align-items:center}
.me-id input{flex:1; min-width:0; font:700 .95rem system-ui; color:var(--ink);
  background:var(--bg); border:1px solid var(--line-strong); border-radius:9px; padding:8px 10px}
.me-stats{display:flex; align-items:baseline; gap:10px; margin-top:9px; flex-wrap:wrap}
.me-rating{font:800 1.5rem ui-monospace,monospace; color:var(--gold-bright); line-height:1}
.me-band{font:700 .68rem system-ui; letter-spacing:.12em; text-transform:uppercase;
  color:var(--ink-mut); background:var(--bg2); padding:3px 8px; border-radius:99px}
.me-wl{font:600 .78rem ui-monospace,monospace; color:var(--ink-mut); margin-left:auto}
.me-prov{font-size:.68rem; color:var(--gold); font-weight:700}

.btn.big{padding:15px; font-size:1.02rem; letter-spacing:.02em}
.searching{display:flex; align-items:center; gap:10px; margin-top:10px; padding:10px 12px;
  background:var(--bg3); border-radius:11px; font-size:.84rem; color:var(--ink-mut)}
.searching .btn{margin-left:auto}
.controls.two{grid-template-columns:1fr 1fr}

.ranks-sheet{max-width:640px}
.ranks-body{overflow-y:auto; padding:14px 18px 20px}
.ranks{list-style:none; margin:0; padding:0; display:flex; flex-direction:column; gap:4px}
.ranks li{display:grid; grid-template-columns:34px 1fr auto auto; align-items:center; gap:12px;
  padding:10px 12px; border-radius:10px; background:var(--bg2); border:1px solid var(--line)}
.ranks li.you{border-color:var(--gold); background:color-mix(in srgb,var(--gold) 12%,var(--bg2))}
.ranks .rk{font:800 .9rem ui-monospace,monospace; color:var(--ink-mut); text-align:right}
.ranks li:nth-child(1) .rk{color:#e8c46a} .ranks li:nth-child(2) .rk{color:#c9ccd4}
.ranks li:nth-child(3) .rk{color:#c98a5a}
.ranks .nm{font-weight:650; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap}
.ranks .nm small{display:block; font-weight:400; font-size:.7rem; color:var(--ink-mut)}
.ranks .rt{font:800 1rem ui-monospace,monospace; color:var(--gold-bright)}
.ranks .wl{font:600 .74rem ui-monospace,monospace; color:var(--ink-mut)}
.ranks .empty{display:block; text-align:center; color:var(--ink-mut); padding:30px; font-size:.9rem}

.ratedchip{font:700 .68rem system-ui; letter-spacing:.1em; text-transform:uppercase;
  color:var(--gold-bright); background:color-mix(in srgb,var(--gold) 18%,transparent);
  padding:3px 9px; border-radius:99px; margin-left:8px}
.ratingdelta{font:800 .9rem ui-monospace,monospace}
.ratingdelta.up{color:var(--good)} .ratingdelta.down{color:var(--clay)}

/* ===========================================================================
   Chess on the same board
   ======================================================================== */
/* The figures are glyphs, so they take the stage's piece colours the way the
   draughts discs do — a light figure with a dark rim, or the reverse. */
.cp{
  font-size:min(9vw, 4.6rem); line-height:1; user-select:none;
  display:grid; place-items:center; width:100%; height:100%;
  transition:transform .12s ease;
}
.board.big .cp, .cp{font-size:clamp(1.4rem, 7.6cqw, 3.4rem)}
.board{container-type:inline-size}
.cp.w{color:var(--wm);
  text-shadow:
    0 0 1px rgba(0,0,0,.9), 0 1px 0 rgba(0,0,0,.55), 0 2px 3px rgba(0,0,0,.55),
    1px 0 0 rgba(0,0,0,.5), -1px 0 0 rgba(0,0,0,.5), 0 -1px 0 rgba(0,0,0,.5)}
.cp.b{color:var(--bm);
  text-shadow:
    0 0 1px rgba(255,255,255,.75), 0 1px 0 rgba(255,255,255,.35),
    0 2px 3px rgba(0,0,0,.5), 1px 0 0 rgba(255,255,255,.3), -1px 0 0 rgba(255,255,255,.3)}
@media (hover: hover) and (pointer: fine) { .sq.play:hover .cp{transform:scale(1.08)} }
.sq.incheck{box-shadow:inset 0 0 0 4px var(--clay), inset 0 0 22px color-mix(in srgb,var(--clay) 60%,transparent)}
.sq .coord{text-transform:none}
body.game-chess .sq .coord{font-size:.42rem; opacity:.55}

/* promotion chooser */
.promo{position:fixed; inset:0; z-index:66; display:grid; place-items:center;
  background:color-mix(in srgb,#080604 80%,transparent)}
.promo-card{background:var(--bg2); border:1px solid var(--line-strong); border-radius:18px;
  padding:20px 24px; text-align:center; box-shadow:var(--shadow); animation:pop .25s ease}
.promo-card p{margin:0 0 12px; font-size:.8rem; text-transform:uppercase; letter-spacing:.12em;
  color:var(--ink-mut); font-weight:700}
.promo-row{display:flex; gap:10px}
.promo-row button{width:64px; height:64px; font-size:2.2rem; line-height:1; cursor:pointer;
  border:1px solid var(--line-strong); border-radius:12px; background:var(--bg3); color:var(--ink)}
.promo-row button:hover{border-color:var(--gold); background:var(--bg)}

/* chess figures in the replay theater, on the same board as the discs */
.rpiece.rchess{display:grid; place-items:center}
.rpiece.rchess .cp{font-size:min(4.6vw, 2.6rem); line-height:1}
/* in the theater the board's side is known, so the figure fills its square */
.replay .rpiece.rchess .cp{font-size:calc((var(--s) - 2 * var(--bezel)) / 8 * .72)}
.rpiece.rchess.gone .cp{animation:takeout .45s ease forwards}
.rpiece.lifted.rchess .cp{transform:scale(1.12)}

/* ---- the fallen ---------------------------------------------------------
   What each player has taken, beside where that player sits: the far side's
   trophies above the board, the near side's below. It is read straight off the
   position rather than counted as the game goes, so it is right after a
   take-back, right when you join a game already under way, and right when you
   scrub a replay — there is no tally to fall out of step. */
.tray-live{
  display:flex; align-items:center; gap:8px; min-height:20px; margin:5px 2px;
  font-size:.7rem; color:var(--ink-mut);
}
.tray-live .tl-who{display:inline-flex; align-items:center; gap:5px; white-space:nowrap;
  text-transform:uppercase; letter-spacing:.07em; font-weight:700; opacity:.75}
.tray-live .tl-who .disc{width:9px; height:9px}
.tray-live .tl-items{display:flex; flex-wrap:wrap; align-items:center; gap:2px; min-width:0}
.tray-live .tl-edge{margin-left:auto; font-weight:800; font-size:.72rem; color:var(--gold-bright);
  letter-spacing:.02em; white-space:nowrap}

/* a taken draughts man, and a crown for a taken king */
.fallen{width:12px; height:12px; border-radius:50%; display:inline-block; position:relative;
  border:1px solid color-mix(in srgb,var(--line-strong) 70%,transparent);
  animation:fallenin .4s cubic-bezier(.2,1.4,.4,1)}
.fallen.w{background:radial-gradient(circle at 38% 32%,#fff,var(--wm) 62%,#cbbfa6)}
.fallen.b{background:radial-gradient(circle at 38% 32%,#4a4038,var(--bm) 62%,#0d0a07)}

/* a taken chess piece keeps its own figure, so you can see what it cost */
.fallen.cpx{width:auto; height:auto; border:0; border-radius:0; background:none;
  font-size:1.05rem; line-height:1; margin:0 -1px}
.fallen.cpx.w{color:var(--wm); text-shadow:0 0 1px rgba(0,0,0,.9), 0 1px 1px rgba(0,0,0,.5)}
.fallen.cpx.b{color:var(--bm); text-shadow:0 0 1px rgba(255,255,255,.6), 0 1px 1px rgba(0,0,0,.4)}
@keyframes fallenin{from{transform:scale(0) rotate(-90deg); opacity:0}to{transform:none; opacity:1}}

/* In the immersive layout the trays stay, but quietly. */
body.immersive .tray-live{margin:3px 2px; opacity:.85}

/* ===========================================================================
   The board as a table you are sitting at
   ===========================================================================
   Apple's Chess puts the board on a table in front of you rather than flat
   under you, and the difference is not decoration: a tilted board says at a
   glance which rank is near and which is far, and a piece with height is a
   thing you could reach for.

   The tilt is on the whole object — timber frame, squares and all — because a
   board whose frame stays flat while its squares lean is not a board in a
   room, it is a bug. Everything that already sits on the board comes along
   without knowing anything about it; only the result card counter-rotates, so
   the announcement faces you rather than lying on the table.
   ======================================================================== */
body.b3d .board-col{
  perspective: 1500px;
  perspective-origin: 50% 26%;
}
body.b3d .board-frame{
  transform-style: preserve-3d;
  transform: rotateX(var(--tilt,21deg)) scale(.94);
  transform-origin: 50% 52%;
  transition: transform .5s cubic-bezier(.2,.8,.3,1);
  will-change: transform;
}
/* Paint containment on the empty squares was tried here and taken out again:
   it flattens the element, and inside the tilted board that moved six squares
   far enough from where the browser thought they were that taps on them landed
   nowhere. In draughts those were light squares nobody taps; in chess every
   square is one. A repaint saved is not worth a tap lost. */
/* A tilted object still occupies its old box, so the near edge would sit on
   whatever comes next. This is the room it needs. */
body.b3d .board-col .board-frame{ margin-bottom: 3.5%; }

/* overflow:hidden would flatten the scene — a clipping box forces
   transform-style back to flat and every piece's height silently vanishes.
   The rounded timber still reads; only the pieces escape, which is the point. */
body.b3d .board{
  overflow: visible;
  transform-style: preserve-3d;
}
/* Only a square with a man on it needs to be a three-dimensional context —
   that is what gives the piece its height. Making all sixty-four into one costs
   the compositor sixty-four scenes to sort for the sake of twenty-four pieces. */
body.b3d .sq.tall{ transform-style: preserve-3d; z-index:1 }

/* ---- what floats above the board, when the board is a table ----------------
   In three dimensions the pieces stand up off the surface — a king is fifteen
   pixels tall — so anything drawn *on* the board plane is behind them. That is
   why the verdict badge was appearing behind the men it was talking about.

   Each of these is lifted clear of the tallest piece and turned back to face
   the viewer, so it reads as a card held over the table rather than a decal
   stuck to it. The best-move arrow is the exception: it belongs to the board,
   so it is lifted just enough to clear the men and left lying flat. */
body.b3d .result-overlay{
  transform: translateZ(90px) rotateX(calc(-1 * var(--tilt,21deg)));
}
body.b3d .verdict-layer{
  transform: translateZ(90px) rotateX(calc(-1 * var(--tilt,21deg)));
  overflow: visible;   /* the shockwave breaks out of the square it came from */
}
body.b3d .bestlayer{ transform: translateZ(22px); }
body.b3d .board.flipped ~ .bestlayer{ transform: translateZ(22px) rotateZ(180deg); }

/* A draughts man is a disc with a side. The stacked shadows are the wall of
   the cylinder — each a hair below the last, in the piece's own shade — so the
   edge is lit from the same direction as everything else. */
body.b3d .piece{
  transform: translateZ(8px);
  box-shadow:
    inset 0 -2px 5px rgba(0,0,0,.26),
    inset 0 2px 4px rgba(255,255,255,.20),
    0 1px 0 var(--edge,#0006), 0 2px 0 var(--edge,#0006), 0 3px 0 var(--edge,#0006),
    0 4px 0 var(--edge,#0005), 0 5px 0 var(--edge,#0005),
    0 9px 12px rgba(0,0,0,.45);
}
body.b3d .piece.w{ --edge:#b9a882; }
body.b3d .piece.b{ --edge:#241d17; }
/* A crown is two men, so a king stands twice as tall. */
body.b3d .piece.king{
  transform: translateZ(15px);
  box-shadow:
    inset 0 -2px 5px rgba(0,0,0,.26),
    inset 0 2px 4px rgba(255,255,255,.20),
    0 1px 0 var(--edge), 0 2px 0 var(--edge), 0 3px 0 var(--edge), 0 4px 0 var(--edge),
    0 5px 0 var(--edge), 0 6px 0 var(--edge), 0 7px 0 var(--edge), 0 8px 0 var(--edge),
    0 9px 0 var(--edge), 0 10px 0 var(--edge),
    0 14px 16px rgba(0,0,0,.45);
}

/* A chess figure stands up: the board's tilt undone, its base left on the
   square it belongs to, and a shadow cast flat on the timber beneath it. */
body.b3d .cp{
  transform: rotateX(calc(-1 * var(--tilt,21deg))) translateY(-15%) scale(1.05);
  transform-origin: 50% 88%;
}
/* The figure's shadow is drawn into the glyph rather than filtered onto it: a
   drop-shadow promotes every piece to its own layer, thirty-two of them, all
   repainting together. text-shadow is the same picture for none of that. */
body.b3d .cp.w{
  text-shadow:
    0 0 1px rgba(0,0,0,.9), 0 1px 0 rgba(0,0,0,.55), 1px 0 0 rgba(0,0,0,.5),
    -1px 0 0 rgba(0,0,0,.5), 0 -1px 0 rgba(0,0,0,.5), 0 4px 5px rgba(0,0,0,.5);
}
body.b3d .cp.b{
  text-shadow:
    0 0 1px rgba(255,255,255,.75), 0 1px 0 rgba(255,255,255,.3),
    1px 0 0 rgba(255,255,255,.28), -1px 0 0 rgba(255,255,255,.28),
    0 4px 5px rgba(0,0,0,.5);
}
/* No separate contact shadow: the figure is a glyph, and the last stop of its
   own text-shadow above is the shadow it casts. A pseudo-element here would be
   positioned against the square rather than the piece — .cp is not positioned —
   and would stand up with the figure instead of lying on the timber. */
@media (hover: hover) and (pointer: fine) {
  body.b3d .sq.play:hover .cp{
    transform: rotateX(calc(-1 * var(--tilt,21deg))) translateY(-18%) scale(1.12);
  }
}

/* On a phone the tilt is gentler: a steep board on a small screen costs more
   in squares you cannot read than it gains in depth. */
@media (max-width:560px){ body.b3d .board-col{ --tilt:15deg } }

/* The toggle reads as engaged. */
#d3Btn{font:800 .78rem system-ui; letter-spacing:.06em}
#d3Btn[aria-pressed="true"]{background:var(--gold); color:#1a1206; border-color:var(--gold)}

/* ---- the account code ---------------------------------------------------
   An account you cannot lose and can carry to another device, without a
   password, an email, or a form. It is a credential, so it is shown as one:
   set apart, monospaced, easy to copy and hard to misread. */
.me-code{margin-top:10px; padding:10px 12px; background:var(--bg);
  border:1px dashed var(--line-strong); border-radius:10px}
.mc-label{display:block; font:700 .62rem system-ui; letter-spacing:.12em;
  text-transform:uppercase; color:var(--ink-mut)}
.me-code code{display:block; margin:4px 0 0; font:700 .92rem ui-monospace,monospace;
  color:var(--gold-bright); letter-spacing:.01em; word-break:break-all}
.me-code .btn{margin-top:8px}
.mc-note{margin:8px 0 0; font-size:.7rem; line-height:1.45; color:var(--ink-mut)}
.btn.block{display:block; width:100%}
#linkPanel .joinrow input{font:600 .82rem ui-monospace,monospace}

/* ---- games happening now ------------------------------------------------
   The difference between a link you send a friend and a place you walk into.
   Each row is a game you could be watching in one tap. */
.ranks.live li{grid-template-columns:auto 1fr auto auto}
.live .lg-kind{font:800 .6rem system-ui; letter-spacing:.1em; text-transform:uppercase;
  color:var(--ink-mut); background:var(--bg3); padding:4px 8px; border-radius:99px; white-space:nowrap}
.live li.ranked .lg-kind{color:var(--gold-bright); background:color-mix(in srgb,var(--gold) 16%,transparent)}
.live .lg-who{min-width:0}
.live .lg-who b{display:block; font-weight:650; overflow:hidden; text-overflow:ellipsis; white-space:nowrap}
.live .lg-who small{display:block; font-size:.7rem; color:var(--ink-mut)}
.live .lg-eyes{font:600 .74rem ui-monospace,monospace; color:var(--ink-mut); white-space:nowrap}
.live .lg-turn{width:10px; height:10px; border-radius:50%; display:inline-block; margin-right:5px;
  vertical-align:-1px; border:1px solid var(--line-strong)}
.live .lg-turn.white{background:var(--wm)} .live .lg-turn.black{background:var(--bm)}

/* Watching: the board is live but nothing on it is yours. */
.watchbadge{display:inline-flex; align-items:center; gap:7px; margin-left:10px;
  font:700 .72rem system-ui; letter-spacing:.06em; text-transform:uppercase;
  color:var(--indigo); background:color-mix(in srgb,var(--indigo) 15%,transparent);
  padding:3px 10px; border-radius:99px}
body.watching .board .sq{cursor:default}
.eyes{display:inline-block; margin-left:6px; font:700 .7rem system-ui; color:var(--gold-bright)}
/* The one moment the account code is worth interrupting for: the end of the
   first rated game, when there is finally something to lose. */
.me-code.urging{border-style:solid; border-color:var(--gold);
  background:color-mix(in srgb,var(--gold) 10%,var(--bg));
  animation:codepulse 1.4s ease-in-out 3}
.me-code.urging .mc-note b{color:var(--gold-bright)}
.mc-ack{margin-top:8px}
@keyframes codepulse{0%,100%{box-shadow:0 0 0 0 transparent}
  50%{box-shadow:0 0 0 4px color-mix(in srgb,var(--gold) 30%,transparent)}}
