/* Layout: the pocket card is the instrument on the left; the game HUD rides above it so it stays
   in view on phones. A quiet operator's panel with Practice / Play / Leaderboard sits beside it. */
:root{
  --bg:#e2e6e8; --surface:#f5f7f8; --surface-2:#eaeef0; --fg:#141a1e; --muted:#58626a; --line:#c5ccd1;
  --accent:#1f7444; --accent-fg:#ffffff; --warn:#b3362a; --gold:#8a6514;
  --card-edge:#e8dab3; --pcb:#0b0d0c; --pcb-2:#151816; --silk:#eee1bc; --pad:#7a5c22; --pad-edge:#e4d3a2;
  --led:#63ff88; --err:#ff5e4e;
  --f-display:"Chakra Petch","Segoe UI",system-ui,sans-serif;
  --f-body:"IBM Plex Sans",system-ui,-apple-system,"Segoe UI",sans-serif;
  --f-mono:"IBM Plex Mono",ui-monospace,Menlo,Consolas,monospace;
  color-scheme:light;
}
@media (prefers-color-scheme: dark){
  :root{
    --bg:#0f1316; --surface:#171c20; --surface-2:#1e2428; --fg:#e6ebee; --muted:#8f99a1; --line:#2a3238;
    --accent:#5fd68a; --accent-fg:#06140b; --warn:#ff8a7c; --gold:#e3c06a; color-scheme:dark;
  }
}
*{box-sizing:border-box}
html{-webkit-text-size-adjust:100%}
body{margin:0; background:var(--bg); color:var(--fg); font-family:var(--f-body); font-size:15px; line-height:1.5;
  padding-top:env(safe-area-inset-top,0px); padding-bottom:env(safe-area-inset-bottom,0px)}
[hidden]{display:none!important}
.wrap{max-width:1000px; margin:0 auto; padding-block:14px 48px;
  padding-left:max(16px, env(safe-area-inset-left, 0px)); padding-right:max(16px, env(safe-area-inset-right, 0px))}

/* ---------- header ---------- */
.top{display:flex; align-items:center; justify-content:space-between; gap:12px 20px; flex-wrap:wrap; margin-bottom:20px}
.brand{display:flex; align-items:center; gap:10px; color:var(--fg); text-decoration:none; font-family:var(--f-display); font-weight:600; font-size:22px; letter-spacing:.02em}
.brand img{border-radius:7px; display:block}
.tabs{display:flex; gap:4px; background:var(--surface-2); border:1px solid var(--line); border-radius:10px; padding:3px}
.tabs a{font-weight:500; font-size:14px; color:var(--muted); text-decoration:none; padding:7px 13px; border-radius:7px}
.tabs a:hover{color:var(--fg)}
.tabs a[aria-current="page"]{background:var(--surface); color:var(--fg); box-shadow:0 1px 2px rgba(0,0,0,.12)}
.tabs a:focus-visible{outline:2px solid var(--accent); outline-offset:1px}

.layout{display:grid; grid-template-columns:minmax(0,380px) minmax(0,1fr); gap:36px; align-items:start}
.left{display:grid; gap:14px; min-width:0; justify-items:center}
.left > *{width:100%; max-width:380px}
@media (max-width:780px){
  .layout{grid-template-columns:minmax(0,1fr); gap:26px}
  /* on phones the game list and the board come before the card; a running game scrolls the HUD into view */
  .layout[data-view="play"] .panel, .layout[data-view="board"] .panel{order:-1}
}

/* ---------- the card (a physical object: same in both themes) ---------- */
.card{position:relative; width:100%; margin-inline:auto;
  background:radial-gradient(120% 80% at 30% 10%, var(--pcb-2), var(--pcb) 60%);
  border:3px solid var(--card-edge); border-radius:26px; padding:16px 12px 18px;
  box-shadow:0 1px 0 rgba(255,255,255,.08) inset, 0 22px 44px -22px rgba(0,0,0,.6);
  color:var(--silk); user-select:none; -webkit-user-select:none; -webkit-touch-callout:none}
.card-head{display:flex; justify-content:space-between; padding:2px 40px 0 20px;
  font-family:var(--f-display); font-weight:500; font-size:clamp(20px,6.4vw,26px); letter-spacing:.05em; color:var(--silk)}
.hole{position:absolute; top:11px; right:11px; width:26px; height:26px; border-radius:50%; border:3px solid var(--card-edge); background:var(--bg)}
#tree{display:block; width:100%; height:auto; margin-top:2px; overflow:visible}

.edge{stroke:var(--silk); stroke-width:3; stroke-linecap:round; transition:stroke .2s}
.edge.trail{stroke:var(--led)}
.node{cursor:pointer}
.node .shape{fill:var(--pad); stroke:var(--pad-edge); stroke-width:2.5; transition:fill .12s, stroke .12s; transform-box:fill-box; transform-origin:center}
.node.path .shape{stroke:var(--led)}
.node.lit .shape{fill:var(--led); stroke:#e4ffea; filter:url(#glow)}
.node.hit .shape{animation:hit .38s ease-out}
.node.miss .shape{fill:var(--err); stroke:#ffd9d4}
.node text{fill:var(--silk); font-family:var(--f-display); font-size:19px; font-weight:500; pointer-events:none; transition:fill .12s}
.node.lit text, .node.path text{fill:var(--led)}
.node.goal text{fill:#fff; font-weight:600}
.node.goal .shape{stroke:#fff; stroke-width:3}
.node:focus{outline:none}
.node:focus-visible .shape{stroke:#fff; stroke-width:3.5}
@keyframes hit{0%{transform:scale(1)}45%{transform:scale(1.4)}100%{transform:scale(1)}}
.antenna{stroke:var(--silk); stroke-width:2.5; fill:none; stroke-linejoin:round; stroke-linecap:round}
#rootLed{fill:var(--pad); stroke:var(--pad-edge); stroke-width:2; transition:fill .15s}
#rootLed.lit{fill:var(--led); stroke:#e4ffea; filter:url(#glow)}
#spark{fill:#f1fff4; filter:url(#glow); transition:opacity .15s, fill .15s}
#spark.lost{fill:var(--err); opacity:.55}
#spark.gone{opacity:0}

.key-row{display:flex; align-items:center; justify-content:center; gap:22px; margin-top:4px}
.mini{width:46px; height:46px; border-radius:50%; border:2px solid var(--silk); background:transparent; color:var(--silk);
  display:grid; place-items:center; cursor:pointer; touch-action:manipulation; transition:background .1s, color .1s; padding:0}
.mini:active, .mini.flash{background:var(--silk); color:var(--pcb)}
.mini:focus-visible, .key:focus-visible{outline:2px solid var(--led); outline-offset:3px}
.mini svg{width:22px; height:22px; fill:currentColor}
.key{width:104px; height:104px; padding:0; border:0; background:transparent; border-radius:50%; cursor:pointer; touch-action:none; -webkit-tap-highlight-color:transparent}
.key svg{width:100%; height:100%; display:block; overflow:visible}
.key .arc{stroke:var(--silk); stroke-width:4; fill:none; stroke-linecap:round; transition:stroke .08s}
.key .cap-ring{fill:var(--silk)}
.key .cap{fill:#1b1e1c; transform-origin:52px 52px; transition:transform .06s, fill .08s}
.key.down .cap{fill:#060706; transform:scale(.88)}
.key.down .arc{stroke:var(--led)}
.key.dash .arc{stroke:#b8ffcb}
.meter{display:grid; grid-template-columns:auto 1fr auto; align-items:center; gap:8px; width:190px; margin:10px auto 0; font-family:var(--f-display); font-size:12px; letter-spacing:.12em; color:var(--silk)}
.bar{position:relative; height:7px; border:1.5px solid var(--silk); border-radius:4px; overflow:hidden}
.bar i{position:absolute; inset:0 auto 0 0; width:0; background:var(--led)}
.bar b{position:absolute; top:-2px; bottom:-2px; left:50%; width:2px; background:var(--silk)}
.meter span{opacity:.55; transition:opacity .08s}
.meter span.on{opacity:1; color:var(--led)}

/* ---------- HUD ---------- */
.hud{position:relative; background:var(--surface); border:1px solid var(--line); border-radius:16px; padding:12px 14px 10px; overflow:hidden; scroll-margin-top:calc(env(safe-area-inset-top,0px) + 8px)}
.hud.shake{animation:shake .28s}
@keyframes shake{25%{transform:translateX(-5px)}75%{transform:translateX(5px)}}
.hud-top{display:flex; justify-content:space-between; align-items:baseline; font-family:var(--f-display); font-weight:600; font-size:13px; letter-spacing:.12em; text-transform:uppercase; color:var(--muted)}
.hud-time{font-family:var(--f-mono); font-size:16px; letter-spacing:0; color:var(--fg); font-variant-numeric:tabular-nums}
.hud-time.low{color:var(--warn)}
.timebar{height:4px; border-radius:2px; background:var(--surface-2); margin:6px 0 8px; overflow:hidden}
.timebar i{display:block; height:100%; width:100%; background:var(--accent); transform-origin:left; transform:scaleX(1)}
.hud-main{display:flex; justify-content:space-between; align-items:center; gap:12px; min-height:58px}
.target{font-family:var(--f-display); font-weight:600; font-size:44px; line-height:1; letter-spacing:.08em; display:flex; align-items:baseline; gap:2px; min-width:0; flex-wrap:wrap}
.target .done{color:var(--accent)}
.target .cur{color:var(--fg); border-bottom:4px solid var(--accent); padding-bottom:2px}
.target .cur.bad{color:var(--warn); border-color:var(--warn)}
.target .todo{color:var(--muted)}
.target .next{font-size:22px; color:var(--muted); margin-left:14px; letter-spacing:.2em}
.target .count{font-size:64px; color:var(--accent)}
.hud-score{text-align:right; display:grid; justify-items:end; line-height:1.05}
.hud-score b{font-family:var(--f-mono); font-weight:500; font-size:28px; font-variant-numeric:tabular-nums}
.hud-score span{font-family:var(--f-display); font-weight:600; font-size:15px; color:var(--gold)}
.hud-foot{display:flex; justify-content:space-between; align-items:center; gap:8px; margin-top:8px; color:var(--muted); font-size:13px; flex-wrap:wrap}
.hud-btns{display:flex; gap:6px}
.pop{position:absolute; right:96px; top:62px; font-family:var(--f-mono); font-weight:500; color:var(--accent); opacity:0; pointer-events:none}
.pop.go{animation:pop .6s ease-out}
@keyframes pop{0%{opacity:1; transform:translateY(0)}100%{opacity:0; transform:translateY(-22px)}}

/* ---------- result ---------- */
.result{background:var(--surface); border:1px solid var(--line); border-radius:16px; padding:14px 16px 16px; display:grid; gap:10px; scroll-margin-top:calc(env(safe-area-inset-top,0px) + 8px)}
.res-head{display:flex; justify-content:space-between; align-items:center; font-family:var(--f-display); font-weight:600; font-size:13px; letter-spacing:.12em; text-transform:uppercase; color:var(--muted)}
.x{border:0; background:transparent; color:var(--muted); font-size:16px; cursor:pointer; padding:4px 6px; border-radius:6px}
.x:hover{color:var(--fg)}
.res-score{font-family:var(--f-display); font-weight:600; font-size:56px; line-height:1; font-variant-numeric:tabular-nums}
.res-stats{color:var(--muted); font-size:14px}
.res-rank{font-weight:500}
.res-rank .big{font-family:var(--f-display); font-weight:600; font-size:20px; color:var(--accent)}
.res-rank .pb{display:inline-block; font-family:var(--f-display); font-weight:600; font-size:12px; letter-spacing:.1em; text-transform:uppercase; color:var(--accent-fg); background:var(--accent); border-radius:4px; padding:1px 6px; margin-left:6px; vertical-align:2px}
.res-vs{border-radius:10px; padding:10px 12px; background:var(--surface-2); font-weight:500}
.res-vs.win{color:var(--accent)}
.name-form{display:grid; gap:6px}
.name-form label{font-size:14px; color:var(--muted)}
.form-err{color:var(--warn); font-size:14px; min-height:0}

/* ---------- panel ---------- */
.panel{display:grid; gap:22px; min-width:0}
.view{display:grid; gap:22px; min-width:0}
.section{display:grid; gap:10px; min-width:0}
.label{font-family:var(--f-display); font-weight:600; font-size:12px; letter-spacing:.14em; text-transform:uppercase; color:var(--muted); display:flex; justify-content:space-between; align-items:center; gap:8px}
.muted{color:var(--muted); font-size:13px; letter-spacing:0; text-transform:none; font-family:var(--f-body); font-weight:400}
.note{margin:0; color:var(--muted); font-size:14px; max-width:60ch}
.out{font-family:var(--f-mono); font-size:clamp(22px,3.4vw,30px); line-height:1.3; letter-spacing:.06em; min-height:3.2em;
  background:var(--surface); border:1px solid var(--line); border-radius:12px; padding:14px 16px; white-space:pre-wrap; overflow-wrap:anywhere; min-width:0}
.out .ph{color:var(--muted); font-family:var(--f-body); font-size:16px; letter-spacing:0}
.out .new{animation:newch .7s ease-out}
@keyframes newch{from{color:var(--accent); text-shadow:0 0 12px var(--accent)}to{color:inherit; text-shadow:none}}
.caret{display:inline-block; width:.55em; height:1.05em; vertical-align:-.15em; background:var(--accent); margin-left:2px; animation:blink 1.1s steps(1) infinite}
@keyframes blink{50%{opacity:0}}
.btns{display:flex; flex-wrap:wrap; gap:8px}
.tbtn{font:500 14px/1 var(--f-body); color:var(--fg); background:var(--surface); border:1px solid var(--line); border-radius:8px; padding:10px 13px; cursor:pointer}
.tbtn:hover{border-color:var(--muted)}
.tbtn:disabled{opacity:.5; cursor:default}
.tbtn.small{padding:6px 10px; font-size:13px}
.tbtn:focus-visible, input:focus-visible, summary:focus-visible, .mode:focus-visible, .chip:focus-visible{outline:2px solid var(--accent); outline-offset:2px}
.tbtn.primary{background:var(--accent); color:var(--accent-fg); border-color:var(--accent)}

.live{display:grid; grid-template-columns:1fr auto; gap:14px; align-items:center; background:var(--surface); border:1px solid var(--line); border-radius:12px; padding:12px 16px; min-width:0}
.live-l{min-width:0}
.seq{display:flex; flex-wrap:wrap; gap:7px; align-items:center; min-height:22px}
.seq .d{width:13px; height:13px; border-radius:50%; background:var(--fg)}
.seq .h{width:32px; height:11px; border-radius:2px; background:var(--fg)}
.seq.bad .d, .seq.bad .h{background:var(--warn)}
.seq .none{color:var(--muted); font-size:14px}
.hint{color:var(--muted); font-size:14px; margin-top:6px; min-height:1.5em}
.hint.bad{color:var(--warn)}
.cand{font-family:var(--f-display); font-weight:600; font-size:44px; line-height:1; min-width:1.2ch; text-align:center; color:var(--accent)}
.cand.empty{color:var(--line)}
.cand.bad{color:var(--warn)}
.send{display:flex; gap:8px; flex-wrap:wrap}
.send input{flex:1 1 180px; min-width:0; font:500 16px var(--f-mono); letter-spacing:.05em; padding:9px 12px; border-radius:8px; border:1px solid var(--line); background:var(--surface); color:var(--fg)}
#msg{text-transform:uppercase}

/* play */
.modes{display:grid; gap:10px}
.mode{display:grid; grid-template-columns:1fr auto; gap:4px 14px; align-items:center; text-align:left; width:100%; font:inherit; color:var(--fg);
  background:var(--surface); border:1px solid var(--line); border-radius:12px; padding:14px 16px; cursor:pointer; transition:border-color .12s, transform .08s}
.mode:hover{border-color:var(--accent)}
.mode:active{transform:scale(.99)}
.mode h3{margin:0; font-family:var(--f-display); font-weight:600; font-size:19px; letter-spacing:.02em}
.mode p{margin:0; color:var(--muted); font-size:14px; grid-column:1}
.mode .meta{grid-column:1 / -1; display:flex; flex-wrap:wrap; gap:4px 16px; font-size:13px; color:var(--muted); margin-top:4px}
.mode .meta b{color:var(--fg); font-weight:600; font-variant-numeric:tabular-nums}
.mode .go{grid-row:1 / span 2; grid-column:2; font-family:var(--f-display); font-weight:600; font-size:14px; letter-spacing:.1em; color:var(--accent-fg); background:var(--accent); border-radius:8px; padding:8px 12px}
.mode.daily{border-color:var(--gold)}
.tag{font-family:var(--f-display); font-weight:600; font-size:11px; letter-spacing:.1em; text-transform:uppercase; color:var(--gold); margin-left:8px; vertical-align:2px}
.challenge{background:var(--surface); border:1.5px solid var(--gold); border-radius:12px; padding:14px 16px; display:grid; gap:10px}
.ch-text{font-weight:500}
.ch-text b{font-family:var(--f-display); font-size:18px}

/* board */
.chips{display:flex; flex-wrap:wrap; gap:6px}
.chip{font:500 14px/1 var(--f-body); color:var(--muted); background:transparent; border:1px solid var(--line); border-radius:999px; padding:8px 13px; cursor:pointer}
.chip[aria-selected="true"]{background:var(--fg); color:var(--bg); border-color:var(--fg)}
.chips.small .chip{font-size:13px; padding:6px 11px}
.board{list-style:none; margin:0; padding:0; background:var(--surface); border:1px solid var(--line); border-radius:12px; overflow:hidden}
.board li{display:grid; grid-template-columns:2.2em minmax(0,1fr) auto auto; gap:4px 12px; align-items:center; padding:10px 14px; border-top:1px solid var(--line)}
.board li:first-child{border-top:0}
.board li.mine{background:color-mix(in srgb, var(--accent) 12%, transparent)}
.board li.gap{padding:4px 14px; color:var(--muted); display:block; text-align:center}
.board .rk{font-family:var(--f-mono); font-variant-numeric:tabular-nums; color:var(--muted); font-size:14px}
.board li:nth-child(1) .rk{color:var(--gold); font-weight:600}
.board .who{min-width:0}
.board .nm{font-weight:600; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; display:block}
.board .sub{font-size:12.5px; color:var(--muted)}
.board .sc{font-family:var(--f-mono); font-weight:500; font-size:17px; font-variant-numeric:tabular-nums; text-align:right}
.board .beat{font-size:12.5px; padding:6px 9px}
.board .empty{display:block; padding:22px 16px; color:var(--muted); text-align:center}
.streak{display:inline-block; font-family:var(--f-display); font-weight:600; font-size:11px; letter-spacing:.06em; color:var(--gold); border:1px solid currentColor; border-radius:4px; padding:0 5px; margin-left:6px; vertical-align:1px}
.me{display:grid; gap:10px}
.me .row{gap:10px}

/* settings */
.settings{border-top:1px solid var(--line); padding-top:14px}
.settings summary{cursor:pointer; font-family:var(--f-display); font-weight:600; font-size:12px; letter-spacing:.14em; text-transform:uppercase; color:var(--muted); list-style-position:inside}
.settings[open] summary{margin-bottom:14px}
.controls{display:grid; gap:12px}
.row{display:flex; flex-wrap:wrap; align-items:center; gap:10px 18px}
.speed{display:grid; grid-template-columns:auto 1fr auto; align-items:center; gap:12px}
.speed output{font-family:var(--f-mono); font-variant-numeric:tabular-nums; min-width:6.5ch; text-align:right}
input[type=range]{width:100%; accent-color:var(--accent)}
.chk{display:inline-flex; align-items:center; gap:7px; cursor:pointer}
.chk input{accent-color:var(--accent); width:17px; height:17px; margin:0}
.timing{font-family:var(--f-mono); font-size:12.5px; color:var(--muted); font-variant-numeric:tabular-nums}
.keys{display:grid; grid-template-columns:auto 1fr; gap:6px 14px; font-size:14px; color:var(--muted); margin:4px 0 0}
.keys dt, .keys dd{margin:0}
kbd{font:500 12px var(--f-mono); color:var(--fg); background:var(--surface); border:1px solid var(--line); border-bottom-width:2px; border-radius:5px; padding:1px 6px}

.toast{position:fixed; left:50%; bottom:calc(20px + env(safe-area-inset-bottom,0px)); transform:translateX(-50%); background:var(--fg); color:var(--bg); padding:10px 16px; border-radius:10px; font-size:14px; z-index:20; max-width:calc(100% - 32px)}

@media (prefers-reduced-motion: reduce){
  .caret, .out .new, .node.hit .shape, .hud.shake, .pop.go{animation:none}
}
