/* =====================================================================
   English tutor v4 — «calm editorial» (direction A).
   base.css   tokens · reset · shell/nav · primitives · player frame · feedback · home · auth · settings
   cards.css  lesson card contents          screens.css  practice · progress · admin
   Re-theme by editing the token block only. Phone-first (360px); desktop layout from 1024px.
   Dark theme: html[data-theme="dark"] (set by js/theme.js + the inline script in index.html).
   ===================================================================== */
:root, html[data-theme="light"] {
  color-scheme: light;
  --bg: #f3eee2; --surface: #fbf8ef; --surface2: #ebe4d2; --line: #d9d0bb; --line2: #b4a98f;
  --text: #2a2620; --muted: #6a6252;
  --accent: #2f5d4a; --accent-ink: #f8f4e8; --accent-soft: #dde6d5;
  --ok: #2e6a45; --ok-soft: #dfe9d6; --bad: #9b4326; --bad-soft: #f1dccd; --warn: #7d5a10; --warn-soft: #f1e5bf;
  --slip: #fffdf5; --slip-edge: #cdc2a8; --emboss: rgba(255,255,255,.95); --emboss-y: 1px;
  --rule: rgba(120,100,60,.2); --tick-off: #d2c8b1; --shadow: rgba(70,50,20,.16); --scrim: rgba(42,38,32,.28);
  --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .42  0 0 0 0 .32  0 0 0 0 .18  0 0 0 .16 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1c1915; --surface: #26221d; --surface2: #2f2a24; --line: #3c362e; --line2: #5c5346;
  --text: #ece4d2; --muted: #a89f8d;
  --accent: #93c7a4; --accent-ink: #13251a; --accent-soft: #28382e;
  --ok: #9ccfa8; --ok-soft: #26372b; --bad: #e5a183; --bad-soft: #3d2b22; --warn: #dcb862; --warn-soft: #3b3220;
  --slip: #3a352d; --slip-edge: #16130f; --emboss: rgba(0,0,0,.65); --emboss-y: -1px;
  --rule: rgba(255,240,210,.08); --tick-off: #433c32; --shadow: rgba(0,0,0,.45); --scrim: rgba(0,0,0,.5);
  --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .9  0 0 0 0 .8  0 0 0 0 .6  0 0 0 .06 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}
:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --font-head: "Source Serif 4", "Noto Serif", "PT Serif", Cambria, Georgia, "Liberation Serif", "Times New Roman", serif;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, "DejaVu Sans Mono", monospace;
  /* phone type scale (body 16px, modest headings); desktop values are restored in the ≥1024 block */
  --t-xs: .75rem; --t-sm: .875rem; --t-md: 1rem; --t-lg: 1.125rem;
  --t-xl: clamp(1.25rem, 5.4vw, 1.5rem); --t-2xl: clamp(1.5rem, 6.4vw, 2rem); --t-3xl: clamp(1.875rem, 8vw, 2.75rem);
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 24px; --s-6: 32px; --s-7: 48px; --s-8: 72px;
  --r: 3px; --r2: 8px; --tap: 52px; --toc-w: 248px;
  --c0: #2f5d4a; --c1: #9b4326; --c2: #7d5a10; --c3: #4a5f8a; --c4: #6d4a7a; --c5: #5a7a7a; /* chart series */
}
html[data-theme="dark"] { --c0: #93c7a4; --c1: #e5a183; --c2: #dcb862; --c3: #9db4e0; --c4: #c9a6d6; --c5: #9cc7c7; }

/* ---------- reset / base ---------- */
* { box-sizing: border-box; margin: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; overflow: hidden; }
body { background: var(--bg) var(--grain); color: var(--text); font: 400 var(--t-md)/1.5 var(--font);
  -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
button, input, textarea, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; text-align: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }
.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ic.sm { width: 18px; height: 18px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
h1, h2, h3 { font-family: var(--font-head); font-weight: 500; letter-spacing: -.005em; }
h1 { font-size: var(--t-3xl); line-height: 1.05; }
h2 { font-size: var(--t-xl); line-height: 1.2; }
em { font-family: var(--font-head); }
small, .small { font-size: var(--t-sm); }
s { opacity: .8; }
.muted { color: var(--muted); }
.center { text-align: center; }
.pre { white-space: pre-line; }
.num { font-family: var(--font-head); font-variant-numeric: tabular-nums lining-nums; }
.eyebrow { font-size: var(--t-xs); letter-spacing: .14em; text-transform: uppercase; color: var(--accent); font-weight: 600; }
.label { font-size: var(--t-xs); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.lede { font-family: var(--font-head); font-style: italic; color: var(--muted); font-size: var(--t-lg); line-height: 1.45; margin-top: var(--s-3); }
.err { color: var(--bad); min-height: 1.5em; font-weight: 600; font-size: var(--t-sm); }
.md { white-space: pre-line; overflow-wrap: anywhere; }
.md strong { font-weight: 700; }

/* ---------- shell ---------- */
#app { position: fixed; left: 0; right: 0; top: var(--vvt, 0px); height: var(--vvh, 100dvh); max-width: 760px; margin: 0 auto;
  display: grid; grid-template-rows: minmax(0, 1fr) auto; overflow: hidden; background: var(--bg) var(--grain); }
@media (min-width: 761px) { #app { border-inline: 1px solid var(--line2); } }
#toc { display: none; }
#view { min-height: 0; min-width: 0; display: flex; flex-direction: column; }
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; outline: none; }
.screen.scroll { overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--line2) transparent; }

#tabbar { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border-top: 1px solid var(--line2); background: var(--bg) var(--grain);
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); position: relative; z-index: 5; }
.kb #tabbar { display: none; }
.tab { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 60px; min-width: 0;
  font-size: .72rem; letter-spacing: .01em; color: var(--muted); text-align: center; }
.tab[aria-current="page"] { color: var(--accent); font-weight: 600; }
.tab[aria-current="page"]::before { content: ""; position: absolute; top: -1px; left: 26%; right: 26%; height: 3px; background: var(--accent); border-radius: 0 0 3px 3px; }

.page { flex: 1 0 auto; display: flex; flex-direction: column; gap: var(--s-6); width: 100%;
  padding: calc(var(--s-5) + env(safe-area-inset-top)) max(var(--s-5), env(safe-area-inset-right)) var(--s-6) max(var(--s-5), env(safe-area-inset-left)); }
.col-main, .col-aside { display: contents; }
.pagehead h1 { margin-top: var(--s-2); }
.pagehead-row { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-3); }
.pagehead-acts { display: flex; align-items: center; gap: var(--s-2); flex: none; }
.streak-pill { display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-head); padding: 6px 12px 6px 10px; border: 1px solid var(--line2); border-radius: 999px; white-space: nowrap; }
.streak-pill .ic { width: 16px; height: 16px; color: var(--accent); fill: var(--accent); stroke: none; }
.streak-pill span { font-family: var(--font); font-size: var(--t-xs); color: var(--muted); }

/* brand */
.brand { display: inline-flex; align-items: center; gap: 10px; font-family: var(--font-head); font-size: 1.375rem; line-height: 1; letter-spacing: -.01em; }
.brand svg { width: 20px; height: 28px; color: var(--accent); fill: currentColor; stroke: none; }
.brand i { color: var(--accent); font-style: italic; }

/* ---------- primitives ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2); min-height: var(--tap); padding: 0 var(--s-5);
  border: 1px solid var(--text); border-radius: var(--r); font-family: var(--font); font-size: var(--t-md); font-weight: 600; letter-spacing: .01em;
  background: transparent; color: var(--text); text-align: center; position: relative; transition: background .15s, transform .1s, opacity .15s; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled, .btn[disabled] { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); box-shadow: 0 1px 0 var(--shadow), inset 0 1px 0 rgba(255,255,255,.14); --spin: var(--accent-ink); }
.btn.ghost { border-color: var(--line2); }
.btn.ghost:hover:not(:disabled) { border-color: var(--text); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.wide { flex: 1; }
.btn.sm { min-height: 44px; padding: 0 var(--s-4); font-size: var(--t-sm); }
.btn.done { background: var(--ok-soft); color: var(--ok); border-color: transparent; opacity: 1; }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn.loading { color: transparent !important; pointer-events: none; }
.btn.loading::after { content: ""; position: absolute; inset: 0; margin: auto; width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--spin, var(--text)); border-top-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.link { color: var(--accent); font-weight: 600; min-height: 44px; text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 1px; text-align: center; }
kbd { font-family: var(--mono); font-size: .6875rem; line-height: 1; padding: 4px 6px 3px; border: 1px solid currentColor; border-bottom-width: 2px; border-radius: 3px; opacity: .8; font-weight: 500; white-space: nowrap; display: none; }
.iconbtn { display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px; border-radius: 50%; color: var(--muted); flex: none; }
.iconbtn:hover { color: var(--text); background: var(--surface2); }
.sound { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; flex: none; border: 1px solid var(--line2); border-radius: 50%; color: var(--accent); }
.sound:hover { background: var(--accent-soft); }
.sound.listening, .btn.listening, .iconbtn.listening { background: var(--bad-soft); color: var(--bad); border-color: var(--bad); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .6; } }

.row-flex { display: flex; gap: var(--s-2); align-items: center; }
.row-flex.acts { flex-wrap: wrap; }
.empty .btn { font-style: normal; }
#login .welcome { font-family: var(--font-head); font-style: italic; color: var(--accent); font-size: var(--t-lg); }
.inp { width: 100%; min-height: var(--tap); padding: 12px var(--s-4); border-radius: var(--r); border: 1px solid var(--line2); background: var(--surface); color: var(--text);
  font-size: 1rem; line-height: 1.4; resize: none; outline: none; box-shadow: inset 0 1px 3px -1px var(--shadow); }
.inp::placeholder { color: var(--muted); opacity: .85; }
.inp:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.inp.sm { min-height: 44px; padding: 8px var(--s-3); }
select.inp { appearance: auto; }
.chip { display: inline-flex; align-items: center; min-height: 28px; padding: 0 var(--s-3); border-radius: 999px; border: 1px solid var(--line2); background: transparent;
  color: var(--text); font-size: var(--t-xs); font-weight: 600; letter-spacing: .02em; white-space: nowrap; gap: 6px; }
.chip.rule, .chip.lvl { border-color: var(--accent); color: var(--accent); }
.chip.lvl { background: var(--accent); color: var(--accent-ink); }
.chip.ok { border-color: var(--ok); color: var(--ok); background: var(--ok-soft); }
.chip.warn { border-color: var(--warn); color: var(--warn); background: var(--warn-soft); }
.chip b { font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: var(--s-4); display: flex; flex-direction: column; gap: var(--s-3); box-shadow: 0 6px 14px -10px var(--shadow); }
.empty { margin: auto; padding: var(--s-5); text-align: center; color: var(--muted); font-family: var(--font-head); font-style: italic; font-size: var(--t-lg); display: flex; flex-direction: column; gap: var(--s-4); align-items: center; }
.bar { height: 3px; border-radius: 2px; background: var(--tick-off); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 2px; transition: width .3s; }
.bar.ok i { background: var(--ok); }
.seg { display: flex; border: 1px solid var(--line2); border-radius: var(--r); overflow: hidden; }
.seg button { flex: 1; min-width: 0; min-height: 44px; padding: 0 var(--s-2); text-align: center; font-size: var(--t-sm); font-weight: 600; color: var(--muted); border-right: 1px solid var(--line); white-space: nowrap; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--text); color: var(--bg); }
.tag { display: inline-flex; align-items: center; gap: 8px; font-size: var(--t-xs); letter-spacing: .14em; text-transform: uppercase; font-weight: 600; color: var(--accent); }
.tag::before { content: ""; width: 18px; height: 1px; background: currentColor; }
.tag.center { justify-content: center; }
mark.ans { background: none; color: var(--accent); font-weight: 700; border-bottom: 2px solid var(--accent); }
del { color: var(--bad); text-decoration-thickness: 1.5px; }
ins { color: var(--ok); text-decoration: none; border-bottom: 2px solid var(--ok); font-weight: 600; }

/* switch */
.switch { position: relative; display: inline-block; width: 52px; height: 32px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; z-index: 1; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 16px; background: var(--surface2); border: 1px solid var(--line2); transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--muted); transition: transform .15s, background .15s; }
.switch input:checked + span { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); background: var(--accent-ink); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 3px; }

/* typographic tables */
.sec-h { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-3); padding-bottom: var(--s-2); border-bottom: 1px solid var(--text); margin-bottom: var(--s-1); }
.sec-h h2 { font-style: italic; }
.sec-h .meta { font-size: var(--t-xs); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.rows { list-style: none; padding: 0; }
.row { display: flex; align-items: baseline; gap: var(--s-2); min-height: 48px; padding: var(--s-3) 0; border-bottom: 1px solid var(--line); width: 100%; text-align: left; }
.row > .ld { flex: 1; border-bottom: 1px dotted var(--line2); transform: translateY(-4px); min-width: 12px; }
.row .nm { font-family: var(--font-head); font-size: var(--t-lg); line-height: 1.3; }
.row .nm small { display: block; font-family: var(--font); font-size: var(--t-sm); color: var(--muted); margin-top: 2px; }
.row .vl { font-family: var(--font-head); font-size: var(--t-lg); font-variant-numeric: tabular-nums lining-nums; white-space: nowrap; }
.row .vl small { font-family: var(--font); font-size: var(--t-xs); color: var(--muted); letter-spacing: .06em; text-transform: uppercase; margin-right: 6px; }
button.row:hover .nm { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 4px; }
.row > .ic { color: var(--muted); align-self: center; }
.row .rk { font-size: var(--t-xs); font-weight: 700; letter-spacing: .06em; color: var(--accent); border: 1px solid currentColor; border-radius: 2px; padding: 0 5px; margin-right: 8px; vertical-align: 2px; font-family: var(--font); }

/* notes (marginalia) */
.note .fn { font-family: var(--font-head); font-size: var(--t-sm); color: var(--accent); margin-right: 6px; }
.note .label { display: flex; align-items: baseline; }
.note-big { font-family: var(--font-head); font-size: var(--t-3xl); line-height: 1; margin: var(--s-2) 0 4px; font-variant-numeric: lining-nums; }
.note-big small { font-size: var(--t-lg); font-style: italic; color: var(--muted); margin-left: 6px; }
.note-text { font-family: var(--font-head); font-style: italic; color: var(--muted); font-size: var(--t-sm); line-height: 1.5; }
.note + .note { padding-top: var(--s-5); border-top: 1px solid var(--line); }

/* dial · week · forecast */
.dial { position: relative; width: 132px; height: 132px; flex: none; }
.dial svg { width: 100%; height: 100%; overflow: visible; }
.dial .tk { stroke: var(--tick-off); stroke-width: 3.4; stroke-linecap: round; transition: stroke .35s ease var(--d, 0ms); }
.dial .tk.on { stroke: var(--accent); }
.dial .hair { fill: none; stroke: var(--line2); stroke-width: .6; }
.dial .mid { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.dial .mid b { font-family: var(--font-head); font-weight: 500; font-size: var(--t-3xl); line-height: 1; font-variant-numeric: lining-nums tabular-nums; }
.dial .mid span { font-size: .6875rem; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-top: 4px; }
@keyframes tk-in { from { opacity: 0; transform: scale(.6); } to { opacity: 1; transform: none; } }
.dial.anim .tk { transform-origin: 60px 60px; animation: tk-in .4s cubic-bezier(.2,.8,.3,1) both; animation-delay: var(--d, 0ms); }
.week { display: grid; grid-template-columns: repeat(7, 1fr); margin-top: var(--s-3); }
.week div { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.week span { font-size: var(--t-xs); color: var(--muted); letter-spacing: .06em; }
.week .today span { color: var(--text); font-weight: 700; }
.week svg { width: 26px; height: 26px; overflow: visible; }
.wk-done { fill: var(--accent); } .wk-check { fill: none; stroke: var(--accent-ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.wk-rest { fill: var(--warn-soft); stroke: var(--warn); stroke-width: 1.2; stroke-dasharray: 2.5 2.5; } .wk-rest-l { stroke: var(--warn); stroke-width: 1.6; stroke-linecap: round; }
.wk-today-t { fill: none; stroke: var(--text); stroke-width: 2; }
.wk-miss { fill: none; stroke: var(--line2); stroke-width: 1.2; } .wk-future { fill: none; stroke: var(--line); stroke-width: 1.2; stroke-dasharray: 1 3; stroke-linecap: round; }
.fc { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; align-items: end; margin-top: var(--s-3); }
.fc div { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.fc .v { font-family: var(--font-head); font-size: var(--t-sm); font-variant-numeric: lining-nums; }
.fc .b { display: block; width: 7px; background: var(--accent); border-radius: 1px 1px 0 0; min-height: 3px; opacity: .9; }
.fc .t { font-size: .6875rem; color: var(--muted); letter-spacing: .04em; margin-top: 2px; }
.fc .first .b { background: transparent; border: 1.5px solid var(--accent); border-bottom: 0; }
.fc .first .t { color: var(--text); font-weight: 700; }
.fc .bar-h { height: 64px; display: flex; align-items: flex-end; }
.legend { font-size: var(--t-xs); color: var(--muted); margin-top: var(--s-3); line-height: 1.5; }

/* hand-drawn underline (js/icons.js pen()) — put inside a position:relative element */
.pen { position: absolute; left: -4%; width: 108%; bottom: -8px; height: 10px; overflow: visible; pointer-events: none; animation: reveal .7s cubic-bezier(.4,.1,.2,1) .1s both; }
.pen path { fill: none; stroke-width: 2.2; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.pen.bad path { stroke: var(--bad); } .pen.ok path { stroke: var(--ok); }
@keyframes reveal { from { clip-path: inset(-12px 100% -12px -4px); } to { clip-path: inset(-12px -6px -12px -6px); } }

/* toast */
#toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translate(-50%, 12px); max-width: calc(100vw - 32px);
  background: var(--text); color: var(--bg); padding: 12px var(--s-4); border-radius: var(--r); font-weight: 600; font-size: var(--t-sm); opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 100; text-align: center; box-shadow: 0 10px 30px -10px var(--shadow); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.act { pointer-events: auto; }
#toast.act .link { color: var(--bg); min-height: 0; margin-left: var(--s-2); }

/* bottom sheet (openSheet) */
.sheet-wrap { position: absolute; inset: 0; z-index: 40; display: flex; flex-direction: column; justify-content: flex-end; }
.backdrop { position: absolute; inset: 0; background: var(--scrim); animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet { position: relative; background: var(--surface); border-top: 1px solid var(--line2); border-radius: 14px 14px 0 0; max-height: 88%; overflow-y: auto; padding: var(--s-3) var(--s-5) calc(var(--s-5) + env(safe-area-inset-bottom));
  animation: sheet .3s cubic-bezier(.2,.85,.3,1); display: flex; flex-direction: column; gap: var(--s-4); box-shadow: 0 -18px 40px -10px var(--shadow); }
.sheet::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--line2); margin: 0 auto; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; font-family: var(--font-head); font-style: italic; font-size: var(--t-xl); }
@keyframes sheet { from { transform: translateY(100%); } }

/* ---------- auth · onboarding · tracks ---------- */
#login, #onboard { position: absolute; inset: 0; z-index: 60; background: var(--bg) var(--grain); display: flex; padding: var(--s-5); overflow: auto; }
#login form, .onb { margin: auto; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: var(--s-4); }
#login form { text-align: center; align-items: stretch; }
#login .brand { align-self: center; font-size: 1.75rem; }
#login .brand svg { width: 26px; height: 36px; }
#login .lede { margin-top: 0; }
.onb { max-width: 460px; }
.onb h1 { font-size: var(--t-2xl); }
.tracks { display: flex; flex-direction: column; gap: var(--s-3); }
.track { display: flex; align-items: center; gap: var(--s-4); min-height: 76px; padding: var(--s-3) var(--s-4); text-align: left; border-radius: var(--r); border: 1px solid var(--line2); background: var(--surface); }
.track > .ic { width: 28px; height: 28px; color: var(--muted); }
.track .tt { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.track .tt b { font-family: var(--font-head); font-weight: 500; font-size: var(--t-lg); }
.track small { color: var(--muted); }
.track .tick { width: 28px; height: 28px; flex: none; border-radius: 50%; border: 1px solid var(--line2); display: grid; place-items: center; color: transparent; }
.track.on { border-color: var(--accent); background: var(--accent-soft); }
.track.on > .ic { color: var(--accent); }
.track.on .tick { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ---------- settings ---------- */
.set-group { display: flex; flex-direction: column; }
.set-row { display: flex; flex-direction: column; gap: var(--s-2); padding: var(--s-4) 0; border-bottom: 1px solid var(--line); }
.set-row.inline { flex-direction: row; align-items: center; justify-content: space-between; gap: var(--s-4); }
.set-label { font-family: var(--font-head); font-size: var(--t-lg); line-height: 1.3; }
.set-label small { display: block; font-family: var(--font); font-size: var(--t-sm); color: var(--muted); }
.set-row input[type=range] { width: 100%; accent-color: var(--accent); min-height: 44px; }
.pw summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; }
.pw form { display: flex; flex-direction: column; gap: var(--s-3); padding-bottom: var(--s-3); }
.set-acts { display: flex; flex-direction: column; gap: var(--s-3); padding-top: var(--s-5); }
.who { display: flex; align-items: baseline; justify-content: space-between; color: var(--muted); font-size: var(--t-sm); }

/* ---------- home ---------- */
.goal { display: grid; grid-template-columns: auto 1fr; grid-template-areas: "dial text" "cta cta"; gap: var(--s-4) var(--s-5); align-items: center; padding: var(--s-5) 0; border-top: 1px solid var(--text); border-bottom: 1px solid var(--line); }
.goal .dial { grid-area: dial; }
.goal .gtext { grid-area: text; min-width: 0; }
.goal h2 { line-height: 1.2; margin: 4px 0 6px; font-size: 1.2rem; }
.goal p { color: var(--muted); font-size: var(--t-sm); }
.goal .cta { grid-area: cta; }
.goal .cta .btn { width: 100%; }
.goal-actions { display: flex; flex-direction: column; gap: var(--s-2); }
.quick-grid { display: grid; grid-template-columns: 1fr 1fr; border-left: 1px solid var(--line); margin-top: var(--s-2); }
.qa { display: flex; align-items: center; gap: var(--s-3); min-height: 64px; padding: var(--s-2) var(--s-3); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); font-family: var(--font-head); font-size: var(--t-md); line-height: 1.25; text-align: left; }
.qa .ic { color: var(--accent); }
.qa small { display: block; font-family: var(--font); font-size: var(--t-xs); color: var(--muted); }
.qa:hover { background: var(--surface); }
.qa:last-child:nth-child(odd) { grid-column: 1 / -1; }
.deck-mini { display: flex; flex-direction: column; gap: var(--s-2); }
.deck-mini .mini-row { display: flex; justify-content: space-between; align-items: baseline; font-size: var(--t-sm); color: var(--muted); }
.deck-mini b { font-family: var(--font-head); font-weight: 500; font-size: var(--t-lg); color: var(--text); font-variant-numeric: lining-nums; }

/* ---------- lesson player ---------- */
#player { position: absolute; inset: 0; z-index: 20; background: var(--bg) var(--grain); display: flex; flex-direction: column; min-height: 0; }
.p-top { display: grid; grid-template-columns: 48px 1fr auto; align-items: center; gap: var(--s-2); padding: calc(var(--s-2) + env(safe-area-inset-top)) var(--s-5) 0 var(--s-3); }
.leave { display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px; border-radius: 50%; color: var(--muted); }
.leave:hover { color: var(--text); background: var(--surface2); }
.p-top .esc { display: none; }
.p-stage { text-align: center; font-family: var(--font-head); font-style: italic; font-size: var(--t-lg); min-height: 1.5em; }
.p-count { font-family: var(--font-head); font-size: var(--t-md); font-variant-numeric: lining-nums tabular-nums; color: var(--muted); min-width: 48px; text-align: right; }
.p-count b { color: var(--text); font-weight: 500; }
.p-bar { height: 3px; background: var(--tick-off); border-radius: 2px; margin: var(--s-2) var(--s-5) 0; overflow: hidden; }
.p-fill { height: 100%; width: 0; background: var(--accent); border-radius: 2px; transition: width .5s cubic-bezier(.2,.8,.3,1); }
.p-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: var(--s-4) max(var(--s-5), env(safe-area-inset-right)) var(--s-4) max(var(--s-5), env(safe-area-inset-left)); scrollbar-width: thin; }
.p-body { position: relative; display: flex; flex-direction: column; gap: var(--s-4); min-width: 0; animation: rise .3s cubic-bezier(.2,.8,.3,1); }
.p-body > * { flex-shrink: 0; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
/* paper flashcard */
.flash { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: var(--s-4) 18px var(--s-5); margin-bottom: 14px;
  box-shadow: 0 1px 0 var(--line), 0 5px 0 -1px var(--surface), 0 6px 0 -1px var(--line), 0 10px 0 -2px var(--surface), 0 11px 0 -2px var(--line), 0 18px 30px -12px var(--shadow); }
.flash::after { content: ""; position: absolute; top: -1px; right: -1px; width: 22px; height: 22px; background: linear-gradient(225deg, var(--bg) 50%, var(--surface2) 50%); border-bottom-left-radius: 3px; border-left: 1px solid var(--line); border-bottom: 1px solid var(--line); pointer-events: none; }
.p-foot { display: flex; gap: var(--s-3); padding: var(--s-3) max(var(--s-5), env(safe-area-inset-right)) calc(var(--s-3) + env(safe-area-inset-bottom)) max(var(--s-5), env(safe-area-inset-left)); background: var(--bg) var(--grain); border-top: 1px solid var(--line); }
.p-foot > .btn { flex: 1; }
.p-foot > .row-flex { width: 100%; }
.p-foot .row-flex .btn { flex: 1; min-width: 0; padding: 0 var(--s-3); }
.p-foot .row-flex .btn.primary { flex: 1.5; }
.p-foot:empty { display: none; }
#player.has-fb .p-foot { visibility: hidden; }
.kb .p-foot { padding-bottom: var(--s-3); }

/* feedback: bottom sheet on phone, margin note on desktop */
.scrim { position: absolute; inset: 0; background: var(--scrim); z-index: 25; animation: fade .3s both; }
.fb { position: absolute; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--line2); border-radius: 14px 14px 0 0;
  padding: var(--s-3) var(--s-5) calc(var(--s-4) + env(safe-area-inset-bottom)); box-shadow: 0 -18px 40px -10px var(--shadow);
  animation: sheet .38s cubic-bezier(.2,.85,.3,1) both; max-height: 88%; overflow-y: auto; display: flex; flex-direction: column; gap: var(--s-3); }
.fb::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--line2); margin: 0 auto var(--s-2); flex: none; }
.fb-h { display: flex; align-items: center; gap: var(--s-3); }
.fb-ic { width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.fb-ic .ic { width: 22px; height: 22px; stroke-width: 2; }
.fb.ok .fb-ic { background: var(--ok-soft); color: var(--ok); animation: pop .5s .1s cubic-bezier(.3,1.4,.5,1) both; }
.fb.warn .fb-ic { background: var(--warn-soft); color: var(--warn); }
.fb.bad .fb-ic { background: var(--bad-soft); color: var(--bad); }
@keyframes pop { 0% { transform: scale(.4); opacity: 0; } 60% { transform: scale(1.12); opacity: 1; } 100% { transform: scale(1); } }
.fb-h > div { flex: 1; min-width: 0; }
.fb-h h3 { font-size: var(--t-xl); font-style: italic; line-height: 1.1; }
.fb.ok h3 { color: var(--ok); } .fb.warn h3 { color: var(--warn); } .fb.bad h3 { color: var(--bad); }
.fb-h p { font-size: var(--t-sm); color: var(--muted); }
.fb-body { display: flex; flex-direction: column; gap: var(--s-3); min-height: 0; }
.diff { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px var(--s-4); align-items: baseline; font-family: var(--font-head); font-size: var(--t-xl); overflow-wrap: anywhere; }
.diff dt { font-family: var(--font); font-size: var(--t-xs); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.diff dd { margin: 0; }
.diff del { text-decoration-color: var(--bad); }
.fb-sent { font-family: var(--font-head); font-size: var(--t-lg); line-height: 1.4; overflow-wrap: anywhere; }
.fb-ref { font-size: var(--t-sm); color: var(--muted); overflow-wrap: anywhere; }
.fb-ref b { font-family: var(--font-head); font-weight: 500; color: var(--text); }
.fb-note { font-size: var(--t-md); line-height: 1.55; overflow-wrap: anywhere; }
.fb-acts { display: flex; gap: var(--s-3); margin-top: var(--s-2); flex: none; }
.fb-acts .btn { flex: 1; min-width: 0; padding: 0 var(--s-3); }
/* quiet confirmation for an effortless correct answer: no sheet, no scrim */
.fb.auto { left: auto; right: var(--s-5); bottom: calc(var(--s-4) + env(safe-area-inset-bottom)); width: auto; padding: var(--s-2) var(--s-4) var(--s-2) var(--s-2); border: 1px solid var(--line2); border-radius: 999px; box-shadow: 0 8px 20px -10px var(--shadow); animation: fade-up .25s both; }
.fb.auto::before { display: none; }
.fb.auto .fb-ic { width: 32px; height: 32px; }
.fb.auto h3 { font-size: var(--t-lg); }
@keyframes fade-up { from { opacity: 0; transform: translateY(6px); } }

/* ---------- desktop ---------- */
@media (min-width: 1024px) {
  :root { --t-lg: 1.1875rem; --t-xl: 1.5rem; --t-2xl: 2rem; --t-3xl: 2.75rem; }
  #login .brand { font-size: 2rem; }
  .goal h2 { font-size: 1.3rem; }
  .only-phone { display: none !important; }
  #app { max-width: none; border-inline: 0; grid-template-columns: var(--toc-w) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  #tabbar { display: none; }
  #toc { display: flex; flex-direction: column; padding: var(--s-6) var(--s-5) var(--s-5); border-right: 1px solid var(--line2); gap: var(--s-5); overflow-y: auto; min-height: 0; }
  #toc .brand { font-size: 1.75rem; }
  #toc .brand svg { width: 22px; height: 32px; }
  #toc .sub { font-family: var(--font-head); font-style: italic; color: var(--muted); font-size: var(--t-sm); margin-top: var(--s-2); }
  #toc h2 { font-family: var(--font); font-size: var(--t-xs); letter-spacing: .16em; text-transform: uppercase; font-weight: 600; color: var(--muted); padding-bottom: var(--s-2); border-bottom: 1px solid var(--text); }
  .toc-list { list-style: none; padding: 0; }
  .toc-item { display: flex; align-items: baseline; gap: 8px; width: 100%; padding: 11px 0 11px 14px; position: relative; font-family: var(--font-head); font-size: var(--t-lg); line-height: 1.2; color: var(--text); border-bottom: 1px solid var(--line); min-height: 48px; }
  .toc-item .ld { flex: 1; border-bottom: 1px dotted var(--line2); transform: translateY(-4px); }
  .toc-item .pg { font-size: var(--t-sm); color: var(--muted); font-variant-numeric: lining-nums tabular-nums; }
  .toc-item:hover { color: var(--accent); }
  .toc-item[aria-current="page"] { color: var(--accent); font-weight: 600; }
  .toc-item[aria-current="page"]::before { content: ""; position: absolute; left: 0; top: 50%; width: 6px; height: 6px; margin-top: -3px; border-radius: 50%; background: var(--accent); }
  .toc-item[aria-current="page"] .pg { color: var(--accent); }
  #toc .appx { margin-top: var(--s-4); }
  #toc .me { margin-top: auto; padding-top: var(--s-4); border-top: 1px solid var(--line2); display: grid; grid-template-columns: 40px 1fr; gap: 4px 12px; align-items: center; }
  #toc .av { grid-row: span 2; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--text); display: inline-flex; align-items: center; justify-content: center; font-family: var(--font-head); font-style: italic; font-size: var(--t-xl); }
  #toc .me b { font-family: var(--font-head); font-weight: 500; font-size: var(--t-lg); line-height: 1.1; }
  #toc .me span:not(.av) { font-size: var(--t-xs); color: var(--muted); letter-spacing: .04em; }

  h1 { font-size: 3.25rem; }
  .page { max-width: 880px; padding: var(--s-6) 40px var(--s-6) 56px; gap: var(--s-5); }
  .page.has-aside { display: grid; grid-template-columns: minmax(0, 1fr) 304px; column-gap: 44px; align-items: start; max-width: 1180px; }
  .page.has-aside .col-main { display: flex; flex-direction: column; gap: var(--s-5); min-width: 0; }
  .page.has-aside .col-aside { display: flex; flex-direction: column; gap: var(--s-5); padding-left: 28px; border-left: 1px solid var(--line2); min-height: 360px; }
  .row { min-height: 44px; padding: 10px 0; }
  .goal { gap: var(--s-6); padding: var(--s-5) 0; }
  .dial { width: 148px; height: 148px; }
  .goal { grid-template-areas: "dial text" "dial cta"; grid-template-rows: auto 1fr; align-items: start; }
  .goal .cta { grid-area: cta; margin-top: 0; align-self: start; }
  .goal .cta .btn { width: auto; min-width: 200px; }
  .quick-grid { grid-template-columns: repeat(4, 1fr); }
  .qa { flex-direction: column; align-items: flex-start; justify-content: center; gap: 6px; min-height: 84px; }
  .qa:last-child:nth-child(odd) { grid-column: auto; }
  kbd { display: inline-flex; }
  .btn:hover:not(:disabled):not(.primary) { background: var(--surface); }

  /* player = centred paper card + margin-note column */
  #player { left: var(--toc-w); display: grid; grid-template-columns: minmax(0, 720px) 304px; grid-template-rows: auto auto auto auto 1fr; column-gap: 44px; justify-content: center; align-content: start; overflow-y: auto; padding: var(--s-6) 40px; }
  #player > .p-top, #player > .p-bar, #player > .p-scroll, #player > .p-foot { grid-column: 1; }
  .p-top { padding: 0; grid-template-columns: auto 1fr auto; }
  .p-top .leave { width: auto; padding: 0 var(--s-2); gap: 10px; border-radius: var(--r); font-size: var(--t-sm); }
  .p-top .leave .esc { display: inline-flex; align-items: center; gap: 8px; }
  .p-bar { margin: var(--s-2) 0 0; }
  .p-scroll { overflow: visible; padding: var(--s-5) 0 var(--s-2); flex: none; min-height: auto; }
  .flash { padding: var(--s-6) var(--s-7) var(--s-7); margin-bottom: 18px; }
  .p-foot { background: none; border: 0; padding: 0; gap: var(--s-3); justify-content: flex-start; }
  .p-foot > .btn, .p-foot .row-flex .btn { flex: none; min-width: 120px; }
  .p-foot .row-flex { width: auto; }
  .p-foot .row-flex .btn.primary { flex: none; min-width: 200px; }
  .p-foot .btn.primary kbd, .fb-acts .btn.primary kbd { margin-left: 4px; }
  #player > .fb { grid-column: 2; grid-row: 1 / span 5; position: static; align-self: start; background: none; border: 0; border-left: 2px solid var(--fbc, var(--line2)); border-radius: 0; box-shadow: none; padding: 0 0 0 var(--s-4); max-height: none; overflow: visible; animation: note-in .5s cubic-bezier(.2,.8,.3,1) both; margin-top: var(--s-2); }
  .fb::before { display: none; }
  .fb.ok { --fbc: var(--ok); } .fb.warn { --fbc: var(--warn); } .fb.bad { --fbc: var(--bad); }
  .fb.auto { width: auto; border-radius: 0; border: 0; border-left: 2px solid var(--ok); box-shadow: none; padding: 0 0 0 var(--s-4); }
  #player > .scrim { display: none; }
  @keyframes note-in { from { opacity: 0; transform: translateX(10px); } }
  .fb-acts { flex-direction: column; }
  .diff { font-size: 1.375rem; }
  .toast-pos, #toast { bottom: var(--s-5); }
}

/* phone details */
@media (max-width: 380px) {
  .page { padding-left: var(--s-4); padding-right: var(--s-4); }
  .p-scroll, .p-foot { padding-left: var(--s-4); padding-right: var(--s-4); }
  .p-top { padding-right: var(--s-4); }
  .p-bar { margin-left: var(--s-4); margin-right: var(--s-4); }
  .flash { padding-left: 14px; padding-right: 14px; }
  .goal { gap: var(--s-4); }
  .dial { width: 116px; height: 116px; }
}
@media (max-height: 560px) and (max-width: 1023px) { .p-foot { padding-top: var(--s-2); padding-bottom: var(--s-2); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
