/* ============================================================
   Jengo Encounter — scoped under #encounter-overlay

   Full-screen React overlay (z-index 1000), same family as the reader /
   dictionary overlays. The word lookup REUSES the shared reading dictionary
   (window.JengoDict.DetailContent in a .wd-scope wrapper), so the dictionary
   styling lives in dictionary.css — this file only positions it (desktop dock /
   mobile bottom sheet) and styles the encounter-specific chrome. All color
   routes through tokens or color-mix(); the reading surface stays ultra-clean.
   ============================================================ */

#encounter-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  background: var(--color-bg);
  overscroll-behavior: none;
  color: var(--color-text-primary);

  /* local token block (theme-tracking) */
  --enc-brand-tint:        color-mix(in oklab, var(--brand) 8%, white);
  --enc-brand-tint-strong: color-mix(in oklab, var(--brand) 16%, white);
  --enc-brand-line:        color-mix(in oklab, var(--brand) 42%, white);
  /* warm-amber word marking — same functional language as the reader's yellow */
  --enc-mark:      color-mix(in oklab, var(--orange) 24%, white);
  --enc-mark-line: color-mix(in oklab, var(--orange) 48%, white);

  --enc-ui-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  --enc-jp-sans: -apple-system, BlinkMacSystemFont, 'Hiragino Kaku Gothic ProN', 'Yu Gothic', sans-serif;
  --sat: env(safe-area-inset-top, 0px);
  font-family: var(--enc-ui-font);
}
#encounter-overlay.open {
  display: block;
  animation: enc-open 0.26s cubic-bezier(.2, .7, .2, 1) both;
}
@keyframes enc-open {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) { #encounter-overlay.open { animation: none; } }

#encounter-overlay * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
#encounter-overlay button { margin: 0; font-family: var(--enc-ui-font); cursor: pointer; }
#encounter-overlay #encounter-mount { position: absolute; inset: 0; overflow: hidden; }

.enc-screen { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--color-bg); }

/* ── Appbar (Home/shelf) — brand bar, back-chevron left, centred title ───────── */
.enc-appbar {
  flex: 0 0 auto;
  min-height: 52px;
  padding: var(--sat) 10px 0 14px;
  background: var(--brand);
  color: #fff;
  display: flex; align-items: center; justify-content: space-between;
}
.enc-appbar-title { font-size: 1.05rem; font-weight: 700; letter-spacing: 0.01em; }
.enc-ico {
  width: 38px; height: 38px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: none; color: #fff;
  transition: background 0.14s ease;
}
.enc-ico:hover { background: rgba(255,255,255,0.14); }
.enc-ico svg { width: 22px; height: 22px; stroke: #fff; stroke-width: 1.9; }
.enc-appbar-spacer { width: 38px; display: inline-block; }

/* ── Reading header — quiet light bar so the prose is the focus (reader .rtop) ── */
.enc-rtop {
  flex: 0 0 auto;
  padding: calc(var(--sat) + 11px) 16px 11px;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border-light);
}
.enc-rtop-inner {
  display: flex; align-items: center; gap: 14px;
  max-width: 60rem; margin: 0 auto; width: 100%;
}
.enc-rtop-back {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 13px 8px 9px; border-radius: 999px;
  border: 1px solid var(--color-border); background: var(--color-bg);
  font-size: 0.85rem; font-weight: 600; color: var(--color-text-secondary);
  transition: border-color 0.14s ease, color 0.14s ease;
}
.enc-rtop-back:hover { border-color: var(--enc-brand-tint-strong); color: var(--brand); }
.enc-rtop-back svg { width: 17px; height: 17px; stroke: currentColor; stroke-width: 2; }
.enc-rtop-title {
  flex: 1; min-width: 0;
  font-family: var(--enc-jp-sans);
  font-size: 0.95rem; font-weight: 700; color: var(--color-text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.enc-rtop-chip {
  flex: 0 0 auto;
  font-size: 0.62rem; font-weight: 700; color: var(--brand);
  background: var(--enc-brand-tint); border-radius: 999px; padding: 3px 9px;
}
/* Top-bar actions (desktop): a labeled "Targets" button + a proper gear icon —
   not the old 19px mystery glyphs. On mobile these move to the quietbar. */
.enc-rtop-actions { display: none; align-items: center; gap: 8px; flex: 0 0 auto; }
.enc-rtop-act {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 12px; border-radius: 999px;
  background: none; border: 1px solid var(--color-border);
  font-size: 0.82rem; font-weight: 600; color: var(--color-text-secondary);
  transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease;
}
.enc-rtop-act:hover { border-color: var(--enc-brand-tint-strong); color: var(--brand); }
.enc-rtop-act svg { stroke: currentColor; }
.enc-rtop-act-icon { width: 34px; padding: 0; justify-content: center; }

/* ── Home body ──────────────────────────────────────────────────────────────── */
.enc-body { flex: 1; min-height: 0; overflow-y: auto; }
.enc-body-pad { padding: 1.5rem 1.25rem calc(var(--nav-h, 0px) + var(--sab, 20px) + 1.5rem); }

.enc-intro { max-width: 30rem; margin: 0 auto; text-align: center; padding: 1.5rem 0 0.5rem; }
.enc-intro.is-loading { min-height: 140px; }
.enc-intro-lead {
  font-size: 0.92rem; color: var(--color-text-muted); line-height: 1.6;
  margin: 0 auto 1.4rem; max-width: 26rem;
}
/* Headline count — the one prominent "how many are ready" line. */
.enc-intro-count {
  margin: 0 0 0.9rem; font-size: 1.2rem; font-weight: 400; color: var(--color-text-primary);
}
.enc-intro-count strong { font-weight: 700; font-variant-numeric: tabular-nums; }
.enc-intro-sub { font-size: 0.88rem; color: var(--color-text-muted); margin: 0.9rem auto 0; max-width: 26rem; line-height: 1.5; }
/* Roster link — a distinct, unsquished transparency affordance (its own row). */
.enc-intro-see {
  display: inline-flex; align-items: center; gap: 4px; margin: 1.1rem auto 0;
  background: none; border: none; padding: 0.3rem 0.5rem;
  font-size: 0.85rem; font-weight: 600; color: var(--brand); cursor: pointer;
}
.enc-intro-see:hover { text-decoration: underline; }
.enc-intro-see svg { stroke: var(--brand); stroke-width: 2.4; }
.enc-offline-note {
  margin: 1.1rem auto 0; max-width: 24rem;
  font-size: 0.8rem; color: var(--color-text-muted); line-height: 1.5;
}
/* Loading skeleton (shimmer) replaces the old blank box. */
.enc-skel { border-radius: 8px; margin: 0 auto; background: var(--color-surface);
  background-image: linear-gradient(90deg, transparent, color-mix(in oklab, var(--color-border) 60%, transparent), transparent);
  background-size: 200% 100%; animation: enc-shimmer 1.3s ease-in-out infinite; }
@keyframes enc-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .enc-skel { animation: none; } }
.enc-skel-count { width: 13rem; height: 1.5rem; margin-bottom: 1.1rem; }
.enc-skel-meter { width: 8.5rem; height: 0.5rem; margin-bottom: 1.6rem; }
.enc-skel-btn { width: 9.5rem; height: 2.6rem; border-radius: 8px; }

.enc-meter { display: flex; gap: 4px; justify-content: center; }
.enc-meter-seg { width: 30px; height: 5px; border-radius: 999px; background: var(--color-border); transition: background 0.25s ease; }
.enc-meter-seg.is-on { background: var(--brand); }

.enc-btn-primary {
  display: inline-flex; align-items: center; gap: 0.45rem;
  background: var(--brand); color: #fff; border: none;
  border-radius: 8px; padding: 0.65rem 1.5rem;
  font-size: 0.98rem; font-weight: 600;
  transition: opacity 0.15s ease;
}
.enc-btn-primary:hover { opacity: 0.9; }
.enc-btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.enc-btn-secondary {
  background: none; border: 1px solid var(--color-border); color: #555;
  border-radius: 8px; padding: 0.55rem 1.3rem; font-size: 0.9rem; font-weight: 500;
  transition: border-color 0.14s ease, color 0.14s ease;
}
.enc-btn-secondary:hover { border-color: #aaa; color: var(--color-text-primary); }

/* ── Empty state ────────────────────────────────────────────────────────────── */
.enc-empty { text-align: center; padding: 2.5rem 1.5rem 1.5rem; max-width: 24rem; margin: 0 auto; }
.enc-empty-icon { color: color-mix(in oklab, var(--brand) 55%, var(--color-border)); margin-bottom: 0.9rem; }
.enc-empty h3 { font-size: 1.08rem; font-weight: 600; color: #555; margin: 0 0 0.5rem; }
.enc-empty p { font-size: 0.9rem; color: var(--color-text-muted); margin: 0; line-height: 1.6; }

/* ── Chapters shelf ─────────────────────────────────────────────────────────── */
.enc-shelf { max-width: 34rem; margin: 2rem auto 0; }
.enc-shelf-label {
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--color-text-muted); padding: 0 0.25rem 0.5rem;
}
.enc-shelf-row {
  width: 100%; display: flex; align-items: center; gap: 0.75rem;
  background: none; border: none; text-align: left;
  padding: 0.85rem 0.5rem; border-top: 1px solid var(--color-border-light);
  transition: background 0.12s ease;
}
.enc-shelf-row:hover { background: var(--enc-brand-tint); }
.enc-shelf-row-main { flex: 1; min-width: 0; }
.enc-shelf-row-title { display: flex; align-items: center; gap: 0.5rem; font-size: 0.92rem; font-weight: 600; color: var(--color-text-primary); }
/* Done vs in-progress: an unfinished chapter is resumable, a read one is closed. */
.enc-shelf-tag { flex: 0 0 auto; font-size: 0.64rem; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; border-radius: 999px; padding: 2px 8px; }
.enc-shelf-tag.is-unfinished { color: color-mix(in oklab, var(--orange) 80%, black); background: color-mix(in oklab, var(--orange) 16%, white); }
.enc-shelf-tag.is-done { color: var(--color-text-muted); background: var(--color-surface); }
.enc-shelf-row.is-unfinished .enc-shelf-row-title { color: var(--color-text-primary); }
.enc-shelf-row:not(.is-unfinished) .enc-shelf-row-title { color: var(--color-text-secondary); }
.enc-shelf-row-snippet {
  font-family: var(--paragraph-font-family);
  font-size: 0.82rem; color: var(--color-text-muted);
  margin-top: 0.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.enc-shelf-row-level {
  flex: 0 0 auto; font-size: 0.68rem; font-weight: 600; color: #555;
  background: var(--color-surface); padding: 2px 7px; border-radius: 3px;
}

/* ── Reading body: prose + (desktop) docked dictionary aside ─────────────────── */
.enc-read-body { flex: 1; min-height: 0; display: flex; }
.enc-reading-main { flex: 1; min-width: 0; display: flex; }
.enc-read {
  flex: 1; min-width: 0; overflow-y: auto;
  padding: 1.75rem 1.25rem calc(var(--sab, 20px) + 1.5rem);
}
.enc-p {
  max-width: 38rem; margin: 0 auto 1.05rem;
  font-family: var(--enc-ff, var(--paragraph-font-family));
  font-size: var(--enc-fs, 1.12rem);
  line-height: var(--enc-lh, 1.95);
  color: var(--color-text-primary);
}
.enc-p-stream { color: color-mix(in oklab, var(--color-text-primary) 75%, white); }

.enc-w { cursor: pointer; border-radius: 3px; transition: background 0.12s ease; }
.enc-w:hover { background: var(--enc-brand-tint); }
.enc-w.is-marked { background: var(--enc-mark); box-shadow: inset 0 -2px 0 var(--enc-mark-line); }
.enc-w.is-active { outline: 2px solid var(--brand); outline-offset: 1px; border-radius: 2px; }
.enc-w rt { font-size: 0.6em; color: var(--color-text-secondary); font-family: var(--enc-ui-font); }

.enc-read-footer { max-width: 38rem; margin: 2rem auto 0; text-align: center; padding-top: 1.25rem; border-top: 1px solid var(--color-border-light); }
.enc-read-hint { font-size: 0.84rem; color: var(--color-text-muted); margin: 0 0 0.9rem; line-height: 1.5; }

/* ── First-run coach (one-time, dismissible) ────────────────────────────────── */
.enc-coach {
  max-width: 38rem; margin: 0 auto 1.5rem;
  background: var(--enc-brand-tint); border-radius: 12px;
  padding: 0.95rem 1.1rem;
  display: flex; align-items: flex-start; gap: 0.85rem;
}
.enc-coach p { flex: 1; margin: 0; font-size: 0.86rem; line-height: 1.55; color: var(--color-text-secondary); }
.enc-coach p strong { color: var(--brand); font-weight: 700; }
.enc-coach-dismiss {
  flex: 0 0 auto; align-self: center;
  background: none; border: 1px solid var(--enc-brand-line); color: var(--brand);
  border-radius: 999px; padding: 0.35rem 0.85rem; font-size: 0.8rem; font-weight: 600;
  transition: background 0.14s ease;
}
.enc-coach-dismiss:hover { background: var(--enc-brand-tint-strong); }

/* ── Desktop docked dictionary + flagged-words list (mirrors reader aside) ───── */
.enc-word-panel { display: none; }
.enc-wp-inner { display: flex; flex-direction: column; gap: 14px; }
.enc-dict-slot:empty { display: none; }
/* Bounded flex column so DetailContent's .detail-scroll scrolls inside and the
   .detail-actions row stays pinned at the bottom (mirrors the reader slot). */
.enc-dict-slot.has-detail {
  border: 1px solid var(--color-border); border-radius: 14px;
  background: var(--color-bg); overflow: hidden;
  display: flex; flex-direction: column; max-height: 60vh;
}
.enc-wp-list {
  border: 1px solid var(--color-border); border-radius: 14px;
  background: var(--color-bg); overflow: hidden; display: flex; flex-direction: column; min-height: 0;
}
.enc-lh { display: flex; align-items: baseline; gap: 8px; padding: 13px 15px; border-bottom: 1px solid var(--color-border-light); }
.enc-lt { font-size: 0.82rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--color-text-secondary); }
.enc-lc { font-size: 0.74rem; color: var(--color-text-muted); margin-left: auto; font-variant-numeric: tabular-nums; }
.enc-list-rows { overflow-y: auto; }
.enc-list-row { display: flex; align-items: center; gap: 10px; padding: 11px 15px; cursor: pointer; border-bottom: 1px solid var(--color-border-light); }
.enc-list-row:last-child { border-bottom: none; }
.enc-list-row:hover { background: var(--color-surface); }
.enc-list-row.is-active { background: var(--enc-brand-tint); }
.enc-swatch { width: 7px; height: 28px; border-radius: 4px; flex: 0 0 auto; background: var(--enc-mark-line); }
.enc-rmid { min-width: 0; }
.enc-rmid-jp { font-family: var(--enc-jp-sans); font-size: 1rem; font-weight: 700; color: var(--color-text-primary); display: block; }
.enc-rmid-rd { font-family: var(--paragraph-font-family); font-size: 0.72rem; color: var(--color-text-secondary); margin-top: 1px; display: block; }
.enc-rmid-en { margin-left: auto; font-size: 0.74rem; color: var(--color-text-secondary); max-width: 45%; text-align: right; }
.enc-list-empty { padding: 2rem 1.25rem; text-align: center; font-size: 0.84rem; color: var(--color-text-muted); line-height: 1.6; }

/* ── Mobile bottom nav (quietbar) ───────────────────────────────────────────── */
.enc-quietbar {
  flex: 0 0 auto;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 7px 12px calc(var(--sab, 20px) + 7px);
  border-top: 1px solid var(--color-border-light); background: var(--color-bg);
}
.enc-qb-back { justify-self: start; display: inline-flex; align-items: center; gap: 5px; padding: 7px 13px 7px 9px; border-radius: 999px; border: none; background: none; font-size: 0.82rem; font-weight: 600; color: var(--color-text-secondary); cursor: pointer; }
.enc-qb-back:active { background: var(--color-surface); }
.enc-qb-back svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 2; }
/* Center group: Targets + Flagged, the two per-scene word surfaces. */
.enc-qb-center { justify-self: center; display: inline-flex; align-items: center; gap: 6px; }
.enc-qb-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 13px; border-radius: 999px; border: none;
  background: var(--enc-brand-tint);
  font-size: 0.82rem; font-weight: 600; color: var(--brand); cursor: pointer;
}
.enc-qb-pill:active { background: var(--enc-brand-tint-strong); }
.enc-qb-pill svg { width: 16px; height: 16px; stroke: var(--brand); stroke-width: 1.9; }
.enc-qb-ct { font-variant-numeric: tabular-nums; }
.enc-qb-btn { justify-self: end; width: 36px; height: 36px; border-radius: 999px; border: none; background: none; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.enc-qb-btn:active { background: var(--color-surface); }
.enc-qb-btn svg { width: 20px; height: 20px; stroke: var(--color-text-secondary); stroke-width: 1.8; }

/* ── Shared sheet (settings / roster / recap): bottom sheet on mobile,
      centered card on desktop ────────────────────────────────────────────────── */
.enc-sheet-wrap {
  position: fixed; inset: 0; z-index: 700;
  background: rgba(0,0,0,0.32);
  display: flex; align-items: center; justify-content: center;
  animation: enc-fade 0.18s ease;
}
@keyframes enc-fade { from { opacity: 0; } to { opacity: 1; } }
.enc-sheet {
  width: 100%; max-width: 27rem; max-height: 85vh; display: flex; flex-direction: column;
  background: var(--color-bg); border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.16);
  padding: 0.4rem 1.25rem 1.25rem;
}
.enc-sheet-grab { display: none; }
.enc-sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 0.7rem 0 0.5rem; }
.enc-sheet-title { font-size: 1rem; font-weight: 700; color: var(--color-text-primary); }
.enc-sheet-close {
  width: 30px; height: 30px; border-radius: 8px; background: none; border: none;
  color: var(--color-text-muted); display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.14s ease, color 0.14s ease;
}
.enc-sheet-close:hover { background: var(--color-surface); color: #555; }
.enc-sheet-body { overflow-y: auto; }

.enc-set-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.7rem 0; border-top: 1px solid var(--color-border-light); }
.enc-set-label { font-size: 0.92rem; color: var(--color-text-primary); display: flex; flex-direction: column; gap: 2px; }
.enc-set-label small { font-size: 0.74rem; color: var(--color-text-muted); font-weight: 400; max-width: 15rem; }
.enc-set-seg { display: inline-flex; gap: 3px; background: var(--color-surface); border-radius: 9px; padding: 3px; }
.enc-set-segbtn {
  background: none; border: none; color: var(--color-text-secondary);
  border-radius: 7px; padding: 0.3rem 0.7rem; font-size: 0.84rem; font-weight: 600;
  transition: background 0.14s ease, color 0.14s ease;
}
.enc-set-segbtn.is-on { background: var(--color-bg); color: var(--brand); box-shadow: 0 1px 2px rgba(0,0,0,0.1); }
.enc-switch { flex: 0 0 auto; width: 42px; height: 25px; border-radius: 999px; background: var(--color-border); border: none; padding: 0; position: relative; transition: background 0.2s ease; }
.enc-switch.is-on { background: var(--brand); }
.enc-switch i { position: absolute; top: 3px; left: 3px; width: 19px; height: 19px; background: #fff; border-radius: 50%; transition: transform 0.2s ease; }
.enc-switch.is-on i { transform: translateX(17px); }

/* ── Rehab roster (why each word is due) ─────────────────────────────────────── */
.enc-roster-group { margin-top: 0.4rem; }
.enc-roster-grouph {
  display: flex; align-items: center; gap: 7px;
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--color-text-muted); padding: 0.85rem 0.1rem 0.4rem;
}
.enc-roster-groupc { font-variant-numeric: tabular-nums; color: var(--color-text-muted); }
.enc-roster-row {
  width: 100%; display: flex; align-items: center; gap: 11px; text-align: left;
  background: none; border: none; padding: 0.7rem 0.1rem;
  border-top: 1px solid var(--color-border-light);
}
.enc-roster-row:hover { background: var(--color-surface); }
.enc-tier-dot { flex: 0 0 auto; width: 9px; height: 9px; border-radius: 50%; background: var(--color-text-muted); }
.enc-tier-dot.t-leech  { background: var(--color-danger, #cc0000); }
.enc-tier-dot.t-weak   { background: var(--orange); }
.enc-tier-dot.t-stall  { background: color-mix(in oklab, var(--orange) 55%, var(--color-border)); }
.enc-tier-dot.t-manual { background: var(--brand); }
.enc-roster-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.enc-roster-jp { font-family: var(--enc-jp-sans); font-size: 1rem; font-weight: 700; color: var(--color-text-primary); }
.enc-roster-reason { font-size: 0.78rem; color: var(--color-text-secondary); }
.enc-roster-chev { flex: 0 0 auto; width: 15px; height: 15px; stroke: var(--color-text-muted); stroke-width: 2; }

/* ── Per-chapter recap (the hidden targets revealed) ────────────────────────── */
.enc-recap-lead { font-size: 0.86rem; color: var(--color-text-secondary); line-height: 1.5; margin: 0.4rem 0 0.6rem; }
.enc-recap-row {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  background: none; border: none; padding: 0.75rem 0.1rem;
  border-top: 1px solid var(--color-border-light);
}
.enc-recap-row:hover { background: var(--color-surface); }
.enc-recap-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.enc-recap-head { display: flex; align-items: baseline; gap: 8px; }
.enc-recap-jp { font-family: var(--enc-jp-sans); font-size: 1.05rem; font-weight: 700; color: var(--color-text-primary); }
.enc-recap-rd { font-family: var(--paragraph-font-family); font-size: 0.74rem; color: var(--color-text-secondary); }
.enc-recap-en { font-size: 0.82rem; color: var(--color-text-secondary); }
.enc-recap-reason { font-size: 0.75rem; color: var(--color-text-muted); }
.enc-outcome {
  flex: 0 0 auto; align-self: flex-start; font-size: 0.66rem; font-weight: 700;
  border-radius: 999px; padding: 3px 9px; white-space: nowrap;
}
.enc-outcome.is-flagged { color: color-mix(in oklab, var(--orange) 80%, black); background: var(--enc-mark); }
.enc-outcome.is-read { color: var(--brand); background: var(--enc-brand-tint); }

/* ── Word detail bottom sheet (mobile) — wraps the shared DetailContent ──────── */
.enc-detail-host { position: fixed; inset: 0; z-index: 90; pointer-events: none; }
.enc-detail-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.4); opacity: 0; pointer-events: none; transition: opacity 0.22s ease; }
.enc-detail-backdrop.open { opacity: 1; pointer-events: auto; }
.enc-detail-sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: 80vh; max-height: 88vh; overflow: hidden;
  display: flex; flex-direction: column;
  background: var(--color-bg); border-radius: 16px 16px 0 0;
  box-shadow: 0 -10px 40px rgba(0,0,0,0.22);
  transform: translateY(100%); transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
  pointer-events: none; padding-bottom: var(--sab, 20px);
}
/* Grab handle stays fixed; the dictionary's own .detail-scroll takes the slack
   so the action row pins to the bottom instead of scrolling away. */
.enc-detail-sheet .detail-grab,
.enc-detail-sheet .enc-detail-grab { flex: 0 0 auto; }
.enc-detail-sheet .detail-scroll { flex: 1 1 auto; min-height: 0; }
.enc-detail-sheet .detail-actions { flex: 0 0 auto; }
.enc-detail-sheet.open { transform: translateY(0); pointer-events: auto; }
.enc-detail-grab { width: 36px; height: 4px; border-radius: 999px; background: var(--color-border); margin: 8px auto 2px; }
@media (prefers-reduced-motion: reduce) { .enc-detail-sheet { transition: none; } }

/* ── Desktop word detail (Home roster taps) — centered dialog ────────────────── */
.enc-home-detail { position: fixed; inset: 0; z-index: 95; display: flex; align-items: center; justify-content: center; }
.enc-home-detail-scrim { position: absolute; inset: 0; background: rgba(0,0,0,0.4); }
.enc-home-detail-card {
  position: relative; width: 100%; max-width: 30rem; height: 70vh; max-height: 82vh; overflow: hidden;
  display: flex; flex-direction: column;
  background: var(--color-bg); border-radius: 14px; box-shadow: 0 24px 80px rgba(0,0,0,0.32);
}
.enc-home-detail-card .detail-scroll { flex: 1 1 auto; min-height: 0; }
.enc-home-detail-card .detail-actions { flex: 0 0 auto; }

/* ── Mobile: the quietbar owns back / Targets / Flagged / gear, so the top bar
      keeps just a centered "Chapter N" title (no duplicated controls). ───────── */
@media (max-width: 767px) {
  .enc-rtop-back { display: none; }
  .enc-rtop-actions { display: none; }
  .enc-rtop-title { text-align: center; }

  .enc-sheet-wrap { align-items: flex-end; }
  .enc-sheet {
    max-width: none; max-height: 88vh; border-radius: 16px 16px 0 0;
    padding-bottom: calc(var(--sab, 20px) + 1rem);
    box-shadow: 0 -10px 40px rgba(0,0,0,0.22);
    animation: enc-sheet-up 0.26s cubic-bezier(0.4,0,0.2,1);
  }
  .enc-sheet-grab { display: block; width: 36px; height: 4px; border-radius: 999px; background: var(--color-border); margin: 6px auto 2px; }
  @keyframes enc-sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
}

/* ── Desktop: docked aside, no quietbar; top bar owns back + Targets + gear ──── */
@media (min-width: 768px) {
  .enc-quietbar { display: none; }
  .enc-rtop-actions { display: flex; }
  .enc-read-body { max-width: 70rem; margin: 0 auto; width: 100%; }
  .enc-word-panel {
    display: block; flex: 0 0 300px; width: 300px;
    position: sticky; top: 18px; align-self: flex-start;
    padding: 18px 18px 32px 0;
  }
  .enc-wp-list { max-height: 46vh; }
  .enc-detail-host { display: none; }
}
