/* Kotoba Beat web. A shōnen-flavoured study game: ink outlines, flame accent, heavy italic display type.
   Everything is built on the design tokens below (colour, type, spacing, radius, motion) in light and dark. */

/* ======================================================================
   Tokens
   ====================================================================== */
:root {
  /* Colour: light (paper and ink) */
  --bg: #f6f1e8;
  --surface: #fffdf9;
  --surface-2: #efe8dc;
  --border: #ddd3c3;
  --border-strong: #8f8577;      /* 3:1 on surface: outlines that must be seen */
  --ink: #16131d;
  --dim: #5b5466;
  --accent: #c4300c;             /* flame */
  --accent-ink: #ffffff;
  --accent-soft: color-mix(in srgb, var(--accent) 12%, var(--surface));
  --electric: #0b5fc0;           /* the rival's colour: links, info, focus */
  --trace: #0a6a88;
  --good: #146c43;
  --good-soft: color-mix(in srgb, var(--good) 13%, var(--surface));
  --miss: #984806;
  --miss-soft: color-mix(in srgb, var(--miss) 12%, var(--surface));
  --gold: #f5b800;               /* highlight fills only, always with ink text */
  --bonus-ink: #8a5a00;          /* text for bonus things (gold is too light to read as text) */
  --edge: #16131d;               /* hard "manga" shadow */
  --line: rgba(22, 19, 29, 0.1);
  --scrim: rgba(14, 12, 20, 0.6);
  --focus: #0b5fc0;
  --focus-halo: #ffffff;
  /* The aliases the modes already use */
  --panel: var(--surface);
  --panel-2: var(--surface-2);

  /* Type: Latin UI fonts first, then Japanese fonts that ship with iOS (Hiragino) and Windows (Yu Gothic, Meiryo). */
  --font-ui: "Segoe UI Variable Text", "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Roboto, Inter, Arial,
    "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic", Meiryo, "Noto Sans JP", "Noto Sans CJK JP", "IPAPGothic", sans-serif;
  --font-jp: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic", Meiryo, "Noto Sans JP", "Noto Sans CJK JP", "IPAPGothic", var(--font-ui);
  --font-mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
  --jp: var(--font-jp);
  --fs-xs: 0.75rem;
  --fs-sm: 0.875rem;
  --fs-md: 1rem;
  --fs-lg: 1.125rem;
  --fs-xl: 1.375rem;
  --fs-2xl: 1.75rem;
  --fs-3xl: 2.25rem;
  --fs-4xl: 3rem;
  --fs-jp-md: 1.25rem;           /* Japanese body text runs a step bigger than Latin */
  --fs-jp-lg: clamp(1.6rem, 6.5vw, 2.1rem);
  --fs-jp-xl: clamp(2.4rem, 11vw, 3.6rem);
  --lh-tight: 1.15;
  --lh: 1.5;
  --lh-ruby: 2.1;                /* room for furigana or romaji above every line */

  /* Space, radius, motion, layers */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.5rem;
  --sp-6: 2rem;
  --sp-7: 3rem;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-pill: 999px;
  --radius: var(--r-lg);
  --shadow: 0 1px 0 var(--line), 0 2px 8px rgba(22, 19, 29, 0.06);
  --shadow-hard: 3px 3px 0 var(--edge);
  --dur-fast: 120ms;
  --dur: 220ms;
  --dur-slow: 450ms;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-pop: cubic-bezier(0.3, 1.5, 0.5, 1);
  --z-bar: 20;
  --z-tabs: 30;
  --z-overlay: 60;
  --z-toast: 70;
  --tabbar-h: 64px;
  --topbar-h: 56px;
  --content-w: 720px;
  color-scheme: light;
}

/* Dark: night stage */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0c14;
    --surface: #1b1724;
    --surface-2: #14111c;
    --border: #2d273a;
    --border-strong: #6d6380;
    --ink: #f5efe4;
    --dim: #aaa2b8;
    --accent: #ff6b3d;
    --accent-ink: #1a0b05;
    --electric: #62adff;
    --trace: #5fd0ec;
    --good: #63d98a;
    --miss: #ffae5e;
    --gold: #ffcc33;
    --bonus-ink: #ffcc33;
    --edge: #000000;
    --line: rgba(255, 255, 255, 0.08);
    --scrim: rgba(0, 0, 0, 0.7);
    --focus: #62adff;
    --focus-halo: #0e0c14;
    --shadow: 0 1px 0 rgba(255, 255, 255, 0.04);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e0c14;
  --surface: #1b1724;
  --surface-2: #14111c;
  --border: #2d273a;
  --border-strong: #6d6380;
  --ink: #f5efe4;
  --dim: #aaa2b8;
  --accent: #ff6b3d;
  --accent-ink: #1a0b05;
  --electric: #62adff;
  --trace: #5fd0ec;
  --good: #63d98a;
  --miss: #ffae5e;
  --gold: #ffcc33;
  --bonus-ink: #ffcc33;
  --edge: #000000;
  --line: rgba(255, 255, 255, 0.08);
  --scrim: rgba(0, 0, 0, 0.7);
  --focus: #62adff;
  --focus-halo: #0e0c14;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.04);
  color-scheme: dark;
}

/* Text size setting: every size is in rem, so this scales the whole app. */
html { font-size: 100%; -webkit-text-size-adjust: 100%; }
html[data-text="s"] { font-size: 93.75%; }
html[data-text="l"] { font-size: 112.5%; }
html[data-text="xl"] { font-size: 125%; }
@media (min-width: 1000px) { :root { --content-w: 1040px; } }

/* ======================================================================
   Base
   ====================================================================== */
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  line-height: var(--lh);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
}
[lang="ja"] { font-family: var(--font-jp); }
p { margin: 0; }
h1, h2, h3 { margin: 0; }
a { color: var(--electric); }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Visible focus on every surface: a halo plus a coloured ring. */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px var(--focus-halo);
}
.skip-link {
  position: absolute; left: var(--sp-3); top: -100px; z-index: var(--z-toast);
  background: var(--ink); color: var(--bg); padding: var(--sp-2) var(--sp-4); border-radius: var(--r-sm); font-weight: 800;
}
.skip-link:focus { top: var(--sp-2); }
/* The screen itself takes focus after each move (for screen readers); it needs no ring, its controls keep theirs. */
.view:focus { outline: none; }

/* ======================================================================
   Shell: top bar, tab bar, view
   ====================================================================== */
.topbar {
  position: sticky; top: 0; z-index: var(--z-bar);
  display: flex; align-items: center; gap: var(--sp-1);
  min-height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(var(--sp-3), env(safe-area-inset-right)) 0 max(var(--sp-3), env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 2px solid var(--ink);
}
.topbar-title {
  flex: 1; min-width: 0;
  font-weight: 900; font-style: italic; font-size: var(--fs-lg); letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.iconbtn {
  min-width: 44px; min-height: 44px; display: inline-grid; place-items: center; flex: none;
  border: 2px solid transparent; background: transparent; color: var(--ink);
  font-size: 1.5rem; line-height: 1; text-decoration: none; cursor: pointer; border-radius: var(--r-md);
}
.iconbtn:hover { background: var(--surface-2); }
#back { font-size: 2rem; font-weight: 300; padding-bottom: 4px; }
.topbar .spacer { display: none; }
.view, .banner-wrap {
  width: 100%; max-width: var(--content-w); margin: 0 auto;
  padding: var(--sp-4) max(var(--sp-4), env(safe-area-inset-right)) var(--sp-6) max(var(--sp-4), env(safe-area-inset-left));
}
.banner-wrap { padding-bottom: 0; }
body.has-tabs .view { padding-bottom: calc(var(--tabbar-h) + var(--sp-6) + env(safe-area-inset-bottom)); }

/* Bottom tab bar on phones */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-tabs);
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 2px solid var(--ink);
}
body:not(.has-tabs) .tabbar { display: none; }
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--tabbar-h); padding: var(--sp-1) 0;
  color: var(--dim); text-decoration: none; font-size: var(--fs-xs); font-weight: 700;
  position: relative;
}
.tab-k { font-family: var(--font-jp); font-size: 1.4rem; font-weight: 900; line-height: 1; transition: transform var(--dur) var(--ease-pop); }
.tab[aria-current="page"] { color: var(--ink); }
.tab[aria-current="page"] .tab-k {
  color: var(--accent-ink); background: var(--accent); border-radius: var(--r-sm);
  padding: 4px 8px; transform: rotate(-4deg) scale(1.05); box-shadow: 2px 2px 0 var(--edge);
}
.tab:active .tab-k { transform: scale(0.9); }

/* Desktop: the same five destinations sit in the middle of the top bar, and are always there. */
@media (min-width: 760px) {
  body.has-tabs .view { padding-bottom: var(--sp-6); }
  .tabbar, body:not(.has-tabs) .tabbar {
    display: flex; gap: var(--sp-1);
    top: 0; bottom: auto; left: 50%; right: auto; transform: translateX(-50%);
    height: var(--topbar-h); margin-top: env(safe-area-inset-top);
    padding: 0; background: none; border: 0; backdrop-filter: none; -webkit-backdrop-filter: none;
    z-index: calc(var(--z-bar) + 1);
  }
  .tab { flex-direction: row; gap: var(--sp-2); min-height: 44px; padding: 0 var(--sp-3); margin: auto 0; border-radius: var(--r-md); font-size: var(--fs-sm); }
  .tab:hover { background: var(--surface-2); color: var(--ink); }
  .tab-k { font-size: 1.1rem; }
  .tab[aria-current="page"] .tab-k { padding: 2px 6px; }
  .topbar-title { flex: 0 1 auto; max-width: calc(50% - 300px); }
  .topbar .spacer { display: block; flex: 1; }
}

/* Screen transitions: a short slide in the direction of travel. */
.view.enter-fwd { animation: enter-fwd var(--dur) var(--ease-out); }
.view.enter-back { animation: enter-back var(--dur) var(--ease-out); }
.view.enter-fade { animation: enter-fade var(--dur) var(--ease-out); }
/* Forward: a slight zoom in. Never shift right: content pushed past the right edge widens the page mid-transition. */
@keyframes enter-fwd { from { opacity: 0; transform: scale(0.985); } to { opacity: 1; transform: none; } }
@keyframes enter-back { from { opacity: 0; transform: translateX(-18px); } to { opacity: 1; transform: none; } }
@keyframes enter-fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ======================================================================
   Primitives
   ====================================================================== */
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--sp-3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.row-gap { display: flex; gap: var(--sp-4); align-items: center; flex-wrap: wrap; }
.row-gap.baseline { align-items: baseline; }
.wrap-gap { flex-wrap: wrap; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-2); }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }
.right { text-align: right; }
.center-text { text-align: center; align-items: center; }
.left-text { text-align: left; align-self: stretch; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.panel {
  background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: var(--sp-4); box-shadow: var(--shadow); color: var(--ink);
}
.note { background: var(--surface-2); font-size: var(--fs-sm); }
.strong { font-weight: 700; }
.big { font-size: var(--fs-lg); }
.lead { font-size: var(--fs-lg); line-height: 1.4; }
.small { font-size: var(--fs-sm); }
.tiny { font-size: var(--fs-xs); }
.dim { color: var(--dim); }
.mono { font-variant-numeric: tabular-nums; }
.accent-c { color: var(--accent); }
.good-c { color: var(--good); }
.miss-c { color: var(--miss); }
.trace-c { color: var(--trace); }
.section-title { font-size: var(--fs-xl); font-weight: 900; font-style: italic; letter-spacing: -0.01em; }
.section-label {
  font-size: var(--fs-xs); font-weight: 900; letter-spacing: 0.12em; color: var(--dim); margin-top: var(--sp-2);
  display: flex; align-items: center; gap: var(--sp-2);
}
.section-label::after { content: ""; flex: 1; height: 2px; background: var(--line); }
.tag.new-tag { border-color: var(--good); color: var(--good); font-weight: 800; letter-spacing: 0.04em; }
.new-c { color: var(--good); }
.pair-line { border-top: 1px dashed var(--border); padding-top: var(--sp-1); margin-top: var(--sp-1); }
.tag {
  display: inline-block; font-size: var(--fs-xs); font-weight: 800; padding: 2px var(--sp-2); border-radius: var(--r-pill);
  background: var(--surface-2); color: var(--miss); border: 1px solid var(--border); vertical-align: middle; font-style: normal;
}

/* Buttons: chunky, outlined in ink, with a hard shadow that presses in. */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 52px; padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md);
  border: 2px solid var(--border-strong); background: var(--surface); color: var(--ink);
  font-weight: 800; font-size: var(--fs-md); line-height: 1.25; text-decoration: none; cursor: pointer; text-align: center;
  transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast), background var(--dur-fast);
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translate(1px, 2px) scale(0.98); }
.btn.primary {
  background: var(--accent); color: var(--accent-ink); border-color: var(--edge);
  box-shadow: var(--shadow-hard); font-style: italic; letter-spacing: 0.01em;
}
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--edge)); }
.btn.primary:active { box-shadow: 0 0 0 var(--edge); transform: translate(3px, 3px); }
.btn.good { background: var(--good-soft); border-color: var(--good); }
.btn.danger { background: var(--miss); color: var(--surface); border-color: var(--edge); }
.btn.danger-outline:not(.danger) { border-color: var(--miss); color: var(--miss); }
.danger-zone { border: 2px dashed var(--miss); }
.danger-zone .btn { justify-self: start; align-self: flex-start; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.wide { width: 100%; }
.btn.left { justify-content: flex-start; text-align: left; }
.btn.small-btn { min-height: 44px; padding: var(--sp-2) var(--sp-3); font-size: var(--fs-sm); }
.btn:disabled, .btn.primary:disabled {
  cursor: not-allowed; transform: none; box-shadow: none;
  background: var(--surface-2); color: var(--dim); border: 2px dashed var(--border-strong); font-style: normal;
}
.linkbtn {
  background: none; border: 0; padding: var(--sp-2) 0; min-height: 44px;
  color: var(--electric); font-weight: 800; cursor: pointer; font-size: var(--fs-sm); text-decoration: underline; text-underline-offset: 3px;
}

/* Segmented controls and switches */
.seg {
  display: inline-flex; background: var(--surface-2); border: 2px solid var(--border); border-radius: var(--r-md);
  padding: 3px; gap: 3px; margin-top: var(--sp-2); flex-wrap: wrap; max-width: 100%;
}
.seg-btn {
  border: 0; background: transparent; padding: var(--sp-2) var(--sp-3); min-height: 44px; border-radius: var(--r-sm);
  font-weight: 800; font-size: var(--fs-sm); cursor: pointer; color: var(--dim);
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.on { background: var(--ink); color: var(--bg); }
.seg.compact { margin-top: 0; }
.seg.compact .seg-btn { padding: var(--sp-2); font-size: var(--fs-xs); }
.switch-row { display: flex; align-items: center; gap: var(--sp-3); justify-content: space-between; min-height: 44px; cursor: pointer; }
.switch-row input {
  appearance: none; -webkit-appearance: none; flex: none; cursor: pointer;
  width: 52px; height: 30px; border-radius: var(--r-pill); background: var(--surface-2); border: 2px solid var(--border-strong);
  position: relative; transition: background var(--dur);
}
.switch-row input::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--dim); transition: transform var(--dur) var(--ease-pop), background var(--dur);
}
.switch-row input:checked { background: var(--accent); border-color: var(--edge); }
.switch-row input:checked::after { transform: translateX(22px); background: var(--accent-ink); }
.bar { height: 10px; background: var(--surface-2); border-radius: var(--r-pill); overflow: hidden; margin-top: var(--sp-2); border: 1.5px solid var(--border); }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: var(--r-pill); transition: width var(--dur-slow) var(--ease-out); }
.badge { font-size: var(--fs-xs); font-weight: 900; padding: 4px var(--sp-3); border-radius: var(--r-pill); background: var(--surface-2); border: 1.5px solid var(--border-strong); }
.badge.boss { background: var(--ink); color: var(--gold); border-color: var(--edge); }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--sp-5) + env(safe-area-inset-bottom)); transform: translate(-50%, 40px);
  background: var(--ink); color: var(--bg); padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); font-weight: 800; font-size: var(--fs-sm);
  opacity: 0; transition: opacity var(--dur), transform var(--dur) var(--ease-out); pointer-events: none; z-index: var(--z-toast); max-width: calc(100% - 32px);
  box-shadow: var(--shadow-hard);
}
body.has-tabs #toast { bottom: calc(var(--tabbar-h) + var(--sp-3) + env(safe-area-inset-bottom)); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 760px) { body.has-tabs #toast { bottom: var(--sp-5); } }

/* Speed lines: a radial burst used behind hero moments only. */
.speedlines { position: relative; isolation: isolate; overflow: hidden; }
.speedlines::before {
  content: ""; position: absolute; inset: -50%; z-index: -1; pointer-events: none;
  background: repeating-conic-gradient(from 0deg at 70% 50%, transparent 0deg 5deg, color-mix(in srgb, var(--accent) 10%, transparent) 5deg 7deg);
  mask-image: radial-gradient(circle at 70% 50%, transparent 0 18%, #000 55%);
  -webkit-mask-image: radial-gradient(circle at 70% 50%, transparent 0 18%, #000 55%);
}

/* ======================================================================
   Home / Today
   ====================================================================== */
.home { display: grid; gap: var(--sp-4); }
@media (min-width: 1000px) { .home { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: start; } .home-side { position: sticky; top: calc(var(--topbar-h) + var(--sp-4)); } }
.hero {
  background: var(--surface); border: 2px solid var(--ink); border-radius: var(--r-lg); padding: var(--sp-5) var(--sp-4) var(--sp-4);
  box-shadow: 4px 4px 0 var(--edge); display: flex; flex-direction: column; gap: var(--sp-3);
}
.hero-kicker { font-size: var(--fs-xs); font-weight: 900; letter-spacing: 0.14em; color: var(--accent); text-transform: uppercase; }
.hero-title { font-size: var(--fs-3xl); font-weight: 900; font-style: italic; line-height: 1; letter-spacing: -0.03em; }
.hero-title .jp-mark { font-family: var(--font-jp); font-style: normal; color: var(--accent); margin-right: var(--sp-2); }
.hero-next { display: flex; flex-direction: column; gap: var(--sp-2); }
.hero-next .btn { min-height: 60px; font-size: var(--fs-lg); }
.app-title { font-size: var(--fs-3xl); font-weight: 900; font-style: italic; letter-spacing: -0.03em; }
.meter-row { display: flex; align-items: center; gap: var(--sp-3); }
.pips { display: flex; gap: 6px; }
.pip { width: 26px; height: 10px; border-radius: 3px; background: var(--surface-2); border: 1.5px solid var(--border-strong); transform: skewX(-18deg); }
.pip.done { background: var(--good); border-color: var(--good); }
.pip.bonus { border-style: dashed; border-color: var(--gold); background: transparent; }
.pip.bonus.done { background: var(--gold); border-style: solid; }
.bonus-c { color: var(--bonus-ink); font-weight: 700; }
.tag.bonus-tag { border-color: var(--gold); color: var(--bonus-ink); }
.pip.skipped { background: repeating-linear-gradient(45deg, var(--surface-2) 0 3px, var(--border) 3px 6px); }
.hint { display: flex; align-items: center; gap: var(--sp-2); background: var(--surface-2); padding: var(--sp-3) var(--sp-4); }
.link-panel { text-decoration: none; color: inherit; }
.link-panel:hover { border-color: var(--border-strong); }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-2); }
.tile { display: flex; flex-direction: column; gap: 2px; padding: var(--sp-3); }
.summary .tile { background: var(--surface-2); border-radius: var(--r-md); }
.tile-v { font-size: var(--fs-2xl); font-weight: 900; font-style: italic; line-height: 1.1; }
.today { display: flex; flex-direction: column; gap: var(--sp-2); }
.summary { display: flex; flex-direction: column; gap: var(--sp-3); border: 2px solid var(--good); }
.block-row { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) 0; border-top: 1.5px solid var(--line); }
.block-check {
  flex: none; width: 38px; height: 38px; display: grid; place-items: center;
  background: var(--surface-2); border: 2px solid var(--border-strong); font-weight: 900; font-style: italic;
  clip-path: polygon(8% 0, 100% 0, 92% 100%, 0 100%); border-radius: 4px;
}
.block-row.next .block-check { background: var(--accent); color: var(--accent-ink); border-color: var(--edge); }
.block-row.done .block-check { background: var(--good); border-color: var(--good); color: var(--surface); }
.block-row.skipped { opacity: 0.7; }
.block-actions { display: flex; gap: var(--sp-2); flex-direction: column; }
@media (min-width: 520px) { .block-actions { flex-direction: row; } }
.mode-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-3); }
@media (min-width: 760px) { .mode-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1000px) { .mode-grid.wide { grid-template-columns: repeat(3, 1fr); } }
.mode-card { display: flex; gap: var(--sp-3); align-items: flex-start; text-decoration: none; color: var(--ink); transition: transform var(--dur-fast), box-shadow var(--dur-fast), border-color var(--dur-fast); }
.mode-card .strong.big + .small[lang="ja"] { white-space: nowrap; }   /* the Japanese name never breaks mid-word */
.mode-card:hover { border-color: var(--ink); box-shadow: var(--shadow-hard); transform: translate(-1px, -1px); }
.mode-icon {
  flex: none; width: 52px; height: 52px; display: grid; place-items: center;
  font-family: var(--font-jp); font-size: 1.7rem; font-weight: 900; color: var(--accent-ink);
  background: var(--accent); border: 2px solid var(--edge); border-radius: var(--r-md); box-shadow: 2px 2px 0 var(--edge);
  transform: rotate(-3deg);
}
.mode-card:nth-child(3n+2) .mode-icon { background: var(--ink); color: var(--gold); transform: rotate(2deg); }
.mode-card:nth-child(3n) .mode-icon { background: var(--gold); color: var(--edge); transform: rotate(-1deg); }
.chev { font-size: var(--fs-xl); align-self: center; }
.banner {
  display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); border-radius: var(--r-md);
  background: var(--surface-2); border: 2px solid var(--border-strong);
}
.banner.done { border-color: var(--good); background: var(--good-soft); }

/* Progress screen */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-3); }
@media (min-width: 760px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat-v { font-size: var(--fs-3xl); font-weight: 900; font-style: italic; line-height: 1; letter-spacing: -0.02em; }
.stat-of { font-size: var(--fs-md); color: var(--dim); font-style: normal; }
.hbars { display: flex; flex-direction: column; gap: var(--sp-2); }
.hbar { display: grid; grid-template-columns: 7.5rem 1fr 2.5rem; gap: var(--sp-2); align-items: center; font-size: var(--fs-sm); }
.hbar .bar { margin: 0; }
.hbar .bar > span { background: var(--good); }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
/* Desktop: the Garden and the month sit side by side, so the calendar stays a compact square. */
.progress-pair { display: grid; gap: var(--sp-4); }
@media (min-width: 760px) { .progress-pair { grid-template-columns: 1fr 1fr; align-items: start; } }
.cal-h { font-size: var(--fs-xs); color: var(--dim); text-align: center; font-weight: 800; }
.cal-d { aspect-ratio: 1; border-radius: var(--r-sm); display: grid; place-items: center; font-size: var(--fs-xs); font-weight: 700; color: var(--dim); background: var(--surface-2); }
.cal-d.on { background: var(--accent); color: var(--accent-ink); font-weight: 900; }
.cal-d.today { outline: 2px solid var(--ink); outline-offset: -2px; }
.cal-d.empty { background: transparent; }

/* ======================================================================
   Garden
   ====================================================================== */
.hero-jp { font-family: var(--font-jp); font-size: var(--fs-jp-xl); font-weight: 900; line-height: 1.1; }
.plant-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: var(--sp-2); }
.plant { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--r-md); min-height: 88px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: var(--sp-2) var(--sp-1); min-width: 0; }
.plant-emoji { font-size: 2rem; position: relative; }
.drop { position: absolute; font-size: var(--fs-sm); right: -12px; top: -4px; }
.plant-jp { font-size: var(--fs-sm); font-weight: 700; max-width: 100%; font-family: var(--font-jp); text-align: center; line-height: var(--lh-ruby); }
.plant-jp.long { font-size: var(--fs-xs); letter-spacing: -0.02em; }
.card-review { display: flex; flex-direction: column; align-items: center; gap: var(--sp-4); text-align: center; min-height: calc(100dvh - 240px); padding-top: var(--sp-3); max-width: 560px; margin: 0 auto; width: 100%; }
.card-review .row2 { width: 100%; }
.review-jp { font-family: var(--font-jp); font-size: var(--fs-jp-xl); font-weight: 900; word-break: break-word; margin-top: 6vh; line-height: 1.3; }
.card-review .n5-ex { width: 100%; display: flex; flex-direction: column; align-items: center; gap: var(--sp-1); }
.card-review .n5-ex p { margin: 0; }
.card-review .n5-pitch { display: flex; justify-content: center; }

/* ======================================================================
   Story
   ====================================================================== */
.title-jp { font-family: var(--font-jp); font-size: var(--fs-2xl); font-weight: 900; line-height: 1.4; }
.chapter-row { display: flex; align-items: center; gap: var(--sp-3); text-align: left; cursor: pointer; width: 100%; }
.chapter-row:not(:disabled):hover { border-color: var(--ink); }
.chapter-row:disabled { opacity: 0.6; cursor: not-allowed; }
.chapter-row .strong { font-family: var(--font-jp); }
.ch-num {
  width: 44px; height: 44px; border-radius: var(--r-sm); display: grid; place-items: center; flex: none;
  background: var(--accent); color: var(--accent-ink); font-weight: 900; font-style: italic; font-size: var(--fs-xl);
  border: 2px solid var(--edge); transform: rotate(-3deg);
}
.ch-num.locked { background: var(--surface-2); color: var(--dim); border-color: var(--border-strong); }
.speaker-row { display: flex; align-items: center; gap: var(--sp-3); }
.avatar { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 900; font-size: var(--fs-lg); flex: none; font-family: var(--font-jp); border: 2px solid var(--edge); }
.chip-toggle { min-height: 44px; padding: var(--sp-1) var(--sp-3); border-radius: var(--r-md); border: 2px solid var(--border-strong); background: var(--surface); font-weight: 800; font-size: var(--fs-sm); cursor: pointer; font-family: var(--font-jp); }
.chip-toggle.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.line-card {
  display: flex; flex-direction: column; gap: var(--sp-2); text-align: left; width: 100%; padding: var(--sp-4) var(--sp-4) var(--sp-3);
  border: 2px solid var(--ink); border-radius: 4px var(--r-lg) var(--r-lg) var(--r-lg); box-shadow: var(--shadow-hard);
}
.reading { font-size: var(--fs-sm); font-family: var(--font-jp); }
.line-jp { font-family: var(--font-jp); font-size: var(--fs-jp-lg); font-weight: 800; line-height: 1.45; word-break: break-word; }
.chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.chip { min-height: 44px; padding: var(--sp-1) var(--sp-4); border-radius: var(--r-pill); border: 1.5px solid var(--border-strong); background: var(--accent-soft); font-weight: 800; cursor: pointer; font-family: var(--font-jp); font-size: var(--fs-md); }
.word-list { display: flex; flex-direction: column; gap: var(--sp-2); }
.word-row { display: flex; gap: var(--sp-3); align-items: baseline; flex-wrap: wrap; }
.w110 { width: 110px; }
.review-sound { display: inline-flex; align-items: center; gap: var(--sp-2); }
.review-row { align-items: center; }
.review-row .w110 { width: 110px; }
.review-sound .melody { width: auto; max-width: 140px; }

/* ======================================================================
   Particle Train
   ====================================================================== */
.train-scroll { overflow-x: auto; overflow-y: hidden; padding: var(--sp-3) 2px; -webkit-overflow-scrolling: touch; }
.train { display: flex; align-items: flex-start; width: max-content; transition: transform 0.9s ease-in, opacity 0.9s; }
.train.departed { transform: translateX(110vw); opacity: 0.2; }
.train.shake { animation: shake 0.35s; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(8px); } 50% { transform: translateX(-6px); } 75% { transform: translateX(4px); } }
.car { display: flex; flex-direction: column; align-items: center; gap: var(--sp-1); }
.car-body {
  display: grid; place-items: center; min-height: 56px; padding: var(--sp-1) var(--sp-3); border-radius: var(--r-sm);
  background: var(--ink); color: var(--bg); font-family: var(--font-jp); font-size: var(--fs-xl); font-weight: 800; white-space: nowrap;
  border: 2px solid var(--edge); line-height: var(--lh-ruby);
}
.car-body.engine { background: var(--accent); color: var(--accent-ink); border-radius: var(--r-lg) var(--r-sm) var(--r-sm) var(--r-sm); }
.car-body rt { color: inherit; opacity: 0.8; }
.wheels { display: flex; gap: 18px; }
.wheels i { width: 12px; height: 12px; border-radius: 50%; background: var(--ink); border: 2px solid var(--surface); }
.coupling {
  width: 48px; height: 48px; margin-top: 4px; border-radius: 50%; border: 2px dashed var(--border-strong); background: var(--surface);
  font-size: var(--fs-xl); font-weight: 900; color: var(--dim); cursor: pointer; flex: none; font-family: var(--font-jp);
}
.coupling.active { border: 3px solid var(--accent); color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); animation: glow 1.4s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 0 8px var(--accent-soft); } }
.coupling.filled { color: var(--good); border: 3px solid var(--good); }
.link-bar { width: 16px; height: 4px; background: var(--ink); margin-top: 26px; flex: none; }
.particle-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--sp-2); }
.btn.particle { font-family: var(--font-jp); font-size: var(--fs-2xl); font-weight: 900; padding: var(--sp-1) 0; min-height: 60px; line-height: var(--lh-ruby); }

/* ======================================================================
   Kanji Forge
   ====================================================================== */
.forge-meaning { font-size: var(--fs-3xl); font-weight: 900; font-style: italic; letter-spacing: -0.02em; }
.anvil {
  min-height: 140px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-2); text-align: center;
  background: var(--surface-2); border: 2px solid var(--ink); border-radius: var(--r-lg) var(--r-lg) 4px 4px;
}
.anvil-row { display: flex; gap: var(--sp-2); flex-wrap: wrap; justify-content: center; align-items: center; min-height: 90px; }
.forged-k { font-family: var(--font-jp); font-size: 6.5rem; font-weight: 900; color: var(--accent); line-height: 1.3; text-shadow: 3px 3px 0 var(--edge); animation: pop var(--dur-slow) var(--ease-pop); }
@keyframes pop { from { transform: scale(0.3) rotate(-12deg); opacity: 0; } to { transform: none; opacity: 1; } }
.part-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-2); }
.part {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 84px; min-width: 0;
  border-radius: var(--r-md); border: 2px solid var(--border-strong); background: var(--surface); cursor: pointer; padding: var(--sp-1);
}
.part:hover { border-color: var(--ink); }
.part.hi { background: var(--accent); color: var(--accent-ink); border-color: var(--edge); box-shadow: 2px 2px 0 var(--edge); }
.part.hi rt { color: inherit; opacity: 0.85; }
.part-k { font-size: 1.9rem; font-weight: 800; line-height: var(--lh-ruby); font-family: var(--font-jp); }
.part-n { font-size: var(--fs-xs); color: inherit; opacity: 0.8; }
.forge-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: var(--sp-2); }
.forge-k { font-family: var(--font-jp); font-size: var(--fs-2xl); font-weight: 800; text-align: center; padding: var(--sp-1) 0; border-radius: var(--r-sm); line-height: var(--lh-ruby); }

/* ======================================================================
   Rhythm
   ====================================================================== */
.rhythm-display { font-family: var(--font-jp); font-size: var(--fs-jp-lg); font-weight: 800; line-height: 1.5; }
.track-wrap { width: 100%; }
canvas.track { width: 100%; height: 230px; display: block; border-radius: var(--r-lg); border: 2px solid var(--ink); }
.score-big { font-size: var(--fs-4xl); font-weight: 900; font-style: italic; line-height: 1; }

/* ======================================================================
   Pitch Duel
   ====================================================================== */
.duel-opt { display: flex; align-items: center; gap: var(--sp-3); width: 100%; cursor: pointer; border-width: 3px; border-color: var(--border-strong); }
.duel-opt:not(:disabled):hover { border-color: var(--ink); }
.duel-opt.correct { border-color: var(--good); background: var(--good-soft); }
.duel-opt:disabled { cursor: default; }
.duel-label { width: 64px; flex: none; font-size: var(--fs-xl); font-weight: 900; font-style: italic; text-align: center; }
.duel-label.emoji { font-size: 2.4rem; font-style: normal; }
svg.melody { width: 100%; display: block; }
.melody-kana { font-size: 18px; font-weight: 700; fill: var(--ink); font-family: var(--font-jp); }
.melody-romaji { font-size: 11px; font-weight: 600; fill: var(--dim); font-family: var(--font-ui); }

/* ======================================================================
   Speak Slice
   ====================================================================== */
.mode-slice { padding-bottom: var(--sp-2); }
.slice-wrap { display: flex; flex-direction: column; gap: var(--sp-2); height: calc(100dvh - 200px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); min-height: 430px; }
.slice-hud { display: flex; flex-direction: column; gap: var(--sp-1); }
.score { font-size: var(--fs-2xl); font-weight: 900; font-style: italic; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--miss); flex: none; }
.dot.on { background: var(--good); }
.reveal { text-align: center; padding: var(--sp-2); }
.playfield {
  position: relative; flex: 1; overflow: hidden; border-radius: var(--r-lg); background: var(--surface-2); border: 2px solid var(--ink);
  touch-action: manipulation; min-height: 240px;
}
.flyer {
  position: absolute; left: 0; top: 0; will-change: transform;
  width: 124px; min-height: 80px; padding: var(--sp-2); border-radius: var(--r-lg); border: 2px solid var(--edge); cursor: pointer;
  background: var(--ink); color: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  box-shadow: 3px 3px 0 var(--accent); font-weight: 800; font-size: var(--fs-md); text-align: center;
}
.flyer.emoji { width: 92px; min-height: 92px; border-radius: 50%; }
.flyer.emoji .flyer-prompt { font-size: 2.9rem; line-height: 1; }
.flyer.focus { outline: 4px solid var(--gold); outline-offset: 3px; }
.flyer-hint { color: var(--gold); font-weight: 900; font-size: var(--fs-md); font-family: var(--font-jp); }
.flyer.sliced { background: transparent; box-shadow: none; border-color: transparent; pointer-events: none; }
.sliced-text { font-family: var(--font-jp); font-size: 2.4rem; font-weight: 900; color: var(--accent); white-space: nowrap; text-shadow: 2px 2px 0 var(--edge); }
.slash { position: absolute; width: 140px; height: 4px; background: var(--ink); transform: rotate(-25deg); box-shadow: 0 0 0 2px var(--surface); }
.slice-controls { display: flex; flex-direction: column; gap: var(--sp-1); }
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); }
.score-huge { font-size: 4rem; font-weight: 900; font-style: italic; line-height: 1; letter-spacing: -0.03em; }

/* ======================================================================
   Shopkeeper
   ====================================================================== */
.customer { display: flex; gap: var(--sp-3); align-items: flex-start; border: 2px solid var(--ink); border-radius: 4px var(--r-lg) var(--r-lg) var(--r-lg); }
.customer .lead { font-family: var(--font-jp); line-height: var(--lh-ruby); }
.cust-emoji { font-size: 3.2rem; line-height: 1; }
.shop-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-2); }
.shop-item { display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 84px; cursor: pointer; padding: var(--sp-2) var(--sp-1); line-height: var(--lh-ruby); }
.shop-item:hover { border-color: var(--ink); }
.shop-emoji { font-size: 2rem; line-height: 1.2; }
.counter-row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); background: var(--surface-2); border-style: dashed; border-color: var(--border-strong); }
.counter-items { font-size: var(--fs-2xl); word-break: break-all; }
.mode-shop p[lang="ja"] { line-height: var(--lh-ruby); }

/* ======================================================================
   Settings and sound check
   ====================================================================== */
textarea {
  width: 100%; font: var(--fs-sm)/1.4 var(--font-mono); padding: var(--sp-3); border-radius: var(--r-md);
  border: 2px solid var(--border-strong); background: var(--surface-2); color: var(--ink); resize: vertical;
}
.text-input {
  /* 16px or more, or iPhone Safari zooms the page when the field is tapped. */
  width: 100%; min-height: 44px; font: max(16px, 1rem)/1.4 var(--font-mono); padding: var(--sp-2) var(--sp-3); border-radius: var(--r-md);
  border: 2px solid var(--border-strong); background: var(--surface-2); color: var(--ink);
}
/* A calm note (sync couldn't run this time): plain text on a soft panel, not an error colour. */
.note-c { padding: var(--sp-2) var(--sp-3); border-radius: var(--r-md); background: var(--surface-2); border-left: 4px solid var(--border-strong); color: var(--ink); }
.filebtn { cursor: pointer; }
.filebtn:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
details summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; }
details ul { padding-left: 18px; margin: var(--sp-1) 0 0; }
/* A long list folded to one line (Reading Dojo tracks, Course phases, Story arcs); only the current one starts open. */
.fold > summary { color: var(--electric); gap: var(--sp-2); list-style: none; }
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::before { content: "›"; display: inline-block; font-size: 1.25em; line-height: 1; transition: transform var(--dur-fast); }
.fold[open] > summary::before { transform: rotate(90deg); }
.fold[open] > summary { margin-bottom: var(--sp-2); }
.how-to { text-align: left; }
.how-to summary { color: var(--electric); }
.center-text .how-to summary { justify-content: center; }
input[type="range"] { width: 100%; accent-color: var(--accent); min-height: 44px; }
.calib { display: flex; flex-direction: column; gap: var(--sp-3); align-items: center; }
.calib-dot { width: 56px; height: 56px; border-radius: 50%; background: var(--surface-2); border: 3px solid var(--accent); transition: background 0.06s; }
.calib-dot.flash { background: var(--accent); }
.tapbtn { min-height: 90px; font-size: var(--fs-lg); }
.settings-grid { display: grid; gap: var(--sp-4); }
@media (min-width: 1000px) { .settings-grid { grid-template-columns: 1fr 1fr; align-items: start; } .settings-grid > .full { grid-column: 1 / -1; } }
.text-preview { font-family: var(--font-jp); font-size: var(--fs-jp-md); line-height: var(--lh-ruby); }
.meter { height: 14px; border-radius: 7px; background: var(--surface-2); border: 1.5px solid var(--border-strong); overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: var(--good); transition: width 0.08s linear; }
.panel ul { margin: var(--sp-1) 0 0; padding-left: 20px; }
.btn.primary rt, .seg-btn.on rt, .chip-toggle.on rt, .ch-num rt, .mode-icon rt { color: inherit; opacity: 0.85; }
.slow-toggle { font-size: 1.25rem; filter: grayscale(1); opacity: 0.6; }
/* On: an accent outline and icon, not a fill, so it doesn't outshout the screen title. */
.slow-toggle.on { filter: none; opacity: 1; border-color: var(--accent); color: var(--accent); }
/* Phones: the quiet badge is just its icon, so the screen title has room. */
@media (max-width: 759px) {
  .quiet-badge .quiet-word { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .quiet-badge { padding: 2px 6px; }
  .quiet-badge .ico { margin-right: 0; }
}

/* ======================================================================
   Reading help (romaji / furigana). Readings get their own line space so they never overlap other text.
   ====================================================================== */
ruby { ruby-position: over; ruby-align: center; white-space: nowrap; }   /* a word never breaks under its romaji; lines wrap between words */
.jr { overflow-wrap: anywhere; }   /* lines can still break between words that each keep their romaji */
.wsp { display: inline-block; width: 0.3em; }   /* the gap between romaji words (no text, so copying stays plain Japanese) */
.jw { display: inline-block; max-width: 100%; text-indent: 0; }   /* one word of several rubies (がくせい|です|か): Safari never breaks inside it */
rt {
  font-size: 0.5em; font-weight: 600; color: var(--dim); font-family: var(--font-ui); font-style: normal;
  letter-spacing: 0; line-height: 1; user-select: none; -webkit-user-select: none;
}
.jr { line-height: var(--lh-ruby); }
.review-jp .jr, .line-jp .jr, .rhythm-display .jr, .hero-jp .jr, .title-jp .jr { line-height: 1.6; }
.ruby-toggle { font-family: var(--font-jp); font-weight: 800; font-size: var(--fs-sm); width: auto; padding: 0 var(--sp-3); border: 2px solid var(--border-strong); }
.ruby-toggle.off { opacity: 0.5; text-decoration: line-through; }
/* Elements whose text gets readings need room above the first line too. */
.btn:has(ruby), .seg-btn:has(ruby), .chip:has(ruby), .tab:has(ruby), .badge:has(ruby) { line-height: var(--lh-ruby); }
p:has(> .jr), .small:has(> .jr), .lead:has(> .jr), .strong:has(> .jr), span:has(> .jr), .tiny:has(> .jr) { line-height: var(--lh-ruby); }

/* ======================================================================
   Reading Dojo
   ====================================================================== */
.lesson-list { display: grid; gap: var(--sp-2); }
@media (min-width: 760px) { .lesson-list { grid-template-columns: 1fr 1fr; } }
.lesson-row { display: flex; align-items: center; gap: var(--sp-3); text-align: left; cursor: pointer; width: 100%; color: inherit; font: inherit; }
.lesson-row:hover { border-color: var(--ink); }
.lesson-row.cleared .ch-num { background: var(--good); color: var(--surface); }
.lesson-row.next { border: 2px solid var(--accent); box-shadow: 3px 3px 0 var(--accent); }
.lesson-row:not(.cleared):not(.next) .ch-num { background: var(--surface-2); color: var(--ink); border-color: var(--border-strong); }
.lesson-preview { font-family: var(--font-jp); color: var(--dim); font-size: var(--fs-md); letter-spacing: 0.08em; }
.kana-chart { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--sp-1); margin-top: var(--sp-1); }
.kana-cell { display: grid; justify-items: center; gap: 2px; padding: var(--sp-2) 2px; border-radius: var(--r-sm); border: 1.5px solid var(--border); background: var(--surface); cursor: pointer; color: var(--dim); }
.kana-cell.known { color: var(--ink); border: 2px solid var(--good); background: var(--good-soft); }
.kc-k { font-family: var(--font-jp); font-size: 1.7rem; font-weight: 700; line-height: 1.2; }
.kc-r { font-size: var(--fs-xs); font-family: var(--font-mono); }
.learn-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--sp-2); }
.learn-card { display: grid; justify-items: center; gap: var(--sp-1); text-align: center; cursor: pointer; color: inherit; font: inherit; }
.learn-card:hover { border-color: var(--ink); }
.learn-k { font-family: var(--font-jp); font-size: 4rem; font-weight: 700; line-height: 1.15; }
.learn-k.pre-word { font-size: 1.9rem; }
.learn-card > * { max-width: 100%; overflow-wrap: anywhere; }
.quiz { max-width: 640px; margin: 0 auto; width: 100%; }
.quiz-prompt { font-family: var(--font-jp); font-size: clamp(4rem, 18vw, 7rem); font-weight: 800; text-align: center; line-height: 1.15; padding: var(--sp-2) 0; }
.quiz-prompt.latin { font-family: var(--font-mono); font-size: clamp(2.75rem, 12vw, 4.5rem); }
.quiz-listen { font-size: var(--fs-xl); min-height: 96px; width: 100%; }
.quiz-opts .btn { min-height: 68px; font-size: var(--fs-xl); gap: var(--sp-2); }
.quiz-opts .btn .tiny { opacity: 0.7; }
.opt-k { font-family: var(--font-jp); font-size: 1.9rem; font-weight: 700; }
.btn.wrong { background: var(--miss-soft); border-color: var(--miss); }
.btn.faded { opacity: 0.6; }
.btn.good:disabled, .btn.wrong:disabled, .btn.faded:disabled { cursor: default; border-style: solid; }
.btn.good:disabled { background: var(--good-soft); border-color: var(--good); color: var(--ink); }
.btn.wrong:disabled { background: var(--miss-soft); border-color: var(--miss); color: var(--ink); }
.btn.faded:disabled { background: var(--surface); color: var(--ink); border-color: var(--border); }
.good-panel { background: var(--good-soft); }

/* ======================================================================
   Game feel: hit bursts, gentle misses, the end-of-day reward
   ====================================================================== */
.fx-layer { position: fixed; inset: 0; pointer-events: none; z-index: var(--z-overlay); overflow: hidden; }
.fx-burst {
  position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px;
  background: var(--gold); border: 0;
  clip-path: polygon(50% 0, 61% 33%, 98% 22%, 70% 50%, 100% 75%, 62% 68%, 50% 100%, 38% 68%, 2% 78%, 30% 50%, 0 22%, 39% 33%);
  animation: burst 420ms var(--ease-out) forwards;
}
.fx-burst::after { content: ""; position: absolute; inset: 22%; background: var(--accent); clip-path: inherit; }
.fx-burst.big { width: 220px; height: 220px; margin: -110px 0 0 -110px; }
@keyframes burst { 0% { transform: scale(0.2) rotate(-20deg); opacity: 1; } 60% { opacity: 1; } 100% { transform: scale(1.25) rotate(8deg); opacity: 0; } }
.fx-lines {
  position: absolute; inset: -40%;
  background: repeating-conic-gradient(from 0deg at var(--x, 50%) var(--y, 50%), transparent 0deg 4deg, color-mix(in srgb, var(--ink) 18%, transparent) 4deg 5.5deg);
  mask-image: radial-gradient(circle at var(--x, 50%) var(--y, 50%), transparent 0 14%, #000 40%);
  -webkit-mask-image: radial-gradient(circle at var(--x, 50%) var(--y, 50%), transparent 0 14%, #000 40%);
  animation: lines 480ms ease-out forwards;
}
@keyframes lines { from { opacity: 0.9; transform: scale(1.1); } to { opacity: 0; transform: scale(1); } }
.fx-nudge { animation: nudge 360ms ease-in-out; }
@keyframes nudge { 0%, 100% { transform: translateX(0); } 30% { transform: translateX(-4px); } 60% { transform: translateX(3px); } }
.fx-pop { animation: fxpop 300ms var(--ease-pop); }
@keyframes fxpop { from { transform: scale(0.94); } to { transform: none; } }

.reward {
  position: fixed; inset: 0; z-index: var(--z-overlay); display: grid; place-items: center; padding: var(--sp-4);
  background: var(--scrim); animation: enter-fade var(--dur) var(--ease-out);
}
.reward-card {
  position: relative; isolation: isolate; overflow: hidden; width: min(440px, 100%);
  background: var(--surface); color: var(--ink); border: 3px solid var(--ink); border-radius: var(--r-lg); box-shadow: 6px 6px 0 var(--edge);
  padding: var(--sp-6) var(--sp-5) var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-4); text-align: center;
  animation: reward-in var(--dur-slow) var(--ease-pop);
}
.reward-card::before {
  content: ""; position: absolute; inset: -60%; z-index: -1;
  background: repeating-conic-gradient(from 0deg, var(--gold) 0deg 6deg, transparent 6deg 12deg);
  opacity: 0.22; animation: spin 18s linear infinite;
}
.reward-kicker { font-size: var(--fs-xs); font-weight: 900; letter-spacing: 0.16em; color: var(--accent); }
.reward-title {
  font-family: var(--font-jp); font-size: clamp(2.2rem, 10vw, 3rem); font-weight: 900; line-height: 1.5;
  display: inline-block; align-self: center; padding: 0 var(--sp-3);
  background: var(--ink); color: var(--gold); transform: rotate(-3deg) skewX(-6deg); box-shadow: 4px 4px 0 var(--accent);
}
.reward-title rt { color: var(--bg); }
.reward .tiles .tile { background: var(--surface-2); border-radius: var(--r-md); border: 1.5px solid var(--border); }
@keyframes reward-in { from { transform: scale(0.6) rotate(-6deg); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ======================================================================
   Small phones and reduced motion
   ====================================================================== */
@media (max-width: 380px) {
  .tiles { gap: var(--sp-1); }
  .tile-v { font-size: var(--fs-xl); }
  .row3 .btn { padding: var(--sp-2) var(--sp-1); font-size: var(--fs-sm); }
  .part-grid { gap: var(--sp-1); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  .fx-burst, .fx-lines { display: none; }
}

/* ======================================================================
   Learning engine: Progress charts, placement check, weekly check-in
   ====================================================================== */
.chart { display: block; width: 100%; max-width: 480px; height: auto; overflow: visible; font-family: var(--font-ui); }
.chart text { font-size: 12.5px; }
.chart .ch-label { fill: var(--ink); font-weight: 600; }
.chart .ch-val { fill: var(--dim); font-family: var(--font-mono); font-size: 12px; }
.chart .ch-note { fill: var(--dim); font-size: 10.5px; }
.chart .ch-inval { fill: var(--accent-ink); font-family: var(--font-mono); font-size: 12px; font-weight: 800; }
.chart .ch-track { fill: var(--surface-2); }
.chart .ch-bar { fill: var(--accent); }
.chart .ch-grid { stroke: var(--line); stroke-width: 1; }
.chart .ch-ref { stroke: var(--ink); stroke-width: 1.5; stroke-dasharray: 4 3; opacity: 0.7; }
.chart .ch-row:hover .ch-bar { opacity: 0.8; }
.engine-card { display: flex; flex-direction: column; gap: var(--sp-2); }
/* Only a weekly check-in with something to say gets a coloured edge; other cards stay plain so the next step stands out. */
.checkin { border-left: 4px solid var(--electric); }
.engine-card .hero-kicker { margin: 0; }
.checkin.low { border-left-color: var(--miss); }
.checkin.high { border-left-color: var(--good); }
.placement { max-width: 560px; margin-inline: auto; width: 100%; }
.placement-k { padding: var(--sp-3) 0; }
.placement-opts { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); }
.placement-opts .btn { font-size: var(--fs-lg); font-weight: 800; min-height: 3.25rem; }
.placement-reveal { text-align: center; font-size: var(--fs-lg); }
.placement-list { margin: 0; padding-left: var(--sp-5); }
   Story saga: chapter map, comprehension questions, Paste a line
   ====================================================================== */
.saga-progress { display: flex; align-items: center; gap: var(--sp-3); }
.saga-progress .bar { flex: 1; margin-top: 0; }
.saga-mine { display: flex; align-items: center; gap: var(--sp-3); width: 100%; text-align: left; cursor: pointer; font: inherit; }
.saga-path { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
/* The path: a connector between chapters, dashed ahead of you and solid once the chapter before it is cleared. */
.saga-node + .saga-node::before {
  content: ""; display: block; width: 4px; height: var(--sp-4); margin-left: calc(var(--sp-4) + 20px);
  background: repeating-linear-gradient(to bottom, var(--border-strong) 0 4px, transparent 4px 8px);
}
.saga-node.cleared + .saga-node::before { background: var(--good); }
.saga-node.cleared .ch-num { background: var(--good); color: var(--surface); }
.saga-node.next .chapter-row { border: 2px solid var(--accent); box-shadow: 3px 3px 0 var(--accent); }
.saga-node.locked .chapter-row { border-style: dashed; }
.saga-next { font-size: var(--fs-xs); font-weight: 900; font-style: italic; color: var(--accent); letter-spacing: 0.08em; white-space: nowrap; }
.saga-card { display: flex; flex-direction: column; gap: var(--sp-2); }
.saga-card .chapter-row { cursor: default; }
.saga-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.saga-actions .btn { flex: 1 1 140px; }
.saga-results { margin: 0; }
.saga-challenge-tag { color: var(--ink); font-size: var(--fs-sm); padding: var(--sp-1) var(--sp-3); }
.saga-quote { display: flex; align-items: center; gap: var(--sp-3); background: var(--surface-2); }
.saga-quote-jp { font-family: var(--font-jp); font-size: var(--fs-jp-md); font-weight: 700; line-height: var(--lh-ruby); }
.saga-feedback.ok { border-color: var(--good); background: var(--good-soft); }
.saga-feedback.missed { border-color: var(--miss); background: var(--miss-soft); }
.saga-feedback p { margin: 0; }
.saga-score { display: flex; align-items: center; gap: var(--sp-4); }
.saga-quiz .section-label, .saga-quiz .section-title { margin: 0; }
@media (min-width: 760px) {
  .saga-path { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
  .saga-node + .saga-node::before { display: none; }
}

.mine-input {
  width: 100%; font: var(--fs-jp-md)/1.4 var(--font-jp); padding: var(--sp-3); border-radius: var(--r-md);
  border: 2px solid var(--border-strong); background: var(--surface); color: var(--ink);
}
.mine-tokens { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: flex-end; }
.mine-tok { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; }
.mine-tok.kanji { padding: var(--sp-1); border-radius: var(--r-sm); border: 2px solid var(--border-strong); background: var(--surface-2); }
.mine-tok.kanji.unknown { border-color: var(--accent); background: var(--accent-soft); }
.mine-k { font-family: var(--font-jp); font-size: var(--fs-jp-md); font-weight: 800; line-height: 1.3; }
.mine-r { font-family: var(--font-jp); font-size: var(--fs-xs); color: var(--dim); }
.mine-reading {
  font: var(--fs-sm)/1.2 var(--font-jp); min-height: 36px; max-width: 9rem; padding: var(--sp-1) var(--sp-2); text-align: center;
  border-radius: var(--r-sm); border: 1.5px solid var(--border-strong); background: var(--surface); color: var(--ink);
}
.mine-row { display: flex; align-items: center; gap: var(--sp-3); }
.mine-line { font-family: var(--font-jp); font-size: var(--fs-jp-md); font-weight: 700; line-height: var(--lh-ruby); word-break: break-word; }
.mine-acts { display: flex; flex-direction: column; align-items: flex-end; gap: var(--sp-1); }
   Course: lesson path, units, grammar reference (js/course.js)
   ====================================================================== */
.course .section-title { line-height: var(--lh-tight); }
.course-card { display: flex; gap: var(--sp-3); align-items: flex-start; border: 2px solid var(--accent); }
.course-card .mode-icon { background: var(--accent); color: var(--accent-ink); }
.course-progress { margin-top: var(--sp-1); }
.course-progress .small { margin-top: var(--sp-1); }
.course-now { border: 2px solid var(--accent); box-shadow: 3px 3px 0 var(--accent); }
.unit-row { text-decoration: none; }
.unit-row .strong { font-size: var(--fs-lg); }
.unit-row.outline { cursor: default; opacity: 0.85; }
.unit-row.outline .ch-num { background: var(--surface-2); color: var(--dim); border-color: var(--border-strong); }
.tag.good { color: var(--good); }
.unit-head .tag { margin-left: var(--sp-1); }
.gp-title { font-size: var(--fs-lg); font-weight: 800; }
.gp-pattern { font-family: var(--font-jp); font-size: var(--fs-jp-md); font-weight: 700; color: var(--accent); line-height: var(--lh-ruby); overflow-wrap: anywhere; }
.ex-list { display: flex; flex-direction: column; gap: var(--sp-2); }
.ex-row { display: flex; gap: var(--sp-3); align-items: flex-start; padding-top: var(--sp-2); border-top: 1px solid var(--line); }
.ex-play { flex: none; }
.ex-jp { font-family: var(--font-jp); font-size: var(--fs-jp-md); font-weight: 700; line-height: var(--lh-ruby); overflow-wrap: anywhere; }
.ex-reading { font-family: var(--font-jp); }
.melody-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--sp-2); }
.melody-item { display: flex; flex-direction: column; align-items: center; gap: var(--sp-1); cursor: pointer; padding: var(--sp-2); font: inherit; color: inherit; }
.melody-item .melody { max-width: 100%; }
.search-row { display: block; }
.search {
  width: 100%; min-height: 52px; padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md);
  border: 2px solid var(--border-strong); background: var(--surface); color: var(--ink); font: inherit; font-size: var(--fs-md);
}
.course-banner .grow { min-width: 0; }
.word-melodies { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--sp-2); }
.word-item { text-align: center; }
.word-item .tiny { line-height: 1.3; }
.course .row-between.wrap-gap > .switch-row { flex: 1 1 220px; }
   New practice modes: Listening Lab, Conjugation Dojo, Sentence Builder, Katakana Rush, Numbers & Time
   ====================================================================== */
.practice { max-width: 680px; margin: 0 auto; width: 100%; }
.practice-opts .btn { min-height: 60px; font-size: var(--fs-lg); line-height: var(--lh-ruby); }
.practice-opts .btn[lang="ja"] { font-family: var(--font-jp); font-size: var(--fs-jp-md); font-weight: 800; }
.practice p[lang="ja"] { line-height: var(--lh-ruby); }
/* Listening Lab and Numbers & Time */
.listen-stage { display: flex; gap: var(--sp-3); align-items: center; border: 2px solid var(--ink); }
.listen-scene { font-size: 3rem; line-height: 1; flex: none; }
.transcript { gap: var(--sp-2); }
.t-line { display: flex; gap: var(--sp-2); align-items: flex-start; }
.t-line + .t-line { border-top: 1.5px solid var(--line); padding-top: var(--sp-2); }
.t-play { flex: none; font-size: 1.1rem; width: 44px; height: 44px; }
.t-jp { font-family: var(--font-jp); font-size: var(--fs-jp-md); font-weight: 700; word-break: break-word; }
/* Conjugation Dojo */
.conj-card { border: 2px solid var(--ink); box-shadow: 4px 4px 0 var(--edge); }
.conj-word { font-family: var(--font-jp); font-size: var(--fs-jp-xl); font-weight: 900; line-height: 1.5; word-break: break-word; }
.conj-form { font-size: var(--fs-xl); font-weight: 900; font-style: italic; color: var(--accent); }
/* Sentence Builder */
.build-prompt { display: flex; gap: var(--sp-3); align-items: center; }
.build-scene { font-size: 2.6rem; line-height: 1; flex: none; }
.tile-row { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; min-height: 64px; }
.answer-row { padding: var(--sp-2); border: 2px dashed var(--border-strong); border-radius: var(--r-md); background: var(--surface-2); }
.answer-row.is-right { border: 2px solid var(--good); background: var(--good-soft); }
.answer-row.is-wrong { border: 2px solid var(--miss); background: var(--miss-soft); }
.word-tile {
  min-height: 48px; padding: var(--sp-1) var(--sp-3); border-radius: var(--r-sm); border: 2px solid var(--ink);
  background: var(--surface); color: var(--ink); font-family: var(--font-jp); font-size: var(--fs-jp-md); font-weight: 800;
  box-shadow: 2px 2px 0 var(--edge); cursor: pointer; line-height: var(--lh-ruby); max-width: 100%; word-break: break-word;
}
.word-tile:hover { border-color: var(--accent); }
.word-tile.placed { background: var(--accent-soft); }
.word-tile:disabled { cursor: default; box-shadow: none; }
.build-answer { font-family: var(--font-jp); font-size: var(--fs-jp-lg); font-weight: 800; word-break: break-word; }
/* Garden card directions, grammar cards and help (js/modes/garden.js) */
.card-head { width: 100%; gap: var(--sp-2); }
.card-dir { font-weight: 800; }
.card-dir-listen { border-color: var(--accent); }
.card-dir-say { border-color: var(--good); }
.card-dir-grammar, .card-dir-conj { border-color: var(--border-strong); }
.listen-orb { font-size: 3.2rem; line-height: 1; margin-top: 4vh; }
.say-en { font-size: var(--fs-2xl); font-weight: 900; line-height: 1.25; margin: var(--sp-2) 0 0; word-break: break-word; }
.gram-show { font-family: var(--font-jp); font-size: var(--fs-jp-lg); font-weight: 800; line-height: var(--lh-ruby); word-break: break-word; margin: var(--sp-2) 0 0; }
.card-gram .choice-grid { width: 100%; }
.card-gram .note { width: 100%; }
.key-hint { display: none; font-size: var(--fs-xs, 0.75rem); opacity: 0.6; font-family: var(--font-mono); margin-right: 2px; }
@media (hover: hover) and (pointer: fine) { .key-hint { display: inline; } }
.help-panel .help-jp { margin-top: 0; }
.mnemonic { font-size: var(--fs-lg); font-weight: 700; line-height: 1.4; margin: 0; word-break: break-word; }
.help-ex p { margin: 0 0 var(--sp-1); }
.alike-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: var(--sp-2); }
.alike { display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; padding: var(--sp-3); min-width: 0; }
.alike-this { border-color: var(--accent); }
.alike-jp { font-family: var(--font-jp); font-size: var(--fs-jp-md); font-weight: 900; line-height: var(--lh-ruby); word-break: break-word; }
.plant .bandage { position: absolute; left: -4px; bottom: -2px; font-size: 0.9rem; }
/* Line icons in place of emoji (js/icons.js): sized and coloured like the text around them */
.ico { display: inline-block; width: 1.15em; height: 1.15em; vertical-align: -0.2em; flex: none; overflow: visible; }
.btn .ico, .tab .ico, .tag .ico { margin-right: 0.15em; }
.btn .ico:last-child:not(:first-child) { margin: 0 0 0 0.15em; }
.plant-emoji .ico, .mode-icon .ico { width: 1em; height: 1em; vertical-align: -0.1em; }
.plant-emoji .ico { color: var(--good); }
.plant-emoji .ico-blossom { color: var(--accent); }
.drop .ico { color: var(--accent); }
/* Pronunciation check (js/pron.js) */
.pron-overlay { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, 0.45); background: color-mix(in srgb, var(--ink) 40%, transparent); display: flex; align-items: flex-end; justify-content: center; padding: var(--sp-3); overflow-y: auto; }
@media (min-width: 700px) { .pron-overlay { align-items: center; } }
.pron-sheet { width: 100%; max-width: 560px; max-height: calc(100dvh - 24px); overflow-y: auto; padding: var(--sp-4); }
.pron-head { gap: var(--sp-2); }
.pron-head .section-title { margin: 0; font-size: var(--fs-lg); }
.pron-word { display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; }
.pron-jp { font-family: var(--font-jp); font-size: var(--fs-jp-lg); font-weight: 900; line-height: var(--lh-ruby); word-break: break-word; }
.pron-melody { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.pron-melody svg { height: auto; max-height: 110px; }
.pron-target { stroke: var(--accent); opacity: 0.55; }
.pron-target-dot { fill: var(--accent); }
.pron-user { stroke: var(--good); }
.pron-user-dot { fill: var(--good); }
.pron-key { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; margin: 0 2px 0 8px; }
.pron-key-t { background: var(--accent); }
.pron-key-u { background: var(--good); }
.pron-verdict { text-align: center; }
.pron-title { font-size: var(--fs-2xl); font-weight: 900; font-style: italic; margin: 0; }
.pron-verdict p { margin: 0; }
.pron-morae { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--sp-1); }
.pron-mora { display: inline-flex; flex-direction: column; align-items: center; min-width: 40px; padding: 4px 6px; border-radius: var(--r-sm); border: 2px solid var(--border); background: var(--surface); }
.pron-mora.ok { border-color: var(--good); background: var(--good-soft); }
.pron-mora.miss { border-color: var(--border-strong); border-style: dashed; }
.pron-kana { font-family: var(--font-jp); font-size: var(--fs-jp-md); font-weight: 800; line-height: 1.3; }
.pron-mark { font-size: var(--fs-sm); line-height: 1; }
.pron-hold { display: block; height: 5px; border-radius: 3px; background: var(--accent); opacity: 0.7; margin-top: 3px; max-width: 46px; }
.pron-tips { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--sp-2); }
.pron-tips li { padding: var(--sp-2) var(--sp-3); border-left: 4px solid var(--accent); background: var(--surface-2); border-radius: var(--r-sm); }
.pron-tips p { margin: 0; word-break: break-word; }
.learn-item, .word-cell { display: flex; flex-direction: column; gap: var(--sp-1); min-width: 0; }
.learn-item .learn-card, .word-cell .melody-item { flex: 1; }
.pron-btn { align-self: center; }
/* Pitch Coach (js/pitch-coach.js) */
.coach-steps { display: flex; width: 100%; }
.coach-steps .seg-btn { flex: 1 1 0; min-width: 0; padding-left: var(--sp-2); padding-right: var(--sp-2); }
.coach-steps .seg-btn.suggested:not(.on) { color: var(--ink); box-shadow: inset 0 0 0 2px var(--good); }
.coach-line-wrap { width: 100%; border: 2px solid var(--border); border-radius: var(--r-md); background: var(--surface); overflow: hidden; }
.coach-line { display: block; width: 100%; height: 190px; }
.pron-live { display: block; width: 100%; height: 150px; }
.pron-count { display: inline-block; min-width: 1.4em; text-align: center; font-size: 1.6em; color: var(--accent); }
.coach-key { margin: 0; display: flex; flex-wrap: wrap; gap: 2px var(--sp-3); }
.coach-key > span { white-space: nowrap; }
.coach-key .pron-key { margin-left: 0; }
.coach-more { display: flex; justify-content: center; }
.coach-step { display: inline-block; padding: 1px 6px; margin: 2px; border-radius: var(--r-sm); border: 1px solid var(--border); white-space: nowrap; }
.coach-step.ok { border-color: var(--good); background: var(--good-soft); }
.coach-step.miss { border-style: dashed; border-color: var(--border-strong); }
.coach-beats { display: grid; grid-template-columns: repeat(auto-fit, minmax(56px, 1fr)); gap: var(--sp-2); }
.coach-beats .btn { font-family: var(--font-jp); font-weight: 800; min-width: 0; }
.coach-beats .btn[data-i="-1"] { font-family: var(--font-ui); grid-column: 1 / -1; }
/* Quick recap (js/recap.js) */
.recap-head { gap: var(--sp-2); flex-wrap: wrap; }
.recap-head .section-label { margin: 0; }
.recap-ask { outline: none; }
.recap-show-jp { font-family: var(--font-jp); font-size: var(--fs-jp-lg); font-weight: 800; line-height: var(--lh-ruby); word-break: break-word; }
.recap-opts .btn { min-height: 52px; word-break: break-word; }
.recap-play { align-self: flex-start; }
.answer-row.is-shown { border: 2px solid var(--border-strong); }
.recap-feedback { padding: var(--sp-2) var(--sp-3); border-radius: var(--r-md); background: var(--surface-2); }
.recap-feedback p { margin: 0; }
.recap-feedback p + p { margin-top: var(--sp-1); }
/* Katakana Rush */
.rush-bar { height: 12px; border-radius: var(--r-pill); background: var(--surface-2); border: 1.5px solid var(--border-strong); overflow: hidden; }
.rush-bar > span { display: block; height: 100%; background: var(--electric); }
.rush-card { border: 2px solid var(--ink); }
.rush-word { font-family: var(--font-jp); font-size: clamp(2.6rem, 13vw, 4.2rem); font-weight: 900; line-height: 1.2; word-break: break-word; }
.rush-romaji { font-size: var(--fs-lg); min-height: 1.5em; }

/* Sentence Builder: "A new word appears!" break before a sentence with an unlearned word */
.challenger { border: 2px solid var(--accent); animation: challenger-in 0.45s ease-out; }
.challenger-head { font-size: 1.35rem; font-weight: 800; font-style: italic; color: var(--accent); letter-spacing: 0.02em; }
@keyframes challenger-in { 0% { opacity: 0; transform: translateX(-24px) skewX(-6deg); } 70% { transform: translateX(4px); } 100% { opacity: 1; transform: none; } }

/* "New version ready" reload button (js/app.js) */
#update-ready {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--sp-5) + env(safe-area-inset-bottom));
  z-index: var(--z-toast); max-width: calc(100% - 32px); box-shadow: var(--shadow-hard);
}
body.has-tabs #update-ready { bottom: calc(var(--tabbar-h) + var(--sp-3) + env(safe-area-inset-bottom)); }
@media (min-width: 760px) { body.has-tabs #update-ready { bottom: var(--sp-5); } }

/* Rhythm: live mic level while you sing (js/modes/rhythm.js) */
.mic-meter { display: flex; align-items: center; gap: var(--sp-2); }
.mic-meter-bar { flex: 1; height: 8px; border-radius: var(--r-pill); background: var(--line); overflow: hidden; }
.mic-meter-bar > span { display: block; height: 100%; width: 0; background: var(--trace); transition: width 80ms linear; }

/* ---------- Kana Brush ---------- */
.brush-ask { display: grid; gap: var(--sp-1); justify-items: center; }
.brush-listen { font-size: var(--fs-xl); min-height: 72px; width: 100%; }
.brush-romaji { min-height: 1.5em; text-align: center; }
.brush-pad {
  --brush-ink: var(--ink);
  --brush-miss: var(--miss);
  position: relative; width: min(100%, 340px); aspect-ratio: 1; margin-inline: auto;
  border: 2px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface);
  touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overscroll-behavior: contain;
}
.brush-pad > svg, .brush-pad > canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.brush-canvas { cursor: crosshair; touch-action: none; transition: opacity .3s; }
.brush-pad.locked .brush-canvas { cursor: default; }
.brush-pad.faded .brush-canvas { opacity: .3; }
.brush-over { pointer-events: none; }
.brush-under { pointer-events: none; }
.brush-grid { stroke: var(--border); stroke-width: .6; stroke-dasharray: 2 2; fill: none; }
.brush-guide path { fill: none; stroke: var(--ink); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; }
.brush-model { fill: none; stroke: var(--accent); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1; stroke-dashoffset: 0; }
.brush-model.anim { stroke-dashoffset: 1; animation: brush-stroke .6s ease-out forwards; }
.brush-model.mark { stroke: var(--electric); stroke-width: 5.5; }
.brush-pad.demo .brush-canvas { cursor: pointer; }
.brush-pair { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); }
.brush-pair-k { margin: 0; display: grid; gap: var(--sp-1); justify-items: center; padding: var(--sp-2); border: 1.5px solid var(--border); border-radius: var(--r-sm); background: var(--surface); }
.brush-pair-k.asked { border-color: var(--good); }
.brush-pair-k svg { width: min(100%, 96px); height: auto; aspect-ratio: 1; }
.brush-pair-k figcaption { font-size: var(--fs-sm); text-align: center; }
.brush-num { font-family: var(--font-mono); font-size: 7px; font-weight: 800; fill: var(--electric); }
.brush-num.anim { opacity: 0; animation: brush-num .2s ease-out forwards; }
@keyframes brush-stroke { to { stroke-dashoffset: 0; } }
@keyframes brush-num { to { opacity: 1; } }
.brush-answer { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.brush-answer-k { display: inline-block; width: 4rem; height: 4rem; align-self: center; }
.brush-glyph { display: block; width: 100%; height: 100%; }
.brush-glyph path { fill: none; stroke: currentColor; stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; }
.brush-tools.row2, .brush-tools.row3 { width: min(100%, 340px); margin-inline: auto; }
.brush-giveup { justify-self: center; }
.brush-chart { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: var(--sp-1); }
.brush-cell { min-height: 44px; border-radius: var(--r-sm); border: 1.5px solid var(--border); background: var(--surface); cursor: pointer;
  font-family: var(--font-jp); font-size: 1.35rem; font-weight: 700; color: var(--dim); }
.brush-cell.g1 { border-color: var(--good); }
.brush-cell.g2 { border-color: var(--good); background: var(--good-soft); color: var(--ink); }
.brush-cell.g3 { border: 2px solid var(--good); background: color-mix(in srgb, var(--good) 28%, var(--surface)); color: var(--ink); }

/* Exam readiness (js/readiness.js) and the mock JLPT (js/exam.js) */
.road-card.ready { border-left: 4px solid var(--good); }
.road-card .section-title { font-size: var(--fs-lg); }
.exam-formats { display: grid; grid-template-columns: 1fr; gap: var(--sp-3); }
@media (min-width: 720px) { .exam-formats { grid-template-columns: 1fr 1fr; } }
.exam-jp { font-family: var(--font-jp); font-size: var(--fs-xl); line-height: 1.7; overflow-wrap: anywhere; }
.exam-mark { text-decoration-thickness: 2px; text-underline-offset: 5px; }
.exam-frame { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.exam-slot { display: inline-flex; align-items: center; justify-content: center; width: 3.2em; height: 1.6em; border-bottom: 2px solid var(--ink); color: var(--accent); }
.exam-slot .ico { width: 1.1em; height: 1.1em; }
.exam-passage { background: var(--surface-2); }
.exam-passage p { margin: 0; overflow-wrap: anywhere; }
.exam-opts .btn { overflow-wrap: anywhere; }
.exam-status { align-self: center; }
.exam-meter { position: relative; height: 14px; background: var(--surface-2); border: 1.5px solid var(--border); border-radius: var(--r-pill); }
.exam-meter .fill { position: absolute; inset: 0 auto 0 0; background: var(--miss); border-radius: var(--r-pill); }
.exam-meter .fill.pass { background: var(--good); }
.exam-meter .line { position: absolute; top: -5px; bottom: -5px; width: 3px; background: var(--ink); border-radius: 2px; }
.exam-parts { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--sp-2); }
.exam-result .tiles .tile-v { font-size: var(--fs-xl); }
.mock-list { margin: 0; padding-left: 1.2em; }
.linkbtn.inline { min-height: 0; padding: 0; }

/* Mock JLPT: the booklet and the answer sheet */
.exam-mondai { border-left: 4px solid var(--ink); padding: var(--sp-1) var(--sp-3); display: grid; gap: 2px; }
.exam-mondai .exam-inst { font-family: var(--font-jp); font-size: var(--fs-sm); line-height: 1.6; }
.exam-mondai.compact .exam-inst, .exam-mondai.compact .small { display: none; }
.exam-opt.on { border: 2.5px solid var(--ink); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--ink); }
.exam-num { display: inline-grid; place-items: center; min-width: 1.6em; height: 1.6em; border-radius: 50%; border: 1.5px solid currentColor; font-family: var(--font-mono); font-size: var(--fs-sm); font-weight: 800; margin-right: var(--sp-1); }
.exam-opts .btn { font-family: var(--font-jp); }
.exam-pics { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-2); }
@media (min-width: 720px) { .exam-pics { grid-template-columns: repeat(4, 1fr); } }
.exam-pics .btn { display: grid; justify-items: center; gap: var(--sp-1); padding: var(--sp-2); }
.exam-pic { width: 64px; height: 64px; }
.exam-pic.inline { width: 1.6em; height: 1.6em; vertical-align: middle; }
.exam-heard { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-2); }
.exam-heard .btn { display: grid; justify-items: center; gap: 2px; text-align: center; }
.exam-scene { width: min(100%, 420px); height: auto; justify-self: center; display: block; margin: 0 auto; }
.exam-scene .exam-scene-place { opacity: .55; }
.exam-scene .exam-arrow { color: var(--accent); stroke: var(--accent); }
.exam-doc { display: grid; gap: var(--sp-2); font-family: var(--font-jp); line-height: 1.8; }
.exam-doc-title { font-weight: 800; text-align: center; }
.exam-text { white-space: pre-line; overflow-wrap: anywhere; margin: 0; }
.exam-ask { font-family: var(--font-jp); font-weight: 700; }
.exam-info { border: 2px solid var(--ink); }
.exam-table-wrap { overflow-x: auto; max-width: 100%; }
.exam-table { border-collapse: collapse; width: 100%; font-size: var(--fs-sm); }
.exam-table th, .exam-table td { border: 1px solid var(--border-strong); padding: 4px 6px; text-align: center; }
.exam-table th { background: var(--surface-2); }
.exam-blank { display: inline-grid; place-items: center; min-width: 2.4em; padding: 0 4px; margin: 0 2px; border: 1.5px solid var(--ink); font-family: var(--font-mono); font-size: .85em; font-weight: 800; }
.exam-blank.on { background: var(--gold); color: #16131d; }
.right-text { text-align: right; }
.exam-nav { display: flex; flex-wrap: wrap; gap: var(--sp-2); justify-content: space-between; }
.exam-nav .btn.on { border-color: var(--accent); color: var(--accent); }
.exam-sheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: var(--sp-2); }
.exam-cell { position: relative; width: 100%; min-height: 48px; border-radius: var(--r-sm); border: 1.5px solid var(--border-strong); background: var(--surface); font: inherit; font-family: var(--font-mono); font-weight: 800; color: var(--ink); cursor: pointer; }
.exam-cell.done { background: var(--ink); color: var(--bg); }
.exam-cell.cur { outline: 3px solid var(--accent); outline-offset: 1px; }
.exam-cell.live { box-shadow: 0 0 0 3px var(--electric); }
.exam-flag { position: absolute; top: 1px; right: 3px; font-size: .75em; color: var(--accent); }
.exam-cell.done .exam-flag { color: var(--gold); }
.exam-mini-pic .exam-pic { width: 32px; height: 32px; }
/* ---------- Ren's Messages ---------- */
.msg-card { --who: var(--accent); display: flex; align-items: center; gap: var(--sp-3); min-width: 0; max-width: 100%; overflow: hidden; contain: inline-size; }
.msg-face { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--who, var(--accent));
  color: var(--accent-ink); font-family: var(--font-jp); font-weight: 800; font-size: 1.1rem; border: 2px solid var(--edge); }
.msg-card .msg-face { flex: none; }
.msg-card .grow { flex: 1; min-width: 0; }   /* lets the one-line preview shorten with an ellipsis instead of widening the page */
.msg-preview { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.msg-thread { display: grid; gap: var(--sp-3); }
.msg-row { display: flex; gap: var(--sp-2); align-items: flex-start; min-width: 0; }
.msg-row.mine { justify-content: flex-end; }
.msg-bubble { min-width: 0; max-width: min(100%, 560px); display: grid; gap: var(--sp-2); padding: var(--sp-3); border-radius: 4px 16px 16px 16px;
  border: 1.5px solid var(--who, var(--border-strong)); background: color-mix(in srgb, var(--who, var(--accent)) 8%, var(--surface)); }
.msg-bubble.mine { border-radius: 16px 4px 16px 16px; border-color: var(--border-strong); background: var(--surface-2); max-width: 85%; }
.msg-text { font-family: var(--font-jp); font-size: var(--fs-jp-md); line-height: var(--lh-ruby); overflow-wrap: anywhere; }
.msg-reply { display: grid; gap: 2px; text-align: left; justify-items: start; }
.msg-new { border-style: dashed; }
/* "What did they mean?" answers are English sentences: one per row, at reading size, so none wraps a word per line. */
.msg-opts { display: grid; gap: var(--sp-2); }
.msg-opts .btn { min-height: 48px; font-weight: 600; }
.msg-contacts { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: var(--sp-2); max-width: 520px; }
.msg-contact { position: relative; display: grid; justify-items: center; gap: 4px; min-width: 0; padding: var(--sp-2) 2px; border-radius: 12px;
  border: 1.5px solid transparent; background: none; color: inherit; font: inherit; cursor: pointer; }
.msg-contact[aria-pressed=true] { border-color: var(--who); background: color-mix(in srgb, var(--who) 12%, var(--surface)); }
.msg-contact.locked .msg-face { background: var(--surface-2); color: var(--dim); }
.msg-contact.locked .msg-contact-name { color: var(--dim); }
.msg-contact-name { font-size: 0.8rem; font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-contact .msg-face .ico { width: 18px; height: 18px; }
.msg-dot { position: absolute; top: 6px; right: calc(50% - 26px); width: 12px; height: 12px; border-radius: 50%; background: var(--accent); border: 2px solid var(--surface); }
.msg-about { border-left: 4px solid var(--who); display: grid; gap: var(--sp-1); }
.msg-reg { font-weight: 700; }
.msg-fit { text-align: right; }
.msg-modes { display: flex; gap: var(--sp-2); }
.msg-modes .btn[aria-pressed=true] { border-color: var(--accent); background: var(--accent-soft); }
.ai-compose { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--sp-2); align-items: end; }
.ai-compose textarea { min-width: 0; resize: vertical; font-family: var(--font-jp); }
.ai-chat .msg-fit.note-c { text-align: left; margin-left: auto; max-width: 85%; }
.ai-model { display: grid; justify-items: start; text-align: left; gap: 2px; }
.ai-model[aria-pressed=true] { border-color: var(--accent); background: var(--accent-soft); }
.linkish { background: none; border: 0; padding: 0; color: var(--electric); text-decoration: underline; font: inherit; cursor: pointer; }
/* ---------- Rival Battle ---------- */
.rival { --rival: var(--trace); }
.rival-list { display: grid; gap: var(--sp-2); }
.rival-card { display: flex; gap: var(--sp-3); align-items: center; text-align: left; cursor: pointer; color: inherit; font: inherit; }
.rival-card.on { border: 2px solid var(--rival); box-shadow: 3px 3px 0 var(--edge); }
.rival-card:disabled { cursor: default; opacity: .7; }
.rival-face { flex: none; display: grid; place-items: end center; width: 56px; height: 56px; border-radius: 50%; overflow: hidden;
  background: color-mix(in srgb, var(--rival) 22%, var(--surface)); border: 2px solid var(--edge); color: var(--rival); }
.rival-face.big-face { width: 120px; height: 120px; justify-self: center; margin-inline: auto; }
.rival-face.down .sprite-svg { transform: rotate(-8deg) translateY(6%); }
.stack-xs { display: grid; gap: 4px; }
/* Character drawings (js/rival-art.js): flat fills with one dark outline, the same in light and dark mode. */
.sprite { color: var(--rival); }
.sprite-svg, .sprite-img { display: block; width: 100%; height: auto; }
.sprite-svg { stroke: #1d1a24; stroke-width: 2.6; stroke-linejoin: round; stroke-linecap: round; overflow: visible; }
.sprite-ground { fill: rgba(22, 19, 29, .16); }
.sprite-img.powered { filter: drop-shadow(0 0 10px var(--rival)); }
/* The arena: rival card top left, rival top right, Ren (from behind) bottom left, Ren's card bottom right. */
.arena { position: relative; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: auto auto; align-items: start;
  column-gap: var(--sp-2); row-gap: var(--sp-5); padding: var(--sp-3) var(--sp-3) 0; overflow: hidden; border: 2px solid var(--edge);
  border-radius: var(--r-md); box-shadow: var(--shadow-hard);
  background: linear-gradient(180deg, color-mix(in srgb, var(--rival) 12%, var(--surface)) 0%, var(--surface-2) 100%); }
.bcard { display: grid; gap: 4px; min-width: 0; padding: var(--sp-2) var(--sp-3); background: var(--surface); border: 2px solid var(--edge);
  border-radius: var(--r-sm); box-shadow: 3px 3px 0 var(--edge); z-index: 1; }
.bcard .strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.bcard .lv { color: var(--dim); font-weight: 700; }
.foe-card { grid-column: 1; grid-row: 1; }
.foe-sprite { grid-column: 2; grid-row: 1; justify-self: center; width: min(128px, 100%); }
.me-sprite { grid-column: 1; grid-row: 2; align-self: end; justify-self: center; width: min(156px, 100%); margin-bottom: -6px; }
.me-card { grid-column: 2; grid-row: 2; align-self: end; margin-bottom: var(--sp-3); }
.me-num { justify-self: end; color: var(--dim); }
.hp-row { display: flex; align-items: center; gap: 6px; }
.hp-tag { font-family: var(--font-mono); font-size: 0.7rem; font-weight: 800; color: var(--gold); background: var(--edge); padding: 0 4px; border-radius: 4px; }
.rival-hp { flex: 1; height: 10px; border-radius: 999px; background: var(--surface-2); border: 1.5px solid var(--edge); overflow: hidden; }
.rival-hp > span { display: block; height: 100%; transition: width .8s ease-out, background-color .4s; }
.rival-hp > .hp-high { background: #1f9d55; }
.rival-hp > .hp-mid { background: #f5b800; }
.rival-hp > .hp-low { background: #d93a1e; }
.sprite.hurt { animation: sprite-hurt .5s steps(2, end) 1; }
.me-sprite.hurt { animation: sprite-shake .45s ease-in-out 1; }
.sprite.ko { transition: transform .9s ease-in, opacity .9s ease-in; transform: translateY(40%); opacity: 0; }
@keyframes sprite-hurt { 0%, 100% { opacity: 1; } 25%, 75% { opacity: .25; } }
@keyframes sprite-shake { 0%, 100% { transform: none; } 20% { transform: translateX(-8px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(3px); } }
/* The attack: a speech bubble that flies from the rival to Ren over --dur; answering freezes it where it is. */
.atk-bubble { position: absolute; z-index: 2; max-width: 64%; left: 50%; top: 18%; pointer-events: none;
  animation: atk-fly var(--dur, 10s) linear forwards; }
.atk-in { position: relative; display: grid; justify-items: center; gap: 2px; padding: var(--sp-2) var(--sp-4) var(--sp-3);
  background: var(--surface); border: 2.5px solid var(--rival); border-radius: 18px; box-shadow: 3px 3px 0 var(--edge); text-align: center;
  animation: atk-pop .3s cubic-bezier(.2, 1.6, .4, 1) both; }
.atk-in::after { content: ""; position: absolute; right: 18px; top: -11px; width: 18px; height: 18px; background: var(--surface);
  border-left: 2.5px solid var(--rival); border-top: 2.5px solid var(--rival); transform: rotate(45deg) skew(8deg, 8deg); }
.atk-in .rival-prompt { font-size: clamp(1.6rem, 8vw, 2.4rem); }
.atk-in .rival-prompt.latin { font-size: var(--fs-xl); }
.atk-listen { font-weight: 800; font-size: var(--fs-lg); }
.atk-fuse { position: absolute; left: 12px; right: 12px; bottom: 5px; height: 4px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.atk-fuse > i { display: block; height: 100%; background: var(--rival); transform-origin: left; animation: atk-fuse var(--dur, 10s) linear forwards; }
.atk-bubble.blocked .atk-in { animation: atk-burst .45s ease-out forwards; }
.atk-bubble.landed .atk-in { animation: atk-burst .45s ease-in forwards; }
@keyframes atk-fly { from { left: 40%; top: 36%; } to { left: 4%; top: 54%; } }
@keyframes atk-fuse { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@keyframes atk-pop { from { transform: scale(.3); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes atk-burst { to { transform: scale(1.35); opacity: 0; } }
.rival-text { display: grid; gap: 2px; padding: var(--sp-2) var(--sp-3); border-radius: var(--r-sm); border: 2px solid var(--edge);
  background: var(--surface); min-height: 3.4em; align-content: center; }
.rival-text.quiet .small { color: var(--dim); }
.atk-ask { margin-bottom: calc(-1 * var(--sp-2)); }
.fighter-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: var(--sp-2); }
.fighter-card { display: grid; justify-items: center; gap: 2px; padding: var(--sp-2) var(--sp-1) var(--sp-1); border-radius: var(--r-sm);
  background: var(--surface); border: 1.5px solid var(--border); color: inherit; font: inherit; cursor: pointer; min-width: 0; }
.fighter-card .strong { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fighter-card.on { border: 2px solid var(--accent); box-shadow: 3px 3px 0 var(--edge); }
.fighter-card:disabled { cursor: default; opacity: .6; }
.fighter-pic { width: 60px; height: 60px; display: grid; place-items: end center; overflow: hidden; }
.fighter-lock { align-self: center; font-size: 1.4rem; }
.rival-combo { display: inline-flex; gap: 4px; vertical-align: middle; margin-left: 4px; }
.rival-combo i { width: 14px; height: 14px; border-radius: 3px; border: 1.5px solid var(--border-strong); transform: skewX(-12deg); }
.rival-combo i.on { background: var(--accent); border-color: var(--accent); }
@media (min-width: 700px) {
  .foe-sprite { width: 170px; }
  .me-sprite { width: 200px; }
}
.rival-prompt { font-family: var(--font-jp); font-size: var(--fs-jp-xl); font-weight: 800; line-height: 1.25; overflow-wrap: anywhere; }
.rival-prompt.latin { font-family: var(--font-ui); font-size: var(--fs-2xl); }
.rival-kicker { font-family: var(--font-mono); font-weight: 800; letter-spacing: .12em; color: var(--rival); font-size: var(--fs-sm); }
.rival-finisher { position: fixed; inset: 0; z-index: 40; display: grid; place-content: center; justify-items: center; gap: var(--sp-2);
  background: color-mix(in srgb, var(--bg) 82%, transparent); pointer-events: none; text-align: center; padding: var(--sp-4); }
.rival-fin-name { font-size: clamp(2rem, 9vw, 3.5rem); font-weight: 900; font-style: italic; color: var(--accent); text-shadow: 3px 3px 0 var(--edge);
  animation: rival-pop .5s cubic-bezier(.2, 1.6, .4, 1) both; }
.rival-fin-line { font-family: var(--font-jp); font-size: var(--fs-xl); font-weight: 800; }
.rival-slash { position: absolute; left: -10%; right: -10%; top: 50%; height: 10px; background: var(--accent); transform: rotate(-14deg) scaleX(0);
  transform-origin: left center; animation: rival-slash .35s ease-out forwards; opacity: .85; }
@keyframes rival-pop { from { transform: scale(.4) rotate(-6deg); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes rival-slash { to { transform: rotate(-14deg) scaleX(1); } }
@media (prefers-reduced-motion: reduce) {
  .rival-fin-name, .rival-slash { animation: none; }
  .rival-slash { transform: rotate(-14deg); }
  .rival-hp > span { transition: width .2s linear; }
  /* The bubble stays put; its fuse still shows the time left. */
  .atk-bubble { animation: none; left: 26%; top: 34%; }
  .atk-in, .atk-bubble.blocked .atk-in, .atk-bubble.landed .atk-in { animation: none; }
  .atk-bubble.blocked, .atk-bubble.landed { opacity: 0; }
  .sprite.hurt, .me-sprite.hurt { animation: none; }
  .sprite.ko { transition: opacity .3s; transform: none; }
}

/* ---------- Encounters (js/modes/meet.js): Hyreign's pixel cast on the Rival Battle arena ---------- */
.px-sprite { display: block; width: 100%; height: auto; image-rendering: pixelated; image-rendering: crisp-edges; user-select: none; }
.sprite.px { color: inherit; }
.meet-arena .foe-sprite { width: min(132px, 100%); }
.meet-arena .me-sprite { width: min(190px, 100%); margin-bottom: -64px; }
.meet-bubble { max-width: 72%; }
.meet-line { font-family: var(--font-jp); font-size: var(--fs-jp-md); font-weight: 800; line-height: var(--lh-ruby); }
.meet-want { margin: 0; }
.meet-people { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-2); }
.meet-person { display: grid; justify-items: center; gap: 2px; padding: var(--sp-2); text-align: center; cursor: pointer; color: inherit; font: inherit; min-width: 0; }
.meet-person.on { border: 2px solid var(--rival); box-shadow: 3px 3px 0 var(--edge); }
.meet-person .small { line-height: 1.2; }
.meet-pic { width: 76px; height: 76px; }
.meet-scenes { display: grid; gap: var(--sp-1); }
.meet-scene { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px var(--sp-2); padding: var(--sp-2) var(--sp-3); text-align: left; border-radius: var(--r-sm);
  background: var(--surface); border: 1.5px solid var(--border); color: inherit; font: inherit; cursor: pointer; }
.meet-scene > .small:last-child { margin-left: auto; }
.meet-scene.on { border: 2px solid var(--rival); }
.fighter-pic.px { width: 64px; height: 64px; }
.meet-end-pic { width: 120px; margin-inline: auto; }

/* ---------- JLPT levels (js/levels.js) ---------- */
.level-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1) var(--sp-2); min-width: 0; }
.level-chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-family: var(--font-mono);
  font-size: var(--fs-sm); font-weight: 700; border: 1.5px solid var(--border-strong); }
.level-chip.on { border-color: var(--accent); color: var(--accent); }
.level-chip.locked { color: var(--dim); border-style: dashed; background: none; cursor: pointer; min-height: 32px; }
.level-bar .small { flex: 1 1 14em; min-width: 0; }
.unit-row.locked { opacity: .7; }
.levels-line { overflow-wrap: anywhere; }
/* Particle Train at N4: longer pieces (ので, ながら, かどうか) fit their buttons. */
.particle-grid .btn.particle { min-width: 0; overflow-wrap: anywhere; }
/* Kana Brush at N4: the word being written, one slot per kana. */
.brush-word-row { display: flex; flex-wrap: wrap; gap: 6px; font-family: var(--font-jp); font-size: var(--fs-jp-md); }
.brush-slot { display: inline-grid; place-items: center; width: 1.8em; height: 1.8em; border-radius: var(--r-sm); border: 1.5px solid var(--border-strong); }
.brush-slot.done { background: var(--surface-2); }
.brush-slot.now { border-color: var(--accent); color: var(--accent); font-weight: 800; }
/* Mock N4 用法: a word, then four full sentences. */
.exam-word { font-size: var(--fs-jp-md); }
.exam-opts.exam-long { grid-template-columns: 1fr; }
.exam-opts.exam-long .btn { text-align: left; justify-content: flex-start; }
.particle-grid.palette { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }

/* ===============================================================
   Story: reading-passage beats (N3). A beat with `doc` (js/story-n3.js) is a written text the characters read: a
   newspaper article, notice, letter, rules, diary or essay. Shown as a sheet of paper (js/modes/story.js renderDoc).
   ====================================================================== */
.doc-card {
  position: relative; width: 100%; max-width: 42rem; color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--border-strong); border-radius: 4px 4px var(--r-md) var(--r-md);
  box-shadow: var(--shadow-hard);
  padding: var(--sp-5) var(--sp-5) var(--sp-4);
  display: flex; flex-direction: column; gap: var(--sp-4);
}
/* A coloured strip along the top edge, like the masthead of a printed sheet. */
.doc-card::before {
  content: ""; position: absolute; inset: -1.5px -1.5px auto; height: 6px; border-radius: 4px 4px 0 0; background: var(--border-strong);
}
.doc-article::before { background: var(--ink); }
.doc-notice::before { background: var(--accent); }
.doc-rules::before { background: var(--electric); }
.doc-letter::before, .doc-diary::before, .doc-essay::before { background: var(--trace); }
.doc-head { display: flex; flex-direction: column; gap: var(--sp-2); padding-bottom: var(--sp-3); border-bottom: 1px solid var(--border); }
.doc-article .doc-head { border-bottom: 3px double var(--border-strong); }
.doc-kind {
  align-self: flex-start; display: inline-flex; align-items: baseline; gap: var(--sp-2);
  padding: 2px var(--sp-3); border-radius: var(--r-pill); border: 1.5px solid var(--border-strong);
  background: var(--surface-2); font-family: var(--font-jp); font-size: var(--fs-sm); font-weight: 800;
}
.doc-kind-en { font-family: var(--font-ui); font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--dim); }
.doc-title { font-family: var(--font-jp); font-size: var(--fs-xl); font-weight: 800; line-height: 1.45; overflow-wrap: anywhere; }
.doc-title:has(.jr) { line-height: var(--lh-ruby); }
/* The text: body weight and size, a comfortable measure, one sentence per line with air between them. */
.doc-body.line-jp {
  font-size: var(--fs-jp-md); font-weight: 500; line-height: 1.85; max-width: 34em;
  display: flex; flex-direction: column; gap: var(--sp-3);
}
.doc-body .jr { line-height: var(--lh-ruby); }
.doc-p { margin: 0; text-indent: 1em; overflow-wrap: anywhere; }   /* 字下げ: Japanese paragraphs start one space in */
.doc-p.doc-salute, .doc-p.doc-item, .doc-rules .doc-p, .doc-notice .doc-p.doc-sign { text-indent: 0; }
.doc-p.doc-item { padding-left: 2em; text-indent: -2em; }   /* 一、二、: numbers hang in the margin */
.doc-p.doc-sign { text-align: right; text-indent: 0; font-weight: 700; color: var(--dim); }
.doc-reading { display: block; text-indent: 0; line-height: 1.6; margin-bottom: 2px; font-weight: 400; }
/* Handwritten kinds (letter, diary, essay) get a faint left margin rule, like writing paper. */
.doc-letter .doc-body, .doc-diary .doc-body, .doc-essay .doc-body { border-left: 2px solid var(--accent-soft); padding-left: var(--sp-3); }
.doc-foot { border-top: 1px dashed var(--border); padding-top: var(--sp-3); }
.doc-meaning { width: auto; }
.doc-en { font-size: var(--fs-md); line-height: 1.7; max-width: 38em; }
/* The sheet slides in once when the beat opens (not on every re-render). */
.doc-card.doc-enter { animation: doc-in var(--dur) var(--ease-out); }
@keyframes doc-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (max-width: 480px) {
  .doc-card { padding: var(--sp-4) var(--sp-4) var(--sp-3); }
  .doc-title { font-size: var(--fs-lg); }
}
@media (prefers-reduced-motion: reduce) {
  .doc-card.doc-enter { animation: none; }
}
=======
/* ---------- Skill chart (js/skill-chart.js) ---------- */
.skill-chart { min-width: 0; }
.sc-tabs { flex: none; }
.sc-figure { display: grid; justify-items: center; min-width: 0; }
.skill-radar { width: min(100%, 460px); height: auto; overflow: visible; display: block; }
.skill-radar .sc-ring { fill: none; stroke: var(--border-strong); stroke-width: 1; opacity: .55; }
.skill-radar .sc-spoke { stroke: var(--border-strong); stroke-width: 1; opacity: .45; }
.skill-radar .sc-ghost { fill: color-mix(in srgb, var(--dim) 12%, transparent); stroke: var(--dim); stroke-width: 1.5; stroke-dasharray: 4 3; }
.skill-radar .sc-shape { fill: color-mix(in srgb, var(--accent) 28%, transparent); stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.skill-radar .sc-dot { fill: var(--accent); }
.skill-radar .sc-label { cursor: pointer; }
.skill-radar .sc-label text { fill: var(--ink, currentColor); font-size: 12.5px; font-weight: 700; font-family: var(--font-ui, inherit); }
.skill-radar .sc-label .sc-rank { fill: var(--dim); font-size: 10.5px; font-weight: 600; font-family: var(--font-jp, inherit); }
.skill-radar .sc-label.review text:first-child { text-decoration: underline dotted; }
.skill-radar.mini { width: 96px; flex: none; }
.skill-radar.mini .sc-shape { stroke-width: 2; }
.sc-summary { overflow-wrap: anywhere; }
.sc-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.sc-row { width: 100%; display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(60px, 1fr) 3.2em auto; align-items: center; gap: var(--sp-2);
  padding: 6px 8px; border: 1px solid transparent; border-radius: var(--r-sm); background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.sc-row:hover, .sc-row.on { border-color: var(--border-strong); background: var(--surface-2); }
.sc-row-name { min-width: 0; overflow-wrap: anywhere; }
.sc-row .bar { height: 8px; margin-top: 0; }
.sc-row .tag { justify-self: start; }
.sc-row .sc-grew + .sc-review, .sc-row .sc-review { grid-column: 1 / -1; }
.sc-locked { margin: 0; }
.skill-mini { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.skill-mini .grow { min-width: 0; }
@media (prefers-reduced-motion: reduce) { .skill-radar * { transition: none !important; animation: none !important; } }
.skill-mini [lang="ja"], .sc-summary [lang="ja"], .sc-row-name [lang="ja"] { white-space: nowrap; }

/* Tap a word to look it up (js/lookup.js): words are quietly underlined; the open one is highlighted, and its card
   sits at the bottom of the screen like a dictionary sheet. */
.lk { cursor: pointer; border-radius: 4px; text-decoration: underline dotted color-mix(in srgb, var(--dim) 55%, transparent); text-underline-offset: 0.28em; text-decoration-thickness: 1.5px; }
.lk:hover { background: var(--accent-soft); }
.lk.on { background: var(--gold); color: #16131d; text-decoration: none; }
.lk:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
.lk-hint { margin-top: calc(-1 * var(--sp-2)); }
.lk-sheet {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--sp-3) + env(safe-area-inset-bottom));
  width: min(560px, calc(100% - 24px)); z-index: var(--z-overlay); background: var(--surface); color: var(--ink);
  border: 2px solid var(--ink); border-radius: var(--r-lg); box-shadow: var(--shadow-hard); padding: var(--sp-3) var(--sp-4) var(--sp-4);
  display: flex; flex-direction: column; gap: var(--sp-2); animation: lk-in var(--dur) var(--ease-out);
}
body.has-tabs .lk-sheet { bottom: calc(var(--tabbar-h) + var(--sp-3) + env(safe-area-inset-bottom)); }
@media (min-width: 760px) { body.has-tabs .lk-sheet { bottom: var(--sp-5); } }
.lk-head { display: flex; align-items: flex-start; gap: var(--sp-3); }
.lk-head .grow { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--sp-1) var(--sp-3); }
.lk-word { font-family: var(--font-jp); font-size: var(--fs-2xl); font-weight: 900; line-height: 1.2; }
.lk-reading { font-family: var(--font-jp); font-size: var(--fs-lg); }
.lk-en { margin: 0; }
.lk-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
@keyframes lk-in { from { opacity: 0; transform: translate(-50%, 16px); } to { opacity: 1; transform: translate(-50%, 0); } }
@media (prefers-reduced-motion: reduce) { .lk-sheet { animation: none; } }

/* Library (js/modes/library.js) */
.lib-list, .lib-lines { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-2); }
.lib-card { display: flex; align-items: center; gap: var(--sp-3); width: 100%; text-align: left; cursor: pointer; color: inherit; font: inherit; }
.lib-card.next { border-color: var(--accent); box-shadow: var(--shadow-hard); }
.lib-card[disabled] { cursor: default; opacity: 0.7; }
.lib-title { font-family: var(--font-jp); font-size: var(--fs-jp-md); }
.lib-tiles { grid-template-columns: repeat(2, 1fr); }
.lib-tiles .tile-v, .lib-today .tile-v { font-size: var(--fs-2xl); font-weight: 900; }
.lib-h { font-family: var(--font-jp); }
.lib-lines { gap: var(--sp-2); }
.lib-line { display: flex; flex-direction: column; gap: 2px; padding: var(--sp-2) var(--sp-3); border-radius: var(--r-md); border-left: 3px solid transparent; }
.lib-line.talk { border-left-color: var(--border); }
.lib-line.playing { background: var(--accent-soft); border-left-color: var(--accent); }
.lib-row { display: flex; align-items: flex-start; gap: var(--sp-2); }
.lib-jp { font-family: var(--font-jp); font-size: var(--fs-jp-md); line-height: var(--lh-ruby); word-break: break-word; min-width: 0; }
.lib-play { flex: none; min-width: 44px; }
.lib-en { padding-left: 2px; }
.lib-en-btn { align-self: flex-start; min-height: 28px; padding: 0; }
.lib-who { font-family: var(--font-jp); }

/* Walk Mode (js/modes/walk.js) */
.walk-card { min-height: 220px; justify-content: center; position: relative; }
.walk-en { font-size: var(--fs-xl); margin: 0; }
.walk-jp { font-family: var(--font-jp); font-size: var(--fs-jp-lg); font-weight: 800; margin: 0; min-height: 1.4em; word-break: break-word; }
.walk-card.pause { border-color: var(--accent); }
.walk-eyes { font-size: var(--fs-lg); }
.walk-pulse { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); margin: 0 auto; animation: walk-pulse 1.2s ease-in-out infinite; }
@keyframes walk-pulse { 0%, 100% { transform: scale(0.7); opacity: 0.5; } 50% { transform: scale(1.2); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .walk-pulse { animation: none; } }

/* Type It (js/modes/type.js) */
.type-prompt-jp { font-family: var(--font-jp); font-size: var(--fs-jp-xl); font-weight: 900; line-height: 1.2; margin: 0; word-break: break-word; }
.type-prompt-en { font-size: var(--fs-2xl); font-weight: 800; margin: 0; }
.type-input { font-size: var(--fs-xl); text-align: center; }
.type-preview { min-height: 1.5em; margin: 0; text-align: center; }
.type-answer { font-family: var(--font-jp); font-size: var(--fs-jp-md); margin: 0; display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: baseline; }
.lib-reader, .library { max-width: 720px; margin-inline: auto; width: 100%; }

/* Dictation Drops (js/modes/dictation.js) */
.dict-play { font-size: var(--fs-xl); min-width: 9rem; margin: 0 auto; }
.dict-hint { min-height: 2.2em; display: flex; flex-wrap: wrap; gap: var(--sp-2); justify-content: center; align-items: center; }
.dict-slots { display: inline-flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.dict-slot { width: 1.6em; height: 1.6em; border: 1.5px solid var(--border-strong); border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; font-family: var(--font-jp); }
.dict-line { margin: 0; display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: baseline; }
.dict-morae { font-family: var(--font-jp); font-size: var(--fs-jp-md); display: inline-flex; flex-wrap: wrap; gap: 1px; word-break: break-all; }
.dict-mora { padding: 0 1px; border-radius: 4px; }
.dict-mora.off { background: var(--miss-soft); color: var(--miss); text-decoration: underline wavy; text-underline-offset: 4px; font-weight: 800; }
.dict-morae.key .dict-mora.off { background: var(--accent-soft); color: var(--accent); }
