/* Learn Japanese — design system.
   Loaded LAST in <head> on every page (after shell.css and after the page's own
   inline <style>), so its tokens win over the older per-page palettes. Four
   layers, in order:
     1. tokens     colour (light + dark), type, space, radius, elevation, levels
     2. base       body, focus, selection, reduced motion
     3. components .ui-* (cards, buttons, chips, segmented, inputs, answer
                   states, progress bar + ring, empty state, toast) and the
                   responsive shell (.ljs-*: app bar, tab bar, sidebar)
     4. adapters   .lj-gen (every page tools/gen-pages.js writes) and .lj-hand
                   (the hand-written section pages) re-skin the classes those
                   pages already use, so they look native without their markup
                   or scripts changing.
   No web fonts: the type stacks are system faces only, so it all works offline.
   Theme: prefers-color-scheme, overridden by <html data-theme="light|dark">,
   which assets/shell.js sets from localStorage 'ljTheme'. */

/* ================================================================ 1. tokens */

:root {
  color-scheme: light;

  /* ground and surfaces: a cool, quiet neutral */
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eff1f4;
  --surface-3: #e4e7ec;
  /* the selected segment of a segmented control: raised white in light, a lighter step plus a hairline in dark */
  --seg-on: #ffffff;
  --seg-ring: 0 0 0 0 transparent;
  --line: #e1e4e9;
  --line-strong: #cbd0d8;
  --ink: #11141a;
  --ink-2: #454c59;
  --ink-3: #5d6471;

  /* the one accent: 藍 indigo */
  --accent: #3a4ad6;
  --accent-hover: #2e3cb8;
  --accent-ink: #2d3bb0;
  --accent-soft: #eceefc;
  --accent-line: #c9cef6;
  --on-accent: #ffffff;

  /* answer states */
  --ok: #17784d;
  --ok-soft: #e5f3eb;
  --bad: #c7362b;
  --bad-soft: #fbeae8;
  --warn: #9e5c00;
  --warn-soft: #fcf0de;
  --on-state: #ffffff;
  --neutral-strong: #3a404b;

  /* N5 -> N1, one hue per level, every one AA on white */
  --lv-n5: #0e7350;
  --lv-n4: #1769aa;
  --lv-n3: #6b46c9;
  --lv-n2: #a8327f;
  --lv-n1: #b8480f;

  /* kanji mnemonic component strokes/chips, 6 hues, every one AA on --surface */
  --mn-1: #1f6fb3;
  --mn-2: #147a4f;
  --mn-3: #8a3fae;
  --mn-4: #b5580b;
  --mn-5: #ae2e6c;
  --mn-6: #4d6a1f;

  /* type */
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI",
    "Yu Gothic", Meiryo, "Noto Sans JP", "Noto Sans CJK JP", system-ui, sans-serif;
  --font-jp: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic",
    "Noto Sans JP", "Noto Sans CJK JP", Meiryo, -apple-system, "Segoe UI", system-ui, sans-serif;
  --font-num: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Display", "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --t-xs: 0.75rem;    /* 12 */
  --t-sm: 0.8125rem;  /* 13 */
  --t-md: 0.9375rem;  /* 15 */
  --t-lg: 1.0625rem;  /* 17 */
  --t-xl: 1.3125rem;  /* 21 */
  --t-2xl: 1.75rem;   /* 28 */
  --t-3xl: 2.25rem;   /* 36 */
  --t-4xl: 3rem;      /* 48 */

  /* space and shape */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px;
  --s-6: 24px; --s-7: 32px; --s-8: 48px;
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 22px; --r-pill: 999px;

  /* the one elevation */
  --elev: 0 1px 2px rgba(17, 20, 26, 0.04), 0 2px 8px rgba(17, 20, 26, 0.05);
  --elev-over: 0 12px 40px rgba(17, 20, 26, 0.18), 0 2px 6px rgba(17, 20, 26, 0.08);
  --scrim: rgba(12, 14, 20, 0.48);
  --glass: rgba(255, 255, 255, 0.86);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);

  /* shell geometry */
  --shell-h: 56px;
  --tab-h: 62px;
  --side-w: 256px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0c0e12;
    --surface: #15181e;
    --surface-2: #1c2027;
    --surface-3: #262b34;
    --seg-on: #2c323d;
    --seg-ring: inset 0 0 0 1px #3d4451;
    --line: #262a32;
    --line-strong: #363c47;
    --ink: #eceef2;
    --ink-2: #b4bac5;
    --ink-3: #8e95a2;
    --accent: #8f9cff;
    --accent-hover: #a7b1ff;
    --accent-ink: #aab3ff;
    --accent-soft: #1d2140;
    --accent-line: #343c78;
    --on-accent: #0b0e1c;
    --ok: #4cc38a;
    --ok-soft: #13271e;
    --bad: #ff7b6f;
    --bad-soft: #2d1614;
    --warn: #f0b04a;
    --warn-soft: #2b2112;
    --on-state: #0c0e12;
    --neutral-strong: #c9ced8;
    --lv-n5: #4fd0a0;
    --lv-n4: #64b7f0;
    --lv-n3: #ab95ff;
    --lv-n2: #ee88cc;
    --lv-n1: #ff9d62;
    --mn-1: #7fb2f2;
    --mn-2: #5fd9a5;
    --mn-3: #cf9bef;
    --mn-4: #f2b562;
    --mn-5: #f293c2;
    --mn-6: #b7d66a;
    --elev: 0 0 0 1px rgba(255, 255, 255, 0.02);
    --elev-over: 0 16px 48px rgba(0, 0, 0, 0.6);
    --scrim: rgba(0, 0, 0, 0.62);
    --glass: rgba(21, 24, 30, 0.84);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c0e12;
  --surface: #15181e;
  --surface-2: #1c2027;
  --surface-3: #262b34;
  --seg-on: #2c323d;
  --seg-ring: inset 0 0 0 1px #3d4451;
  --line: #262a32;
  --line-strong: #363c47;
  --ink: #eceef2;
  --ink-2: #b4bac5;
  --ink-3: #8e95a2;
  --accent: #8f9cff;
  --accent-hover: #a7b1ff;
  --accent-ink: #aab3ff;
  --accent-soft: #1d2140;
  --accent-line: #343c78;
  --on-accent: #0b0e1c;
  --ok: #4cc38a;
  --ok-soft: #13271e;
  --bad: #ff7b6f;
  --bad-soft: #2d1614;
  --warn: #f0b04a;
  --warn-soft: #2b2112;
  --on-state: #0c0e12;
  --neutral-strong: #c9ced8;
  --lv-n5: #4fd0a0;
  --lv-n4: #64b7f0;
  --lv-n3: #ab95ff;
  --lv-n2: #ee88cc;
  --lv-n1: #ff9d62;
  --mn-1: #7fb2f2;
  --mn-2: #5fd9a5;
  --mn-3: #cf9bef;
  --mn-4: #f2b562;
  --mn-5: #f293c2;
  --mn-6: #b7d66a;
  --elev: 0 0 0 1px rgba(255, 255, 255, 0.02);
  --elev-over: 0 16px 48px rgba(0, 0, 0, 0.6);
  --scrim: rgba(0, 0, 0, 0.62);
  --glass: rgba(21, 24, 30, 0.84);
}

/* The older palettes' names, pointed at the tokens above so every page that
   still says var(--card) or var(--paper) follows the theme. */
:root, :root[data-theme] {
  --card: var(--surface);
  --border: var(--line);
  --ink-soft: var(--ink-2);
  --muted: var(--ink-3);
  --ink-dim: var(--ink-3);
  --paper: var(--bg);
  --card-bg: var(--surface);
  --bg-card: var(--surface);
  --bg2: var(--surface-2);
  --card-hover: var(--surface-2);
  --bg-card-hover: var(--surface-2);
  --hover-bg: var(--surface-2);
  --grid-line: var(--line-strong);
  --border-light: var(--line);
  --accent-bright: var(--accent);
  --green: var(--ok);
  --green-soft: var(--ok-soft);
  --irregular: var(--bad);
  --irregular-soft: var(--bad-soft);
  --shadow: var(--elev-over);
  --radius: var(--r-md);
}

/* The level scale as a variable an element can pick up with one class. */
.lv-N5, [data-lv="N5"] { --lv: var(--lv-n5); }
.lv-N4, [data-lv="N4"] { --lv: var(--lv-n4); }
.lv-N3, [data-lv="N3"] { --lv: var(--lv-n3); }
.lv-N2, [data-lv="N2"] { --lv: var(--lv-n2); }
.lv-N1, [data-lv="N1"] { --lv: var(--lv-n1); }

/* ================================================================== 2. base */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

:lang(ja), .jp, [lang="ja"] { font-family: var(--font-jp); }

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

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

/* no one-word last lines in running text (ignored where unsupported) */
p { text-wrap: pretty; }

/* One disclosure marker on every page: a small triangle that turns when open.
   :where() keeps it at element weight so a page's own marker (culture's +/−) wins. */
:where(summary) { list-style: none; }
:where(summary)::-webkit-details-marker { display: none; }
:where(summary)::before { content: "\25B8"; display: inline-block; margin-right: 0.5em; color: var(--ink-3); transition: transform 0.15s; }
:where(details[open]) > :where(summary)::before { transform: rotate(90deg); }

/* native radios, checkboxes and sliders take the theme accent, not the browser blue */
input[type="radio"], input[type="checkbox"], input[type="range"] { accent-color: var(--accent); }

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
input:focus-visible, textarea:focus-visible, select:focus-visible { outline-offset: 0; }

button, input, select, textarea { font-family: inherit; }

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

/* ============================================================ 3. components */

.ui-eyebrow {
  font-size: var(--t-xs);
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* Component bases sit at zero specificity (:where) so a page's own layout
   rule for the same element always wins, whatever the load order. */
[class*="ui-"][hidden] { display: none !important; }

:where(.ui-card) {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--elev);
  padding: var(--s-5);
}

/* ---- buttons ---- */
.ui-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  font: 600 var(--t-md)/1 var(--font-ui);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.1s var(--ease);
}
.ui-btn:hover { background: var(--surface-2); }
.ui-btn:active { transform: scale(0.98); }
.ui-btn svg { width: 18px; height: 18px; flex: none; }
.ui-btn--primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.ui-btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.ui-btn--secondary { background: var(--accent-soft); border-color: transparent; color: var(--accent-ink); }
.ui-btn--secondary:hover { background: var(--accent-soft); border-color: var(--accent-line); }
.ui-btn--quiet { background: transparent; border-color: transparent; color: var(--ink-2); }
.ui-btn--quiet:hover { background: var(--surface-2); color: var(--ink); }
.ui-btn--block { display: flex; width: 100%; }
.ui-btn--lg { min-height: 52px; font-size: var(--t-lg); border-radius: var(--r-lg); padding: 0 22px; }
.ui-btn[disabled], .ui-btn[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }

/* ---- shared list pager (assets/pager.js, LJPager.controls) ---- */
/* Always one line: narrow screens tighten the padding, then drop the
   separators and the Previous/Next words (the arrows and aria-labels stay). */
.ljpager {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  max-width: 100%;
  margin: 14px 0 4px;
}
.ljpager[hidden] { display: none; }
.ljpager__btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  min-width: 44px;
  padding: 0 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  font: 600 var(--t-md)/1 var(--font-ui);
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.ljpager__btn:hover { background: var(--surface-2); }
.ljpager__btn[disabled] { opacity: 0.4; pointer-events: none; }
.ljpager__arw { font-size: 1.3em; line-height: 1; }
.ljpager__sep { color: var(--ink-3); }
.ljpager__info {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: var(--t-sm, .85rem);
  color: var(--ink-2);
  white-space: nowrap;
}
@media (max-width: 420px) {
  .ljpager { gap: 6px; }
  .ljpager__btn { padding: 0 10px; }
}
@media (max-width: 359px) {
  .ljpager__sep { display: none; }
  .ljpager__lbl { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

.ui-iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ui-iconbtn:hover { background: var(--surface-2); color: var(--ink); }
.ui-iconbtn svg { width: 20px; height: 20px; }

/* ---- chips and level tags ---- */
.ui-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--ink-2);
  font: 550 var(--t-sm)/1 var(--font-ui);
  cursor: pointer;
  white-space: nowrap;
}
button.ui-chip { min-height: 44px; }
.ui-chip[aria-pressed="true"], .ui-chip.is-on { background: var(--ink); border-color: var(--ink); color: var(--bg); }

.ui-lv {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--r-pill);
  background: color-mix(in srgb, var(--lv, var(--ink-3)) 13%, transparent);
  color: var(--lv, var(--ink-2));
  font: 700 11px/1 var(--font-num);
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.ui-lv::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ---- segmented control ---- */
.ui-seg {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: var(--r-md);
}
.ui-seg > * {
  flex: 1 1 0;
  min-width: 0;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-2);
  font: 600 var(--t-sm)/1 var(--font-ui);
  text-decoration: none;
  cursor: pointer;
}
.ui-seg > [aria-pressed="true"], .ui-seg > [aria-selected="true"], .ui-seg > [aria-current="page"] {
  background: var(--seg-on);
  color: var(--ink);
  box-shadow: var(--seg-ring), 0 1px 2px rgba(17, 20, 26, 0.08), 0 1px 1px rgba(17, 20, 26, 0.04);
}

/* ---- inputs ---- */
.ui-input {
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  font: 400 1rem/1.3 var(--font-ui);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.ui-input::placeholder { color: var(--ink-3); }
.ui-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---- answer states: correct / wrong / reveal ---- */
.is-correct { background: var(--ok-soft) !important; border-color: var(--ok) !important; color: var(--ok) !important; }
.is-wrong { background: var(--bad-soft) !important; border-color: var(--bad) !important; color: var(--bad) !important; }
.is-reveal { background: var(--warn-soft) !important; border-color: var(--warn) !important; color: var(--warn) !important; }

/* ---- progress bar and ring ---- */
:where(.ui-bar) {
  height: 8px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  overflow: hidden;
}
.ui-bar > span, .ui-bar > div {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--lv, var(--accent));
  transition: width 0.5s var(--ease);
}
.ui-ring {
  --p: 0;
  --size: 72px;
  position: relative;
  width: var(--size);
  height: var(--size);
  flex: none;
  border-radius: 50%;
  background: conic-gradient(var(--lv, var(--accent)) calc(var(--p) * 1%), var(--surface-3) 0);
  display: grid;
  place-items: center;
}
.ui-ring::before {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: var(--surface);
}
.ui-ring > * { position: relative; font: 700 var(--t-md)/1 var(--font-num); font-variant-numeric: tabular-nums; }

/* ---- empty state ---- */
:where(.ui-empty) {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-7) var(--s-5);
  text-align: center;
  color: var(--ink-3);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-lg);
}
.ui-empty b { color: var(--ink); font-size: var(--t-lg); }
.ui-empty__glyph { font: 500 2.2rem/1 var(--font-jp); color: var(--ink-3); opacity: 0.6; }

/* ---- toast ---- */
.ui-toast, .ui-update {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + var(--safe-b) + 14px);
  z-index: 900;
  max-width: min(92vw, 420px);
  padding: 12px 18px;
  border-radius: var(--r-md);
  background: var(--neutral-strong);
  color: var(--bg);
  font: 550 var(--t-sm)/1.35 var(--font-ui);
  box-shadow: var(--elev-over);
  transform: translate(-50%, 16px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
}
.ui-toast.is-on, .ui-update.is-on { opacity: 1; transform: translate(-50%, 0); }
/* The new-version offer (shell.js showUpdateBar) stays until it is used, above
   page sheets such as onboarding (z 1000) and one toast-height above the toast
   slot, so a save-failure toast is never hidden under it. */
.ui-update {
  display: flex; align-items: center; gap: 14px; pointer-events: auto; width: max-content; z-index: 1100;
  bottom: calc(var(--tab-h) + var(--safe-b) + 84px);
}
/* A long (translated) toast can still reach it: step aside while one shows. */
body:has(.ui-toast.is-on) .ui-update.is-on { opacity: 0; pointer-events: none; }
.ui-update__btn {
  min-height: 44px;
  padding: 0 16px;
  border: 1.5px solid currentColor;
  border-radius: var(--r-md);
  background: transparent;
  color: inherit;
  font: 700 var(--t-sm)/1 var(--font-ui);
  cursor: pointer;
}

/* Full-screen picture (shell.js openZoom), for any img[data-zoom]. */
img[data-zoom] { cursor: zoom-in; }
.ljs-zoom {
  width: 100vw; height: 100vh; height: 100dvh;
  max-width: none; max-height: none;
  margin: 0; padding: var(--safe-t) 0 var(--safe-b);
  border: 0; background: #000; color: #fff;
  cursor: zoom-out;
}
.ljs-zoom[open] { display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ljs-zoom::backdrop { background: #000; }
.ljs-zoom img { flex: 0 1 auto; min-height: 0; max-width: 100%; max-height: 100%; object-fit: contain; }
.ljs-zoom__cap { flex: none; margin: 0; padding: 10px 16px 14px; max-width: 640px; font-size: var(--t-sm); color: rgba(255,255,255,.8); text-align: center; }
.ljs-zoom__cap:empty { display: none; }
.ljs-zoom__x {
  position: absolute; top: calc(var(--safe-t) + 10px); right: 10px;
  display: grid; place-items: center; width: 44px; height: 44px;
  border: 0; border-radius: var(--r-pill);
  background: rgba(0,0,0,.5); color: #fff; cursor: pointer;
}
html.ljs-zoomed, html.ljs-zoomed body { overflow: hidden; }

/* What's new: shown once after an update (shell.js showNews). */
.ljs-news {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--tab-h) + var(--safe-b) + 12px);
  z-index: 560;
  max-width: 440px;
  margin: 0 auto;
  padding: 12px 14px 4px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--accent);
  border-radius: var(--r-lg);
  box-shadow: var(--elev-over);
  font-size: var(--t-sm);
}
.ljs-news__head { display: flex; align-items: center; justify-content: space-between; }
.ljs-news__close {
  display: grid; place-items: center;
  width: 36px; height: 36px; margin: -6px -8px -6px 0;
  border: 0; border-radius: var(--r-pill);
  background: transparent; color: var(--ink-2); cursor: pointer;
}
.ljs-news__close:hover { background: var(--surface-2); }
.ljs-news__title { margin: 6px 0 2px; font-weight: 600; }
.ljs-news ul, .home-news ul { margin: 0 0 8px; padding-left: 1.2em; color: var(--ink-2); }
.home-news { margin: 0 auto 10px; max-width: 520px; text-align: left; }
.home-news summary { cursor: pointer; text-align: center; color: var(--ink-2); }
@media (min-width: 1024px) {
  .ljs-news { left: auto; right: 24px; bottom: 24px; }
}

/* ---------------------------------------------------------------- shell */

/* App bar (module pages). shell.js builds it; a page without shell.js keeps
   its own header and simply has no bar. */
.appbar {
  position: sticky;
  top: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  height: var(--shell-h);
  padding: var(--safe-t) calc(8px + var(--safe-r)) 0 calc(8px + var(--safe-l));
  box-sizing: content-box;
  background: var(--glass);
  -webkit-backdrop-filter: saturate(1.6) blur(16px);
  backdrop-filter: saturate(1.6) blur(16px);
  border-bottom: 1px solid var(--line);
}
.appbar__back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 44px;
  height: 44px;
  padding: 0 10px 0 6px;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--accent-ink);
  font: 600 var(--t-md)/1 var(--font-ui);
  letter-spacing: 0;
  text-decoration: none;
}
.appbar__back:hover, .appbar__back:focus-visible { background: var(--surface-2); }
.appbar__back svg { width: 20px; height: 20px; }
.appbar__title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font: 700 var(--t-lg)/1.2 var(--font-ui);
  letter-spacing: -0.01em;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.appbar__title span {
  margin-left: 8px;
  font: 500 var(--t-sm)/1 var(--font-jp);
  color: var(--ink-3);
}
@media (max-width: 420px) {
  .appbar__back span { display: none; }
  .appbar__back { padding: 0; }
}

/* Top-right controls (app bar and home header): a two-letter language
   dropdown and a faint sun / moon light-dark toggle. */
.ljs-ctrls { flex: none; display: flex; align-items: center; gap: 2px; margin-left: auto; }
.ljs-lang {
  -webkit-appearance: none; appearance: none;
  height: 32px; padding: 0 8px; border-radius: 8px;
  border: 1px solid var(--line); background: transparent; color: var(--ink-2);
  font: 600 13px/1 var(--font-ui); letter-spacing: .04em; text-align: center; cursor: pointer;
}
.ljs-lang:hover, .ljs-lang:focus-visible { background: var(--surface-2); color: var(--ink); }
.ljs-theme {
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--ink);
  opacity: .5; cursor: pointer; transition: opacity .15s;
}
.ljs-theme:hover, .ljs-theme:focus-visible { opacity: .9; }
.ljs-theme svg { width: 20px; height: 20px; }

/* Tab bar: phones and tablets. Only drawn once shell.js has run, and the
   body only makes room for it then, so a page whose script failed loses the
   bar and nothing else. */
.ljs-tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 550;
  display: flex;
  height: var(--tab-h);
  padding: 0 var(--safe-r) var(--safe-b) var(--safe-l);
  box-sizing: content-box;
  background: var(--glass);
  -webkit-backdrop-filter: saturate(1.6) blur(18px);
  backdrop-filter: saturate(1.6) blur(18px);
  border-top: 1px solid var(--line);
}
.ljs-tab {
  position: relative;
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  color: var(--ink-3);
  font: 600 12px/1 var(--font-ui);
  letter-spacing: 0.01em;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.ljs-tab svg { width: 24px; height: 24px; }
.ljs-tab[aria-current="page"] { color: var(--accent-ink); }
.ljs-tab[aria-current="page"]::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: 28px;
  height: 3px;
  margin-left: -14px;
  border-radius: 0 0 3px 3px;
  background: var(--accent);
}
.ljs-tab__ico { position: relative; display: block; line-height: 0; }
.ljs-badge {
  position: absolute;
  top: -5px;
  left: 15px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--r-pill);
  border: 2px solid var(--surface);
  background: var(--bad);
  color: var(--on-state);
  font: 700 10px/14px var(--font-num);
  text-align: center;
  box-sizing: border-box;
}
.ljs-badge[hidden] { display: none; }

html.lj-shell body { padding-bottom: calc(var(--tab-h) + var(--safe-b)); }

/* Hub tab strip (shell.js injectHubNav): the pages of one menu area. */
.ljs-hubwrap {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.ljs-hubnav {
  display: flex;
  gap: 6px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 8px calc(12px + var(--safe-r)) 8px calc(12px + var(--safe-l));
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.ljs-hubnav::-webkit-scrollbar { display: none; }
.ljs-hubnav a {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  color: var(--ink-2);
  font: 600 13px/1 var(--font-ui);
  white-space: nowrap;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.ljs-hubnav a:hover { background: var(--surface-2); color: var(--ink); }
.ljs-hubnav a[aria-current="page"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
@media print { .ljs-hubwrap { display: none; } }

/* Sidebar: desktop. */
.ljs-side { display: none; }

@media (min-width: 1024px) {
  .ljs-tabbar { display: none; }
  html.lj-shell body { padding-bottom: 0; padding-left: var(--side-w); }
  .ui-toast { bottom: 28px; margin-left: calc(var(--side-w) / 2); }
  .ui-update { bottom: 98px; margin-left: calc(var(--side-w) / 2); }
  .appbar__back { display: none; }
  .appbar { padding-left: 24px; padding-right: 16px; }

  .ljs-side {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 550;
    display: flex;
    flex-direction: column;
    width: var(--side-w);
    padding: 18px 14px 14px;
    box-sizing: border-box;
    line-height: 1.55;
    background: var(--surface);
    border-right: 1px solid var(--line);
  }
  .ljs-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 8px 18px;
    color: var(--ink);
    text-decoration: none;
  }
  .ljs-brand b { font: 750 var(--t-lg)/1.1 var(--font-ui); letter-spacing: -0.01em; }
  .ljs-brand small { display: block; font: 500 var(--t-xs)/1.3 var(--font-jp); color: var(--ink-3); }
  .ljs-nav { display: flex; flex-direction: column; gap: 2px; }
  .ljs-item {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 40px;
    padding: 0 10px;
    border-radius: 10px;
    color: var(--ink-2);
    font: 600 var(--t-md)/1 var(--font-ui);
    text-decoration: none;
  }
  .ljs-item svg { width: 20px; height: 20px; flex: none; }
  .ljs-item:hover { background: var(--surface-2); color: var(--ink); }
  .ljs-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); }
  .ljs-item .ljs-count {
    margin-left: auto;
    min-width: 22px;
    padding: 3px 7px;
    border-radius: var(--r-pill);
    background: var(--bad);
    color: var(--on-state);
    font: 700 11px/1 var(--font-num);
    text-align: center;
  }
  .ljs-item .ljs-count[hidden] { display: none; }
  .ljs-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    margin: 14px -6px 0;
    padding: 0 6px;
    border-top: 1px solid var(--line);
    scrollbar-width: thin;
  }
  .ljs-group {
    margin: 16px 10px 6px;
    font: 650 11px/1 var(--font-ui);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-3);
  }
  .ljs-mod {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 34px;
    padding: 0 10px;
    border-radius: 8px;
    color: var(--ink-2);
    font: 500 var(--t-sm)/1.2 var(--font-ui);
    text-decoration: none;
  }
  .ljs-mod:hover { background: var(--surface-2); color: var(--ink); }
  .ljs-mod[aria-current="page"] { background: var(--surface-2); color: var(--ink); font-weight: 650; }
  .ljs-mod i {
    width: 24px;
    height: 24px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 7px;
    background: var(--surface-2);
    color: var(--lv, var(--ink-2));
    font: 600 13px/1 var(--font-jp);
    font-style: normal;
  }
  .ljs-mod[aria-current="page"] i { background: var(--accent); color: var(--on-accent); }
  .ljs-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 6px 0;
    border-top: 1px solid var(--line);
    font: 500 var(--t-xs)/1.3 var(--font-ui);
    color: var(--ink-3);
  }
}

/* Brand mark: a 日 on an indigo tile. */
.ljs-mark {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
  font: 700 18px/1 var(--font-jp);
}

/* App credit, appended by shell.js. */
.lj-shell-foot {
  padding: 0 calc(12px + var(--safe-r)) 16px calc(12px + var(--safe-l));
  box-sizing: border-box;
}
.lj-credit {
  margin-top: 10px;
  text-align: center;
  font: 500 11px/1.6 var(--font-ui);
  color: var(--ink-3);
}
.lj-credit a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

/* ============================================================== 3b. icon set
   Lucide-style 24x24 outlines used as a mask, so each takes the colour of the
   text around it (currentColor) in both themes. Markup:
   <span class="ic ic-play" aria-hidden="true"></span>Label  (icon-only: add ic-solo). */
.ic {
  display: inline-block;
  width: 1.1em;
  height: 1.1em;
  margin-inline-end: 0.35em;
  vertical-align: -0.18em;
  flex: none;
  background: currentColor;
  -webkit-mask: var(--ic) center / contain no-repeat;
  mask: var(--ic) center / contain no-repeat;
}
.ic.ic-solo { margin-inline-end: 0; }
.ic-play { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolygon points='6 3 20 12 6 21 6 3'/%3E%3C/svg%3E"); }
.ic-volume { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolygon points='11 5 6 9 2 9 2 15 6 15 11 19 11 5'/%3E%3Cpath d='M15.54 8.46a5 5 0 0 1 0 7.07'/%3E%3Cpath d='M19.07 4.93a10 10 0 0 1 0 14.14'/%3E%3C/svg%3E"); }
.ic-mic { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3z'/%3E%3Cpath d='M19 10v2a7 7 0 0 1-14 0v-2'/%3E%3Cpath d='M12 19v3'/%3E%3C/svg%3E"); }
.ic-image { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect width='18' height='18' x='3' y='3' rx='2'/%3E%3Ccircle cx='9' cy='9' r='2'/%3E%3Cpath d='m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21'/%3E%3C/svg%3E"); }
.ic-pencil { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z'/%3E%3C/svg%3E"); }
.ic-check { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E"); }
.ic-x { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M18 6 6 18'/%3E%3Cpath d='m6 6 12 12'/%3E%3C/svg%3E"); }
.ic-square { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect width='18' height='18' x='3' y='3' rx='2'/%3E%3C/svg%3E"); }
.ic-square-check { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect width='18' height='18' x='3' y='3' rx='2'/%3E%3Cpath d='m9 12 2 2 4-4'/%3E%3C/svg%3E"); }
.ic-circle { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3C/svg%3E"); }
.ic-star { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/%3E%3C/svg%3E"); }
.ic-flame { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z'/%3E%3C/svg%3E"); }
.ic-trophy { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9H4.5a2.5 2.5 0 0 1 0-5H6'/%3E%3Cpath d='M18 9h1.5a2.5 2.5 0 0 0 0-5H18'/%3E%3Cpath d='M4 22h16'/%3E%3Cpath d='M10 14.66V17c0 .55-.47.98-.97 1.21C7.85 18.75 7 20.24 7 22'/%3E%3Cpath d='M14 14.66V17c0 .55.47.98.97 1.21C16.15 18.75 17 20.24 17 22'/%3E%3Cpath d='M18 2H6v7a6 6 0 0 0 12 0V2Z'/%3E%3C/svg%3E"); }
.ic-map { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolygon points='3 6 9 3 15 6 21 3 21 18 15 21 9 18 3 21 3 6'/%3E%3Cline x1='9' x2='9' y1='3' y2='18'/%3E%3Cline x1='15' x2='15' y1='6' y2='21'/%3E%3C/svg%3E"); }
.ic-sparkles { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z'/%3E%3Cpath d='M20 3v4'/%3E%3Cpath d='M22 5h-4'/%3E%3C/svg%3E"); }
.ic-alert { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3'/%3E%3Cpath d='M12 9v4'/%3E%3Cpath d='M12 17h.01'/%3E%3C/svg%3E"); }
.ic-plus { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12h14'/%3E%3Cpath d='M12 5v14'/%3E%3C/svg%3E"); }
.ic-minus { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12h14'/%3E%3C/svg%3E"); }
.ic-replay { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8'/%3E%3Cpath d='M3 3v5h5'/%3E%3C/svg%3E"); }
.ic-fit { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 3H5a2 2 0 0 0-2 2v3'/%3E%3Cpath d='M21 8V5a2 2 0 0 0-2-2h-3'/%3E%3Cpath d='M3 16v3a2 2 0 0 0 2 2h3'/%3E%3Cpath d='M16 21h3a2 2 0 0 0 2-2v-3'/%3E%3C/svg%3E"); }

/* ======================================================= 4a. generated pages
   Scoped by the lj-gen class gen-pages puts on <body>; the extra class makes
   each rule outrank the template's own single-class rule wherever it sits. */

.lj-gen { font-family: var(--font-ui); line-height: 1.55; }
.lj-gen .wrap { padding-top: 20px; }
/* section banner: the home-tile picture, a 5:2 band filling the content
   column (872px = .wrap 900 less its padding) so its edges line up with the
   cards below and the section's first item stays above the fold */
.ljs-banner { max-width: 872px; margin: 0 auto 16px; }
.ljs-banner img { display: block; width: 100%; height: auto; aspect-ratio: 5 / 2; object-fit: cover; border-radius: var(--r-md, 12px); background: var(--line, rgba(127,127,127,.15)); }
/* dark theme: tone down the bright photos so they do not glare off the page */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .lj-gen .word-art img,
  :root:not([data-theme="light"]) .lj-gen .pic > img,
  :root:not([data-theme="light"]) figure.lj-image img { filter: brightness(.85); }
}
:root[data-theme="dark"] .lj-gen .word-art img,
:root[data-theme="dark"] .lj-gen .pic > img,
:root[data-theme="dark"] figure.lj-image img { filter: brightness(.85); }
.lj-ai-note { margin: 8px 0 0; color: var(--muted); font-size: .72rem; text-align: center; letter-spacing: 0; text-transform: none; }
.lj-gen .lead { color: var(--ink-2); font-size: var(--t-md); line-height: 1.6; max-width: 70ch; margin-bottom: 18px; }
.lj-gen .jp, .lj-gen .kcard__c, .lj-gen .qbox__k, .lj-gen .sheet__c, .lj-gen .card__front,
.lj-gen .write-char, .lj-gen .word, .lj-gen .stem, .lj-gen .passage { font-family: var(--font-jp); }

/* cards */
.lj-gen .prog, .lj-gen .card, .lj-gen .box, .lj-gen .qbox, .lj-gen .wcard, .lj-gen .stat,
.lj-gen #session, .lj-gen #sessionDone, .lj-gen #emptyMsg {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--elev);
}
.lj-gen .prog { padding: 16px 18px; }
.lj-gen .prog__top { font-size: var(--t-sm); color: var(--ink-2); font-weight: 550; }
.lj-gen .prog__n { color: var(--ink); font: 750 var(--t-xl)/1 var(--font-num); letter-spacing: -0.01em; }
.lj-gen .prog__hint { color: var(--ink-3); font-size: var(--t-xs); }
.lj-gen .prog__bar, .lj-gen .bar__bar { background: var(--surface-3); height: 8px; }
.lj-gen .prog__fill, .lj-gen .bar__fill { background: var(--accent); border-radius: inherit; }
.lj-gen .stat b { color: var(--ink); font-family: var(--font-num); font-weight: 750; }
.lj-gen .stat span { color: var(--ink-3); }
.lj-gen .box h2 { color: var(--ink-3); font-size: var(--t-xs); letter-spacing: 0.08em; font-weight: 650; }

/* segmented controls: level pickers and view tabs */
.lj-gen .levels, .lj-gen .lvnav {
  background: var(--surface-2);
  border: 0;
  border-radius: var(--r-md);
  padding: 3px;
  gap: 2px;
}
.lj-gen .lvl, .lj-gen .lvnav a {
  min-height: 42px;
  border-radius: 9px;
  color: var(--ink-2);
  font-weight: 650;
  font-family: var(--font-num);
  letter-spacing: 0.02em;
}
.lj-gen .lvl[aria-pressed="true"], .lj-gen .lvnav a[aria-current="page"] {
  background: var(--seg-on);
  color: var(--lv, var(--ink));
  box-shadow: var(--seg-ring), 0 1px 2px rgba(17, 20, 26, 0.1), 0 1px 1px rgba(17, 20, 26, 0.05);
}
/* Level buttons are rendered "All, N5..N1" (levels) and "N5..N1" (lvnav). */
.lj-gen .levels .lvl:nth-child(2), .lj-gen .lvnav a:nth-child(1), .lj-gen .levels--noall .lvl:nth-child(1) { --lv: var(--lv-n5); }
.lj-gen .levels .lvl:nth-child(3), .lj-gen .lvnav a:nth-child(2), .lj-gen .levels--noall .lvl:nth-child(2) { --lv: var(--lv-n4); }
.lj-gen .levels .lvl:nth-child(4), .lj-gen .lvnav a:nth-child(3), .lj-gen .levels--noall .lvl:nth-child(3) { --lv: var(--lv-n3); }
.lj-gen .levels .lvl:nth-child(5), .lj-gen .lvnav a:nth-child(4) { --lv: var(--lv-n2); }
.lj-gen .levels .lvl:nth-child(6), .lj-gen .lvnav a:nth-child(5) { --lv: var(--lv-n1); }
.lj-gen .lvnav a { position: relative; }
.lj-gen .lvnav a::before, .lj-gen .levels .lvl:not(:first-child)::before, .lj-gen .levels--noall .lvl:first-child::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--lv, currentColor);
  vertical-align: 1px;
}

.lj-gen .tabs { gap: 2px; padding: 3px; background: var(--surface-2); border-radius: var(--r-md); }
.lj-gen .tab {
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-2);
  font-weight: 600;
  min-height: 52px;
}
.lj-gen .tab[aria-selected="true"] {
  background: var(--seg-on);
  color: var(--accent-ink);
  box-shadow: var(--seg-ring), 0 1px 2px rgba(17, 20, 26, 0.1), 0 1px 1px rgba(17, 20, 26, 0.05);
}

/* chips */
.lj-gen .chaps { gap: 8px; scrollbar-width: none; }
.lj-gen .chaps::-webkit-scrollbar { display: none; }

/* chip-row slider: assets/shell.js wraps every .chaps row with this, a pair
   of edge-fade masks and prev/next scroll buttons. Touch keeps the plain
   native scroller above; only a fine, hover-capable pointer gets the visible
   controls and the thin scrollbar. */
.lj-gen .ljs-chaprow { position: relative; }
.lj-gen .ljs-chaprow::before, .lj-gen .ljs-chaprow::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  width: 26px;
  z-index: 1;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
.lj-gen .ljs-chaprow::before { left: 0; background: linear-gradient(to right, var(--bg), transparent); }
.lj-gen .ljs-chaprow::after { right: 0; background: linear-gradient(to left, var(--bg), transparent); }
/* where the round arrows show, the fade runs solid under them so a clipped chip never peeks out beside one */
@media (hover: hover) and (pointer: fine) {
  .lj-gen .ljs-chaprow::before, .lj-gen .ljs-chaprow::after { width: 84px; }
  .lj-gen .ljs-chaprow::before { left: 0; background: linear-gradient(to right, var(--bg) 62%, transparent); }
  .lj-gen .ljs-chaprow::after { right: 0; background: linear-gradient(to left, var(--bg) 62%, transparent); }
  .lj-gen .ljs-chapnav--prev { left: 0; }
  .lj-gen .ljs-chapnav--next { right: 0; }
}
.lj-gen .ljs-chaprow.has-overflow:not(.at-start)::before { opacity: 1; }
.lj-gen .ljs-chaprow.has-overflow:not(.at-end)::after { opacity: 1; }
.lj-gen .ljs-chapnav {
  display: none;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  padding: 0;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
  z-index: 2;
  box-shadow: 0 1px 2px rgba(17, 20, 26, 0.12);
}
.lj-gen .ljs-chapnav svg { width: 13px; height: 13px; }
.lj-gen .ljs-chapnav--prev { left: -4px; }
.lj-gen .ljs-chapnav--next { right: -4px; }
.lj-gen .ljs-chapnav:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
@media (hover: hover) and (pointer: fine) {
  .lj-gen .ljs-chaprow.has-overflow .ljs-chapnav { display: flex; }
  /* Nothing to scroll back to (or on to): the arrow would only cover a chip. */
  .lj-gen .ljs-chaprow.at-start .ljs-chapnav--prev,
  .lj-gen .ljs-chaprow.at-end .ljs-chapnav--next { display: none; }
  .lj-gen .ljs-chaprow .chaps {
    scrollbar-width: thin;
    scrollbar-color: var(--line-strong) transparent;
    cursor: grab;
  }
  .lj-gen .ljs-chaprow .chaps::-webkit-scrollbar { display: block; height: 6px; }
  .lj-gen .ljs-chaprow .chaps::-webkit-scrollbar-track { background: transparent; }
  .lj-gen .ljs-chaprow .chaps::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: var(--r-pill); }
  .lj-gen .ljs-chaprow .chaps.ljs-dragging { cursor: grabbing; scroll-snap-type: none; }
}
.lj-gen .chip {
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--ink-2);
  font-weight: 550;
}
.lj-gen button.chip { min-height: 44px; }
.lj-gen .chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.lj-gen .chip small { opacity: 0.65; font-family: var(--font-num); }

/* search and inputs */
.lj-gen .search, .lj-gen input[type="search"], .lj-gen input[type="text"] {
  min-height: 46px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
}
.lj-gen .search::placeholder { color: var(--ink-3); }
.lj-gen .search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
.lj-gen .count { color: var(--ink-3); font-size: var(--t-xs); font-weight: 550; }

/* list rows */
.lj-gen .grp { color: var(--ink-3); font-size: var(--t-xs); letter-spacing: 0.08em; font-weight: 650; margin: 22px 2px 8px; }
.lj-gen .row {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px 12px 12px 14px;
  box-shadow: var(--elev);
}
.lj-gen .row.is-known { border-color: color-mix(in srgb, var(--ok) 40%, var(--line)); background: color-mix(in srgb, var(--ok-soft) 70%, var(--surface)); }
.lj-gen .sub { color: var(--ink-3); }
.lj-gen .en { color: var(--ink-2); }
.lj-gen .tagL {
  border: 0;
  border-radius: var(--r-pill);
  padding: 2px 8px;
  background: color-mix(in srgb, var(--lv, var(--ink-3)) 13%, transparent);
  color: var(--lv, var(--ink-2));
  font: 700 10.5px/1.4 var(--font-num);
  letter-spacing: 0.04em;
}
.lj-gen .iconbtn, .lj-gen .speakbtn {
  border: 0;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink-2);
}
.lj-gen .iconbtn:hover, .lj-gen .speakbtn:hover { background: var(--surface-3); color: var(--ink); }
.lj-gen .iconbtn.on { background: var(--ok); color: var(--on-state); }

/* buttons */
.lj-gen .btn {
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
}
.lj-gen .btn:hover { background: var(--surface-2); }
.lj-gen .btn.primary, .lj-gen #startBtn, .lj-gen #showBtn { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.lj-gen .btn.primary:hover, .lj-gen #startBtn:hover, .lj-gen #showBtn:hover { background: var(--accent-hover); }
.lj-gen .btn.outline { background: var(--accent-soft); border-color: transparent; color: var(--accent-ink); }
.lj-gen .btn.on { background: var(--ok); border-color: var(--ok); color: var(--on-state); }
.lj-gen .btn--ghost { background: transparent; border-color: var(--line-strong); color: var(--ink-2); }
.lj-gen .btn--ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 45%, transparent); color: var(--ok); }
.lj-gen .btn--warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 45%, transparent); color: var(--warn); }
.lj-gen a.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

/* quiz */
.lj-gen .opt {
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  transition: background-color 0.15s, border-color 0.15s;
}
@media (hover: hover) { .lj-gen .opt:not(:disabled):hover { border-color: var(--accent); background: var(--accent-soft); } }
.lj-gen .opt.right { background: var(--ok); border-color: var(--ok); color: var(--on-state); }
.lj-gen .opt.wrong { background: var(--bad); border-color: var(--bad); color: var(--on-state); }
.lj-gen .opt[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.lj-gen .opt[aria-pressed="true"] b { color: var(--on-accent); }
.lj-gen .opt b { color: var(--ink-3); }
.lj-gen .verdict { font-weight: 550; }
.lj-gen .yes { color: var(--ok); }
.lj-gen .no { color: var(--bad); }
.lj-gen .mid { color: var(--warn); }
.lj-gen .grade.A { background: var(--ok); color: var(--on-state); }
.lj-gen .grade.B { background: var(--warn); color: var(--on-state); }
.lj-gen .grade.C { background: var(--bad); color: var(--on-state); }
.lj-gen .gbtn { background: var(--surface); border-radius: var(--r-md); }
.lj-gen .gbtn:hover { background: var(--surface-2); }
.lj-gen .gbtn[data-q="0"] { border-color: color-mix(in srgb, var(--bad) 55%, var(--line)); }
.lj-gen .gbtn[data-q="1"] { border-color: color-mix(in srgb, var(--warn) 55%, var(--line)); }
.lj-gen .gbtn[data-q="2"] { border-color: color-mix(in srgb, var(--ok) 55%, var(--line)); }
.lj-gen .gbtn[data-q="3"] { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.lj-gen .gbtn[data-q="1"] .glab { color: var(--warn); }
.lj-gen .gbtn[data-q="3"] .glab { color: var(--accent-ink); }

/* kanji tiles and the detail sheet */
.lj-gen .kcard {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--elev);
  transition: transform 0.12s var(--ease), border-color 0.12s;
}
@media (hover: hover) { .lj-gen .kcard:hover { transform: translateY(-2px); border-color: var(--accent-line); } }
.lj-gen .kcard.is-known { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); background: color-mix(in srgb, var(--ok-soft) 70%, var(--surface)); }
.lj-gen .kcard__m { color: var(--ink-3); }
.lj-gen .sheet { background: var(--scrim); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.lj-gen .sheet__in {
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--elev-over);
  padding-top: 22px;
}
@media (min-width: 700px) { .lj-gen .sheet__in { border-radius: var(--r-xl); } }
.lj-gen .dl dt { color: var(--ink-3); }

/* handwriting pad stays paper-white in both themes: the stroke engine draws
   in dark ink on it */
.canvas-wrap { background: #fbfbfc !important; border: 1px solid var(--line-strong) !important; border-radius: var(--r-lg) !important; box-shadow: var(--elev) !important; }
.write-result.pass { color: var(--ok) !important; background: var(--ok-soft) !important; }
.write-result.fail { color: var(--bad) !important; background: var(--bad-soft) !important; }

/* practice test */
.lj-gen .bar { background: var(--bg); border-bottom-color: var(--line); }
.lj-gen .bar__sec { color: var(--ink); }
.lj-gen .clock { font-family: var(--font-num); }
.lj-gen .clock.low { color: var(--bad); }
.lj-gen .qtype { color: var(--ink-3); font-weight: 650; letter-spacing: 0.06em; }
.lj-gen .passage { background: var(--surface); border-color: var(--line); border-radius: var(--r-md); }
.lj-gen .dot { border-color: var(--line-strong); background: var(--surface); color: var(--ink-3); border-radius: 8px; }
.lj-gen .dot.done { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.lj-gen .dot.now { outline-color: var(--ink); }
.lj-gen table.comp th, .lj-gen table.comp td { border-bottom-color: var(--line); }
.lj-gen table.comp tr.grp td { background: var(--surface-2); }
.lj-gen .rev { background: var(--surface); border-color: var(--line); border-radius: var(--r-md); }
.lj-gen .warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); color: var(--ink); }
.lj-gen .resrow { border-bottom-color: var(--line); }
.lj-gen .fbar { background: var(--accent); }
.lj-gen .flab { color: var(--ink-3); }
.lj-gen .card__tag { border-color: var(--line-strong); color: var(--ink-3); border-radius: var(--r-pill); }

/* footnote and empty */
.lj-gen .empty { color: var(--ink-3); }
.lj-gen .note { color: var(--ink-3); border-top-color: var(--line); font-size: var(--t-xs); line-height: 1.6; margin-top: 32px; padding-top: 14px; }

/* ================================================== 4b. hand-written pages */

.lj-hand::before { display: none !important; }
.lj-hand > .container, .lj-hand .container { padding-top: 22px; }
.lj-hand header h1 {
  font-family: var(--font-ui);
  font-size: clamp(1.75rem, 4.5vw, 2.4rem);
  font-weight: 800;
  letter-spacing: -0.025em;
  color: var(--ink);
}
.lj-hand header h1 span { color: var(--accent); font-family: var(--font-jp); }
.lj-hand header p { color: var(--ink-3); letter-spacing: 0.06em; font-weight: 600; }
.lj-hand .modal-overlay { background: var(--scrim) !important; }
.lj-hand .modal { background: var(--surface); color: var(--ink); box-shadow: var(--elev-over); border: 1px solid var(--line); border-radius: var(--r-xl); }
.lj-hand input:not([type="checkbox"]):not([type="radio"]):focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.lj-hand footer { color: var(--ink-3); }

/* The app bar already names the page, so the big title block is only kept on
   the desktop layout. Phones and tablets get that height back. */
@media (max-width: 1023px) {
  html.lj-shell .lj-hand .lj-hero { display: none; }
}

/* Component metrics: the same pill, tile, option and progress shapes the
   generated pages use (.chip / .btn / .opt / .prog), without touching any of
   the state classes (.active, .learned, .irregular, .selected, .open,
   .pick-correct, .pick-wrong) or any JS-toggled display. Only widths, radii,
   weights and shadows are set here, never a colour a state class owns. */
.lj-hand :is(.controls button, .pill, .pill-btn, .quiz-filter button, .quiz-mode-row button,
  .write-filter button, .write-nav button, .quiz-mode-toggle button, .quiz-answer-row button,
  .write-btns button, .modal .btn-row button, .quiz-listen) {
  border-width: 1px;
  border-radius: var(--r-pill);
  font-weight: 600;
  letter-spacing: 0;
}
.lj-hand :is(.controls button, .pill, .pill-btn, .quiz-mode-toggle button, .quiz-answer-row button,
  .write-btns button, .modal .btn-row button) { min-height: 40px; }
/* the one-screen quiz keeps its compact controls */
.lj-hand.quiz-on .controls button { min-height: 0; }
.lj-hand .modal .btn-row button { display: inline-flex; align-items: center; justify-content: center; }
.lj-hand .modal .btn-row button[hidden] { display: none; }
/* Reset sits in the mode row but is not a mode: a quiet text button */
.controls button.ctl-reset,
.controls button.ctl-reset:hover { background: transparent; border-color: transparent; color: var(--muted);
  text-decoration: underline; text-underline-offset: 3px; }
.controls button.ctl-reset:hover { color: var(--ink); }

/* tiles. :where() keeps these at (0,1,0) so page state rules such as
   .card.irregular's thick left border and :hover lifts still win. */
.lj-hand :where(.kana-cell:not(.vowel-header), .card, .lc, .map-wrap) {
  border-width: 1px;
  border-radius: var(--r-md);
  box-shadow: var(--elev);
}
@media (min-width: 901px) { .lj-hand .detail-panel { box-shadow: var(--elev); } }
.lj-hand :where(.quiz-pick-btn, .q-opts button) {
  border-width: 1px;
  border-radius: var(--r-md);
  box-shadow: var(--elev);
  font-weight: 700;
}

/* progress */
.lj-hand .bar-track { height: 8px; background: var(--surface-3); border-radius: var(--r-pill); }
.lj-hand .bar-fill { background: var(--accent); border-radius: inherit; }
.lj-hand .bar-label { color: var(--ink-2); font-weight: 550; }

/* ========================================= 5. shared sequence player (LJPlayer) */

.lj-player {
  display: flex;
  flex-direction: column;
  gap: var(--s-2, 8px);
  padding: var(--s-3, 12px);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-lg, 14px);
}
.lj-player__row { display: flex; flex-wrap: wrap; gap: var(--s-2, 8px); }
.lj-player__btn {
  flex: 1 1 auto;
  min-width: 72px;
  padding: 10px 12px;
  font-size: var(--t-sm, 0.875rem);
  font-weight: 650;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md, 10px);
  cursor: pointer;
}
.lj-player__btn:hover { background: var(--surface-3); }
.lj-player__btn:disabled { opacity: 0.45; cursor: default; }
.lj-player__btn--primary {
  flex: 2 1 auto;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.lj-player__btn--primary:hover { background: var(--accent-hover, var(--accent)); }
.lj-player__btn--repeat[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--ink);
}
.lj-player__status { font-size: var(--t-xs, 0.75rem); color: var(--ink-3); text-align: center; }
.lj-player__bar {
  height: 6px;
  border-radius: var(--r-pill, 999px);
  background: var(--surface-3);
  overflow: hidden;
}
.lj-player__fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: inherit;
  transition: width 0.2s ease;
}
@media (prefers-reduced-motion: reduce) { .lj-player__fill { transition: none; } }
@media (max-width: 360px) { .lj-player__btn { min-width: 64px; font-size: var(--t-xs, 0.75rem); padding: 8px 8px; } }

@media print {
  .ljs-tabbar, .ljs-side, .appbar { display: none !important; }
  html.lj-shell body { padding: 0 !important; }
}
