/* ───────────────────────────────────────────────────────────────
   Bee's Grammar — manuscript paper (原稿用紙) edition
   Visual language borrowed from Kanji Crossings: paper, green rule,
   black ink and one vermilion pen. Klee One for what is written on
   the page (Japanese), BIZ UDPGothic for what is printed around it.

   Two printings of the same sheet: `:root` is day, `[data-theme=dark]`
   is night. Every colour is a token below; nothing downstream names
   a colour of its own. Text sizes are in rem so the reader's size
   control (html[data-size]) scales the whole page.
   ─────────────────────────────────────────────────────────────── */
:root {
  --cell: 36px;
  --hair: 1px;
  --frame-w: 1.5px;
  --ctl: 36px;
  --gutter: 48px;
  --header-h: 56px;

  --ground: #f5f5f0;
  --paper: #fcfcfa;
  --paper-deep: #f3f3ee;
  --rule: #b9d3c4;
  --rule-faint: rgba(127, 174, 149, 0.22);
  --rule-mid: #7fae95;
  --rule-strong: #2f6b4f;
  --frame: #2f6b4f;
  --ink: #161616;
  --ink-2: #4d4d48;
  --ink-3: #66665f;
  --vermilion: #c8361e;
  --vermilion-ink: #a52a15;
  --vermilion-solid: #c8361e;
  --vermilion-hover: #a52a15;
  --vermilion-wash: #f6e1db;
  --green-wash: #e3efe8;
  --fill: #161616;
  --on-fill: #fcfcfa;
  --on-vermilion: #ffffff;
  --selection: #e3efe8;
  --backdrop: rgba(22, 22, 22, 0.32);
  --image-dim: none;
  color-scheme: light;

  --font-ui: 'BIZ UDPGothic', 'Hiragino Sans', 'Yu Gothic', system-ui, sans-serif;
  --font-hand: 'Klee One', 'Hiragino Mincho ProN', 'Yu Mincho', serif;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --focus: 0 0 0 2px var(--paper), 0 0 0 4px var(--rule-strong);
  --grid: linear-gradient(var(--rule-faint) var(--hair), transparent var(--hair)),
          linear-gradient(90deg, var(--rule-faint) var(--hair), transparent var(--hair));
  accent-color: var(--rule-strong);
}

/* night: the same sheet under a lamp */
:root[data-theme='dark'] {
  --ground: #0d0f0d;
  --paper: #171a17;
  --paper-deep: #212520;
  --rule: #2d372e;
  --rule-faint: rgba(77, 101, 85, 0.26);
  --rule-mid: #4d6555;
  --rule-strong: #8ab89f;
  --frame: #4a6a55;
  --ink: #eceadf;
  --ink-2: #b4b2a6;
  --ink-3: #8a897e;
  --vermilion: #e2543a;
  --vermilion-ink: #f4795c;
  --vermilion-solid: #c33f26;
  --vermilion-hover: #a8341f;
  --vermilion-wash: #38201b;
  --green-wash: #1f2d25;
  --fill: #35483c;
  --on-fill: #eceadf;
  --selection: #2d4136;
  --backdrop: rgba(7, 9, 7, 0.62);
  --image-dim: brightness(0.88);
  color-scheme: dark;
}

/* the reader's text size: six steps, persisted by site.js */
html { font-size: 100%; }
html[data-size='0'] { font-size: 87.5%; }
html[data-size='1'] { font-size: 93.75%; }
html[data-size='3'] { font-size: 112.5%; }
html[data-size='4'] { font-size: 125%; }
html[data-size='5'] { font-size: 140%; }

@media (min-resolution: 2dppx) { :root { --hair: 0.5px; } }
@media (max-width: 900px) { :root { --cell: 28px; --ctl: 42px; --gutter: 28px; } }
@media (max-width: 560px) { :root { --cell: 22px; --ctl: 44px; --gutter: 16px; --header-h: 52px; } }

/* ── Base ─────────────────────────────────────────────────── */
* { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 16px);
  scrollbar-color: var(--rule-mid) var(--ground);
}
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
::selection { background: var(--selection); color: var(--ink); }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
button, a, input, select, label, summary { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 2px; }
img, svg { max-width: 100%; }
h1, h2, h3, h4, p { margin-top: 0; }
h1, h2, h3, h4 { font-weight: 700; }
em { font-style: normal; }
[hidden] { display: none !important; }
[lang='ja'] { line-break: strict; }
input, textarea { caret-color: var(--vermilion); }
.wrap { width: min(1120px, calc(100% - var(--gutter) * 2)); margin-inline: auto; }
.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 { position: fixed; top: -100px; left: 16px; z-index: 60; padding: 10px 16px; background: var(--fill); color: var(--on-fill); font-weight: 700; }
.skip:focus { top: 8px; }
kbd {
  font-family: var(--font-ui);
  font-size: 11px;
  padding: 0 5px;
  border: var(--hair) solid var(--rule-strong);
  border-radius: 2px;
  color: var(--rule-strong);
  line-height: 16px;
  display: inline-block;
  min-width: 18px;
  text-align: center;
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--ground); }
::-webkit-scrollbar-thumb { background: var(--rule-mid); border: 2px solid var(--ground); }

/* running head: the heading voice of every section */
.eyebrow {
  display: block;
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--rule-strong);
  line-height: 1.5;
}
.small-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--vermilion); margin-right: 8px; vertical-align: 1px; }

/* ── Imprint (sticky header) ──────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--ground);
  border-bottom: var(--hair) solid var(--rule);
}
.header-inner {
  width: min(1240px, calc(100% - var(--gutter)));
  height: var(--header-h);
  margin-inline: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); min-width: 0; }
.bee { width: 24px; height: 26px; flex-shrink: 0; color: var(--ink); }
.brand > span { font-weight: 700; font-size: 1.125rem; letter-spacing: 0.01em; line-height: 1; white-space: nowrap; }
.brand-sub {
  font-weight: 400;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--rule-strong);
  margin-left: 10px;
  padding-left: 10px;
  border-left: var(--hair) solid var(--rule);
}

/* display controls: printed cells, pressed state is a wash + red rule */
.prefs { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.theme-switch, .size-switch { display: flex; border: var(--hair) solid var(--rule-strong); background: var(--paper); }
.theme-switch button, .size-switch button, .theme-cycle {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: var(--ctl);
  height: var(--ctl);
  color: var(--rule-strong);
  transition: background 140ms var(--ease-out), color 140ms var(--ease-out);
}
.theme-switch button + button { border-left: var(--hair) solid var(--rule); }
.theme-switch svg, .theme-cycle svg { width: 16px; height: 16px; }
.theme-switch button[aria-pressed='true'] { background: var(--green-wash); color: var(--ink); }
.theme-switch button[aria-pressed='true']::after {
  content: '';
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 3px;
  height: 2px;
  background: var(--vermilion);
}
.theme-cycle { display: none; border: var(--hair) solid var(--rule-strong); background: var(--paper); color: var(--ink); }
.cycle-mark { display: grid; place-items: center; }
.size-switch button { display: inline-flex; align-items: center; justify-content: center; gap: 1px; font-weight: 700; font-size: 13px; color: var(--ink); }
.size-switch button .size-big { font-size: 17px; }
.size-switch .size-sign { font-size: 12px; margin-top: -2px; color: var(--rule-strong); }
.size-switch button:disabled { color: var(--ink-3); cursor: not-allowed; opacity: 0.5; }
.size-value {
  display: inline-grid;
  place-items: center;
  min-width: 52px;
  padding: 0 6px;
  font-size: 12px;
  color: var(--ink-2);
  border-inline: var(--hair) solid var(--rule);
}
@media (hover: hover) {
  .theme-switch button:hover, .size-switch button:hover:not(:disabled), .theme-cycle:hover { background: var(--paper-deep); color: var(--ink); }
}
@media (hover: none) {
  .theme-switch button:active, .size-switch button:active, .theme-cycle:active { background: var(--paper-deep); }
}

/* ── The sheet ────────────────────────────────────────────── */
.sheet {
  width: min(1240px, calc(100% - var(--gutter)));
  margin: 16px auto 32px;
  background: var(--paper);
  border: var(--frame-w) solid var(--frame);
}
.site-nav {
  display: flex;
  align-items: stretch;
  gap: 0;
  min-height: calc(var(--cell) * 1.25);
  padding: 0 calc(var(--cell) * 0.5);
  border-bottom: var(--frame-w) solid var(--frame);
  font-size: 0.8125rem;
  letter-spacing: 0.04em;
  overflow-x: auto;
  scrollbar-width: none;
}
.site-nav::-webkit-scrollbar { display: none; }
.site-nav > a {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 calc(var(--cell) * 0.5);
  color: var(--ink-2);
  white-space: nowrap;
}
.site-nav > a[aria-current='page'] { color: var(--ink); font-weight: 700; }
.site-nav > a[aria-current='page']::after {
  content: '';
  position: absolute;
  left: calc(var(--cell) * 0.5);
  right: calc(var(--cell) * 0.5);
  bottom: -1.5px;
  height: 3px;
  background: var(--ink);
}
.site-nav > .edition-link { color: var(--rule-strong); }
.site-nav > .download-nav { margin-left: auto; font-weight: 700; color: var(--ink); }
@media (hover: hover) { .site-nav > a:hover { color: var(--ink); background: var(--paper-deep); } }

/* ── Buttons (detents) ────────────────────────────────────── */
.primary {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 44px;
  padding: 0 18px;
  background: var(--vermilion-solid);
  color: var(--on-vermilion);
  border: var(--frame-w) solid var(--vermilion-solid);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  transition: background 140ms var(--ease-out), transform 140ms var(--ease-out);
}
.primary:active { transform: translateY(1px); }
@media (hover: hover) { .primary:hover { background: var(--vermilion-hover); border-color: var(--vermilion-hover); } }
.text-link { display: inline-block; font-size: 0.8125rem; color: var(--ink); text-decoration: underline; text-decoration-color: var(--rule-strong); text-decoration-thickness: 1px; text-underline-offset: 4px; margin: 16px 0; }
@media (hover: hover) { .text-link:hover { text-decoration-color: var(--ink); } }

/* ── Library (home) ───────────────────────────────────────── */
.library { padding-top: calc(var(--cell) * 1.5); padding-bottom: calc(var(--cell) * 2); scroll-margin-top: calc(var(--header-h) + 8px); }
.section-heading { padding-bottom: 20px; }
.section-heading h1 { font-size: clamp(2rem, 4.2vw, 3.25rem); line-height: 1.15; letter-spacing: -0.01em; margin: 10px 0 10px; }
.section-heading h1 em, .hero h2 em, .download h2 em, .sources-page > h1 em { color: var(--vermilion); }
.section-heading p { font-size: 0.9375rem; color: var(--ink-2); margin-bottom: 0; }

.search-form {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 0 16px;
  background: var(--paper);
  border: var(--frame-w) solid var(--ink);
}
.search-form:focus-within { box-shadow: var(--focus); }
.search-icon { font-size: 1.75rem; line-height: 1; color: var(--rule-strong); transform: rotate(-15deg); }
.search-form input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 1rem; padding: 10px 0; color: var(--ink); }
.search-form input:focus-visible { box-shadow: none; }
.search-form input::placeholder { color: var(--ink-3); }

.filters { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 16px 0 24px; flex-wrap: wrap; }
.level-filters { display: flex; flex-wrap: wrap; border: var(--frame-w) solid var(--ink); }
.level-filters button {
  min-height: var(--ctl);
  padding: 0 14px;
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  background: var(--paper);
  transition: background 140ms var(--ease-out), color 140ms var(--ease-out);
}
.level-filters button + button { border-left: var(--hair) solid var(--ink); }
.level-filters button.active { background: var(--fill); color: var(--on-fill); }
@media (hover: hover) { .level-filters button:hover:not(.active) { background: var(--paper-deep); } }
.source-filter { display: flex; align-items: center; gap: 10px; font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--rule-strong); }
.source-filter select {
  max-width: 260px;
  min-height: var(--ctl);
  padding: 0 28px 0 12px;
  border: var(--hair) solid var(--rule-strong);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  font-size: 0.8125rem;
  letter-spacing: 0;
  text-transform: none;
}

.results-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  min-height: var(--cell);
  border-top: var(--frame-w) solid var(--frame);
  border-bottom: var(--hair) solid var(--rule);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--rule-strong);
}
.results-heading p { margin: 0; }
.results-heading > span { color: var(--ink-3); text-transform: none; letter-spacing: 0.02em; }

/* the grammar grid: squares ruled on the sheet, sharing their hairlines */
.grammar-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-left: var(--hair) solid var(--rule);
}
.grammar-card {
  display: flex;
  flex-direction: column;
  min-height: 13.5rem;
  padding: 18px 20px 14px;
  border-right: var(--hair) solid var(--rule);
  border-bottom: var(--hair) solid var(--rule);
  background: var(--paper);
  overflow-wrap: anywhere;
  transition: background 140ms var(--ease-out);
}
.grammar-card:focus-visible { box-shadow: inset 0 0 0 2px var(--rule-strong); border-radius: 0; }
@media (hover: hover) {
  .grammar-card:hover { background: var(--paper-deep); }
  .grammar-card:hover h3 { color: var(--vermilion); }
}
.card-top { display: flex; align-items: center; gap: 4px; min-height: 22px; }
.card-arrow { margin-left: auto; color: var(--rule-strong); font-size: 1rem; }
.grammar-card h3 { font-family: var(--font-hand); font-weight: 600; font-size: 1.75rem; line-height: 1.35; margin: 12px 0 2px; color: var(--ink); transition: color 140ms var(--ease-out); }
.card-reading { font-family: var(--font-hand); font-size: 0.875rem; color: var(--ink-2); margin: 0 0 8px; letter-spacing: 0.06em; }
.card-reading:empty { display: none; }
.card-meaning { font-size: 0.875rem; line-height: 1.65; color: var(--ink-2); margin-bottom: 16px; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.card-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: auto;
  padding-top: 10px;
  border-top: var(--hair) solid var(--rule);
  font-size: 0.75rem;
  color: var(--ink-3);
}
.card-footer > span:last-child { color: var(--rule-strong); }

/* JLPT levels: square pips, a green ramp from N5 (open) to N1 (solid) */
.level {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.04em;
  padding: 4px 6px;
  border: var(--hair) solid var(--rule-mid);
  color: var(--rule-strong);
  background: transparent;
}
.level.n4 { background: var(--green-wash); }
.level.n3 { background: var(--rule); color: var(--ink); border-color: var(--rule); }
.level.n2 { background: var(--rule-mid); color: var(--paper); border-color: var(--rule-mid); }
.level.n1 { background: var(--rule-strong); color: var(--paper); border-color: var(--rule-strong); }
:root[data-theme='dark'] .level.n2 { color: var(--ink); }

.load-more {
  display: block;
  margin: 28px auto 0;
  min-height: 44px;
  padding: 0 22px;
  border: var(--frame-w) solid var(--ink);
  background: var(--paper);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}
@media (hover: hover) { .load-more:hover { background: var(--fill); color: var(--on-fill); } }
.empty-state { text-align: center; padding: 48px 24px; border: var(--hair) dashed var(--rule-mid); }
.empty-state > span { font-size: 2rem; color: var(--vermilion); }
.empty-state h3 { font-family: var(--font-ui); font-size: 1.5rem; margin: 8px 0; }
.empty-state p { font-size: 0.875rem; color: var(--ink-2); }
.empty-state button, .search-error button { min-height: 36px; padding: 0 4px; border-bottom: var(--hair) solid var(--rule-strong); font-size: 0.8125rem; }
.search-error { border: var(--hair) solid var(--vermilion); background: var(--vermilion-wash); color: var(--vermilion-ink); padding: 14px 16px; font-size: 0.875rem; }

.library-band {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 48px;
  min-height: calc(var(--cell) * 1.5);
  padding: 0 var(--gutter);
  border-top: var(--frame-w) solid var(--frame);
  border-bottom: var(--hair) solid var(--rule);
  background-color: var(--paper);
  background-image: var(--grid);
  background-size: var(--cell) var(--cell);
}
.library-band > span { background: var(--paper); padding: 2px 8px; }
.library-band > span:first-child { font-size: 0.75rem; letter-spacing: 0.08em; color: var(--rule-strong); }
.library-band > [lang='ja'] { font-family: var(--font-hand); font-weight: 600; font-size: 1rem; letter-spacing: 0.08em; }
.band-flower { font-size: 1.5rem; color: var(--vermilion); }

/* hero: the field-guide spread, printed flat on the grid */
.hero { display: grid; grid-template-columns: 1.05fr 1fr; gap: 40px; padding-top: calc(var(--cell) * 2); padding-bottom: calc(var(--cell) * 2); align-items: center; }
.hero h2 { font-size: clamp(2.5rem, 5.2vw, 4.25rem); line-height: 1.08; letter-spacing: -0.015em; margin: 18px 0 20px; }
.hero-description { max-width: 30rem; font-size: 1rem; color: var(--ink-2); line-height: 1.8; margin-bottom: 24px; }
.translation-note { font-size: 0.8125rem; color: var(--rule-strong); max-width: 26rem; }
.hero-stats { display: flex; margin-top: 32px; border-top: var(--hair) solid var(--rule); border-bottom: var(--hair) solid var(--rule); }
.hero-stats > div { display: flex; flex-direction: column; padding: 12px 24px 12px 0; margin-right: 24px; border-right: var(--hair) solid var(--rule); }
.hero-stats > div:last-child { border-right: 0; margin-right: 0; }
.hero-stats strong { font-size: 1.75rem; line-height: 1.2; font-weight: 700; }
.hero-stats span { font-size: 0.6875rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); margin-top: 4px; }

.hero-art { position: relative; min-height: 420px; display: grid; place-items: center; }
.art-grid { position: absolute; inset: 0; background-image: var(--grid); background-size: var(--cell) var(--cell); border: var(--hair) solid var(--rule); }
.art-note { position: absolute; top: 12px; right: 16px; font-size: 0.75rem; letter-spacing: 0.04em; color: var(--ink-3); background: var(--paper); padding: 2px 6px; }
.paper-back {
  position: absolute;
  top: calc(var(--cell) * 2);
  left: calc(var(--cell) * 1);
  width: calc(var(--cell) * 4);
  height: calc(var(--cell) * 8);
  background: var(--paper);
  border: var(--frame-w) solid var(--rule-mid);
  padding: calc(var(--cell) * 0.5) 0;
  display: flex;
  justify-content: center;
}
.paper-back span { display: block; font-family: var(--font-hand); font-weight: 600; writing-mode: vertical-rl; text-orientation: upright; font-size: calc(var(--cell) * 0.7); line-height: 1.45; letter-spacing: 0.3em; color: var(--ink-2); }
.paper-front {
  position: relative;
  width: min(330px, 80%);
  margin: calc(var(--cell) * 1) 0 0 calc(var(--cell) * 3);
  padding: 22px 24px 16px;
  background: var(--paper);
  border: var(--frame-w) solid var(--frame);
}
.paper-meta { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-bottom: 8px; border-bottom: var(--hair) solid var(--rule); }
.paper-meta > span:first-child { font-size: 0.6875rem; letter-spacing: 0.08em; color: var(--rule-strong); }
.paper-word { font-family: var(--font-hand); font-weight: 600; font-size: 2.75rem; line-height: 1.2; margin: 18px 0 12px; }
.paper-word > span { display: block; font: 0.75rem var(--font-ui); letter-spacing: 0.08em; color: var(--ink-3); margin-top: 6px; }
.paper-line { width: var(--cell); height: 1.5px; background: var(--vermilion); margin-bottom: 12px; }
.paper-front > p { font-size: 0.875rem; margin-bottom: 0; }
.paper-example { padding: 14px 0 6px; font-family: var(--font-hand); font-weight: 600; font-size: 1.125rem; line-height: 2; }
.paper-example span { color: var(--vermilion); border-bottom: 1.5px solid var(--vermilion); }
.paper-front > p.paper-translation { font-size: 0.75rem; color: var(--ink-2); line-height: 1.6; margin-bottom: 18px; }
.paper-bottom { display: flex; align-items: center; justify-content: space-between; padding-top: 10px; border-top: var(--hair) solid var(--rule); font-size: 0.6875rem; color: var(--ink-3); }
.paper-bottom > span:last-child { color: var(--rule-strong); font-size: 1rem; }
.art-star { position: absolute; bottom: 10px; left: 18px; color: var(--vermilion); font-size: 3.5rem; line-height: 1; }

.download {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 40px;
  align-items: center;
  padding: calc(var(--cell) * 1.25);
  margin-bottom: calc(var(--cell) * 2);
  border: var(--frame-w) solid var(--frame);
}
.download h2 { font-size: clamp(1.875rem, 3.4vw, 2.75rem); line-height: 1.12; margin: 12px 0 16px; }
.download p { font-size: 0.875rem; color: var(--ink-2); max-width: 30rem; }
.download-options { justify-self: end; }
.download-options .primary { min-width: 270px; }
.download-options p { font-size: 0.75rem; color: var(--ink-3); margin: 0; }

/* ── Footer ───────────────────────────────────────────────── */
.site-footer { border-top: var(--frame-w) solid var(--frame); padding: 24px 0 18px; }
.footer-inner { width: calc(100% - var(--gutter) * 2); margin: auto; display: flex; align-items: center; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
.site-footer .brand-sub { color: var(--ink-3); }
.footer-inner > p { font-size: 0.875rem; color: var(--ink-2); margin: 0; }
.footer-inner > a:last-child { font-size: 0.8125rem; color: var(--rule-strong); }
.footer-credit { text-align: center; color: var(--ink-3); font-size: 0.75rem; margin: 20px var(--gutter) 0; padding-top: 14px; border-top: var(--hair) solid var(--rule); }

/* ── Entry pages ──────────────────────────────────────────── */
.entry-wrap { padding-top: 20px; padding-bottom: calc(var(--cell) * 2); }
.back-link { display: inline-flex; align-items: center; min-height: 36px; font-size: 0.8125rem; color: var(--ink-2); letter-spacing: 0.02em; margin-bottom: 12px; }
@media (hover: hover) { .back-link:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 4px; text-decoration-color: var(--rule-strong); } }

/* the headword is written onto the grid of the sheet */
.entry-intro {
  position: relative;
  padding: calc(var(--cell) * 0.75) calc(var(--cell) * 0.75) calc(var(--cell) * 0.75);
  margin-bottom: calc(var(--cell) * 1.25);
  border: var(--hair) solid var(--rule);
  border-top: var(--frame-w) solid var(--frame);
  background-image: var(--grid);
  background-size: var(--cell) var(--cell);
  background-position: -1px -1px;
  overflow-wrap: anywhere;
}
.entry-intro > * { position: relative; }
.entry-intro h1 { font-family: var(--font-hand); font-weight: 600; font-size: clamp(2.5rem, 6vw, 4.5rem); line-height: 1.3; letter-spacing: 0.02em; margin: 14px 0 4px; }
.entry-reading { font-family: var(--font-hand); font-size: 1rem; letter-spacing: 0.08em; color: var(--ink); margin-bottom: 14px; }
.entry-meaning { font-size: clamp(1.125rem, 2vw, 1.375rem); line-height: 1.55; max-width: 46rem; margin-bottom: 18px; }
.entry-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 0.8125rem; color: var(--ink-3); }
.entry-meta > span:not(.level):not(.translation-badge) { margin: 0 6px; }
.variants { font-size: 0.8125rem; color: var(--ink-3); margin: 14px 0 0; max-width: 52rem; }
.variants > span { color: var(--ink); margin-left: 4px; font-family: var(--font-hand); font-weight: 600; }
.translation-badge { display: inline-block; font-size: 0.6875rem; letter-spacing: 0.04em; color: var(--rule-strong); border: var(--hair) solid var(--rule-strong); padding: 3px 7px; line-height: 1.2; }

.entry-layout { display: grid; grid-template-columns: minmax(0, 1fr) 272px; gap: calc(var(--cell) * 1.25); }
.entry-content { min-width: 0; }

.source-section { border: var(--frame-w) solid var(--frame); background: var(--paper); margin-bottom: calc(var(--cell) * 1); overflow-wrap: anywhere; }
.source-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: calc(var(--cell) * 1.25);
  padding-right: 18px;
  border-bottom: var(--frame-w) solid var(--frame);
  background: var(--paper);
  position: sticky;
  top: var(--header-h);
  z-index: 5;
}
.source-heading > div { display: flex; align-items: stretch; gap: 14px; min-width: 0; align-self: stretch; }
.source-number {
  display: grid;
  place-items: center;
  width: calc(var(--cell) * 1.25);
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--vermilion-ink);
  font-weight: 700;
  border-right: var(--hair) solid var(--rule);
}
.source-heading h2 { align-self: center; font-size: 1rem; font-weight: 700; margin: 0; line-height: 1.4; padding: 8px 0; }
.upstream-link { font-size: 0.75rem; flex-shrink: 0; color: var(--rule-strong); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
@media (hover: hover) { .upstream-link:hover { color: var(--ink); } }

.sense { padding: 26px 28px 28px; border-bottom: var(--hair) solid var(--rule); scroll-margin-top: calc(var(--header-h) + var(--cell) * 1.25 + 12px); }
.sense:last-child { border-bottom: 0; }
.sense > .upstream-link { display: inline-block; margin: -10px 0 14px; }
.sense-heading { font-size: 1.1875rem; line-height: 1.4; margin: 0 0 14px; padding-left: 12px; border-left: 3px solid var(--ink); }
.sense-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.sense-meta:empty { display: none; }

.definition-field { margin-bottom: 22px; }
.definition-field:last-child { margin-bottom: 0; }
.definition-field h4, .examples h4 {
  display: flex;
  align-items: baseline;
  gap: 12px;
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--rule-strong);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: var(--hair) solid var(--rule);
}
.source-prose { font-size: 1.0625rem; line-height: 1.85; max-width: 44rem; }
.source-prose p { margin-bottom: 14px; }
.source-prose > div { margin-bottom: 12px; }
.source-prose p:last-child, .source-prose > div:last-child { margin-bottom: 0; }
.source-prose[lang='ja'] { font-size: 1.0625rem; line-height: 2; }
.source-prose table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; font-size: 0.875rem; margin: 8px 0; }
.source-prose td, .source-prose th { border: var(--hair) solid var(--rule-mid); padding: 6px 10px; vertical-align: top; }
.source-prose th { background: var(--paper-deep); font-weight: 700; }
.source-prose ul, .source-prose ol { padding-left: 1.4em; }
ruby rt { font-family: var(--font-hand); font-weight: 400; font-size: 0.55em; color: var(--ink-2); letter-spacing: 0.04em; }
.emphasis { font-weight: 700; color: var(--vermilion-ink); }
.italic { font-style: italic; }
.omitted { text-decoration: line-through; text-decoration-color: var(--vermilion); }

.examples { margin-top: 28px; }
.examples h4 > span { margin-left: auto; font-size: 0.75rem; letter-spacing: 0; text-transform: none; color: var(--ink-3); }
.examples ol { margin: -10px 0 0; padding: 0; list-style: none; counter-reset: examples; }
.examples li {
  counter-increment: examples;
  position: relative;
  display: grid;
  grid-template-columns: calc(var(--cell) * 1) minmax(0, 1fr);
  padding: 12px 0;
  border-bottom: var(--hair) solid var(--rule);
}
.examples li > * { grid-column: 2; }
.examples li::before {
  content: counter(examples, decimal-leading-zero);
  grid-column: 1;
  grid-row: 1 / span 2;
  padding-top: 0.6em;
  font-size: 0.6875rem;
  color: var(--ink-3);
}
.example-japanese { font-family: var(--font-hand); font-weight: 600; font-size: 1.1875rem; line-height: 2; }
.example-japanese p { margin: 0; }
.example-english { font-size: 0.9375rem; color: var(--ink-2); line-height: 1.7; margin: 2px 0 0; }

.original { border-top: var(--hair) dashed var(--rule-mid); margin-top: 24px; padding-top: 8px; }
.original summary { display: flex; align-items: center; gap: 8px; min-height: 40px; font-size: 0.8125rem; color: var(--rule-strong); cursor: pointer; list-style: none; }
.original summary::-webkit-details-marker { display: none; }
.original summary::before { content: '▸'; display: inline-block; transition: transform 140ms var(--ease-out); }
.original[open] summary::before { transform: rotate(90deg); }
.original[open] summary { margin-bottom: 12px; }
@media (hover: hover) { .original summary:hover { color: var(--ink); } }

.illustration { margin: 0 0 24px; }
.illustration img { display: block; width: 100%; max-width: 480px; height: auto; border: var(--hair) solid var(--rule-mid); background: #fff; filter: var(--image-dim); }
.illustration figcaption { font-family: var(--font-hand); font-size: 0.875rem; color: var(--ink-2); margin-top: 8px; }

/* ── Contents: sticky sidebar on wide sheets, a drawer on narrow ones ── */
.entry-sidebar { align-self: start; position: sticky; top: calc(var(--header-h) + 16px); }
.toc {
  border: var(--frame-w) solid var(--frame);
  background: var(--paper);
  max-height: calc(100dvh - var(--header-h) - 32px);
  display: flex;
  flex-direction: column;
}
.toc-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--cell);
  padding: 0 12px 0 14px;
  border-bottom: var(--hair) solid var(--rule);
  flex-shrink: 0;
}
.toc-head .eyebrow { margin: 0; }
.toc-count { margin-left: auto; font-size: 0.75rem; color: var(--ink-3); }
.toc-close { display: none; width: 44px; height: 44px; margin-right: -12px; font-size: 1.5rem; line-height: 1; color: var(--ink-2); }
.toc-list { list-style: none; margin: 0; padding: 4px 0; overflow-y: auto; overscroll-behavior: contain; flex: 1 1 auto; }
.toc-list > li > a {
  position: relative;
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  align-items: baseline;
  gap: 6px;
  padding: 7px 14px 7px 14px;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--ink-2);
}
.toc-number { font-size: 0.6875rem; color: var(--ink-3); }
.toc-list a[aria-current='true'] { background: var(--green-wash); color: var(--ink); font-weight: 700; }
.toc-list > li > a[aria-current='true']::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--vermilion); }
.toc-list > li > a[aria-current='true'] .toc-number { color: var(--vermilion-ink); }
.toc-senses { list-style: none; margin: 0 0 4px; padding: 0 0 0 46px; }
.toc-senses a { display: block; padding: 3px 14px 3px 8px; font-size: 0.75rem; line-height: 1.45; color: var(--ink-3); border-left: var(--hair) solid var(--rule); }
.toc-senses a[aria-current='true'] { border-left-color: var(--vermilion); font-weight: 400; background: none; color: var(--ink); }
@media (hover: hover) { .toc-list a:hover { background: var(--paper-deep); color: var(--ink); } }
.toc-note { font-size: 0.75rem; line-height: 1.6; color: var(--ink-3); padding: 10px 14px; border-top: var(--hair) solid var(--rule); flex-shrink: 0; }
.toc-actions { display: flex; flex-wrap: wrap; align-items: stretch; border-top: var(--hair) solid var(--rule); flex-shrink: 0; }
.toc-actions > * {
  flex: 1 1 auto;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--ctl);
  padding: 0 10px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink);
}
.toc-actions > * + * { border-left: var(--hair) solid var(--rule); }
.toc-actions button[aria-pressed='true'] { background: var(--green-wash); }
@media (hover: hover) { .toc-actions > *:hover { background: var(--paper-deep); } }
.hide-furigana rt, .hide-furigana rp { display: none; }

.toc-fab {
  display: none;
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 45;
  align-items: center;
  gap: 8px;
  height: 48px;
  padding: 0 16px;
  background: var(--paper);
  color: var(--ink);
  border: var(--frame-w) solid var(--ink);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  box-shadow: 0 0 0 3px var(--paper);
}
.fab-ja { font-family: var(--font-hand); font-weight: 600; font-size: 1rem; color: var(--vermilion); letter-spacing: 0; }
.fab-where { font-weight: 400; font-size: 0.75rem; color: var(--ink-3); padding-left: 8px; border-left: var(--hair) solid var(--rule); }
.fab-where:empty { display: none; }
.toc-fab:active { transform: translateY(1px); }
.toc-backdrop { position: fixed; inset: 0; z-index: 46; background: var(--backdrop); }

/* ── Sources & 404 ────────────────────────────────────────── */
.sources-page { padding: calc(var(--cell) * 1.5) 0 calc(var(--cell) * 2); }
.sources-page > h1 { font-size: clamp(2.25rem, 5vw, 3.75rem); line-height: 1.1; margin: 14px 0 22px; }
.sources-page > p { max-width: 40rem; color: var(--ink-2); font-size: 1rem; line-height: 1.85; }
.sources-list { padding: 0; list-style: none; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 32px 0; border-top: var(--frame-w) solid var(--frame); border-left: var(--hair) solid var(--rule); }
.sources-list li { padding: 18px 20px; border-right: var(--hair) solid var(--rule); border-bottom: var(--hair) solid var(--rule); }
.sources-list h2 { font-size: 1rem; margin-bottom: 6px; }
.sources-list p { color: var(--ink-3); font-size: 0.8125rem; margin: 0; }

/* ── Breakpoints (each narrows the rules above it) ────────── */
@media (max-width: 1100px) {
  .hero { gap: 16px; }
  .grammar-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1000px) {
  .entry-layout { display: flex; flex-direction: column; gap: 20px; }
  .entry-sidebar { position: static; order: -1; width: 100%; }
  .toc { max-height: none; }
  .toc-note { display: none; }

  /* with JS the contents leave the flow and become a drawer from below */
  .js .entry-sidebar {
    position: fixed;
    top: auto;
    order: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    width: auto;
    max-height: min(78dvh, 640px);
    transform: translateY(100%);
    visibility: hidden;
    transition: transform 220ms var(--ease-out), visibility 0s linear 220ms;
  }
  .js .toc { max-height: inherit; border-width: var(--frame-w) 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .js .toc-close { display: inline-grid; place-items: center; }
  .js .toc-head { min-height: 52px; }
  .js .toc-list > li > a { padding-top: 11px; padding-bottom: 11px; font-size: 0.9375rem; }
  .js .toc-senses a { padding-top: 7px; padding-bottom: 7px; font-size: 0.8125rem; }
  .js .toc-open .entry-sidebar { transform: none; visibility: visible; transition: transform 220ms var(--ease-out); }
  .js .toc-fab { display: inline-flex; }
  .js .toc-open .toc-fab { visibility: hidden; }
  .entry-wrap { padding-bottom: calc(var(--cell) * 2 + 64px); }
}
@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; gap: 24px; padding-top: calc(var(--cell) * 1.5); padding-bottom: calc(var(--cell) * 1.5); }
  .hero-art { min-height: 380px; }
  .download { grid-template-columns: 1fr; gap: 16px; }
  .download-options { justify-self: stretch; }
  .download-options .primary { width: 100%; min-width: 0; }
  .library-band { gap: 20px; justify-content: space-between; }
  .library-band > [lang='ja'] { display: none; }
  .brand-sub { display: none; }
}
@media (max-width: 760px) {
  .sheet { width: 100%; margin: 0; border-width: 0 0 var(--frame-w); }
  .header-inner { width: calc(100% - var(--gutter) * 2); }
  .site-nav { padding: 0 6px; }
  .site-nav > a { padding: 0 10px; }
  .site-nav > a[aria-current='page']::after { left: 10px; right: 10px; }
  .site-nav > .download-nav { margin-left: 0; }
  .grammar-grid { grid-template-columns: 1fr; }
  .grammar-card { min-height: 0; }
  .filters { flex-direction: column; align-items: stretch; gap: 12px; }
  .level-filters { display: grid; grid-template-columns: 1.7fr repeat(5, 1fr); }
  .level-filters button { padding: 0 8px; }
  .source-filter { justify-content: space-between; }
  .source-filter select { flex: 1; min-width: 0; width: 100%; max-width: none; }
  .sources-list { grid-template-columns: 1fr; }
  .results-heading > span { display: none; }
  .source-heading { position: static; padding-right: 12px; flex-wrap: wrap; row-gap: 0; }
  .source-heading > .upstream-link { padding: 0 0 10px calc(var(--cell) * 1.25 + 14px); }
  .source-heading { border-bottom-width: var(--hair); }
  .sense { padding: 20px 16px 22px; scroll-margin-top: calc(var(--header-h) + 12px); }
  .entry-intro { padding: 16px; }
  .examples li { grid-template-columns: 28px minmax(0, 1fr); }
  .example-japanese { line-height: 1.85; }
  .hero-stats > div { padding-right: 14px; margin-right: 14px; }
  .footer-inner { flex-direction: column; align-items: flex-start; gap: 12px; }
}
@media (max-width: 560px) {
  .prefs { gap: 8px; }
  .theme-switch { display: none; }
  .theme-cycle { display: inline-grid; }
  .size-value { display: none; }
  .size-switch button:last-child { border-left: var(--hair) solid var(--rule); }
  .search-form { min-height: 52px; }
  .hero-art { min-height: 340px; }
  .paper-back { left: 0; }
  .paper-front { margin-left: calc(var(--cell) * 2.5); width: calc(100% - var(--cell) * 3); padding: 18px; }
  .paper-word { font-size: 2.25rem; }
  .art-note, .art-star { display: none; }
  .hero-stats strong { font-size: 1.375rem; }
  .download { padding: 20px 16px; }
  .entry-meaning { font-size: 1.125rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
::view-transition-old(root), ::view-transition-new(root) { animation-duration: 280ms; }
@media (forced-colors: active) {
  .level, .primary, .level-filters button.active, .theme-switch button[aria-pressed='true'] { border: 1px solid ButtonText; }
}
@media print {
  .site-header, .site-nav, .site-footer, .entry-sidebar, .toc-fab, .back-link { display: none !important; }
  .sheet { border: 0; width: 100%; margin: 0; }
  .entry-layout { display: block; }
  .source-heading { position: static; }
  .source-section { break-inside: avoid; }
}
