/* Mathgic: one screen. The family's light paper page with the board in a deep "night window", so the fireworks read
   well in both themes. Tiles are all one colour (colour never hints at an answer); colour lives only in the shows.
   Calm motion (html.calm) and reduced motion: nothing moves (no fall, no breathing hint, no card rise). */
:root{
  --paper:#f1eee8; --rule:rgba(70,52,120,.07); --ink:#1d1a33; --muted:#625d7a;
  --tile:#ffffff; --tile-edge:#d5cfe2; --given:#e9e5f1; --panel:rgba(255,255,255,.78); --panel-line:rgba(29,26,51,.1);
  --you:#5b3fd6; --you-soft:#e7e1fb; --you-edge:#3f28a8; --on-you:#ffffff;
  --gold:#f2b632; --scrim:rgba(241,238,232,.74);
  --night1:#141a3a; --night2:#251c4f; --night-line:rgba(255,255,255,.08);
  --stone:#fbf6ea; --stone-edge:#cbbfa4; --stone-ink:#1d1a33; --stone-lit:#fff3c9; --glow:#ffd36a;
  --lift:0 1px 2px rgba(29,26,51,.06),0 16px 44px rgba(29,26,51,.16);
  --font-display:"Fredoka","Baloo 2","Trebuchet MS",system-ui,sans-serif;
  --font-body:"Nunito",system-ui,-apple-system,"Segoe UI",sans-serif;
}
@media (prefers-color-scheme: dark){ :root:not([data-theme="light"]){
  --paper:#0d1124; --rule:rgba(160,150,255,.05); --ink:#ece9fb; --muted:#a29dc0;
  --tile:#1c2142; --tile-edge:#080a18; --given:#262c52; --panel:rgba(26,30,60,.82); --panel-line:rgba(236,233,251,.1);
  --you:#8f7bff; --you-soft:#2a2560; --you-edge:#5b48d6; --on-you:#ffffff; --scrim:rgba(13,17,36,.76);
  --night1:#0a0e22; --night2:#1a1440; --stone:#ece5d2; --stone-edge:#8f8670; --stone-lit:#fff0bd;
  --lift:0 1px 0 rgba(236,233,251,.06) inset,0 18px 48px rgba(0,0,0,.5); color-scheme:dark;
}}
:root[data-theme="dark"]{
  --paper:#0d1124; --rule:rgba(160,150,255,.05); --ink:#ece9fb; --muted:#a29dc0;
  --tile:#1c2142; --tile-edge:#080a18; --given:#262c52; --panel:rgba(26,30,60,.82); --panel-line:rgba(236,233,251,.1);
  --you:#8f7bff; --you-soft:#2a2560; --you-edge:#5b48d6; --on-you:#ffffff; --scrim:rgba(13,17,36,.76);
  --night1:#0a0e22; --night2:#1a1440; --stone:#ece5d2; --stone-edge:#8f8670; --stone-lit:#fff0bd;
  --lift:0 1px 0 rgba(236,233,251,.06) inset,0 18px 48px rgba(0,0,0,.5); color-scheme:dark;
}
html,body{height:100%; touch-action:manipulation}
body{background-color:var(--paper); background-image:radial-gradient(var(--rule) 1.2px, transparent 1.3px); background-size:22px 22px;
  color:var(--ink); font-family:var(--font-body); margin:0; overflow:hidden; -webkit-tap-highlight-color:transparent; user-select:none; -webkit-user-select:none}
button{font:inherit; color:inherit; cursor:pointer}
[hidden]{display:none!important}
h1,h2{font-family:var(--font-display); font-weight:600; margin:0}
#app{height:100vh; height:100dvh; max-width:640px; margin:0 auto; display:flex; flex-direction:column; gap:8px; box-sizing:border-box;
  padding:max(8px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(10px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px))}

/* ---------- the top bar ---------- */
.topbar{display:flex; flex-direction:column; gap:6px; min-width:0}
.hud{display:flex; align-items:center; gap:8px; min-width:0}
.lvl{font-family:var(--font-display); font-weight:600; font-size:15px; padding:4px 11px; border-radius:999px; background:var(--ink); color:var(--paper); white-space:nowrap}
.prog{flex:1 1 auto; min-width:0; display:flex; align-items:center; gap:8px}
.prog .bar{flex:1; height:10px; border-radius:99px; background:var(--given); overflow:hidden}
.prog .bar i{display:block; height:100%; width:0; border-radius:99px; background:linear-gradient(90deg, var(--you), #c86bfa, var(--gold)); transition:width .45s ease}
.prog b{font:600 15px/1 var(--font-display); font-variant-numeric:tabular-nums; white-space:nowrap}
.stat{padding:4px 10px; border-radius:14px; background:var(--panel); border:1px solid var(--panel-line)}
.stat b{font:600 18px/1 var(--font-display); font-variant-numeric:tabular-nums; color:var(--you)}
.iconbtn{flex:none; width:44px; height:44px; border-radius:50%; border:1px solid var(--panel-line); background:var(--tile); box-shadow:0 3px 0 var(--tile-edge); font:700 18px/1 var(--font-display); padding:0}
.iconbtn:active{transform:translateY(2px); box-shadow:0 1px 0 var(--tile-edge)}
.racebar{display:flex; flex-direction:column; gap:3px}
.racebar .rr{display:flex; align-items:center; gap:6px; font-size:12px; font-weight:800; color:var(--muted)}
.racebar .rr .nm{width:54px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap}
.racebar .rr .tr{flex:1; height:6px; border-radius:6px; background:var(--given); position:relative}
.racebar .rr .tr i{position:absolute; left:0; top:0; bottom:0; border-radius:6px; background:var(--c, var(--you)); transition:width .4s ease}
.racebar .rr.me .nm{color:var(--ink)}

/* ---------- the formula line ---------- */
.line{min-height:52px; display:flex; align-items:center; justify-content:center; flex-wrap:nowrap; gap:6px; padding:4px 8px; border-radius:16px;
  font:600 26px/1 var(--font-display); font-variant-numeric:tabular-nums; color:var(--ink); white-space:nowrap; overflow:hidden; transition:background .2s, box-shadow .2s}
.line .lh{font:700 15px/1.2 var(--font-body); color:var(--muted); white-space:normal; text-align:center}
.line .n{display:inline-flex; align-items:center}
.line .s{color:var(--muted); min-width:.5em; text-align:center; transition:opacity .15s}
.line .s.dot{opacity:.35; font-size:.7em}
.line.ok{background:var(--you-soft); box-shadow:0 0 0 2px color-mix(in srgb, var(--you) 40%, transparent)}
.line.ok .s{color:var(--you)}
.line.praise{font-size:20px; color:var(--you)}
.line.small{font-size:20px} .line.tiny{font-size:16px}
.fr{display:inline-flex; flex-direction:column; align-items:center; vertical-align:middle; line-height:1; font-size:.62em; margin:0 .06em}
.fr > span:first-child{border-bottom:.09em solid currentColor; padding:0 .12em .06em}
.fr > span:last-child{padding:.06em .12em 0}
.wh{margin-right:.08em}

/* ---------- the stage: the night window, the board, the fireworks ---------- */
.stage{position:relative; flex:1 1 0; min-height:240px; border-radius:24px; overflow:hidden; touch-action:none;
  background:radial-gradient(120% 90% at 50% 0%, var(--night2), var(--night1) 70%); box-shadow:inset 0 0 0 1px var(--night-line), 0 10px 30px rgba(20,16,60,.18)}
.sky{position:absolute; inset:0; pointer-events:none; opacity:.55;
  background-image:radial-gradient(1px 1px at 12% 18%, #fff 50%, transparent 51%), radial-gradient(1px 1px at 78% 12%, #fff 50%, transparent 51%),
    radial-gradient(1.4px 1.4px at 46% 8%, #ffe9b0 50%, transparent 51%), radial-gradient(1px 1px at 88% 46%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 6% 64%, #fff 50%, transparent 51%), radial-gradient(1.2px 1.2px at 62% 92%, #d6ccff 50%, transparent 51%),
    radial-gradient(1px 1px at 30% 40%, #fff 50%, transparent 51%), radial-gradient(1px 1px at 94% 82%, #fff 50%, transparent 51%)}
.board{position:absolute; left:50%; top:50%; transform:translate(-50%, -50%); width:calc(var(--cell) * var(--cols, 6)); height:calc(var(--cell) * var(--rows, 7)); --cell:56px; touch-action:none; overflow:hidden; border-radius:calc(var(--cell) * .2)}
/* the levels: the board stands at the foot of the night window, the sky above it for the shows (no empty band below) */
#app:not(.duel) .board{top:auto; bottom:var(--foot, 10px); transform:translateX(-50%); overflow:visible}
/* Every value has its own look (src/palette.js: --a --m --b the stops, --e the edge, --g the glow, a pattern class);
   the same value always looks the same and nothing about a tile's look depends on a formula. The glyph is the dark ink
   on a light tile (WCAG AA large text at every stop, tests/check-palette.mjs). */
.tile{position:absolute; left:0; top:0; width:var(--cell); height:var(--cell); display:grid; place-items:center; pointer-events:none; will-change:transform}
.tile .st{position:relative; width:88%; height:88%; box-sizing:border-box; border-radius:calc(var(--cell) * .24); color:#1d1a33; isolation:isolate;
  background:linear-gradient(150deg, var(--a, var(--stone)) 8%, var(--m, var(--stone)) 52%, var(--b, var(--stone)) 96%);
  display:grid; place-items:center; box-shadow:inset 0 calc(var(--cell) * .035) 0 rgba(255,255,255,.55), inset 0 0 0 1px rgba(255,255,255,.35), 0 calc(var(--cell) * .055) 0 var(--e, var(--stone-edge)), 0 5px 12px rgba(0,0,0,.32);
  font:600 calc(var(--cell) * .46)/1 var(--font-display); font-variant-numeric:tabular-nums; letter-spacing:-.01em; transition:transform .12s ease, box-shadow .15s, opacity .3s ease}
.tile .st > span{position:relative; z-index:2; white-space:nowrap; max-width:96%; overflow:hidden; text-align:center; text-shadow:0 1px 0 rgba(255,255,255,.45)}
/* a fraction: its numerator's colour over its denominator's, as it is written */
.tile .st.frac{background:linear-gradient(180deg, var(--a) 0 50%, var(--b) 50% 100%)}
/* a negative number: its digits' look inside a dark inner rim */
.tile .st.neg{box-shadow:inset 0 0 0 calc(var(--cell) * .055) rgba(29,26,51,.62), inset 0 calc(var(--cell) * .09) 0 rgba(255,255,255,.4), 0 calc(var(--cell) * .055) 0 var(--e), 0 5px 12px rgba(0,0,0,.32)}
/* the surface pattern (white, faint: it tells the looks apart without colour) */
.tile .st::before{content:''; position:absolute; inset:0; border-radius:inherit; z-index:1; opacity:.34; pointer-events:none; --w:rgba(255,255,255,.9); background-size:calc(var(--cell) * .2) calc(var(--cell) * .2)}
.tile .st.pat-rings::before{background-image:repeating-radial-gradient(circle at 50% 50%, transparent 0 calc(var(--cell) * .07), var(--w) calc(var(--cell) * .07) calc(var(--cell) * .09)); background-size:auto}
.tile .st.pat-slash::before{background-image:repeating-linear-gradient(45deg, var(--w) 0 2px, transparent 2px calc(var(--cell) * .1)); background-size:auto}
.tile .st.pat-back::before{background-image:repeating-linear-gradient(-45deg, var(--w) 0 2px, transparent 2px calc(var(--cell) * .1)); background-size:auto}
.tile .st.pat-rows::before{background-image:repeating-linear-gradient(0deg, var(--w) 0 2px, transparent 2px calc(var(--cell) * .11)); background-size:auto}
.tile .st.pat-cols::before{background-image:repeating-linear-gradient(90deg, var(--w) 0 2px, transparent 2px calc(var(--cell) * .11)); background-size:auto}
.tile .st.pat-dots::before{background-image:radial-gradient(circle, var(--w) 0 1.6px, transparent 2.2px)}
.tile .st.pat-bigdots::before{background-image:radial-gradient(circle, var(--w) 0 3px, transparent 3.6px); background-size:calc(var(--cell) * .28) calc(var(--cell) * .28)}
.tile .st.pat-fine::before{background-image:radial-gradient(circle, var(--w) 0 1px, transparent 1.5px); background-size:calc(var(--cell) * .1) calc(var(--cell) * .1)}
.tile .st.pat-grid::before{background-image:linear-gradient(var(--w) 0 1.5px, transparent 1.5px), linear-gradient(90deg, var(--w) 0 1.5px, transparent 1.5px)}
.tile .st.pat-check::before{background-image:conic-gradient(var(--w) 25%, transparent 0 50%, var(--w) 0 75%, transparent 0); opacity:.2; background-size:calc(var(--cell) * .22) calc(var(--cell) * .22)}
.tile .st.pat-diamond::before{background-image:repeating-linear-gradient(45deg, var(--w) 0 1.5px, transparent 1.5px calc(var(--cell) * .14)), repeating-linear-gradient(-45deg, var(--w) 0 1.5px, transparent 1.5px calc(var(--cell) * .14)); background-size:auto}
/* the gentle idle life: a slow sheen breathes across each tile, every tile of a value in step (off in Calm) */
.tile .st::after{content:''; position:absolute; inset:0; border-radius:inherit; z-index:1; pointer-events:none; opacity:0;
  background:linear-gradient(135deg, rgba(255,255,255,.55), rgba(255,255,255,0) 55%); animation:sheen 7s ease-in-out infinite; animation-delay:var(--d, 0s)}
@keyframes sheen{0%, 100%{opacity:0} 50%{opacity:.5}}
.tile.l3 .st{font-size:calc(var(--cell) * .37)} .tile.l4 .st{font-size:calc(var(--cell) * .31)} .tile.l5 .st{font-size:calc(var(--cell) * .25)} .tile.l7 .st{font-size:calc(var(--cell) * .2)}
/* the trace: traced tiles lift, ringed in white with a glow of their own colour; a true formula adds the gold ring */
.tile.on{z-index:3}
.tile.on .st{transform:scale(1.1); box-shadow:inset 0 calc(var(--cell) * .035) 0 rgba(255,255,255,.6), 0 0 0 3px #fff, 0 0 calc(var(--cell) * .38) var(--g, #fff), 0 calc(var(--cell) * .055) 0 var(--e, var(--stone-edge))}
.tile.ok .st{box-shadow:inset 0 calc(var(--cell) * .035) 0 rgba(255,255,255,.6), 0 0 0 3px var(--glow), 0 0 0 6px rgba(255,255,255,.55), 0 0 calc(var(--cell) * .45) var(--g, var(--glow)), 0 calc(var(--cell) * .055) 0 var(--e, var(--stone-edge))}
.tile.turn .st > span{transform:rotate(180deg)}
/* Duel: the two halves read apart by a frame, never by colour: side a a solid rim, side b a dashed rim; the half whose
   turn it is not steps back a little */
.tile.sa .st{outline:2px solid rgba(255,255,255,.8); outline-offset:2px}
.tile.sb .st{outline:2px dashed rgba(255,236,180,.85); outline-offset:2px}
.tile.rest .st{opacity:.62}
.tile.hint .st{animation:breathe 2.4s ease-in-out infinite}
@keyframes breathe{50%{box-shadow:0 0 0 4px rgba(255,236,170,.8), 0 0 18px rgba(255,220,130,.55), 0 calc(var(--cell) * .055) 0 var(--e, var(--stone-edge))}}
/* while a show plays the tiles that are not in it step back a little; play resumes at full brightness */
.board.showing .tile:not(.lit):not(.gone) .st{opacity:.7}
.tile.gone .st{transition:transform .26s ease-in, opacity .26s ease-in; transform:scale(.4); opacity:0}
.tile.wait .st{opacity:.7}
/* a fresh tile arrives with a soft glint of its own colour (a slow rise and fade, never a flash; off in Calm) */
.tile.glint .st{animation:glint 1.1s ease-out}
@keyframes glint{0%{box-shadow:0 0 0 0 var(--g), 0 calc(var(--cell) * .055) 0 var(--e)} 35%{box-shadow:0 0 calc(var(--cell) * .4) calc(var(--cell) * .04) var(--g), 0 calc(var(--cell) * .055) 0 var(--e)} 100%{box-shadow:0 0 0 0 transparent, 0 calc(var(--cell) * .055) 0 var(--e)}}
.trail{position:absolute; inset:0; z-index:4; pointer-events:none; overflow:visible}
.trail line{stroke-linecap:round}
.trail .core{stroke:rgba(255,255,255,.75)}
.fx{position:absolute; inset:0; width:100%; height:100%; pointer-events:none}
.tags{position:absolute; inset:0; pointer-events:none}
.tag{position:absolute; transform:translate(-50%, -100%); display:flex; align-items:center; gap:4px; padding:3px 8px 3px 4px; border-radius:999px; background:rgba(255,255,255,.88); color:#1d1a33; font:800 12px/1 var(--font-body); transition:opacity .6s}
.tag canvas{width:20px!important; height:20px!important; border-radius:50%}

/* ---------- Duel on one device: a bar at each end, the far one turned to face its player ---------- */
#app.duel .topbar{display:none}
.dbar{display:grid; grid-template-columns:auto 1fr auto; grid-template-rows:auto auto; align-items:center; column-gap:10px; row-gap:4px; padding:6px 10px; border-radius:16px; background:var(--panel); border:1px solid var(--panel-line); transition:box-shadow .25s, background .25s}
.dbar.far{transform:rotate(180deg)}
.dbar .dn{font:600 17px/1.1 var(--font-display); white-space:nowrap; overflow:hidden; text-overflow:ellipsis}
.dbar .dg{grid-column:3; font:600 26px/1 var(--font-display); font-variant-numeric:tabular-nums; color:var(--you)}
.dbar .dg::after{content:' ' attr(data-u); font:800 12px/1 var(--font-body); color:var(--muted)}
.dbar .dl{grid-column:1 / -1; min-height:34px; display:flex; align-items:center; justify-content:center; gap:5px; font:600 22px/1 var(--font-display); color:var(--muted); white-space:nowrap; overflow:hidden}
.dbar .dl .lh{font:700 14px/1.2 var(--font-body); white-space:normal; text-align:center}
.dbar .dl .s{color:var(--you)}
.dbar.on{background:var(--you-soft); box-shadow:0 0 0 2px var(--you)}
.dbar.on .dl{color:var(--ink)}
.dbar #duelMenu{grid-column:2; grid-row:1; justify-self:end; width:38px; height:38px; font-size:15px}
.duelbtn{display:flex; flex-direction:column; align-items:flex-start; gap:2px; text-align:left; padding:12px 16px}
.duelbtn b{font:600 18px/1.15 var(--font-display)} .duelbtn span{font:700 13px/1.3 var(--font-body); color:var(--muted)}
.stage .mid{position:absolute; left:8%; right:8%; height:0; border-top:2px dashed rgba(255,236,180,.35); pointer-events:none}

/* ---------- cards ---------- */
.overlay{position:fixed; inset:0; z-index:40; display:grid; place-items:center; background:var(--scrim); backdrop-filter:blur(5px); -webkit-backdrop-filter:blur(5px); overflow:auto; box-sizing:border-box;
  padding:max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left))}
.card{width:100%; max-width:440px; box-sizing:border-box; padding:22px 20px 18px; border-radius:24px; background:var(--tile); box-shadow:var(--lift); display:flex; flex-direction:column; gap:14px; animation:cardIn .4s cubic-bezier(.3,1.3,.5,1)}
@keyframes cardIn{from{transform:translateY(18px); opacity:0}}
.card h2{text-align:center; font-size:24px}
.sub{margin:0; text-align:center; color:var(--muted); font-size:14px; font-weight:700}
.btn{border:0; border-radius:16px; min-height:56px; padding:12px 18px; font-family:var(--font-display); font-weight:600; font-size:20px; background:var(--you); color:var(--on-you); box-shadow:0 4px 0 var(--you-edge); touch-action:manipulation}
.btn:active{transform:translateY(3px); box-shadow:0 1px 0 var(--you-edge)}
.btn.ghost{min-height:48px; background:var(--given); color:var(--ink); box-shadow:none; font-size:17px}
.btn.ghost:active{transform:translateY(1px)}
.btn[disabled]{opacity:.55; pointer-events:none}
.btns{display:flex; flex-direction:column; gap:10px}
.chip{padding:6px 10px; border-radius:999px; border:0; background:var(--given); color:var(--ink); font-size:13px; font-weight:800}
.btn:focus-visible,.chip:focus-visible,.choice:focus-visible,.linkbtn:focus-visible,.iconbtn:focus-visible,.topic:focus-visible,.way:focus-visible,.pl-tgt:focus-visible{outline:3px solid var(--you); outline-offset:2px}
.linkbtn{border:0; background:none; padding:8px 4px; min-height:40px; font:700 14px/1.2 var(--font-body); color:var(--muted); text-decoration:underline; text-underline-offset:3px}
.linkbtn[aria-pressed="true"]#calmBtn, .linkbtn[aria-pressed="true"]#calmBtn2{color:var(--you)}
.foot{display:flex; justify-content:center; align-items:center; gap:4px; flex-wrap:wrap; color:var(--muted)}
.together{margin:0; text-align:center; text-wrap:balance; font-size:13px; font-weight:700; color:var(--muted)}

/* the start card */
.card.start{position:relative; gap:14px; padding-top:18px}
.card.start .mebtn{align-self:flex-end; display:inline-flex; align-items:center; gap:6px; min-height:44px; padding:6px 14px 6px 10px; margin:-6px -4px -6px 0; font:800 14px/1 var(--font-body); max-width:60%; overflow:hidden; white-space:nowrap}
.mebtn .me-face{border-radius:50%}
.start-head{display:flex; flex-direction:column; align-items:center; gap:10px}
.logo-tiles{display:flex; align-items:center; gap:5px; padding:10px 14px; border-radius:18px; background:radial-gradient(120% 120% at 50% 0%, var(--night2), var(--night1)); box-shadow:0 0 0 1px var(--night-line)}
.logo-tiles span{min-width:38px; height:38px; padding:0 4px; box-sizing:border-box; display:grid; place-items:center; border-radius:10px; background:linear-gradient(150deg, var(--a, var(--stone-lit)), var(--b, var(--stone-lit))); color:var(--stone-ink); font:600 22px/1 var(--font-display); box-shadow:inset 0 2px 0 rgba(255,255,255,.55), 0 0 0 2px rgba(255,255,255,.7), 0 0 14px var(--g, rgba(255,211,106,.5))}
.logo-tiles i{font:600 20px/1 var(--font-display); font-style:normal; color:#ffe7a6}
.card.start h1{font-size:40px; letter-spacing:.01em}
.pl-tgt{width:100%; min-height:48px; padding:8px 14px; border:0; border-radius:14px; background:var(--you-soft); color:var(--ink); font:800 15px/1.25 var(--font-body); text-align:left; display:flex; flex-direction:column; gap:2px; justify-content:center; touch-action:manipulation}
.pl-tgt .tg-go{color:var(--you); font-size:14px}
.choice{display:flex; align-items:center; justify-content:space-between; gap:12px; width:100%; min-height:52px; padding:10px 16px; border:0; border-radius:16px; background:var(--given); color:var(--ink); text-align:left; touch-action:manipulation}
.choice .ct{min-width:0; font:600 17px/1.2 var(--font-display); overflow-wrap:anywhere}
.choice .cg{flex:none; font-size:15px; font-weight:800; color:var(--you)}
.startmain{display:flex; flex-direction:column; gap:12px}
.ageask{display:flex; flex-direction:column; gap:12px}
.ageask h2{font-size:24px; text-align:center}
.agebig{display:grid; grid-template-columns:repeat(5, 1fr); gap:8px}
.agebig button{min-height:52px; border:0; border-radius:14px; background:var(--given); font:600 20px/1 var(--font-display)}

/* the topic sheet */
.card.sheet{max-height:calc(100dvh - 32px); overflow:auto; overscroll-behavior:contain}
.card.sheet > *{flex-shrink:0}
.gradelist{display:flex; flex-direction:column; gap:8px}
.grade > summary{list-style:none; cursor:pointer; display:flex; align-items:center; gap:10px; min-height:44px; padding:6px 12px; border-radius:14px; background:var(--given); font:600 17px/1.2 var(--font-display)}
.grade > summary::-webkit-details-marker{display:none}
.grade > summary .gl{flex:none; min-width:44px; text-align:center; padding:4px 8px; border-radius:999px; background:var(--ink); color:var(--paper); font-size:13px}
.grade > summary::after{content:'›'; margin-left:auto; color:var(--muted); transition:transform .2s}
.grade[open] > summary::after{transform:rotate(90deg)}
.grade .tl{display:grid; grid-template-columns:repeat(auto-fill, minmax(150px, 1fr)); gap:8px; padding:8px 2px 4px}
.topic{display:flex; flex-direction:column; align-items:flex-start; gap:3px; min-height:64px; padding:10px 12px; border:2px solid transparent; border-radius:14px; background:var(--tile); box-shadow:0 0 0 1px var(--panel-line); text-align:left; touch-action:manipulation}
.topic b{font:600 16px/1.15 var(--font-display)}
.topic small{color:var(--muted); font-weight:700; font-size:13px}
.topic .lv{font-size:12px; font-weight:800; color:var(--you)}
.topic[aria-current="true"]{border-color:var(--you); background:var(--you-soft)}

/* how to play */
.card.how .rules{margin:0; padding-left:22px; display:flex; flex-direction:column; gap:8px; font-size:16px; line-height:1.45}
.howdemo{margin:0; display:flex; align-items:center; justify-content:center; gap:6px; font:600 20px/1 var(--font-display); flex-wrap:wrap}
.howdemo .t{display:inline-grid; place-items:center; min-width:34px; height:34px; padding:0 3px; box-sizing:border-box; border-radius:9px; background:linear-gradient(150deg, var(--a, var(--stone)), var(--b, var(--stone))); color:var(--stone-ink); box-shadow:0 0 0 1px var(--e, var(--stone-edge))}
.howdemo .arrow{color:var(--muted)}

/* the end card */
.card.end{position:relative; text-align:center}
.endbig{margin:0; font:600 22px/1.3 var(--font-display)}
.endbig small{display:block; font:700 15px/1.3 var(--font-body); color:var(--muted); margin-top:4px}
.endlong{display:flex; flex-direction:column; gap:6px; align-items:center}
.endlong .lab{font-size:11px; font-weight:800; letter-spacing:.1em; text-transform:uppercase; color:var(--muted)}
.fline{display:flex; align-items:center; justify-content:center; gap:6px; flex-wrap:wrap; font:600 22px/1.1 var(--font-display); padding:8px 12px; border-radius:14px; background:var(--you-soft)}
.fline .s{color:var(--you)}
.praise{margin:0; font:600 18px/1.2 var(--font-display); color:var(--you)}
.ranks{margin:0; padding:0; list-style:none; display:flex; flex-direction:column; gap:6px; text-align:left}
.ranks li{display:flex; align-items:center; gap:8px; padding:6px 10px; border-radius:12px; background:var(--given); font-weight:800}
.ranks li.me{box-shadow:0 0 0 2px var(--you)}
.ranks li .pl{width:22px; text-align:center; font:600 16px/1 var(--font-display); color:var(--muted)}
.ranks li .nm{flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap}
.ranks li .ct{font:600 16px/1 var(--font-display)}
.ranks li canvas{width:24px!important; height:24px!important; border-radius:50%}

/* the room sheet */
.card.room .code{margin:0; text-align:center; font-weight:800; color:var(--muted)}
.card.room .code b{display:block; font:600 44px/1.1 var(--font-display); letter-spacing:.12em; color:var(--ink)}
.faces{display:flex; flex-wrap:wrap; justify-content:center; gap:8px}
.faces .fc{display:flex; flex-direction:column; align-items:center; gap:3px; width:64px; font-size:12px; font-weight:800}
.faces .fc canvas{width:44px!important; height:44px!important; border-radius:50%; background:var(--given)}
.faces .fc span{max-width:64px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap}
.ways{display:grid; grid-template-columns:1fr 1fr; gap:8px}
.ways .way[data-way="duel"]{grid-column:1 / -1}
.way{display:flex; flex-direction:column; gap:4px; align-items:flex-start; text-align:left; padding:10px 12px; border:2px solid transparent; border-radius:14px; background:var(--given); min-height:44px}
.way b{font:600 17px/1.1 var(--font-display)} .way span{font-size:13px; font-weight:700; color:var(--muted)}
.way[aria-checked="true"]{border-color:var(--you); background:var(--you-soft)}
.joinrow{display:flex; align-items:center; gap:8px; margin-top:10px}
.joinrow label{font-weight:800; font-size:14px; color:var(--muted); white-space:nowrap}
.joinrow input{flex:1; min-width:0; width:0; font:600 22px/1 var(--font-display); letter-spacing:.14em; text-transform:uppercase; text-align:center; padding:9px 6px; border-radius:12px; border:2px solid var(--panel-line); background:var(--tile); color:var(--ink)}
.joinrow .btn{min-height:46px; padding:8px 16px}

/* countdown and toast */
.count{position:fixed; inset:0; z-index:60; display:grid; place-items:center; pointer-events:none}
.cnum{font:600 120px/1 var(--font-display); color:var(--you); text-shadow:0 4px 24px rgba(91,63,214,.35)}
.toast{position:fixed; left:50%; top:72px; transform:translateX(-50%); z-index:70; padding:8px 14px; border-radius:999px; background:var(--tile); color:var(--ink); font-weight:800; font-size:15px; box-shadow:0 4px 14px rgba(0,0,0,.14); white-space:nowrap; max-width:calc(100vw - 32px); box-sizing:border-box; overflow:hidden; text-overflow:ellipsis; pointer-events:none}

/* landscape phones: the top bar becomes a column beside the board */
@media (max-height: 520px) and (min-aspect-ratio: 5/4){
  #app{max-width:none; flex-direction:row; gap:12px}
  .topbar{width:min(260px, 34vw); flex:none; justify-content:center}
  .hud{flex-wrap:wrap}
  .prog{flex-basis:100%; order:3}
  .line{font-size:22px; min-height:44px; white-space:normal; flex-wrap:wrap}
  .stage{min-height:0}
  .card.start{max-width:min(760px, 100%); display:grid; grid-template-columns:1fr 1fr; column-gap:18px; align-items:center}
  .card.start .mebtn{grid-column:1 / -1}
  .card.start h1{font-size:32px}
}

/* Calm motion and reduced motion: nothing moves */
html.calm *, html.calm *::before, html.calm *::after{animation:none!important; transition:none!important}
@media (prefers-reduced-motion: reduce){ *, *::before, *::after{animation:none!important; transition:none!important} }

/* print: no colour fills, a clean outline per tile */
@media print{
  .stage{background:#fff!important; box-shadow:none} .sky,.fx{display:none}
  .tile .st,.logo-tiles span,.howdemo .t{background:#fff!important; box-shadow:none!important; border:2px solid #1d1a33; outline:none!important}
  .tile .st::before,.tile .st::after{display:none}
}
