/* ── Jengo Flashcards — scoped under #flashcard-overlay ─────────────
   Full-viewport overlay launched from the Study tab Flashcards card.
   All rules live under #flashcard-overlay so generic class names
   (.app-header, .study-card, .btn-primary, .session…) won't collide
   with the rest of the app. Tokens come from style.css; flashcard-only
   stops are declared locally below. Demo chrome from the prototype
   (#stage, .device, .frame-*, .desktop-*, .tab-nav, .viewer-*) is
   intentionally dropped — the overlay supplies its own chrome. */

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

  /* Local-only stops. --brand-tint-strong tracks the active theme.
     Stat + rating-row colors are identifiers — never theme them. */
  --brand-tint-strong: color-mix(in oklab, var(--brand) 18%, white);
  --stat-new: #2196f3;
  --stat-learning: #e07b00;
  --stat-review: #2a7a4e;
  --red-soft: #b35454;
  --amber-soft: #c79532; /* saturated 'hard' tone — pairs with --red-soft for rate flashes */

  --header-h: 52px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --jp-font: -apple-system, BlinkMacSystemFont, 'Hiragino Kaku Gothic ProN', 'Yu Gothic', sans-serif;
  --jp-serif: 'Hiragino Mincho ProN', 'Yu Mincho', 'Noto Serif CJK JP', 'Noto Serif JP', serif;
  --ui-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  font-family: var(--ui-font);
}

#flashcard-overlay.open {
  display: block;
  /* Mode-open transition — fade + slight rise (matches the reader overlay). */
  animation: fcOverlayOpen 0.26s cubic-bezier(.2, .7, .2, 1) both;
}
@keyframes fcOverlayOpen {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  #flashcard-overlay.open { animation: none; }
}

/* The Words hub reuses CardBack / EditCardModal under a plain .fc-host, which
   does NOT inherit the flashcard-local custom props declared on #flashcard-overlay
   above. Without them, var()s like --safe-bottom resolve to nothing and their
   calc()s go invalid — e.g. .fc-form-actions loses all padding (cramped, unshaded
   Cancel/Save). Mirror the local stops here so the reused subtree renders identically. */
.fc-host {
  --brand-tint-strong: color-mix(in oklab, var(--brand) 18%, white);
  --stat-new: #2196f3;
  --stat-learning: #e07b00;
  --stat-review: #2a7a4e;
  --red-soft: #b35454;
  --amber-soft: #c79532;
  --header-h: 52px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

:is(#flashcard-overlay, .fc-host) * { box-sizing: border-box; }
:is(#flashcard-overlay, .fc-host) button { margin: 0; font-family: inherit; }

/* App shell fills the overlay (replaces the prototype's .device flex column) */
:is(#flashcard-overlay, .fc-host) #flashcard-mount {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: #fff;
  overflow: hidden;
}
:is(#flashcard-overlay, .fc-host) .fc-app {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ── App header ───────────────────────────────────────── */

:is(#flashcard-overlay, .fc-host) .app-header {
  height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  flex-shrink: 0;
  background: var(--brand-header);
  color: #fff;
  display: flex;
  align-items: center;
  padding-left: 14px;
  padding-right: 14px;
  gap: 10px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
  z-index: 5;
}
:is(#flashcard-overlay, .fc-host) .app-header h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  flex: 1;
  text-align: center;
}
/* Stacked title + today's activity subtitle. Replaces the flat h1 flex slot, so
   the title block owns the centre column between the back and settings buttons. */
:is(#flashcard-overlay, .fc-host) .fc-header-titles {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.15;
}
:is(#flashcard-overlay, .fc-host) .fc-header-titles h1 { flex: none; }
:is(#flashcard-overlay, .fc-host) .fc-today-stat {
  margin-top: 1px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: rgba(255, 255, 255, 0.82);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
:is(#flashcard-overlay, .fc-host) .fc-today-dot { color: rgba(255, 255, 255, 0.5); }
/* Subtitle row: today's activity + the sync indicator, on the brand header.
   Dots are tuned to read on the green header (literal --green would vanish). */
:is(#flashcard-overlay, .fc-host) .fc-header-sub {
  margin-top: 1px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: rgba(255, 255, 255, 0.82);
  max-width: 100%;
}
/* Sync indicator: its own status color so it reads as state, not as the muted
   white metadata (title / today line) beside it. Dot follows the label color via
   currentColor. Colors lightened off the token palette to carry on --brand-header. */
:is(#flashcard-overlay, .fc-host) .fc-sync-status { display: inline-flex; align-items: center; gap: 5px; font-weight: 700; }
:is(#flashcard-overlay, .fc-host) .fc-sync-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
:is(#flashcard-overlay, .fc-host) .fc-sync-status.synced { color: color-mix(in oklab, var(--stat-review) 55%, white); }
:is(#flashcard-overlay, .fc-host) .fc-sync-status.syncing { color: var(--orange); }
:is(#flashcard-overlay, .fc-host) .fc-sync-status.syncing .fc-sync-dot { animation: sync-pulse 1.1s ease-in-out infinite; }
:is(#flashcard-overlay, .fc-host) .fc-sync-status.offline { color: color-mix(in oklab, var(--red-soft) 70%, white); }
:is(#flashcard-overlay, .fc-host) .icon-btn {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.92);
  padding: 8px;
  cursor: pointer;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
:is(#flashcard-overlay, .fc-host) .app-header .icon-btn:hover { background: rgba(255, 255, 255, 0.12); }
:is(#flashcard-overlay, .fc-host) .app-header .icon-btn:disabled { opacity: 0.35; cursor: default; }
:is(#flashcard-overlay, .fc-host) .app-header .icon-btn:disabled:hover { background: transparent; }
:is(#flashcard-overlay, .fc-host) .app-header .icon-btn svg { width: 20px; height: 20px; }
:is(#flashcard-overlay, .fc-host) .header-spacer { width: 36px; flex-shrink: 0; }

/* Labeled chip button (Undo) */
:is(#flashcard-overlay, .fc-host) .icon-btn-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px 5px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.22);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: background 0.12s, opacity 0.12s;
}
:is(#flashcard-overlay, .fc-host) .icon-btn-chip:hover { background: rgba(255, 255, 255, 0.22); }
:is(#flashcard-overlay, .fc-host) .icon-btn-chip:disabled {
  opacity: 0.42;
  cursor: default;
  background: transparent;
  border-color: rgba(255, 255, 255, 0.18);
}
:is(#flashcard-overlay, .fc-host) .icon-btn-chip:disabled:hover { background: transparent; }
:is(#flashcard-overlay, .fc-host) .icon-btn-chip svg { width: 14px; height: 14px; }
/* On phones the "Undo" word widens the left group enough to crowd the centered
   stats pill — drop to an icon-only chip there. */
@media (max-width: 767px) {
  :is(#flashcard-overlay, .fc-host) .icon-btn-chip { padding: 6px; gap: 0; }
  :is(#flashcard-overlay, .fc-host) .icon-btn-chip .chip-label { display: none; }
}

/* Inline stats group inside session header */
:is(#flashcard-overlay, .fc-host) .fc-header-side {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
:is(#flashcard-overlay, .fc-host) .fc-header-right { justify-content: flex-end; }
:is(#flashcard-overlay, .fc-host) .header-stats {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  line-height: 1;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  font-size: 0.92rem;
  font-weight: 700;
  background: rgba(0, 0, 0, 0.22);
  padding: 5px 12px;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
:is(#flashcard-overlay, .fc-host) .header-stats .h-new { color: #8fc8ff; }
:is(#flashcard-overlay, .fc-host) .header-stats .h-learning { color: #ffc278; }
:is(#flashcard-overlay, .fc-host) .header-stats .h-review { color: #9fe2b6; }
:is(#flashcard-overlay, .fc-host) .header-stats .sep { color: rgba(255, 255, 255, 0.55); font-weight: 400; }

/* ── App body ─────────────────────────────────────────── */

:is(#flashcard-overlay, .fc-host) .app-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: #fff;
  position: relative;
}

/* ── Flashcard Home deck list ────────────────────────── */

:is(#flashcard-overlay, .fc-host) .deck-col-header {
  display: flex;
  align-items: center;
  padding: 10px 16px 6px;
  color: var(--color-text-muted);
  font-size: 0.66rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  font-weight: 700;
  border-bottom: 1px solid var(--color-border-light);
}
:is(#flashcard-overlay, .fc-host) .deck-col-header .spacer { flex: 1; }
:is(#flashcard-overlay, .fc-host) .deck-col-header .col { width: 36px; text-align: right; }
:is(#flashcard-overlay, .fc-host) .deck-col-header .col.col-new { color: var(--stat-new); }
:is(#flashcard-overlay, .fc-host) .deck-col-header .col.col-learning { color: var(--stat-learning); }
:is(#flashcard-overlay, .fc-host) .deck-col-header .col.col-review { color: var(--stat-review); }
:is(#flashcard-overlay, .fc-host) .deck-col-header .col-gear { width: 30px; }

:is(#flashcard-overlay, .fc-host) .deck-list {
  display: flex;
  flex-direction: column;
  padding: 8px 0 0;
}
:is(#flashcard-overlay, .fc-host) .deck-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border-light);
  cursor: pointer;
  background: #fff;
  transition: background 0.12s;
}
:is(#flashcard-overlay, .fc-host) .deck-row:hover { background: #fafafa; }
:is(#flashcard-overlay, .fc-host) .deck-row.empty { opacity: 0.55; }
:is(#flashcard-overlay, .fc-host) .deck-row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
:is(#flashcard-overlay, .fc-host) .deck-row-top {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}
:is(#flashcard-overlay, .fc-host) .deck-row-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
:is(#flashcard-overlay, .fc-host) .deck-row-sub {
  font-size: 0.72rem;
  color: var(--color-text-muted);
  letter-spacing: 0.01em;
}

/* Direction chip */
:is(#flashcard-overlay, .fc-host) .dir-chip {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  padding: 1px 6px 2px;
  border-radius: 4px;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  background: var(--color-surface);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
  line-height: 1.4;
}
:is(#flashcard-overlay, .fc-host) .dir-chip .arr { margin: 0 2px; font-weight: 400; opacity: 0.7; }
:is(#flashcard-overlay, .fc-host) .dir-chip.dir-comp { color: #1f6a3e; background: #eaf5ee; border-color: #d2e6da; }
:is(#flashcard-overlay, .fc-host) .dir-chip.dir-prod { color: #8e5400; background: #fbf3e3; border-color: #ecdfc1; }
:is(#flashcard-overlay, .fc-host) .dir-chip.dir-kanji { color: #555; background: var(--color-surface); }

:is(#flashcard-overlay, .fc-host) .deck-stats {
  display: flex;
  gap: 4px;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
:is(#flashcard-overlay, .fc-host) .deck-stat {
  min-width: 28px;
  text-align: right;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 2px 4px;
}
:is(#flashcard-overlay, .fc-host) .deck-stat.s-new { color: var(--stat-new); }
:is(#flashcard-overlay, .fc-host) .deck-stat.s-learning { color: var(--stat-learning); }
:is(#flashcard-overlay, .fc-host) .deck-stat.s-review { color: var(--stat-review); }
:is(#flashcard-overlay, .fc-host) .deck-stat.s-zero { color: #c8c8c8; font-weight: 500; }

:is(#flashcard-overlay, .fc-host) .deck-gear {
  background: none;
  border: none;
  color: var(--color-text-muted);
  padding: 6px;
  cursor: pointer;
  border-radius: 6px;
  display: inline-flex;
  flex-shrink: 0;
}
:is(#flashcard-overlay, .fc-host) .deck-gear:hover { color: var(--color-text-secondary); background: rgba(0, 0, 0, 0.05); }
:is(#flashcard-overlay, .fc-host) .deck-gear svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; display: block; }

:is(#flashcard-overlay, .fc-host) .deck-new-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  margin: 12px auto 20px;
  width: fit-content;
  min-width: 200px;
  border: 1.5px dashed #cfcfcf;
  border-radius: 10px;
  color: var(--color-text-secondary);
  background: transparent;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
}
:is(#flashcard-overlay, .fc-host) .deck-new-row:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-tint); }
:is(#flashcard-overlay, .fc-host) .deck-new-row svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

:is(#flashcard-overlay, .fc-host) .fc-training-entry {
  width: min(760px, calc(100% - 24px));
  margin: 12px auto 4px;
  padding: 12px 13px;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid color-mix(in oklab, var(--brand) 24%, var(--color-border));
  border-radius: 12px;
  background: color-mix(in oklab, var(--brand) 7%, var(--color-bg));
  color: var(--color-text-primary);
  cursor: pointer;
  text-align: left;
}
:is(#flashcard-overlay, .fc-host) .fc-training-entry:hover { background: color-mix(in oklab, var(--brand) 11%, var(--color-bg)); }
:is(#flashcard-overlay, .fc-host) .fc-training-entry-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--brand);
  background: var(--brand-tint);
  flex: none;
}
:is(#flashcard-overlay, .fc-host) .fc-training-entry-icon svg { width: 18px; height: 18px; }
:is(#flashcard-overlay, .fc-host) .fc-training-entry-copy {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
:is(#flashcard-overlay, .fc-host) .fc-training-entry-copy strong { font-size: 0.92rem; }
:is(#flashcard-overlay, .fc-host) .fc-training-entry-copy span { font-size: 0.74rem; color: var(--color-text-muted); }
:is(#flashcard-overlay, .fc-host) .fc-training-entry-cta {
  border-radius: 999px;
  background: var(--brand);
  color: var(--color-bg);
  padding: 6px 12px;
  font-size: 0.82rem;
  font-weight: 700;
}

:is(#flashcard-overlay, .fc-host) .deck-empty-hint {
  padding: 48px 28px;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

/* ── Empty deck-home: import is the primary call to action ───────────── */
:is(#flashcard-overlay, .fc-host) .fc-empty-home {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  max-width: 360px;
  margin: 0 auto;
  padding: 44px 24px 32px;
}
:is(#flashcard-overlay, .fc-host) .fc-empty-home-icon {
  width: 56px; height: 56px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 16px;
  background: var(--brand-tint);
  color: var(--brand);
  margin-bottom: 4px;
}
:is(#flashcard-overlay, .fc-host) .fc-empty-home-icon svg { width: 28px; height: 28px; }
:is(#flashcard-overlay, .fc-host) .fc-empty-home-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--color-text-primary);
}
:is(#flashcard-overlay, .fc-host) .fc-empty-home-sub {
  margin: 0 0 10px;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--color-text-secondary);
}
:is(#flashcard-overlay, .fc-host) .fc-empty-home-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px 18px;
  border: none;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
:is(#flashcard-overlay, .fc-host) .fc-empty-home-cta:hover { opacity: 0.9; }
:is(#flashcard-overlay, .fc-host) .fc-empty-home-cta svg { width: 18px; height: 18px; }
:is(#flashcard-overlay, .fc-host) .fc-empty-home-alt {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 6px 12px;
  border: none;
  background: none;
  color: var(--color-text-secondary);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 8px;
  transition: color 0.15s, background 0.15s;
}
:is(#flashcard-overlay, .fc-host) .fc-empty-home-alt:hover { color: var(--brand); background: var(--brand-tint); }
:is(#flashcard-overlay, .fc-host) .fc-empty-home-alt svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Bottom-of-mode link into the Words hub (Flashcard words). */
:is(#flashcard-overlay, .fc-host) .fc-words-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 100%;
  margin: 4px 0 24px;
  padding: 8px;
  background: none;
  border: none;
  color: var(--color-text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
:is(#flashcard-overlay, .fc-host) .fc-words-link:hover { color: var(--brand); }
:is(#flashcard-overlay, .fc-host) .fc-words-link svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ── Card-template preview (New Deck) ────────────────────────────────── */
:is(#flashcard-overlay, .fc-host) .fc-prev {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin-top: 4px;
  padding: 12px;
  border-radius: 12px;
  background: var(--color-surface, #f6f7f8);
  border: 1px solid var(--color-border-light);
}
:is(#flashcard-overlay, .fc-host) .fc-prev-face {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 62px;
  padding: 8px 6px;
  border-radius: 9px;
  background: #fff;
  border: 1px solid var(--color-border-light);
  text-align: center;
}
:is(#flashcard-overlay, .fc-host) .fc-prev-label {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}
:is(#flashcard-overlay, .fc-host) .fc-prev-text { font-size: 1.05rem; font-weight: 600; color: var(--color-text-primary); }
:is(#flashcard-overlay, .fc-host) .fc-prev-text.is-ja { font-family: var(--jp-font); }
:is(#flashcard-overlay, .fc-host) .fc-prev-arrow {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  color: var(--color-text-muted);
}
:is(#flashcard-overlay, .fc-host) .fc-prev-arrow svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ── Import word-lists sheet ─────────────────────────────────────────── */
:is(#flashcard-overlay, .fc-host) .fc-starter-intro {
  margin: 0 0 14px;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--color-text-secondary);
}
:is(#flashcard-overlay, .fc-host) .fc-starter-opt {
  width: 100%;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}
:is(#flashcard-overlay, .fc-host) .fc-starter-opt.is-sel {
  border-color: var(--brand);
  background: var(--brand-tint);
}
/* Multi-select checkbox: empty rounded box when off, filled brand when on. */
:is(#flashcard-overlay, .fc-host) .fc-starter-check {
  flex-shrink: 0;
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--color-border);
  border-radius: 6px;
  color: #fff;
  transition: background 0.15s, border-color 0.15s;
}
:is(#flashcard-overlay, .fc-host) .fc-starter-check.is-on { background: var(--brand); border-color: var(--brand); }
:is(#flashcard-overlay, .fc-host) .fc-starter-check svg { width: 16px; height: 16px; }

/* Zero to Hero: pinned starter option, visually promoted above the JLPT list. */
:is(#flashcard-overlay, .fc-host) .fc-zero-hero {
  border-color: var(--brand);
  background: var(--brand-tint);
  margin-bottom: 12px;
}
:is(#flashcard-overlay, .fc-host) .fc-zero-hero[disabled] { opacity: 0.6; cursor: default; }
:is(#flashcard-overlay, .fc-host) .fc-zero-hero-badge { background: var(--brand); }
:is(#flashcard-overlay, .fc-host) .fc-zero-hero-badge svg {
  width: 20px; height: 20px; stroke: #fff; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
:is(#flashcard-overlay, .fc-host) .fc-zero-hero-go {
  flex-shrink: 0;
  padding: 0.3rem 0.7rem; border-radius: 999px;
  background: var(--brand); color: #fff;
  font-size: 0.8rem; font-weight: 600;
}
/* "or pick JLPT levels" divider between the pinned starter and the JLPT list. */
:is(#flashcard-overlay, .fc-host) .fc-starter-or {
  display: flex; align-items: center; gap: 0.6rem;
  margin: 0 0 12px;
  font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--color-text-muted);
}
:is(#flashcard-overlay, .fc-host) .fc-starter-or::before,
:is(#flashcard-overlay, .fc-host) .fc-starter-or::after {
  content: ""; flex: 1; height: 1px; background: var(--color-border);
}

/* ── Multi-card session ──────────────────────────────── */

:is(#flashcard-overlay, .fc-host) .session {
  padding: 14px 14px 24px;
  display: grid;
  gap: 10px;
}
:is(#flashcard-overlay, .fc-host) .session.cols-2 { grid-template-columns: 1fr 1fr; }
:is(#flashcard-overlay, .fc-host) .session.cols-3 { grid-template-columns: 1fr 1fr 1fr; }

:is(#flashcard-overlay, .fc-host) .flashrow {
  display: flex;
  align-items: stretch;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 14px;
  overflow: hidden;
  min-height: 72px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  transition: opacity 0.21s ease, transform 0.21s ease;
}
:is(#flashcard-overlay, .fc-host) .flashrow.cleared {
  opacity: 0;
  transform: translateY(-8px) scale(0.97);
  pointer-events: none;
}
:is(#flashcard-overlay, .fc-host) .flashrow.entering {
  animation: fcRowEnter 0.34s cubic-bezier(.2, .7, .2, 1) both;
}
@keyframes fcRowEnter {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
:is(#flashcard-overlay, .fc-host) .flashrow-face {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 12px 16px;
  cursor: pointer;
  min-width: 0;
  gap: 2px;
}
:is(#flashcard-overlay, .fc-host) .flashrow-front {
  font-size: 1.55rem;
  font-weight: 500;
  color: var(--color-text-primary);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--fc-jp-font, var(--jp-font));
}
:is(#flashcard-overlay, .fc-host) .flashrow-front.gloss { font-size: 1.15rem; font-weight: 600; }
:is(#flashcard-overlay, .fc-host) .flashrow-meta {
  font-size: 0.7rem;
  color: var(--color-text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
:is(#flashcard-overlay, .fc-host) .flashrow-meta .pip { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
:is(#flashcard-overlay, .fc-host) .flashrow-meta .pip.new { background: var(--stat-new); }
:is(#flashcard-overlay, .fc-host) .flashrow-meta .pip.learning { background: var(--stat-learning); }
:is(#flashcard-overlay, .fc-host) .flashrow-meta .pip.review { background: var(--stat-review); }

:is(#flashcard-overlay, .fc-host) .flashrow-check {
  flex-shrink: 0;
  width: 72px;
  border: none;
  border-left: 1px solid var(--color-border-light);
  background: transparent;
  color: var(--brand);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s;
}
/* Hover/active only on true pointer devices — on touch these pseudo-states
   stick after a tap and bleed the green tint onto the next card in the slot. */
@media (hover: hover) and (pointer: fine) {
  :is(#flashcard-overlay, .fc-host) .flashrow-check:hover { background: var(--brand-tint); }
  :is(#flashcard-overlay, .fc-host) .flashrow-check:active { background: var(--brand); color: #fff; }
}
:is(#flashcard-overlay, .fc-host) .flashrow-check svg { width: 28px; height: 28px; stroke: currentColor; fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

/* Furigana inline */
:is(#flashcard-overlay, .fc-host) ruby.fc-ruby { display: inline-flex; flex-direction: column-reverse; align-items: center; vertical-align: bottom; line-height: 1; }
:is(#flashcard-overlay, .fc-host) ruby.fc-ruby rt {
  font-size: 0.52em;
  color: var(--color-text-muted);
  line-height: 1.2;
  margin-bottom: 2px;
  font-weight: 400;
}
/* On the reveal, furigana is the answer, not a hint — make it comfortably
   legible and give it room so it never crowds the definition below. */
:is(#flashcard-overlay, .fc-host) .card-back-word ruby.fc-ruby rt {
  font-size: 0.46em;
  margin-bottom: 5px;
  color: var(--color-text-secondary);
}

/* ── Completion state ────────────────────────────────── */

:is(#flashcard-overlay, .fc-host) .completion {
  position: absolute;
  inset: 0;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  text-align: center;
  padding: 64px 28px 32px;
  gap: 12px;
}
:is(#flashcard-overlay, .fc-host) .completion-badge {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--brand-tint);
  color: var(--brand);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 6px;
}
:is(#flashcard-overlay, .fc-host) .completion-badge svg { width: 26px; height: 26px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:is(#flashcard-overlay, .fc-host) .completion h2 { margin: 0; font-size: 1.05rem; font-weight: 600; color: var(--color-text-primary); }
:is(#flashcard-overlay, .fc-host) .completion p { margin: 0; font-size: 0.85rem; color: var(--color-text-secondary); line-height: 1.5; max-width: 280px; }
:is(#flashcard-overlay, .fc-host) .completion-cta-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
  width: 100%;
  max-width: 280px;
}
:is(#flashcard-overlay, .fc-host) .completion-stepper-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--color-text-secondary);
  padding: 8px 0;
}

/* ── Empty state ─────────────────────────────────────── */

:is(#flashcard-overlay, .fc-host) .empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 64px 28px 32px;
  gap: 12px;
}
:is(#flashcard-overlay, .fc-host) .empty-state-icon {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--color-surface);
  color: var(--color-text-muted);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 6px;
}
:is(#flashcard-overlay, .fc-host) .empty-state-icon svg { width: 26px; height: 26px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:is(#flashcard-overlay, .fc-host) .empty-state h3 { margin: 0; font-size: 1.05rem; font-weight: 600; color: var(--color-text-primary); }
:is(#flashcard-overlay, .fc-host) .empty-state p { margin: 0; font-size: 0.85rem; color: var(--color-text-secondary); }
:is(#flashcard-overlay, .fc-host) .empty-state .next-review {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  background: var(--color-surface);
  padding: 6px 12px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

/* ── Buttons ─────────────────────────────────────────── */

:is(#flashcard-overlay, .fc-host) .btn-primary {
  background: var(--brand); color: #fff; border: none;
  border-radius: 8px; padding: 10px 22px;
  font-size: 0.95rem; font-weight: 600; cursor: pointer;
  transition: opacity 0.12s;
}
:is(#flashcard-overlay, .fc-host) .btn-primary:hover { opacity: 0.9; }
:is(#flashcard-overlay, .fc-host) .btn-primary:disabled { opacity: 0.4; cursor: default; }
:is(#flashcard-overlay, .fc-host) .btn-secondary {
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 0.9rem;
  cursor: pointer;
}
:is(#flashcard-overlay, .fc-host) .btn-secondary:hover { background: var(--color-surface); }
:is(#flashcard-overlay, .fc-host) .btn-link {
  background: none; border: none;
  color: var(--brand);
  font-size: 0.88rem; font-weight: 600; cursor: pointer;
  padding: 6px 8px;
}
:is(#flashcard-overlay, .fc-host) .btn-danger {
  background: var(--color-danger);
  color: #fff; border: none;
  border-radius: 8px; padding: 8px 16px;
  font-size: 0.9rem; font-weight: 600; cursor: pointer;
  transition: opacity 0.12s;
}
:is(#flashcard-overlay, .fc-host) .btn-danger:hover { opacity: 0.9; }

/* ==========================================================================
   BATTLEGROUND — redesigned training overlay
   Appendable block for static/flashcard.css. Replaces the v1 `── Battleground
   training` section (lines ~790–1112) and the `.card-train-toggle` rules
   (~1247–1265). All color/space via tokens from docs/DESIGN.md — no hardcoded
   hex. Scope selector matches the app; `.bt-host` is added so the standalone
   prototype resolves the same rules. Drop `.bt-host` when pasting in-app (or
   leave it — it never matches inside the app).
   ========================================================================== */

:is(#flashcard-overlay, .fc-host) .bt-app {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  overflow: hidden;
  position: relative;
}

/* ── Top bar (continuous with the Flashcards header) ─────────────────────── */
:is(#flashcard-overlay, .fc-host) .bt-topbar {
  flex-shrink: 0;
  height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: 12px;
  padding-right: 12px;
  background: var(--brand-header, var(--brand));
  color: var(--color-bg);
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 1px 4px color-mix(in oklab, var(--color-text-primary) 12%, transparent);
  position: relative;
  z-index: 6;
}
:is(#flashcard-overlay, .fc-host) .bt-side {
  flex: 1;
  display: flex;
  align-items: center;
  min-width: 0;
}
:is(#flashcard-overlay, .fc-host) .bt-side.right { justify-content: flex-end; }
:is(#flashcard-overlay, .fc-host) .bt-heading {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 1.02rem;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
:is(#flashcard-overlay, .fc-host) .bt-cardcount {
  font-size: 0.78rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  background: color-mix(in oklab, var(--color-text-primary) 22%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--color-bg) 8%, transparent);
  padding: 4px 10px;
  border-radius: 999px;
}
:is(#flashcard-overlay, .fc-host) .bt-skip {
  background: color-mix(in oklab, var(--color-bg) 14%, transparent);
  color: var(--color-bg);
  border: 1px solid color-mix(in oklab, var(--color-bg) 22%, transparent);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.14s ease, opacity 0.14s ease;
}
:is(#flashcard-overlay, .fc-host) .bt-skip:hover { background: color-mix(in oklab, var(--color-bg) 24%, transparent); }
:is(#flashcard-overlay, .fc-host) .bt-skip:disabled { opacity: 0.35; cursor: default; background: transparent; }
:is(#flashcard-overlay, .fc-host) .bt-iconbtn {
  background: transparent;
  border: none;
  color: color-mix(in oklab, var(--color-bg) 92%, transparent);
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  transition: background 0.14s ease;
}
:is(#flashcard-overlay, .fc-host) .bt-iconbtn:hover { background: color-mix(in oklab, var(--color-bg) 14%, transparent); }
:is(#flashcard-overlay, .fc-host) .bt-iconbtn svg { width: 20px; height: 20px; }

/* ── Stage stepper (Examples · Produce · Feedback) ───────────────────────── */
:is(#flashcard-overlay, .fc-host) .bt-steps {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 16px;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border-light);
  z-index: 5;
}
:is(#flashcard-overlay, .fc-host) .bt-step {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
:is(#flashcard-overlay, .fc-host) .bt-conn { flex: 1; }
:is(#flashcard-overlay, .fc-host) .bt-step-dot {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 800;
  background: var(--color-surface);
  color: var(--color-text-muted);
  border: 1.5px solid var(--color-border);
  transition: background 0.25s ease, color 0.25s ease, border-color 0.25s ease, transform 0.25s cubic-bezier(0.2, 0.7, 0.2, 1);
}
:is(#flashcard-overlay, .fc-host) .bt-step-dot svg { width: 13px; height: 13px; }
:is(#flashcard-overlay, .fc-host) .bt-step-label {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.25s ease;
}
:is(#flashcard-overlay, .fc-host) .bt-step-bar {
  flex: 1;
  height: 2px;
  border-radius: 2px;
  background: var(--color-border);
  min-width: 8px;
  overflow: hidden;
  position: relative;
}
:is(#flashcard-overlay, .fc-host) .bt-step-bar::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: scaleX(0);
  transform-origin: left;
  background: var(--brand);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
:is(#flashcard-overlay, .fc-host) .bt-step.is-done .bt-step-bar::after,
:is(#flashcard-overlay, .fc-host) .bt-step.is-active .bt-step-bar::after { transform: scaleX(1); }
:is(#flashcard-overlay, .fc-host) .bt-step.is-active .bt-step-dot {
  background: var(--brand);
  color: var(--color-bg);
  border-color: var(--brand);
  transform: scale(1.08);
}
:is(#flashcard-overlay, .fc-host) .bt-step.is-active .bt-step-label { color: var(--color-text-primary); }
:is(#flashcard-overlay, .fc-host) .bt-step.is-done .bt-step-dot {
  background: color-mix(in oklab, var(--brand) 14%, var(--color-bg));
  color: var(--brand);
  border-color: color-mix(in oklab, var(--brand) 40%, var(--color-bg));
}
:is(#flashcard-overlay, .fc-host) .bt-step.is-done .bt-step-label { color: var(--color-text-secondary); }

/* ── Scrolling body + stage frame ────────────────────────────────────────── */
:is(#flashcard-overlay, .fc-host) .bt-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--color-bg);
  position: relative;
}
:is(#flashcard-overlay, .fc-host) .bt-stage {
  width: min(680px, 100%);
  min-height: 100%;
  margin: 0 auto;
  padding: 22px 18px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: bt-stage-in 0.34s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
:is(#flashcard-overlay, .fc-host) .bt-stage.back { animation-name: bt-stage-in-back; }

/* ── Target-word hero ────────────────────────────────────────────────────── */
:is(#flashcard-overlay, .fc-host) .bt-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 5px;
  padding: 6px 0 2px;
}
:is(#flashcard-overlay, .fc-host) .bt-kicker {
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}
:is(#flashcard-overlay, .fc-host) .bt-word {
  font-family: var(--jp-serif);
  font-size: clamp(2.2rem, 9vw, 2.9rem);
  line-height: 1.08;
  font-weight: 500;
  color: var(--color-text-primary);
  letter-spacing: 0.01em;
}
:is(#flashcard-overlay, .fc-host) .bt-reading {
  font-family: var(--jp-font);
  color: var(--color-text-secondary);
  font-size: 0.98rem;
  letter-spacing: 0.02em;
}
:is(#flashcard-overlay, .fc-host) .bt-gloss {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  line-height: 1.4;
  max-width: 26rem;
}
:is(#flashcard-overlay, .fc-host) .bt-note {
  margin: -4px auto 2px;
  max-width: 24rem;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

/* ── Example rows ────────────────────────────────────────────────────────── */
:is(#flashcard-overlay, .fc-host) .bt-examples {
  display: flex;
  flex-direction: column;
  gap: 11px;
}
:is(#flashcard-overlay, .fc-host) .bt-ex {
  border: 1px solid var(--color-border-light);
  border-radius: 14px;
  background: var(--color-surface);
  padding: 14px 14px 13px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
  animation: bt-ex-in 0.4s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
:is(#flashcard-overlay, .fc-host) .bt-ex.is-marked {
  border-color: color-mix(in oklab, var(--brand) 22%, var(--color-border));
  background: color-mix(in oklab, var(--brand) 4%, var(--color-surface));
}
:is(#flashcard-overlay, .fc-host) .bt-ex-top {
  display: flex;
  align-items: center;
  gap: 12px;
}
:is(#flashcard-overlay, .fc-host) .bt-ex-jp {
  flex: 1;
  min-width: 0;
  font-family: var(--jp-serif);
  font-size: 1.12rem;
  line-height: 1.7;
  color: var(--color-text-primary);
}

/* ── Furigana + tap-to-look-up (JpText) ──────────────────────────────────── */
:is(#flashcard-overlay, .fc-host) .bt-jp.has-furi { line-height: 2.1; }
:is(#flashcard-overlay, .fc-host) .bt-jp ruby { ruby-align: center; }
:is(#flashcard-overlay, .fc-host) .bt-jp rt {
  font-family: var(--jp-font);
  font-size: 0.52em;
  font-weight: 400;
  color: var(--color-text-muted);
  line-height: 1;
  letter-spacing: 0.02em;
  -webkit-user-select: none;
  user-select: none;
}
:is(#flashcard-overlay, .fc-host) .bt-jp-word {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  margin: 0;
  padding: 0 0.5px;
  cursor: pointer;
  border-radius: 4px;
  text-decoration: underline dotted color-mix(in oklab, var(--color-text-muted) 50%, transparent);
  text-underline-offset: 4px;
  text-decoration-thickness: 1px;
  transition: background 0.13s ease;
  -webkit-tap-highlight-color: transparent;
}
:is(#flashcard-overlay, .fc-host) .bt-jp-word:hover { background: color-mix(in oklab, var(--brand) 12%, transparent); }
:is(#flashcard-overlay, .fc-host) .bt-jp-word:active { background: color-mix(in oklab, var(--brand) 22%, transparent); }

/* Prototype dictionary drawer omitted: in-app word taps open window.JengoDict.openWithQuery. */

/* [ X | ✓ ] — flashcard rating muscle memory (X left, check right). */
:is(#flashcard-overlay, .fc-host) .bt-choice {
  flex: none;
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--color-bg);
}
:is(#flashcard-overlay, .fc-host) .bt-choice-btn {
  width: 48px;
  height: 44px;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: 800;
  font-size: 1.05rem;
  transition: background 0.16s ease, color 0.16s ease, transform 0.12s ease;
}
:is(#flashcard-overlay, .fc-host) .bt-choice-btn svg { width: 19px; height: 19px; }
:is(#flashcard-overlay, .fc-host) .bt-choice-btn + .bt-choice-btn { border-left: 1px solid var(--color-border); }
:is(#flashcard-overlay, .fc-host) .bt-choice-btn:active { transform: scale(0.9); }
:is(#flashcard-overlay, .fc-host) .bt-choice-btn.miss:hover { color: var(--color-danger); background: var(--color-danger-bg); }
:is(#flashcard-overlay, .fc-host) .bt-choice-btn.known:hover { color: var(--brand); background: var(--brand-tint); }
:is(#flashcard-overlay, .fc-host) .bt-choice-btn.miss.on {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  animation: bt-choice-pop 0.28s cubic-bezier(0.2, 0.7, 0.2, 1);
}
:is(#flashcard-overlay, .fc-host) .bt-choice-btn.known.on {
  background: var(--brand);
  color: var(--color-bg);
  animation: bt-choice-pop 0.28s cubic-bezier(0.2, 0.7, 0.2, 1);
}
/* Reveal (translation / explanation) — unlocks with a wipe. */
:is(#flashcard-overlay, .fc-host) .bt-reveal {
  border-top: 1px solid color-mix(in oklab, var(--color-border) 60%, transparent);
  padding-top: 11px;
  display: grid;
  grid-template-rows: 1fr;
  animation: bt-reveal 0.34s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
:is(#flashcard-overlay, .fc-host) .bt-reveal-inner { min-height: 0; overflow: hidden; }
:is(#flashcard-overlay, .fc-host) .bt-translation {
  color: var(--color-text-primary);
  font-size: 0.95rem;
  line-height: 1.5;
}
:is(#flashcard-overlay, .fc-host) .bt-explain {
  margin-top: 7px;
  padding: 9px 11px;
  border-radius: 9px;
  background: var(--color-ai-tint);
  border: 1px solid color-mix(in oklab, var(--color-ai) 20%, transparent);
  color: color-mix(in oklab, var(--color-ai) 65%, var(--color-text-primary));
  font-size: 0.86rem;
  line-height: 1.5;
}

/* ── Production stage ────────────────────────────────────────────────────── */
:is(#flashcard-overlay, .fc-host) .bt-prompt {
  border: 1px solid color-mix(in oklab, var(--color-ai) 22%, var(--color-border));
  border-radius: 14px;
  background: var(--color-ai-tint);
  padding: 15px 16px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
:is(#flashcard-overlay, .fc-host) .bt-prompt-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--color-ai);
}
:is(#flashcard-overlay, .fc-host) .bt-prompt-label svg { width: 13px; height: 13px; }
:is(#flashcard-overlay, .fc-host) .bt-prompt-text {
  font-size: 1.04rem;
  line-height: 1.55;
  color: var(--color-text-primary);
}
:is(#flashcard-overlay, .fc-host) .bt-answer {
  width: 100%;
  min-height: 128px;
  resize: vertical;
  border: 1px solid var(--color-border);
  border-radius: 14px;
  background: var(--color-bg);
  padding: 13px 14px;
  font-family: var(--jp-serif);
  font-size: 1.05rem;
  line-height: 1.6;
  color: var(--color-text-primary);
  transition: border-color 0.15s ease, background 0.15s ease;
}
:is(#flashcard-overlay, .fc-host) .bt-answer::placeholder { color: var(--color-text-muted); font-family: var(--jp-font); }
:is(#flashcard-overlay, .fc-host) .bt-answer:focus {
  outline: none;
  border-color: var(--brand);
  background: var(--brand-tint);
}

/* ── Feedback stage ──────────────────────────────────────────────────────── */
:is(#flashcard-overlay, .fc-host) .bt-verdict {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 15px 16px;
  border-radius: 16px;
  animation: bt-verdict-in 0.42s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
:is(#flashcard-overlay, .fc-host) .bt-verdict.pass {
  background: color-mix(in oklab, var(--brand) 9%, var(--color-bg));
  border: 1px solid color-mix(in oklab, var(--brand) 26%, transparent);
}
:is(#flashcard-overlay, .fc-host) .bt-verdict.retry {
  background: var(--color-ai-tint);
  border: 1px solid color-mix(in oklab, var(--color-ai) 26%, transparent);
}
:is(#flashcard-overlay, .fc-host) .bt-verdict-badge {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-bg);
}
:is(#flashcard-overlay, .fc-host) .bt-verdict.pass .bt-verdict-badge {
  background: var(--brand);
  animation: bt-badge-pop 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
:is(#flashcard-overlay, .fc-host) .bt-verdict.retry .bt-verdict-badge { background: var(--color-ai); }
:is(#flashcard-overlay, .fc-host) .bt-verdict-badge svg { width: 22px; height: 22px; }
:is(#flashcard-overlay, .fc-host) .bt-verdict-badge.draw svg path,
:is(#flashcard-overlay, .fc-host) .bt-verdict-badge.draw svg polyline {
  stroke-dasharray: 26;
  stroke-dashoffset: 26;
  animation: bt-draw 0.5s 0.16s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
:is(#flashcard-overlay, .fc-host) .bt-verdict-title {
  font-size: 1.02rem;
  font-weight: 800;
  letter-spacing: 0.01em;
}
:is(#flashcard-overlay, .fc-host) .bt-verdict.pass .bt-verdict-title { color: var(--brand); }
:is(#flashcard-overlay, .fc-host) .bt-verdict.retry .bt-verdict-title { color: color-mix(in oklab, var(--color-ai) 78%, var(--color-text-primary)); }
:is(#flashcard-overlay, .fc-host) .bt-verdict-sub {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  margin-top: 1px;
}
:is(#flashcard-overlay, .fc-host) .bt-primary-feedback {
  margin: 0;
  font-size: 1.08rem;
  line-height: 1.55;
  color: var(--color-text-primary);
}
:is(#flashcard-overlay, .fc-host) .bt-panel {
  border: 1px solid var(--color-border-light);
  border-radius: 14px;
  background: var(--color-surface);
  padding: 13px 14px;
}
:is(#flashcard-overlay, .fc-host) .bt-panel-label {
  font-size: 0.64rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  font-weight: 800;
  color: var(--color-text-muted);
  margin-bottom: 6px;
}
:is(#flashcard-overlay, .fc-host) .bt-suggested-text {
  font-family: var(--jp-serif);
  font-size: 1.1rem;
  line-height: 1.55;
  color: var(--color-text-primary);
}
:is(#flashcard-overlay, .fc-host) .bt-tips {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
:is(#flashcard-overlay, .fc-host) .bt-tip {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  color: var(--color-text-secondary);
  font-size: 0.9rem;
  line-height: 1.5;
}
:is(#flashcard-overlay, .fc-host) .bt-tip-dot {
  flex: none;
  margin-top: 7px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: color-mix(in oklab, var(--brand) 55%, var(--color-border));
}

/* ── Gaps ────────────────────────────────────────────────────────────────── */
:is(#flashcard-overlay, .fc-host) .bt-gaps {
  display: flex;
  flex-direction: column;
  gap: 9px;
}
:is(#flashcard-overlay, .fc-host) .bt-gap {
  display: flex;
  align-items: center;
  gap: 13px;
  border: 1px solid var(--color-border-light);
  border-radius: 14px;
  background: var(--color-bg);
  padding: 12px 13px;
}
:is(#flashcard-overlay, .fc-host) .bt-gap-word {
  flex: none;
  font-family: var(--jp-serif);
  font-size: 1.4rem;
  font-weight: 500;
  line-height: 1;
  color: var(--color-text-primary);
  min-width: 2.4rem;
}
:is(#flashcard-overlay, .fc-host) .bt-gap-copy {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
:is(#flashcard-overlay, .fc-host) .bt-gap-meaning { font-size: 0.9rem; font-weight: 600; color: var(--color-text-secondary); }
:is(#flashcard-overlay, .fc-host) .bt-gap-evidence { font-size: 0.8rem; color: var(--color-text-muted); line-height: 1.4; }
:is(#flashcard-overlay, .fc-host) .bt-gap-btn {
  flex: none;
  position: relative;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: filter 0.14s ease, transform 0.1s ease;
  border: 1px solid transparent;
}
:is(#flashcard-overlay, .fc-host) .bt-gap-btn svg { width: 14px; height: 14px; }
:is(#flashcard-overlay, .fc-host) .bt-gap-btn:active { transform: scale(0.96); }
:is(#flashcard-overlay, .fc-host) .bt-gap-btn.add { background: var(--green); color: var(--color-bg); }        /* commit → green */
:is(#flashcard-overlay, .fc-host) .bt-gap-btn.add:hover { filter: brightness(1.06); }
:is(#flashcard-overlay, .fc-host) .bt-gap-btn.added {   /* commit done → confirmed */
  background: color-mix(in oklab, var(--green) 12%, var(--color-bg));
  color: var(--green);
  border-color: color-mix(in oklab, var(--green) 34%, transparent);
  cursor: default;
}
:is(#flashcard-overlay, .fc-host) .bt-gap-btn.train {
  background: var(--brand-tint);
  color: var(--brand);
  border-color: color-mix(in oklab, var(--brand) 30%, transparent);
}
:is(#flashcard-overlay, .fc-host) .bt-gap-btn.train:hover { background: color-mix(in oklab, var(--brand) 14%, var(--color-bg)); }
:is(#flashcard-overlay, .fc-host) .bt-gap-btn.train.is-marked { background: var(--brand); color: var(--color-bg); border-color: var(--brand); }
:is(#flashcard-overlay, .fc-host) .bt-gap-btn.train.is-marked:hover { background: var(--brand); filter: brightness(1.05); }
:is(#flashcard-overlay, .fc-host) .bt-gap-btn.next {
  background: var(--color-bg);
  color: var(--color-text-secondary);
  border-color: var(--color-border);
}
:is(#flashcard-overlay, .fc-host) .bt-gap-btn.next:hover { border-color: color-mix(in oklab, var(--color-text-secondary) 40%, var(--color-border)); color: var(--color-text-primary); }
:is(#flashcard-overlay, .fc-host) .bt-gap-btn.done {
  background: transparent;
  color: var(--color-text-muted);
  border-color: var(--color-border);
  cursor: default;
}

/* ── Sticky footer action bar (one primary per stage) ────────────────────── */
:is(#flashcard-overlay, .fc-host) .bt-footer {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--color-bg);
  border-top: 1px solid var(--color-border-light);
  box-shadow: 0 -2px 12px color-mix(in oklab, var(--color-text-primary) 4%, transparent);
}
:is(#flashcard-overlay, .fc-host) .bt-btn {
  flex: 1;
  border: none;
  border-radius: 12px;
  padding: 14px 18px;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity 0.15s ease, filter 0.15s ease, transform 0.1s ease;
}
:is(#flashcard-overlay, .fc-host) .bt-btn svg { width: 18px; height: 18px; }
:is(#flashcard-overlay, .fc-host) .bt-btn:active { transform: translateY(1px); }
:is(#flashcard-overlay, .fc-host) .bt-btn:disabled { opacity: 0.4; cursor: not-allowed; }
:is(#flashcard-overlay, .fc-host) .bt-btn.primary { background: var(--brand); color: var(--color-bg); }
:is(#flashcard-overlay, .fc-host) .bt-btn.primary:not(:disabled):hover { filter: brightness(1.05); }
:is(#flashcard-overlay, .fc-host) .bt-btn.primary.ready:not(:disabled) { animation: bt-ready 0.5s ease; }
:is(#flashcard-overlay, .fc-host) .bt-btn.ai { background: var(--color-ai); color: var(--color-bg); }        /* AI action → amber */
:is(#flashcard-overlay, .fc-host) .bt-btn.ai:not(:disabled):hover { filter: brightness(1.05); }
:is(#flashcard-overlay, .fc-host) .bt-btn.ghost {
  flex: none;
  background: transparent;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}
:is(#flashcard-overlay, .fc-host) .bt-btn.ghost:hover { border-color: color-mix(in oklab, var(--color-text-secondary) 40%, var(--color-border)); color: var(--color-text-primary); }

/* ── Loading / skeletons (amber = AI generating) ─────────────────────────── */
:is(#flashcard-overlay, .fc-host) .bt-genline {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  justify-content: center;
  color: var(--color-ai);
  font-size: 0.86rem;
  font-weight: 600;
}
:is(#flashcard-overlay, .fc-host) .bt-dots { display: inline-flex; gap: 4px; }
:is(#flashcard-overlay, .fc-host) .bt-dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-ai);
  animation: bt-bounce 1.1s infinite ease-in-out both;
}
:is(#flashcard-overlay, .fc-host) .bt-dots i:nth-child(2) { animation-delay: 0.14s; }
:is(#flashcard-overlay, .fc-host) .bt-dots i:nth-child(3) { animation-delay: 0.28s; }
:is(#flashcard-overlay, .fc-host) .bt-skel {
  border: 1px solid var(--color-border-light);
  border-radius: 14px;
  height: 74px;
  background: linear-gradient(100deg, var(--color-surface) 30%, color-mix(in oklab, var(--color-ai) 8%, var(--color-surface)) 50%, var(--color-surface) 70%);
  background-size: 220% 100%;
  animation: bt-shimmer 1.3s infinite linear;
}
:is(#flashcard-overlay, .fc-host) .bt-skel.tall { height: 96px; }
:is(#flashcard-overlay, .fc-host) .bt-spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--color-border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: bt-spin 0.7s linear infinite;
}
:is(#flashcard-overlay, .fc-host) .bt-center {
  min-height: 62vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  color: var(--color-text-secondary);
  font-size: 0.92rem;
}

/* ── Error banner ────────────────────────────────────────────────────────── */
:is(#flashcard-overlay, .fc-host) .bt-error {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--color-danger);
  background: var(--color-danger-bg);
  border: 1px solid var(--color-danger-border);
  border-radius: 12px;
  padding: 11px 13px;
  font-size: 0.9rem;
  line-height: 1.4;
  animation: bt-shake 0.4s ease;
}
:is(#flashcard-overlay, .fc-host) .bt-error svg { width: 18px; height: 18px; flex: none; }
:is(#flashcard-overlay, .fc-host) .bt-retry {
  margin-left: auto;
  flex: none;
  background: var(--color-bg);
  border: 1px solid var(--color-danger-border);
  color: var(--color-danger);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

/* ── Empty / offline full-screen states ──────────────────────────────────── */
:is(#flashcard-overlay, .fc-host) .bt-full {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
  padding: 40px 28px calc(48px + env(safe-area-inset-bottom, 0px));
}
:is(#flashcard-overlay, .fc-host) .bt-full-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  animation: bt-badge-pop 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
:is(#flashcard-overlay, .fc-host) .bt-full-icon.clear { background: color-mix(in oklab, var(--brand) 12%, var(--color-bg)); color: var(--brand); }
:is(#flashcard-overlay, .fc-host) .bt-full-icon.offline { background: var(--color-surface); color: var(--color-text-muted); }
:is(#flashcard-overlay, .fc-host) .bt-full-icon svg { width: 28px; height: 28px; }
:is(#flashcard-overlay, .fc-host) .bt-full h2 { margin: 4px 0 0; font-size: 1.2rem; font-weight: 700; color: var(--color-text-primary); }
:is(#flashcard-overlay, .fc-host) .bt-full p {
  margin: 0 0 6px;
  max-width: 22rem;
  color: var(--color-text-muted);
  font-size: 0.92rem;
  line-height: 1.5;
}
:is(#flashcard-overlay, .fc-host) .bt-full .bt-btn { flex: none; min-width: 160px; }

/* ── Swords mark toggle (flashcard back) — crossed → drawn activation ─────── */
:is(#flashcard-overlay, .fc-host) .card-train-toggle,
:is(#flashcard-overlay, .fc-host) .bt-mark {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid color-mix(in oklab, var(--brand) 26%, var(--color-border));
  border-radius: 999px;
  background: color-mix(in oklab, var(--brand) 7%, var(--color-bg));
  color: var(--brand);
  padding: 6px 12px 6px 10px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  position: relative;
  overflow: visible;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
:is(#flashcard-overlay, .fc-host) .card-train-toggle svg,
:is(#flashcard-overlay, .fc-host) .bt-mark svg,
:is(#flashcard-overlay, .fc-host) .bt-gap-btn svg { width: 15px; height: 15px; overflow: visible; }
:is(#flashcard-overlay, .fc-host) .card-train-toggle .bt-blade,
:is(#flashcard-overlay, .fc-host) .bt-mark .bt-blade,
:is(#flashcard-overlay, .fc-host) .bt-gap-btn .bt-blade { transform-box: fill-box; transform-origin: center; transition: transform 0.35s cubic-bezier(0.2, 0.7, 0.2, 1); }
:is(#flashcard-overlay, .fc-host) .card-train-toggle.is-marked,
:is(#flashcard-overlay, .fc-host) .bt-mark.is-marked {
  background: var(--brand);
  color: var(--color-bg);
  border-color: var(--brand);
}
/* Activation: blades draw apart + settle, chip pulses, spark flashes. */
:is(#flashcard-overlay, .fc-host) .card-train-toggle.is-activating,
:is(#flashcard-overlay, .fc-host) .bt-mark.is-activating,
:is(#flashcard-overlay, .fc-host) .bt-gap-btn.is-activating { animation: bt-mark-pop 0.45s cubic-bezier(0.2, 0.7, 0.2, 1); }
:is(#flashcard-overlay, .fc-host) .is-activating .bt-blade-a { animation: bt-blade-a 0.5s cubic-bezier(0.3, 0.8, 0.3, 1); }
:is(#flashcard-overlay, .fc-host) .is-activating .bt-blade-b { animation: bt-blade-b 0.5s cubic-bezier(0.3, 0.8, 0.3, 1); }
:is(#flashcard-overlay, .fc-host) .bt-spark {
  position: absolute;
  left: 15px;
  top: 50%;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: color-mix(in oklab, var(--orange) 45%, var(--color-bg));
  opacity: 0;
  pointer-events: none;
}
:is(#flashcard-overlay, .fc-host) .is-activating .bt-spark { animation: bt-spark 0.5s ease-out; }

/* ── Keyframes ───────────────────────────────────────────────────────────── */
@keyframes bt-stage-in { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
@keyframes bt-stage-in-back { from { opacity: 0; transform: translateX(-24px); } to { opacity: 1; transform: none; } }
@keyframes bt-ex-in { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes bt-reveal { from { grid-template-rows: 0fr; opacity: 0; } to { grid-template-rows: 1fr; opacity: 1; } }
@keyframes bt-choice-pop { 0% { transform: scale(1); } 45% { transform: scale(1.14); } 100% { transform: scale(1); } }
@keyframes bt-verdict-in { from { opacity: 0; transform: translateY(12px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes bt-badge-pop { 0% { transform: scale(0.4); opacity: 0; } 60% { transform: scale(1.12); opacity: 1; } 100% { transform: scale(1); } }
@keyframes bt-draw { to { stroke-dashoffset: 0; } }
@keyframes bt-ready { 0% { box-shadow: 0 0 0 0 color-mix(in oklab, var(--brand) 40%, transparent); } 100% { box-shadow: 0 0 0 12px color-mix(in oklab, var(--brand) 0%, transparent); } }
@keyframes bt-bounce { 0%, 80%, 100% { transform: translateY(0); opacity: 0.4; } 40% { transform: translateY(-4px); opacity: 1; } }
@keyframes bt-shimmer { to { background-position: -220% 0; } }
@keyframes bt-spin { to { transform: rotate(360deg); } }
@keyframes bt-shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-5px); } 40% { transform: translateX(4px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(2px); } }
@keyframes bt-mark-pop { 0% { transform: scale(1); } 40% { transform: scale(1.09); } 100% { transform: scale(1); } }
@keyframes bt-blade-a { 0% { transform: rotate(0deg); } 35% { transform: rotate(-16deg) translateX(-1px); } 100% { transform: rotate(0deg); } }
@keyframes bt-blade-b { 0% { transform: rotate(0deg); } 35% { transform: rotate(16deg) translateX(1px); } 100% { transform: rotate(0deg); } }
@keyframes bt-spark { 0% { opacity: 0; transform: translate(0, -50%) scale(0.4); } 30% { opacity: 1; transform: translate(0, -50%) scale(1); } 100% { opacity: 0; transform: translate(-8px, -140%) scale(0.3); } }

/* ── Lobby (interim: study landing → begin training → training) ──────────── */
:is(#flashcard-overlay, .fc-host) .bt-lobby {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 14px;
  padding: 40px 28px calc(28px + env(safe-area-inset-bottom, 0px));
  animation: bt-stage-in 0.34s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
:is(#flashcard-overlay, .fc-host) .bt-lobby-emblem {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in oklab, var(--brand) 12%, var(--color-bg));
  color: var(--brand);
  animation: bt-badge-pop 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
:is(#flashcard-overlay, .fc-host) .bt-lobby-emblem svg { width: 32px; height: 32px; }
:is(#flashcard-overlay, .fc-host) .bt-lobby-title {
  margin: 2px 0 0;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  color: var(--color-text-primary);
}
:is(#flashcard-overlay, .fc-host) .bt-lobby-count {
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--brand);
}
:is(#flashcard-overlay, .fc-host) .bt-lobby-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
  margin-top: 2px;
}
:is(#flashcard-overlay, .fc-host) .bt-chip {
  font-family: var(--jp-serif);
  font-size: 1.15rem;
  line-height: 1;
  color: var(--color-text-primary);
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: 10px;
  padding: 7px 11px;
}
/* Visual how-it-works cue (replaces prose): Examples → Write → Feedback */
:is(#flashcard-overlay, .fc-host) .bt-flow {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 14px;
  padding: 12px 8px;
  border-radius: 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
}
:is(#flashcard-overlay, .fc-host) .bt-flow-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 62px;
}
:is(#flashcard-overlay, .fc-host) .bt-flow-ico {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in oklab, var(--brand) 12%, var(--color-bg));
  color: var(--brand);
}
:is(#flashcard-overlay, .fc-host) .bt-flow-ico svg { width: 18px; height: 18px; }
:is(#flashcard-overlay, .fc-host) .bt-flow-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--color-text-secondary);
}
:is(#flashcard-overlay, .fc-host) .bt-flow-arrow {
  color: var(--color-text-muted);
  display: inline-flex;
  opacity: 0.7;
}
:is(#flashcard-overlay, .fc-host) .bt-flow-arrow svg { width: 15px; height: 15px; }

/* ── Settings full-screen overlay (matches Flashcards global settings) ────── */
:is(#flashcard-overlay, .fc-host) .bt-settings {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: var(--color-bg);
  display: flex;
  flex-direction: column;
  animation: bt-settings-in 0.28s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
:is(#flashcard-overlay, .fc-host) .bt-settings-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 18px calc(18px + env(safe-area-inset-bottom, 0px));
}
:is(#flashcard-overlay, .fc-host) .bt-setting {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 0;
  border-bottom: 1px solid var(--color-border-light);
}
:is(#flashcard-overlay, .fc-host) .bt-setting-copy { flex: 1; min-width: 0; }
:is(#flashcard-overlay, .fc-host) .bt-setting-title {
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--color-text-primary);
  margin-bottom: 3px;
}
:is(#flashcard-overlay, .fc-host) .bt-setting-desc {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  line-height: 1.45;
}
:is(#flashcard-overlay, .fc-host) .bt-seg {
  flex: none;
  display: inline-flex;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 11px;
  padding: 3px;
  gap: 3px;
}
:is(#flashcard-overlay, .fc-host) .bt-seg-btn {
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  border-radius: 8px;
  padding: 7px 13px;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}
:is(#flashcard-overlay, .fc-host) .bt-seg-btn.on {
  background: var(--brand);
  color: var(--color-bg);
  box-shadow: 0 1px 3px color-mix(in oklab, var(--color-text-primary) 14%, transparent);
}

@keyframes bt-settings-in { from { transform: translateX(16px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 520px) {
  :is(#flashcard-overlay, .fc-host) .bt-step-label { display: none; }
  :is(#flashcard-overlay, .fc-host) .bt-step { flex: 0 0 auto; }
  :is(#flashcard-overlay, .fc-host) .bt-step:has(.bt-step-bar) { flex: 1; }
  :is(#flashcard-overlay, .fc-host) .bt-gap { flex-wrap: wrap; }
  :is(#flashcard-overlay, .fc-host) .bt-gap-btn { margin-left: auto; }
}

/* ── Reduced motion ──────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  :is(#flashcard-overlay, .fc-host) [class*="bt-"] {
    animation-duration: 0.001ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }
  :is(#flashcard-overlay, .fc-host) .bt-reveal { grid-template-rows: 1fr; opacity: 1; }
  :is(#flashcard-overlay, .fc-host) .bt-verdict-badge.draw svg path,
  :is(#flashcard-overlay, .fc-host) .bt-verdict-badge.draw svg polyline { stroke-dashoffset: 0; }
}

/* ── Single-card modal (bottom sheet on mobile) ──────── */

:is(#flashcard-overlay, .fc-host) .modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(20, 28, 24, 0.42);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 90;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fcOverlayIn 0.18s ease both;
}
@keyframes fcOverlayIn { from { opacity: 0; } to { opacity: 1; } }

:is(#flashcard-overlay, .fc-host) .card-modal {
  background: #fff;
  width: 100%;
  height: 92%;
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.22);
  display: flex;
  flex-direction: column;
  animation: fcModalUp 0.28s cubic-bezier(.2, .7, .2, 1) both;
  overflow: hidden;
  position: relative;
}
@keyframes fcModalUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* Drag handle: affordance for pull-down-to-dismiss (touch only). */
:is(#flashcard-overlay, .fc-host) .card-modal-grabber {
  flex-shrink: 0;
  width: 36px;
  height: 4px;
  margin: 8px auto 4px;
  border-radius: 2px;
  background: var(--color-border);
}

:is(#flashcard-overlay, .fc-host) .card-modal-header {
  height: 44px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 0 8px;
  border-bottom: 1px solid var(--color-border-light);
  position: relative;
}
:is(#flashcard-overlay, .fc-host) .card-modal-header .icon-btn {
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  color: var(--color-text-secondary);
  border-radius: 6px;
  display: inline-flex;
}
:is(#flashcard-overlay, .fc-host) .card-modal-header .icon-btn:hover { background: var(--color-surface); color: var(--color-text-primary); }
:is(#flashcard-overlay, .fc-host) .card-modal-header .icon-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:is(#flashcard-overlay, .fc-host) .card-modal-header .spacer { flex: 1; }

/* Back face (post-reveal) */
:is(#flashcard-overlay, .fc-host) .card-back {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 22px 22px 0;
  overflow-y: auto;
  animation: fcRevealIn 0.22s ease both;
}
@keyframes fcRevealIn { from { opacity: 0; } to { opacity: 1; } }

/* Centered headword block: word + audio, with the POS tag beneath. */
:is(#flashcard-overlay, .fc-host) .card-back-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 20px;
}
:is(#flashcard-overlay, .fc-host) .card-back-word-row { --fc-audio-size: 40px; display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 10px; }
/* Spacer mirrors the audio button's width (shared var, not a duplicated literal)
   so the word stays optically centered with the button to its right. */
:is(#flashcard-overlay, .fc-host) .card-back-word-spacer { width: var(--fc-audio-size); flex-shrink: 0; }
:is(#flashcard-overlay, .fc-host) .card-back-word {
  font-size: 2.6rem;
  font-weight: 500;
  font-family: var(--fc-jp-font, var(--jp-serif));
  color: var(--color-text-primary);
  line-height: 1.12;
}
:is(#flashcard-overlay, .fc-host) .card-back-head .card-pos { align-self: center; margin-bottom: 0; }
:is(#flashcard-overlay, .fc-host) .card-audio-btn {
  width: var(--fc-audio-size, 40px); height: var(--fc-audio-size, 40px);
  border-radius: 50%;
  background: var(--brand-tint);
  color: var(--brand);
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
:is(#flashcard-overlay, .fc-host) .card-audio-btn svg { width: 16px; height: 16px; fill: currentColor; }
:is(#flashcard-overlay, .fc-host) .card-audio-btn:hover { background: var(--brand-tint-strong); }
:is(#flashcard-overlay, .fc-host) .card-audio-btn.is-playing { animation: fcAudioPulse 0.9s ease-in-out infinite; }
@keyframes fcAudioPulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in oklab, var(--brand) 40%, transparent); }
  50% { box-shadow: 0 0 0 5px color-mix(in oklab, var(--brand) 0%, transparent); }
}

:is(#flashcard-overlay, .fc-host) .card-back-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}
:is(#flashcard-overlay, .fc-host) .card-back-pos-stack {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
:is(#flashcard-overlay, .fc-host) .card-pos {
  font-size: 0.7rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--color-surface);
  padding: 2px 8px;
  border-radius: 4px;
  display: inline-block;
}
:is(#flashcard-overlay, .fc-host) .card-leech-tag {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-danger);
  background: var(--color-danger-bg, #fff5f5);
  border: 1px solid color-mix(in oklab, var(--color-danger) 30%, transparent);
  padding: 2px 8px;
  border-radius: 4px;
  display: inline-block;
}
:is(#flashcard-overlay, .fc-host) .card-section-label {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  font-weight: 700;
  margin-bottom: 5px;
}
:is(#flashcard-overlay, .fc-host) .card-def {
  font-size: 1.2rem;
  color: var(--color-text-primary);
  line-height: 1.45;
  margin-bottom: 14px;
}
:is(#flashcard-overlay, .fc-host) .card-def-list {
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
  font-size: 1.2rem;
  color: var(--color-text-primary);
  line-height: 1.5;
}
:is(#flashcard-overlay, .fc-host) .card-def-list li { display: flex; gap: 8px; padding: 2px 0; }
/* Collapse affordance for words with many senses — keeps the reveal scannable. */
:is(#flashcard-overlay, .fc-host) .card-def-more {
  background: none;
  border: none;
  color: var(--brand);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 0 0;
  margin: -8px 0 14px;
  align-self: flex-start;
}
:is(#flashcard-overlay, .fc-host) .card-def-more:hover { text-decoration: underline; }
:is(#flashcard-overlay, .fc-host) .card-def-list li .num {
  color: var(--color-text-muted);
  font-size: 0.82rem;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  padding-top: 3px;
  min-width: 16px;
}
:is(#flashcard-overlay, .fc-host) .card-example-list {
  list-style: none;
  margin: 4px 0 16px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  counter-reset: ex;
}
:is(#flashcard-overlay, .fc-host) .card-example {
  position: relative;
  margin: 0;
  padding: 10px 12px;
  background: var(--color-surface);
  border-radius: 8px;
  font-size: 1rem;
  line-height: 1.55;
  color: var(--color-text-secondary);
  font-family: var(--jp-font);
}
:is(#flashcard-overlay, .fc-host) .card-example .example-jp { display: block; color: var(--color-text-primary); line-height: 1.9; }
/* Tap an example to open the tokenized explorer (lookup per word). */
:is(#flashcard-overlay, .fc-host) .card-example.is-openable { cursor: pointer; transition: background 0.12s ease, border-color 0.12s ease; border: 1px solid transparent; padding-right: 28px; }
:is(#flashcard-overlay, .fc-host) .card-example.is-openable:hover { border-color: var(--color-border); background: var(--brand-tint); }
:is(#flashcard-overlay, .fc-host) .card-example.is-openable::after { content: ""; position: absolute; right: 11px; top: 50%; width: 7px; height: 7px; border-right: 2px solid var(--color-text-muted); border-bottom: 2px solid var(--color-text-muted); transform: translateY(-50%) rotate(-45deg); }
:is(#flashcard-overlay, .fc-host) .card-example .example-en { display: block; font-size: 0.88rem; color: var(--color-text-muted); margin-top: 4px; font-family: var(--ui-font); }
/* Difficulty tag, shown only when a card has more than one example. */
:is(#flashcard-overlay, .fc-host) .card-example-level {
  display: inline-block;
  margin-bottom: 5px;
  font-family: var(--ui-font);
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--color-text-muted);
  background: var(--color-bg, #fff);
}
:is(#flashcard-overlay, .fc-host) .card-example-level.medium { color: var(--brand); background: var(--brand-tint); }
:is(#flashcard-overlay, .fc-host) .card-example-level.advanced { color: var(--color-ai); background: var(--color-ai-tint); }

/* Example-sentence explorer modal: a slide-up sheet hosting the dictionary's
   SentenceExplorer (wrapped in .wd-scope so its overlay-scoped styles apply).
   Fixed + z below the dict overlay (1001) so "go to full entry" stacks on top. */
.fc-ex-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(20, 28, 24, 0.42);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fcOverlayIn 0.18s ease both;
}
.fc-ex-sheet {
  position: relative;
  background: #fff;
  width: 100%;
  max-width: 640px;
  max-height: 88vh;
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.22);
  display: flex;
  flex-direction: column;
  padding: 6px 4px env(safe-area-inset-bottom);
  animation: fcModalUp 0.28s cubic-bezier(.2, .7, .2, 1) both;
  overflow: hidden;
}

/* Rating row */
:is(#flashcard-overlay, .fc-host) .rating-row {
  flex-shrink: 0;
  display: grid;
  gap: 6px;
  padding: 12px 14px calc(14px + var(--safe-bottom));
  border-top: 1px solid var(--color-border-light);
  background: #fff;
}
:is(#flashcard-overlay, .fc-host) .rating-row.r-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }
:is(#flashcard-overlay, .fc-host) .rating-row.r-2 { grid-template-columns: 1fr 1fr; }
:is(#flashcard-overlay, .fc-host) .rate-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 11px 6px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: opacity 0.12s;
}
:is(#flashcard-overlay, .fc-host) .rate-btn:hover { opacity: 0.88; }
:is(#flashcard-overlay, .fc-host) .rate-btn .interval {
  font-size: 0.66rem;
  font-weight: 500;
  opacity: 0.85;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
/* Rating colors are an identifier contract — keep across themes */
:is(#flashcard-overlay, .fc-host) .rate-again { background: #f7e7e7; color: var(--red-soft); }
:is(#flashcard-overlay, .fc-host) .rate-again:hover { background: #f1d8d8; }
:is(#flashcard-overlay, .fc-host) .rate-hard { background: #fbeec6; color: #856015; }
:is(#flashcard-overlay, .fc-host) .rate-hard:hover { background: #f6e3a8; }
:is(#flashcard-overlay, .fc-host) .rate-good { background: var(--brand); color: #fff; }
:is(#flashcard-overlay, .fc-host) .rate-good:hover { background: var(--brand); opacity: 0.92; }
:is(#flashcard-overlay, .fc-host) .rate-easy { background: var(--brand-tint-strong); color: var(--brand); }
:is(#flashcard-overlay, .fc-host) .rate-easy:hover { background: #c8e3d2; }

/* Kebab popover */
/* Card action menu — labelled icon buttons (caution = amber, destructive = red) */
:is(#flashcard-overlay, .fc-host) .kebab-pop {
  /* amber "caution" tones, scoped to this menu (matches the Hard rating chip) */
  --ca-caution-bg: #fbeec6;
  --ca-caution-fg: #856015;
  --ca-caution-hover: #f6e3a8;
  position: absolute;
  right: 8px;
  top: 44px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.16);
  min-width: 224px;
  z-index: 5;
  padding: 7px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
:is(#flashcard-overlay, .fc-host) .kebab-pop .card-action {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--color-surface);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text-primary);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
:is(#flashcard-overlay, .fc-host) .kebab-pop .card-action:hover { background: var(--color-surface-hover); }
:is(#flashcard-overlay, .fc-host) .kebab-pop .ca-icon {
  display: inline-flex;
  flex-shrink: 0;
}
:is(#flashcard-overlay, .fc-host) .kebab-pop .ca-icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
}
/* Compare — AI amber (DESIGN.md: anything AI is amber) */
:is(#flashcard-overlay, .fc-host) .kebab-pop .ca-compare {
  background: var(--color-ai-tint);
  color: var(--color-ai);
}
:is(#flashcard-overlay, .fc-host) .kebab-pop .ca-compare:hover {
  background: color-mix(in oklab, var(--color-ai) 14%, white);
}
/* Suspend — amber caution */
:is(#flashcard-overlay, .fc-host) .kebab-pop .ca-suspend {
  background: var(--ca-caution-bg);
  color: var(--ca-caution-fg);
}
:is(#flashcard-overlay, .fc-host) .kebab-pop .ca-suspend:hover { background: var(--ca-caution-hover); }
/* Delete — destructive red */
:is(#flashcard-overlay, .fc-host) .kebab-pop .ca-delete {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}
:is(#flashcard-overlay, .fc-host) .kebab-pop .ca-delete:hover {
  background: var(--color-danger-hover);
  border-color: var(--color-danger-border);
}
/* Find in dictionary — brand green */
:is(#flashcard-overlay, .fc-host) .kebab-pop .ca-dict {
  background: color-mix(in oklab, var(--brand) 12%, white);
  color: var(--brand);
}
:is(#flashcard-overlay, .fc-host) .kebab-pop .ca-dict:hover {
  background: color-mix(in oklab, var(--brand) 20%, white);
}
/* Rate now — neutral toggle with a chevron pushed to the right edge */
:is(#flashcard-overlay, .fc-host) .kebab-pop .ca-rate .wh-rowchev { margin-left: auto; }
:is(#flashcard-overlay, .fc-host) .kebab-pop .ca-rate .wh-rowchev svg { transition: transform 0.15s ease; }
:is(#flashcard-overlay, .fc-host) .kebab-pop .ca-rate .wh-rowchev.is-open svg { transform: rotate(90deg); }
/* Grade row revealed under "Rate now" — reuses the flashcard RatingRow verbatim
   (same Again/Hard/Good/Easy colors), but stripped of its docked-footer chrome and
   shrunk to fit the narrow popover. */
:is(#flashcard-overlay, .fc-host) .kebab-pop .kebab-rate { display: grid; }
:is(#flashcard-overlay, .fc-host) .kebab-pop .kebab-rate .rating-row {
  padding: 0; border-top: none; background: none; gap: 4px;
}
:is(#flashcard-overlay, .fc-host) .kebab-pop .kebab-rate .rate-btn { padding: 8px 2px; font-size: 0.8rem; }
/* Explain | Compare side-by-side pair — each a compact stacked (icon over label) tile */
:is(#flashcard-overlay, .fc-host) .kebab-pop .kebab-pair { display: flex; gap: 5px; }
:is(#flashcard-overlay, .fc-host) .kebab-pop .ca-pair {
  flex: 1;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  text-align: center;
  padding: 10px 6px;
}

/* Toast */
:is(#flashcard-overlay, .fc-host) .toast {
  position: absolute;
  bottom: 76px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 20, 20, 0.92);
  color: #fff;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.82rem;
  z-index: 10;
  animation: fcToastIn 0.18s ease;
}
@keyframes fcToastIn { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ── Dwell nudge: soft "switch to single" suggestion, top-anchored so it never
   reflows the card grid mid-review. Floats; dismiss = stay this stint. ──── */
:is(#flashcard-overlay, .fc-host) .fc-dwell-nudge {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100% - 24px);
  padding: 8px 8px 8px 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.14);
  z-index: 40;
  animation: fcDwellIn 0.2s ease;
}
:is(#flashcard-overlay, .fc-host) .fc-dwell-text {
  font-size: 0.86rem;
  color: var(--color-text-primary);
  line-height: 1.3;
}
:is(#flashcard-overlay, .fc-host) .fc-dwell-switch {
  flex: none;
  padding: 7px 16px;
  border: none;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
:is(#flashcard-overlay, .fc-host) .fc-dwell-switch:hover { opacity: 0.9; }
:is(#flashcard-overlay, .fc-host) .fc-dwell-close {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  background: none;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: 8px;
}
:is(#flashcard-overlay, .fc-host) .fc-dwell-close:hover { background: var(--color-surface-hover); }
:is(#flashcard-overlay, .fc-host) .fc-dwell-close svg { width: 16px; height: 16px; }
@keyframes fcDwellIn { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }
@media (prefers-reduced-motion: reduce) {
  :is(#flashcard-overlay, .fc-host) .fc-dwell-nudge { animation: none; }
}

/* Scrollbars */
:is(#flashcard-overlay, .fc-host) .app-body::-webkit-scrollbar,
:is(#flashcard-overlay, .fc-host) .card-back::-webkit-scrollbar { width: 6px; }
:is(#flashcard-overlay, .fc-host) .app-body::-webkit-scrollbar-thumb,
:is(#flashcard-overlay, .fc-host) .card-back::-webkit-scrollbar-thumb { background: #d8d8d8; border-radius: 3px; }

/* ── Confirm dialog ──────────────────────────────────── */

:is(#flashcard-overlay, .fc-host) .confirm-overlay {
  position: absolute;
  inset: 0;
  background: rgba(20, 28, 24, 0.5);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fcOverlayIn 0.16s ease both;
}
:is(#flashcard-overlay, .fc-host) .confirm-box {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.24);
  padding: 20px 20px 16px;
  max-width: 320px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: fcConfirmIn 0.18s ease both;
}
@keyframes fcConfirmIn {
  from { opacity: 0; transform: translateY(6px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
:is(#flashcard-overlay, .fc-host) .confirm-title { font-size: 1rem; font-weight: 700; color: var(--color-text-primary); margin: 0; }
:is(#flashcard-overlay, .fc-host) .confirm-body { font-size: 0.88rem; color: var(--color-text-secondary); line-height: 1.5; margin: 0; }
:is(#flashcard-overlay, .fc-host) .confirm-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* ── Stepper ─────────────────────────────────────────── */

:is(#flashcard-overlay, .fc-host) .stepper {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--color-border);
  border-radius: 7px;
  overflow: hidden;
  height: 30px;
  background: #fff;
}
:is(#flashcard-overlay, .fc-host) .stepper button {
  background: none;
  border: none;
  width: 28px;
  cursor: pointer;
  color: var(--color-text-secondary);
  font-size: 1rem;
  font-weight: 600;
  padding: 0;
}
:is(#flashcard-overlay, .fc-host) .stepper button:hover { background: var(--color-surface); }
:is(#flashcard-overlay, .fc-host) .stepper-val {
  min-width: 32px;
  width: 36px;
  padding: 0 4px;
  text-align: center;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
  border-left: 1px solid var(--color-border-light);
  border-right: 1px solid var(--color-border-light);
  border-top: none;
  border-bottom: none;
  background: transparent;
  color: var(--color-text-primary);
  font-family: inherit;
  -moz-appearance: textfield;
}
:is(#flashcard-overlay, .fc-host) .stepper-val::-webkit-outer-spin-button,
:is(#flashcard-overlay, .fc-host) .stepper-val::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
:is(#flashcard-overlay, .fc-host) .stepper-val:focus { outline: none; background: var(--brand-tint); }

/* ── Form modal (New Deck / Edit card) ───────────────── */

:is(#flashcard-overlay, .fc-host) .fc-form-overlay {
  position: absolute;
  inset: 0;
  background: rgba(20, 28, 24, 0.42);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 120;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fcOverlayIn 0.18s ease both;
}
/* Words tab reuses CardBack + EditCardModal outside #flashcard-overlay (the
   :is(…, .fc-host) selectors above style them there). The editor's overlay is
   position:absolute, so it needs a full-screen positioned host that also clears
   the app header/nav + words sheet stack; below the z1000 dict/flash overlays so
   a tap-to-lookup still lands on top. CardBack mounts in a plain .fc-host. */
.fc-host-modal { position: fixed; inset: 0; z-index: 950; }
/* The words host is full-viewport, so unlike #flashcard-overlay (which sits
   inside the already-inset app body) the editor must clear the top status bar
   and the bottom words nav + home-indicator itself. Padding shrinks the
   flex-end overlay's content box, so the box's max-height:92% follows. */
.fc-host-modal .fc-form-overlay {
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: calc(var(--nav-h) + var(--sab));
}
/* Opening the editor hides the words nav (body.nav-hidden), so the reserved
   nav gutter above becomes a dead dimmed strip under the sheet. Sit flush to the
   bottom like the flashcard editor — .fc-form-actions carries the safe-area pad. */
body.nav-hidden .fc-host-modal .fc-form-overlay { padding-bottom: 0; }

:is(#flashcard-overlay, .fc-host) .fc-form-box {
  position: relative;
  background: #fff;
  width: 100%;
  max-height: 92%;
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.22);
  display: flex;
  flex-direction: column;
  animation: fcModalUp 0.28s cubic-bezier(.2, .7, .2, 1) both;
  overflow: hidden;
}
:is(#flashcard-overlay, .fc-host) .fc-form-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border-light);
  flex-shrink: 0;
}
:is(#flashcard-overlay, .fc-host) .fc-form-header h2 { margin: 0; font-size: 1rem; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--color-text-primary); }
:is(#flashcard-overlay, .fc-host) .fc-form-header .icon-btn { color: var(--color-text-secondary); background: none; border: none; padding: 6px; cursor: pointer; border-radius: 6px; display: inline-flex; }
:is(#flashcard-overlay, .fc-host) .fc-form-header .icon-btn:hover { background: var(--color-surface); }
:is(#flashcard-overlay, .fc-host) .fc-form-header .icon-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

:is(#flashcard-overlay, .fc-host) .fc-form-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
:is(#flashcard-overlay, .fc-host) .fc-field { display: flex; flex-direction: column; gap: 6px; }
:is(#flashcard-overlay, .fc-host) .fc-field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
:is(#flashcard-overlay, .fc-host) .fc-field-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
}
:is(#flashcard-overlay, .fc-host) .fc-input,
:is(#flashcard-overlay, .fc-host) .fc-textarea {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.95rem;
  font-family: var(--jp-font);
  color: var(--color-text-primary);
  background: #fff;
}
:is(#flashcard-overlay, .fc-host) .fc-input:focus,
:is(#flashcard-overlay, .fc-host) .fc-textarea:focus { outline: none; border-color: var(--brand); background: var(--brand-tint); }
/* field-sizing:content grows the box to fit its text (no inner scroll); min-height
   keeps an empty floor, resize lets the user still drag it. */
:is(#flashcard-overlay, .fc-host) .fc-textarea { field-sizing: content; resize: vertical; min-height: 54px; line-height: 1.5; }

/* Structured example editor: one row per example (JP + translation), so the
   translation isn't hidden behind a "—" delimiter the user can't discover. */
:is(#flashcard-overlay, .fc-host) .fc-ex-list { display: flex; flex-direction: column; gap: 10px; }
:is(#flashcard-overlay, .fc-host) .fc-ex-row { display: flex; align-items: flex-start; gap: 8px; }
:is(#flashcard-overlay, .fc-host) .fc-ex-fields { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
:is(#flashcard-overlay, .fc-host) .fc-ex-en { font-family: var(--ui-font); font-size: 0.88rem; }
:is(#flashcard-overlay, .fc-host) .fc-ex-remove {
  flex: none; width: 34px; height: 34px; margin-top: 2px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--color-border); border-radius: 8px;
  background: #fff; color: var(--color-text-muted); cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}
:is(#flashcard-overlay, .fc-host) .fc-ex-remove:hover { color: var(--color-danger); border-color: var(--color-danger); }
:is(#flashcard-overlay, .fc-host) .fc-ex-remove svg { width: 16px; height: 16px; }
:is(#flashcard-overlay, .fc-host) .fc-ex-add {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 6px;
  margin-top: 2px; padding: 6px 10px; border: none; background: none;
  color: var(--brand); font-size: 0.85rem; font-weight: 600; cursor: pointer;
}
:is(#flashcard-overlay, .fc-host) .fc-ex-add:hover { text-decoration: underline; }
:is(#flashcard-overlay, .fc-host) .fc-ex-add svg { width: 15px; height: 15px; }

/* Per-field AI generate/improve + suggestion review */
:is(#flashcard-overlay, .fc-host) .fc-field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
:is(#flashcard-overlay, .fc-host) .fc-field-head .fc-field-label { margin-bottom: 0; }
/* Amber = the app's AI indicator (--color-ai). Used for every AI affordance:
   the generate/improve pills and the suggestion box. Green stays for commit
   actions (Accept / Save); neutral for Reject. */
:is(#flashcard-overlay, .fc-host) .fc-field-gen {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--color-ai);
  background: var(--color-ai-tint);
  border: none;
  border-radius: 999px;
  padding: 3px 10px;
  cursor: pointer;
  transition: background 0.12s ease, opacity 0.12s ease;
}
:is(#flashcard-overlay, .fc-host) .fc-field-gen:hover { background: color-mix(in oklab, var(--color-ai) 16%, white); }
:is(#flashcard-overlay, .fc-host) .fc-field-gen:disabled { opacity: 0.45; cursor: default; }
:is(#flashcard-overlay, .fc-host) .fc-field-gen svg { width: 13px; height: 13px; }

/* Accept-all swaps the amber AI button to a green commit action. */
:is(#flashcard-overlay, .fc-host) .fc-ai-btn-header.is-accept {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

:is(#flashcard-overlay, .fc-host) .fc-proposal {
  margin-top: 8px;
  border: 1px solid color-mix(in oklab, var(--color-ai) 35%, white);
  border-radius: 10px;
  background: var(--color-ai-tint);
  padding: 10px 12px;
}
:is(#flashcard-overlay, .fc-host) .fc-proposal-head {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-ai);
  margin-bottom: 6px;
}
:is(#flashcard-overlay, .fc-host) .fc-proposal-head svg { width: 12px; height: 12px; }
:is(#flashcard-overlay, .fc-host) .fc-prop-text { color: var(--color-text-primary); }
:is(#flashcard-overlay, .fc-host) .fc-prop-defs {
  margin: 0;
  padding-left: 18px;
  color: var(--color-text-primary);
}
:is(#flashcard-overlay, .fc-host) .fc-prop-defs li { margin: 2px 0; }
:is(#flashcard-overlay, .fc-host) .fc-prop-ex-row { padding: 3px 0; }
:is(#flashcard-overlay, .fc-host) .fc-prop-ex-jp { display: block; color: var(--color-text-primary); }
:is(#flashcard-overlay, .fc-host) .fc-prop-ex-en {
  display: block;
  color: var(--color-text-muted);
  font-size: 0.82rem;
}
/* Diff highlight — only what differs from the current field, in a stronger
   amber chip so it reads against the pale amber suggestion background. */
:is(#flashcard-overlay, .fc-host) .fc-prop-line.is-changed {
  background: color-mix(in oklab, var(--color-ai) 22%, white);
  border-radius: 4px;
}
:is(#flashcard-overlay, .fc-host) .fc-prop-text.is-changed { padding: 2px 7px; }
:is(#flashcard-overlay, .fc-host) .fc-prop-defs li.is-changed { padding: 1px 7px; }
:is(#flashcard-overlay, .fc-host) .fc-prop-ex-row.is-changed { padding-left: 8px; padding-right: 8px; }
:is(#flashcard-overlay, .fc-host) .fc-proposal-acts {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}
:is(#flashcard-overlay, .fc-host) .fc-prop-accept,
:is(#flashcard-overlay, .fc-host) .fc-prop-reject {
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: 8px;
  padding: 5px 14px;
  cursor: pointer;
  border: 1px solid transparent;
}
:is(#flashcard-overlay, .fc-host) .fc-prop-accept { background: var(--brand); color: #fff; }
:is(#flashcard-overlay, .fc-host) .fc-prop-accept:hover { background: var(--brand-tint-strong); }
:is(#flashcard-overlay, .fc-host) .fc-prop-reject {
  background: transparent;
  color: var(--color-text-muted);
  border-color: var(--color-border);
}
:is(#flashcard-overlay, .fc-host) .fc-prop-reject:hover { color: var(--color-text-primary); }

/* Transient error notification — pinned below the header, auto-fades. */
:is(#flashcard-overlay, .fc-host) .fc-form-toast {
  position: absolute;
  top: calc(var(--header-h) + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  max-width: calc(100% - 32px);
  background: var(--color-danger, #c0392b);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  animation: fcToastIn 0.18s ease both;
}
@keyframes fcToastIn { from { opacity: 0; transform: translate(-50%, -6px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* Global flashcard settings sheet */
:is(#flashcard-overlay, .fc-host) .fc-settings-group {
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: 0.4rem;
}
:is(#flashcard-overlay, .fc-host) .fc-field-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
:is(#flashcard-overlay, .fc-host) .fc-field-hint {
  font-size: 0.78rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--color-text-muted);
}
:is(#flashcard-overlay, .fc-host) .fc-input-num { width: 72px; flex: none; text-align: center; }

/* Auto-create with AI — fills definitions + example from the shared LLM cache */
:is(#flashcard-overlay, .fc-host) .fc-ai-btn {
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid color-mix(in oklab, var(--color-ai) 25%, white);
  background: var(--color-ai-tint);
  color: var(--color-ai);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, opacity 0.12s;
}
:is(#flashcard-overlay, .fc-host) .fc-ai-btn:hover { background: color-mix(in oklab, var(--color-ai) 16%, white); }
:is(#flashcard-overlay, .fc-host) .fc-ai-btn:disabled { opacity: 0.55; cursor: default; }
:is(#flashcard-overlay, .fc-host) .fc-ai-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:is(#flashcard-overlay, .fc-host) .fc-ai-btn.is-busy svg { animation: fcSpin 0.8s linear infinite; }
:is(#flashcard-overlay, .fc-host) .fc-ai-hint {
  font-size: 0.74rem;
  color: var(--color-text-muted);
  text-align: center;
  margin-top: -8px;
  line-height: 1.4;
}
:is(#flashcard-overlay, .fc-host) .fc-ai-hint-err { margin-top: 0; text-align: left; color: var(--color-danger, #c0392b); }
/* Compact header variant of the AI button (top-right of the edit modal). */
:is(#flashcard-overlay, .fc-host) .fc-ai-btn-header {
  width: auto;
  /* Pin the box so the label swap (Auto-create with AI -> Writing...) doesn't
     reflow the header. The shrink under the overlay's backdrop-filter leaves a
     stale paint tile on iOS WKWebView, ghosting the two labels over each other. */
  min-width: 12rem;
  flex-shrink: 0;
  padding: 7px 12px;
  font-size: 0.8rem;
  border-radius: 8px;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
:is(#flashcard-overlay, .fc-host) .fc-ai-btn-header svg { width: 15px; height: 15px; }

/* Template / mode pickers */
:is(#flashcard-overlay, .fc-host) .fc-picker { display: flex; flex-direction: column; gap: 8px; }
:is(#flashcard-overlay, .fc-host) .fc-picker-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--color-text-primary);
  text-align: left;
}
:is(#flashcard-overlay, .fc-host) .fc-picker-opt:hover { background: var(--color-surface); }
:is(#flashcard-overlay, .fc-host) .fc-picker-opt.active { border-color: var(--brand); background: var(--brand-tint); color: var(--brand); font-weight: 600; }
:is(#flashcard-overlay, .fc-host) .fc-picker-opt .fc-picker-opt-sub { display: block; font-size: 0.76rem; color: var(--color-text-muted); font-weight: 400; margin-top: 2px; }

:is(#flashcard-overlay, .fc-host) .seg-inline {
  display: inline-flex;
  background: var(--color-surface);
  border-radius: 7px;
  padding: 2px;
}
:is(#flashcard-overlay, .fc-host) .seg-inline button {
  background: transparent;
  border: none;
  padding: 6px 12px;
  font-size: 0.82rem;
  color: var(--color-text-secondary);
  border-radius: 5px;
  cursor: pointer;
  font-weight: 500;
}
:is(#flashcard-overlay, .fc-host) .seg-inline button.active {
  background: #fff;
  color: var(--color-text-primary);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

/* iOS-style toggle (used inside Edit form) */
:is(#flashcard-overlay, .fc-host) .toggle { position: relative; width: 40px; height: 24px; flex-shrink: 0; }
:is(#flashcard-overlay, .fc-host) .toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
:is(#flashcard-overlay, .fc-host) .toggle-track {
  position: absolute;
  inset: 0;
  background: #d8d8d8;
  border-radius: 12px;
  transition: background 0.18s;
  cursor: pointer;
}
:is(#flashcard-overlay, .fc-host) .toggle-track::before {
  content: '';
  position: absolute;
  width: 20px; height: 20px;
  top: 2px; left: 2px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.18s;
}
:is(#flashcard-overlay, .fc-host) .toggle input:checked + .toggle-track { background: var(--brand); }
:is(#flashcard-overlay, .fc-host) .toggle input:checked + .toggle-track::before { transform: translateX(16px); }

:is(#flashcard-overlay, .fc-host) .fc-form-actions {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  padding: 12px 16px calc(14px + var(--safe-bottom));
  border-top: 1px solid var(--color-border-light);
}
:is(#flashcard-overlay, .fc-host) .fc-form-actions .btn-primary,
:is(#flashcard-overlay, .fc-host) .fc-form-actions .btn-secondary { flex: 1; }

/* ── Loading / error ─────────────────────────────────── */

:is(#flashcard-overlay, .fc-host) .fc-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 64px 20px;
  color: var(--color-text-muted);
  font-size: 0.9rem;
}
:is(#flashcard-overlay, .fc-host) .fc-spinner {
  width: 22px; height: 22px;
  border: 2px solid var(--color-border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: fcSpin 0.7s linear infinite;
  margin-right: 10px;
}
@keyframes fcSpin { to { transform: rotate(360deg); } }

/* ── Deck settings panel ─────────────────────────────── */

:is(#flashcard-overlay, .fc-host) .settings-list { padding: 8px 0 28px; }
:is(#flashcard-overlay, .fc-host) .settings-group-title {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--color-text-muted);
  font-weight: 700;
  padding: 16px 16px 7px;
}
/* Grouped card: related rows read as one set instead of an endless divider list */
:is(#flashcard-overlay, .fc-host) .settings-group-card {
  margin: 0 12px 10px;
  background: #fff;
  border: 1px solid var(--color-border-light);
  border-radius: 12px;
  overflow: hidden;
}
:is(#flashcard-overlay, .fc-host) .settings-group-card .settings-row:not(:last-child) {
  border-bottom: 1px solid var(--color-border-light);
}
:is(#flashcard-overlay, .fc-host) .settings-row {
  display: flex;
  align-items: center;
  padding: 11px 14px;
  gap: 10px;
}
:is(#flashcard-overlay, .fc-host) .settings-row.danger { color: var(--color-danger); }
:is(#flashcard-overlay, .fc-host) .settings-row.danger:hover { background: var(--color-surface); }
/* Full-width control beneath its label (segmented pickers, grids) */
:is(#flashcard-overlay, .fc-host) .settings-row-stack { flex-direction: column; align-items: stretch; gap: 9px; }
:is(#flashcard-overlay, .fc-host) .settings-row-stack-control { width: 100%; }
:is(#flashcard-overlay, .fc-host) .settings-row-stack .seg-inline { width: 100%; }
:is(#flashcard-overlay, .fc-host) .settings-row-stack .seg-inline button { flex: 1; }
:is(#flashcard-overlay, .fc-host) .settings-row-grid { padding: 12px 14px; }

/* Vertical single-select list (OptionList) — used when a segmented control
   would cram too many choices onto one line (e.g. review order). */
:is(#flashcard-overlay, .fc-host) .opt-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--color-border-light);
  border-radius: 9px;
  overflow: hidden;
}
:is(#flashcard-overlay, .fc-host) .opt-list-row {
  -webkit-appearance: none; appearance: none;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 9px 12px;
  cursor: pointer;
  color: var(--color-text-primary);
  transition: background 140ms ease;
}
:is(#flashcard-overlay, .fc-host) .opt-list-row:not(:last-child) {
  border-bottom: 1px solid var(--color-border-light);
}
:is(#flashcard-overlay, .fc-host) .opt-list-row.active {
  background: color-mix(in oklab, var(--brand) 9%, transparent);
}
:is(#flashcard-overlay, .fc-host) .opt-list-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
:is(#flashcard-overlay, .fc-host) .opt-list-label { font-size: 0.88rem; font-weight: 500; }
:is(#flashcard-overlay, .fc-host) .opt-list-row.active .opt-list-label {
  color: var(--brand);
  font-weight: 600;
}
:is(#flashcard-overlay, .fc-host) .opt-list-text small { font-size: 0.72rem; color: var(--color-text-muted); }
:is(#flashcard-overlay, .fc-host) .opt-list-check {
  flex-shrink: 0;
  display: inline-flex;
  color: var(--brand);
}
:is(#flashcard-overlay, .fc-host) .opt-list-check svg { width: 17px; height: 17px; }

/* Easy Days — weekday rows, each a 3-stop snapping slider (Min/Reduced/Normal) */
:is(#flashcard-overlay, .fc-host) .easy-days { width: 100%; display: flex; flex-direction: column; gap: 11px; }
:is(#flashcard-overlay, .fc-host) .easy-days-head,
:is(#flashcard-overlay, .fc-host) .easy-days-row {
  display: grid;
  grid-template-columns: 38px 1fr;
  align-items: center;
  gap: 14px;
}
:is(#flashcard-overlay, .fc-host) .easy-days-cols { display: flex; justify-content: space-between; }
:is(#flashcard-overlay, .fc-host) .easy-days-cols span {
  font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--color-text-muted); font-weight: 700;
}
:is(#flashcard-overlay, .fc-host) .easy-days-day { font-size: 0.8rem; font-weight: 600; color: var(--color-text-secondary); }
:is(#flashcard-overlay, .fc-host) .easy-slider {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px; border-radius: 999px; outline: none; cursor: pointer;
  background: linear-gradient(to right,
    var(--brand) var(--fill, 100%), var(--color-border-light) var(--fill, 100%));
}
:is(#flashcard-overlay, .fc-host) .easy-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--brand); border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); cursor: pointer;
}
:is(#flashcard-overlay, .fc-host) .easy-slider::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--brand); border: 2px solid #fff; cursor: pointer;
}

/* Manual tune action + result note */
:is(#flashcard-overlay, .fc-host) .fc-tune-btn {
  -webkit-appearance: none; appearance: none;
  border: 1px solid var(--brand); background: var(--brand); color: #fff;
  font-size: 0.84rem; font-weight: 600; padding: 7px 14px; border-radius: 8px; cursor: pointer;
}
:is(#flashcard-overlay, .fc-host) .fc-tune-btn:disabled { opacity: 0.6; cursor: default; }
:is(#flashcard-overlay, .fc-host) .settings-advanced-note.is-ok { color: var(--brand); }
:is(#flashcard-overlay, .fc-host) .settings-advanced-note.is-warn { color: var(--color-danger); }
:is(#flashcard-overlay, .fc-host) .settings-row-label {
  flex: 1;
  font-size: 0.92rem;
  color: var(--color-text-primary);
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
:is(#flashcard-overlay, .fc-host) .settings-row-label small { font-size: 0.74rem; color: var(--color-text-muted); font-weight: 400; }
/* Appearance live sample — shows the chosen face + size on a real word. */
:is(#flashcard-overlay, .fc-host) .settings-font-preview {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}
:is(#flashcard-overlay, .fc-host) .fc-font-sample {
  font-family: var(--fc-jp-font, var(--jp-serif));
  font-size: calc(2rem * var(--fc-face-scale, 1));
  line-height: 1.15;
  color: var(--color-text-primary);
}
:is(#flashcard-overlay, .fc-host) .fc-font-sample-en { font-size: 0.74rem; color: var(--color-text-muted); }
:is(#flashcard-overlay, .fc-host) .settings-row-val {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  font-variant-numeric: tabular-nums;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
:is(#flashcard-overlay, .fc-host) .settings-row .chev { color: var(--color-text-muted); display: inline-flex; }
:is(#flashcard-overlay, .fc-host) .settings-row .chev svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
:is(#flashcard-overlay, .fc-host) .settings-name-input { width: auto; max-width: 58%; padding: 7px 10px; font-size: 0.92rem; }

/* Advanced (FSRS) disclosure — an unmistakable button, not a header */
:is(#flashcard-overlay, .fc-host) .settings-group-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: calc(100% - 24px);
  margin: 12px 12px 10px;
  padding: 12px 14px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text-primary);
}
:is(#flashcard-overlay, .fc-host) .settings-group-toggle:hover { border-color: var(--brand); }
:is(#flashcard-overlay, .fc-host) .settings-group-toggle-label { flex: 1; text-align: left; }
:is(#flashcard-overlay, .fc-host) .settings-group-toggle-hint { font-size: 0.78rem; color: var(--color-text-muted); font-weight: 500; }
:is(#flashcard-overlay, .fc-host) .settings-group-toggle .chev { display: inline-flex; transition: transform 0.18s ease; color: var(--color-text-muted); }
:is(#flashcard-overlay, .fc-host) .settings-group-toggle .chev svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
:is(#flashcard-overlay, .fc-host) .settings-group-toggle.open .chev { transform: rotate(90deg); }
:is(#flashcard-overlay, .fc-host) .settings-advanced-note {
  padding: 4px 16px 10px;
  font-size: 0.74rem;
  line-height: 1.4;
  color: var(--color-text-muted);
}
:is(#flashcard-overlay, .fc-host) .fc-steps-input {
  width: auto;
  max-width: 46%;
  padding: 7px 10px;
  font-size: 0.9rem;
  font-family: var(--font-family, inherit);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ── Single-viewer mode ──────────────────────────────── */

:is(#flashcard-overlay, .fc-host) .fc-single-body {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}
:is(#flashcard-overlay, .fc-host) .viewer-front {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  cursor: pointer;
  user-select: none;
  text-align: center;
  gap: 14px;
}
:is(#flashcard-overlay, .fc-host) .viewer-front-word {
  font-size: calc(3rem * var(--fc-face-scale, 1));
  font-weight: 500;
  line-height: 1.15;
  font-family: var(--fc-jp-font, var(--jp-serif));
  color: var(--color-text-primary);
}
:is(#flashcard-overlay, .fc-host) .viewer-front-word.gloss { font-size: 1.9rem; font-weight: 600; font-family: var(--ui-font); }
:is(#flashcard-overlay, .fc-host) .viewer-front-hint {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
:is(#flashcard-overlay, .fc-host) .fc-single-body .card-back { flex: 1; min-height: 0; }
/* Card region: holds flex:1 even when momentarily empty so the rating row below
   stays anchored. Each new card (keyed by id) mounts with a fade-in; the
   outgoing card fades via .is-clearing on the body. */
:is(#flashcard-overlay, .fc-host) .fc-single-card {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  animation: fcSingleIn 0.22s ease both;
}
/* Anki-style rate confirmation: a small tinted dot that pulses once near the top
   of the card, then fades. Just enough to confirm the press registered. */
:is(#flashcard-overlay, .fc-host) .rate-flash {
  position: absolute;
  top: 14px;
  left: 50%;
  width: 11px;
  height: 11px;
  border-radius: 999px;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 6;
  animation: rateFlashPulse 0.6s ease-out forwards;
}
:is(#flashcard-overlay, .fc-host) .rate-flash-again { background: var(--red-soft); }
:is(#flashcard-overlay, .fc-host) .rate-flash-hard { background: var(--amber-soft); }
:is(#flashcard-overlay, .fc-host) .rate-flash-good { background: var(--brand); }
:is(#flashcard-overlay, .fc-host) .rate-flash-easy { background: var(--brand); }
@keyframes rateFlashPulse {
  0% { opacity: 0; transform: translateX(-50%) scale(0.6); }
  25% { opacity: 1; transform: translateX(-50%) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  :is(#flashcard-overlay, .fc-host) .rate-flash { animation-duration: 0.4s; }
}
@keyframes fcSingleIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
:is(#flashcard-overlay, .fc-host) .fc-single-body.is-clearing .fc-single-card {
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.16s ease, transform 0.16s ease;
  animation: none;
}

/* Remaining-count chip next to the stats pill */
:is(#flashcard-overlay, .fc-host) .topbar-counter {
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.74rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
  background: rgba(0, 0, 0, 0.18);
  padding: 4px 10px;
  border-radius: 999px;
  margin-left: 8px;
}

/* Header More button + popover anchor (single view) */
:is(#flashcard-overlay, .fc-host) .fc-header-more { position: relative; display: inline-flex; }
:is(#flashcard-overlay, .fc-host) .fc-header-more .kebab-pop { top: calc(100% + 4px); right: 0; }

/* Keyboard hint footer (desktop single view) */
:is(#flashcard-overlay, .fc-host) .dt-keyhints {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 10px 0 14px;
  font-size: 0.72rem;
  color: var(--color-text-muted);
  letter-spacing: 0.02em;
}
:is(#flashcard-overlay, .fc-host) .dt-keyhints kbd {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.74rem;
  color: var(--color-text-secondary);
  margin-right: 4px;
}

/* ── Desktop refinements ─────────────────────────────── */
@media (min-width: 768px) {
  :is(#flashcard-overlay, .fc-host) .deck-col-header,
  :is(#flashcard-overlay, .fc-host) .deck-list,
  :is(#flashcard-overlay, .fc-host) .session {
    max-width: 760px;
    margin-left: auto;
    margin-right: auto;
  }
  :is(#flashcard-overlay, .fc-host) .deck-new-row { max-width: 760px; margin-left: auto; margin-right: auto; }
  :is(#flashcard-overlay, .fc-host) .fc-words-link { max-width: 760px; margin-left: auto; margin-right: auto; }
  :is(#flashcard-overlay, .fc-host) .fc-empty-home { padding-top: 64px; }

  /* Center the single-card modal as a dialog instead of a bottom sheet */
  :is(#flashcard-overlay, .fc-host) .modal-overlay { align-items: center; padding: 28px; }
  :is(#flashcard-overlay, .fc-host) .card-modal {
    width: 560px;
    max-width: 100%;
    height: auto;
    max-height: 90%;
    border-radius: 14px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.32);
    animation: fcConfirmIn 0.22s cubic-bezier(.2, .7, .2, 1) both;
  }
  :is(#flashcard-overlay, .fc-host) .card-modal-grabber { display: none; }
  :is(#flashcard-overlay, .fc-host) .fc-form-overlay { align-items: center; padding: 28px; }
  :is(#flashcard-overlay, .fc-host) .fc-form-box {
    width: 520px;
    max-width: 100%;
    border-radius: 14px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.32);
    animation: fcConfirmIn 0.22s cubic-bezier(.2, .7, .2, 1) both;
  }

  /* Settings list + single-viewer centered on wide screens */
  :is(#flashcard-overlay, .fc-host) .settings-list { max-width: 640px; margin: 0 auto; }
  :is(#flashcard-overlay, .fc-host) .viewer-front-word { font-size: calc(4.2rem * var(--fc-face-scale, 1)); }
  :is(#flashcard-overlay, .fc-host) .viewer-front-word.gloss { font-size: 2.6rem; }
  :is(#flashcard-overlay, .fc-host) .fc-single-body .viewer-front,
  :is(#flashcard-overlay, .fc-host) .fc-single-body .card-back,
  :is(#flashcard-overlay, .fc-host) .fc-single-body .rating-row { max-width: 640px; width: 100%; margin-left: auto; margin-right: auto; }
}

/* ── Deck identity: icon/color tile + pickers ─────────────────────────
   Unscoped on purpose — the Words hub renders the same DeckTile/pickers
   outside .fc-host. Palette definitions live here (the one allowed hex site,
   like tokens): keys mirror DECK_COLOR_KEYS in flashcard.js. */
:root {
  --deckc-forest: #3e7a52;
  --deckc-ocean: #2f6f8f;
  --deckc-sunset: #d0702e;
  --deckc-plum: #7d5ba6;
  --deckc-sand: #a98844;
  --deckc-slate: #5c6b77;
  --deckc-rose: #c25573;
  --deckc-sky: #4f8fd1;
}
.deck-tile {
  width: 40px; height: 40px; border-radius: 11px;
  display: grid; place-items: center; flex-shrink: 0; color: #fff;
}
.deck-tile svg { width: 20px; height: 20px; }
.deck-tile.is-forest, .deck-ident-swatch.is-forest { background: var(--deckc-forest); }
.deck-tile.is-ocean,  .deck-ident-swatch.is-ocean  { background: var(--deckc-ocean); }
.deck-tile.is-sunset, .deck-ident-swatch.is-sunset { background: var(--deckc-sunset); }
.deck-tile.is-plum,   .deck-ident-swatch.is-plum   { background: var(--deckc-plum); }
.deck-tile.is-sand,   .deck-ident-swatch.is-sand   { background: var(--deckc-sand); }
.deck-tile.is-slate,  .deck-ident-swatch.is-slate  { background: var(--deckc-slate); }
.deck-tile.is-rose,   .deck-ident-swatch.is-rose   { background: var(--deckc-rose); }
.deck-tile.is-sky,    .deck-ident-swatch.is-sky    { background: var(--deckc-sky); }
.deck-ident-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.deck-ident-opt {
  width: 38px; height: 38px; border-radius: 10px; cursor: pointer;
  border: 1.5px solid var(--color-border); background: #fff;
  color: var(--color-text-secondary); display: grid; place-items: center;
  padding: 0;
}
.deck-ident-opt svg { width: 19px; height: 19px; }
.deck-ident-opt.is-on { border-color: var(--brand); color: var(--brand); background: var(--brand-tint); }
.deck-ident-swatch {
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; padding: 0;
  background-clip: padding-box;
}
.deck-ident-swatch.is-on { box-shadow: 0 0 0 2px #fff inset, 0 0 0 2px var(--color-text-primary); }
:is(#flashcard-overlay, .fc-host) .deck-row-sub { display: flex; align-items: center; gap: 7px; }

/* ── Practice mode (re-drill today's cards, no SRS effect) ──────────── */
:is(#flashcard-overlay, .fc-host) .fc-practice-note {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 12px;
  font-size: 0.82rem; font-weight: 600;
  color: var(--brand);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border-light);
}
:is(#flashcard-overlay, .fc-host) .fc-practice-note svg {
  width: 15px; height: 15px; stroke: currentColor; fill: none;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round;
}
:is(#flashcard-overlay, .fc-host) .fc-practice-link {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 10px;
}
:is(#flashcard-overlay, .fc-host) .fc-practice-link svg {
  width: 15px; height: 15px; stroke: currentColor; fill: none;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round;
}
:is(#flashcard-overlay, .fc-host) .deck-practice { color: var(--brand); }

/* Practice pool chooser — bottom sheet (reuses modal-overlay animation feel) */
:is(#flashcard-overlay, .fc-host) .fc-sheet-overlay {
  position: absolute; inset: 0;
  background: rgba(20, 28, 24, 0.42);
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
  z-index: 95;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fcOverlayIn 0.18s ease both;
}
:is(#flashcard-overlay, .fc-host) .fc-sheet {
  background: #fff; width: 100%;
  border-top-left-radius: 18px; border-top-right-radius: 18px;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.22);
  padding: 0 18px 24px;
  animation: fcModalUp 0.28s cubic-bezier(.2, .7, .2, 1) both;
}
:is(#flashcard-overlay, .fc-host) .fc-sheet-grabber {
  width: 36px; height: 4px; margin: 8px auto 6px;
  border-radius: 2px; background: var(--color-border);
}
:is(#flashcard-overlay, .fc-host) .fc-sheet-title {
  margin: 6px 0 14px; font-size: 1.05rem; font-weight: 700;
  color: var(--color-text-primary); text-align: center;
}
:is(#flashcard-overlay, .fc-host) .fc-sheet-opt {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  width: 100%; text-align: left;
  padding: 13px 15px; margin-bottom: 10px;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: 12px; cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
:is(#flashcard-overlay, .fc-host) .fc-sheet-opt:hover { background: var(--color-surface-hover); border-color: var(--brand); }
:is(#flashcard-overlay, .fc-host) .fc-sheet-opt strong { font-size: 0.95rem; font-weight: 600; color: var(--color-text-primary); }
:is(#flashcard-overlay, .fc-host) .fc-sheet-opt span { font-size: 0.82rem; color: var(--color-text-secondary); }
:is(#flashcard-overlay, .fc-host) .fc-sheet-note {
  margin: 4px 2px 0; font-size: 0.78rem; color: var(--color-text-muted); text-align: center;
}
