/* ============================================================
   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 300px;
  gap: 24px;
  align-items: start;
  margin-top: 22px;   /* breathing room below the title banner */
}
/* The detail + ad columns sit level with the search row by default; nudge
   them down so their tops line up with the top of the kanji LIST instead
   (the list sits below the ~39px search input + its 10px bottom margin). */
.kanji-details, .kanji-adrail { margin-top: 49px; }

/* Below the widest layout, drop the dedicated ad column: it spans full
   width beneath the list + detail pair (centered), then everything
   stacks to a single column on phones. */
@media (max-width: 1024px) {
  .kanji-library { grid-template-columns: minmax(240px, 340px) 1fr; }
  .kanji-adrail { grid-column: 1 / -1; position: static; display: flex; justify-content: center; margin-top: 0; }
}
@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;
  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;
}
.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); }

/* ── Ad column: dedicated third column, sticky like the detail pane ── */
.kanji-adrail { position: sticky; top: 16px; }

/* ── Right pane: detail ─────────────────────────────────── */
.kanji-details {
  position: sticky; top: 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 home view's ad rail uses block flow in its main column
   so the set manager + "Find & add" section keep their own margins (the rail's
   default flex `gap` would double up with the section margins). */
#kanji-recall-home .layout-with-rail__main { display: block; }

/* 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 */
}
