/* Focus Immersion — 通用规范汉字表 hanzi tier map.
   Page-scoped styles; relies on shared design tokens in /styles.css
   (--ink, --cream, --gold, fonts) but defines its own grid + drawer. */

.hanzi-page {
  --tier-cell: 2.35rem;
  max-width: 1240px;
  margin: 0 auto;
  padding: clamp(2.5rem, 5vw, 4rem) clamp(1rem, 4vw, 3rem) 5rem;
}

/* ---------- hero ---------- */
.hanzi-hero { padding: clamp(2.5rem, 7vw, 5rem) 0 clamp(1.4rem, 3vw, 2.2rem); }
.hanzi-hero .study-title { margin: 0.3rem 0 1rem; }
.hanzi-lede { max-width: 46rem; color: var(--cream); opacity: 0.86; font-size: 1.06rem; line-height: 1.62; }
.hanzi-lede strong { color: var(--gold); font-weight: 500; }
.hanzi-note { margin-top: 0.9rem; max-width: 46rem; font-size: 0.84rem; color: var(--cream); opacity: 0.5; line-height: 1.55; }

/* ---------- controls: tier filter + search ---------- */
.hanzi-controls {
  position: sticky; top: 0; z-index: 30;
  margin: 0 0 1.8rem;
  padding: 0.9rem 0 0.8rem;
  background: linear-gradient(180deg, var(--ink) 72%, rgba(11,10,8,0));
}
.hanzi-search {
  width: 100%; max-width: 30rem;
  margin-bottom: 0.9rem;
  background: rgba(236,227,211,0.05);
  border: 1px solid rgba(236,227,211,0.16);
  border-radius: 2px;
  color: var(--cream);
  font: inherit; font-size: 0.95rem;
  padding: 0.6rem 0.85rem;
  transition: border-color 0.2s;
}
.hanzi-search::placeholder { color: rgba(236,227,211,0.4); }
.hanzi-search:focus { outline: none; border-color: var(--gold); }

.tier-legend { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.tier-chip {
  display: inline-flex; align-items: center; gap: 0.45rem;
  background: rgba(236,227,211,0.04);
  border: 1px solid rgba(236,227,211,0.12);
  border-radius: 2px;
  color: var(--cream);
  font-family: var(--ff-mono, "DM Mono", monospace);
  font-size: 0.7rem; letter-spacing: 0.02em;
  padding: 0.32rem 0.55rem; cursor: pointer;
  transition: border-color 0.18s, background 0.18s, opacity 0.18s;
}
.tier-chip .tier-sw { width: 0.85rem; height: 0.85rem; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.35); flex: none; }
.tier-chip .tier-n { opacity: 0.5; }
.tier-chip:hover { border-color: rgba(236,227,211,0.32); }
.tier-chip.is-on { border-color: var(--gold); background: rgba(196,163,92,0.12); }
.hanzi-controls.has-filter .tier-chip:not(.is-on) { opacity: 0.42; }

/* ---------- tier bands ---------- */
.tier-band { margin-bottom: 2.4rem; scroll-margin-top: 7rem; }
.tier-band.is-hidden { display: none; }
.tier-band-head {
  display: flex; align-items: baseline; gap: 0.8rem; flex-wrap: wrap;
  padding-bottom: 0.7rem; margin-bottom: 0.9rem;
  border-bottom: 1px solid rgba(236,227,211,0.1);
}
.tier-band-head .tier-bar { align-self: center; width: 2.4rem; height: 0.62rem; border-radius: 1px; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.4); flex: none; }
.tier-band-head .tier-name { font-family: var(--ff-disp, "Fraunces", Georgia, serif); font-size: 1.5rem; color: var(--cream); }
.tier-band-head .tier-meta { font-size: 0.78rem; color: var(--cream); opacity: 0.5; margin-left: auto; }
.tier-band-head .tier-meta b { color: var(--cream); opacity: 0.85; font-weight: 500; }

.hanzi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--tier-cell), 1fr)); gap: 0.28rem; }
.hanzi-cell {
  aspect-ratio: 1 / 1;
  display: flex; align-items: center; justify-content: center;
  font-family: "Noto Serif SC", var(--ff-disp, "Fraunces", Georgia, serif);
  font-size: 1.32rem; line-height: 1;
  border: 1px solid transparent; border-radius: 2px;
  cursor: pointer; user-select: none;
  transition: transform 0.12s ease, background 0.15s, border-color 0.15s;
}
.hanzi-cell:hover, .hanzi-cell:focus-visible { transform: translateY(-2px); border-color: rgba(236,227,211,0.5); outline: none; }
.hanzi-cell.is-hidden { display: none; }
.hanzi-cell.is-hit { border-color: var(--gold); }

/* ---------- detail drawer ---------- */
.hanzi-drawer {
  position: fixed; top: 0; right: 0; z-index: 60;
  width: min(400px, 92vw); height: 100%;
  background: var(--surface, rgba(16,14,12,0.97));
  backdrop-filter: blur(8px);
  border-left: 1px solid rgba(236,227,211,0.14);
  box-shadow: -24px 0 60px rgba(0,0,0,0.5);
  transform: translateX(100%); transition: transform 0.32s cubic-bezier(0.22,1,0.36,1);
  overflow-y: auto; padding: 1.6rem 1.6rem 2.5rem;
}
.hanzi-drawer.is-open { transform: translateX(0); }
.hanzi-drawer-close {
  position: absolute; top: 1rem; right: 1.1rem;
  background: none; border: none; color: var(--cream); opacity: 0.55;
  font-size: 1.4rem; line-height: 1; cursor: pointer; padding: 0.2rem;
}
.hanzi-drawer-close:hover { opacity: 1; }

/* Glyph pair: traditional large, simplified secondary */
.hd-glyphs {
  display: flex; align-items: flex-end; gap: 1rem;
  margin: 0.3rem 0 0.5rem;
}
.hd-trad {
  font-family: "Noto Serif TC", "Noto Serif SC", var(--ff-disp, serif);
  font-size: 5.5rem; line-height: 1;
}
.hd-simp-wrap {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0.15rem;
  padding-bottom: 0.5rem;
}
.hd-simp {
  font-family: "Noto Serif SC", var(--ff-disp, serif);
  font-size: 2.4rem; line-height: 1; opacity: 0.7;
}
.hd-simp-label {
  font-family: var(--ff-mono, monospace); font-size: 0.6rem;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--cream); opacity: 0.35;
}
/* When traditional = simplified, show only one glyph */
.hd-glyphs.is-same .hd-simp-wrap { display: none; }

.hd-tier { display: inline-flex; align-items: center; gap: 0.5rem; font-family: var(--ff-mono, monospace); font-size: 0.78rem; color: var(--cream); opacity: 0.85; margin-bottom: 1.2rem; }
.hd-tier .tier-sw { width: 0.85rem; height: 0.85rem; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.4); }

.hd-rows { display: grid; gap: 0.05rem; }
.hd-row { display: grid; grid-template-columns: 6.2rem 1fr; gap: 0.6rem; padding: 0.6rem 0; border-top: 1px solid rgba(236,227,211,0.08); }
.hd-row:first-child { border-top: none; }
.hd-k { font-family: var(--ff-mono, monospace); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--cream); opacity: 0.45; padding-top: 0.15rem; }
.hd-v { color: var(--cream); font-size: 0.98rem; line-height: 1.5; }
.hd-v.zh { font-family: "Noto Serif SC", "Noto Serif TC", var(--ff-disp), serif; font-size: 1.1rem; }
.hd-v .muted { opacity: 0.4; }
.hd-pinyin { font-size: 1.15rem; letter-spacing: 0.04em; }

.hanzi-backdrop { position: fixed; inset: 0; z-index: 55; background: rgba(5,4,3,0.45); opacity: 0; pointer-events: none; transition: opacity 0.3s; }
.hanzi-backdrop.is-open { opacity: 1; pointer-events: auto; }

.hanzi-empty { padding: 2rem 0; color: var(--cream); opacity: 0.5; font-size: 0.95rem; }

@media (max-width: 640px) {
  .hanzi-page { --tier-cell: 2.05rem; }
  .hanzi-drawer { width: 100%; height: auto; max-height: 86vh; top: auto; bottom: 0; right: 0;
    border-left: none; border-top: 1px solid rgba(236,227,211,0.14);
    transform: translateY(100%); border-radius: 10px 10px 0 0; }
  .hanzi-drawer.is-open { transform: translateY(0); }
  .tier-band-head .tier-meta { margin-left: 0; width: 100%; }
  .hd-trad { font-size: 4rem; }
  .hd-simp { font-size: 1.8rem; }
}

/* ---------- stroke-order panel (hanzi drawer) ----------
   Was missing entirely (strokes.js, which injects this for kanji/kana, isn't loaded here),
   so the KanjiVG SVG paths rendered with the SVG default (black fill, no stroke) = invisible. */
.fi-stroke { margin: 0.4rem 0 1rem; display: flex; flex-direction: column; align-items: flex-start; gap: 0.5rem; }
.fi-stroke-canvas { width: 120px; height: 120px; border: 1px solid rgba(236,227,211,0.14); border-radius: 4px; background: rgba(236,227,211,0.03); }
.fi-stroke-canvas svg { width: 100%; height: 100%; }
.fi-stroke-canvas path { fill: none; stroke: var(--cream, #ece3d3); stroke-width: 4.5; stroke-linecap: round; stroke-linejoin: round; }
.fi-stroke-canvas g[id^='StrokeNumbers_'] text { fill: var(--gold, #c4a35c); font-size: 6px; opacity: 0.55; }
.fi-stroke-canvas path.fi-stroke-anim { animation: fi-stroke-draw var(--dur, 0.4s) linear forwards var(--delay, 0s); }
@keyframes fi-stroke-draw { to { stroke-dashoffset: 0; } }
.fi-stroke-btn { background: rgba(196,163,92,0.1); border: 1px solid rgba(196,163,92,0.4); color: var(--cream, #ece3d3); font-family: var(--ff-mono, 'DM Mono', monospace); font-size: 0.72rem; letter-spacing: 0.03em; padding: 0.34rem 0.7rem; border-radius: 3px; cursor: pointer; transition: border-color 0.18s, background 0.18s; }
.fi-stroke-btn:hover { border-color: var(--gold, #c4a35c); background: rgba(196,163,92,0.18); }
@media (prefers-reduced-motion: reduce) { .fi-stroke-canvas path.fi-stroke-anim { animation: none; stroke-dashoffset: 0; } }
