/* ==========================================================================
   五分典 FiveIdioms — 溫潤宣紙 × 松煙墨 × 硃砂印泥紅 設計系統
   支援三種高對比視覺主題：paper (日間宣紙) / dark (夜間護眼) / eink (電子紙)
   ========================================================================== */

:root,
[data-theme="paper"] {
  --bg: #f9f7f2;
  --bg-subtle: #f1ede3;
  --surface: #ffffff;
  --surface-raised: #fffdf9;
  --border: #e3ddd0;
  --border-strong: #c8bfb0;

  --ink: #1a2128;
  --ink-secondary: #485460;
  --ink-muted: #5d6a76;

  --accent: #9e2a2b;
  --accent-hover: #7f2021;
  --accent-soft: #faecec;
  --accent-ink: #ffffff;

  --warm: #9a5414;
  --warm-soft: #fbf0e3;

  --ok: #1d7446;
  --ok-soft: #e5f5ec;
  --danger: #b8332a;
  --danger-soft: #fceae8;

  --shadow-sm: 0 1px 2px rgba(26, 33, 40, 0.05);
  --shadow-md: 0 8px 24px rgba(26, 33, 40, 0.07);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --nav-height: 68px;
  --font-sans: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
  --font-serif: "Noto Serif TC", "Songti TC", "PMingLiU", serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, monospace;
}

[data-theme="dark"] {
  --bg: #121519;
  --bg-subtle: #1a2026;
  --surface: #1d242b;
  --surface-raised: #242d36;
  --border: #2f3b46;
  --border-strong: #465766;

  --ink: #f3efe7;
  --ink-secondary: #c5ced6;
  --ink-muted: #9eb0be;

  --accent: #e06b65;
  --accent-hover: #ec827d;
  --accent-soft: rgba(224, 107, 101, 0.17);
  --accent-ink: #160a0a;

  --warm: #e6a15c;
  --warm-soft: rgba(230, 161, 92, 0.16);

  --ok: #46c982;
  --ok-soft: rgba(70, 201, 130, 0.16);
  --danger: #f06e65;
  --danger-soft: rgba(240, 110, 101, 0.18);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 12px 28px rgba(0, 0, 0, 0.36);
}

[data-theme="eink"] {
  --bg: #ffffff;
  --bg-subtle: #f4f4f4;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --border: #111111;
  --border-strong: #000000;

  --ink: #000000;
  --ink-secondary: #111111;
  --ink-muted: #222222;

  --accent: #000000;
  --accent-hover: #222222;
  --accent-soft: #eaeaea;
  --accent-ink: #ffffff;

  --warm: #000000;
  --warm-soft: #ededed;

  --ok: #000000;
  --ok-soft: #e6e6e6;
  --danger: #000000;
  --danger-soft: #e0e0e0;

  --shadow-sm: none;
  --shadow-md: none;
}

[data-theme="eink"] *,
[data-theme="eink"] *::before,
[data-theme="eink"] *::after {
  animation: none !important;
  transition: none !important;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 16px);
}

a {
  color: var(--accent);
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

/* ==================== Topbar ==================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.topbar-inner {
  max-width: 780px;
  margin: 0 auto;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-icon {
  border-radius: 9px;
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-title {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: 0.03em;
}

.brand-sub {
  font-size: 0.72rem;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.ctrl-pill {
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.ctrl-pill:hover {
  border-color: var(--accent);
}

/* ==================== In-App Browser Banner ==================== */
.inapp-banner {
  max-width: 780px;
  margin: 10px auto 0;
  padding: 12px 14px;
  background: var(--warm-soft);
  border: 1px solid var(--warm);
  border-radius: var(--radius-md);
  color: var(--ink);
  font-size: 0.88rem;
}

.inapp-banner-actions {
  margin-top: 8px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ==================== Main Container ==================== */
.app-main {
  max-width: 780px;
  margin: 0 auto;
  padding: 14px;
}

.view-panel {
  display: none;
}

.view-panel.active {
  display: block;
}

/* ==================== Cards & Surfaces ==================== */
.card,
.hero-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

.hero-card {
  background: var(--surface-raised);
  box-shadow: var(--shadow-md);
}

.hero-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.hero-greeting {
  margin: 0 0 4px;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--accent);
}

.hero-heading {
  margin: 0;
  font-size: 1.42rem;
  font-weight: 800;
  line-height: 1.25;
}

.hero-desc {
  margin: 4px 0 0;
  font-size: 0.84rem;
  color: var(--ink-muted);
}

.streak-badge {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  text-align: center;
  min-width: 68px;
  flex-shrink: 0;
}

.streak-num {
  display: block;
  font-size: 1.45rem;
  font-weight: 800;
  line-height: 1.1;
}

.streak-lbl {
  font-size: 0.72rem;
  font-weight: 700;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.kpi-box {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px;
  text-align: center;
}

.kpi-val {
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1.2;
}

.kpi-lbl {
  font-size: 0.76rem;
  color: var(--ink-muted);
  margin-top: 2px;
}

.goal-bar-wrap {
  margin-top: 14px;
}

.goal-bar-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  margin-bottom: 6px;
}

.progress-track {
  height: 9px;
  border-radius: 999px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s ease;
}

/* ==================== Chips & Buttons ==================== */
.scope-strip {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 12px 0 4px;
  scrollbar-width: none;
}

.scope-strip::-webkit-scrollbar {
  display: none;
}

.chip {
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-secondary);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}

.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  transition: all 0.15s;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
}

.btn:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-danger {
  border-color: var(--danger);
  color: var(--danger);
}

.btn-sm {
  padding: 6px 11px;
  font-size: 0.82rem;
}

/* ==================== Home Mode Grid ==================== */
.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 12px;
}

@media (max-width: 560px) {
  .mode-grid {
    grid-template-columns: 1fr;
  }
}

.mode-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: transform 0.12s, border-color 0.15s, box-shadow 0.15s;
}

.mode-btn:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.mode-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.mode-btn.primary .mode-sub {
  color: rgba(255, 255, 255, 0.86);
}

[data-theme="dark"] .mode-btn.primary .mode-sub {
  color: rgba(22, 10, 10, 0.82);
}

.mode-ico {
  font-size: 1.55rem;
  flex-shrink: 0;
}

.mode-name {
  display: block;
  font-size: 1rem;
  font-weight: 800;
}

.mode-sub {
  display: block;
  font-size: 0.78rem;
  color: var(--ink-muted);
  margin-top: 2px;
}

/* ==================== Section Headers & Levels ==================== */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.section-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
}

.section-meta {
  font-size: 0.78rem;
  color: var(--ink-muted);
}

.level-list {
  display: grid;
  gap: 10px;
}

.level-row {
  display: grid;
  gap: 5px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  cursor: pointer;
}

.level-row:hover {
  border-color: var(--accent);
}

.level-row-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.86rem;
}

.stage-tag {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--accent);
  margin-left: 6px;
}

/* ==================== Trends Card ==================== */
.trends-summary {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
}

.trends-metrics {
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 12px;
}

.trends-metric {
  text-align: center;
}

.trends-total-num {
  display: block;
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--accent);
}

.trends-total-lbl {
  font-size: 0.76rem;
  color: var(--ink-muted);
}

.trends-divider {
  width: 1px;
  height: 30px;
  background: var(--border-strong);
}

.trends-summary-foot {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.trends-tabs {
  display: flex;
  gap: 6px;
}

.trends-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.trend-pill {
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
}

.trend-pill:hover {
  border-color: var(--accent);
}

.trend-pill small {
  color: var(--ink-muted);
  margin-left: 4px;
  font-weight: 600;
}

/* ==================== Attribution Box ==================== */
.attribution-box p {
  margin: 6px 0;
  font-size: 0.82rem;
  color: var(--ink-secondary);
}

/* ==================== Quiz Stage (Cloze & Disc) ==================== */
.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.quiz-progress-text {
  font-weight: 800;
  font-size: 0.94rem;
}

.question-card {
  margin-top: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 18px;
  box-shadow: var(--shadow-sm);
}

.stage-pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  margin-bottom: 12px;
}

.question-sentence {
  font-size: 1.24rem;
  font-weight: 700;
  line-height: 1.75;
  margin: 0;
  letter-spacing: 0.02em;
}

.blank-slot {
  display: inline-block;
  min-width: 5.2em;
  text-align: center;
  border-bottom: 3px dashed var(--accent);
  color: var(--accent);
  font-weight: 800;
  padding: 0 6px;
  margin: 0 3px;
}

.blank-slot.filled {
  border-bottom-style: solid;
  background: var(--accent-soft);
  border-radius: 6px 6px 0 0;
}

.xy-spotlight {
  font-family: var(--font-serif);
  font-size: 2.1rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-align: center;
  margin: 10px 0 8px;
}

.xy-spotlight .hl-char {
  color: var(--accent);
  background: var(--accent-soft);
  border: 2px solid var(--accent);
  border-radius: 10px;
  padding: 0 6px;
}

.question-subhint {
  margin: 10px 0 0;
  font-size: 0.86rem;
  color: var(--ink-muted);
}

.question-tools {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.kbd-hint {
  font-size: 0.74rem;
  color: var(--ink-muted);
}

.choices-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 14px;
}

@media (max-width: 520px) {
  .choices-grid {
    grid-template-columns: 1fr;
  }
}

.choice-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 14px 14px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: all 0.14s;
}

.choice-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--bg-subtle);
}

.choice-btn:disabled {
  cursor: default;
}

.choice-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--ink-secondary);
  flex-shrink: 0;
}

.choice-body {
  min-width: 0;
  flex: 1;
}

.choice-label {
  display: block;
  font-size: 1.12rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.choice-meta {
  display: block;
  font-size: 0.78rem;
  color: var(--ink-muted);
  margin-top: 2px;
}

.choice-btn.is-correct {
  border-color: var(--ok);
  background: var(--ok-soft);
}

.choice-btn.is-correct .choice-key {
  background: var(--ok);
  border-color: var(--ok);
  color: #fff;
}

.choice-btn.is-wrong {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.choice-btn.is-wrong .choice-key {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

/* ==================== Reveal Detail Card ==================== */
.reveal-card {
  margin-top: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

.verdict-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.verdict-pill {
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 800;
}

.verdict-pill.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.verdict-pill.wrong {
  background: var(--danger-soft);
  color: var(--danger);
}

.idiom-head-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.idiom-title-lg {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.idiom-zhuyin {
  font-size: 0.92rem;
  color: var(--accent);
  font-weight: 700;
  margin-top: 2px;
}

.idiom-pinyin {
  font-size: 0.8rem;
  color: var(--ink-muted);
  margin-left: 8px;
}

.tone-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 800;
}

.tone-badge.pos {
  background: var(--ok-soft);
  color: var(--ok);
}

.tone-badge.neg {
  background: var(--danger-soft);
  color: var(--danger);
}

.detail-block {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}

.detail-label {
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--ink-muted);
  margin-bottom: 4px;
}

.detail-text {
  margin: 0;
  font-size: 0.94rem;
  white-space: pre-line;
}

.callout-warn {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--warm-soft);
  border: 1px solid var(--warm);
  font-size: 0.9rem;
}

.callout-disc {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  font-size: 0.88rem;
}

.disc-case-list {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
}

.disc-case-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 0.86rem;
}

.rel-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.rel-chip {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  font-size: 0.82rem;
  font-weight: 700;
}

.rel-chip.clickable {
  cursor: pointer;
  border-color: var(--accent);
  color: var(--accent);
  background: var(--surface);
}

.story-details {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
}

.story-details summary {
  font-weight: 800;
  font-size: 0.88rem;
  cursor: pointer;
}

.story-details p {
  margin: 8px 0 0;
  font-size: 0.88rem;
  color: var(--ink-secondary);
  white-space: pre-line;
}

.next-action-bar {
  margin-top: 16px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* ==================== Summary & Empty ==================== */
.summary-box {
  margin-top: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 18px;
  text-align: center;
}

.summary-score {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--accent);
}

.summary-mistakes {
  text-align: left;
  margin-top: 14px;
  display: grid;
  gap: 8px;
}

/* ==================== Commute Mode ==================== */
.commute-stage {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 18px;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.commute-word {
  font-family: var(--font-serif);
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  margin: 8px 0 4px;
}

.commute-step-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 800;
}

.commute-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
}

.commute-play-btn {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 1.5rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--shadow-md);
}

/* ==================== Library & Sync ==================== */
.search-input {
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 0.95rem;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
}

.idiom-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.idiom-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  width: 100%;
}

.idiom-row:hover {
  border-color: var(--accent);
}

.idiom-row-title {
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
}

.idiom-row-zy {
  font-size: 0.78rem;
  color: var(--accent);
  margin-left: 6px;
}

.idiom-row-sem {
  font-size: 0.84rem;
  color: var(--ink-secondary);
  margin-top: 3px;
}

.idiom-badges {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
  flex-shrink: 0;
}

.mini-badge {
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--ink-secondary);
}

.mini-badge.disc {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.mini-badge.xy {
  background: var(--warm-soft);
  border-color: var(--warm);
  color: var(--warm);
}

.mini-badge.mistake {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

.mini-badge.mastered {
  background: var(--ok-soft);
  border-color: var(--ok);
  color: var(--ok);
}

.sync-code-box {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  padding: 10px 12px;
  background: var(--bg-subtle);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  margin: 8px 0;
  word-break: break-all;
}

/* ==================== Bottom Navigation ==================== */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 45;
  height: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  max-width: 100%;
}

.nav-item {
  border: none;
  background: transparent;
  color: var(--ink-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  font-size: 0.74rem;
  font-weight: 700;
}

.nav-item .nav-ico {
  font-size: 1.25rem;
  line-height: 1;
}

.nav-item.active {
  color: var(--accent);
}

/* ==================== Modal ==================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(15, 20, 26, 0.58);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-dialog {
  width: min(640px, 100%);
  max-height: 86dvh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-md);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.modal-title {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 800;
}

.license-pre {
  white-space: pre-wrap;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 0.8rem;
  line-height: 1.55;
  overflow-x: auto;
}

/* ==================== Screen Code Debug Badge & Catalog ==================== */
.screen-badge {
  position: fixed;
  z-index: 95;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  color: var(--ink);
  border: 2px solid var(--accent);
  border-radius: 999px;
  padding: 4px 8px;
  box-shadow: var(--shadow-md);
  font-size: 0.74rem;
  max-width: calc(100vw - 20px);
}

.screen-badge.pos-bl { left: 10px; bottom: calc(var(--nav-height) + 12px); }
.screen-badge.pos-tl { left: 10px; top: 64px; }
.screen-badge.pos-tr { right: 10px; top: 64px; }
.screen-badge.pos-br { right: 10px; bottom: calc(var(--nav-height) + 12px); }

.screen-badge-main {
  border: none;
  background: transparent;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 2px 4px;
  text-align: left;
}

.screen-badge-code {
  font-family: var(--font-mono);
  font-weight: 800;
  color: var(--accent);
}

.screen-badge-name {
  font-weight: 700;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.screen-badge-meta {
  color: var(--ink-muted);
  font-size: 0.68rem;
}

.screen-badge-btn {
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  border-radius: 999px;
  padding: 2px 6px;
  cursor: pointer;
  font-size: 0.72rem;
}

.screen-catalog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 99;
  background: rgba(0, 0, 0, 0.58);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.screen-catalog-dialog {
  width: min(760px, 100%);
  max-height: 86dvh;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.screen-catalog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.screen-catalog-body {
  overflow-y: auto;
  display: grid;
  gap: 6px;
}

.screen-catalog-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-subtle);
}

.screen-catalog-row.is-current {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.screen-row-code {
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 0.78rem;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--surface);
  color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.screen-row-name {
  font-weight: 700;
  font-size: 0.88rem;
}

.screen-row-target {
  font-size: 0.76rem;
  color: var(--ink-muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + 18px);
  transform: translateX(-50%);
  z-index: 98;
  background: var(--ink);
  color: var(--bg);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 700;
  display: none;
}

.toast.show {
  display: block;
}
