:root{
  --bg:#0a0e1a; --bg2:#121831; --panel:#1b2342; --panel2:#28335c;
  --ink:#eef2ff; --muted:#9aa6cf; --line:#303c66;
  --tile:#3b4a86; --tile-lo:#2c3a6e; --tile-edge:#5a6cae; --tile-ink:#f5f8ff;
  --accent:#5b8cff; --accent2:#7af0c8; --good:#3dd39b; --good-bg:#123a30;
  --warn:#ffb454; --bad:#ff6b7a;
  --gold:#ffc94b; --gold-lo:#9a6e15; --gold-ink:#1b1403;
  --push:#3f74d6; --push-edge:#84a8ff;
  --cell:46px; --radius:14px;
  --shadow:0 6px 18px rgba(0,0,0,.35); --shadow-lg:0 14px 40px rgba(0,0,0,.5);
  --safe-b:env(safe-area-inset-bottom,0px); --safe-t:env(safe-area-inset-top,0px);
}
*{box-sizing:border-box; -webkit-tap-highlight-color:transparent;}
html,body{height:100%;}
body{
  margin:0; background:radial-gradient(130% 90% at 50% -10%, #18223f 0%, var(--bg) 58%) fixed, var(--bg);
  color:var(--ink); font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  overscroll-behavior:none; user-select:none; -webkit-user-select:none;
}
.screen{display:none; flex-direction:column; min-height:100dvh;}
.screen.show{display:flex;}
/* The play screen is pinned to the viewport so a tall board (e.g. all letters in one
   vertical line) can never grow the page past 100dvh and raise a body scrollbar. The
   flex:1 board-wrap then bounds the board, and computeCell shrinks it to fit. #help /
   #result sheets are siblings of #game, so this clip never touches them. */
#game{height:100dvh; overflow:hidden;}
:focus{outline:none;}
:focus-visible{outline:3px solid var(--accent2); outline-offset:2px; border-radius:6px;}

/* ---------- loading ---------- */
#loading{align-items:center; justify-content:center;}
.loader{text-align:center;}
.splash{display:flex; gap:5px; justify-content:center; flex-wrap:wrap; max-width:300px; margin:0 auto 18px;}
.sp-tile{
  width:46px; height:54px; border-radius:11px; display:flex; align-items:center; justify-content:center;
  font-size:26px; font-weight:800; color:var(--tile-ink);
  background:linear-gradient(180deg,var(--tile),var(--tile-lo)); border:1px solid var(--tile-edge);
  box-shadow:inset 0 2px 0 rgba(255,255,255,.14), 0 4px 0 rgba(0,0,0,.35), var(--shadow);
  animation:pop .42s cubic-bezier(.2,1.3,.4,1) backwards;
}
.sp-tile.accent{background:linear-gradient(180deg,var(--accent),#3f6fe0); border-color:#7da0ff; color:#fff;}
.sp-tile:nth-child(1){animation-delay:.02s} .sp-tile:nth-child(2){animation-delay:.08s}
.sp-tile:nth-child(3){animation-delay:.14s} .sp-tile:nth-child(4){animation-delay:.20s}
.sp-tile:nth-child(5){animation-delay:.28s} .sp-tile:nth-child(6){animation-delay:.34s}
.sp-tile:nth-child(7){animation-delay:.40s} .sp-tile:nth-child(8){animation-delay:.46s}
.sp-tile:nth-child(9){animation-delay:.52s}
@keyframes pop{from{transform:translateY(10px) scale(.6); opacity:0;} to{transform:none; opacity:1;}}
.loader p{color:var(--muted); animation:fadein .6s .5s backwards;}
@keyframes fadein{from{opacity:0} to{opacity:1}}

/* ---------- bars ---------- */
.topbar,.gamebar{
  display:flex; align-items:center; gap:10px; padding:calc(10px + var(--safe-t)) 14px 10px;
  position:sticky; top:0; background:linear-gradient(var(--bg),rgba(10,14,26,.72)); backdrop-filter:blur(10px); z-index:5;
}
.brand{flex:1; min-width:0;}
.topbar .title{font-size:24px; font-weight:800; letter-spacing:-.5px; line-height:1.05;}
.brand-sub{font-size:12.5px; color:var(--muted); font-weight:600; margin-top:1px;}
.gamebar .level-name{flex:1; text-align:center; min-width:0;}
.gamebar .level-name #levelName{font-weight:800; font-size:17px; line-height:1.1; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.level-pos{font-size:11px; color:var(--muted); font-weight:700; letter-spacing:.5px; text-transform:uppercase;}
.icon-btn{
  width:44px; height:44px; flex:0 0 44px; border-radius:13px; border:1px solid var(--line);
  background:var(--panel); color:var(--ink); font-size:19px; font-weight:700; cursor:pointer;
  display:flex; align-items:center; justify-content:center; transition:background .12s, transform .08s;
}
.icon-btn:active{background:var(--panel2); transform:scale(.94);}
.icon-btn.muted-ico{color:var(--muted);}

/* ---------- level select ---------- */
.levels-intro{padding:2px 18px 6px; color:var(--muted); font-size:14px;}
#levelsProgress .lp-bar{display:inline-block; vertical-align:middle; width:84px; height:6px; border-radius:6px; background:var(--line); overflow:hidden; margin-left:8px;}
#levelsProgress .lp-fill{display:block; height:100%; background:linear-gradient(90deg,var(--good),var(--accent2)); border-radius:6px;}
.level-grid{
  display:grid; grid-template-columns:repeat(auto-fill,minmax(154px,1fr)); gap:13px;
  padding:8px 16px 16px; flex:1; align-content:start;
}
.level-card{
  background:linear-gradient(160deg,var(--panel),var(--bg2)); border:1px solid var(--line);
  border-radius:var(--radius); padding:14px; cursor:pointer; position:relative; overflow:hidden;
  transition:transform .1s ease, border-color .15s, box-shadow .15s; box-shadow:var(--shadow);
}
.level-card:active{transform:scale(.97);}
.level-card:hover{border-color:var(--tile-edge);}
.level-card .num{font-size:11.5px; color:var(--muted); font-weight:800; letter-spacing:.6px;}
.level-card .lname{font-size:18px; font-weight:800; margin:2px 0 6px; letter-spacing:-.2px;}
.level-card .meta{font-size:12.5px; color:var(--muted);}
.level-card .meta b{color:var(--ink);}
.level-card .mini-grid{margin-top:11px; display:flex; flex-wrap:wrap; gap:2px;}
.mini-cell{width:11px; height:11px; border-radius:2px; background:transparent;}
.mini-cell.on{background:linear-gradient(160deg,var(--tile-edge),var(--tile-lo)); box-shadow:inset 0 1px 0 rgba(255,255,255,.12);}
.level-card .badge{
  position:absolute; top:10px; right:10px; font-size:11px; font-weight:800; padding:3px 8px;
  border-radius:20px; background:var(--good-bg); color:var(--good); border:1px solid var(--good);
}
.level-card .card-stars{margin-top:8px; font-size:13px; color:var(--gold); letter-spacing:1px; height:16px;}
.level-card .card-stars .dim{color:var(--line);}
.level-card.solved{border-color:var(--good); box-shadow:0 6px 18px rgba(0,0,0,.35), 0 0 0 1px rgba(61,211,155,.18);}
.credit{padding:10px 18px calc(16px + var(--safe-b)); color:var(--muted); font-size:12.5px; text-align:center;}

/* ---------- stats HUD ---------- */
.stats{display:flex; flex-direction:column; gap:7px; padding:8px 16px 6px;}
.stat-row{display:flex; align-items:center; gap:12px;}
.stat{display:flex; flex-direction:column; align-items:center; line-height:1;}
.stat-val{font-size:22px; font-weight:800;}
.stat-lbl{font-size:9.5px; color:var(--muted); text-transform:uppercase; letter-spacing:.7px; margin-top:5px;}
.stat.score .stat-val{font-size:30px; color:var(--good);}
/* goal is the objective — make it the single most visible stat (mint chip) */
.stat.goal{padding:4px 14px; border-radius:13px; background:rgba(122,240,200,.12);
  border:1px solid rgba(122,240,200,.45); box-shadow:0 0 0 3px rgba(122,240,200,.06);}
.stat.goal .stat-val{font-size:29px; color:var(--accent2); text-shadow:0 0 12px rgba(122,240,200,.35);}
.stat.goal .stat-lbl{color:var(--accent2); opacity:.85;}
/* pts — quiet 2nd axis, deliberately dimmer than WORDS/GOAL (§3.3) */
.stat.pts .stat-val{font-size:19px; color:var(--muted); font-weight:800;}
.stat.pts .stat-lbl{opacity:.8;}
.moves-stat{margin-left:auto;}
.moves-stat .over-pill{display:inline-block; margin-top:3px; font-size:9px; font-weight:800; color:#2a0c10; background:var(--bad); border-radius:10px; padding:1px 6px; letter-spacing:.4px;}
/* progress track (words -> goal): full-width, thick, glowing */
.goal-track{padding:0 1px;}
.bar{height:11px; border-radius:8px; background:var(--line); overflow:hidden; box-shadow:inset 0 1px 2px rgba(0,0,0,.35);}
.bar-fill{height:100%; width:0%; border-radius:8px; background:linear-gradient(90deg,var(--accent),var(--accent2));
  box-shadow:0 0 10px rgba(122,240,200,.45); transition:width .5s cubic-bezier(.2,.8,.2,1);}
.bar-fill.full{background:linear-gradient(90deg,var(--good),var(--accent2)); box-shadow:0 0 12px rgba(61,211,155,.6);}
.stat-actions{display:flex; gap:6px;}
.mini-btn{
  border:1px solid var(--line); background:var(--panel); color:var(--ink); border-radius:11px;
  min-width:40px; height:40px; padding:0 9px; font-size:16px; font-weight:700; cursor:pointer;
  display:flex; align-items:center; justify-content:center; transition:background .12s, transform .08s;
}
.mini-btn:disabled{opacity:.34;}
.mini-btn:active:not(:disabled){background:var(--panel2); transform:scale(.93);}
#btnRestart{color:var(--muted);}

/* ---------- phase chip ---------- */
.phase-chip{
  margin:6px auto 2px; padding:6px 14px; border-radius:20px; font-size:12.5px; font-weight:800;
  letter-spacing:.2px; display:inline-flex; align-items:center; gap:7px; align-self:center;
  border:1px solid var(--line); background:var(--panel); color:var(--ink); transition:.18s;
}
.phase-chip::before{content:""; width:8px; height:8px; border-radius:50%; background:currentColor;}
.phase-chip.select{color:var(--accent); border-color:rgba(91,140,255,.5); background:rgba(91,140,255,.12);}
.phase-chip.place{color:var(--good); border-color:rgba(61,211,155,.5); background:rgba(61,211,155,.12);}

/* ---------- board ---------- */
.board-wrap{flex:1; overflow:auto; display:flex; align-items:center; justify-content:center; padding:10px; min-height:0; position:relative;}
/* While a piece is in hand / pending, the board is drawn in a larger fixed "world"
   frame and moved by a camera translate; clip it to the viewport so the panned
   world never spills over the HUD or dock. */
.board-wrap.holding{overflow:hidden;}
.board{position:relative; margin:auto; touch-action:none; will-change:transform;}
.slot-layer{position:absolute; top:0; left:0;}
.slot,.tile{
  position:absolute; width:var(--cell); height:var(--cell);
  display:flex; align-items:center; justify-content:center;
}
.slot{border-radius:9px; background:rgba(255,255,255,.022); box-shadow:inset 0 0 0 1px rgba(255,255,255,.03);}
.tile{
  border-radius:11px; background:linear-gradient(180deg,var(--tile),var(--tile-lo));
  border:1px solid var(--tile-edge); color:var(--tile-ink);
  font-size:calc(var(--cell)*.5); font-weight:800; touch-action:manipulation;
  box-shadow:inset 0 2px 0 rgba(255,255,255,.16), inset 0 -3px 4px rgba(0,0,0,.28), 0 4px 7px rgba(0,0,0,.35);
  text-shadow:0 1px 1px rgba(0,0,0,.35);
  transition:left .2s cubic-bezier(.2,.8,.2,1), top .2s cubic-bezier(.2,.8,.2,1),
             transform .12s ease, background .15s, border-color .15s, box-shadow .15s;
}
/* Suppress the position transition on a reframe (lift into / commit out of the world
   frame): the coordinate origin shifts under every tile at once, and the camera — not
   an animation — carries the on-screen continuity. Set for one render by renderBoard. */
.board.noanim .tile{transition:none;}
.tile.scoring{background:linear-gradient(180deg,#2a8e6f,#177453); border-color:var(--good); color:#eafff6;
  box-shadow:inset 0 2px 0 rgba(255,255,255,.2), 0 4px 8px rgba(0,0,0,.35), 0 0 0 1px rgba(61,211,155,.25);}
.tile.tappable{cursor:pointer;}
.tile.sel{background:linear-gradient(180deg,var(--gold),var(--gold-lo)); border-color:#ffe08a; color:var(--gold-ink);
  transform:translateY(-3px) scale(1.05); z-index:4; box-shadow:0 8px 14px rgba(0,0,0,.4), inset 0 2px 0 rgba(255,255,255,.4);}
.tile.sel-cand{box-shadow:inset 0 0 0 2px rgba(255,201,75,.55), inset 0 2px 0 rgba(255,255,255,.14), 0 4px 7px rgba(0,0,0,.3);
  background:linear-gradient(180deg,#46508a,#333f73);}
.tile.target{z-index:5; box-shadow:0 0 0 3px var(--accent), inset 0 2px 0 rgba(255,255,255,.18), 0 6px 12px rgba(0,0,0,.4); animation:targetpulse 1.4s ease-in-out infinite;}
@keyframes targetpulse{0%,100%{box-shadow:0 0 0 3px var(--accent), inset 0 2px 0 rgba(255,255,255,.18), 0 6px 12px rgba(0,0,0,.4);} 50%{box-shadow:0 0 0 5px rgba(91,140,255,.55), inset 0 2px 0 rgba(255,255,255,.18), 0 6px 12px rgba(0,0,0,.4);}}
/* placed chunk (gold) vs structure that slid to make room (blue) */
.tile.landing{background:linear-gradient(180deg,var(--gold),var(--gold-lo)); border-color:#ffe08a; color:var(--gold-ink); z-index:3;
  box-shadow:0 0 0 2px rgba(255,201,75,.5), 0 6px 12px rgba(0,0,0,.4), inset 0 2px 0 rgba(255,255,255,.35);}
.tile.pushed{border-color:var(--push-edge); z-index:2;
  box-shadow:0 0 0 2px rgba(132,168,255,.5), 0 5px 10px rgba(0,0,0,.35), inset 0 2px 0 rgba(255,255,255,.18);
  background:linear-gradient(180deg,var(--push),#2a5bb0);}
.tile.enter{animation:tilein .26s cubic-bezier(.2,1.2,.4,1) backwards;}
@keyframes tilein{from{transform:scale(.3); opacity:0;} to{transform:none; opacity:1;}}
.tile.leaving{animation:tileout .2s ease forwards; pointer-events:none; z-index:1;}
@keyframes tileout{to{transform:scale(.4); opacity:0;}}
.tile.shake{animation:shake .34s;}
@keyframes shake{10%,90%{transform:translateX(-2px)} 30%,70%{transform:translateX(4px)} 50%{transform:translateX(-5px)}}
.tile.just-scored{animation:scored .6s ease;}
@keyframes scored{0%{box-shadow:0 0 0 2px var(--good), 0 0 18px 4px rgba(61,211,155,.7);} 40%{transform:translateY(-4px) scale(1.08);} 100%{transform:none;}}
/* cascade wave — the board's word lights up in a cool ripple (§3.7); per-tile stagger in JS */
.tile.cascade-wave{animation:cascadewave .62s ease;}
@keyframes cascadewave{0%{box-shadow:0 0 0 2px var(--accent), 0 0 20px 5px rgba(91,140,255,.75); transform:translateY(-5px) scale(1.1);} 60%{box-shadow:0 0 0 3px rgba(122,240,200,.6), 0 0 14px rgba(122,240,200,.5);} 100%{transform:none;}}
/* long placed word (6+) — a gold shimmer */
.tile.long-word{animation:longword .72s ease;}
@keyframes longword{0%{box-shadow:0 0 0 2px #ffe08a, 0 0 22px 5px rgba(255,201,75,.8); transform:scale(1.1);} 50%{box-shadow:0 0 0 3px var(--gold), 0 0 16px rgba(255,201,75,.6);} 100%{transform:none;}}
.tile.moved{animation:movedpulse .7s ease;}
@keyframes movedpulse{0%,100%{box-shadow:inset 0 2px 0 rgba(255,255,255,.16), inset 0 -3px 4px rgba(0,0,0,.28), 0 4px 7px rgba(0,0,0,.35);} 40%{box-shadow:0 0 0 2px var(--push-edge), 0 0 14px rgba(132,168,255,.6);}}
/* on-board legal-side ghost marker (spatial hint) */
.side-hint{position:absolute; width:var(--cell); height:var(--cell); border-radius:11px; display:flex; align-items:center;
  justify-content:center; font-size:calc(var(--cell)*.4); font-weight:800; color:var(--accent2); cursor:pointer; z-index:3;
  border:2px dashed rgba(122,240,200,.6); background:rgba(122,240,200,.1); animation:tilein .2s backwards;}
.side-hint:active{transform:scale(.92);}

/* ---------- score pop ---------- */
.score-pop{position:absolute; top:0; left:0; width:100%; height:0; pointer-events:none; z-index:20;}
.pop-item{position:absolute; left:50%; top:8px; transform:translateX(-50%); font-weight:800; font-size:22px;
  color:var(--good); text-shadow:0 2px 8px rgba(0,0,0,.5); animation:poprise 1s ease forwards; white-space:nowrap;}
.pop-item.neg{color:var(--bad);}
@keyframes poprise{0%{opacity:0; transform:translate(-50%,10px) scale(.7);} 25%{opacity:1; transform:translate(-50%,-6px) scale(1.1);} 100%{opacity:0; transform:translate(-50%,-46px) scale(1);}}

/* ---------- dock (phase controls) ---------- */
.dock{
  background:linear-gradient(rgba(10,14,26,0),var(--bg2) 34%); border-top:1px solid var(--line);
  padding:12px 14px calc(14px + var(--safe-b)); min-height:118px; box-shadow:0 -8px 24px rgba(0,0,0,.25);
}
.dock-msg{color:var(--muted); font-size:13.5px; margin:0 0 10px; text-align:center; line-height:1.45;}
.dock-msg b{color:var(--ink);}
.dock-banner{display:flex; align-items:center; gap:8px; justify-content:center; flex-wrap:wrap;
  background:rgba(255,107,122,.12); border:1px solid rgba(255,107,122,.5); color:#ffd2d7;
  border-radius:12px; padding:9px 12px; margin-bottom:10px; font-size:13px; font-weight:700;}
.row{display:flex; gap:10px; align-items:center;}
.row.center{justify-content:center;}
.btn{
  border:1px solid var(--line); background:var(--panel); color:var(--ink); border-radius:13px;
  padding:14px 16px; font-size:15.5px; font-weight:800; cursor:pointer; flex:1; text-align:center;
  transition:transform .08s, background .12s, box-shadow .12s;
}
.btn:active{transform:translateY(1px) scale(.99);}
.btn:disabled{opacity:.4;}
.btn.primary{background:linear-gradient(180deg,var(--accent),#3f6fe0); border-color:#7da0ff; color:#fff; box-shadow:0 5px 14px rgba(63,111,224,.4);}
.btn.good{background:linear-gradient(180deg,var(--good),#22a079); border-color:#54e6b4; color:#04241a; box-shadow:0 5px 14px rgba(61,211,155,.35);}
.btn.ghost{background:transparent; box-shadow:none;}
.btn.danger{color:var(--bad); border-color:rgba(255,107,122,.45);}
.btn.small{flex:0 0 auto; padding:11px 14px; font-size:14px;}
.btn.block{width:100%; flex:none;}
.dock-actions{margin-top:10px;}

/* held chunk tray */
.hand{display:flex; align-items:center; gap:10px; justify-content:center; margin-bottom:11px;}
.hand-label{color:var(--muted); font-size:11.5px; text-transform:uppercase; letter-spacing:.5px; font-weight:700;}
.chunk-tiles{display:flex; gap:5px;}
.ctile{
  width:38px; height:38px; border-radius:10px; background:linear-gradient(180deg,var(--gold),var(--gold-lo));
  border:1px solid #ffe08a; color:var(--gold-ink); font-weight:800; display:flex; align-items:center; justify-content:center;
  font-size:19px; box-shadow:inset 0 2px 0 rgba(255,255,255,.4), 0 4px 8px rgba(0,0,0,.35); animation:pop .3s backwards;}
.chunk-tiles .ctile:nth-child(2){animation-delay:.04s} .chunk-tiles .ctile:nth-child(3){animation-delay:.08s}
.chunk-tiles .ctile:nth-child(4){animation-delay:.12s} .chunk-tiles .ctile:nth-child(5){animation-delay:.16s}

/* option list */
.options{display:flex; flex-direction:column; gap:8px; max-height:32vh; overflow:auto; margin-bottom:6px;}
.opt{
  display:flex; align-items:center; gap:11px; padding:11px 13px; border:1px solid var(--line);
  border-radius:13px; background:var(--panel); cursor:pointer; transition:background .12s, border-color .12s, transform .08s;
}
.opt:active{transform:scale(.99);}
.opt.active,.opt:hover{background:var(--panel2); border-color:var(--accent);}
.opt.best{border-color:rgba(61,211,155,.5);}
.opt .dir{font-size:20px; width:22px; text-align:center; color:var(--accent2); flex:0 0 22px;}
.opt .desc{flex:1; min-width:0;}
.opt .desc .main{font-size:14.5px; font-weight:800;}
.opt .desc .main .made{color:var(--good);}
.opt .desc .gloss{font-size:11.5px; color:var(--muted); margin-top:2px;}
.opt .desc .gloss .tag{display:inline-block; font-size:9.5px; font-weight:800; letter-spacing:.4px; text-transform:uppercase;
  color:var(--muted); border:1px solid var(--line); border-radius:6px; padding:0 5px; margin-right:5px;}
.opt .delta{font-weight:800; font-size:13px; text-align:right; flex:0 0 auto; white-space:nowrap;}
.opt .delta.pos{color:var(--good);} .opt .delta.zero{color:var(--muted);} .opt .delta.neg{color:var(--bad);}

/* ---------- overlays ---------- */
.overlay{
  position:fixed; inset:0; background:rgba(5,8,16,.7); backdrop-filter:blur(5px);
  display:none; align-items:flex-end; justify-content:center; z-index:30;
}
.overlay.show{display:flex;}
.sheet{
  width:100%; max-width:560px; background:var(--bg2); border:1px solid var(--line);
  border-radius:22px 22px 0 0; padding:18px 18px calc(20px + var(--safe-b)); max-height:90dvh; overflow:auto;
  animation:slideup .24s cubic-bezier(.2,.9,.3,1); box-shadow:var(--shadow-lg);
}
@keyframes slideup{from{transform:translateY(40px);opacity:.3;} to{transform:none;opacity:1;}}
.sheet-head{display:flex; align-items:center; justify-content:space-between; margin-bottom:6px;}
.sheet-head h2{margin:0; font-size:21px;}
.sheet-body{font-size:14.5px; line-height:1.55; color:#d9e0ff;}
.muted{color:var(--muted); font-size:12.5px;}
/* help steps + demos */
.help-cascade{margin:16px 0; padding:12px 14px; border-radius:12px; background:rgba(91,140,255,.08); border:1px solid rgba(91,140,255,.28);}
.help-cascade h3{margin:0 0 6px; font-size:15px; color:var(--accent);}
.help-cascade p{margin:6px 0;}
.help-cascade ul{margin:6px 0; padding-left:20px;} .help-cascade li{margin:2px 0;}
.help-step{display:flex; gap:12px; margin:14px 0; align-items:flex-start;}
.hs-num{flex:0 0 28px; width:28px; height:28px; border-radius:50%; background:var(--accent); color:#fff;
  font-weight:800; display:flex; align-items:center; justify-content:center; font-size:15px;}
.hs-body{flex:1;}
.mini-demo{display:flex; align-items:center; gap:10px; margin-top:10px; flex-wrap:wrap;}
.md-grid{position:relative; background:rgba(255,255,255,.02); border-radius:8px; padding:3px;}
.md-tile{position:absolute; width:20px; height:20px; border-radius:5px; display:flex; align-items:center; justify-content:center;
  font-size:11px; font-weight:800; background:linear-gradient(180deg,var(--tile),var(--tile-lo)); border:1px solid var(--tile-edge); color:var(--tile-ink);}
.md-tile.g{background:linear-gradient(180deg,var(--gold),var(--gold-lo)); border-color:#ffe08a; color:var(--gold-ink);}
.md-tile.b{background:linear-gradient(180deg,var(--push),#2a5bb0); border-color:var(--push-edge);}
.md-arrow{color:var(--muted); font-size:18px;}
.legend-intro{margin-top:16px;}
.legend{list-style:none; padding:0; margin:8px 0; display:flex; flex-direction:column; gap:6px;}
.legend li{font-size:13px; color:var(--muted);}
.lg-tag{display:inline-block; min-width:62px; font-size:10.5px; font-weight:800; text-transform:uppercase; letter-spacing:.4px;
  color:var(--accent2); border:1px solid rgba(122,240,200,.4); border-radius:7px; padding:2px 7px; margin-right:8px; text-align:center;}
.chip-good,.chip-gold,.chip-blue{display:inline-block; font-size:11.5px; font-weight:800; border-radius:7px; padding:1px 7px;}
.chip-good{background:var(--good-bg); color:var(--good); border:1px solid var(--good);}
.chip-gold{background:rgba(255,201,75,.16); color:var(--gold); border:1px solid var(--gold);}
.chip-blue{background:rgba(63,116,214,.18); color:var(--push-edge); border:1px solid var(--push-edge);}
#helpCta{margin-top:18px;}
/* result */
.result-sheet{text-align:center; border-radius:22px; margin:0 14px 14px; align-self:center; position:relative; overflow:visible;}
.overlay.result-mode{align-items:center;}
.result-close{position:absolute; top:12px; right:12px;}
.result-stars{font-size:40px; letter-spacing:6px; color:var(--gold); height:48px; margin-bottom:2px;}
.result-stars .dim{color:var(--line);}
.result-stars span{display:inline-block; animation:pop .4s backwards;}
.result-stars span:nth-child(2){animation-delay:.12s} .result-stars span:nth-child(3){animation-delay:.24s}
.result-icon{font-size:50px; line-height:1;}
.result-sheet h2{margin:6px 0;}
.result-sheet #resultText{font-size:15px; line-height:1.5; color:#d9e0ff; margin:6px 6px 0;}
.result-sheet #resultText b{color:var(--ink);}
.res-note{display:block; margin-top:9px; font-size:13px; font-weight:600; color:var(--muted);}
.res-note.good{color:var(--good);}
.res-note b{color:var(--ink);}
/* win sheet: star labels · points · word tiers · moves line (§3.5) */
.res-labels{font-size:11px; font-weight:800; letter-spacing:.8px; margin:2px 0 12px;}
.res-lab{color:var(--line); text-transform:uppercase;}
.res-lab.on{color:var(--gold);}
.res-lock{display:block; margin-top:6px; font-size:11px; font-weight:600; letter-spacing:.3px; color:var(--muted); text-transform:none;}
.res-pts{font-size:26px; font-weight:800; margin:2px 0 12px;} .res-pts b{color:var(--gold);}
.res-tiers{display:inline-block; text-align:left; margin:0 auto 10px;}
.res-tier-h{font-size:10px; font-weight:800; letter-spacing:.8px; text-transform:uppercase; color:var(--muted); margin-bottom:4px;}
.res-tier{font-size:14px; line-height:1.7; color:#d9e0ff;}
.res-moves{font-size:13px; font-weight:600; color:var(--muted); margin-top:4px;}
.result-actions{display:flex; flex-direction:column; gap:10px; margin-top:18px;}
.result-actions .btn{width:100%;}
.share-btn{margin-top:10px; width:100%; font-size:14px;}

/* confetti */
.confetti{position:fixed; inset:0; pointer-events:none; z-index:40; overflow:hidden;}
.confetti i{position:absolute; top:-12px; width:9px; height:14px; border-radius:2px; opacity:.95; animation:fall linear forwards;}
@keyframes fall{to{transform:translateY(108vh) rotate(720deg); opacity:.9;}}

.toast{
  position:fixed; left:50%; bottom:calc(150px + var(--safe-b)); transform:translateX(-50%) translateY(18px);
  background:var(--panel2); border:1px solid var(--line); border-left:4px solid var(--warn); color:var(--ink);
  padding:11px 16px; border-radius:12px; box-shadow:var(--shadow);
  font-size:13.5px; font-weight:600; opacity:0; pointer-events:none; transition:.2s; z-index:50; max-width:88vw; text-align:center;
}
.toast.show{opacity:1; transform:translateX(-50%) translateY(0);}

/* ---------- responsive: narrow width ---------- */
@media (max-width:360px){
  .stat-row{gap:8px;}
  .stat-actions{gap:4px;}
  .mini-btn{min-width:34px; padding:0 6px; font-size:15px;}
  .stat.score .stat-val{font-size:26px;}
  .stat.goal{padding:3px 10px;} .stat.goal .stat-val{font-size:25px;}
  .moves-stat .stat-val{font-size:19px;}
}

/* ---------- responsive: short / landscape ---------- */
@media (max-height:540px), (orientation:landscape) and (max-height:600px){
  .stats{padding:5px 14px 2px; gap:5px;} .stat.score .stat-val{font-size:24px;}
  .stat.goal{padding:2px 12px;} .stat.goal .stat-val{font-size:24px;}
  .bar{height:9px;}
  .phase-chip{margin:3px auto 0; padding:4px 12px;}
  .dock{min-height:96px; padding-top:9px;}
  .options{max-height:26vh;}
  .board-wrap{padding:6px;}
}

/* ---------- drag-and-drop interaction ---------- */
.tile.legal{box-shadow:inset 0 0 0 2px rgba(122,240,200,.6), inset 0 2px 0 rgba(255,255,255,.14), 0 4px 7px rgba(0,0,0,.3); cursor:pointer;}
/* home glow: a legal spot whose result is congruent to B0 — dropping there
   returns the board (MOVES +0, free). Bright violet, thick, gently pulsing to
   invite the eye; distinct from the green legal glow. */
.tile.home{box-shadow:inset 0 0 0 3px #b88aff, 0 0 15px rgba(184,138,255,.6), inset 0 2px 0 rgba(255,255,255,.14), 0 4px 7px rgba(0,0,0,.3); cursor:pointer; animation:homepulse 1.5s ease-in-out infinite;}
@keyframes homepulse{
  0%,100%{box-shadow:inset 0 0 0 3px #b88aff, 0 0 11px rgba(184,138,255,.5), inset 0 2px 0 rgba(255,255,255,.14), 0 4px 7px rgba(0,0,0,.3);}
  50%    {box-shadow:inset 0 0 0 3px #d3bcff, 0 0 24px rgba(184,138,255,.92), inset 0 2px 0 rgba(255,255,255,.14), 0 4px 7px rgba(0,0,0,.3);}
}
/* the held piece resting on a home spot: unmistakable violet double-ring + halo */
.tile.landing.home{box-shadow:inset 0 0 0 3px #d3bcff, 0 0 0 4px rgba(184,138,255,.9), 0 0 20px rgba(184,138,255,.75), inset 0 2px 0 rgba(255,255,255,.4), 0 6px 12px rgba(0,0,0,.4);}
/* pending piece: real on the board but not yet committed (this move) — dashed collar */
.tile.pending{outline:2px dashed rgba(255,255,255,.72); outline-offset:-5px;}
/* armed Turn: lit button + a translucent DASHED ghost of the piece in its rotated
   orientation, floated over the selection (the "outline"). */
.btn.small.armed{color:var(--gold-ink); background:linear-gradient(180deg,var(--gold),var(--gold-lo)); border-color:#ffe08a;}
.puck.ghost{opacity:1; filter:none; z-index:58;}
.puck.ghost .ptile{background:linear-gradient(180deg,rgba(255,201,75,.2),rgba(154,110,21,.16)); border:2.5px dashed #ffe08a; color:rgba(255,236,178,.95); box-shadow:0 0 12px rgba(255,201,75,.4); animation:ghostpulse 1.25s ease-in-out infinite;}
@keyframes ghostpulse{0%,100%{border-color:#ffdf8a; box-shadow:0 0 8px rgba(255,201,75,.3);} 50%{border-color:#fff3cf; box-shadow:0 0 16px rgba(255,201,75,.65);}}
.home-note{color:#c9b8ff; font-weight:700;}
.puck{
  position:fixed; z-index:60; display:flex; gap:4px; touch-action:none; pointer-events:none;
  filter:drop-shadow(0 12px 18px rgba(0,0,0,.55));
}
.puck[hidden]{display:none;}
.puck.vert{flex-direction:column;}
.puck.dragging{opacity:.94;}
/* anchor of the seated selection (pivot for refine/deselect) */
.tile.anchor{box-shadow:inset 0 0 0 3px rgba(255,255,255,.92), 0 8px 14px rgba(0,0,0,.4), inset 0 2px 0 rgba(255,255,255,.4);}
.ptile{
  position:relative; width:var(--pcell,46px); height:var(--pcell,46px); border-radius:11px;
  display:flex; align-items:center; justify-content:center;
  font-size:calc(var(--pcell,46px)*.5); font-weight:800; color:var(--gold-ink);
  background:linear-gradient(180deg,var(--gold),var(--gold-lo)); border:1px solid #ffe08a;
  box-shadow:inset 0 2px 0 rgba(255,255,255,.4), 0 3px 6px rgba(0,0,0,.35);
}
.ptile .dot{position:absolute; top:4px; left:4px; width:7px; height:7px; border-radius:50%; background:rgba(27,20,3,.6);}

/* ---------- how-to-play demo (autoplay solve of Puzzle 1) ---------- */
.demo-cta{width:100%; margin:14px 0 2px; background:linear-gradient(180deg,var(--accent),#3f6fe0);
  border-color:#7da0ff; color:#fff; box-shadow:0 5px 14px rgba(63,111,224,.4);}
/* the ghost hand pointer — a translucent neon hand whose FINGERTIP is the hotspot.
   left/top are set to the target cell centre; the transform lands the fingertip
   there (tip ≈ 10px,4px inside the 86×108 sprite) and is the pivot for the press
   "tap" scale. Asset: web/assets/hand.png (chroma-keyed from doc/images/hand.png). */
.demo-finger{position:fixed; left:0; top:0; z-index:62; width:86px; height:108px; pointer-events:none; opacity:0;
  background:url("assets/hand.png") left top/contain no-repeat;
  transform:translate(-10px,-4px); transform-origin:10px 4px;
  filter:drop-shadow(0 0 9px rgba(122,240,200,.45)) drop-shadow(0 10px 16px rgba(0,0,0,.5));
  transition:left .5s cubic-bezier(.45,.05,.25,1), top .5s cubic-bezier(.45,.05,.25,1), transform .16s ease, opacity .25s;}
.demo-finger.show{opacity:.95;}
.demo-finger.press{transform:translate(-10px,-4px) scale(.9);}
/* a soft mint tap-ring pulses out from the fingertip on each press */
.demo-finger::after{content:""; position:absolute; left:10px; top:4px; width:16px; height:16px; margin:-8px 0 0 -8px;
  border-radius:50%; border:2px solid rgba(122,240,200,.9); opacity:0; pointer-events:none;}
.demo-finger.press::after{animation:tapring .5s ease-out;}
@keyframes tapring{0%{opacity:.85; transform:scale(.35);} 100%{opacity:0; transform:scale(2.6);}}
.demo-caption{position:absolute; left:50%; top:6px; transform:translateX(-50%); z-index:21; max-width:92%;
  background:rgba(18,26,50,.94); border:1px solid var(--line); color:var(--ink); border-radius:14px;
  padding:8px 14px; font-size:13.5px; font-weight:700; text-align:center; line-height:1.35;
  box-shadow:var(--shadow); backdrop-filter:blur(6px); opacity:0; transition:opacity .22s, transform .22s; pointer-events:none;}
.demo-caption.show{opacity:1;}
.demo-caption b{color:var(--accent2);}
.demo-caption .dc-tag{display:inline-block; font-size:9.5px; font-weight:800; letter-spacing:.7px; color:var(--gold);
  border:1px solid rgba(255,201,75,.45); border-radius:6px; padding:1px 6px; margin-right:8px; vertical-align:1px;}
.demo-skip{position:fixed; right:14px; bottom:calc(20px + var(--safe-b)); z-index:62;
  background:var(--panel2); border:1px solid var(--line); color:var(--ink); border-radius:20px;
  padding:9px 16px; font-size:13.5px; font-weight:800; cursor:pointer; box-shadow:var(--shadow); opacity:0;
  transition:opacity .25s, transform .08s;}
body.demo-on .demo-skip{opacity:1;}
.demo-skip:active{transform:scale(.94);}
/* dim + disable the live HUD controls while the demo plays; keep the dock fully
   visible (so the real ↻ Turn button lights when armed) but not user-clickable —
   the ghost hand drives the real gestures, so the user never touches the board. */
body.demo-on .stat-actions, body.demo-on .gamebar .icon-btn{opacity:.45; pointer-events:none;}
body.demo-on .dock{pointer-events:none;}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion:reduce){
  *{animation-duration:.001s !important; animation-iteration-count:1 !important;
    transition-duration:.001s !important;}
  /* keep a brief acknowledgment pulse alive — cascade/long-word FX fall back to it (§3.7) */
  .tile.just-scored{animation-duration:.3s !important;}
  .confetti{display:none;}
}
