/* ── Kanji Detail Modal — scoped under #kanji-detail-overlay ─────────
   z-index: 2000 (above #dict-overlay at 1000).
──────────────────────────────────────────────────────────────────────── */

#kanji-detail-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2000;
  pointer-events: none;
}

#kanji-detail-overlay.open {
  display: block;
  pointer-events: auto;
}

#kanji-detail-overlay .kd-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}

/* ── Modal shell ───────────────────────────────────────────────────── */

#kanji-detail-overlay .kd-modal {
  background: var(--color-bg);
  border-radius: 16px;
  width: 100%;
  max-width: 340px;
  min-height: 480px;
  max-height: calc(100dvh - 2.5rem);
  box-shadow: 0 16px 56px rgba(0, 0, 0, 0.26);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Header ────────────────────────────────────────────────────────── */

#kanji-detail-overlay .kd-head {
  display: flex;
  align-items: center;
  padding: 0.85rem 0.75rem 0.6rem 1rem;
  border-bottom: 1px solid var(--color-border-light);
  flex-shrink: 0;
}

#kanji-detail-overlay .kd-char {
  flex: 1;
  font-size: 3.5rem;
  line-height: 1;
  font-family: var(--paragraph-font-family);
  color: var(--color-text-primary);
}

#kanji-detail-overlay .kd-head-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  align-self: flex-start;
  padding-top: 0.1rem;
}

#kanji-detail-overlay .kd-jlpt-badge {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--brand);
  background: var(--brand-tint);
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  white-space: nowrap;
}

/* Matches the dictionary search bar's clear button: 44px tap target with a
   28px circular swatch and a 13px stroke-X that rotates on hover. Negative
   margins keep the larger hit area from bloating the header row. */
#kanji-detail-overlay .kd-close {
  position: relative;
  width: 44px;
  height: 44px;
  margin: -0.5rem -0.4rem -0.5rem 0;
  border: none;
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: #888;
}
#kanji-detail-overlay .kd-close::after {
  content: '';
  position: absolute;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #ebebeb;
  transition: background 0.12s, transform 0.1s;
}
#kanji-detail-overlay .kd-close:hover::after { background: #ddd; }
#kanji-detail-overlay .kd-close:active::after {
  transform: scale(0.84);
  background: color-mix(in oklab, var(--brand) 18%, #ddd);
}
#kanji-detail-overlay .kd-close svg {
  width: 13px;
  height: 13px;
  position: relative;
  z-index: 1;
  transition: transform 0.15s, color 0.12s;
}
#kanji-detail-overlay .kd-close:hover svg {
  transform: rotate(90deg);
  color: #555;
}

/* ── Scrollable body ───────────────────────────────────────────────── */

#kanji-detail-overlay .kd-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Stroke canvas ─────────────────────────────────────────────────── */

#kanji-detail-overlay .kd-stroke-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem 1rem 0.5rem;
  gap: 0.6rem;
}

#kanji-detail-overlay .kd-canvas {
  width: 176px;
  height: 176px;
  background: var(--color-surface);
  border-radius: 12px;
  border: 1px solid var(--color-border-light);
  position: relative;
  flex-shrink: 0;
}

/* KanjiVG stroke animation: centerline paths drawn in order via stroke-dash.
   The faint outline shows the full glyph; .kd-strokes paths start hidden
   (opacity 0) and are revealed one by one by the JS animation. */
#kanji-detail-overlay .kd-svg {
  display: block;
  width: 176px;
  height: 176px;
}
#kanji-detail-overlay .kd-guide line {
  stroke: var(--color-border-light);
  stroke-width: 1;
  stroke-dasharray: 4 4;
}
#kanji-detail-overlay .kd-outline path {
  fill: none;
  stroke: var(--color-border);
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.4;
}
#kanji-detail-overlay .kd-strokes path {
  fill: none;
  stroke: var(--color-text-primary);
  stroke-width: 4.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0; /* JS sets opacity:1 as each stroke begins drawing */
}

#kanji-detail-overlay .kd-canvas--error {
  display: flex;
  align-items: center;
  justify-content: center;
}

#kanji-detail-overlay .kd-stroke-missing {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  text-align: center;
  padding: 1rem;
  line-height: 1.5;
}

#kanji-detail-overlay .kd-stroke-controls {
  min-height: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

#kanji-detail-overlay .kd-stroke-loading {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

#kanji-detail-overlay .kd-replay-btn {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 0.25rem 1rem;
  font-size: 0.82rem;
  cursor: pointer;
  color: var(--color-text-secondary);
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
}
#kanji-detail-overlay .kd-replay-btn:hover:not(:disabled) {
  background: var(--color-surface);
  color: var(--color-text-primary);
}
#kanji-detail-overlay .kd-replay-btn.is-active {
  color: var(--color-text-muted);
  cursor: default;
  border-color: var(--color-border-light);
}

/* ── Info ──────────────────────────────────────────────────────────── */

#kanji-detail-overlay .kd-info {
  padding: 0.75rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border-top: 1px solid var(--color-border-light);
}

#kanji-detail-overlay .kd-meanings {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text-primary);
  line-height: 1.35;
}

#kanji-detail-overlay .kd-readings {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.88rem;
  color: var(--color-text-primary);
}

#kanji-detail-overlay .kd-reading-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

#kanji-detail-overlay .kd-reading-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
  border-radius: 3px;
  padding: 1px 6px;
  flex-shrink: 0;
  line-height: 1.4;
}

#kanji-detail-overlay .kd-on  { color: var(--reading-on); border: 1px solid color-mix(in oklab, var(--reading-on) 22%, transparent); }
#kanji-detail-overlay .kd-kun { color: var(--reading-kun); border: 1px solid color-mix(in oklab, var(--reading-kun) 22%, transparent); }

#kanji-detail-overlay .kd-meta {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

#kanji-detail-overlay .kd-meta-chip {
  font-size: 0.73rem;
  color: var(--color-text-muted);
  background: var(--color-surface);
  border-radius: 4px;
  padding: 0.15rem 0.45rem;
}

/* ── Footer — always pinned at bottom ──────────────────────────────── */

#kanji-detail-overlay .kd-words-btn {
  flex-shrink: 0;
  display: block;
  width: 100%;
  /* The modal floats centered, never touching the home indicator — symmetric
     padding keeps the label vertically centered with no dead band below it. */
  padding: 0.9rem 1rem;
  background: var(--brand);
  color: #fff;
  border: none;
  border-top: 1px solid rgba(0,0,0,0.08);
  font-size: 0.93rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: opacity 0.12s;
  letter-spacing: 0.01em;
}
#kanji-detail-overlay .kd-words-btn:hover { opacity: 0.88; }

#kanji-detail-overlay .kd-words-char {
  font-family: var(--paragraph-font-family);
  font-size: 1.1em;
}

/* ── Words screen — full-height second screen in the same overlay ──── */

/* Words + entry screens go full-bleed (the centered modal clipped the header
   controls off-screen on a phone). The kanji screen (screen 1) stays a card. */
#kanji-detail-overlay .kd-backdrop:has(.kd-modal--words) { padding: 0; }
#kanji-detail-overlay .kd-modal--words {
  max-width: none;
  width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  border-radius: 0;
}

#kanji-detail-overlay .kd-head--words {
  gap: 0.5rem;
  padding: calc(0.6rem + env(safe-area-inset-top, 0px)) 0.75rem 0.6rem;
}

#kanji-detail-overlay .kd-back { margin: -0.5rem 0 -0.5rem -0.4rem; }

#kanji-detail-overlay .kd-words-title {
  flex: 1;
  min-width: 0;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-text-primary);
}
#kanji-detail-overlay .kd-words-title .kd-words-char { font-size: 1.25em; }

#kanji-detail-overlay .kd-words-empty {
  padding: 2rem 1rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

/* Hosts the dictionary's own result zone (.wd-scope > .zone.zone-brand). Just
   padding + a safe-area gutter; the rows carry their own styling verbatim. */
#kanji-detail-overlay .kd-words-results {
  padding: 0.5rem 0.75rem calc(0.85rem + var(--sab, env(safe-area-inset-bottom)));
}

/* ── Entry screen — hosts the dictionary's shared DetailContent ────── */
/* Same flex-column contract as .detail-host in dictionary.css: the entry's
   own .detail-scroll flexes and scrolls, the action bar pins at the bottom. */
#kanji-detail-overlay .kd-entry-host {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
