/* ============================================================
   kanji-library.css — the standalone /kanji catalog browser.
   Mirrors vocab-library.css: a virtualized list (left) + detail
   panel (right), stacking on narrow screens. Theme-token based.
   ============================================================ */

.kanji-library {
  display: grid;
  grid-template-columns: minmax(240px, 320px) 1fr;
  gap: 24px;
  align-items: start;
  margin-top: 22px;   /* breathing room below the title banner */
}
/* The detail column sits level with the search row by default; nudge it down
   so its top lines up with the top of the kanji LIST instead (the list sits
   below the ~39px search input + its 10px bottom margin). */
.kanji-details { margin-top: 49px; }

/* The promo rail is NOT part of this grid — it lives in the page-level
   .layout-with-rail (site.css) wrapping the library AND the editorial block,
   so it can stay stuck past this fixed-height pane. The shared rail stacks at
   900px, but two panes plus a 300px rail get too narrow below ~1024px, so this
   page drops it at the same breakpoint the library itself reflows. */
@media (max-width: 1024px) {
  .kanji-library { grid-template-columns: minmax(240px, 340px) 1fr; }
  .kanjilib-page .layout-with-rail { grid-template-columns: 1fr; }
  .kanjilib-page .layout-with-rail__main,
  .kanjilib-page .layout-with-rail__rail { min-width: 0; }
  .kanjilib-page .layout-with-rail__rail { position: static; align-items: center; }
}
.kanjilib-page .layout-with-rail { margin-top: 22px; }
.kanjilib-page .kanji-library { margin-top: 0; }
/* The toolbar (search + category + stroke filter) spans a full grid row
   above the list, so the promo has to clear it to sit flush with the
   list card rather than floating level with the search box. */
@media (min-width: 1025px) {
  .kanjilib-page .layout-with-rail__rail { margin-top: 88px; }
}
@media (max-width: 760px) {
  /* Single column. The second selector matches the store-promo rule's
     specificity (.kanji-library:not(:has(.store-promo)) in site.css) so it
     actually wins on phones instead of being overridden back to 2 columns.
     The detail pane's bottom-sheet treatment lives at the END of this file
     (after the base .kanji-details rule) so its position:fixed wins. */
  .kanji-library,
  .kanji-library:not(:has(.store-promo)) { grid-template-columns: 1fr; gap: 16px; }
}

/* ── Left pane: search + list ───────────────────────────── */
.kanji-browse { display: flex; flex-direction: column; min-width: 0; }
/* wrap so a longer count / recall-link in other languages drops to a second
   line instead of squeezing the input; min-width keeps the field usable. */
.kanji-search-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 10px; }
#kanji-search-input {
  flex: 1 1 220px; min-width: 200px; font-family: inherit; font-size: 15px;
  padding: 9px 13px; border: 1.5px solid var(--container-border, #d9cdb4);
  border-radius: 10px; background: var(--bg, #fbf6ea); color: var(--text, #1f1a1a);
}
#kanji-search-input:focus {
  outline: none; border-color: var(--accent, #b32a2a);
  box-shadow: 0 0 0 3px var(--accent-bg, rgba(179, 42, 42, 0.07));
}
.kanji-count { font-size: 12px; color: var(--text-faint, #7a6260); letter-spacing: 0.04em; white-space: nowrap; }

/* "Recall sets & study →" link in the library search row — the primary
   route to /kanji-recall (mirrors .vocab-decks-link on /vocabulary). */
.kanji-recall-link {
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent, #b32a2a);
  text-decoration: none;
  white-space: nowrap;
}
@media (hover: hover) { .kanji-recall-link:hover { text-decoration: underline; } }

/* Category filter — browse the catalog by theme (Numbers, Nature, …).
   Dropdown matches the search-input border language; colours come from
   theme vars, so dark mode is covered. */
.kanji-cats {
  display: flex;
  align-items: center;
  flex-wrap: wrap;      /* the stroke filter drops to its own line on phones
                           instead of pushing the row past the viewport */
  gap: 8px;
  margin-bottom: 12px;
}
.kanji-cat-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint, #7a6260);
}
.kanji-cat-select {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text, #1f1a1a);
  background: var(--bg, #fbf6ea);
  border: 1.5px solid var(--container-border, #d9cdb4);
  border-radius: 10px;
  padding: 8px 34px 8px 12px;
  cursor: pointer;
  max-width: 100%;
  /* Custom chevron so the control reads intentional in both themes. */
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%237a6260' stroke-width='1.6' d='M1 1.5 6 6.5 11 1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  transition: border-color 0.15s;
}
.kanji-cat-select:hover { border-color: var(--accent, #20507e); }
.kanji-cat-select:focus {
  outline: none;
  border-color: var(--accent, #20507e);
}

.kanji-list {
  height: clamp(360px, 62vh, 720px);
  overflow-y: auto;
  border: 1.5px solid var(--container-border, #d9cdb4);
  border-radius: 12px; background: var(--bg, #fbf6ea);
  -webkit-overflow-scrolling: touch;
}
.kanji-item {
  height: 56px;            /* MUST match ROW_H in library-page.js */
  box-sizing: border-box;
  display: flex; align-items: center; gap: 12px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line, rgba(31, 26, 26, 0.08));
  cursor: pointer;
}
@media (hover: hover) { .kanji-item:hover { background: var(--accent-hover, rgba(179, 42, 42, 0.10)); } }
.kanji-item.selected {
  background: var(--accent-bg, rgba(179, 42, 42, 0.07));
  box-shadow: inset 3px 0 0 var(--accent, #b32a2a);
}
.kanji-item-char {
  flex: 0 0 auto; width: 34px; text-align: center;
  font-family: 'Klee One', 'Noto Sans JP', serif;
  font-size: 26px; font-weight: 600; color: var(--text, #1f1a1a); line-height: 1;
}
.kanji-item-meaning {
  flex: 1; min-width: 0; font-size: 14px; color: var(--text-muted, #54403a);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kanji-item-jlpt {
  flex: 0 0 auto; font-size: 11px; font-weight: 700; letter-spacing: 0.04em;
  color: var(--text-faint, #7a6260); background: var(--bg-outer, #f4ede0);
  border-radius: 999px; padding: 2px 8px;
}
/* Detail pane aligned with the top of the LIST, not the top of the toolbar.
   display:contents lifts .kanji-browse's children into this grid so the rows
   measure themselves; a fixed margin-top (what the .kr-add-kanji embed uses)
   would drift the moment the search row wraps -- which it already does in
   several languages. Scoped to --page so the embed keeps its own treatment. */
.kanji-library--page { grid-template-rows: auto 1fr; }
.kanji-library--page .kanji-browse { display: contents; }
/* One toolbar line across the whole grid. Confined to the 320px list column
   it had to stack onto three rows; spanning every column lets the search,
   count, category and stroke filter share a single line. */
.kanji-library--page .kanji-toolbar {
  grid-column: 1 / -1; grid-row: 1;
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 10px 16px; margin-bottom: 16px;
}
/* Dissolve the two inner wrappers so their children lay out on the toolbar's
   own flex line instead of forming two sub-rows. */
.kanji-library--page .kanji-toolbar .kanji-search-row,
.kanji-library--page .kanji-toolbar .kanji-cats { display: contents; }
.kanji-library--page .kanji-toolbar #kanji-search-input {
  /* grows to ~320px on desktop; shrinks on phones so the count keeps its
     line instead of being pushed to one of its own */
  flex: 1 1 200px; max-width: 320px; min-width: 0;
}
/* order:1 moves it past the category controls in DOM order, so the auto
   margin parks it at the FAR right instead of mid-row. */
.kanji-library--page .kanji-toolbar .kanji-recall-link { order: 1; margin-left: auto; }
.kanji-library--page .kanji-list    { grid-column: 1; grid-row: 2; }
.kanji-library--page .kanji-details { grid-column: 2; grid-row: 2; }
/* The ~49px nudge above was an earlier attempt at this same alignment, sized
   for a toolbar of just the search input. The grid rows now measure the real
   toolbar (search row + category row, either of which can wrap), so the fixed
   offset has to stand down here or it double-counts. */
.kanji-library--page .kanji-details { margin-top: 0; }
@media (max-width: 760px) {
  /* Single column: hand the flow back to .kanji-browse's flex column, and the
     detail pane becomes the fixed bottom sheet, so grid placement is moot. */
  .kanji-library--page { grid-template-rows: none; }
  .kanji-library--page .kanji-browse { display: flex; }
  /* Phones can't fit one line anyway, and the dissolved wrappers let
     "CATEGORY" split from its select. Put the two grouped rows back. */
  .kanji-library--page .kanji-toolbar { display: block; margin-bottom: 0; }
  .kanji-library--page .kanji-toolbar .kanji-search-row,
  .kanji-library--page .kanji-toolbar .kanji-cats { display: flex; }
  .kanji-library--page .kanji-toolbar .kanji-recall-link { order: 0; margin-left: 0; }
  .kanji-library--page .kanji-toolbar #kanji-search-input { max-width: none; }
  .kanji-library--page .kanji-toolbar,
  .kanji-library--page .kanji-search-row,
  .kanji-library--page .kanji-cats,
  .kanji-library--page .kanji-list,
  .kanji-library--page .kanji-details { grid-column: auto; grid-row: auto; }
}

/* Page-level coverage notice: sets the expectation that stroke data is still
   being generated. The "N of M so far" span is filled live by library-page.js. */
.kanji-stroke-notice {
  display: flex; align-items: flex-start; gap: 10px;
  margin: 22px 0 0;   /* matches .kanji-library's own top gap */
  padding: 12px 14px;
  border: 1.5px solid var(--container-border, #d9cdb4);
  border-radius: 12px;
  background: var(--bg-outer, #f4ede0);
}
.kanji-stroke-notice__icon {
  flex: 0 0 auto; font-size: 15px; line-height: 1.5;
  color: var(--accent, #b32a2a);
}
.kanji-stroke-notice__text {
  margin: 0; font-size: 13.5px; line-height: 1.55;
  color: var(--text-muted, #54403a);
}
.kanji-stroke-notice__stat { font-weight: 700; color: var(--text, #1f1a1a); }
.kanji-stroke-notice__stat:not(:empty) { margin-left: 4px; }

/* Stroke-order marker. Only ~292 of 1998 kanji have stroke data, so we mark
   the ones that DO rather than badging the 85% that don't. */
.kanji-item-stroke {
  flex: 0 0 auto; width: 18px; text-align: center;
  font-size: 13px; line-height: 1;
  color: var(--accent, #b32a2a);
}
.kanji-stroke-filter {
  display: inline-flex; align-items: center; gap: 5px;
  white-space: nowrap;   /* never let "Stroke order only" wrap + clip */
  font-size: 12px; font-weight: 700; letter-spacing: 0.02em;
  color: var(--text-faint, #7a6260);
  cursor: pointer; user-select: none;
}
.kanji-stroke-filter input { margin: 0; cursor: pointer; accent-color: var(--accent, #b32a2a); }
.kanji-stroke-filter:hover { color: var(--text, #1f1a1a); }
.kanji-stroke-filter:has(input:checked) { color: var(--accent, #b32a2a); }
.kanji-no-stroke-note {
  margin: 10px 0 0;
  font-size: 12.5px; line-height: 1.5;
  color: var(--text-faint, #7a6260);
  border-left: 2px solid var(--container-border, #d9cdb4);
  padding-left: 10px;
}

.kanji-spacer { width: 100%; }
.kanji-loading, .kanji-empty, .kanji-error {
  padding: 40px 16px; text-align: center; color: var(--text-faint, #7a6260); font-size: 14px;
}
.kanji-error { color: var(--accent, #b32a2a); }

/* ── Right pane: detail ─────────────────────────────────── */
.kanji-details {
  position: sticky; top: calc(var(--site-header-h, 67px) + 16px);
  border: 1.5px solid var(--container-border, #d9cdb4);
  border-radius: 14px; background: var(--bg, #fbf6ea);
  padding: 22px 24px; min-height: 200px;
}
.kanji-details-empty { color: var(--text-faint, #7a6260); font-size: 14px; text-align: center; padding: 40px 8px; }
.kanji-detail-head { display: flex; align-items: center; gap: 14px; }
/* "Add to set" action in the detail head — mirrors the list row's + button,
   pinned to the top-right of the pane. */
.kanji-detail-add {
  margin-left: auto; align-self: flex-start;
  display: inline-flex; align-items: center; gap: 6px;
  font-family: inherit; font-size: 13px; font-weight: 600; white-space: nowrap;
  padding: 7px 12px; border-radius: 9px; cursor: pointer;
  color: #fff; background: var(--accent, #b32a2a); border: 1.5px solid var(--accent, #b32a2a);
}
.kanji-detail-add__icon { font-size: 15px; line-height: 1; }
@media (hover: hover) { .kanji-detail-add:hover { filter: brightness(1.08); } }
.kanji-detail-add.in-set {
  color: var(--accent, #b32a2a);
  background: var(--accent-bg, rgba(179, 42, 42, 0.08));
  border-color: var(--accent-border, rgba(179, 42, 42, 0.30));
}
.kanji-detail-char {
  font-family: 'Klee One', 'Noto Sans JP', serif;
  font-size: 72px; font-weight: 700; color: var(--text, #1f1a1a); line-height: 1;
}
.kanji-detail-jlpt {
  font-size: 12px; font-weight: 700; letter-spacing: 0.04em;
  color: var(--accent, #b32a2a); background: var(--accent-bg, rgba(179, 42, 42, 0.08));
  border-radius: 999px; padding: 3px 10px;
}
.kanji-detail-meaning { font-size: 18px; color: var(--text, #1f1a1a); margin-top: 12px; }
.kanji-detail-readings {
  margin-top: 14px; padding-top: 14px;
  border-top: 1px solid var(--line, rgba(31, 26, 26, 0.08));
  display: flex; flex-direction: column; gap: 6px;
}
.kanji-reading-row { display: flex; align-items: baseline; gap: 12px; }
.kanji-reading-label {
  flex: 0 0 32px; font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--accent, #b32a2a);
}
.kanji-reading-val { font-family: 'Klee One', 'Noto Sans JP', serif; font-size: 16px; color: var(--text-muted, #54403a); }
.kanji-reading-loading { font-size: 13px; color: var(--text-faint, #7a6260); }
.kanji-detail-link {
  display: inline-block; margin-top: 18px;
  font-size: 14px; font-weight: 600; color: var(--accent, #b32a2a); text-decoration: none;
}
@media (hover: hover) { .kanji-detail-link:not(.is-disabled):hover { text-decoration: underline; } }
.kanji-detail-link.is-disabled { color: var(--text-faint, #7a6260); cursor: default; opacity: 0.7; }
.kanji-soon { font-weight: 400; font-style: italic; }

/* ── Compact embed (/kanji-recall "Find & add kanji") ───────
   The browser is a secondary helper here, not the whole page, so it
   uses a much shorter list and a non-stretching detail panel. Scoped to
   .kr-add-kanji so the standalone /kanji page keeps its full size. */
.kr-add-kanji .kanji-list { height: clamp(220px, 34vh, 380px); }
/* Keep the detail top aligned with the LIST top (offset past the ~49px search
   row), and give it the same height as the list so their BOTTOMS align too
   (box-sizing:border-box is global, so equal `height` = equal total box). */
.kr-add-kanji .kanji-details {
  min-height: 0; position: static; margin-top: 49px;
  height: clamp(220px, 34vh, 380px);
  overflow-y: auto;
}
/* The embed has no ad column, so keep it a 2-col list|detail browser (the
   standalone /kanji page's 3rd 300px ad column would otherwise leave an empty
   gap). */
.kr-add-kanji .kanji-library { grid-template-columns: minmax(240px, 320px) 1fr; margin-top: 0; }
@media (max-width: 760px) {
  .kr-add-kanji .kanji-library { grid-template-columns: 1fr; }   /* stack on phones */
  .kr-add-kanji .kanji-details { margin-top: 0; height: auto; }  /* no list to align to */
}

/* On /kanji-recall the set manager + "Find & add" section carry their own
   margins, so zero the layout's gaps rather than the old `display:block` on
   __main — that overrode `display:contents` and stopped the promo rail being
   lifted into the grid's second column. `gap` on __main is inert while it is
   display:contents and takes effect when it flips back to flex under 900px. */
#kanji-recall-home .layout-with-rail { row-gap: 0; }
#kanji-recall-home .layout-with-rail__main { gap: 0; }

/* Match the standalone /kanji page: strip the big `.section` card wrapping the
   "Find & add" embed so its search row + list card + detail card stand on
   their own (instead of the card-within-card look), and space it from the set
   manager above. */
.kr-add-kanji.section {
  margin-top: 30px;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
}

/* ── Mobile detail = bottom sheet ───────────────────────────────────
   Placed at end-of-file (after the base .kanji-details rule) so the
   position:fixed + close/backdrop reveal WIN on source order. On phones the
   list is full-width and tapping a kanji slides the detail up from the
   bottom; opened via the `kanji-detail-open` body class (library-page.js). */
.kanji-detail-close { display: none; }          /* shown only in sheet mode */
.kanji-sheet-backdrop { display: none; }

@media (max-width: 760px) {
  .kanji-details {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; margin: 0;
    z-index: 60; max-height: 82vh; overflow: auto;
    border-radius: 16px 16px 0 0; padding-top: 40px;
    transform: translateY(101%); transition: transform .28s ease;
    box-shadow: 0 -10px 34px rgba(0, 0, 0, 0.22);
  }
  .kanji-details::before {                       /* grab handle */
    content: ""; position: absolute; top: 11px; left: 50%;
    transform: translateX(-50%);
    width: 40px; height: 4px; border-radius: 2px;
    background: var(--container-border, #d9cdb4);
  }
  body.kanji-detail-open .kanji-details { transform: translateY(0); }
  .kanji-detail-close {
    display: inline-flex; align-items: center; justify-content: center;
    position: absolute; top: 6px; right: 10px; z-index: 2;
    width: 34px; height: 34px; padding: 0; border: none; border-radius: 8px;
    background: transparent; cursor: pointer; font-size: 17px; line-height: 1;
    color: var(--text-faint, #7a6260);
  }
  .kanji-sheet-backdrop {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(0, 0, 0, 0.42); opacity: 0; pointer-events: none;
    transition: opacity .28s ease;
  }
  body.kanji-detail-open .kanji-sheet-backdrop { opacity: 1; pointer-events: auto; }
  body.kanji-detail-open { overflow: hidden; }   /* lock background scroll */
}
