/* Layout: one centered column (max 680px) of scrolling screens above a bottom tab bar;
   an exercise is a "workbook card" – big sentence with a highlighter gap, rule folded above it. */
:root{
  --bg:#f6f7f9; --surface:#ffffff; --ink:#18202e; --muted:#5d6676; --line:#dde1e8; --line-soft:#eceff3;
  --accent:#2747c9; --accent-ink:#ffffff; --accent-soft:#eaeefc; --hl:#ffe76a; --hl-ink:#18202e;
  --ok:#1d7a46; --ok-bg:#e3f4ea; --bad:#b4282e; --bad-bg:#fbe6e6;
  --display:"Bricolage Grotesque",ui-sans-serif,system-ui,sans-serif;
  --body:"Atkinson Hyperlegible",ui-sans-serif,system-ui,sans-serif;
  color-scheme:light;
}
@media (prefers-color-scheme:dark){:root:not([data-theme="light"]){
  --bg:#10141c; --surface:#181e29; --ink:#e8ecf3; --muted:#9aa3b3; --line:#2a3240; --line-soft:#222937;
  --accent:#7d97ff; --accent-ink:#0d1220; --accent-soft:#1d2540; --hl:#e3c936; --hl-ink:#14181f;
  --ok:#6fd49a; --ok-bg:#16301f; --bad:#ff8a8f; --bad-bg:#3a1a1c; color-scheme:dark}}
:root[data-theme="dark"]{
  --bg:#10141c; --surface:#181e29; --ink:#e8ecf3; --muted:#9aa3b3; --line:#2a3240; --line-soft:#222937;
  --accent:#7d97ff; --accent-ink:#0d1220; --accent-soft:#1d2540; --hl:#e3c936; --hl-ink:#14181f;
  --ok:#6fd49a; --ok-bg:#16301f; --bad:#ff8a8f; --bad-bg:#3a1a1c; color-scheme:dark}

*{box-sizing:border-box}
html,body{height:100%;margin:0}
body{background:var(--bg);color:var(--ink);font-family:var(--body);font-size:16px;line-height:1.5;-webkit-tap-highlight-color:transparent}
button,input,select{font:inherit;color:inherit}
button{cursor:pointer}
button:focus-visible,input:focus-visible,select:focus-visible,summary:focus-visible{outline:3px solid var(--accent);outline-offset:2px}
[hidden]{display:none!important}
svg{flex-shrink:0}
h1,h2,p{margin:0}
h1,h2{font-family:var(--display);text-wrap:balance}
h1{font-weight:800;font-size:clamp(1.7rem,6vw,2.2rem);line-height:1.1}
h2{font-weight:800;font-size:1.15rem}
a{color:var(--accent)}
.muted{color:var(--muted)}
.small{font-family:var(--body);font-weight:400;font-size:.85rem}
.center{text-align:center;align-self:center}
.label{font-size:.75rem;text-transform:uppercase;letter-spacing:.08em;color:var(--muted);font-weight:700}

.app{height:100dvh;display:flex;flex-direction:column;overflow:hidden}
.screen{flex:1;overflow-y:auto;min-height:0}
.wrap{max-width:680px;margin:0 auto;padding:calc(env(safe-area-inset-top,0px) + 22px) max(16px,env(safe-area-inset-right,0px)) 32px max(16px,env(safe-area-inset-left,0px));display:flex;flex-direction:column;gap:20px}
.phead{display:flex;flex-direction:column;gap:4px}
.section{display:flex;flex-direction:column;gap:10px}
.sechead{display:flex;justify-content:space-between;align-items:baseline;gap:12px}
.stack{display:flex;flex-direction:column;gap:10px}

/* tab bar */
nav.tabs{display:grid;grid-template-columns:repeat(4,minmax(0,120px));justify-content:center;background:var(--surface);border-top:1px solid var(--line);padding-bottom:env(safe-area-inset-bottom,0px)}
nav.tabs button{border:0;background:none;height:60px;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;font-size:.75rem;font-weight:700;color:var(--muted)}
nav.tabs svg{width:22px;height:22px}
nav.tabs button[aria-current="page"]{color:var(--accent)}

/* buttons */
.btn{border:0;border-radius:10px;padding:12px 20px;font:700 1rem var(--body);background:var(--accent);color:var(--accent-ink);display:inline-flex;align-items:center;justify-content:center;gap:6px;min-height:48px}
.btn:disabled{opacity:.45;cursor:default}
.btn.ghost{background:var(--surface);color:var(--ink);border:1px solid var(--line)}
.btn.light{background:#fff;color:#1d3299}
.btn.small{min-height:38px;padding:6px 14px;font-size:.9rem}
.btn svg{width:18px;height:18px}
.linkbtn{background:none;border:0;padding:4px 0;color:var(--accent);font-weight:700;text-decoration:underline;text-underline-offset:3px}
.linkbtn.danger{color:var(--bad);align-self:flex-start;margin-top:4px}
.iconbtn{flex:none;width:44px;height:44px;border:0;background:none;border-radius:10px;display:grid;place-items:center;color:var(--muted)}
.iconbtn svg{width:22px;height:22px}
.iconbtn.inline{display:inline-grid;width:36px;height:36px;vertical-align:middle;color:var(--accent);margin-left:2px}

/* home */
.banner{display:flex;align-items:center;gap:10px;background:var(--accent-soft);border-radius:12px;padding:10px 6px 10px 14px;font-size:.9rem}
.banner b{display:block}
.grow{flex:1;min-width:0;display:flex;flex-direction:column;gap:2px}
.goal{display:flex;align-items:center;gap:16px;background:var(--surface);border:1px solid var(--line);border-radius:14px;padding:14px 16px}
.goal .grow b{font-size:1.05rem}
.goal .grow span{color:var(--muted);font-size:.9rem}
.ring{flex:none;position:relative;width:60px;height:60px}
.ring svg{width:60px;height:60px}
.ring b{position:absolute;inset:0;display:grid;place-items:center;font-family:var(--display);font-weight:800;font-variant-numeric:tabular-nums}
.rec{background:var(--accent);color:var(--accent-ink);border-radius:16px;padding:20px;display:flex;flex-direction:column;gap:8px}
.rec .label{color:inherit;opacity:.8}
.rec h2{font-size:1.5rem;line-height:1.2}
.rec p{opacity:.9}
.rec .btn{margin-top:8px;align-self:stretch}
.quick{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
.qbtn{border:1px solid var(--line);background:var(--surface);border-radius:14px;padding:12px 14px;text-align:left;display:flex;flex-direction:column;gap:2px;min-height:72px;justify-content:center}
.qbtn b{font-size:1rem}
.qbtn span{font-size:.85rem;color:var(--muted);overflow:hidden;text-overflow:ellipsis;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}
.qbtn:disabled{opacity:.55;cursor:default}
.panel{background:var(--surface);border:1px solid var(--line);border-radius:14px;overflow:hidden}
.row{display:flex;align-items:center;gap:10px;padding:12px 14px;border-bottom:1px solid var(--line-soft)}
.row:last-child{border-bottom:0}
.row .grow b{font-size:1rem}
.row .grow span{font-size:.85rem;color:var(--muted)}
.rowbtn{width:100%;border:0;border-bottom:1px solid var(--line-soft);background:none;text-align:left}
.rowmain{flex:1;min-width:0;display:flex;align-items:center;gap:10px;border:0;background:none;padding:0;text-align:left}
.row:has(.rowmain){padding-right:4px}
.playic{color:var(--accent);display:grid;place-items:center}
.playic svg{width:20px;height:20px;fill:currentColor}
.count{font-variant-numeric:tabular-nums;font-weight:700;color:var(--accent)}
.count.low{color:var(--bad)}
.count.none{color:var(--muted);font-weight:400;font-size:.9rem}
.empty{color:var(--muted);background:var(--surface);border:1px dashed var(--line);border-radius:14px;padding:16px;font-size:.95rem}
.bar{display:block;height:6px;background:var(--line-soft);border-radius:3px;overflow:hidden;margin-top:6px}
.bar i{display:block;height:100%;background:var(--accent);border-radius:3px}
.bar i.low{background:var(--bad)}

/* practice setup */
.chips{display:flex;flex-wrap:wrap;gap:8px}
.chip{border:1px solid var(--line);background:var(--surface);color:var(--ink);padding:8px 14px;border-radius:999px;min-height:42px}
.chip[aria-pressed="true"]{border-color:var(--accent);color:var(--accent);font-weight:700;box-shadow:inset 0 0 0 1px var(--accent)}
.chip .pct{font-weight:400;color:var(--muted);font-size:.8rem}
.forms{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px}
.fbtn{border:1px solid var(--line);background:var(--surface);border-radius:12px;padding:10px 6px;display:flex;flex-direction:column;align-items:center;gap:0;font-weight:700}
.fbtn b{font-family:var(--display);font-size:1.5rem;line-height:1.1}
.fbtn[aria-pressed="true"]{border-color:var(--accent);color:var(--accent);box-shadow:inset 0 0 0 1px var(--accent);background:var(--accent-soft)}
.seg{display:flex;gap:4px;background:var(--surface);border:1px solid var(--line);border-radius:10px;padding:4px;width:fit-content;max-width:100%;flex-wrap:wrap}
.seg button{border:0;background:none;color:var(--muted);font-weight:700;padding:8px 14px;border-radius:7px}
.seg button[aria-pressed="true"]{background:var(--accent);color:var(--accent-ink)}
.seg.full{display:grid;grid-auto-flow:column;grid-auto-columns:1fr;width:100%}
.seg.full button{padding:8px 2px;white-space:nowrap;font-size:.92rem}
.check{display:flex;align-items:center;gap:12px;padding:12px 14px;border-bottom:1px solid var(--line-soft);cursor:pointer}
.check:last-child{border-bottom:0}
.check span span{font-size:.85rem;color:var(--muted)}
.check.off{opacity:.5;cursor:default}
.check input{width:22px;height:22px;accent-color:var(--accent);flex:none;margin:0}
.switchrow,.setrow{display:flex;align-items:center;justify-content:space-between;gap:12px}
.switchrow{background:var(--surface);border:1px solid var(--line);border-radius:14px;padding:12px 14px}
.switchrow span{display:flex;flex-direction:column}
.switchrow .muted{font-size:.85rem}
.setrow{padding:12px 14px;border-bottom:1px solid var(--line-soft);min-height:60px}
.setrow:last-child{border-bottom:0}
.setrow > span{display:flex;flex-direction:column;font-weight:700}
.setrow small{font-weight:400;color:var(--muted);font-size:.85rem}
.switch{appearance:none;-webkit-appearance:none;flex:none;width:48px;height:28px;border-radius:14px;background:var(--line);position:relative;cursor:pointer;margin:0;transition:background .2s}
.switch::after{content:"";position:absolute;top:3px;left:3px;width:22px;height:22px;border-radius:50%;background:#fff;box-shadow:0 1px 2px rgba(0,0,0,.3);transition:transform .2s}
.switch:checked{background:var(--accent)}
.switch:checked::after{transform:translateX(20px)}
.switch:disabled{opacity:.4}
select{height:40px;max-width:55%;border:1px solid var(--line);border-radius:10px;background:var(--surface);padding:0 8px;font-size:.9rem}
.saverow{display:flex;gap:8px}
.saverow input{flex:1;min-width:0;border:1px solid var(--line);border-radius:10px;padding:0 12px;min-height:48px;background:var(--surface)}

/* stats */
.statgrid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
.stat{background:var(--surface);border:1px solid var(--line);border-radius:14px;padding:12px 14px;display:flex;flex-direction:column}
.stat b{font-family:var(--display);font-weight:800;font-size:1.6rem;font-variant-numeric:tabular-nums;line-height:1.2}
.stat span{color:var(--muted);font-size:.85rem}
.week{background:var(--surface);border:1px solid var(--line);border-radius:14px;padding:14px;display:grid;grid-template-columns:repeat(7,1fr);gap:6px;height:150px}
.week .d{display:flex;flex-direction:column;align-items:center;justify-content:flex-end;gap:5px;font-size:.75rem;color:var(--muted)}
.week .col{width:100%;max-width:24px;border-radius:5px;background:var(--accent)}
.week .col.full{background:var(--ok)}
.week .col.zero{background:var(--line-soft)}
.week .d.today{color:var(--ink);font-weight:700}
.week .n{font-variant-numeric:tabular-nums}
.tablewrap{overflow-x:auto}
.ftable{width:100%;border-collapse:collapse;font-variant-numeric:tabular-nums}
.ftable th,.ftable td{padding:10px 12px;text-align:left;border-bottom:1px solid var(--line-soft)}
.ftable tr:last-child th,.ftable tr:last-child td{border-bottom:0}
.ftable thead th{font-size:.8rem;color:var(--muted)}
.ftable td{font-weight:700;color:var(--accent)}
.ftable td.low{color:var(--bad)}
.ftable td.none{color:var(--muted);font-weight:400}
.foot{color:var(--muted);font-size:.85rem;margin-top:8px}

/* rules */
.rulecard{gap:12px;padding:16px 18px}
.rulecard:not([open]){display:block}
.rulecard summary{list-style:none;display:flex;justify-content:space-between;align-items:center;font-family:var(--display);font-weight:800;font-size:1.2rem;cursor:pointer}
.rulecard summary::-webkit-details-marker{display:none}
.rulecard summary svg{width:20px;height:20px;color:var(--muted);transition:transform .2s}
.rulecard[open] summary svg{transform:rotate(90deg)}
.rulecard .btn{align-self:flex-start}

/* session */
.shead{display:flex;align-items:center;gap:6px;max-width:680px;width:100%;margin:0 auto;padding:calc(env(safe-area-inset-top,0px) + 8px) 12px 8px 4px}
.stitle{flex:1;min-width:0;display:flex;flex-direction:column}
.stitle b{font-family:var(--display);font-size:1.05rem;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.stitle span{font-size:.85rem;color:var(--muted);font-variant-numeric:tabular-nums}
.progress{height:6px;background:var(--line);overflow:hidden;max-width:680px;width:calc(100% - 32px);margin:0 auto;border-radius:3px}
.progress span{display:block;height:100%;background:var(--accent);transition:width .3s}
.sbody{flex:1;overflow-y:auto;padding:16px max(16px,env(safe-area-inset-right,0px)) 32px max(16px,env(safe-area-inset-left,0px))}
#scr-session{display:flex;flex-direction:column}
#scr-session .card{max-width:680px;margin:0 auto}

.card{background:var(--surface);border:1px solid var(--line);border-radius:14px;padding:22px 20px;display:flex;flex-direction:column;gap:18px}
.cardhead{display:flex;flex-wrap:wrap;justify-content:space-between;align-items:center;gap:8px}
.rule summary{cursor:pointer;color:var(--accent);font-weight:700;font-size:.85rem}
.rule[open]{flex-basis:100%}
.rule > div{overflow-x:auto;font-size:.92rem;padding-top:8px}
.rule p,.rulecard .rule p{margin:6px 0}
.rule table{border-collapse:collapse;margin:6px 0}
.rule th,.rule td{border:1px solid var(--line);padding:4px 10px;text-align:left}
.rule th{color:var(--muted);font-weight:700}
.rulecard .rule{overflow-x:auto;font-size:.95rem}
.tip{background:var(--hl);color:var(--hl-ink);border-radius:6px;padding:6px 10px;font-weight:700}
.cz{color:var(--muted);font-size:.95rem}
.cz + .sentence{margin-top:-10px}
.tr{color:var(--muted);font-size:.9rem;font-style:italic;margin-top:-10px}
.sentence{font-family:var(--display);font-weight:600;font-size:clamp(1.35rem,5.2vw,1.9rem);line-height:1.4;text-wrap:balance;overflow-wrap:anywhere}
.sentence.plain{font-size:clamp(1.25rem,4.8vw,1.7rem)}
.gap{display:inline-block;min-width:4.5ch;padding:0 .3em;border-radius:4px;background:var(--hl);color:var(--hl-ink);text-align:center}
.gap.empty{color:transparent}
.gap.bad{background:var(--bad-bg);color:var(--bad);text-decoration:line-through}
.typein{font:inherit;color:var(--hl-ink);background:var(--hl);border:0;border-bottom:2px solid var(--hl-ink);border-radius:4px;padding:0 .3em;width:8ch;max-width:100%;text-align:center}
.typein:focus{outline:3px solid var(--accent);outline-offset:2px}
.options{display:grid;grid-template-columns:repeat(auto-fit,minmax(96px,1fr));gap:10px}
.options.wide{grid-template-columns:1fr}
.opt{position:relative;border:2px solid var(--line);background:var(--bg);color:var(--ink);font:700 1.1rem var(--body);padding:14px 10px;border-radius:10px;min-height:56px}
.options.wide .opt{text-align:left;padding-left:44px;font-size:1.02rem}
.opt kbd{position:absolute;left:8px;top:8px;font:700 .7rem var(--body);color:var(--muted);border:1px solid var(--line);border-radius:4px;padding:0 4px}
.options.wide .opt kbd{top:50%;transform:translateY(-50%);left:12px}
@media (pointer:coarse){.opt kbd{display:none}.options.wide .opt{padding-left:14px}}
@media (hover:hover){.opt:hover:not(:disabled){border-color:var(--accent)}}
.opt.ok{border-color:var(--ok);background:var(--ok-bg);color:var(--ok)}
.opt.bad{border-color:var(--bad);background:var(--bad-bg);color:var(--bad)}
.opt:disabled{cursor:default}
.built{min-height:60px;border:2px dashed var(--line);border-radius:10px;padding:10px;display:flex;flex-wrap:wrap;gap:8px;align-items:center}
.built.ok{border-style:solid;border-color:var(--ok);background:var(--ok-bg)}
.built.bad{border-style:solid;border-color:var(--bad);background:var(--bad-bg)}
.pool{display:flex;flex-wrap:wrap;gap:8px}
.word{border:1px solid var(--line);background:var(--bg);color:var(--ink);font:700 1.05rem var(--body);padding:9px 13px;border-radius:8px;min-height:44px}
.built .word{background:var(--surface)}
.pool .word:disabled{opacity:.25;cursor:default}
.built .word:disabled{opacity:1;cursor:default}
.hint{color:var(--muted);font-size:.9rem}
.mic{align-self:center;width:96px;height:96px;border-radius:50%;border:0;background:var(--accent);color:var(--accent-ink);display:grid;place-items:center}
.mic svg{width:40px;height:40px}
.mic.on{animation:pulse 1.2s infinite}
@keyframes pulse{0%{box-shadow:0 0 0 0 color-mix(in srgb,var(--accent) 50%,transparent)}100%{box-shadow:0 0 0 22px transparent}}
.actions.center{justify-content:center}
.heard{text-align:center;color:var(--muted);min-height:24px}
.feedback{border-radius:10px;padding:14px 16px;display:flex;flex-direction:column;gap:6px;align-items:flex-start}
.feedback.ok{background:var(--ok-bg);color:var(--ok)}
.feedback.bad{background:var(--bad-bg);color:var(--bad)}
.feedback p{color:var(--ink)}
.feedback p.muted{color:var(--muted);font-size:.9rem}
.feedback strong{font-size:1.05rem}
.actions{display:flex;flex-wrap:wrap;gap:10px;justify-content:flex-end}
.actions .say{margin-right:auto}
.actions #nextBtn{flex:1 1 160px;max-width:260px}
@media (max-width:420px){.actions #nextBtn{max-width:none;flex-basis:100%}}

/* summary */
#scr-summary{overflow-y:auto}
.sumhead{display:flex;align-items:center;gap:18px}
.ringbig{flex:none;position:relative;width:120px;height:120px}
.ringbig svg{width:120px;height:120px}
.ringbig b{position:absolute;inset:0;display:grid;place-items:center;font-family:var(--display);font-weight:800;font-size:1.6rem}
@media (prefers-reduced-motion:reduce){*{animation:none!important;transition:none!important}}
