/* ==========================================================================
   Kanjr — stylesheet
   Light + dark themes via custom properties; responsive; reduced motion.
   ========================================================================== */

/* --- Tokens ------------------------------------------------------------ */

:root {
  color-scheme: light;

  --font-ui: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Zen Kaku Gothic New", "Noto Sans JP", "Manrope", system-ui, sans-serif;
  --font-jp: "Noto Sans JP", "Hiragino Sans", "Yu Gothic", "Meiryo", "Hiragino Kaku Gothic ProN", "Noto Sans CJK JP", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --bg: #efe8dc;
  --surface: #f6f1e6;
  --surface-2: #e8e0d1;
  --surface-3: #ddd3c2;
  --text: #211b16;
  --text-2: #423a32;
  --muted: #75695d;
  --border: #2a231d;
  --border-strong: #2a231d;
  --line: #d3c8b6;
  --shadow: 4px 4px 0 var(--border);
  --shadow-lg: 6px 6px 0 var(--border);

  --accent: #d7262a;
  --accent-deep: #9e1418;
  --accent-ink: #ffffff;
  --accent-soft: #f8d7d5;
  --gold: #c9a227;
  --gold-soft: #f4e7b6;
  --focus: #d7262a;

  --radical: #17130f;
  --kanji: #d7262a;
  --vocab: #2f5fa8;
  --radical-soft: #e3dacb;
  --kanji-soft: #f8d7d5;

  --apprentice: #e35f5b;
  --guru: #b31e22;
  --master: #5e1113;
  --enlightened: #2b1a1a;
  --burned: #c9a227;
  --locked: #e3dacb;
  --st-1: #f3b4b0;
  --st-2: #ec8a86;
  --st-3: #e35f5b;
  --st-4: #d7262a;
  --st-5: #b31e22;
  --st-6: #8f161a;
  --st-7: #5e1113;
  --st-8: #2b1a1a;
  --st-9: #c9a227;

  --ok: #2f7d4f;
  --ok-soft: #dcefe2;
  --bad: #9e1418;
  --bad-soft: #f8d7d5;
  --warn: #a3741a;
  --warn-soft: #f4e7b6;

  --radius: 18px;
  --radius-sm: 12px;
  --radius-lg: 22px;
  --topbar-h: 56px;
  --tabbar-h: 60px;
  --max-w: 960px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --dur: 180ms;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #2a241f;
    --surface: #332c26;
    --surface-2: #3d352e;
    --surface-3: #4a4139;
    --text: #f3ebde;
    --text-2: #ddd2c3;
    --muted: #b0a394;
    --border: #ebe1d2;
    --border-strong: #ebe1d2;
    --line: #55493f;
    --shadow: 4px 4px 0 #15110e;
    --shadow-lg: 6px 6px 0 #15110e;
    --accent-soft: #4a2325;
    --gold-soft: #3a3012;
    --radical-soft: #332b24;
    --kanji-soft: #3a1516;
    --radical: #ebe1d2;
    --locked: #4a4139;
    --enlightened: #d9c9c9;
    --st-8: #d9c9c9;
    --ok-soft: #14351f;
    --bad-soft: #3d1717;
    --warn-soft: #3b2a0a;
    --focus: #f06a6d;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #2a241f;
  --surface: #332c26;
  --surface-2: #3d352e;
  --surface-3: #4a4139;
  --text: #f3ebde;
  --text-2: #ddd2c3;
  --muted: #b0a394;
  --border: #ebe1d2;
  --border-strong: #ebe1d2;
  --line: #55493f;
  --shadow: 4px 4px 0 #15110e;
  --shadow-lg: 6px 6px 0 #15110e;
  --accent-soft: #4a2325;
  --gold-soft: #3a3012;
  --radical-soft: #332b24;
  --kanji-soft: #3a1516;
  --radical: #ebe1d2;
  --locked: #4a4139;
  --enlightened: #d9c9c9;
  --st-8: #d9c9c9;
  --ok-soft: #14351f;
  --bad-soft: #3d1717;
  --warn-soft: #3b2a0a;
  --focus: #f06a6d;
}

/* --- Base --------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-top: var(--topbar-h);
}

h1, h2, h3, h4 { margin: 0 0 0.5rem; line-height: 1.2; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.125rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.75rem; }
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
kbd {
  font-family: var(--font-mono);
  font-size: 0.75em;
  padding: 0.1em 0.4em;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface-2);
}

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
:focus:not(:focus-visible) { outline: none; }

.jp { font-family: var(--font-jp); }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; top: -60px; left: 12px; z-index: 100;
  padding: 8px 12px; background: var(--accent); color: var(--accent-ink);
  border-radius: var(--radius-sm);
}
.skip-link:focus { top: 8px; }

/* --- Top bar and navigation -------------------------------------------- */

.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 max(16px, env(safe-area-inset-left)) 0 max(16px, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}
@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .topbar { background: var(--surface); }
}

.logo { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.125rem; letter-spacing: -0.02em; }
.logo-mark {
  width: 30px; height: 30px; border-radius: 8px;
  display: grid; place-items: center;
  background: var(--kanji); color: #fff;
  font-family: var(--font-jp); font-size: 1rem; font-weight: 500;
}

.nav { display: flex; gap: 4px; margin-left: 12px; }
.nav a {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  color: var(--muted); font-weight: 500; font-size: 0.9375rem;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav a svg { width: 18px; height: 18px; fill: currentColor; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }

.level-badge {
  margin-left: auto;
  padding: 4px 12px; border-radius: 999px;
  background: var(--text); color: var(--bg);
  font-weight: 700; font-size: 0.8125rem; letter-spacing: 0.02em;
}

/* --- Layout ------------------------------------------------------------- */

.main {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 24px max(16px, env(safe-area-inset-left)) 48px max(16px, env(safe-area-inset-right));
  outline: none;
}
.screen { animation: fade-in 220ms var(--ease); }
.screen-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.screen-head h1 { margin: 0; }
.stack > * + * { margin-top: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 720px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card h2 { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card h2 .muted { font-weight: 500; font-size: 0.8125rem; }

.banner {
  max-width: var(--max-w); margin: 12px auto 0; padding: 10px 16px;
  border-radius: var(--radius-sm); font-size: 0.9rem;
  background: var(--warn-soft); color: var(--text); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.banner[hidden] { display: none; }
.banner-error { background: var(--bad-soft); }
.banner button { margin-left: auto; }

.loading { display: grid; place-items: center; gap: 8px; padding: 80px 0; color: var(--muted); }
.loading-glyph { font-family: var(--font-jp); font-size: 4rem; color: var(--kanji); animation: pulse 1.4s ease-in-out infinite; }

.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty .empty-glyph { font-family: var(--font-jp); font-size: 3.5rem; color: var(--border-strong); margin-bottom: 8px; }
.empty h2 { color: var(--text); }

/* --- Buttons ------------------------------------------------------------ */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 600; font-size: 0.9375rem; line-height: 1.2;
  transition: background var(--dur) var(--ease), transform var(--dur) var(--ease), border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  user-select: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px) scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, black); }
.btn-primary kbd { background: rgba(255, 255, 255, 0.18); border-color: rgba(255, 255, 255, 0.45); color: #fff; }
.streak svg { width: 18px; height: 18px; fill: #f97316; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, transparent); }
.btn-danger:hover { background: var(--bad-soft); }
.btn-sm { padding: 6px 12px; font-size: 0.8125rem; }
.btn-lg { padding: 14px 26px; font-size: 1.0625rem; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* Big home buttons */
.big-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 560px) { .big-buttons { grid-template-columns: 1fr; } }
.big-btn {
  position: relative; display: flex; flex-direction: column; justify-content: space-between;
  min-height: 132px; padding: 20px 22px; border-radius: var(--radius-lg);
  color: #fff; overflow: hidden;
  box-shadow: var(--shadow-lg);
  transition: transform var(--dur) var(--ease), filter var(--dur) var(--ease);
}
.big-btn:hover { transform: translateY(-2px); filter: brightness(1.04); }
.big-btn:active { transform: translateY(0); }
.big-btn-lessons { background: var(--surface); color: var(--text); }
.big-btn-reviews { background: var(--accent); color: #fff; border-color: var(--accent-deep); box-shadow: 4px 4px 0 var(--accent-deep); }
.big-btn.is-empty { background: var(--surface-2); color: var(--muted); box-shadow: none; border: 1px solid var(--border); }
.big-btn-label { font-weight: 600; font-size: 1rem; opacity: 0.92; display: flex; align-items: center; gap: 8px; }
.big-btn-count { font-weight: 800; font-size: 2.75rem; letter-spacing: -0.03em; line-height: 1; }
.big-btn-sub { font-size: 0.8125rem; opacity: 0.85; }
.big-btn-glyph {
  position: absolute; right: -10px; bottom: -22px;
  font-family: var(--font-jp); font-size: 7rem; opacity: 0.14; pointer-events: none; line-height: 1;
}

/* --- Chips and badges --------------------------------------------------- */

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 12px 4px 6px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 0.875rem; font-weight: 500; color: var(--text);
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
  cursor: pointer;
}
.chip:hover { transform: translateY(-1px); background: var(--surface-3); }
.chip .chip-glyph {
  font-family: var(--font-jp); font-size: 1rem; line-height: 1;
  width: 26px; height: 26px; display: grid; place-items: center; border-radius: 999px; color: #fff;
}
.chip.type-kanji .chip-glyph { background: var(--kanji); }
.chip.type-radical .chip-glyph { background: var(--radical); }
.chip.type-vocab .chip-glyph { background: var(--vocab); font-size: 0.8em; padding: 0 5px; width: auto; min-width: 1.6em; letter-spacing: 0.02em; }
.chip.is-locked { opacity: 0.55; }
.chip.is-locked .chip-glyph { background: var(--locked); color: var(--text-2); }
.chip .chip-remove { border: 0; background: none; padding: 0 0 0 4px; color: var(--muted); line-height: 1; font-size: 1rem; }
.chip .chip-remove:hover { color: var(--bad); }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px;
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  color: #fff;
}
.badge.type-kanji { background: var(--kanji); }
.badge.type-radical { background: var(--radical); }
.badge.type-vocab { background: var(--vocab); }
.badge.stage-locked { background: var(--locked); color: var(--text-2); }
.badge.stage-apprentice { background: var(--apprentice); }
.badge.stage-guru { background: var(--guru); }
.badge.stage-master { background: var(--master); }
.badge.stage-enlightened { background: var(--enlightened); }
.badge.stage-burned { background: var(--burned); }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); font-size: 0.8125rem; color: var(--text-2); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.dot.stage-apprentice { background: var(--apprentice); }
.dot.stage-guru { background: var(--guru); }
.dot.stage-master { background: var(--master); }
.dot.stage-enlightened { background: var(--enlightened); }
.dot.stage-burned { background: var(--burned); }
.dot.stage-locked { background: var(--locked); }

/* --- Home --------------------------------------------------------------- */

.home-hero { display: flex; align-items: center; gap: 24px; }
.home-hero h1 { margin-bottom: 4px; }
.ring-wrap { position: relative; width: 112px; height: 112px; flex: none; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--surface-3); stroke-width: 9; }
.ring-value { fill: none; stroke: var(--accent); stroke-width: 9; stroke-linecap: round; transition: stroke-dashoffset 900ms var(--ease); }
.ring-label { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; line-height: 1.1; }
.ring-label .ring-level { font-weight: 800; font-size: 1.5rem; letter-spacing: -0.03em; }
.ring-label .ring-sub { font-size: 0.75rem; color: var(--muted); font-weight: 600; }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 12px; }
.stat { padding: 12px; border-radius: var(--radius-sm); background: var(--surface-2); }
.stat .stat-value { font-weight: 800; font-size: 1.5rem; letter-spacing: -0.02em; line-height: 1.1; }
.stat .stat-label { font-size: 0.75rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; margin-top: 4px; }

.streak { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; }
.streak .flame { color: #f97316; }

/* Forecast bars */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 96px; padding-top: 18px; }
.bar { position: relative; flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; min-width: 0; }
.bar-fill {
  background: var(--radical); border-radius: 4px 4px 2px 2px; min-height: 2px;
  transform-origin: bottom; animation: grow 500ms var(--ease) backwards;
  transition: background var(--dur) var(--ease);
}
.bar.is-empty .bar-fill { background: var(--surface-3); }
.bar .bar-count { position: absolute; top: -18px; left: 0; right: 0; text-align: center; font-size: 0.6875rem; font-weight: 700; color: var(--muted); }
.bar-labels { display: flex; gap: 3px; margin-top: 6px; }
.bar-labels span { flex: 1; text-align: center; font-size: 0.6875rem; color: var(--muted); min-width: 0; white-space: nowrap; }
.bars.bars-tall { height: 140px; }
.bar-fill.is-accent { background: var(--accent); }
.bar-fill.is-ok { background: var(--ok); }

.group-counts { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
@media (max-width: 560px) { .group-counts { grid-template-columns: repeat(3, 1fr); } }
.group-count { padding: 12px; border-radius: var(--radius-sm); color: #fff; text-align: center; }
.group-count .n { font-weight: 800; font-size: 1.5rem; letter-spacing: -0.02em; line-height: 1; }
.group-count .l { font-size: 0.6875rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; opacity: 0.9; margin-top: 4px; }
.group-count.stage-apprentice { background: var(--apprentice); }
.group-count.stage-guru { background: var(--guru); }
.group-count.stage-master { background: var(--master); }
.group-count.stage-enlightened { background: var(--enlightened); }
.group-count.stage-burned { background: var(--burned); }

/* --- Glyph card (lessons, reviews, item) ------------------------------- */

.glyph-card {
  position: relative; overflow: hidden;
  text-align: center; padding: 36px 20px 28px;
}
.glyph-card::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 6px;
}
.glyph-card.type-kanji::before { background: var(--kanji); }
.glyph-card.type-radical::before { background: var(--radical); }
.glyph-card.type-vocab::before { background: var(--vocab); }
.glyph {
  font-family: var(--font-jp); font-weight: 500; line-height: 1;
  font-size: min(28vw, 8rem);
  color: var(--text);
  user-select: text;
}
@media (min-width: 640px) { .glyph { font-size: 9rem; } }
/* Words: several characters side by side, sized so the longest still fits. */
.glyph.is-word { font-size: min(18vw, 5.5rem); letter-spacing: 0.02em; white-space: nowrap; }
.glyph.is-word.is-long { font-size: min(13vw, 4rem); }
@media (min-width: 640px) { .glyph.is-word { font-size: 6rem; } .glyph.is-word.is-long { font-size: 4.5rem; } }
.glyph-card .glyph-type { margin-bottom: 8px; }
.glyph-card .glyph-prompt { color: var(--muted); font-size: 0.9375rem; margin-top: 12px; }
.glyph-card .glyph-prompt strong { color: var(--text); }

.glyph-card.is-correct { box-shadow: 0 0 0 3px var(--ok), var(--shadow); }
.glyph-card.is-wrong { box-shadow: 0 0 0 3px var(--bad), var(--shadow); }
.glyph-card.is-typo { box-shadow: 0 0 0 3px var(--warn), var(--shadow); }
.shake { animation: shake 420ms var(--ease); }
.fade-in { animation: fade-in 220ms var(--ease); }

/* --- Reviews ------------------------------------------------------------ */

.review { max-width: 640px; margin: 0 auto; }
.review-top { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; font-weight: 600; }
.review-top .counter { font-variant-numeric: tabular-nums; font-size: 1.0625rem; }
.review-top .accuracy { color: var(--muted); font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.review-top .spacer { flex: 1; }
.review-progress { height: 4px; border-radius: 2px; background: var(--surface-3); overflow: hidden; margin-bottom: 20px; }
.review-progress > div { height: 100%; background: var(--accent); transition: width 300ms var(--ease); }

.answer-form { margin-top: 16px; }
.answer {
  width: 100%; padding: 16px 20px; text-align: center;
  font-size: 1.375rem; font-weight: 500;
  border-radius: var(--radius); border: 2px solid var(--border-strong);
  background: var(--surface); color: var(--text);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  -webkit-appearance: none; appearance: none;
}
.answer::placeholder { color: var(--muted); font-weight: 400; }
.answer:focus { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 20%, transparent); outline: none; }
.answer.is-correct { border-color: var(--ok); background: var(--ok-soft); box-shadow: none; }
.answer.is-wrong { border-color: var(--bad); background: var(--bad-soft); box-shadow: none; }
.answer.is-typo { border-color: var(--warn); background: var(--warn-soft); box-shadow: none; }
.answer:disabled { opacity: 1; }
.answer-hint { text-align: center; color: var(--muted); font-size: 0.8125rem; margin-top: 10px; min-height: 1.25em; }
.answer-hint.is-warn { color: var(--warn); font-weight: 600; }
.answer-hint.is-ok { color: var(--ok); font-weight: 600; }
.answer-hint.is-bad { color: var(--bad); font-weight: 600; }

.feedback { margin-top: 16px; }
.feedback .feedback-answer { font-size: 1.375rem; font-weight: 700; text-align: center; }
.feedback .feedback-alt { text-align: center; color: var(--muted); margin-top: 2px; }
.feedback .feedback-meta { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.feedback .mnemonic { margin-top: 14px; }
.feedback-actions { display: flex; justify-content: center; gap: 10px; margin-top: 16px; }

.mnemonic {
  padding: 14px 16px; border-radius: var(--radius-sm);
  background: var(--surface-2); border-left: 4px solid var(--accent);
  font-size: 0.9375rem; line-height: 1.55; color: var(--text-2);
}
.mnemonic.is-empty { border-left-color: var(--border-strong); font-style: italic; color: var(--muted); }
.mnemonic-note { border-left-color: var(--radical); }

.info-panel { margin-top: 16px; }
.section-label { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 14px 0 6px; }

.session-summary { text-align: center; }
.session-summary h2 { justify-content: center; }
.session-summary .big-number { font-weight: 800; font-size: 3.5rem; letter-spacing: -0.04em; line-height: 1; color: var(--accent); }

/* --- Lessons ------------------------------------------------------------ */

.lesson { max-width: 720px; margin: 0 auto; }
.lesson-dots { display: flex; justify-content: center; gap: 8px; margin: 0 0 16px; }
.lesson-dots span { width: 10px; height: 10px; border-radius: 50%; background: var(--surface-3); transition: background var(--dur) var(--ease), transform var(--dur) var(--ease); }
.lesson-dots span.is-done { background: var(--accent); }
.lesson-dots span.is-current { background: var(--accent); transform: scale(1.35); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.lesson-dots span.is-quiz { border-radius: 3px; }

.lesson-card .glyph { font-size: min(24vw, 7rem); }
@media (min-width: 640px) { .lesson-card .glyph { font-size: 7.5rem; } }
.lesson-name { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.02em; margin-top: 12px; }
.lesson-alt { color: var(--muted); margin-top: 2px; }
.lesson-body { text-align: left; margin-top: 20px; }
.lesson-facts { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
.lesson-nav { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 16px; }

.examples { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.examples li { display: flex; align-items: baseline; gap: 12px; padding: 8px 12px; border-radius: var(--radius-sm); background: var(--surface-2); }
.examples .ex-word { font-family: var(--font-jp); font-size: 1.25rem; font-weight: 500; white-space: nowrap; }
.examples .ex-gloss { color: var(--text-2); font-size: 0.9375rem; }

.parts-inline { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; font-size: 1.25rem; color: var(--muted); }

.peek {
  margin-top: 10px; padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px dashed var(--border-strong);
  display: flex; align-items: center; gap: 14px; text-align: left;
}
.peek .peek-glyph { font-family: var(--font-jp); font-size: 2.25rem; line-height: 1; }
.peek .peek-name { font-weight: 700; }

/* --- Item page ---------------------------------------------------------- */

.item-head { display: flex; gap: 24px; align-items: center; }
.item-head .glyph { font-size: min(24vw, 6rem); }
.item-head .item-title { flex: 1; min-width: 0; }
.item-head .item-title h1 { margin-bottom: 4px; }
.item-facts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 0.9375rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }
.synonym-form { display: flex; gap: 8px; margin-top: 10px; }
.synonym-form input { flex: 1; }

input[type="text"], input[type="number"], select, textarea {
  padding: 9px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  min-width: 0;
}
textarea { width: 100%; min-height: 96px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }

/* --- Levels ------------------------------------------------------------- */

.levels-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.level-card {
  display: flex; flex-direction: column; gap: 6px;
  padding: 12px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.level-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.level-card.is-current { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent); }
.level-card.is-locked { opacity: 0.6; }
.level-card .level-num { font-weight: 800; font-size: 1.25rem; letter-spacing: -0.02em; }
.level-card .level-meta { font-size: 0.75rem; color: var(--muted); }
.level-bar { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.level-bar > div { height: 100%; background: var(--guru); border-radius: 3px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.tile {
  aspect-ratio: 1 / 1; display: grid; place-items: center; position: relative;
  border-radius: var(--radius-sm); color: #fff;
  font-family: var(--font-jp); font-size: 1.75rem; font-weight: 500; line-height: 1;
  background: var(--locked);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.tile:hover { transform: translateY(-2px) scale(1.03); box-shadow: var(--shadow); z-index: 1; }
.tile.stage-locked { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.tile.stage-apprentice { background: var(--apprentice); }
.tile.stage-guru { background: var(--guru); }
.tile.stage-master { background: var(--master); }
.tile.stage-enlightened { background: var(--enlightened); }
.tile.stage-burned { background: var(--burned); }
.tile .tile-mark { position: absolute; top: 4px; left: 6px; width: 8px; height: 8px; border-radius: 50%; }
.tile.type-radical .tile-mark { background: var(--radical); }
.tile.type-kanji .tile-mark { background: var(--kanji); }
.tile.type-vocab .tile-mark { background: var(--vocab); }
.tiles.is-words { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.tile.type-vocab { aspect-ratio: auto; min-height: 64px; padding: 14px 10px 16px; font-size: 1.25rem; white-space: nowrap; }
.tile.stage-locked .tile-mark { opacity: 0.7; }
.tile-name { position: absolute; bottom: 3px; left: 4px; right: 4px; font-family: var(--font-ui); font-size: 0.5625rem; font-weight: 600; text-align: center; opacity: 0.9; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 0.8125rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* --- Stats -------------------------------------------------------------- */

.stage-bars { display: grid; gap: 8px; }
.stage-bar { display: grid; grid-template-columns: 110px 1fr 48px; align-items: center; gap: 10px; font-size: 0.875rem; }
.stage-bar .track { height: 12px; border-radius: 6px; background: var(--surface-3); overflow: hidden; }
.stage-bar .track > div { height: 100%; border-radius: 6px; transform-origin: left; animation: grow-x 600ms var(--ease) backwards; }
.stage-bar .n { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.timeline li { display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center; font-size: 0.875rem; padding: 6px 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }
.timeline .tl-level { font-weight: 700; }
.timeline .tl-date { color: var(--muted); font-variant-numeric: tabular-nums; }

/* --- Settings ----------------------------------------------------------- */

.setting {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; align-items: center;
  padding: 14px 0; border-bottom: 1px solid var(--border);
}
.setting:last-child { border-bottom: 0; }
.setting .setting-label { font-weight: 600; }
.setting .setting-help { grid-column: 1; font-size: 0.8125rem; color: var(--muted); }
.setting .setting-control { grid-row: 1 / span 2; grid-column: 2; }
.setting input[type="number"] { width: 92px; text-align: right; }
.setting select { min-width: 120px; }

.switch { position: relative; display: inline-block; width: 46px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .track {
  position: absolute; inset: 0; border-radius: 999px; background: var(--border-strong);
  transition: background var(--dur) var(--ease); cursor: pointer;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform var(--dur) var(--ease);
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 3px solid var(--focus); outline-offset: 2px; }

.backup-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.backup-list li { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: var(--radius-sm); background: var(--surface-2); font-size: 0.875rem; }
.backup-list li .grow { flex: 1; }

.about p { color: var(--text-2); font-size: 0.9375rem; }
.about a { color: var(--accent); text-decoration: underline; }

/* --- Toasts and dialogs ------------------------------------------------- */

.toasts {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: grid; gap: 8px; z-index: 90; pointer-events: none; width: min(92vw, 420px);
}
.toast {
  pointer-events: auto;
  padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--text); color: var(--bg); font-size: 0.9rem; font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toast-in 240ms var(--ease);
}
.toast.is-error { background: var(--bad); color: #fff; }
.toast.is-ok { background: var(--ok); color: #fff; }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 16px;
  background: rgba(2, 6, 23, 0.55); animation: fade-in 160ms var(--ease);
}
.modal {
  width: min(100%, 440px); padding: 22px; border-radius: var(--radius);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
  animation: pop-in 200ms var(--ease);
}
.modal h2 { margin-bottom: 8px; }
.modal p { color: var(--text-2); }
.modal .btn-row { justify-content: flex-end; margin-top: 16px; }

/* --- Search ------------------------------------------------------------- */

.search { position: relative; }
.search input { width: 100%; }
.search-results { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
.search-results li a { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: var(--radius-sm); }
.search-results li a:hover { background: var(--surface-2); }
.search-results .r-glyph { font-family: var(--font-jp); font-size: 1.5rem; width: 36px; text-align: center; }
.search-results .r-name { font-weight: 600; }
.search-results .r-meta { color: var(--muted); font-size: 0.8125rem; margin-left: auto; }

/* --- Motion ------------------------------------------------------------- */

@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes grow-x { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes pulse { 0%, 100% { opacity: 0.5; } 50% { opacity: 1; } }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  .shake { animation: none; }
  .ring-value { transition: none; }
}

/* --- Mobile: bottom tab bar --------------------------------------------- */

@media (max-width: 639px) {
  body { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  /* No backdrop-filter here: it would make the top bar the containing block
     for the fixed tab bar and pin it to the top instead of the bottom. */
  .topbar { backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--surface); }
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; margin: 0;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding: 6px 8px env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--border);
    display: grid; grid-template-columns: repeat(5, 1fr); gap: 0;
  }
  .nav a {
    flex-direction: column; justify-content: center; gap: 2px;
    padding: 4px 0; border-radius: var(--radius-sm); font-size: 0.6875rem; font-weight: 600;
  }
  .nav a svg { width: 22px; height: 22px; }
  .nav a[aria-current="page"] { background: transparent; }
  .main { padding-top: 16px; }
  .card { padding: 16px; }
  .home-hero { gap: 16px; }
  .ring-wrap { width: 92px; height: 92px; }
  .item-head { gap: 16px; }
  .setting { grid-template-columns: 1fr auto; }
  .toasts { bottom: calc(var(--tabbar-h) + 12px + env(safe-area-inset-bottom)); }
  .review-top .btn kbd { display: none; } /* phones have no Esc key */
}

@media print {
  .topbar, .nav, .toasts { display: none; }
  body { padding: 0; }
}

/* --- Grid screen ------------------------------------------------------- */
.kgrid-controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px; }
.kgrid-key b { font-weight: 600; font-variant-numeric: tabular-nums; margin-left: 2px; }
.kgrid-toggles { display: flex; gap: 18px; flex-wrap: wrap; }
.kgrid-toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 0.875rem; color: var(--text-2); cursor: pointer; }
.kgrid-bar { display: flex; height: 6px; border-radius: 3px; overflow: hidden; background: var(--surface-3); }
.kgrid-bar i { display: block; height: 100%; transition: width 400ms var(--ease); }
.kgrid-bar .stage-apprentice { background: var(--apprentice); }
.kgrid-bar .stage-guru { background: var(--guru); }
.kgrid-bar .stage-master { background: var(--master); }
.kgrid-bar .stage-enlightened { background: var(--enlightened); }
.kgrid-bar .stage-burned { background: var(--burned); }
.kgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(30px, 1fr)); gap: 3px; }
.kcell {
  position: relative; aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-jp); font-size: 0.95rem; font-weight: 500; line-height: 1;
  border-radius: 4px; color: #fff; text-decoration: none;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.kcell:hover, .kcell:focus-visible { transform: scale(1.35); box-shadow: var(--shadow-lg); z-index: 2; outline: none; }
.kcell.stage-locked { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.kcell.stage-apprentice { background: var(--apprentice); }
.kcell.stage-guru { background: var(--guru); }
.kcell.stage-master { background: var(--master); }
.kcell.stage-enlightened { background: var(--enlightened); }
.kcell.stage-burned { background: var(--burned); }
.kcell.type-radical { border-radius: 50%; }
/* The Words tab: cells stretch to the word, flowing in rows. */
.kgrid.is-words { display: flex; flex-wrap: wrap; gap: 4px; }
.kgrid.is-words .kgrid-level { flex: 0 0 auto; width: 30px; }
.kcell.type-vocab { aspect-ratio: auto; height: 30px; padding: 0 7px; font-size: 0.8125rem; white-space: nowrap; }
.kcell.type-vocab:hover, .kcell.type-vocab:focus-visible { transform: scale(1.15); }
.dex-tabs { display: inline-flex; gap: 2px; padding: 3px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.dex-tab { border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 700; font-size: 0.8125rem; padding: 5px 14px; border-radius: 999px; cursor: pointer; }
.dex-tab[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.dex-tab:focus-visible { outline: 2px solid var(--kanji); outline-offset: 1px; }
.kcell.is-due::after { content: ""; position: absolute; top: 2px; right: 2px; width: 5px; height: 5px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,0.25); }
.kgrid-level {
  grid-column: 1 / -1; margin-top: 8px; padding: 0 2px; font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted); text-decoration: none; border-bottom: 1px solid var(--border); line-height: 1.8;
}
.kgrid-level:first-child { margin-top: 0; }
@media (max-width: 640px) {
  .kgrid { grid-template-columns: repeat(auto-fill, minmax(26px, 1fr)); gap: 2px; }
  .kcell { font-size: 0.8rem; border-radius: 3px; }
}

/* --- Grid: selection mode ------------------------------------------- */
.kgrid-select-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.kgrid-select-head h2 { margin-bottom: 4px; }
.kgrid-select-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.kgrid-select-row input { flex: 1 1 260px; font-size: 1.125rem; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); }
.kgrid-select-row input:focus { outline: 2px solid var(--focus); outline-offset: 1px; }
.kgrid.is-selecting .kcell.is-dim { opacity: 0.35; }
.kgrid.is-selecting .kcell.is-selectable { cursor: pointer; border-color: var(--border-strong); }
.kgrid.is-selecting .kcell.is-selectable:hover { transform: scale(1.2); border-color: var(--accent); }
.kgrid.is-selecting .kcell.is-selected { background: var(--accent-soft); color: var(--accent); border: 2px solid var(--accent); font-weight: 600; }
.kgrid-actionbar {
  position: sticky; bottom: calc(var(--tabbar-h) * 0 + 12px); z-index: 20; margin-top: 8px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  font-weight: 600; font-variant-numeric: tabular-nums;
}
@media (max-width: 640px) {
  .kgrid-actionbar { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px); }
}

/* --- Context menu ----------------------------------------------------- */
.ctx-menu {
  position: fixed; z-index: 60; min-width: 220px; padding: 6px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
}
.ctx-menu .ctx-title { padding: 6px 10px 8px; font-size: 0.8125rem; font-weight: 600; color: var(--text-2); border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.ctx-menu .ctx-title .jp { font-size: 1.1rem; margin-right: 4px; }
.ctx-menu button { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none; color: var(--text); font: inherit; font-size: 0.875rem; border-radius: 6px; cursor: pointer; }
.ctx-menu button:hover, .ctx-menu button:focus-visible { background: var(--accent-soft); color: var(--accent); outline: none; }
.kgrid.is-selecting { user-select: none; -webkit-user-select: none; }
.kgrid.is-selecting .kgrid-level { cursor: pointer; }
.kgrid.is-selecting .kgrid-level:hover { color: var(--accent); }

/* --- Sub-stage colours (grid boxes, level tiles, legend dots) ---------- */
.kcell.st-1, .tile.st-1, .dot.st-1 { background: var(--st-1); }
.kcell.st-2, .tile.st-2, .dot.st-2 { background: var(--st-2); }
.kcell.st-3, .tile.st-3, .dot.st-3 { background: var(--st-3); }
.kcell.st-4, .tile.st-4, .dot.st-4 { background: var(--st-4); }
.kcell.st-5, .tile.st-5, .dot.st-5 { background: var(--st-5); }
.kcell.st-6, .tile.st-6, .dot.st-6 { background: var(--st-6); }
.kcell.st-7, .tile.st-7, .dot.st-7 { background: var(--st-7); }
.kcell.st-8, .tile.st-8, .dot.st-8 { background: var(--st-8); }
.kcell.st-9, .tile.st-9, .dot.st-9 { background: var(--st-9); }
.kgrid-key { display: inline-flex; align-items: center; gap: 6px; }
.kgrid-key .dot + .dot { margin-left: -3px; }
.kgrid-key .dot { box-shadow: 0 0 0 1.5px var(--surface); }

/* --- Review typeface variety ------------------------------------------- */
.glyph.font-mincho { font-family: "Noto Serif JP", "Hiragino Mincho ProN", "Yu Mincho", "MS Mincho", serif; font-weight: 500; }
.glyph.font-pen { font-family: "Klee One", "Noto Sans JP", sans-serif; font-weight: 600; }
.glyph.font-hand { font-family: "Zen Kurenaido", "Noto Sans JP", sans-serif; }
.glyph-font-note { font-size: 0.6875rem; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; margin-top: 2px; }

/* --- Leeches ------------------------------------------------------------ */
.badge.leech { background: var(--warn-soft); color: var(--warn); }
.leech-list { display: grid; gap: 6px; }
.leech-list li { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 0.875rem; }
.leech-list li:last-child { border-bottom: 0; }
.leech-list .jp { font-size: 1.4rem; }
.leech-list .n { color: var(--muted); font-variant-numeric: tabular-nums; }

/* --- Stats: heatmap, area chart, stage accuracy ----------------------- */
.heatmap-wrap { overflow-x: auto; padding-bottom: 4px; }
.heatmap { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 11px); gap: 3px; width: max-content; }
.heatmap i { display: block; width: 11px; height: 11px; border-radius: 2px; background: var(--surface-3); }
.heatmap i.h1 { background: color-mix(in srgb, var(--accent) 25%, var(--surface-3)); }
.heatmap i.h2 { background: color-mix(in srgb, var(--accent) 50%, var(--surface-3)); }
.heatmap i.h3 { background: color-mix(in srgb, var(--accent) 75%, var(--surface-3)); }
.heatmap i.h4 { background: var(--accent); }
.heatmap i.future { visibility: hidden; }
.heatmap-months { display: grid; grid-auto-flow: column; width: max-content; font-size: 0.6875rem; color: var(--muted); margin-bottom: 4px; }
.heatmap-months span { width: 14px; white-space: nowrap; overflow: visible; }
.heatmap-legend { display: flex; align-items: center; gap: 4px; font-size: 0.6875rem; color: var(--muted); margin-top: 8px; }
.heatmap-legend i { width: 11px; height: 11px; border-radius: 2px; display: inline-block; background: var(--surface-3); }
.area-chart { width: 100%; height: auto; display: block; }
.area-chart .axis { stroke: var(--border-strong); stroke-width: 1; }
.area-chart .fill { fill: var(--accent); opacity: 0.18; }
.area-chart .line { fill: none; stroke: var(--accent); stroke-width: 2; }
.area-chart text { fill: var(--muted); font-size: 11px; font-family: var(--font-ui); }
.area-chart .end { fill: var(--text); font-weight: 600; }
.stage-acc { display: grid; gap: 8px; }
.stage-acc .row { display: grid; grid-template-columns: 96px 1fr 64px; align-items: center; gap: 10px; font-size: 0.875rem; }
.stage-acc .track { height: 10px; border-radius: 5px; background: var(--surface-3); overflow: hidden; }
.stage-acc .track div { height: 100%; border-radius: 5px; }
.stage-acc .n { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

/* --- Juice: streak, bursts, floating text, confetti ------------------- */
.btn-icon { padding: 6px 8px; min-width: 0; }
.streak {
  font-weight: 700; font-variant-numeric: tabular-nums; font-size: 0.875rem; padding: 2px 10px; border-radius: 999px;
  background: var(--ok-soft); color: var(--ok); animation: pop 260ms var(--ease);
}
.streak.is-hot { background: var(--accent-soft); color: var(--accent); }
@keyframes pop { 0% { transform: scale(0.6); opacity: 0; } 60% { transform: scale(1.15); opacity: 1; } 100% { transform: scale(1); } }
.glyph-card { position: relative; overflow: visible; }
.glyph-card.is-correct { animation: glow 520ms var(--ease); }
@keyframes glow { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 55%, transparent); } 100% { box-shadow: 0 0 0 26px transparent; } }
.burst { position: absolute; left: 50%; top: 50%; width: 0; height: 0; pointer-events: none; z-index: 3; }
.burst i {
  position: absolute; left: -4px; top: -4px; width: 8px; height: 8px; border-radius: 50%; background: var(--c);
  animation: burst 720ms cubic-bezier(0.15, 0.8, 0.3, 1) forwards;
}
.burst i:nth-child(odd) { border-radius: 2px; width: 6px; height: 10px; }
@keyframes burst { 0% { transform: translate(0, 0) scale(1); opacity: 1; } 100% { transform: translate(var(--dx), var(--dy)) scale(0.3); opacity: 0; } }
.float-text {
  position: absolute; left: 50%; top: 40%; transform: translateX(-50%); pointer-events: none; z-index: 4;
  font-weight: 800; font-size: 1.25rem; color: var(--ok); text-shadow: 0 1px 0 var(--surface);
  animation: floatUp 1000ms var(--ease) forwards;
}
.float-text.is-hot { color: var(--accent); font-size: 1.5rem; }
@keyframes floatUp { 0% { transform: translate(-50%, 10px) scale(0.8); opacity: 0; } 20% { opacity: 1; transform: translate(-50%, 0) scale(1.1); } 100% { transform: translate(-50%, -48px) scale(1); opacity: 0; } }
.confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 70; }
@media (prefers-reduced-motion: reduce) {
  .glyph-card.is-correct, .streak { animation: none; }
}

/* --- Review: sticky continue bar on phones, tappable card ------------- */
.glyph-card { cursor: pointer; }
.continue-bar { display: none; }
@media (max-width: 640px) {
  .continue-bar {
    position: fixed; left: 12px; right: 12px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 10px); z-index: 30;
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 8px 8px 8px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  }
  .feedback-actions [data-act="next"] { display: none; }
}
.lesson-dots span[data-dot] { cursor: pointer; }

/* --- Scan screen -------------------------------------------------------- */
.scan-preview { margin-top: 12px; }
.scan-preview img { max-height: 260px; width: auto; max-width: 100%; border-radius: var(--radius-sm); border: 1px solid var(--border); display: block; }
.scan-progress { margin-top: 12px; display: grid; gap: 6px; }
.scan-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; }
.scan-tile {
  display: grid; gap: 2px; justify-items: center; padding: 10px 6px; border-radius: var(--radius-sm); cursor: pointer;
  border: 2px solid var(--border); background: var(--surface); color: var(--text); font: inherit; text-align: center;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.scan-tile .scan-char { font-size: 2.2rem; line-height: 1.1; }
.scan-tile .scan-name { font-weight: 600; font-size: 0.875rem; }
.scan-tile .scan-meta { font-size: 0.6875rem; color: var(--muted); }
.scan-tile.is-selected { border-color: var(--accent); background: var(--accent-soft); }
.scan-tile.is-selected .scan-char { color: var(--accent); }
.scan-tile.is-known { opacity: 0.55; cursor: default; }
.scan-tile:not(:disabled):hover { transform: translateY(-1px); }
.scan-stage { position: relative; display: inline-block; max-width: 100%; touch-action: none; user-select: none; -webkit-user-select: none; cursor: crosshair; }
.scan-stage img { display: block; max-height: 320px; width: auto; max-width: 100%; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.scan-box { position: absolute; border: 2px solid var(--accent); background: color-mix(in srgb, var(--accent) 18%, transparent); border-radius: 3px; pointer-events: none; box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.25); }
.scan-unsure-label { grid-column: 1 / -1; font-size: 0.75rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin-top: 6px; }
.scan-tile.is-unsure { border-style: dashed; }

/* ======================================================================
   Kanjidex theme layer: ink outlines, offset shadows, display type
   ====================================================================== */
h1, h2, h3, .big-btn-count, .stat .stat-value, .ring-label .ring-level, .big-number, .level-num { font-family: var(--font-display); font-weight: 900; letter-spacing: -0.01em; }
h1 { font-size: 1.9rem; }
.topbar { background: var(--bg); backdrop-filter: none; -webkit-backdrop-filter: none; border-bottom: 2px solid var(--border); }
.logo { font-family: var(--font-display); font-weight: 900; font-size: 1.2rem; }
.logo-mark { background: var(--bg); color: var(--accent); border: 2.5px solid var(--accent); border-radius: 9px; transform: rotate(-6deg); font-weight: 900; }
.nav a { font-weight: 800; }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.level-badge { background: var(--text); color: var(--bg); font-weight: 800; }
.card { border: 2px solid var(--border); box-shadow: var(--shadow); background: var(--surface); }
.btn { border: 2px solid var(--border); box-shadow: 3px 3px 0 var(--border); font-weight: 800; border-radius: 14px; }
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--border); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent-deep); box-shadow: 3px 3px 0 var(--accent-deep); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.05); }
.btn-ghost { box-shadow: none; border-color: transparent; }
.btn-ghost:hover { border-color: var(--border); }
.btn-sm { box-shadow: 2px 2px 0 var(--border); }
.btn-primary.btn-sm { box-shadow: 2px 2px 0 var(--accent-deep); }
.big-btn { border: 2px solid var(--border); box-shadow: var(--shadow); }
.big-btn.is-empty { box-shadow: none; border-color: var(--line); background: var(--surface-2); }
.big-btn-label { font-weight: 800; }
.answer { border: 2px solid var(--border); box-shadow: inset 0 0 0 3px var(--accent-soft); font-weight: 700; font-family: var(--font-ui); }
.answer.is-correct { background: var(--ok-soft); border-color: var(--ok); }
.answer.is-wrong { background: var(--bad-soft); border-color: var(--bad); }
.glyph-card { border: 2px solid var(--border); box-shadow: var(--shadow); }
.glyph-card::before { display: none; }
.badge { border-radius: 8px; }
.badge.type-radical { background: var(--text); color: var(--bg); }
.tile, .kcell { border: 1.5px solid var(--border); }
.kcell.stage-locked, .tile.stage-locked { border-color: var(--line); background: var(--surface-2); color: var(--muted); }
.kgrid-bar, .level-bar, .review-progress, .hp { border: 2px solid var(--border); background: var(--surface-2); height: 12px; border-radius: 6px; }
.review-progress > div, .level-bar > div { background: var(--accent); }
.stat { border: 2px solid var(--border); background: var(--surface); box-shadow: 3px 3px 0 var(--border); }
.ring-value { stroke: var(--accent); }
.ring-track { stroke: var(--surface-3); }
.toast { border: 2px solid var(--border); box-shadow: 3px 3px 0 var(--border); font-weight: 700; }
.chip { border: 1.5px solid var(--border); }
.switch input:checked + .track { background: var(--accent); }
.feedback-answer { font-family: var(--font-display); font-weight: 900; }
.streak { background: var(--accent); color: #fff; }
.streak.is-hot { background: var(--gold); color: var(--text); }
.float-text { color: var(--accent); }
.float-text.is-hot { color: var(--gold); }
.glyph-card.is-correct { animation: none; }
@media (max-width: 640px) {
  .nav { border-top: 2px solid var(--border); }
  .nav a[aria-current="page"] { color: var(--accent); }
}

/* --- Unseen kanji hide behind ? in the dex ---------------------------- */
.kcell.is-unseen { color: var(--line); font-family: var(--font-display); font-weight: 900; }
.kcell.is-unseen::before { content: "?"; }

/* --- Rarity and shiny ---------------------------------------------------- */
.rarity { display: inline-flex; align-items: center; gap: 4px; font-size: 0.6875rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; padding: 2px 8px; border-radius: 8px; border: 1.5px solid var(--border); background: var(--surface); }
.rarity .stars { letter-spacing: -0.05em; }
.rarity.r-common { color: var(--muted); border-color: var(--line); }
.rarity.r-uncommon { color: var(--text); }
.rarity.r-rare { color: var(--accent); border-color: var(--accent); }
.rarity.r-epic { color: #fff; background: var(--accent); border-color: var(--accent-deep); }
.rarity.r-ancient { color: var(--text); background: var(--gold); border-color: var(--border); }
.rarity.r-part { color: var(--muted); border-color: var(--line); }
.dexno { font-family: var(--font-display); font-weight: 900; color: var(--muted); letter-spacing: 0.02em; }
.shiny-badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 8px; background: linear-gradient(120deg, #f4e7b6, #c9a227 45%, #fff2b8 70%, #c9a227); color: var(--text); border: 1.5px solid var(--border); font-size: 0.6875rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; }

.glyph-card.is-shiny { background: linear-gradient(120deg, var(--surface) 0%, var(--gold-soft) 45%, var(--surface) 60%); background-size: 240% 100%; animation: shimmer 2.4s linear infinite; border-color: var(--gold); box-shadow: 4px 4px 0 var(--gold); }
.glyph-card.is-shiny .glyph { background: linear-gradient(120deg, var(--text), var(--gold) 40%, var(--text) 60%, var(--gold)); background-size: 240% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shimmer 2.4s linear infinite; }
.shiny-tag { position: absolute; top: 12px; right: 12px; }
.sparkle { position: absolute; pointer-events: none; color: var(--gold); font-size: 1.1rem; animation: twinkle 1.6s ease-in-out infinite; }
@keyframes shimmer { 0% { background-position: 120% 0; } 100% { background-position: -120% 0; } }
@keyframes twinkle { 0%, 100% { opacity: 0.2; transform: scale(0.7); } 50% { opacity: 1; transform: scale(1.15); } }

/* --- Stamp: the "caught" mark ------------------------------------------- */
.stamp-hit { position: absolute; left: 50%; top: 50%; width: 118px; height: 118px; margin: -59px 0 0 -59px; border: 6px solid var(--accent); border-radius: 22px; color: var(--accent); display: grid; place-items: center; font-family: var(--font-display); font-weight: 900; font-size: 1.15rem; letter-spacing: 0.04em; text-transform: uppercase; background: color-mix(in srgb, var(--surface) 70%, transparent); pointer-events: none; z-index: 5; animation: stampDown 720ms cubic-bezier(0.2, 1.4, 0.3, 1) forwards; transform: rotate(-12deg) scale(2.2); opacity: 0; }
.stamp-hit.gold { border-color: var(--gold); color: var(--gold); }
@keyframes stampDown { 0% { transform: rotate(-12deg) scale(2.2); opacity: 0; } 35% { transform: rotate(-12deg) scale(1); opacity: 1; } 75% { opacity: 1; } 100% { transform: rotate(-12deg) scale(1.05); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .stamp-hit, .glyph-card.is-shiny, .glyph-card.is-shiny .glyph, .sparkle { animation: none; } }

/* --- Intro screen -------------------------------------------------------- */
.intro { position: fixed; inset: 0; z-index: 90; background: #7fc8f0; color: #17130f; display: flex; flex-direction: column; align-items: center; justify-content: space-between; cursor: pointer; overflow: hidden; }
.intro svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.intro .intro-text { position: relative; z-index: 2; text-align: center; padding: calc(64px + env(safe-area-inset-top)) 20px 0; }
.intro .intro-cta { position: relative; z-index: 2; padding: 0 20px calc(40px + env(safe-area-inset-bottom)); }
.intro h1 { font-size: clamp(3rem, 12vw, 5.5rem); line-height: 0.95; color: #fff; text-shadow: 4px 4px 0 #17130f; margin: 0; }
.intro h1 .stamp-logo { display: inline-grid; place-items: center; width: 0.95em; height: 0.95em; border: 0.09em solid #d7262a; border-radius: 0.18em; color: #d7262a; background: #f7f2e8; transform: rotate(-8deg); font-size: 0.9em; margin-right: 0.12em; text-shadow: none; vertical-align: -0.1em; }
.intro p { color: #fff; font-weight: 800; font-size: clamp(1rem, 3.6vw, 1.25rem); text-shadow: 2px 2px 0 #17130f; margin: 10px 0 18px; }
.intro .btn { font-size: 1.05rem; padding: 14px 26px; animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
.intro .kan { animation: hover 3.2s ease-in-out infinite; transform-origin: center; }
@keyframes hover { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-9px); } }
.intro.is-leaving { animation: introOut 480ms var(--ease) forwards; }
@keyframes introOut { to { opacity: 0; transform: scale(1.04); } }
@media (prefers-reduced-motion: reduce) { .intro .btn, .intro .kan { animation: none; } }
.review-top { flex-wrap: nowrap; }
.review-top .counter { white-space: nowrap; }
.streak { white-space: nowrap; }
@media (max-width: 420px) { .review-top .accuracy { display: none; } .review-top .counter { font-size: 0.875rem; } }

/* --- Capture square ---------------------------------------------------- */
.capture-box { position: absolute; border: 3px solid var(--accent); border-radius: 6px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35); pointer-events: none; }
.capture-box i { position: absolute; width: 14px; height: 14px; border: 3px solid var(--accent); }
.capture-box i:nth-child(1) { top: -3px; left: -3px; border-right: 0; border-bottom: 0; }
.capture-box i:nth-child(2) { top: -3px; right: -3px; border-left: 0; border-bottom: 0; }
.capture-box i:nth-child(3) { bottom: -3px; left: -3px; border-right: 0; border-top: 0; }
.capture-box i:nth-child(4) { bottom: -3px; right: -3px; border-left: 0; border-top: 0; }
.capture-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-top: 10px; }
.capture-controls input[type="range"] { vertical-align: middle; width: 140px; accent-color: var(--accent); }
.scan-stage { cursor: grab; overflow: hidden; border-radius: var(--radius-sm); }

/* --- Evolution -------------------------------------------------------- */
.evo { position: fixed; inset: 0; z-index: 85; display: grid; place-items: center; background: rgba(20, 14, 10, 0.72); cursor: pointer; animation: fadeIn 240ms var(--ease); }
.evo.is-leaving { animation: introOut 340ms var(--ease) forwards; }
.evo-card { width: min(92vw, 420px); text-align: center; padding: 26px 20px 18px; background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.evo-title { font-family: var(--font-display); font-weight: 900; font-size: 1.35rem; margin-bottom: 14px; }
.evo-stage { position: relative; display: grid; place-items: center; height: 190px; }
.evo-glyph { font-size: 7rem; line-height: 1; font-weight: 700; padding: 6px 22px; border-radius: 20px; border: 3px solid var(--border); background: var(--bg); animation: evoPulse 1.7s ease-in-out; }
.evo-glyph.stage-apprentice { color: var(--apprentice); } .evo-glyph.stage-guru { color: var(--guru); } .evo-glyph.stage-master { color: var(--master); } .evo-glyph.stage-enlightened { color: var(--enlightened); } .evo-glyph.stage-burned { color: var(--burned); border-color: var(--gold); }
.evo-glyph.is-evolved { animation: evoPop 600ms cubic-bezier(0.2, 1.4, 0.3, 1); box-shadow: 0 0 0 6px color-mix(in srgb, currentColor 25%, transparent); }
.evo-name { font-family: var(--font-display); font-weight: 900; font-size: 1.15rem; margin-top: 8px; }
.evo-arrow { font-weight: 900; color: var(--muted); }
.evo-hint { margin: 12px 0 0; }
@keyframes evoPulse { 0%, 100% { filter: brightness(1); transform: scale(1); } 20% { filter: brightness(2.2) saturate(0); transform: scale(1.06); } 40% { filter: brightness(1); } 60% { filter: brightness(2.6) saturate(0); transform: scale(1.1); } 80% { filter: brightness(1); } 90% { filter: brightness(3) saturate(0); transform: scale(1.14); } }
@keyframes evoPop { 0% { transform: scale(0.6); filter: brightness(3) saturate(0); } 60% { transform: scale(1.12); filter: brightness(1.2); } 100% { transform: scale(1); filter: brightness(1); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .evo-glyph, .evo-glyph.is-evolved { animation: none; } }

/* --- Shiny stamps: a gold light sweeps across, the glyph glints ------- */
.kcell.is-shiny, .tile.is-shiny {
  position: relative; overflow: hidden; isolation: isolate;
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold), 0 0 10px color-mix(in srgb, var(--gold) 55%, transparent);
  color: #fff6d6; text-shadow: 0 0 6px var(--gold), 0 0 1px #000;
}
.kcell.is-shiny::before, .tile.is-shiny::before {
  content: ""; position: absolute; inset: -60% -40%; z-index: 1; pointer-events: none;
  background: linear-gradient(115deg, transparent 38%, rgba(255, 244, 190, 0.15) 44%, rgba(255, 250, 220, 0.85) 50%, rgba(255, 244, 190, 0.15) 56%, transparent 62%);
  transform: translateX(-70%);
  animation: shineSweep 3.4s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  animation-delay: var(--d, 0s);
}
.kcell.is-shiny::after, .tile.is-shiny::after {
  content: "✦"; position: absolute; top: -3px; right: -1px; z-index: 2; font-size: 0.75rem; line-height: 1; color: #fff3b0;
  text-shadow: 0 0 4px var(--gold), 0 0 1px #000; animation: twinkle 2.2s ease-in-out infinite; animation-delay: calc(var(--d, 0s) + 0.7s);
}
.tile.is-shiny::after { font-size: 1rem; top: 2px; right: 4px; }
@keyframes shineSweep { 0% { transform: translateX(-70%); } 45% { transform: translateX(70%); } 100% { transform: translateX(70%); } }
.item-page .glyph.is-shiny, .glyph.is-shiny-static {
  background: linear-gradient(120deg, var(--text) 30%, var(--gold) 48%, #fff3b0 52%, var(--gold) 56%, var(--text) 75%);
  background-size: 300% 100%; -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: shimmer 3.2s linear infinite;
}
@media (prefers-reduced-motion: reduce) {
  .kcell.is-shiny::before, .tile.is-shiny::before { animation: none; transform: none; opacity: 0.35; }
  .kcell.is-shiny::after, .tile.is-shiny::after, .item-page .glyph.is-shiny { animation: none; }
}

/* --- Legendary: a colourful shiny --------------------------------------- */
.kcell.is-legendary, .tile.is-legendary {
  position: relative; overflow: hidden; isolation: isolate; border-color: transparent;
  background-image: linear-gradient(var(--surface), var(--surface)), conic-gradient(from var(--a, 0deg), #ff5b5b, #ffb347, #ffe66d, #5be07a, #4fc3f7, #b388ff, #ff5b5b);
  background-origin: border-box; background-clip: padding-box, border-box;
  color: var(--text); text-shadow: 0 0 6px rgba(255, 255, 255, 0.8);
  animation: legendSpin 4s linear infinite; box-shadow: 0 0 10px rgba(180, 120, 255, 0.45);
}
@property --a { syntax: '<angle>'; inherits: false; initial-value: 0deg; }
@keyframes legendSpin { to { --a: 360deg; } }
.kcell.is-legendary::before, .tile.is-legendary::before {
  content: ""; position: absolute; inset: -60% -40%; z-index: 1; pointer-events: none;
  background: linear-gradient(115deg, transparent 40%, rgba(255,255,255,0.7) 50%, transparent 60%);
  transform: translateX(-70%); animation: shineSweep 3s cubic-bezier(0.4, 0, 0.2, 1) infinite; animation-delay: var(--d, 0s);
}
.kcell.is-legendary::after, .tile.is-legendary::after { content: "✦"; position: absolute; top: -3px; right: -1px; z-index: 2; font-size: 0.75rem; line-height: 1;
  background: linear-gradient(90deg, #ff5b5b, #ffe66d, #4fc3f7, #b388ff); -webkit-background-clip: text; background-clip: text; color: transparent; animation: twinkle 2s ease-in-out infinite; }
.glyph-card.is-legendary { border-color: transparent; background-image: linear-gradient(var(--surface), var(--surface)), conic-gradient(from var(--a, 0deg), #ff5b5b, #ffb347, #ffe66d, #5be07a, #4fc3f7, #b388ff, #ff5b5b); background-origin: border-box; background-clip: padding-box, border-box; animation: legendSpin 4s linear infinite; box-shadow: 4px 4px 0 #b388ff; }
.glyph-card.is-legendary .glyph { background: linear-gradient(120deg, #ff5b5b, #ffb347, #ffe66d, #5be07a, #4fc3f7, #b388ff); background-size: 300% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shimmer 2.4s linear infinite; }
.legendary-badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 8px; border: 1.5px solid var(--border); font-size: 0.6875rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: #fff; text-shadow: 0 0 2px #000; background: linear-gradient(90deg, #ff5b5b, #ffb347, #ffe66d, #5be07a, #4fc3f7, #b388ff); background-size: 200% 100%; animation: shimmer 3s linear infinite; }
.item-page .glyph.is-legendary { background: linear-gradient(120deg, #ff5b5b, #ffb347, #ffe66d, #5be07a, #4fc3f7, #b388ff); background-size: 300% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shimmer 3s linear infinite; }

/* --- Wild-caught marker --------------------------------------------------- */
.kcell.is-wild { box-shadow: inset 0 -3px 0 #4f9e3c; }
.tile.is-wild { box-shadow: inset 0 -4px 0 #4f9e3c; }
.wild-badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 8px; border: 1.5px solid var(--border); background: #dcefe2; color: #1f5a33; font-size: 0.6875rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; }
:root[data-theme="dark"] .wild-badge { background: #1f3a27; color: #b6e5c2; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .wild-badge { background: #1f3a27; color: #b6e5c2; } }

/* --- Dex search ---------------------------------------------------------- */
.dex-search { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.dex-search input { flex: 1 1 220px; font-size: 1rem; padding: 10px 12px; border: 2px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); }
.dex-search input:focus { outline: 3px solid var(--accent-soft); }
.dex-hits { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.dex-hit { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 6px; border: 1.5px solid var(--border); border-radius: 10px; background: var(--surface); font-weight: 700; font-size: 0.8125rem; text-decoration: none; color: var(--text); }
.dex-hit .jp { font-size: 1.2rem; }
.dex-hit.is-unseen { color: var(--muted); border-style: dashed; }
.kgrid.is-searching .kcell:not(.is-hit) { opacity: 0.18; }
.kgrid .kcell.is-hit { outline: 3px solid var(--accent); outline-offset: 1px; z-index: 2; }

/* --- Quest ----------------------------------------------------------------- */
.quest-card { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; }
.quest-glyph { width: 84px; height: 84px; border-radius: 18px; border: 3px solid var(--accent); display: grid; place-items: center; font-family: var(--font-jp); font-weight: 700; font-size: 3rem; color: var(--accent); background: var(--bg); transform: rotate(-4deg); }
.quest-glyph.is-done { border-color: #4f9e3c; color: #2f7d4f; transform: none; }
.quest-glyph.is-secret { color: var(--line); border-style: dashed; }
.quest-name { font-family: var(--font-display); font-weight: 900; font-size: 1.15rem; }
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.calendar .dow { font-size: 0.625rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); text-align: center; padding-bottom: 2px; }
.calendar .day { aspect-ratio: 1; border-radius: 8px; border: 1.5px solid var(--line); display: grid; place-items: center; position: relative; font-family: var(--font-jp); font-size: 1.15rem; font-weight: 700; color: var(--text); background: var(--surface); }
.calendar .day.is-empty { border-color: transparent; background: transparent; }
.calendar .day.is-caught { background: #dcefe2; border-color: #4f9e3c; }
.calendar .day.is-today { outline: 2px solid var(--accent); outline-offset: 1px; }
.calendar .day.is-future { opacity: 0.35; }
.calendar .day small { position: absolute; top: 2px; left: 4px; font-family: var(--font-ui); font-size: 0.5625rem; font-weight: 800; color: var(--muted); }
.calendar .day.is-caught small { color: #2f7d4f; }
:root[data-theme="dark"] .calendar .day.is-caught { background: #1f3a27; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .calendar .day.is-caught { background: #1f3a27; } }
.meanings { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 8px 0 4px; }
.meaning { padding: 4px 10px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--surface); font-weight: 700; font-size: 0.9375rem; }
.meaning.is-typed { border-color: var(--ok); background: var(--ok-soft); }
.meaning.is-main { border-color: var(--border); border-width: 2px; }
.meaning.is-mine { border-style: dashed; }

/* ---------- Lookalike duels ---------- */
.chip .chip-count { font-weight: 800; color: var(--accent); font-size: 0.75rem; }
.duel-home { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.duel-home h2 { margin: 0 0 10px; }
.duel-pairs { display: flex; flex-wrap: wrap; gap: 8px; }
.duel-pair { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1.5px solid var(--border); border-radius: 10px; background: var(--bg); font-size: 1.25rem; font-weight: 600; line-height: 1.2; }
.duel-pair i { font-style: normal; font-family: var(--font-ui); font-size: 0.625rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.duel-pair.is-confused { border-color: var(--accent); color: var(--accent-deep); background: var(--accent-soft); }

.duel-dots { display: flex; gap: 6px; margin: 0 0 14px; }
.duel-dots i { flex: 1; max-width: 44px; height: 8px; border-radius: 4px; background: var(--surface-3); border: 1.5px solid var(--border); }
.duel-dots i.is-current { background: var(--surface); box-shadow: 0 0 0 2px var(--accent-soft); border-color: var(--accent); }
.duel-dots i.is-won { background: var(--ok); }
.duel-dots i.is-lost { background: var(--accent); }

.duel-card { position: relative; overflow: hidden; text-align: center; padding: 22px 16px 18px; }
.duel-card.is-correct { box-shadow: 0 0 0 3px var(--ok), var(--shadow); }
.duel-card.is-wrong { box-shadow: 0 0 0 3px var(--bad), var(--shadow); }
.duel-kicker { font-size: 0.6875rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.duel-prompt { font-size: 1.125rem; margin-bottom: 16px; text-wrap: balance; }
.duel-prompt strong { font-family: var(--font-display); font-weight: 900; font-size: 1.35em; color: var(--accent); }
.duel-status { min-height: 1.6em; margin-top: 14px; font-size: 0.9375rem; color: var(--muted); }
.duel-status.is-ok { color: var(--ok); font-weight: 700; }
.duel-status.is-bad { color: var(--bad); }
.duel-key { position: absolute; top: 6px; left: 8px; font-family: var(--font-ui); font-size: 0.6875rem; font-weight: 800; color: var(--muted); }

.duel-tiles { display: flex; align-items: stretch; justify-content: center; gap: 10px; }
.duel-tile {
  position: relative; flex: 1 1 0; min-width: 0; max-width: 170px; padding: 18px 4px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--bg); color: var(--text); border: 2px solid var(--border); border-radius: 18px; box-shadow: 4px 4px 0 var(--border);
  cursor: pointer; transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
}
.duel-tile:hover:not(:disabled) { transform: translate(-1px, -2px); box-shadow: 6px 7px 0 var(--border); }
.duel-tile:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--border); }
.duel-tile:focus-visible, .duel-choice:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.duel-tile-glyph { font-size: min(22vw, 5.5rem); font-weight: 500; line-height: 1.05; }
.duel-tiles.n-3 .duel-tile-glyph { font-size: min(17vw, 4.5rem); }
.duel-tiles.n-4 .duel-tile-glyph { font-size: min(13vw, 3.75rem); }
.duel-tiles.n-4 { gap: 6px; }
.duel-tile-name { font-size: 0.8125rem; font-weight: 700; min-height: 1.3em; line-height: 1.3; overflow-wrap: anywhere; }
.duel-vs {
  align-self: center; flex: 0 0 auto; width: 38px; height: 38px; display: grid; place-items: center;
  border: 3px solid var(--accent); border-radius: 10px; color: var(--accent); background: var(--surface);
  font-family: var(--font-display); font-weight: 900; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; transform: rotate(-8deg);
}
.duel-tile.is-right, .duel-choice.is-right { background: var(--ok-soft); border-color: var(--ok); box-shadow: 4px 4px 0 var(--ok); color: var(--text); opacity: 1; }
.duel-tile.is-wrong, .duel-choice.is-wrong { background: var(--accent-soft); border-color: var(--bad); box-shadow: 4px 4px 0 var(--bad); opacity: 1; }
.duel-tile.is-dim, .duel-choice.is-dim { opacity: 0.55; box-shadow: none; }
.duel-tile:disabled, .duel-choice:disabled { cursor: default; }

.duel-glyph { font-size: min(34vw, 8rem); font-weight: 500; line-height: 1; margin: 0 0 18px; }
.duel-choices { display: grid; gap: 10px; max-width: 420px; margin: 0 auto; }
.duel-choice {
  position: relative; display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 52px; padding: 10px 28px;
  background: var(--bg); color: var(--text); border: 2px solid var(--border); border-radius: 14px; box-shadow: 4px 4px 0 var(--border);
  font-weight: 800; font-size: 1.0625rem; cursor: pointer; transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.duel-choice:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--border); }
.duel-choice .duel-key { top: 50%; transform: translateY(-50%); left: 12px; }
.duel-choice-glyph { font-size: 1.5rem; font-weight: 500; }

.duel-compare h2 { margin-top: 0; }
.duel-rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.duel-row { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: center; padding: 10px; border-radius: 14px; border: 1.5px solid var(--line); }
.duel-row.is-target { border-color: var(--ok); background: var(--ok-soft); }
.duel-row-glyph { width: 76px; height: 76px; display: grid; place-items: center; font-size: 3rem; font-weight: 500; line-height: 1; color: var(--text); background: var(--surface); border: 2px solid var(--border); border-radius: 12px; text-decoration: none; }
.duel-row-glyph canvas { width: 66px; height: 66px; display: block; }
.duel-row-name { font-family: var(--font-display); font-weight: 900; font-size: 1.0625rem; }
.duel-summary-rows { display: grid; gap: 8px; text-align: left; margin-bottom: 8px; }
.duel-vs-small { align-self: center; font-size: 0.625rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.screen.duel { display: grid; gap: 14px; }
.screen.duel .screen-head, .screen.duel .duel-dots { margin-bottom: 0; }
@media (prefers-reduced-motion: reduce) { .duel-tile, .duel-choice { transition: none; } }

/* ---------- Pictures: an emoji beside a kanji whose meaning is on screen ---------- */
.glyph-row { display: flex; align-items: center; justify-content: center; gap: clamp(10px, 4vw, 28px); }
.pic { font-size: min(14vw, 4rem); line-height: 1; font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; }
.pic.is-small { font-size: min(10vw, 2.75rem); }
.pic.is-inline { font-size: 1.1em; margin-left: 8px; vertical-align: -0.1em; }
.pic.pop-in { animation: picPop 520ms cubic-bezier(0.2, 1.4, 0.3, 1) both; }
@keyframes picPop { 0% { transform: scale(0.3) rotate(-12deg); opacity: 0; } 60% { transform: scale(1.12) rotate(3deg); opacity: 1; } 100% { transform: scale(1) rotate(0); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .pic.pop-in { animation: none; } }
