/* Chinese flashcards · shrimply.xyz/chinese
   Quiet celadon + indigo-ink chrome so the tone colours carry the screen.
   Tone colours follow Pleco's defaults: 1 red, 2 green, 3 blue, 4 purple, neutral grey. */

:root {
  --paper: #e9efec;
  --surface: #ffffff;
  --ink: #16213a;
  --muted: #5d6a7c;
  --line: #cfdad4;
  --primary: #16213a;
  --on-primary: #ffffff;
  --hit: #1e8a52;
  --miss: #c9392c;

  --t1: #d9352a;
  --t2: #1f944f;
  --t3: #2a66d4;
  --t4: #8a3dc4;
  --t5: #7d8795;

  --han-sans: "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Noto Sans SC", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
  --han-serif: "Songti SC", "STSong", "Noto Serif CJK SC", "Noto Serif SC", "Source Han Serif SC", "SimSun", serif;
  --han-kai: "Kaiti SC", "STKaiti", "KaiTi", "Kaiti TC", "BiauKai", "AR PL UKai CN", var(--han-serif);
  --han: var(--han-sans);
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, var(--han-sans);

  --r-lg: 22px;
  --r-md: 14px;
  --lift: 0 1px 2px rgb(22 33 58 / .06), 0 6px 18px -10px rgb(22 33 58 / .25);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0f1623;
    --surface: #182235;
    --ink: #e7edf6;
    --muted: #93a0b4;
    --line: #2a364c;
    --primary: #e7edf6;
    --on-primary: #0f1623;
    --hit: #3fb572;
    --miss: #ef6557;
    --t1: #ff6f63;
    --t2: #4cc97c;
    --t3: #6ea1ff;
    --t4: #c286f5;
    --t5: #99a3b3;
    --lift: 0 1px 2px rgb(0 0 0 / .3), 0 8px 22px -12px rgb(0 0 0 / .7);
  }
}

body[data-han="serif"] { --han: var(--han-serif); }
body[data-han="kai"]   { --han: var(--han-kai); }

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.45 var(--ui);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
/* Lessons, notes and review schedule need the v2 API on the Pi. */
body:not([data-v2]) .v2 { display: none !important; }

.t1 { --tc: var(--t1); color: var(--t1); }
.t2 { --tc: var(--t2); color: var(--t2); }
.t3 { --tc: var(--t3); color: var(--t3); }
.t4 { --tc: var(--t4); color: var(--t4); }
.t5 { --tc: var(--t5); color: var(--t5); }

/* ── shell ────────────────────────────────────────────────────────────── */

.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-areas: "top" "main" "nav";
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) calc(env(safe-area-inset-right) + 18px) 10px calc(env(safe-area-inset-left) + 18px);
}
.topbar .home { color: var(--muted); text-decoration: none; font-size: 14px; padding: 8px 0; }
.topbar h1 { font-size: 17px; font-weight: 650; flex: 1; }
.conn { width: 10px; height: 10px; border-radius: 50%; background: var(--line); flex: none; }
.conn[data-state="up"] { background: var(--hit); }
.conn[data-state="down"] { background: var(--miss); }

main {
  grid-area: main;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px calc(env(safe-area-inset-right) + 16px) 24px calc(env(safe-area-inset-left) + 16px);
}

.view {
  max-width: 680px;
  min-height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tabbar {
  grid-area: nav;
  display: grid;
  grid-template-columns: 1.25fr repeat(5, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 4px calc(env(safe-area-inset-right) + 4px) calc(env(safe-area-inset-bottom) + 4px) calc(env(safe-area-inset-left) + 4px);
}
.tab {
  min-height: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  border-radius: var(--r-md);
}
.tab .glyph { font-family: var(--han); font-size: 22px; line-height: 1; }
.tab .lbl { font-size: clamp(10px, 2.9vw, 12px); white-space: nowrap; }
.tab[aria-current="page"] { color: var(--ink); }
.tab[aria-current="page"] .lbl { font-weight: 650; }

/* The tone drill tab is the headline: a filled seal that stays visible. */
.tab-hero .glyph {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--t1) 0 25%, var(--t2) 25% 50%, var(--t3) 50% 75%, var(--t4) 75%);
  color: #fff;
  font-size: 22px;
  text-shadow: 0 1px 2px rgb(0 0 0 / .35);
}
.tab-hero[aria-current="page"] .glyph { outline: 2px solid var(--ink); outline-offset: 2px; }

/* ── controls ─────────────────────────────────────────────────────────── */

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, [role="button"]:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 3px solid var(--t3);
  outline-offset: 2px;
}

.primary, .ghost, .danger, .btn-hit, .btn-miss {
  min-height: 48px;
  padding: 0 18px;
  border-radius: var(--r-md);
  font-weight: 600;
  transition: transform .08s ease;
}
.primary:active, .ghost:active, .btn-hit:active, .btn-miss:active, .tone-btn:active { transform: scale(.97); }
.primary { background: var(--primary); color: var(--on-primary); }
.ghost { background: var(--surface); border: 1.5px solid var(--line); }
.danger { color: var(--miss); border: 1.5px solid currentColor; background: transparent; }
.btn-hit { background: var(--hit); color: #fff; }
.btn-miss { background: var(--miss); color: #fff; }
.small { min-height: 44px; padding: 0 14px; font-size: 15px; }
.big { min-height: 64px; font-size: 19px; width: 100%; border-radius: 18px; }
.link { color: var(--t3); text-decoration: underline; min-height: 44px; padding: 0; }
.added { color: var(--hit); }

input, select, textarea {
  font: inherit;
  font-size: 17px; /* 16px+ stops iOS zooming on focus */
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 12px;
}
textarea { resize: vertical; }
select { width: auto; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > * { flex: 1 1 0; }
.muted { color: var(--muted); }
.small-text { font-size: 14px; }
.center { text-align: center; padding: 24px 0; }
.error { color: var(--miss); min-height: 1.4em; }

.toolbar { display: flex; align-items: center; gap: 10px; }
.toolbar .progress { flex: 1; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.toolbar select { min-height: 44px; padding: 6px 12px; font-size: 15px; }
.toolbar .scope { flex: 1 1 0; min-width: 0; }
.toolbar .scope ~ .progress { flex: none; font-size: 14px; min-width: 2.5em; }
.icon { width: 44px; padding: 0; font-size: 20px; flex: none; }
#quiz-mode { flex: none; }
.toolbar.sticky {
  position: sticky; top: -4px; z-index: 2;
  background: var(--paper);
  padding: 8px 0;
}
.toolbar.sticky input { flex: 1; }

.panel { background: var(--surface); border-radius: var(--r-lg); padding: 18px; box-shadow: var(--lift); display: grid; gap: 12px; }
.panel h2 { font-size: 17px; }
.api-base { font-size: 14px; word-break: break-all; }

/* ── study stages (drill + quiz) ──────────────────────────────────────── */

.stage { flex: 1; display: flex; flex-direction: column; gap: 14px; }
.controls { display: flex; flex-direction: column; gap: 10px; }

.hanzi-block { text-align: center; }
.hanzi { font-family: var(--han); font-size: clamp(64px, 22vw, 128px); line-height: 1.12; word-break: break-all; }
.hanzi.len-m { font-size: clamp(48px, 15vw, 100px); }
.hanzi.len-l { font-size: clamp(34px, 10vw, 72px); }
.hanzi.len-xl { font-size: clamp(26px, 7.5vw, 52px); }
.trad { font-family: var(--han); color: var(--muted); font-size: 20px; }

.drill-card, .flashcard {
  flex: 1;
  min-height: 250px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 22px 16px;
  background: var(--surface);
  border-radius: 26px;
  box-shadow: var(--lift);
  border: 2px solid transparent;
  transition: border-color .2s ease;
}
.drill-card.is-ok { border-color: var(--hit); }
.drill-card.is-bad { border-color: var(--miss); }

.slots { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.slot {
  min-width: 66px;
  padding: 8px 10px 6px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  border-radius: var(--r-md);
  border: 2px dashed var(--line);
}
.slot .syl { font-size: 20px; font-weight: 600; }
.slot .num { font-size: 24px; font-weight: 800; line-height: 1.1; min-height: 1.1em; color: var(--muted); }
.slot .num[class*=" t"] { color: var(--tc); }
.slot.current { border-style: solid; border-color: var(--ink); }
.slot.filled { border-style: solid; }
.slot.just .num { animation: pop .18s ease-out; }
.slot.ok { border-style: solid; border-color: var(--hit); }
.slot.bad { border-style: solid; border-color: var(--miss); }
.slot .yours { font-size: 12px; color: var(--muted); }

.reveal { text-align: center; display: grid; gap: 6px; max-width: 34em; }
.verdict { font-weight: 700; font-size: 17px; }
.is-ok .verdict { color: var(--hit); }
.is-bad .verdict { color: var(--miss); }
.eng { color: var(--ink); overflow-wrap: anywhere; }

.tone-pad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.tone-btn {
  min-height: 84px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  border-radius: 18px;
  background: color-mix(in srgb, var(--tc) 12%, var(--surface));
  border: 2px solid color-mix(in srgb, var(--tc) 45%, transparent);
  transition: transform .08s ease;
}
.tone-btn .n { font-size: 30px; font-weight: 800; line-height: 1; }
.tone-btn .contour svg { width: 34px; height: 24px; display: block; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.tone-btn .contour circle { fill: currentColor; stroke: none; }
.pad-aux .ghost { min-height: 48px; }

.flashcard { cursor: pointer; user-select: none; -webkit-user-select: none; text-align: center; }
.flashcard .hint { color: var(--muted); }
.flashcard .back { display: grid; gap: 8px; animation: rise .22s ease-out; max-width: 34em; }
.pinyin { font-weight: 600; font-size: 18px; }
.pinyin.big { font-size: 26px; }
.meta { color: var(--muted); font-size: 14px; }
.answer-row { flex-direction: row; }
.answer-row > * { flex: 1; }

.empty, .summary {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; text-align: center; padding: 24px 8px;
}
.empty h2 { font-size: 20px; }
.summary .score { font-size: 20px; }
.summary .score strong { font-size: 44px; display: block; font-variant-numeric: tabular-nums; }
.missed { width: 100%; max-width: 420px; }
.missed h3 { font-size: 15px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.missed ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.missed li { display: flex; align-items: baseline; gap: 12px; background: var(--surface); padding: 10px 14px; border-radius: 12px; }
.missed .han { font-family: var(--han); font-size: 24px; }
.summary .btn-row { width: 100%; max-width: 420px; }

/* ── writing practice ─────────────────────────────────────────────────── */

.write-card {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px;
  padding: 14px 10px;
  background: var(--surface);
  border-radius: 26px;
  box-shadow: var(--lift);
}
.write-prompt { display: grid; gap: 4px; justify-items: center; text-align: center; max-width: 30em; }
.write-prompt .prompt-eng { font-size: 21px; }
.write-prompt .pinyin.big { font-size: 22px; min-height: 0; width: auto; border-radius: 0; }
.link.mini { min-height: 32px; font-size: 14px; }
.wboxes { display: grid; gap: 10px; justify-content: center; }
.wbox { position: relative; color: color-mix(in srgb, var(--miss) 50%, transparent); }
.wgrid, .wghost, .wcanvas { position: absolute; inset: 0; }
.wgrid svg { width: 100%; height: 100%; display: block; }
.wghost {
  display: grid; place-items: center;
  font-family: var(--han-kai); line-height: 1;
  color: color-mix(in srgb, var(--t3) 35%, transparent);
  pointer-events: none;
}
.wcanvas {
  touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  cursor: crosshair;
}
.write-answer { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; }
.write-answer .trad { font-size: 16px; }
.so-layer { position: absolute; inset: 0; pointer-events: none; }
.so-layer svg { display: block; }
.wbox.so-on .wcanvas { opacity: .18; }
.wbox.so-on .wghost { opacity: 0; }
.so-strip { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.write-answer .ghost.small { min-height: 36px; }
.write-card .notes { color: var(--muted); font-size: 15px; text-align: center; }
.controls.write-tools { flex-direction: row; gap: 8px; }
.write-tools > * { flex: 1; min-height: 56px; padding: 0 10px; }
.write-tools .w-show { flex: 2; font-size: 17px; }
.write-tools .btn-hit, .write-tools .btn-miss { font-size: 17px; }

/* ── deck ─────────────────────────────────────────────────────────────── */

.deck-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.deck-card { perspective: 900px; cursor: pointer; border-radius: 18px; }
.deck-card .inner {
  display: grid;
  min-height: 150px;
  transform-style: preserve-3d;
  transition: transform .45s cubic-bezier(.2, .7, .2, 1);
}
.deck-card.flipped .inner { transform: rotateY(180deg); }
.face {
  grid-area: 1 / 1;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--lift);
  padding: 14px 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  text-align: center;
  min-width: 0;
}
.face.back { transform: rotateY(180deg); }
.deck-card:not(.flipped) .back, .deck-card.flipped .front { pointer-events: none; }
.face .han { font-family: var(--han); font-size: 44px; line-height: 1.15; word-break: break-all; }
.face .han.len-m { font-size: 32px; }
.face .han.len-l { font-size: 24px; }
.face .han.len-xl { font-size: 18px; }
.face .trad { font-size: 15px; }
.face .eng { font-size: 14px; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.face .pinyin { font-size: 17px; }
.face .meta { font-size: 12px; }

/* ── dictionary ─────────────────────────────────────────────────────── */

.dict-list { display: grid; gap: 16px; }
.dict-group { display: grid; gap: 6px; }
.dict-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 0 4px 0 6px; min-height: 36px;
}
.dict-head h3 { font-size: 13px; font-weight: 700; letter-spacing: .04em; color: var(--muted); min-width: 0; }
.gh-n { font-weight: 500; margin-left: 8px; }
.gh-actions { display: flex; gap: 6px; flex: none; }
.pill {
  min-height: 34px; padding: 0 12px; border-radius: 999px;
  background: var(--surface); border: 1.5px solid var(--line);
  font-size: 14px; font-weight: 600;
}
.pill:active { transform: scale(.96); }
.dr-tag {
  flex: none; align-self: center; max-width: 30%;
  padding: 2px 8px; border-radius: 999px;
  background: var(--paper); color: var(--muted); font-size: 12px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dict-rows {
  list-style: none; margin: 0; padding: 0;
  background: var(--surface); border-radius: 18px; box-shadow: var(--lift); overflow: hidden;
}
.dict-rows li + li { border-top: 1px solid var(--line); }
.dict-row {
  width: 100%; min-height: 62px;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px;
  text-align: left;
}
.dict-row:active { background: color-mix(in srgb, var(--ink) 7%, transparent); }
.dr-han { flex: none; min-width: 2.1em; max-width: 46%; font-family: var(--han); font-size: 28px; line-height: 1.2; overflow-wrap: anywhere; }
.dr-han.len-m { font-size: 22px; }
.dr-han.len-l, .dr-han.len-xl { font-size: 18px; }
.dr-body { flex: 1; min-width: 0; display: grid; gap: 1px; }
.dr-py { font-size: 16px; }
.dr-eng {
  color: var(--muted); font-size: 15px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

#entry-dialog { padding: 0; overflow-y: auto; overscroll-behavior: contain; }
.entry { padding: 22px 18px 18px; display: grid; gap: 18px; }
.entry-head { display: grid; justify-items: center; gap: 10px; text-align: center; }
.entry-defs { font-size: 17px; }
p.entry-defs { text-align: center; }
.entry-sec { display: grid; gap: 8px; }
.entry-sec h3 { font-size: 13px; font-weight: 700; letter-spacing: .04em; color: var(--muted); }
.entry .dict-rows { box-shadow: none; background: var(--paper); }
.char-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.char-chip {
  width: 100%; min-height: 52px;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px; border-radius: 14px;
  background: var(--paper); text-align: left;
}
.char-chip .han { font-family: var(--han); font-size: 26px; line-height: 1.2; }
.char-chip .pinyin { font-size: 16px; }
.char-chip .ce { flex: 1; min-width: 0; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.char-chip.none { opacity: .75; }
.entry .meta { text-align: center; }
.entry-tools { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; }
.lesson-chip { padding: 6px 12px; border-radius: 999px; background: var(--paper); font-size: 14px; font-weight: 600; }
.notes { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 16px; }
.flashcard .notes { color: var(--muted); font-size: 15px; }
.prompt-en { display: grid; gap: 8px; text-align: center; max-width: 30em; }
.prompt-eng { font-size: clamp(22px, 6.5vw, 32px); font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.lesson-panel { gap: 8px; padding: 14px 16px; }
.lesson-panel label { font-weight: 600; }
.entry-actions { display: flex; gap: 10px; }
.entry-actions > * { flex: 1; }

/* ── add ──────────────────────────────────────────────────────────────── */

.search-row { display: flex; gap: 8px; }
.search-row input { flex: 1; min-width: 0; }
.results { display: grid; gap: 10px; }
.candidate { background: var(--surface); border-radius: 18px; padding: 14px 16px; box-shadow: var(--lift); display: grid; gap: 6px; }
.cand-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.cand-han { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; min-width: 0; }
.candidate .han { font-family: var(--han); font-size: 34px; line-height: 1.15; word-break: break-all; }
.candidate .han.len-l, .candidate .han.len-xl { font-size: 24px; }
.candidate .trad { font-size: 18px; }
.defs { margin: 0; padding-left: 1.3em; color: var(--ink); }
.defs li { margin: 2px 0; }

.manual summary { cursor: pointer; font-weight: 600; min-height: 32px; display: flex; align-items: center; }
.form-grid { display: grid; gap: 14px; }
.form-grid label { display: grid; gap: 6px; font-weight: 600; font-size: 15px; }
.form-grid small { font-weight: 400; color: var(--muted); }
.opt { font-weight: 400; color: var(--muted); }
.inline-label { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 600; }

/* ── dialog, lock, toast ──────────────────────────────────────────────── */

dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  border: none;
  border-radius: 24px;
  padding: 20px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 20px 60px rgb(0 0 0 / .35);
}
dialog::backdrop { background: rgb(10 16 28 / .5); }
dialog h2 { font-size: 19px; }
.dialog-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dialog-actions .spacer { flex: 1; }

.lock {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  padding: 24px;
  background: var(--paper);
}
.lock-card { width: min(380px, 100%); display: grid; gap: 14px; text-align: center; }
.seal {
  width: 76px; height: 76px; margin: 0 auto 6px;
  display: grid; place-items: center;
  border-radius: 20px;
  font-family: var(--han); font-size: 46px; color: #fff;
  background: linear-gradient(135deg, var(--t1) 0 25%, var(--t2) 25% 50%, var(--t3) 50% 75%, var(--t4) 75%);
  text-shadow: 0 1px 3px rgb(0 0 0 / .35);
}
.lock-card h2 { font-size: 22px; }

.toast {
  position: fixed; left: 50%; z-index: 30;
  bottom: calc(env(safe-area-inset-bottom) + 84px);
  transform: translate(-50%, 20px);
  width: max-content; max-width: calc(100vw - 32px);
  padding: 12px 18px;
  border-radius: var(--r-md);
  background: var(--primary); color: var(--on-primary);
  font-size: 15px;
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--miss); color: #fff; }
.toast.warn { background: #b86e00; color: #fff; }

@keyframes pop { from { transform: scale(1.5); } to { transform: scale(1); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── landscape phones: nav becomes a side rail, study stages go two-up ── */

@media (orientation: landscape) and (max-height: 540px) {
  .app {
    grid-template-columns: auto 1fr;
    grid-template-rows: 1fr;
    grid-template-areas: "nav main";
  }
  .topbar { display: none; }
  .tabbar {
    grid-template-columns: 1fr;
    grid-template-rows: 1.25fr repeat(5, 1fr);
    width: calc(env(safe-area-inset-left) + 78px);
    border-top: none;
    border-right: 1px solid var(--line);
    padding: calc(env(safe-area-inset-top) + 4px) 4px calc(env(safe-area-inset-bottom) + 4px) calc(env(safe-area-inset-left) + 4px);
  }
  .tab { min-height: 0; }
  main { padding: 10px calc(env(safe-area-inset-right) + 16px) 12px 16px; }
  .view { max-width: 980px; }
  .stage.drill, .stage.quiz { display: grid; grid-template-columns: 1.1fr 1fr; align-items: stretch; }
  .stage > .empty, .stage > .summary { grid-column: 1 / -1; }
  .controls { justify-content: center; }
  .drill-card, .flashcard { min-height: 0; gap: 12px; padding: 14px; }
  .hanzi { font-size: clamp(48px, 17vh, 96px); }
  .hanzi.len-m { font-size: clamp(38px, 13vh, 76px); }
  .hanzi.len-l { font-size: clamp(28px, 9vh, 56px); }
  .tone-btn { min-height: 72px; }
  .answer-row { flex-direction: column; }
  .toast { bottom: calc(env(safe-area-inset-bottom) + 16px); }
}

@media (min-width: 900px) and (min-height: 600px) {
  .tone-btn { min-height: 96px; }
}

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