/* ============================================================================
   Kotoba — Japanese grammar practice
   A warm, editorial "textbook meets SRS" design system. Vanilla CSS.
   Tokens → base → components → review shell → motion → responsive.
   ========================================================================== */

/* ---------------------------------------------------------------------------
   1. Design tokens
   ------------------------------------------------------------------------- */
:root {
  /* Paper & ink — warm, bookish neutrals (Sumi + Washi) */
  --bg: #faf7f2;
  --bg-soft: #f3eee6;
  --surface: #fffdf9;
  --surface-2: #f6f1e9;
  --ink: #2b2622;
  --ink-soft: #453d36;
  --ink-mute: #6f655c;
  --ink-faint: #9b9086;
  --line: #e7dfd3;
  --line-strong: #d9cebf;

  /* Accent — vermilion (shu 朱), a classic Japanese ink color */
  --accent: #c43c2e;
  --accent-ink: #a93024;
  --accent-soft: #f6e3dd;
  --accent-soft-2: #faece8;

  /* Semantic — washi-tinted, desaturated */
  --ok: #4b7a4e;
  --ok-ink: #3c6640;
  --ok-soft: #e3ede2;
  --warn: #a3702c;
  --warn-ink: #8a5c1e;
  --warn-soft: #f3e8d2;
  --bad: #b0483a;
  --bad-ink: #96392d;
  --bad-soft: #f5e0db;

  /* Brand bar mark & inline seal */
  --seal: #c43c2e;
  --seal-paper: #fdf6ee;

  /* Paper-feel surfaces */
  --shadow-paper: 0 1px 2px rgba(68, 55, 40, 0.05), 0 2px 10px rgba(68, 55, 40, 0.05);
  --shadow-lift: 0 2px 4px rgba(68, 55, 40, 0.07), 0 12px 28px -8px rgba(68, 55, 40, 0.18);

  /* Radius */
  --r-xs: 6px;
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-pill: 999px;

  /* Type */
  --font-display: "Bricolage Grotesque", "Zen Kaku Gothic New", "Yu Gothic UI", system-ui, sans-serif;
  --font-body: "Zen Kaku Gothic New", "Yu Gothic UI", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-jp: "Zen Kaku Gothic New", "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;

  --fs-xs: 0.72rem;
  --fs-sm: 0.84rem;
  --fs-md: 0.96rem;
  --fs-base: 1rem;
  --fs-lg: 1.16rem;
  --fs-xl: 1.42rem;
  --fs-2xl: 1.85rem;
  --fs-3xl: 2.4rem;

  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px;
  --space-5: 24px; --space-6: 32px; --space-7: 48px; --space-8: 72px;

  --speed: 160ms;
  --ease: cubic-bezier(0.3, 0.8, 0.3, 1);

  color-scheme: light dark;
}

[data-theme="dark"] {
  --bg: #191512;
  --bg-soft: #211c17;
  --surface: #231e19;
  --surface-2: #2b251f;
  --ink: #eee5d8;
  --ink-soft: #cfc3b4;
  --ink-mute: #a3947f;
  --ink-faint: #7d7061;
  --line: #383027;
  --line-strong: #463c30;

  --accent: #e0614f;
  --accent-ink: #ef8373;
  --accent-soft: #452a25;
  --accent-soft-2: #36201d;

  --ok: #8db98f;
  --ok-ink: #a6cba8;
  --ok-soft: #2a3a2a;
  --warn: #cfab6c;
  --warn-ink: #dfc390;
  --warn-soft: #3d3020;
  --bad: #dd6a57;
  --bad-ink: #eb8b79;
  --bad-soft: #452722;

  --seal: #e0614f;
  --seal-paper: #2b211b;

  --shadow-paper: 0 1px 2px rgba(0, 0, 0, 0.3), 0 2px 10px rgba(0, 0, 0, 0.25);
  --shadow-lift: 0 2px 4px rgba(0, 0, 0, 0.35), 0 14px 30px -8px rgba(0, 0, 0, 0.5);
}

/* ---------------------------------------------------------------------------
   2. Base
   ------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Subtle paper grain via layered radial gradients — no image asset needed */
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(1200px 500px at 85% -10%, color-mix(in srgb, var(--accent) 5%, transparent), transparent 60%),
    radial-gradient(900px 400px at -10% 20%, color-mix(in srgb, var(--accent) 3%, transparent), transparent 55%);
}

main, .review-shell-inner { position: relative; z-index: 1; }

a { color: var(--accent-ink); }
a:hover { color: var(--accent); }

::selection { background: var(--accent-soft); color: var(--accent-ink); }

/* Accessible focus */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.hidden { display: none !important; }

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 0 0 10px 0;
  z-index: 100;
}
.skip-link:focus { left: 0; }

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.25;
  margin: 0;
}

/* ---------------------------------------------------------------------------
   3. Header & navigation
   ------------------------------------------------------------------------- */
#app-header {
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
}
.header-inner {
  max-width: 1080px; margin: 0 auto;
  padding: 10px var(--space-5);
  display: flex; align-items: center; gap: var(--space-4);
}
#brand {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--ink);
  font-family: var(--font-display); font-weight: 700; font-size: 1.14rem;
  letter-spacing: -0.01em; white-space: nowrap;
}
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px;
  display: grid; place-items: center;
  background: var(--seal); color: #fff8ef;
  font-size: 1.05rem; font-weight: 700;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.18);
}
.brand-sub { color: var(--ink-faint); font-weight: 500; font-size: 0.74em; margin-left: 6px; letter-spacing: 0.04em; }
#app-header nav { display: flex; gap: 2px; flex: 1; margin-left: var(--space-2); }
#app-header nav a {
  padding: 7px 14px; border-radius: var(--r-pill);
  text-decoration: none; color: var(--ink-mute);
  font-weight: 500; font-size: 0.94rem;
  transition: color var(--speed) var(--ease), background var(--speed) var(--ease);
}
#app-header nav a:hover { color: var(--ink); background: var(--bg-soft); }
#app-header nav a.active { background: var(--ink); color: var(--bg); }
[data-theme="dark"] #app-header nav a.active { background: var(--ink); color: var(--bg); }
.header-actions { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  width: 36px; height: 36px; border-radius: var(--r-pill);
  border: 1px solid transparent; background: transparent;
  color: var(--ink-mute); cursor: pointer;
  display: grid; place-items: center;
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease);
}
.icon-btn:hover { background: var(--bg-soft); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; }
[data-theme="dark"] .ico-sun { display: block; }
[data-theme="dark"] .ico-moon { display: none; }
.ico-sun { display: none; }
.ico-moon { display: block; }

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: clamp(18px, 4vw, 40px) var(--space-5) var(--space-8);
  min-height: 70vh;
}
main:focus { outline: none; }

/* Page hero headers */
.page-head { margin-bottom: var(--space-6); }
.page-head .eyebrow {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: var(--fs-sm); font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--accent-ink);
}
.page-head h1 { font-size: clamp(1.7rem, 3.4vw, 2.3rem); margin: 10px 0 6px; }
.page-head .page-sub { color: var(--ink-mute); max-width: 60ch; margin: 0; font-size: 1.02rem; }
.page-head .eyebrow::before { content: ""; width: 22px; height: 1px; background: var(--accent); }

/* ---------------------------------------------------------------------------
   4. Buttons
   ------------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font-display); font-weight: 600; font-size: 1rem;
  border: none; cursor: pointer;
  background: var(--accent); color: #fff8ef;
  padding: 11px 20px; border-radius: var(--r-md);
  text-decoration: none; text-align: center;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.14);
  transition: transform var(--speed) var(--ease), box-shadow var(--speed) var(--ease),
              background var(--speed) var(--ease), filter var(--speed) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { filter: brightness(1.05); transform: translateY(-1px); }
.btn:active { transform: translateY(0); box-shadow: inset 0 1px 0 rgba(0,0,0,0.14); }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; filter: none; }
.btn svg { width: 17px; height: 17px; }

.btn-secondary {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong);
  box-shadow: none;
}
.btn-secondary:hover { border-color: var(--ink-mute); color: var(--ink); }
.btn-ghost { background: transparent; color: var(--ink-mute); box-shadow: none; border: 1px solid transparent; }
.btn-ghost:hover { background: var(--bg-soft); color: var(--ink); filter: none; }
.btn-small { padding: 7px 14px; font-size: 0.9rem; border-radius: var(--r-sm); }
.btn-block { width: 100%; }
.btn-lg { padding: 15px 28px; font-size: 1.12rem; border-radius: 18px; }
.btn .kbd { font-family: var(--font-body); font-size: 0.78em; opacity: 0.75; }

/* ---------------------------------------------------------------------------
   5. Cards & surfaces
   ------------------------------------------------------------------------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-paper);
}
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 10px; border-radius: var(--r-pill);
  background: var(--surface-2); color: var(--ink-mute);
  border: 1px solid var(--line);
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase;
  white-space: nowrap;
}
.chip-level { background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; }
.chip-new { background: var(--accent); color: #fff8ef; border-color: transparent; }
.chip-line { background: transparent; }
.kbd-hint {
  font-size: 0.68rem; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-faint); font-family: var(--font-body);
}

/* ---------------------------------------------------------------------------
   6. Dashboard
   ------------------------------------------------------------------------- */
.dash-hero {
  position: relative;
  border-radius: 24px;
  padding: clamp(22px, 4.5vw, 40px);
  overflow: hidden;
}
.dash-hero .panel-inner { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-6); position: relative; z-index: 1; }
.dash-hero-main { flex: 1 1 320px; }
.dash-hero-side { flex: 0 1 320px; }
.dash-hero h1 { font-size: clamp(1.65rem, 3vw, 2.35rem); font-weight: 650; letter-spacing: -0.02em; }
.dash-hero .eyebrow { color: var(--accent-ink); display: block; margin-bottom: 8px; font-weight: 600; }
.dash-hero .hero-copy { color: var(--ink-soft); margin: 10px 0 0; max-width: 52ch; }
[data-theme="dark"] .dash-hero h1, [data-theme="dark"] .dash-hero .hero-copy { color: var(--ink); }

.hero-actions { display: flex; gap: var(--space-3); margin-top: var(--space-5); flex-wrap: wrap; }

.hero-numbers { display: flex; gap: 0; }
.hero-num {
  padding: 0 clamp(14px, 2vw, 26px);
  display: flex; flex-direction: column;
  border-right: 1px solid color-mix(in srgb, currentColor 16%, transparent);
}
.hero-num:first-child { padding-left: 0; }
.hero-num:last-child { border-right: none; }
.hero-num .num { font-family: var(--font-display); font-weight: 700; font-size: clamp(1.6rem, 3vw, 2.2rem); line-height: 1.1; color: var(--ink); font-variant-numeric: tabular-nums; }
.hero-num .cap { font-size: 0.74rem; color: var(--ink-mute); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; margin-top: 4px; }

/* Due ring — the "what to do now" dial */
.ring-wrap { position: relative; width: 150px; height: 150px; margin: 0 auto; }
.ring-wrap svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: color-mix(in srgb, var(--ink) 9%, transparent); stroke-width: 9; }
.ring-fg { fill: none; stroke: var(--accent); stroke-width: 9; stroke-linecap: round; transition: stroke-dashoffset 700ms var(--ease); }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-center .n { font-family: var(--font-display); font-weight: 700; font-size: 2.1rem; line-height: 1; color: var(--ink); font-variant-numeric: tabular-nums; }
.ring-center .l { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink-mute); font-weight: 700; margin-top: 5px; }
.ring-label { text-align: center; margin-top: 10px; font-size: 0.9rem; color: var(--ink-mute); }
.ring-label b { color: var(--ink); font-weight: 600; }

/* Stat row */
.stat-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); margin-top: var(--space-4); }
.stat-cell { padding: var(--space-4) var(--space-5); display: flex; align-items: center; gap: var(--space-4); }
.stat-ic { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0; background: var(--accent-soft); color: var(--accent-ink); }
.stat-ic svg { width: 19px; height: 19px; }
.stat-cell .t { font-size: 0.78rem; color: var(--ink-mute); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-cell .v { font-family: var(--font-display); font-weight: 700; font-size: 1.35rem; line-height: 1.15; color: var(--ink); font-variant-numeric: tabular-nums; }

/* Strength meter — "your grammar, held in mind" */
.strength-meter { width: 150px; height: 150px; margin: 0 auto; }
.strength-meter svg { width: 100%; height: 100%; }
.sm-track { fill: none; stroke: color-mix(in srgb, currentColor 10%, transparent); stroke-width: 10; }
.sm-arc { fill: none; stroke: var(--accent); stroke-width: 10; stroke-linecap: round; }
.sm-center { text-anchor: middle; font-family: var(--font-display); font-weight: 700; fill: var(--ink); }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); margin: var(--space-6) 0 var(--space-4); }
.section-head h2 { font-size: 1.22rem; }
.section-head .link-more { font-size: 0.9rem; text-decoration: none; font-weight: 600; }

/* Continue / recent row */
.quick-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-4); }
.quick-item { padding: var(--space-5); display: flex; gap: var(--space-4); align-items: center; text-decoration: none; color: inherit; transition: transform var(--speed) var(--ease), box-shadow var(--speed) var(--ease), border-color var(--speed) var(--ease); }
.quick-item:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); border-color: var(--line-strong); }
.quick-badge {
  width: 46px; height: 46px; flex-shrink: 0; border-radius: 14px;
  display: grid; place-items: center;
  background: var(--bg-soft); color: var(--ink-soft);
  font-family: var(--font-display); font-weight: 700; font-size: 0.9rem;
  border: 1px solid var(--line);
}
.quick-badge.is-locked { opacity: 0.55; }
.quick-badge.is-done { background: var(--ok-soft); color: var(--ok-ink); border-color: transparent; }
.quick-body { min-width: 0; flex: 1; }
.quick-body .qt { font-weight: 600; color: var(--ink); }
.quick-body .qd { font-size: 0.85rem; color: var(--ink-mute); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quick-item .go { color: var(--ink-faint); flex-shrink: 0; }
.quick-meta { margin-left: auto; text-align: right; flex-shrink: 0; }

/* ---------------------------------------------------------------------------
   7. Lessons
   ------------------------------------------------------------------------- */
.lesson-tabs { display: flex; gap: var(--space-2); margin-bottom: var(--space-5); flex-wrap: wrap; }
.lesson-tabs .tab {
  padding: 9px 18px; border-radius: var(--r-pill); cursor: pointer;
  font: inherit; font-family: var(--font-display); font-weight: 600; font-size: 0.92rem;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-mute);
  display: inline-flex; align-items: center; gap: 8px;
  transition: all var(--speed) var(--ease);
}
.lesson-tabs .tab:hover { border-color: var(--line-strong); color: var(--ink); }
.lesson-tabs .tab.active { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.lesson-tabs .tab .cnt { font-size: 0.72rem; opacity: 0.7; font-variant-numeric: tabular-nums; }

.lesson-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-4); }
.lesson-item {
  padding: var(--space-4) var(--space-5); text-decoration: none; color: inherit;
  display: flex; align-items: center; gap: var(--space-4);
  transition: transform var(--speed) var(--ease), box-shadow var(--speed) var(--ease), border-color var(--speed) var(--ease);
  background: var(--surface);
}
.lesson-item:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); border-color: var(--line-strong); }
.lesson-no {
  flex-shrink: 0; width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; font-size: 0.94rem;
  background: var(--bg-soft); color: var(--ink-soft); border: 1px solid var(--line);
}
.lesson-no.seen { background: var(--accent-soft); border-color: transparent; color: var(--accent-ink); }
.lesson-main { flex: 1; min-width: 0; }
.lesson-title { font-weight: 600; font-size: 0.98rem; display: flex; align-items: center; gap: 8px; }
.lesson-desc { font-size: 0.8rem; color: var(--ink-mute); margin-top: 2px; display: flex; gap: 10px; align-items: center; }
.lesson-counts { flex-shrink: 0; text-align: right; }

/* Dots: one per grammar point — sparse = starting out, dense + vermilion = solid */
.dots { display: inline-flex; gap: 3px; max-width: 120px; overflow: hidden; }
.dots i { width: 5px; height: 5px; border-radius: 50%; background: color-mix(in srgb, var(--ink) 12%, transparent); flex-shrink: 0; }
.dots i.on { background: var(--accent); }

.progress-line { height: 5px; background: var(--bg-soft); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.progress-line > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width 600ms var(--ease); }

/* ---------------------------------------------------------------------------
   8. Lesson detail — grammar points
   ------------------------------------------------------------------------- */
.lesson-hero { padding: var(--space-5) var(--space-6); margin-bottom: var(--space-5); display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-4); }
.lesson-hero .lhs { flex: 1 1 300px; min-width: 0; }
.lesson-hero .rhs { display: flex; flex-direction: column; gap: var(--space-3); align-items: flex-end; }
.lesson-hero .rhs .btn { white-space: nowrap; }
.lesson-big-no { font-family: var(--font-display); font-weight: 700; font-size: clamp(2.4rem, 6vw, 3.6rem); line-height: 1; color: var(--accent); letter-spacing: -0.03em; }
.lesson-summary { display: flex; gap: var(--space-4); margin: var(--space-3) 0 var(--space-5); flex-wrap: wrap; }
.lesson-stat { display: flex; flex-direction: column; }
.lesson-stat .v { font-family: var(--font-display); font-weight: 700; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.lesson-stat .k { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-mute); font-weight: 600; }

.gp-list { display: flex; flex-direction: column; gap: var(--space-3); }
.gp-row {
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  text-decoration: none; color: inherit;
  transition: transform var(--speed) var(--ease), box-shadow var(--speed) var(--ease), border-color var(--speed) var(--ease);
}
.gp-row:hover { transform: translateY(-1px); box-shadow: var(--shadow-lift); border-color: var(--line-strong); }
.gp-main { flex: 1; min-width: 0; }
.gp-grammar { font-size: 1.06rem; font-weight: 600; letter-spacing: 0.01em; display: flex; align-items: center; gap: 8px; }
.gp-grammar .pattern-hl {
  background: var(--accent-soft-2); border-radius: var(--r-xs); padding: 1px 6px;
}
.gp-meaning { font-size: 0.86rem; color: var(--ink-mute); margin-top: 1px; }
.gp-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; }
.gp-side .progress-line { width: 110px; margin-top: 0; }

/* Strength bars */
.bar { height: 5px; background: var(--bg-soft); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 3px; background: var(--accent); transition: width 700ms var(--ease); }
.bar.thin { height: 4px; }

/* ---------------------------------------------------------------------------
   9. Grammar detail — the "textbook page"
   ------------------------------------------------------------------------- */
.gd-top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-5); flex-wrap: wrap; }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-mute); text-decoration: none; font-size: 0.9rem; font-weight: 500; margin-bottom: var(--space-4); }
.back-link:hover { color: var(--ink); }

.gd-card {
  padding: clamp(20px, 4vw, 40px);
  position: relative;
  overflow: hidden;
  margin-bottom: var(--space-5);
}
.gd-card::after {
  content: "文"; /* kanji for "sentence/grammar" — quiet texture mark */
  position: absolute; right: -8px; bottom: -30px;
  font-size: 8.5rem; line-height: 1; opacity: 0.04;
  font-weight: 900; pointer-events: none; color: var(--ink);
  transform: rotate(-8deg);
}
.gd-pattern {
  font-family: var(--font-jp);
  font-size: clamp(1.7rem, 4vw, 2.6rem);
  font-weight: 700; line-height: 1.3; letter-spacing: 0.02em;
  color: var(--ink);
  text-align: center;
  word-break: keep-all;
}
.gd-meaning { text-align: center; font-size: 1.05rem; color: var(--ink-soft); margin-top: 10px; max-width: 56ch; margin-inline: auto; }
.gd-meaning-id { text-align: center; font-size: 0.92rem; color: var(--ink-faint); font-style: italic; margin-top: 4px; }
.gd-meta { display: flex; justify-content: center; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.gd-actions { display: flex; justify-content: center; gap: var(--space-3); margin-top: 22px; flex-wrap: wrap; }

.gd-block { margin-bottom: var(--space-5); }
.gd-block h2 {
  font-size: 1rem; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--accent-ink); display: flex; align-items: center; gap: 10px;
  margin-bottom: var(--space-3);
}
.gd-block h2::after { content: ""; height: 1px; flex: 1; background: var(--line); }
.gd-block .body { color: var(--ink-soft); font-size: 1rem; line-height: 1.8; white-space: pre-line; }
.gd-block .body p { margin: 0 0 10px; }

.formation-box {
  background: var(--surface-2); border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--r-md) var(--r-md) 0;
  padding: var(--space-4) var(--space-5);
}
.formation-box .f-pattern { font-family: var(--font-jp); font-weight: 700; font-size: 1.2rem; line-height: 1.6; color: var(--ink); }
.formation-box .f-note { color: var(--ink-mute); font-size: 0.9rem; margin-top: 6px; white-space: pre-line; }

.mistake-item, .similar-item { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 0.96rem; }
.mistake-item:last-child, .similar-item:last-child { border-bottom: none; }
.mistake-item::before { content: "✕"; color: var(--bad); font-weight: 700; flex-shrink: 0; }
.similar-item::before { content: "→"; color: var(--accent); font-weight: 700; flex-shrink: 0; }

/* Master language toolbar and material header */
.gd-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}
.gd-top-bar .back-link {
  margin-bottom: 0;
}

.gd-material-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-6);
  margin-bottom: var(--space-4);
  padding: 12px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-paper);
  flex-wrap: wrap;
}
.gd-material-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink);
}
.gd-material-sub {
  font-family: var(--font-body);
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--ink-faint);
}

.lang-toggle-all-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.lang-toggle-all-hint {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
}
.lang-toggle-all {
  border: 1px solid var(--line-strong);
  background: var(--bg-soft);
  box-shadow: var(--shadow-paper);
}
.lang-toggle-all .lang-toggle-btn {
  font-size: 0.7rem;
  padding: 3px 12px;
  font-weight: 800;
}

/* Bilingual EN ↔ ID toggle — compact pill pair inline with section titles */
.lang-toggle {
  display: inline-flex;
  gap: 2px;
  margin-left: auto;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 2px;
  flex-shrink: 0;
}
.lang-toggle-btn {
  all: unset;
  cursor: pointer;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  padding: 2px 10px;
  border-radius: calc(var(--r-sm) - 2px);
  color: var(--ink-faint);
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease);
  line-height: 1.6;
}
.lang-toggle-btn:hover { color: var(--ink-mute); }
.lang-toggle-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.lang-toggle-btn.active {
  background: var(--accent-soft);
  color: var(--accent-ink);
}
.lang-panel.hidden { display: none; }
.lang-empty {
  color: var(--ink-faint);
  font-style: italic;
  font-size: 0.9rem;
}

/* Example sentences — the reading zone */
.examples-section { margin-top: var(--space-7); }
.examples-section > h2 { margin-bottom: var(--space-4); }
.ex-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-4); }
.ex-card {
  padding: var(--space-5);
  display: flex; flex-direction: column; gap: 4px;
  transition: transform var(--speed) var(--ease), box-shadow var(--speed) var(--ease), border-color var(--speed) var(--ease);
}
.ex-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.ex-top { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); margin-bottom: 8px; flex-wrap: wrap; }
.ex-idx {
  width: 26px; height: 26px; border-radius: 8px;
  display: grid; place-items: center;
  font-family: var(--font-display); font-size: 0.78rem; font-weight: 700;
  background: var(--bg-soft); color: var(--ink-mute);
}
.ex-card .jp {
  font-family: var(--font-jp); font-size: 1.22rem; font-weight: 500; line-height: 1.7;
  letter-spacing: 0.01em; color: var(--ink);
}
.ex-card .furi { color: var(--ink-faint); font-size: 0.85rem; font-family: var(--font-jp); }
.ex-card .en { color: var(--ink-mute); font-size: 0.94rem; margin-top: 6px; }
.ex-card .id { color: var(--ink-mute); font-size: 0.94rem; margin-top: 6px; }
.ex-context {
  margin-top: 10px; font-size: 0.85rem; color: var(--ink-mute);
  border-top: 1px dashed var(--line); padding-top: 8px;
  display: flex; gap: 6px;
}
.ex-context svg { width: 14px; height: 14px; flex-shrink: 0; margin-top: 3px; opacity: 0.7; }
.ex-usage {
  margin-top: 6px;
  font-size: 0.85rem;
  color: var(--ink-mute);
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.ex-usage-tag {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-ink);
  background: var(--accent-soft);
  padding: 1px 6px;
  border-radius: var(--r-xs);
  flex-shrink: 0;
  line-height: 1.4;
}

/* Similar grammar pointers */
.similar-grammar { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-top: 6px; }
.similar-grammar a { text-decoration: none; font-size: 0.88rem; font-weight: 600; }

/* ---------------------------------------------------------------------------
   10. Forms & practice setup
   ------------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--space-4); }
.field > span { font-size: 0.8rem; font-weight: 600; color: var(--ink-mute); letter-spacing: 0.02em; }
.input, select.input, textarea.input {
  font: inherit; font-size: 1rem;
  padding: 11px 14px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  width: 100%;
  transition: border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink-faint) 50%), linear-gradient(135deg, var(--ink-faint) 50%, transparent 50%); background-position: calc(100% - 20px) 55%, calc(100% - 15px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px; }
.radio-row { display: flex; gap: var(--space-4); }
.radio-row label { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; font-size: 0.95rem; }
.radio-row input { accent-color: var(--accent); width: 16px; height: 16px; }

/* Setup panel */
.setup-card { padding: clamp(20px, 4vw, 34px); max-width: 560px; }
.setup-card h1 { font-size: 1.5rem; margin-bottom: 4px; }
.setup-card .sub { color: var(--ink-mute); margin: 0 0 var(--space-5); font-size: 0.94rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--space-4); }
.form-grid .span2 { grid-column: 1 / -1; }

/* Chips used as multi-selects (JLPT, categories) */
.opt-group { display: flex; flex-wrap: wrap; gap: 8px; }
.opt-pill {
  border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink-mute); font: inherit; font-size: 0.9rem; font-weight: 600;
  padding: 7px 15px; border-radius: var(--r-pill); cursor: pointer;
  transition: all var(--speed) var(--ease);
}
.opt-pill:hover { border-color: var(--accent); color: var(--accent-ink); }
.opt-pill.on { background: var(--accent); border-color: var(--accent); color: #fff8ef; }
.opt-hint { font-size: 0.78rem; color: var(--ink-faint); margin-top: 6px; }

/* Multi-select filter component */
.btn-xs { padding: 4px 10px; font-size: 0.76rem; border-radius: var(--r-sm); }
.field-label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 2px; }
.selection-badge {
  font-size: 0.74rem; font-weight: 700; color: var(--accent-ink);
  background: var(--accent-soft); padding: 2px 9px; border-radius: var(--r-pill);
  letter-spacing: 0.02em;
}
.multi-select-box { position: relative; width: 100%; }
.multi-select-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; font: inherit; font-size: 0.95rem; font-weight: 500;
  padding: 10px 14px; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  cursor: pointer; text-align: left;
  transition: border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
}
.multi-select-btn:hover { border-color: var(--accent); }
.multi-select-btn.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.multi-select-btn .btn-text {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;
}
.multi-select-arrow {
  width: 14px; height: 14px; color: var(--ink-faint); flex-shrink: 0;
  transition: transform var(--speed) var(--ease);
}
.multi-select-btn.active .multi-select-arrow { transform: rotate(180deg); color: var(--accent-ink); }

/* Selection chip tags below the trigger */
.multi-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; align-items: center; }
.multi-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.76rem; font-weight: 600; padding: 3px 9px;
  background: var(--bg-soft); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-pill);
  transition: all var(--speed) var(--ease); max-width: 100%;
}
.multi-chip:hover { border-color: var(--line-strong); background: var(--surface); }
.multi-chip .chip-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.multi-chip .chip-del {
  display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; border: none; background: transparent;
  color: var(--ink-faint); font-weight: 700; cursor: pointer;
  font-size: 0.85rem; line-height: 1; padding: 0; margin-left: 2px;
  transition: color var(--speed) var(--ease);
}
.multi-chip .chip-del:hover { color: var(--bad-ink); }
.multi-chip-clear {
  font-size: 0.74rem; font-weight: 600; color: var(--ink-faint);
  background: transparent; border: none; cursor: pointer;
  padding: 2px 6px; text-decoration: underline; text-underline-offset: 2px;
  transition: color var(--speed) var(--ease);
}
.multi-chip-clear:hover { color: var(--bad-ink); }

/* Multi-select dropdown popover */
.multi-panel {
  position: absolute; top: calc(100% + 5px); left: 0; right: 0;
  z-index: 60; background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  box-shadow: var(--shadow-lift); padding: 10px;
  display: flex; flex-direction: column; gap: 8px;
  animation: multiPanelIn 140ms var(--ease);
}
@keyframes multiPanelIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}
.multi-panel.hidden { display: none; }
.panel-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding-bottom: 7px; border-bottom: 1px solid var(--line);
}
.panel-search { flex: 1; min-width: 0; }
.panel-search input.input {
  padding: 6px 10px; font-size: 0.85rem; height: 32px;
}
.panel-btn-group { display: flex; gap: 5px; flex-shrink: 0; }
.panel-items {
  max-height: 220px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
  overscroll-behavior: contain;
}
.panel-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 9px; border-radius: var(--r-sm);
  cursor: pointer; user-select: none;
  transition: background var(--speed) var(--ease);
  font-size: 0.88rem;
}
.panel-item:hover { background: var(--bg-soft); }
.panel-item.selected { background: var(--accent-soft); }
.panel-item input[type="checkbox"] {
  accent-color: var(--accent); width: 16px; height: 16px;
  margin: 0; cursor: pointer; flex-shrink: 0;
}
.panel-item .item-main {
  display: flex; flex-direction: column; min-width: 0; flex: 1; gap: 2px;
}
.panel-item .item-title {
  font-weight: 600; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.panel-item .item-sub {
  font-size: 0.76rem; color: var(--ink-mute);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.panel-item .item-book {
  font-size: 0.72rem; color: var(--ink-faint); margin-left: auto;
  padding-left: 6px; flex-shrink: 0;
}
.panel-empty {
  padding: 16px; text-align: center; color: var(--ink-mute);
  font-size: 0.85rem; font-style: italic;
}
/* ---------------------------------------------------------------------------
   11. Auth
   ------------------------------------------------------------------------- */
.auth-wrap { max-width: 400px; margin: 6vh auto 0; text-align: center; }
.auth-brand { display: inline-flex; flex-direction: column; align-items: center; gap: 10px; text-decoration: none; margin-bottom: var(--space-6); }
.auth-brand .brand-mark { width: 58px; height: 58px; border-radius: 18px; font-size: 1.9rem; box-shadow: var(--shadow-lift); }
.auth-brand .name { font-family: var(--font-display); font-weight: 700; font-size: 1.45rem; color: var(--ink); letter-spacing: -0.01em; }
.auth-brand .name small { display: block; color: var(--ink-faint); font-weight: 500; font-size: 0.6em; letter-spacing: 0.12em; text-transform: uppercase; margin-top: 2px; }
.auth-card { padding: var(--space-6); text-align: left; }
.auth-card h1 { font-size: 1.35rem; margin-bottom: var(--space-4); text-align: center; }
.auth-card .input { margin-bottom: var(--space-4); }
.auth-card .btn { margin-top: var(--space-2); }
.auth-switch { text-align: center; color: var(--ink-mute); font-size: 0.92rem; margin-top: var(--space-4); }
.auth-switch a { font-weight: 600; }
.error-msg {
  background: var(--bad-soft); color: var(--bad-ink);
  border-radius: var(--r-sm); padding: 10px 14px; margin-bottom: var(--space-4);
  font-size: 0.92rem;
}
.auth-note { text-align: center; font-size: 0.8rem; color: var(--ink-faint); margin-top: var(--space-5); line-height: 1.6; }

/* ---------------------------------------------------------------------------
   12. Toast
   ------------------------------------------------------------------------- */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(8px);
  background: var(--ink); color: var(--bg);
  padding: 11px 20px; border-radius: var(--r-pill);
  font-size: 0.92rem; font-weight: 500; z-index: 90;
  max-width: 92vw; box-shadow: var(--shadow-lift);
  opacity: 0; transition: opacity var(--speed) var(--ease), transform var(--speed) var(--ease);
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.hidden { display: block; visibility: hidden; }
.toast.err { background: var(--bad); color: #fff; }

/* ---------------------------------------------------------------------------
   13. Empty & loading states
   ------------------------------------------------------------------------- */
.empty { text-align: center; padding: clamp(40px, 8vw, 80px) var(--space-5); }
.empty-glyph {
  width: 72px; height: 72px; margin: 0 auto var(--space-4);
  border-radius: 22px; display: grid; place-items: center;
  background: var(--surface); border: 1px dashed var(--line-strong); color: var(--ink-faint);
}
.empty-glyph svg { width: 30px; height: 30px; }
.empty h2 { font-size: 1.35rem; margin-bottom: 6px; }
.empty p { color: var(--ink-mute); max-width: 44ch; margin: 0 auto var(--space-5); }

.loading {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--space-4); padding: var(--space-8) 0; color: var(--ink-mute);
}
.loading-mark { animation: pulse 1.3s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 0.45; } 50% { opacity: 1; } }

/* Skeleton shimmer for first paint */
.skel { border-radius: var(--r-md); background: linear-gradient(100deg, var(--bg-soft) 40%, var(--surface-2) 50%, var(--bg-soft) 60%); background-size: 200% 100%; animation: shimmer 1.3s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------------------------------------------------------------------------
   14. Review shell — focused, minimal
   ------------------------------------------------------------------------- */
.review-shell {
  position: fixed; inset: 0; z-index: 60;
  background: var(--bg);
  overflow-y: auto;
  animation: rvFade 240ms var(--ease);
}
@keyframes rvFade { from { opacity: 0; } to { opacity: 1; } }

body.no-scroll { overflow: hidden; }

.review-shell-inner { max-width: 720px; margin: 0 auto; padding: 0 var(--space-5) var(--space-7); display: flex; flex-direction: column; min-height: 100%; }

.review-topbar {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: 14px 0 0;
}
.review-topbar .icon-btn { width: 40px; height: 40px; }
.review-toplabel {
  font-family: var(--font-display); font-weight: 600; font-size: 0.78rem;
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-faint);
}
.review-topmeta { display: flex; align-items: center; gap: var(--space-3); }
.review-count { font-size: 0.82rem; color: var(--ink-mute); font-variant-numeric: tabular-nums; font-weight: 600; }
.review-quit { font-size: 0.8rem; color: var(--ink-faint); }

.review-stage { flex: 1; display: flex; flex-direction: column; padding-top: var(--space-4); }
.review-stage:focus { outline: none; }

/* Progress dashes along the top of the review area */
.rv-dashes { display: flex; gap: 5px; justify-content: center; margin: 6px 0 4px; }
.rv-dashes i { height: 3px; border-radius: 2px; background: color-mix(in srgb, var(--ink) 14%, transparent); flex: 1; max-width: 46px; transition: background 300ms var(--ease); }
.rv-dashes i.past { background: var(--line-strong); }
.rv-dashes i.cur { background: var(--accent); }

/* Card context line: grammar pattern being practiced */
.rv-context-line { text-align: center; margin: var(--space-4) 0 var(--space-2); }
.rv-pattern {
  display: inline-flex; align-items: center; gap: 9px;
  font-family: var(--font-jp); font-weight: 700; font-size: 1.14rem;
  color: var(--ink-soft); letter-spacing: 0.02em;
  background: var(--surface); border: 1px solid var(--line);
  padding: 7px 16px; border-radius: var(--r-pill);
  box-shadow: var(--shadow-paper);
}
.rv-pattern .cat { font-family: var(--font-body); font-weight: 600; font-size: 0.62rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-faint); border-left: 1px solid var(--line); padding-left: 9px; }

/* The main card */
.rv-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-paper);
  padding: clamp(22px, 5vw, 42px);
  animation: rvCardIn 280ms var(--ease);
  margin-bottom: var(--space-4);
}
@keyframes rvCardIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.rv-card.is-flipping { animation: rvFlip 260ms var(--ease); }
@keyframes rvFlip { 50% { opacity: 0; transform: translateY(-7px) scale(0.995); } }

/* Prompt block — what to recall */
.rv-prompt-label {
  text-align: center;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--ink-faint); margin-bottom: 4px;
}
.rv-context { text-align: center; font-size: 0.94rem; color: var(--ink-faint); font-style: italic; max-width: 50ch; margin: 0 auto 2px; }
.rv-english {
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 4vw, 1.9rem);
  font-weight: 650; line-height: 1.35; letter-spacing: -0.01em;
  text-align: center; color: var(--ink);
  margin: 6px 0 0;
}

/* Answer input zone */
.rv-answer-zone { margin-top: var(--space-6); }
.answer-input {
  font-family: var(--font-jp); font-size: clamp(1.25rem, 4vw, 1.55rem);
  text-align: center; letter-spacing: 0.02em;
  padding: 16px 18px;
  border: 1.5px solid var(--line-strong); border-radius: var(--r-md);
  background: var(--surface); color: var(--ink); width: 100%;
  transition: border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
}
.answer-input::placeholder { color: var(--ink-faint); font-size: 0.75em; }
.answer-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.answer-input:disabled { background: var(--surface-2); color: var(--ink-faint); border-color: var(--line); }
.answer-input.ok { border-color: var(--ok); background: var(--ok-soft); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 18%, transparent); }
.answer-input.no { border-color: var(--bad); background: var(--bad-soft); box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 16%, transparent); }

.rv-input-row { display: flex; gap: 10px; align-items: stretch; }
.rv-input-row .answer-input { flex: 1; }
.rv-check-btn { padding: 0 26px; flex-shrink: 0; font-size: 1.02rem; }

.answer-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: 0.8rem; color: var(--ink-faint); }
.kbd { font-family: var(--font-body); background: var(--surface-2); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 6px; font-size: 0.74rem; color: var(--ink-mute); }

/* Verdict */
.rv-verdict {
  margin-top: var(--space-5); border-radius: var(--r-md);
  padding: var(--space-4) var(--space-5);
  display: flex; align-items: flex-start; gap: 12px;
  animation: verdictIn 300ms var(--ease);
}
@keyframes verdictIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.answer-input.warn { border-color: var(--warn); background: var(--warn-soft); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 18%, transparent); }
.rv-verdict .v-ic { flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 0.9rem; margin-top: 1px; }
.rv-verdict.correct { background: var(--ok-soft); }
.rv-verdict.correct .v-ic { background: var(--ok); color: #fff; }
.rv-verdict.correct .v-title { color: var(--ok-ink); }
.rv-verdict.partial { background: var(--warn-soft); }
.rv-verdict.partial .v-ic { background: var(--warn); color: #fff; }
.rv-verdict.partial .v-title { color: var(--warn-ink); }
.rv-verdict.incorrect { background: var(--bad-soft); }
.rv-verdict.incorrect .v-ic { background: var(--bad); color: #fff; }
.rv-verdict.incorrect .v-title { color: var(--bad-ink); }
.rate-btn.highlight-rating { border-color: var(--accent); background: var(--accent-soft-2); box-shadow: 0 0 0 2px var(--accent-soft); }
.rv-verdict .v-body { flex: 1; min-width: 0; }
.rv-verdict .v-title { font-family: var(--font-display); font-weight: 700; font-size: 1.02rem; }
.rv-verdict .v-note { font-size: 0.82rem; opacity: 0.8; margin-top: 1px; }

/* Answer comparison */
.rv-compare { margin-top: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); }
.rv-compare-row { display: grid; grid-template-columns: 96px 1fr; gap: var(--space-3); align-items: baseline; }
.rv-compare-row .k { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-faint); }
.rv-compare-row .jp-ans { font-family: var(--font-jp); font-size: 1.3rem; font-weight: 600; color: var(--ink); line-height: 1.6; }
.rv-compare-row .furi { color: var(--ink-faint); font-size: 0.85rem; }
.rv-compare-row .jp-ans.mine { color: var(--ink-mute); }
.rv-compare-row .jp-ans.mine.mismatch { color: var(--bad-ink); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--bad) 60%, transparent); text-decoration-thickness: 2px; }

/* Rating controls */
.rv-ratings { margin-top: var(--space-5); animation: verdictIn 300ms var(--ease); }
.rv-ratings .rate-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.rate-btn {
  border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink); font: inherit; font-family: var(--font-display); font-weight: 600;
  padding: 13px 8px 11px; border-radius: var(--r-md); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  transition: transform var(--speed) var(--ease), border-color var(--speed) var(--ease), background var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
}
.rate-btn:hover { transform: translateY(-2px); }
.rate-btn:active { transform: translateY(0); }
.rate-btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.rate-btn .rt { font-size: 1.02rem; }
.rate-btn .ks { font-size: 0.66rem; color: var(--ink-faint); font-weight: 500; letter-spacing: 0.04em; }
.rate-btn[data-r="1"]:hover { border-color: var(--bad); background: var(--bad-soft); color: var(--bad-ink); }
.rate-btn[data-r="2"]:hover { border-color: var(--warn); background: var(--warn-soft); color: var(--warn-ink); }
.rate-btn[data-r="3"]:hover { border-color: var(--ok); background: var(--ok-soft); color: var(--ok-ink); }
.rate-btn[data-r="4"]:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }
.rate-tip { text-align: center; margin-top: 12px; font-size: 0.78rem; color: var(--ink-faint); }

/* Session finish */
.finish-wrap { text-align: center; padding: clamp(30px, 8vh, 70px) 0; }
.finish-stamp { margin: 0 auto var(--space-5); }
.finish-wrap h1 { font-size: clamp(1.9rem, 5vw, 2.6rem); margin-bottom: 8px; }
.finish-wrap .finish-sub { color: var(--ink-mute); max-width: 44ch; margin: 0 auto; }
.finish-stats { display: flex; justify-content: center; gap: clamp(20px, 6vw, 56px); margin: var(--space-6) 0 var(--space-6); }
.finish-stat { display: flex; flex-direction: column; }
.finish-stat .n { font-family: var(--font-display); font-weight: 700; font-size: clamp(2rem, 5vw, 2.7rem); line-height: 1; color: var(--ink); font-variant-numeric: tabular-nums; }
.finish-stat .n.ok { color: var(--ok-ink); }
.finish-stat .k { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-mute); font-weight: 600; margin-top: 6px; }
.finish-actions { display: flex; justify-content: center; gap: var(--space-3); flex-wrap: wrap; }

/* Review loading */
.rv-loading { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); padding: var(--space-8) 0; color: var(--ink-faint); font-size: 0.92rem; }

/* Stamp seal for the finish screen */
.stamp {
  width: 108px; height: 108px;
  border: 4px solid var(--accent); border-radius: 50%;
  display: grid; place-items: center;
  color: var(--accent); font-family: var(--font-display); font-weight: 700;
  transform: rotate(-9deg);
  opacity: 0.9;
  box-shadow: inset 0 0 0 3px var(--bg);
  animation: stampIn 500ms var(--ease) both;
}
@keyframes stampIn { from { transform: rotate(-9deg) scale(1.7); opacity: 0; } to { transform: rotate(-9deg) scale(1); opacity: 0.9; } }
.stamp .s-kanji { font-size: 2.3rem; line-height: 1; }
.stamp .s-sub { font-size: 0.58rem; letter-spacing: 0.18em; margin-top: 2px; font-weight: 600; }

/* ---------------------------------------------------------------------------
   14b. Book groups (lessons page)
   ------------------------------------------------------------------------- */
.book-groups { display: flex; flex-direction: column; gap: var(--space-6); }
.book-group { display: flex; flex-direction: column; gap: var(--space-3); }
.book-head {
  display: flex; align-items: baseline; gap: var(--space-3);
  padding-bottom: 8px; border-bottom: 2px solid var(--accent);
}
.book-title {
  font-family: var(--font-display); font-weight: 700; font-size: 1.12rem;
  letter-spacing: -0.01em; color: var(--ink);
  min-width: 0; overflow-wrap: anywhere;
}
.book-count {
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--ink-faint); white-space: nowrap;
}
.book-group .lesson-list { margin-top: 2px; }

/* ---------------------------------------------------------------------------
   14c. Two-level curriculum navigation (grammar page)
   ------------------------------------------------------------------------- */
.gd-nav-wrap { display: flex; flex-direction: column; gap: var(--space-4); margin: var(--space-5) 0 var(--space-3); }
.gd-nav-wrap:empty { display: none; margin: 0; }
.nav-group { display: flex; flex-direction: column; gap: 7px; }
.nav-group-label {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--ink-faint);
}
.nav-group-label::after { content: ""; height: 1px; flex: 1; background: var(--line); }
.nav-pos { color: var(--accent-ink); font-variant-numeric: tabular-nums; }
.nav-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.nav-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 16px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--line);
  text-decoration: none; color: var(--ink);
  box-shadow: var(--shadow-paper);
  min-width: 0;
  transition: transform var(--speed) var(--ease), box-shadow var(--speed) var(--ease), border-color var(--speed) var(--ease);
}
.nav-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-lift); border-color: var(--line-strong); }
.nav-btn.is-disabled { opacity: 0.42; cursor: default; box-shadow: none; }
.nav-btn.is-disabled:hover { transform: none; box-shadow: none; border-color: var(--line); }
.nav-arrow {
  flex-shrink: 0; width: 26px; height: 26px; border-radius: 8px;
  display: grid; place-items: center;
  font-size: 1.25rem; line-height: 1;
  background: var(--bg-soft); color: var(--ink-soft);
}
.nav-btn.nav-gp .nav-arrow { background: var(--accent-soft); color: var(--accent-ink); }
.nav-btn.nav-gp .nav-label { color: var(--accent-ink); }
.nav-btn.is-disabled .nav-arrow { background: var(--bg-soft); color: var(--ink-faint); }
.nav-body { display: flex; flex-direction: column; gap: 0; min-width: 0; flex: 1; }
.nav-label { font-size: 0.66rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-faint); }
.nav-text {
  font-family: var(--font-display); font-weight: 600; font-size: 0.96rem;
  color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nav-btn.is-disabled .nav-text { color: var(--ink-faint); }

/* ---------------------------------------------------------------------------
   14d. Developer Mode drawer (technical, contained — never affects normal users)
   ------------------------------------------------------------------------- */
.dev-shell { position: fixed; inset: 0; z-index: 80; }
.dev-backdrop { position: absolute; inset: 0; background: rgba(20, 14, 8, 0.45); backdrop-filter: blur(2px); }
.dev-drawer {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: min(440px, 92vw);
  background: var(--surface); border-left: 1px solid var(--line-strong);
  box-shadow: var(--shadow-lift);
  display: flex; flex-direction: column;
  animation: devSlideIn 220ms var(--ease);
}
@keyframes devSlideIn { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.dev-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.dev-title { display: flex; align-items: center; gap: 9px; font-family: var(--font-display); font-weight: 700; font-size: 1rem; }
.dev-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.dev-body { flex: 1; overflow-y: auto; padding: 6px 0 var(--space-6); }
.dev-section { padding: var(--space-3) 18px 0; }
.dev-subhead {
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--accent-ink); margin-bottom: 6px;
}
.dev-line { display: flex; gap: 12px; align-items: baseline; padding: 3px 0; font-size: 0.84rem; min-width: 0; }
.dev-line .dev-k { flex-shrink: 0; width: 74px; color: var(--ink-faint); font-size: 0.72rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
.dev-line .dev-v { color: var(--ink-soft); min-width: 0; overflow-wrap: anywhere; }
.dev-mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 0.76rem; }
.dev-n { color: var(--ink-faint); font-weight: 600; }
.dev-scroll { max-height: 46vh; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--r-sm); }
.dev-book {
  padding: 7px 12px; font-size: 0.78rem; font-weight: 700;
  color: var(--accent-ink); background: var(--accent-soft-2);
  border-bottom: 1px solid var(--line); position: sticky; top: 0;
}
.dev-row {
  display: flex; gap: 10px; align-items: baseline; width: 100%;
  padding: 8px 12px; border: none; border-bottom: 1px dashed var(--line);
  background: transparent; color: var(--ink-soft);
  font: inherit; font-size: 0.8rem; text-align: left; cursor: pointer;
  min-width: 0;
}
.dev-row:hover { background: var(--bg-soft); color: var(--ink); }
.dev-row .dev-k { flex-shrink: 0; font-family: ui-monospace, Consolas, monospace; font-size: 0.74rem; color: var(--ink-mute); }
.dev-gp-row { padding-left: 26px; }
.dev-gp-row .dev-k { color: var(--accent-ink); }
.dev-lesson-row .dev-k { color: var(--ink-soft); }
.dev-lesson-row .dev-v { color: var(--ink-faint); }
.dev-row .dev-v { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dev-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.dev-loading, .dev-error { padding: var(--space-5) 18px; color: var(--ink-faint); font-size: 0.88rem; }
.dev-error { color: var(--bad-ink); }

/* ---------------------------------------------------------------------------
   14e. Developer chip (review card + grammar example cards)
   ------------------------------------------------------------------------- */
.dev-chip-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: 0.8rem; font-weight: 600;
  color: var(--ink-faint); background: transparent;
  border: 1px dashed var(--line-strong); border-radius: var(--r-pill);
  padding: 4px 12px; cursor: pointer;
  transition: color var(--speed) var(--ease), border-color var(--speed) var(--ease), background var(--speed) var(--ease);
}
.dev-chip-btn svg { width: 13px; height: 13px; }
.dev-chip-btn:hover { color: var(--accent-ink); border-color: var(--accent); background: var(--accent-soft-2); }
.ex-dev-edit {
  font: inherit; font-size: 0.72rem; font-weight: 600;
  color: var(--ink-faint); background: var(--bg-soft);
  border: 1px solid transparent; border-radius: var(--r-pill);
  padding: 2px 10px; cursor: pointer; margin-left: auto;
  transition: color var(--speed) var(--ease), background var(--speed) var(--ease);
}
.ex-dev-edit:hover { color: var(--accent-ink); background: var(--accent-soft-2); }
/* Dev row inside the review card: hint + edit, kept out of the learner flow */
.rv-dev-actions {
  display: flex; align-items: center; justify-content: center;
  gap: 10px; margin-top: 14px; min-height: 0;
}
.rv-dev-hint {
  font-size: 0.74rem; font-weight: 600; letter-spacing: 0.02em;
  color: var(--warn-ink); background: var(--warn-soft);
  border-radius: var(--r-pill); padding: 3px 12px;
}
.rv-english + .rv-dev-actions { margin-top: 4px; }

/* ---------------------------------------------------------------------------
   14f. Example editor modal (Developer Mode content QA)
   ------------------------------------------------------------------------- */
.edit-shell { position: fixed; inset: 0; z-index: 85; display: flex; align-items: center; justify-content: center; }
.edit-backdrop { position: absolute; inset: 0; background: rgba(20, 14, 8, 0.5); backdrop-filter: blur(2px); }
.edit-dialog {
  position: relative; width: min(620px, 94vw); max-height: 88vh;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--r-lg); box-shadow: var(--shadow-lift);
  animation: editIn 200ms var(--ease);
}
@keyframes editIn { from { opacity: 0; transform: translateY(10px) scale(0.99); } to { opacity: 1; transform: none; } }
.edit-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 18px; border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.edit-title { display: flex; align-items: center; gap: 9px; font-family: var(--font-display); font-weight: 700; font-size: 1.02rem; }
.edit-pen { color: var(--accent-ink); }
.edit-body { flex: 1; overflow-y: auto; padding: var(--space-4) 18px var(--space-5); }
.edit-loading, .edit-error { padding: var(--space-6) 0; text-align: center; color: var(--ink-faint); }
.edit-error { color: var(--bad-ink); }
.edit-meta {
  display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center;
  font-family: ui-monospace, Consolas, monospace; font-size: 0.74rem;
  color: var(--ink-mute); background: var(--bg-soft);
  border-radius: var(--r-sm); padding: 6px 12px; margin-bottom: var(--space-3);
  min-width: 0;
}
.edit-details { margin-bottom: var(--space-3); }
.edit-details summary {
  cursor: pointer; font-size: 0.74rem; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--ink-faint);
}
.edit-detail-grid {
  display: grid; grid-template-columns: auto 1fr; gap: 3px 16px;
  margin-top: 8px; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: var(--r-sm); font-size: 0.8rem; min-width: 0;
}
.edit-detail-grid .k { color: var(--ink-faint); font-size: 0.7rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; padding-top: 2px; }
.edit-detail-grid .v { color: var(--ink-soft); min-width: 0; overflow-wrap: anywhere; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace !important; font-size: 0.86rem !important; }
.edit-warnings { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--space-3); }
.edit-warn {
  font-size: 0.82rem; color: var(--warn-ink); background: var(--warn-soft);
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  border-radius: var(--r-sm); padding: 7px 12px;
}
.edit-fields { display: flex; flex-direction: column; gap: var(--space-3); }
.edit-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.edit-label { font-size: 0.78rem; font-weight: 700; color: var(--ink-soft); display: flex; align-items: baseline; gap: 7px; flex-wrap: wrap; }
.edit-label .req { color: var(--bad-ink); font-style: normal; }
.edit-hint { font-weight: 500; font-size: 0.72rem; color: var(--ink-faint); }
.edit-input {
  font: inherit; font-size: 0.96rem; line-height: 1.6;
  padding: 9px 12px; width: 100%; resize: vertical;
  background: var(--surface); color: var(--ink);
  border: 1.5px solid var(--line-strong); border-radius: var(--r-sm);
  transition: border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
  min-width: 0;
}
.edit-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.edit-input.mono { font-family: var(--font-jp); font-size: 1.05rem !important; }
.edit-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: var(--space-4); }
.edit-actions .btn { min-width: 96px; }
.edit-foot { font-size: 0.72rem; color: var(--ink-faint); margin: var(--space-3) 0 0; }
.edit-ordering-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 600px) { .edit-ordering-grid { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------------------
   15. Motion
   ------------------------------------------------------------------------- */
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.fade-up { animation: fadeUp 340ms var(--ease) both; }
.fade-up-1 { animation: fadeUp 340ms var(--ease) 60ms both; }
.fade-up-2 { animation: fadeUp 340ms var(--ease) 120ms both; }
@keyframes popIn { from { opacity: 0; transform: scale(0.94); } to { opacity: 1; transform: scale(1); } }
.pop-in { animation: popIn 240ms var(--ease) both; }

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  html { scroll-behavior: auto; }
}

/* ---------------------------------------------------------------------------
   16. Responsive
   ------------------------------------------------------------------------- */

/* Global overflow guards — the underlying cause of mobile horizontal
   scrolling is unbreakable content: long words, nowrap text and fixed-size
   rows escaping flexible containers. These let text wrap everywhere while
   keeping layout sane. */
main { min-width: 0; }
img, svg, canvas { max-width: 100%; }
.gd-pattern, .gd-meaning, .gd-meaning-id, .gd-block .body,
.lesson-title, .lesson-desc, .gp-meaning, .gp-grammar,
.rv-english, .rv-context, .rv-pattern, .ex-card .jp,
.lesson-hero .lhs, .page-sub, .hero-copy, .auth-note,
.formation-box, .f-pattern, .f-note, .book-title,
.nav-btn, .dev-v, .edit-input { overflow-wrap: anywhere; }

@media (max-width: 900px) {
  .ex-grid { grid-template-columns: 1fr; }
  /* Nav strips must never force a wide row on tablets */
  .gd-nav-wrap { margin-top: var(--space-4); }
}

@media (max-width: 640px) {
  :root { --space-6: 26px; }
  .header-inner { padding: 8px var(--space-4); gap: var(--space-2); }
  .brand-sub, #brand .brand-word .brand-sub { display: none; }
  #app-header nav { margin-left: 0; }
  #app-header nav a { padding: 7px 10px; font-size: 0.9rem; }
  main { padding: var(--space-4) var(--space-4) var(--space-7); }
  .hero-numbers { width: 100%; justify-content: space-between; }
  .hero-num { border-right: none; padding: 0; }
  .dash-hero-side { flex-basis: 100%; }
  .stat-strip { grid-template-columns: 1fr; }
  .stat-cell { padding: 14px 16px; }
  .quick-row, .lesson-list { grid-template-columns: 1fr; }
  .gp-side .progress-line { width: 76px; }
  .form-grid { grid-template-columns: 1fr; }
  .rv-input-row { flex-direction: column; }
  .rv-check-btn { width: 100%; padding: 14px; }
  .rate-btn .ks { display: none; }
  .rv-ratings .rate-row { gap: 8px; }
  .review-shell-inner { padding: 0 var(--space-4) var(--space-6); }
  .rv-compare-row { grid-template-columns: 1fr; gap: 2px; }
  .finish-stats { gap: 26px; }
  .lesson-hero .rhs { align-items: stretch; width: 100%; }
  .lesson-hero .rhs .btn { width: 100%; }
  .gd-actions { flex-direction: column; }
  .gd-actions .btn { width: 100%; }

  /* Review shell: give the input + ratings full comfort width */
  .review-shell-inner { max-width: 100%; }
  .rv-card { padding: var(--space-5) var(--space-4); }

  /* Dev drawer: near-full width */
  .dev-drawer { width: 100vw; }

  /* Editor modal: full-bleed on phones — no horizontal overflow possible */
  .edit-shell { align-items: stretch; }
  .edit-dialog {
    width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh;
    border-radius: 0; border: none;
  }
  .edit-body { padding: var(--space-3) 14px var(--space-5); }
  .edit-actions { position: sticky; bottom: 0; background: var(--surface); padding-top: 10px; }
}

/* Extra-tiny phones (<= 380px): trim nav so two buttons still fit a row */
@media (max-width: 380px) {
  .nav-row { gap: 8px; }
  .nav-btn { padding: 10px 10px; gap: 7px; }
  .nav-arrow { width: 22px; height: 22px; font-size: 1.05rem; }
  .nav-label { font-size: 0.6rem; }
  .nav-text { font-size: 0.88rem; }
  #app-header nav a { padding: 7px 8px; font-size: 0.86rem; }
  .header-actions { gap: 2px; }
}

/* Narrow phones: let the primary nav wrap onto its own centered row so the
   header never forces horizontal page scrolling. */
@media (max-width: 560px) {
  .header-inner { flex-wrap: wrap; row-gap: 4px; padding-bottom: 8px; }
  #app-header nav {
    order: 3; flex: 1 1 100%; margin-left: 0;
    justify-content: center; margin-top: 2px;
  }
  #app-header nav a { padding: 6px 12px; }
  .header-actions { margin-left: auto; }
}

/* Keep the review pattern pill from overflowing its row on small screens */
.rv-context-line { overflow: hidden; }
.rv-pattern { max-width: 100%; flex-wrap: wrap; justify-content: center; text-align: center; }

/* ---------------------------------------------------------------------------
   17. V2.1 Grammar Cloze Practice Styles
   ------------------------------------------------------------------------- */
.rv-mode-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  background: var(--accent-soft);
  color: var(--accent-ink);
  margin-left: 8px;
  vertical-align: middle;
}

.rv-cloze-prompt {
  text-align: center;
  margin: var(--space-4) 0 var(--space-2);
}

.rv-cloze-sentence {
  font-family: var(--font-jp);
  font-size: clamp(1.4rem, 4.5vw, 2.1rem);
  font-weight: 700;
  line-height: 1.5;
  color: var(--ink);
  letter-spacing: 0.02em;
  margin-bottom: 10px;
}

.cloze-blank {
  display: inline-block;
  min-width: 60px;
  padding: 0 10px;
  margin: 0 4px;
  border-bottom: 3px solid var(--accent);
  color: var(--accent);
  background: var(--accent-soft-2);
  border-radius: var(--r-xs);
  font-weight: 800;
  text-align: center;
  letter-spacing: 2px;
}

.cloze-target-filled {
  color: var(--ok-ink);
  font-weight: 800;
  text-decoration: underline;
  text-decoration-thickness: 3px;
  text-underline-offset: 4px;
  background: var(--ok-soft);
  padding: 2px 6px;
  border-radius: var(--r-xs);
}

.rv-cloze-full-sentence {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: var(--space-3);
  align-items: baseline;
}

.rv-cloze-full-sentence .jp-sentence {
  font-family: var(--font-jp);
  font-size: 1.2rem;
  line-height: 1.6;
  color: var(--ink-soft);
}

.cloze-explanations {
  margin-top: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cloze-exp-block {
  border-radius: var(--r-md);
  padding: 12px 16px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
}

.cloze-exp-block.en {
  border-left: 4px solid var(--accent);
}

.cloze-exp-block.id {
  border-left: 4px solid var(--ok);
}

.cloze-exp-block .exp-header {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  display: flex;
  align-items: center;
  gap: 6px;
}

.cloze-exp-block .exp-tag {
  display: inline-block;
  font-size: 0.62rem;
  padding: 1px 6px;
  border-radius: var(--r-xs);
  font-weight: 800;
}

.cloze-exp-block.en .exp-tag {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.cloze-exp-block.id .exp-tag {
  background: var(--ok-soft);
  color: var(--ok-ink);
}

.cloze-exp-block .exp-text {
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--ink-soft);
  margin: 0;
}

.edit-fields-section-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.88rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-ink);
  padding-bottom: 6px;
  border-bottom: 1.5px solid var(--accent);
  margin-bottom: var(--space-3);
}

.edit-cloze-toggle-wrap {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 10px 14px;
  margin-bottom: var(--space-3);
}

.edit-checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--ink);
}

.edit-checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ============================================================================
   V2.2 Particle & Function Retrieval Practice
   ========================================================================== */
.particle-gap {
  display: inline-block;
  min-width: 68px;
  padding: 0 12px;
  margin: 0 4px;
  border-bottom: 3px solid var(--accent);
  color: var(--accent);
  background: var(--accent-soft-2);
  border-radius: var(--r-xs);
  font-weight: 800;
  text-align: center;
  letter-spacing: 2px;
  animation: pulse-subtle 2s infinite ease-in-out;
}

@keyframes pulse-subtle {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.75; }
}

.function-highlight {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 800;
  padding: 2px 8px;
  border-radius: var(--r-xs);
  border-bottom: 2.5px solid var(--accent);
}

.particle-filled {
  color: var(--ok-ink);
  font-weight: 800;
  text-decoration: underline;
  text-decoration-thickness: 3px;
  text-underline-offset: 4px;
  background: var(--ok-soft);
  padding: 2px 8px;
  border-radius: var(--r-xs);
}

/* Choice Grid (Multiple Choice) */
.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: var(--space-4);
  margin-bottom: var(--space-3);
  width: 100%;
}

@media (max-width: 600px) {
  .choice-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
}

.choice-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--speed) var(--ease);
  box-shadow: var(--shadow-paper);
  text-align: left;
  user-select: none;
  position: relative;
}

.choice-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--surface-2);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lift);
}

.choice-btn:active:not(:disabled) {
  transform: translateY(0);
}

.choice-btn.selected {
  border-color: var(--accent);
  background: var(--accent-soft-2);
  color: var(--accent-ink);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.choice-btn .choice-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--r-xs);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--ink-mute);
  font-size: 0.78rem;
  font-weight: 700;
  font-family: var(--font-display);
  flex-shrink: 0;
  transition: all var(--speed) var(--ease);
}

.choice-btn.selected .choice-key {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.choice-btn .choice-text {
  flex: 1;
  font-family: var(--font-jp);
}

.choice-btn.choice-function .choice-text {
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
}

/* Verdict highlights on choices */
.choice-btn.is-correct {
  border-color: var(--ok);
  background: var(--ok-soft) !important;
  color: var(--ok-ink) !important;
  font-weight: 700;
}

.choice-btn.is-correct .choice-key {
  background: var(--ok);
  color: #fff;
  border-color: var(--ok);
}

.choice-btn.is-wrong {
  border-color: var(--bad);
  background: var(--bad-soft) !important;
  color: var(--bad-ink) !important;
  text-decoration: line-through;
}

.choice-btn.is-wrong .choice-key {
  background: var(--bad);
  color: #fff;
  border-color: var(--bad);
}

.choice-btn:disabled {
  cursor: default;
  opacity: 0.75;
}

.choice-btn.is-correct:disabled,
.choice-btn.is-wrong:disabled {
  opacity: 1;
}

.choice-btn .choice-status-icon {
  margin-left: auto;
  font-weight: 800;
  font-size: 1.1rem;
}

/* ---------------------------------------------------------------------------
 * Sentence Ordering (V2.3)
 * ------------------------------------------------------------------------- */
.ordering-wrap {
  width: 100%;
  margin-top: var(--space-3);
  margin-bottom: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ordering-tray-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-mute);
  padding: 0 4px;
}

.ordering-tray {
  background: var(--surface-2);
  border: 2px dashed var(--line);
  border-radius: var(--r-md);
  padding: 12px 14px;
  min-height: 64px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  transition: all var(--speed) var(--ease);
}

.ordering-tray.has-items {
  border-style: solid;
  border-color: var(--line-strong, var(--line));
  background: var(--surface);
}

.ordering-tray.is-complete {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.ordering-tray-placeholder {
  color: var(--ink-subtle, var(--ink-mute));
  font-size: 0.95rem;
  font-style: italic;
  width: 100%;
  text-align: center;
  padding: 8px 0;
  user-select: none;
}

.ordering-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--r-sm);
  background: var(--surface);
  border: 1.5px solid var(--line);
  color: var(--ink);
  font-family: var(--font-jp);
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: all var(--speed) var(--ease);
  box-shadow: var(--shadow-paper);
}

.ordering-chip:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--surface-2);
  transform: translateY(-1px);
}

.ordering-chip.placed {
  background: var(--accent-soft-2);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.ordering-chip.placed:hover {
  border-color: var(--bad);
  background: var(--bad-soft);
  color: var(--bad-ink);
}

.ordering-chip.placed .ordering-remove-icon {
  font-size: 0.8rem;
  opacity: 0.6;
  margin-left: 2px;
}

.ordering-chip.placed:hover .ordering-remove-icon {
  opacity: 1;
}

.ordering-pos {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  font-family: var(--font-display);
  flex-shrink: 0;
}

.ordering-chip.placed:hover .ordering-pos {
  background: var(--bad);
}

.ordering-bank-header {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-mute);
  padding: 0 4px;
  margin-top: 4px;
}

.ordering-bank {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  width: 100%;
}

@media (max-width: 600px) {
  .ordering-bank {
    grid-template-columns: 1fr;
    gap: 8px;
  }
}

.ordering-bank-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  color: var(--ink);
  font-family: var(--font-jp);
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--speed) var(--ease);
  box-shadow: var(--shadow-paper);
  text-align: left;
  user-select: none;
}

.ordering-bank-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--surface-2);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lift);
}

.ordering-bank-btn .choice-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--r-xs);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--ink-mute);
  font-size: 0.78rem;
  font-weight: 700;
  font-family: var(--font-display);
  flex-shrink: 0;
}

.ordering-bank-btn .choice-text {
  flex: 1;
}

.ordering-bank-btn .choice-slot-hint {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ink-faint);
  margin-left: auto;
}

.ordering-bank-btn.is-used {
  opacity: 0.35;
  pointer-events: none;
  border-style: dashed;
  box-shadow: none;
  background: var(--bg-soft);
}

.ordering-reset-btn {
  background: none;
  border: none;
  color: var(--ink-mute);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--r-xs);
  transition: all var(--speed) var(--ease);
}

.ordering-reset-btn:hover {
  color: var(--ink);
  background: var(--bg-soft);
}

.ordering-canonical {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink);
  padding: 10px 14px;
  background: var(--surface-2);
  border-radius: var(--r-md);
  margin-top: 6px;
  font-family: var(--font-jp);
}

.ordering-part-pill {
  display: inline-block;
  padding: 2px 6px;
  margin: 0 2px;
  border-radius: var(--r-xs);
  background: var(--accent-soft-2);
  color: var(--accent-ink);
  font-weight: 700;
}

/* Collapse bank when card is answered to keep ratings visible */
.rv-card.is-answered .ordering-bank,
.rv-card.is-answered .ordering-bank-header,
.rv-card.is-answered .ordering-tray-header .ordering-reset-btn {
  display: none;
}
