/* Styles specific to /writing's ja study board (kana-board + the Yōon/
   Sokuon/Dakuon extras) + character dialog (docs/DESIGN_SYSTEM.md's
   planned static/css/pages/*.css split — first real page to use it).
   Reuses home.css's existing :root tokens (already linked before this
   file in writing.html's <head>) rather than introducing a second
   palette: --gold-soft/--text-brown/--muted-brown/--panel-white/
   --panel-cream match .interface-lang__link/.learn-card/.content-sections.
   --kana-ink/--kana-card-border are new, page-local tokens for the glyph
   and card-border colors the reference spec calls for that don't already
   exist in home.css's palette (that one has no plain near-black or
   blue-gray). */

/* Wraps kana-board + kana-extra together so the chart and the lower
   learning blocks read as one continuous panel instead of a plain area
   sitting above a separately-boxed cream area. Kana cells and the
   example/mark cards inside stay white, same "cards on a cream panel"
   language the rest of the site already uses. */
.kana-panel {
  background: var(--panel-cream);
  border-radius: 16px;
  padding: 16px;
}

.kana-board {
  --kana-ink: #262626;
  --kana-card-border: #d3dbe4;
}

/* One flex child of .content-sections (which has its own 28px gap between
   top-level children) instead of three separate ones — title and both
   description paragraphs used to each eat that 28px individually, which
   read as far too much space between lines that belong together. Internal
   gap here is what actually controls their spacing now. */
.kana-board__intro {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc(100% + 3px);
  margin-bottom: -6px;
}

/* Sits directly on .content-sections's own (lighter) background, above
   .kana-panel's cream area — not inside it. */
.kana-board__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.kana-board__title {
  margin: 0;
}

/* Small diamond bullet in front of a heading's text — shared by
   .kana-board__title (h2) and the Yōon block's .kana-extra__title (h3), a
   rotated square sized off the heading's own font-size so it scales with
   whichever level uses it, rather than a fixed px size for both. */
.kana-marker {
  display: flex;
  align-items: center;
  gap: 0.5em;
}

.kana-marker::before {
  content: "";
  flex-shrink: 0;
  width: 0.4em;
  height: 0.4em;
  background: var(--blue-strong);
  transform: rotate(45deg);
}

.kana-board__description {
  margin: 0;
}

/* Highlighter-chip treatment for key terms (Kana/Hiragana/Katakana,
   Dakuon/Handakuten below) — a pale pink background with the page's
   normal --text-brown on top, rather than colored text: at this pale a
   tint, colored text itself can't carry 4.5:1 contrast, but as a
   background under --text-brown it's a non-issue (11.7:1) while still
   reading as "this word matters". box-decoration-break keeps the chip
   background/radius applied per-line if a term ever wraps, instead of
   one box spanning both lines. */
.kana-note__term {
  padding: 1px 5px;
  background: var(--pink-chip);
  border-radius: 5px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

/* Compact segmented control, not a rebuild trigger: clicking a button
   only flips .kana-board__table's data-mode attribute (static/js/
   writing.js) — the hiragana/katakana spans below are just hidden via
   CSS, same DOM/grid positions stay put in every mode. flex-wrap so the
   now-5-button row (All/Hiragana/Katakana/Dakuon/Handakuten) doesn't
   overflow narrow viewports. */
.kana-filter {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 2px;
  background: var(--panel-cream);
  border: 1px solid var(--gold-soft);
  border-radius: 999px;
}

.kana-filter__btn {
  appearance: none;
  cursor: pointer;
  border: 1.5px solid transparent;
  padding: 4px 12px;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted-brown);
  background: transparent;
  border-radius: 999px;
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    color 140ms ease;
}

.kana-filter__btn:hover {
  color: var(--text-brown);
}

/* Same active-state recipe as .interface-lang__link--active (home.css):
   --tab-blue fill + --blue-heart border, not the flat --blue-strong fill
   this used before. */
.kana-filter__btn[aria-pressed="true"] {
  background: var(--tab-blue);
  border-color: var(--blue-heart);
  color: var(--text-brown);
}

.kana-board__table {
  display: grid;
  gap: clamp(2px, 0.5vw, 5px);
  margin-top: 8px;
  width: 100%;
}

.kana-board__row {
  display: grid;
  grid-template-columns: minmax(14px, 30px) repeat(11, minmax(0, 1fr));
  align-items: stretch;
  gap: clamp(2px, 0.5vw, 5px);
  border-radius: 6px;
}

.kana-board__row--head {
  margin-bottom: 2px;
}

.kana-board__corner {
  display: block;
}

.kana-board__colhead,
.kana-board__rowhead {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.55rem, 1.2vw, 0.7rem);
  font-weight: 700;
  color: var(--text-brown);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  border-radius: 4px;
  transition:
    background-color 120ms ease,
    color 120ms ease;
}

/* Column (consonant-group) highlight only — no row/horizontal strip by
   design. JS-driven (writing.js toggles this on every element sharing
   the hovered cell's data-col), since each vowel-row is its own grid
   container and a column's cells live in five separate containers pure
   CSS :hover can't reach across. Same active-state recipe as
   .interface-lang__link--active (home.css) / .kana-filter__btn[aria-pressed]
   above — --tab-blue fill + --blue-heart border — not the old translucent
   rgba(95, 153, 198, 0.28), which read as too faint. */
.kana-board__cell.kana-col-hover:not(.kana-board__cell--empty) {
  background: var(--tab-blue);
  border-color: var(--blue-heart);
}

/* No color override here (stays the inherited --text-brown): --blue-strong
   and even --blue-strong-text read under 4.5:1 against --tab-blue's fill,
   so font-weight alone (700 -> 800) carries the hover emphasis. */
.kana-board__colhead.kana-col-hover {
  background: var(--tab-blue);
  font-weight: 800;
}

.kana-board__cell {
  appearance: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: clamp(46px, 8vw, 67px);
  padding: 3px 1px;
  font-family: inherit;
  background: var(--panel-white);
  border: 1px solid var(--kana-card-border);
  border-radius: 6px;
  overflow: hidden;
}

.kana-board__cell--empty {
  background: transparent;
  border-color: transparent;
  cursor: default;
}

/* Individual hover/focus touches only the glyph text — the card itself
   (background, border, shadow) stays put. Applies to every cell
   regardless of which script(s) it currently shows — one shared class,
   not split per-script — so this reads the same whether the filter is
   All, Hiragana, or Katakana. */
.kana-board__cell:not(.kana-board__cell--empty):hover .kana-board__hira,
.kana-board__cell:not(.kana-board__cell--empty):hover .kana-board__kata,
.kana-board__cell:not(.kana-board__cell--empty):focus-visible .kana-board__hira,
.kana-board__cell:not(.kana-board__cell--empty):focus-visible .kana-board__kata {
  color: var(--blue-strong-text);
}

.kana-board__cell:focus-visible {
  outline: 2px solid rgba(95, 153, 198, 0.55);
  outline-offset: 1px;
}

.kana-board__glyphs {
  display: flex;
  align-items: baseline;
  gap: clamp(1px, 0.4vw, 4px);
  line-height: 1.2;
}

.kana-board__hira {
  font-size: clamp(0.92rem, 2.4vw, 1.2rem);
  color: var(--kana-ink);
  transition: color 140ms ease;
}

.kana-board__kata {
  font-size: clamp(0.75rem, 1.95vw, 0.98rem);
  color: var(--muted-brown);
  transition: color 140ms ease;
}

.kana-board__romaji {
  margin-top: 1px;
  font-size: clamp(0.58rem, 1.25vw, 0.75rem);
  line-height: 1.3;
  color: var(--blue-strong-text);
}

/* Narrow viewports: stack hiragana over katakana instead of squeezing
   both onto one line, so 11 columns still never force a horizontal
   scrollbar — width never changes, only how the glyph pair wraps. */
@media (max-width: 520px) {
  .kana-board__glyphs {
    flex-direction: column;
    align-items: center;
    gap: 0;
  }
}

/* data-mode toggled by static/js/writing.js's filter buttons; "all" (the
   default) shows both spans, so no rule is needed for it. */
.kana-board__table[data-mode="hiragana"] .kana-board__kata {
  display: none;
}

.kana-board__table[data-mode="katakana"] .kana-board__hira {
  display: none;
}

/* Each cell holds up to three .kana-board__variant wrappers (base/dakuon/
   handakuten, kana_data.go's mainKanaCell) sharing the same inner
   .kana-board__glyphs/__hira/__kata/__romaji markup and styling — only
   the variant matching the table's current data-mode is shown, so
   switching modes swaps content in place rather than rebuilding cells. */
.kana-board__variant {
  display: none;
  flex-direction: column;
  align-items: center;
}

.kana-board__table[data-mode="all"] .kana-board__variant--base,
.kana-board__table[data-mode="hiragana"] .kana-board__variant--base,
.kana-board__table[data-mode="katakana"] .kana-board__variant--base {
  display: flex;
}

.kana-board__table[data-mode="dakuon"] .kana-board__variant--dakuon {
  display: flex;
}

.kana-board__table[data-mode="handakuten"] .kana-board__variant--handakuten {
  display: flex;
}

/* Dakuon/handakuten only apply to the k/s/t/h columns (kana_data.go's
   dakuonHiragana/handakutenHiragana maps) — cells outside those columns
   have no matching .kana-board__variant to show in that mode, so they'd
   otherwise render as an empty box with a border. These two modifier
   classes (set server-side per cell) give them the same "nothing here"
   look as the grid's genuinely nonexistent combinations
   (.kana-board__cell--empty, e.g. yi/ye/wu/wi/we). */
.kana-board__table[data-mode="dakuon"] .kana-board__cell--no-dakuon,
.kana-board__table[data-mode="handakuten"] .kana-board__cell--no-handakuten {
  background: transparent;
  border-color: transparent;
  cursor: default;
  pointer-events: none;
}

/* Every card in both lower sections is white on top of .kana-panel-style
   cream backgrounds — no color swap for hierarchy — and (per feedback on
   the first pass) normal text weight everywhere except the one prominent
   "answer" per block, which gets a moderate weight bump plus a size bump,
   not heavy 700/800. */
.kana-extra__block {
  display: flex;
  flex-direction: column;
  padding: 12px;
  background: var(--panel-white);
  border: 1px solid var(--gold-soft);
  border-radius: 12px;
  min-width: 0;
}

/* Left-aligned explicitly, not just by default block-level behavior: every
   heading/caption at this level (block titles, row labels below) anchors
   left consistently, so alignment doesn't jump between left and center as
   you read down the section — only self-contained tiles (.combo-card)
   center their own content internally. */
.kana-extra__title {
  margin: 0 0 6px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-brown);
  text-align: left;
}

/* Zeroes .content-section__title's base 8px margin-bottom for this one
   heading — .kana-dakuon__grid below supplies the actual gap (8px), same
   split .kana-board__title uses (margin: 0, gap lives on the flex
   container). Scoped to this section only; the base 8px still applies to
   every other .content-section__title on the page (Special Kana Forms,
   Kanji, Vocabulary) where nothing overrides it. */
.kana-dakuon-section > .content-section__title {
  margin-bottom: 0;
}

/* Dakuon and Handakuten: a plain content-section (docs/PAGES.md
   convention, same as Kanji/Vocabulary) with its own two-column layout —
   the explanation replaces the removed "Voiced Mark"/"Handakuten" mark
   showcase, so the table on the right needs no separate legend anymore.
   margin-top matches .kana-board__intro's heading-to-body gap (8px) —
   .kana-dakuon__desc's paragraph sits right under this section's heading
   the same way .kana-board__description's paragraphs sit under that
   section's, so the two should read as the same gap, not two different
   ones (was 10px, collapsing with .content-section__title's 8px below).
   align-items: start, not center: the table (.kana-dakuon__table-wrap) is
   taller than the description text (.kana-dakuon__desc) at most viewport
   widths, and center vertically centers the shorter column against the
   taller one — pushing the paragraph's actual top edge down below the 8px
   margin by however much shorter it is, growing wider as the description
   column gets more horizontal room to wrap onto fewer lines. start keeps
   its top flush with the grid's top edge regardless of the height
   mismatch, so the heading-to-paragraph gap stays a constant 8px. */
.kana-dakuon__grid {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: 16px;
  align-items: start;
  margin-top: 8px;
}

@media (max-width: 640px) {
  .kana-dakuon__grid {
    grid-template-columns: 1fr;
  }
}

.kana-dakuon__desc {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.kana-dakuon__table-wrap {
  padding: 12px;
  background: var(--panel-white);
  border: 1px solid var(--gold-soft);
  border-radius: 12px;
  min-width: 0;
}

/* Strict 6-column table (row name | kana | + | mark | arrow | result) so
   all five rows line up exactly — a shared CSS grid does that for free,
   unlike five independent flex rows each sizing to their own content. */
.dakuon__rows-table {
  display: grid;
  grid-template-columns: repeat(6, auto);
  align-items: center;
  justify-items: center;
  row-gap: 4px;
  column-gap: 8px;
}

.dakuon__row-label {
  justify-self: start;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--muted-brown);
  white-space: nowrap;
}

.dakuon__kana-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
}

.dakuon__kana {
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-brown);
}

/* The result kana is the "answer" of the row: bigger, a touch heavier —
   same restrained treatment as the other two blocks' prominent element. */
.dakuon__kana--result {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text-brown);
}

.dakuon__romaji {
  margin-top: 1px;
  font-size: 0.62rem;
  font-weight: 500;
  color: var(--blue-strong-text);
}

.dakuon__op,
.dakuon__arrow {
  color: var(--muted-brown);
  font-size: 0.8rem;
  font-weight: 600;
}

/* The small ゛/゜ mark inside each transformation row — sized up from the
   first pass's 0.85rem so it actually registers at a glance, while the
   box itself stays a small, centered "mark cell". */
.dakuon__chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.6em;
  min-height: 1.6em;
  padding: 2px 5px;
  border: 1px solid var(--gold-soft);
  border-radius: 6px;
  font-weight: 500;
  color: var(--text-brown);
  font-size: 1.35rem;
  line-height: 1;
}

/* Special Kana Forms and Combinations: a 2x2 grid of self-contained
   panels — Yōon / Small Vowels on top (both the combo-card "kana + small
   kana = combination" pattern), ヴ / Sokuon below (both compact
   comparisons) — reading order matches source order (grid
   auto-placement fills left-to-right, top-to-bottom). Each panel now
   carries its own explanation paragraph (.kana-extra__body) directly
   below its cards, replacing the old separate .kana-special__explanations
   row that matched tables to explanations by position alone.
   Grid's default align-items: stretch is left in place here (not
   overridden at the grid level) so Yōon and Small Vowels — the matched
   combo-card pair sharing the top row — stretch to the same height as
   each other. ヴ and Sokuon opt out individually below instead, since
   only that pair (both naturally shorter) needs to avoid stretching. */
.kana-special__tables {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

/* ヴ and Sokuon are naturally shorter than their combo-card counterparts
   above — align-self: start keeps each sized to its own content instead
   of stretching to match whichever panel it happens to share a grid row
   with (a previous grid-wide align-items: start fixed this pair's height
   but also broke Yōon/Small Vowels' matching height above, since a grid
   property applies to every row, not just this one). */
.kana-extra__block--vu,
.kana-extra__block--sokuon {
  align-self: start;
}

@media (max-width: 720px) {
  .kana-special__tables {
    grid-template-columns: 1fr;
  }
}

.kana-extra__body {
  margin-top: 10px;
}

/* Combo cards: the "kana + small kana = combination" equation pattern
   shared by Yōon (き + ゃ = きゃ) and Small Vowels (フ + ァ = ファ) — the
   same visual component with different glyphs, so it isn't duplicated
   under two class trees. Fixed (not 1fr) column tracks + justify-content:
   center means the grid sizes to its own content and centers as a block
   inside its panel, instead of stretching edge-to-edge. Each row type
   across every card shares a
   min-height utility class (.combo-h-cell/.combo-h-op/.combo-h-result) so
   every card's rows line up with each other even though each card is its
   own self-contained flex column rather than a shared grid track. */
.combo-cards {
  display: grid;
  grid-template-columns: repeat(3, 74px);
  justify-content: center;
  gap: 6px;
  min-width: 0;
}

.combo-card {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 3px;
  background: var(--panel-white);
  border: 1px solid var(--gold-soft);
  border-radius: 8px;
  overflow: hidden;
}

.combo-row {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-width: 0;
}

.combo-h-cell {
  min-height: 20px;
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-brown);
}

.combo-h-op {
  min-height: 16px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted-brown);
}

.combo-h-result {
  min-height: 32px;
  flex-direction: column;
  padding-top: 2px;
}

.combo-row--small {
  font-size: 0.8rem;
}

/* The one deliberately prominent element in each card — bigger and a
   touch heavier than the supporting き/+/ゃ/= above it, not bold. */
.combo-card__kana {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.1;
  color: var(--text-brown);
}

.combo-card__romaji {
  margin-top: 1px;
  font-size: 0.6rem;
  font-weight: 500;
  color: var(--blue-strong-text);
}

/* Sokuon: two comparisons stacked in one panel. First, a compact
   size/identity check — つ (full size) ≠ っ (small), .sokuon-row__char--small
   backing up the glyphs' own size difference with an explicit font-size
   drop. Second, .sokuon-compare shows what that size difference actually
   does to a real word: きて (kite, "come") vs きって (kitte, "stamp"),
   with .sokuon-compare__mark underlining the doubled consonant it
   produces. */
.sokuon-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 4px 0;
}

.sokuon-row__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

.sokuon-row__char {
  font-size: 1.15rem;
  font-weight: 400;
  line-height: 1.1;
  color: var(--text-brown);
}

.sokuon-row__char--small {
  font-size: 0.9rem;
}

.sokuon-row__label {
  margin-top: 1px;
  font-size: 0.6rem;
  font-weight: 500;
  color: var(--blue-strong-text);
}

.sokuon-row__eq {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted-brown);
}

.sokuon-compare {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--gold-soft);
}

.sokuon-compare__word {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

.sokuon-compare__kana {
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.1;
  color: var(--text-brown);
}

.sokuon-compare__romaji {
  margin-top: 1px;
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--blue-strong-text);
}

.sokuon-compare__meaning {
  margin-top: 1px;
  font-size: 0.62rem;
  color: var(--muted-brown);
}

/* The doubled consonant itself — underlined rather than boxed so it
   reads as an annotation on the running kana/romaji, not a separate
   boxed mark cell. */
.sokuon-compare__mark {
  font-weight: 700;
  border-bottom: 2px solid var(--gold-border);
}

.sokuon-compare__vs {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted-brown);
}

/* ヴ (vu) row — katakana-only, formed from ウ + dakuten. 2-3-2 layout, not
   a straight row: va/vi on top, vu alone centered on its own full-width
   row (grid-column: 1 / -1 forces auto-placement to give it the whole
   next row; justify-self: center keeps its box the same size as the
   others instead of stretching it), ve/vo on the bottom — same boxed-tile
   language as .kana-board__cell/.combo-card elsewhere on this board, kana
   prominent on top of each box, romaji smaller and blue below. */
.vu-table {
  display: grid;
  grid-template-columns: 1fr 1fr;
  /* Matches .combo-cards' 6px in the panel beside it — same "grid of
     small kana tiles" language, so the tile spacing reads the same
     across both panels in this section. */
  gap: 6px;
}

.vu-table__cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 2px;
  background: var(--panel-white);
  border: 1px solid var(--gold-soft);
  border-radius: 6px;
  min-width: 0;
}

.vu-table__cell--center {
  grid-column: 1 / -1;
  justify-self: center;
  width: 50%;
}

.vu-table__kana {
  font-size: 1.05rem;
  font-weight: 400;
  line-height: 1.1;
  color: var(--text-brown);
}

.vu-table__romaji {
  margin-top: 1px;
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--blue-strong-text);
}

/* Dialog */

.kana-dialog {
  border: none;
  border-radius: 20px;
  padding: 0;
  width: min(560px, 92vw);
  background: var(--panel-white);
  box-shadow: 0 24px 64px rgba(28, 54, 92, 0.22);
}

.kana-dialog::backdrop {
  background: rgba(61, 40, 31, 0.35);
  backdrop-filter: blur(2px);
}

.kana-dialog__form {
  display: contents;
}

.kana-dialog__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 18px 22px 0;
}

.kana-dialog__tag {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--blue-strong-text);
}

.kana-dialog[data-script="katakana"] .kana-dialog__tag {
  color: var(--pink-strong-text);
}

.kana-dialog__close {
  appearance: none;
  cursor: pointer;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1.5px solid var(--gold-soft);
  background: var(--panel-white);
  color: var(--muted-brown);
  font-size: 1.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 160ms ease;
}

.kana-dialog__close:hover {
  border-color: var(--blue-heart);
}

.kana-dialog__close:focus-visible {
  outline: 3px solid rgba(95, 153, 198, 0.55);
  outline-offset: 2px;
}

.kana-dialog__body {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 20px;
  padding: 12px 22px 22px;
}

@media (max-width: 480px) {
  .kana-dialog__body {
    grid-template-columns: 1fr;
  }
}

.kana-dialog__stroke-pane {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.kana-dialog__stroke-box {
  width: 100%;
  max-width: 150px;
  aspect-ratio: 1 / 1;
  background: var(--panel-cream);
  border: 1.5px solid var(--gold-soft);
  border-radius: 14px;
  overflow: hidden;
}

/* The stroke-order animation itself is an existing CC0 GIF (Wikimedia
   Commons, static/images/kana-strokes/ATTRIBUTION.md) — this file only
   sizes/frames it, no drawing or timing logic of its own. */
.kana-dialog__stroke-gif {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.kana-dialog__detail {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.kana-dialog__glyph-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.kana-dialog__glyph {
  font-size: 2.75rem;
  line-height: 1;
  color: var(--text-brown);
}

.kana-dialog__romaji {
  font-size: 0.85rem;
  color: var(--muted-brown);
}

.kana-dialog__label {
  margin: 0 0 6px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted-brown);
}

.kana-dialog__mnemonic {
  margin: 0;
  padding: 10px 12px;
  background: var(--panel-cream);
  border-left: 3px solid var(--blue-heart);
  border-radius: 6px;
  font-size: 0.9rem;
  color: var(--text-brown);
}

.kana-dialog[data-script="katakana"] .kana-dialog__mnemonic {
  border-left-color: var(--pink-heart);
}

table.kana-dialog__words {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.kana-dialog__words th {
  text-align: left;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted-brown);
  padding: 0 8px 4px 0;
  border-bottom: 1.5px solid var(--gold-soft);
}

.kana-dialog__words td {
  padding: 6px 8px 6px 0;
  border-bottom: 1px dashed var(--gold-soft);
  vertical-align: baseline;
}

.kana-dialog__words tr:last-child td {
  border-bottom: none;
}

.kana-dialog__words .kana-word__jp {
  font-size: 1rem;
  color: var(--text-brown);
  white-space: nowrap;
}

.kana-dialog__words .kana-word__reading {
  color: var(--muted-brown);
  white-space: nowrap;
}

.kana-dialog__words .kana-word__meaning {
  color: var(--muted-brown);
}

/* Kana dialog's "Words by level" container: full dialog width under
   .kana-dialog__body (the widget itself is styled below). */
.kana-dialog__levels {
  padding: 0 22px 22px;
}

.kana-dialog__levels[hidden] {
  display: none;
}

/* "Words by level" widget (templates/pages/writing.html's "level-words"
   block, static/js/level-words.js), shared by the kana dialog and the
   kanji study card: N5..N1 tabs with each level's word count, a
   scrollable table (a character can have hundreds of N1 words) and a
   "Show more" button for the next page. */
.level-words__tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.level-words__tab {
  appearance: none;
  cursor: pointer;
  padding: 4px 12px;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted-brown);
  background: transparent;
  border: 1.5px solid var(--gold-soft);
  border-radius: 999px;
}

.level-words__tab:hover:not(:disabled) {
  background: var(--gold-soft);
}

.level-words__tab--selected,
.level-words__tab--selected:hover:not(:disabled) {
  color: #fff;
  background: var(--blue-strong, #3f7cc2);
  border-color: var(--blue-strong, #3f7cc2);
}

.level-words__tab:disabled {
  opacity: 0.4;
  cursor: default;
}

.level-words__count {
  font-weight: 400;
  opacity: 0.8;
}

.level-words__scroll {
  max-height: 260px;
  overflow-y: auto;
}

/* The rows flow into as many ~300px columns as fit — two on the wide
   kanji card, one in the narrow kana dialog — instead of one full-width
   table with big gaps between its word/reading/translation columns. Each
   row is its own fixed-track grid so the columns still line up; the
   header row can't span those columns, so it's hidden. */
.level-words .kana-dialog__words thead {
  display: none;
}

.level-words__rows {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  column-gap: 24px;
}

.level-words__rows tr {
  display: grid;
  grid-template-columns: 5.5em 8em minmax(0, 1fr);
  align-items: baseline;
  border-bottom: 1px dashed var(--gold-soft);
}

.level-words__row--example td:first-child::after {
  content: " ★";
  font-size: 0.7em;
  color: var(--gold-border);
}

.level-words .kana-dialog__words td,
.level-words .kana-dialog__words tr:last-child td {
  border-bottom: none;
}

.level-words__more {
  appearance: none;
  cursor: pointer;
  margin-top: 8px;
  border: 1.5px solid var(--blue-heart);
  padding: 4px 12px;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--blue-strong-text);
  background: var(--tab-blue);
  border-radius: 999px;
  transition: background-color 140ms ease;
}

.level-words__more:hover:not(:disabled) {
  background: var(--blue-heart);
  color: var(--panel-white);
}

.level-words__more:disabled {
  opacity: 0.5;
  cursor: default;
}

.level-words__more[hidden] {
  display: none;
}

/* Kanji mode ------------------------------------------------------------
   Everything below backs templates/pages/writing.html's Kana/Kanji
   writing-mode-tabs and the writing-mode-panel[data-mode-panel=kanji]
   block (static/js/writing.js for the tab toggle, static/js/
   kanji-writing.js for everything inside the kanji panel). Reuses the
   same tokens/recipes as the kana board above rather than introducing a
   second visual language — pill buttons match .kana-filter/.kana-filter
   __btn, cards match .kana-extra__block, the study panel matches
   .kana-dialog's stroke-pane/detail split. */

.writing-mode-tabs {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  margin-bottom: 4px;
  background: var(--panel-cream);
  border: 1px solid var(--gold-soft);
  border-radius: 999px;
}

.writing-mode-tab {
  appearance: none;
  cursor: pointer;
  border: 1.5px solid transparent;
  padding: 6px 20px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted-brown);
  background: transparent;
  border-radius: 999px;
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    color 140ms ease;
}

.writing-mode-tab:hover {
  color: var(--text-brown);
}

.writing-mode-tab--selected {
  background: var(--tab-blue);
  border-color: var(--blue-heart);
  color: var(--text-brown);
}

/* Sits directly on .content-sections's own background, same treatment as
   .kana-board__intro above it in Kana mode - no card/border of its own. */
.kanji-intro {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.kanji-intro .content-section__title {
  margin: 0;
}

.kanji-intro .content-section__body {
  margin: 0;
}

/* Settings panel: JLPT level checkboxes, search, the "hide repeats"
   filter, the browse-grid size control, and the kanji-selection-mode
   toggle, all in one place. Lives inside .kanji-panel, directly above
   .kanji-grid - same arrangement as .kana-filter sitting above
   .kana-board inside .kana-panel in Kana mode, so the two tabs feel like
   the same app. Its own panel-white card (below) is what keeps it
   visually distinct from the surrounding .kanji-panel cream, the same
   way .kanji-settings__levels' pills already contrast against it.

   position: sticky with `top` (not `bottom`) — same recipe as
   .support-panel in home.css: it's the *first* element inside
   .kanji-panel, so it pins near the top of the viewport once scrolling
   would otherwise carry it past, staying reachable the whole time
   you're scrolling the (long) grid below it. z-index keeps it above the
   grid's cards as they scroll underneath; the opaque background (above)
   is what keeps that scrolling content from showing through. */
.kanji-settings {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
  position: sticky;
  top: 12px;
  z-index: 2;
  background: var(--panel-white);
  border: 1px solid var(--gold-soft);
  border-radius: 14px;
}

.kanji-settings__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.kanji-settings__label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted-brown);
}

.kanji-settings__levels {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 2px;
  background: var(--panel-white);
  border: 1px solid var(--gold-soft);
  border-radius: 999px;
}

.kanji-settings__level {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 4px 12px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted-brown);
  border-radius: 999px;
  transition:
    background-color 140ms ease,
    color 140ms ease;
}

.kanji-settings__level:has(input:checked) {
  background: var(--tab-blue);
  color: var(--text-brown);
}

.kanji-settings__level input {
  accent-color: var(--blue-heart);
  cursor: pointer;
}

.kanji-settings__row--search {
  flex-wrap: wrap;
}

.kanji-settings__search-input {
  flex: 1 1 180px;
  min-width: 0;
  padding: 5px 10px;
  font-family: inherit;
  font-size: 0.78rem;
  color: var(--text-brown);
  background: var(--panel-white);
  border: 1.5px solid var(--gold-soft);
  border-radius: 999px;
  outline: none;
}

.kanji-settings__search-input:focus-visible {
  border-color: var(--blue-heart);
}

.kanji-settings__scope {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 2px;
  background: var(--panel-cream);
  border: 1px solid var(--gold-soft);
  border-radius: 999px;
}

.kanji-settings__scope-opt {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 4px 10px;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted-brown);
  border-radius: 999px;
  transition:
    background-color 140ms ease,
    color 140ms ease;
}

.kanji-settings__scope-opt:has(input:checked) {
  background: var(--tab-blue);
  color: var(--text-brown);
}

.kanji-settings__scope-opt input {
  accent-color: var(--blue-heart);
  cursor: pointer;
}

/* [hidden] needs its own override for the same reason as .kanji-study__top
   below: an author display rule ties with the UA stylesheet's [hidden] {
   display: none } on specificity, and author styles win ties regardless
   of source order. This label starts hidden (N5 alone has nothing earlier
   to filter out) until kanji-writing.js reveals it once a level with an
   easier level below it is checked. */
.kanji-settings__filter {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted-brown);
  cursor: pointer;
}

.kanji-settings__filter[hidden] {
  display: none;
}

.kanji-settings__filter input {
  accent-color: var(--blue-heart);
  cursor: pointer;
}

.kanji-settings__size {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.kanji-settings__size-btn {
  appearance: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: 1.5px solid var(--gold-soft);
  padding: 0;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1;
  color: var(--muted-brown);
  background: var(--panel-white);
  border-radius: 999px;
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    color 140ms ease;
}

.kanji-settings__size-btn:hover:not(:disabled) {
  color: var(--text-brown);
  border-color: var(--blue-heart);
}

.kanji-settings__size-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.kanji-settings__size-value {
  min-width: 3.2em;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted-brown);
  text-align: center;
}

.kanji-settings__selected-count {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted-brown);
}

.kanji-settings__clear-btn {
  appearance: none;
  cursor: pointer;
  margin-left: auto;
  border: 1.5px solid var(--gold-soft);
  padding: 4px 12px;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted-brown);
  background: var(--panel-white);
  border-radius: 999px;
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    color 140ms ease;
}

.kanji-settings__clear-btn:hover:not(:disabled) {
  color: var(--text-brown);
  border-color: var(--blue-heart);
}

.kanji-settings__clear-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Launches Game 2 (Kanji Drill) with only the checked cards - filled blue
   rather than clear-btn's quiet outline, since this is the row's primary
   action, not a housekeeping one. */
.kanji-settings__practice-btn {
  appearance: none;
  cursor: pointer;
  border: none;
  padding: 5px 14px;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  color: #fff;
  background: var(--blue-strong, #3f7cc2);
  border-radius: 999px;
  transition: filter 140ms ease;
}

.kanji-settings__practice-btn:hover:not(:disabled) {
  filter: brightness(1.08);
}

.kanji-settings__practice-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Main study area ---------------------------------------------------
   Always on screen (not conditionally shown on click) — the single most
   important element on this page after the JLPT selector, so it gets the
   biggest card treatment: thicker border, more generous padding than
   .kanji-browser below it. */
.kanji-study {
  margin-bottom: 16px;
  padding: 20px;
  background: var(--panel-cream);
  border: 1.5px solid var(--gold-soft);
  border-radius: 20px;
}

.kanji-study__empty {
  margin: 0;
  padding: 24px 4px;
  font-size: 0.9rem;
  color: var(--muted-brown);
  text-align: center;
}

.kanji-study__top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr);
  gap: 24px;
  align-items: start;
}

/* [hidden] needs its own override here: any author display rule ties with
   the UA stylesheet's [hidden] { display: none } on specificity, and
   author styles win ties regardless of source order. */
.kanji-study__top[hidden] {
  display: none;
}

@media (max-width: 640px) {
  .kanji-study__top {
    grid-template-columns: 1fr;
  }
}

.kanji-study__canvas-pane {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* The writing canvas is the visual anchor of the whole page — large and
   square, not a small side-panel thumbnail like the first pass had. */
.kanji-study__canvas-box {
  width: 100%;
  max-width: 280px;
  aspect-ratio: 1 / 1;
  background: var(--panel-white);
  border: 1.5px solid var(--gold-soft);
  border-radius: 18px;
  overflow: hidden;
}

.kanji-study__canvas-svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Faint handwriting-practice-paper cross through the center — a guide,
   not content, so it sits behind everything and stays quiet. */
.kanji-study__guide-line {
  stroke: var(--gold-soft);
  stroke-width: 0.6;
  stroke-dasharray: 2 2;
}

/* The full character, very pale, always visible behind the animation so
   the shape it's building toward is never a mystery — a guide the active
   stroke draws over, not content competing with it. Built from the same
   KanjiVG stroke paths the animation itself uses (kanji-writing.js copies
   every stroke's "d" into this group, fully drawn, before building the
   animated set) — a system-font glyph for the character looked similar
   at a glance but didn't actually match the hand-drawn stroke shapes'
   proportions, so the animation appeared to trace a different-looking
   kanji than the guide underneath it. Same source data both times now,
   so the two always agree pixel-for-pixel. */
.kanji-study__ghost .kanji-study__stroke-path {
  stroke: var(--text-brown);
  opacity: 0.14;
}

.kanji-study__stroke-path {
  fill: none;
  stroke: var(--muted-brown);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Currently drawing, mid-animation — the one moment a stroke should stand
   out from both the pale ghost and the other, already-settled strokes. */
.kanji-study__stroke-path--active {
  stroke: var(--blue-strong-text);
  stroke-width: 3.5;
}

/* Finished drawing (Play, once its transition settles; Step, instantly) —
   visible but quieter than the active stroke, so the ghost and the live
   stroke stay the two things actually competing for attention. */
.kanji-study__stroke-path--done {
  stroke: var(--text-brown);
}

.kanji-study__stroke-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.kanji-study__stroke-btn {
  appearance: none;
  cursor: pointer;
  border: 1.5px solid var(--gold-soft);
  padding: 5px 14px;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted-brown);
  background: var(--panel-white);
  border-radius: 999px;
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    color 140ms ease;
}

.kanji-study__stroke-btn:hover {
  color: var(--text-brown);
  border-color: var(--blue-heart);
}

/* Play is the primary action here — same active-state recipe as the
   selected writing-mode-tab/jlpt-selector button, not a third button
   style. */
.kanji-study__stroke-btn--play {
  background: var(--tab-blue);
  border-color: var(--blue-heart);
  color: var(--text-brown);
}

.kanji-study__hint {
  margin: 0;
  font-size: 0.7rem;
  color: var(--muted-brown);
  text-align: center;
}

.kanji-study__detail {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

/* Facts list on the left, the kanji glyph + its translation on the right
   — the glyph block sits beside the facts rather than stacked above
   them, so the two share one row instead of the glyph eating a full row
   of its own. */
.kanji-study__summary {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

/* Wraps the glyph card and its browse-selection nav (when selection mode
   is on) into one column, so the ← → arrows read as a single control
   right under the character they're browsing from — not a separate
   panel elsewhere on the page. */
.kanji-study__glyph-col {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

/* Same light-square-card language as .kanji-grid__item/.kana-board__cell
   elsewhere on this page, just bigger — the glyph reads as the one
   featured tile rather than plain floating text. */
.kanji-study__glyph-block {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 96px;
  height: 96px;
  background: var(--panel-white);
  border: 1.5px solid var(--gold-soft);
  border-radius: 16px;
}

/* The largest text on the page — this is the one thing the whole study
   area exists to show. */
.kanji-study__glyph {
  font-size: 3.25rem;
  line-height: 1;
  color: var(--text-brown);
}

/* [hidden] override for the same reason noted elsewhere in this file -
   an author display rule always wins the specificity tie against the UA
   stylesheet's [hidden] { display: none }. Hidden until kanji-writing.js
   reveals it once selection mode is turned on in the settings panel. */
.kanji-study__browse-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.kanji-study__browse-nav[hidden] {
  display: none;
}

.kanji-study__nav-btn {
  appearance: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 1.5px solid var(--gold-soft);
  padding: 0;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted-brown);
  background: var(--panel-white);
  border-radius: 999px;
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    color 140ms ease;
}

.kanji-study__nav-btn:hover:not(:disabled) {
  color: var(--text-brown);
  border-color: var(--blue-heart);
}

.kanji-study__nav-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Meaning/On'yomi/Kun'yomi/JLPT/Strokes/Frequency/Grade — a definition
   list so only the facts kanji-writing.js actually has data for ever
   render (it skips the dt/dd pair entirely rather than leaving an empty
   value showing), and so every property reads as one compact scannable
   block instead of a separate card each.

   flex: 1 1 0 (not the default auto) is load-bearing: as a flex item of
   .kanji-study__summary with basis `auto`, this grid's hypothetical main
   size is its max-content width - the width content would take laid out
   on a single line, ignoring wrap opportunities entirely. Kanji with a
   long reading list (e.g. 出's six kun'yomi entries) have a much wider
   max-content line than most, which used to be enough on its own to
   overflow the row and wrap .kanji-study__glyph-col onto its own line
   below. Basis 0 makes it size from the row's actual available space
   instead, so reading-list length no longer affects whether the glyph
   shifts down. */
.kanji-study__facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 10px;
  margin: 0;
  flex: 1 1 0;
  font-size: 0.8rem;
  min-width: 0;
}

.kanji-study__facts dt {
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.65rem;
  color: var(--muted-brown);
  align-self: baseline;
  padding-top: 2px;
}

.kanji-study__facts dd {
  margin: 0;
  color: var(--text-brown);
  overflow-wrap: anywhere;
}

/* ON/KUN readings: one small pill button per reading instead of addFact's
   plain joined string, so each is individually clickable to hear via
   mt-back's /api/tts (kanji-writing.js's playReading). Wraps onto
   multiple lines for kanji with long reading lists (e.g. 出's six
   kun'yomi), same reason .kanji-study__facts itself uses flex-basis 0
   above. */
.kanji-study__readings {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.kanji-study__reading {
  appearance: none;
  cursor: pointer;
  padding: 1px 9px;
  font-family: inherit;
  font-size: 0.8rem;
  color: var(--text-brown);
  background: var(--panel-white);
  border: 1px solid var(--gold-soft);
  border-radius: 999px;
  transition:
    background-color 140ms ease,
    border-color 140ms ease;
}

.kanji-study__reading:hover,
.kanji-study__reading:focus-visible {
  background: var(--tab-blue);
  border-color: var(--blue-heart);
}

/* Shown for as long as a reading's audio is still being synthesized
   (kanji-writing.js's setReadingLoading) - only visible on a reading's
   first-ever play, since mt-back caches every synthesized clip on disk
   after that. Without this the button just sits there for up to ~1s with
   no feedback while VOICEVOX (CPU-bound) renders it. */
.kanji-study__reading--loading {
  opacity: 0.6;
  cursor: wait;
  animation: mt-audio-pulse 900ms ease-in-out infinite;
}

@keyframes mt-audio-pulse {
  0%,
  100% {
    opacity: 0.6;
  }
  50% {
    opacity: 0.9;
  }
}

/* JLPT's value specifically reads as a small badge (same light-blue chip
   language as the selected jlpt-selector/writing-mode-tab button) rather
   than plain text, since it's the one fact that's also a selectable
   filter elsewhere on this page. */
.kanji-study__badge {
  display: inline-block;
  padding: 1px 9px;
  background: var(--tab-blue);
  border: 1px solid var(--blue-heart);
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
}

/* Small highlighted card, not just a paragraph — the mnemonic is a
   distinct learning aid, so it gets its own quiet background and a tiny
   decorative mark the way Kanjimono pairs an illustration with its
   mnemonics (see docs/API.md's "Implemented: kanji"), without borrowing
   that site's actual visual design. */
.kanji-study__mnemonic-card {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  background: var(--pink-chip);
  border: 1px solid var(--gold-soft);
  border-radius: 12px;
}

.kanji-study__mnemonic-icon {
  flex-shrink: 0;
  font-size: 1.1rem;
  line-height: 1.4;
}

.kanji-study__mnemonic-body {
  min-width: 0;
}

.kanji-study__mnemonic-label {
  margin: 0 0 2px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted-brown);
}

.kanji-study__mnemonic {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-brown);
}

.kanji-study__examples {
  min-width: 0;
}

.kanji-study__levels {
  grid-column: 1 / -1;
  min-width: 0;
}

.kanji-study__levels[hidden] {
  display: none;
}

/* Lower section: Browse Kanji ----------------------------------------
   Deliberately quieter than .kanji-study above — a functional selector,
   not a second information panel, so a plainer heading + tighter grid
   rather than another big cream card. */
.kanji-browser__title {
  margin: 0 0 4px;
  font-size: 1rem;
}

.kanji-browser__hint {
  margin: 0 0 10px;
  font-size: 0.78rem;
  color: var(--muted-brown);
}

/* Wraps .kanji-settings + .kanji-grid in one cream card, same role as
   .kana-panel wrapping .kana-filter + .kana-board in Kana mode - the
   settings panel reads as part of the same panel as the kanji it
   controls, not a separate block elsewhere on the page. */
.kanji-panel {
  background: var(--panel-cream);
  border-radius: 16px;
  padding: 16px;
}

/* Compact grid of small clickable kanji cards — deliberately not the
   large dashboard-card treatment; sized so many kanji are visible at
   once, same density spirit as .kana-board__cell's grid. --kanji-grid-scale
   is set inline by kanji-writing.js from the settings panel's size
   control (50%-300%, default 1) - every size below scales off it so the
   +/- buttons only need to touch one custom property. */
.kanji-grid {
  --kanji-grid-scale: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(calc(48px * var(--kanji-grid-scale)), 1fr));
  gap: calc(5px * var(--kanji-grid-scale));
}

.kanji-grid__empty {
  grid-column: 1 / -1;
  margin: 0;
  padding: 8px 4px;
  font-size: 0.85rem;
  color: var(--muted-brown);
  text-align: center;
}

/* The grid cell itself - a relative-positioned wrapper around the
   clickable .kanji-grid__item button plus the .kanji-grid__pick checkbox
   layered on top of it, so the checkbox isn't nested inside the button
   (invalid HTML - interactive content isn't allowed inside <button>) while
   still visually reading as one card. */
.kanji-grid__item-wrap {
  position: relative;
  min-height: calc(62px * var(--kanji-grid-scale));
}

.kanji-grid__item {
  appearance: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  width: 100%;
  height: 100%;
  padding: calc(4px * var(--kanji-grid-scale)) calc(2px * var(--kanji-grid-scale));
  font-family: inherit;
  background: var(--panel-white);
  border: 1px solid var(--kana-card-border);
  border-radius: 8px;
  overflow: hidden;
  transition:
    background-color 140ms ease,
    border-color 140ms ease;
}

/* Adds this kanji to the browse-selection nav in .kanji-settings. The
   label sits beside the study button, so clicking it never opens the
   kanji, and is larger than the box so near misses still tick it. */
.kanji-grid__pick-area {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  box-sizing: border-box;
  width: max(26px, calc(20px * var(--kanji-grid-scale)));
  height: max(26px, calc(20px * var(--kanji-grid-scale)));
  padding: 3px;
  cursor: pointer;
}

.kanji-grid__pick {
  display: block;
  width: calc(11px * var(--kanji-grid-scale));
  height: calc(11px * var(--kanji-grid-scale));
  margin: 0;
  accent-color: var(--blue-heart);
  cursor: pointer;
  opacity: 0.35;
}

/* Quiet by default so the checkboxes don't clutter every card; full
   strength while selecting, or when this card is already ticked. */
.kanji-grid--selecting .kanji-grid__pick,
.kanji-grid__pick:checked,
.kanji-grid__pick-area:hover .kanji-grid__pick {
  opacity: 1;
}

/* This combined list's browsing order (1 = most frequent) — sits at the
   bottom of the card, under the kanji itself, not a corner badge. */
.kanji-grid__order {
  font-size: calc(0.5rem * var(--kanji-grid-scale));
  line-height: 1;
  color: var(--muted-brown);
  opacity: 0.7;
}

/* [N5]-style JLPT tag next to a card's order number — same muted tone as
   the number itself, just enough weight to read as a distinct label
   rather than part of the digit sequence. */
.kanji-grid__level {
  font-weight: 700;
  opacity: 0.9;
}

.kanji-grid__item:hover {
  border-color: var(--blue-heart);
}

.kanji-grid__item:focus-visible {
  outline: 2px solid rgba(95, 153, 198, 0.55);
  outline-offset: 1px;
}

.kanji-grid__item--selected {
  background: var(--tab-blue);
  border-color: var(--blue-heart);
}

.kanji-grid__glyph {
  font-size: calc(1.1rem * var(--kanji-grid-scale));
  line-height: 1.1;
  color: var(--text-brown);
}

.kanji-grid__meaning {
  font-size: calc(0.68rem * var(--kanji-grid-scale));
  line-height: 1.1;
  color: var(--muted-brown);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* --- Dictionary mode ---------------------------------------------------
   Search box + result list for the Dictionary tab (dictionary.js), same
   "cream card wrapping a white-card list" language as .kana-panel/
   .kanji-panel wrapping their own boards. */

.dictionary-panel {
  background: var(--panel-cream);
  border-radius: 16px;
  padding: 16px;
}

.dictionary-search {
  display: block;
}

.dictionary-search__input {
  width: 100%;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text-brown);
  background: var(--panel-white);
  border: 1.5px solid var(--gold-soft);
  border-radius: 999px;
  outline: none;
}

.dictionary-search__input:focus-visible {
  border-color: var(--blue-heart);
}

.dictionary-results__status {
  margin: 12px 2px 0;
  font-size: 0.78rem;
  color: var(--muted-brown);
}

.dictionary-results {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dictionary-result {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
  padding: 10px 14px;
  background: var(--panel-white);
  border: 1px solid var(--kana-card-border, var(--gold-soft));
  border-radius: 12px;
}

.dictionary-result__tag {
  flex: 0 0 auto;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted-brown);
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--panel-cream);
}

.dictionary-result__tag--kanji {
  color: var(--blue-heart);
}

.dictionary-result__tag--kana {
  color: var(--pink-heart);
}

.dictionary-result__word {
  font-size: 1.05rem;
  color: var(--text-brown);
  white-space: nowrap;
}

.dictionary-result__reading {
  font-size: 0.85rem;
  color: var(--muted-brown);
  white-space: nowrap;
}

.dictionary-result__meaning {
  flex: 1 1 auto;
  font-size: 0.85rem;
  color: var(--text-brown);
}

/* Example-word links (kanji-writing.js's wordLinkCell) that jump into
   this tab - styled to still read as plain table text, just with an
   affordance that it's clickable, rather than looking like a generic
   button dropped into the words table. */
.kanji-study__word-link {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}

.kanji-study__word-link:hover,
.kanji-study__word-link:focus-visible {
  color: var(--blue-heart);
}

/* Per-result play button (dictionary.js's playWordAudio) - plain emoji
   glyph like games/core.js's 🔊 buttons elsewhere on the site, not a new
   icon style. */
.dictionary-result__play {
  flex: 0 0 auto;
  appearance: none;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  padding: 4px 6px;
  background: var(--panel-cream);
  border: 1px solid var(--gold-soft);
  border-radius: 999px;
  transition: opacity 140ms ease;
}

.dictionary-result__play:hover,
.dictionary-result__play:focus-visible {
  border-color: var(--blue-heart);
}

.dictionary-result__play--loading {
  opacity: 0.5;
  cursor: wait;
  animation: mt-audio-pulse 900ms ease-in-out infinite;
}
