/* ═══════════════════════════════════════════════════════
   Folio — Editorial Atelier Theme
   A warm light interface with serif/sans typographic contrast,
   colored section borders, and generous editorial whitespace.
   ═══════════════════════════════════════════════════════ */

/* ── Design Tokens ── */
:root {
  /* Surfaces — warm cream to clean white */
  --bg: #F6F4F0;
  --bg-hero: linear-gradient(168deg, #F9F7F3 0%, #EDE9E3 48%, #F4F1EC 100%);
  --surface-0: #FFFFFF;
  --surface-1: #FAFAF8;
  --surface-2: #F2F0EC;
  --surface-3: #EAE7E2;
  --surface-hover: #F0EDE8;
  --surface-code: #2C2A2A;

  /* Text — rich ink tones */
  --ink: #1A1816;
  --ink-secondary: #5C5650;
  --ink-tertiary: #908880;
  --ink-placeholder: #B8B0A8;
  --ink-inverse: #FAFAF8;

  /* Primary accent — deep teal */
  --accent: #1A7A6D;
  --accent-light: #2AA393;
  --accent-soft: rgba(26, 122, 109, 0.08);
  --accent-softer: rgba(26, 122, 109, 0.04);
  --accent-border: rgba(26, 122, 109, 0.2);

  /* Secondary — warm coral */
  --coral: #D4654A;
  --coral-soft: rgba(212, 101, 74, 0.08);
  --coral-border: rgba(212, 101, 74, 0.18);

  /* Semantic */
  --success: #2D8F6F;
  --success-soft: rgba(45, 143, 111, 0.08);
  --success-border: rgba(45, 143, 111, 0.2);
  --warn: #C2882A;
  --warn-soft: rgba(194, 136, 42, 0.08);
  --warn-border: rgba(194, 136, 42, 0.2);
  --danger: #C44B4B;
  --danger-soft: rgba(196, 75, 75, 0.07);
  --danger-border: rgba(196, 75, 75, 0.18);

  /* Section accent colors — editorial rainbow */
  --section-douban: #C2882A;
  --section-drama: #1A7A6D;
  --section-basics: #3B6BB5;
  --section-synopsis: #7B5EA7;
  --section-taxonomy: #2D8F6F;
  --section-actors: #D4654A;
  --section-advanced: #7A7570;

  /* Borders */
  --border: #E4E0DA;
  --border-strong: #D4CFC8;
  --border-light: #EDE9E3;

  /* Shadows — soft, large-radius editorial shadows */
  --shadow-xs: 0 1px 2px rgba(26, 24, 22, 0.04);
  --shadow-sm: 0 1px 3px rgba(26, 24, 22, 0.05), 0 1px 2px rgba(26, 24, 22, 0.03);
  --shadow-md: 0 4px 16px rgba(26, 24, 22, 0.06), 0 1px 4px rgba(26, 24, 22, 0.04);
  --shadow-lg: 0 8px 32px rgba(26, 24, 22, 0.07), 0 2px 8px rgba(26, 24, 22, 0.04);
  --shadow-xl: 0 16px 48px rgba(26, 24, 22, 0.10), 0 4px 16px rgba(26, 24, 22, 0.05);
  --shadow-card: 0 2px 12px rgba(26, 24, 22, 0.04), 0 0 0 1px rgba(26, 24, 22, 0.03);
  --shadow-focus: 0 0 0 3px var(--accent-soft), 0 0 0 1px var(--accent);

  /* Radii */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-2xl: 20px;
  --radius-pill: 999px;

  /* Spacing */
  --panel-padding: 24px;
  --gap-xs: 6px;
  --gap-sm: 10px;
  --gap-md: 16px;
  --gap-lg: 24px;
  --gap-xl: 32px;

  /* Typography */
  --font-display: "Instrument Serif", "Noto Serif SC", "Source Han Serif SC", "STSong", Georgia, serif;
  --font-body: "DM Sans", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
html, body { margin: 0; min-height: 100%; }

body {
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Subtle warm texture overlay */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.3;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23c4b99a' fill-opacity='0.03'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

img { display: block; max-width: 100%; }
button, input, textarea, select { font: inherit; }
code, pre, kbd { font-family: var(--font-mono); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.mobile-context, .mobile-nav, .mobile-settings-panel { display: none; }

/* ── Animations ── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes progressPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* ── Page Shell ── */
.page-shell {
  position: relative;
  z-index: 1;
  width: min(1860px, calc(100% - 48px));
  margin: 28px auto;
  padding-top: env(safe-area-inset-top);
  animation: fadeIn 500ms ease;
}

/* ── Typography ── */
h1, h2, h3 {
  margin: 0;
  font-family: var(--font-display);
  color: var(--ink);
}

h1 {
  font-size: clamp(36px, 4vw, 64px);
  font-weight: 400;
  line-height: 1.05;
  letter-spacing: -0.02em;
  font-style: normal;
}

h2 {
  font-size: clamp(22px, 2.2vw, 30px);
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

h3 {
  font-size: 18px;
  font-weight: 400;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 16px 0 0;
  max-width: 56ch;
  color: var(--ink-secondary);
  font-size: 15px;
  line-height: 1.8;
}

.subtitle code {
  padding: 3px 8px;
  border-radius: var(--radius-xs);
  background: var(--surface-2);
  border: 1px solid var(--border-light);
  color: var(--accent);
  font-size: 12px;
}

/* ── Eyebrow / Kicker ── */
.eyebrow, .panel-kicker {
  margin: 0;
  color: var(--accent);
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.panel-kicker { margin-bottom: 10px; }

.muted {
  margin: 8px 0 0;
  color: var(--ink-tertiary);
  font-size: 13px;
  line-height: 1.7;
}

/* ── Masthead ── */
.masthead {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(360px, 0.9fr);
  gap: var(--gap-lg);
  margin-bottom: var(--gap-lg);
}

/* ── Cards / Panels — Base ── */
.brand-copy, .root-card, .panel {
  background: var(--surface-0);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-card);
}

/* ── Hero Panel ── */
.brand-copy {
  position: relative;
  overflow: hidden;
  padding: 36px 32px 28px;
  display: grid;
  gap: var(--gap-lg);
  background: var(--bg-hero);
  border: 1px solid var(--border-light);
}

/* Decorative top bar */
.brand-copy::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--coral) 50%, var(--section-synopsis) 100%);
}

/* Decorative circles */
.brand-copy::after {
  content: "";
  position: absolute;
  top: -80px;
  right: -60px;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  border: 1px solid var(--border);
  pointer-events: none;
  opacity: 0.5;
}

.hero-top, .hero-footer, .panel-head, .section-head,
.lookup-head, .modal-head, .modal-actions, .overview-foot,
.mapping-row-head, .actor-row-head, .lookup-candidate-head,
.show-item-top, .show-item-meta, .xml-head {
  position: relative;
  z-index: 1;
}

/* ── Grid utility classes ── */
.eyebrow-row, .hero-main, .hero-footer, .stat-grid,
.overview-foot, .sidebar-summary, .editor-actions,
.mini-actions, .summary-strip, .grid-two, .art-grid,
.lookup-meta, .actor-chip-grid, .actor-row-grid,
.mapping-grid, .mapping-list, .form-stack,
.actor-list-editor, .lookup-candidate-grid, .pill-row {
  display: grid;
}

.eyebrow-row {
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

/* ── Status Banner ── */
.status-banner {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 6px 16px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface-0);
  color: var(--ink-secondary);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  transition: all 220ms ease;
  box-shadow: var(--shadow-xs);
}

.status-banner[data-state="ready"] {
  color: var(--success);
  background: var(--success-soft);
  border-color: var(--success-border);
}

.status-banner[data-state="fresh"] {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-border);
}

.status-banner[data-state="dirty"] {
  color: var(--coral);
  background: var(--coral-soft);
  border-color: var(--coral-border);
}

/* ── Hero sections ── */
.hero-main { grid-template-columns: minmax(0, 1fr); gap: 16px; }
.hero-copy { min-width: 0; max-width: 72ch; }

.hero-footer {
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 14px;
}

.hero-foot-card {
  min-width: 0;
  padding: 16px 18px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface-0);
  display: grid;
  gap: var(--gap-xs);
  box-shadow: var(--shadow-xs);
  transition: box-shadow 200ms ease;
}

.hero-foot-card:hover { box-shadow: var(--shadow-sm); }

/* Shared label style */
.hero-foot-card span, .stat-card span, .summary-item span,
.meta-line span, .field span, .lookup-meta span,
.lookup-group > span, .summary-token span, .art-card figcaption {
  color: var(--ink-tertiary);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.hero-foot-card code, .hero-foot-card strong {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  word-break: break-all;
}

.hero-foot-card code { color: var(--accent); font-size: 13px; }

.hero-footnote {
  margin: 0;
  color: var(--ink-tertiary);
  font-size: 12px;
  line-height: 1.6;
}

/* ── Overview Panel ── */
.root-card {
  padding: var(--panel-padding);
  display: grid;
  gap: var(--gap-lg);
  align-content: start;
}

.stat-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--gap-sm);
}

.stat-card {
  padding: 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface-1);
  display: grid;
  gap: var(--gap-xs);
  transition: transform 180ms ease, box-shadow 180ms ease;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
}

.stat-total::before { background: var(--section-basics); }
.stat-missing::before { background: var(--warn); }
.stat-complete::before { background: var(--success); }
.stat-visible::before { background: var(--section-synopsis); }

.stat-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.stat-card strong {
  font-family: var(--font-display);
  font-size: clamp(28px, 2.5vw, 38px);
  font-weight: 400;
  line-height: 1;
  color: var(--ink);
}

.stat-footnote {
  margin: 0;
  color: var(--ink-tertiary);
  font-size: 11px;
  line-height: 1.5;
}

/* ── Progress Bar ── */
.progress-panel {
  padding: 16px 18px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface-1);
  display: grid;
  gap: 12px;
}

.progress-copy { display: grid; gap: 4px; }

.progress-copy span {
  color: var(--ink-tertiary);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.progress-copy strong { font-size: 14px; color: var(--ink); }

.progress-track {
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  overflow: hidden;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-light) 100%);
  transition: width 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Overview Footer ── */
.overview-foot {
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--gap-md);
  align-items: center;
}

.overview-meta,
.overview-foot-actions {
  display: grid;
  gap: 10px;
}

.settings-status-grid,
.mobile-settings-stack {
  display: grid;
  gap: 14px;
}

.meta-line {
  min-width: 0;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-1);
  display: grid;
  gap: 4px;
}

.meta-line strong { font-size: 14px; }
.meta-note {
  margin: 0;
  color: var(--ink-tertiary);
  font-size: 12px;
  line-height: 1.6;
}

#embyStatus[data-state="ok"], #nfoStatus[data-state="ok"], #pwaStatus[data-state="ok"] { color: var(--success); }
#mobileSettingsEmbyStatus[data-state="ok"], #mobilePwaStatus[data-state="ok"] { color: var(--success); }
#embyStatus[data-state="warn"], #nfoStatus[data-state="warn"], #pwaStatus[data-state="warn"] { color: var(--warn); }
#mobileSettingsEmbyStatus[data-state="warn"], #mobilePwaStatus[data-state="warn"] { color: var(--warn); }

/* ── Workspace Layout ── */
.workspace {
  display: grid;
  grid-template-columns: minmax(300px, 340px) minmax(580px, 1fr) minmax(360px, 420px);
  gap: var(--gap-lg);
  align-items: start;
}

.panel {
  min-width: 0;
  padding: var(--panel-padding);
}

/* ── Sidebar & Preview ── */
.sidebar, .preview {
  position: sticky;
  top: 20px;
  align-self: start;
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  max-height: calc(100vh - 40px);
  overflow: hidden;
}

.preview {
  display: grid;
  gap: var(--gap-md);
}

/* ── Editor ── */
.editor {
  background: var(--surface-0);
}

/* ── Panel Head ── */
.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: var(--gap-lg);
}

.panel-head > div:first-child { min-width: 0; }

/* ── Editor Subnav ── */
.editor-subnav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: var(--gap-lg);
  padding: 12px 14px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface-1);
}

.section-chip, .shortcut-chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: all 180ms ease;
}

.section-chip {
  color: var(--ink-secondary);
  border: 1px solid var(--border);
  background: var(--surface-0);
}

.section-chip:hover {
  border-color: var(--accent-border);
  color: var(--accent);
  background: var(--accent-soft);
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: var(--shadow-xs);
}

.shortcut-chip {
  color: var(--ink-placeholder);
  border: 1px solid transparent;
  background: transparent;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 400;
}

/* ── Sidebar Tools ── */
.sidebar-tools {
  display: grid;
  gap: var(--gap-md);
  margin-bottom: var(--gap-md);
}

/* ── Fields ── */
.field { display: grid; gap: var(--gap-xs); }

.field-hint, .section-note {
  margin: 0;
  color: var(--ink-tertiary);
  font-size: 12px;
  line-height: 1.7;
}

.search-field { position: relative; }

.search-field::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 36px;
  width: 14px;
  height: 14px;
  border: 2px solid var(--ink-placeholder);
  border-radius: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  z-index: 1;
}

.search-field::after {
  content: "";
  position: absolute;
  left: 26px;
  top: 43px;
  width: 6px;
  height: 2px;
  background: var(--ink-placeholder);
  border-radius: var(--radius-pill);
  transform: rotate(45deg);
  pointer-events: none;
  z-index: 1;
}

/* ── Inputs ── */
input, textarea, select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-0);
  color: var(--ink);
  padding: 11px 14px;
  font-size: 14px;
  transition: border-color 180ms ease, box-shadow 180ms ease, background-color 180ms ease;
}

.search-field input { padding-left: 42px; }

input::placeholder, textarea::placeholder { color: var(--ink-placeholder); }

textarea { min-height: 100px; resize: vertical; line-height: 1.75; }

input:hover, textarea:hover, select:hover {
  border-color: var(--border-strong);
  background: var(--surface-1);
}

input:focus, textarea:focus, select:focus, button:focus-visible { outline: none; }

input:focus-visible, textarea:focus-visible, select:focus-visible {
  border-color: var(--accent);
  box-shadow: var(--shadow-focus);
  background: var(--surface-0);
}

/* ── Buttons ── */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: all 180ms ease;
}

.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:active:not(:disabled) { transform: translateY(0); }
.button:disabled { opacity: 0.35; cursor: not-allowed; }
.button svg { flex-shrink: 0; }

.button.primary {
  color: var(--ink-inverse);
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.button.primary:hover:not(:disabled) {
  background: var(--accent-light);
  border-color: var(--accent-light);
  box-shadow: var(--shadow-md);
}

.button.ghost {
  color: var(--ink-secondary);
  background: var(--surface-0);
  border-color: var(--border);
}

.button.ghost:hover:not(:disabled) {
  color: var(--ink);
  background: var(--surface-2);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-xs);
}

.button.small {
  min-height: 34px;
  padding: 5px 12px;
  font-size: 12px;
  border-radius: var(--radius-sm);
}

/* ── Sidebar Summary ── */
.sidebar-summary {
  grid-template-columns: minmax(0, 1.4fr) repeat(2, minmax(80px, 1fr));
  gap: 8px;
}

.summary-token {
  min-width: 0;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-1);
  display: grid;
  gap: 4px;
  align-content: center;
}

.summary-token strong { font-size: 13px; line-height: 1.3; color: var(--ink); }

/* ── Toggle Line ── */
.toggle-line {
  min-height: 44px;
  padding: 0 14px;
  display: inline-flex;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-1);
  color: var(--ink-secondary);
  font-size: 13px;
  line-height: 1.5;
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease;
}

.toggle-line:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.toggle-line input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ── Show List ── */
.show-list {
  gap: 10px;
  overflow: auto;
  padding-right: 4px;
  align-content: start;
}

.show-list::-webkit-scrollbar, .xml-preview::-webkit-scrollbar, .modal-body::-webkit-scrollbar { width: 5px; height: 5px; }
.show-list::-webkit-scrollbar-thumb, .xml-preview::-webkit-scrollbar-thumb, .modal-body::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--radius-pill); }
.show-list::-webkit-scrollbar-thumb:hover, .xml-preview::-webkit-scrollbar-thumb:hover, .modal-body::-webkit-scrollbar-thumb:hover { background: var(--ink-tertiary); }
.show-list::-webkit-scrollbar-track, .xml-preview::-webkit-scrollbar-track, .modal-body::-webkit-scrollbar-track { background: transparent; }

/* ── Show Item ── */
.show-item {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-0);
  text-align: left;
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  cursor: pointer;
  transition: all 180ms ease;
}

.show-item:hover:not(.selected) {
  border-color: var(--border-strong);
  background: var(--surface-1);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.show-item.selected {
  border-color: var(--accent-border);
  background: var(--accent-softer);
  box-shadow: inset 3px 0 0 var(--accent);
}

.show-item-media {
  width: 72px;
  height: 100px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
  box-shadow: var(--shadow-xs);
}

.show-item-poster {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.show-item-poster-fallback {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--ink-placeholder);
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 400;
  background: linear-gradient(145deg, var(--surface-2) 0%, var(--surface-3) 100%);
}

.show-item-body { min-width: 0; display: grid; gap: 8px; }

.show-item-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
}

.show-item-heading { min-width: 0; display: grid; gap: 3px; }

.show-item-heading strong {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--ink);
}

.show-item-path {
  color: var(--ink-tertiary);
  font-size: 11px;
  line-height: 1.4;
  word-break: break-word;
}

.show-item-meta { display: flex; flex-wrap: wrap; gap: 5px; }

.show-item-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--ink-tertiary);
  font-size: 11px;
  font-weight: 500;
}

/* ── Badge / Pill ── */
.badge, .pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 12px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.badge.ok, .pill {
  color: var(--success);
  background: var(--success-soft);
  border: 1px solid var(--success-border);
}

.badge.warn {
  color: var(--warn);
  background: var(--warn-soft);
  border: 1px solid var(--warn-border);
}

/* ── Empty States ── */
.empty-list {
  padding: 28px;
  border-radius: var(--radius-lg);
  border: 2px dashed var(--border);
  background: var(--surface-1);
  text-align: center;
  color: var(--ink-tertiary);
  font-size: 13px;
}

.empty-state {
  padding: 48px 32px;
  border-radius: var(--radius-xl);
  border: 2px dashed var(--border);
  background: var(--surface-1);
  text-align: center;
  color: var(--ink-tertiary);
  display: grid;
  gap: 14px;
  place-items: center;
  min-height: 300px;
}

.empty-state-icon { color: var(--ink-placeholder); opacity: 0.6; }

.empty-state-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.empty-state strong {
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 400;
}

.empty-state p {
  margin: 0;
  max-width: 48ch;
  font-size: 14px;
  line-height: 1.8;
}

/* ── Editor Content ── */
.editor-content { display: grid; gap: var(--gap-md); }

.editor-actions, .mini-actions {
  grid-auto-flow: column;
  grid-auto-columns: max-content;
  gap: 8px;
  justify-content: start;
  align-items: center;
}

.summary-strip {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.summary-item {
  min-width: 0;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-1);
  display: grid;
  gap: 4px;
}

.summary-item strong { font-size: 13px; line-height: 1.4; color: var(--ink); }

/* ── Path Lines ── */
.path-line {
  margin: 0;
  color: var(--ink-tertiary);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.7;
  word-break: break-all;
}

.secondary-line { margin-top: -6px; }

/* ── Warning ── */
.warning {
  margin: 0;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  line-height: 1.7;
}

/* ── Form Stack ── */
.form-stack { gap: 16px; }

.form-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 22px 20px;
  background: var(--surface-0);
  display: grid;
  gap: 16px;
  scroll-margin-top: 80px;
  transition: border-color 200ms ease, box-shadow 200ms ease;
  position: relative;
  /* Left color border */
  border-left: 4px solid var(--border);
}

.form-section:hover {
  box-shadow: var(--shadow-sm);
}

/* Section-specific left borders */
.section-douban  { border-left-color: var(--section-douban); }
.section-drama   { border-left-color: var(--section-drama); }
.section-basics  { border-left-color: var(--section-basics); }
.section-synopsis { border-left-color: var(--section-synopsis); }
.section-taxonomy { border-left-color: var(--section-taxonomy); }
.section-actors  { border-left-color: var(--section-actors); }
.section-advanced { border-left-color: var(--section-advanced); }

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

.section-head > div:first-child { min-width: 0; }

.grid-two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.lookup-grid { align-items: start; }

/* ── Lookup ── */
.lookup-note, .lookup-result, .lookup-text,
.actor-row, .mapping-row, .settings-block,
.art-card, .xml-block {
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.lookup-note {
  padding: 16px 18px;
  background: var(--surface-1);
}

.lookup-note .muted { margin: 0; }
.lookup-status { margin-top: 8px !important; }
.lookup-status.error { color: var(--danger); }

.lookup-result {
  padding: 18px;
  background: var(--surface-1);
  display: grid;
  gap: 16px;
}

.lookup-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

.lookup-head strong {
  display: block;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 400;
  color: var(--ink);
}

.lookup-head a { color: var(--accent); font-size: 13px; word-break: break-all; }

.lookup-meta {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.lookup-meta div {
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-0);
  display: grid;
  gap: 4px;
}

.lookup-group { display: grid; gap: 8px; }

.lookup-candidate-grid { gap: 12px; }

.lookup-candidate {
  padding: 14px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface-0);
  display: grid;
  gap: 12px;
  transition: all 180ms ease;
}

.lookup-candidate:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.lookup-candidate.selected {
  border-color: var(--accent-border);
  background: var(--accent-softer);
  box-shadow: inset 3px 0 0 var(--accent);
}

.lookup-candidate-body {
  display: grid;
  grid-template-columns: 100px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.lookup-candidate-cover, .lookup-candidate-cover-fallback {
  width: 100px;
  height: 133px;
  border-radius: var(--radius-md);
}

.lookup-candidate-cover {
  object-fit: cover;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}

.lookup-candidate-cover-fallback {
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink-tertiary);
  font-size: 11px;
  text-align: center;
  padding: 10px;
}

.lookup-candidate-content { min-width: 0; display: grid; gap: 8px; }

.lookup-candidate-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.lookup-candidate-head strong { font-size: 15px; font-weight: 600; color: var(--ink); }

.lookup-candidate-meta { display: flex; flex-wrap: wrap; gap: 6px; }

.lookup-candidate-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--ink-tertiary);
  font-size: 11px;
  font-weight: 500;
}

.lookup-candidate-text, .lookup-text {
  font-size: 13px;
  line-height: 1.85;
  white-space: pre-wrap;
  color: var(--ink-secondary);
}

.lookup-text {
  padding: 16px 18px;
  background: var(--surface-0);
}

/* ── Pill Row ── */
.pill-row { grid-auto-flow: row; gap: 6px; }

.muted-pill {
  color: var(--ink-tertiary) !important;
  background: var(--surface-2) !important;
  border-color: var(--border) !important;
}

/* ── Actor Chips (lookup display) ── */
.actor-chip-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.actor-chip {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-0);
  transition: box-shadow 180ms ease;
}

.actor-chip:hover { box-shadow: var(--shadow-xs); }

.actor-chip img, .actor-chip-fallback {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
}

.actor-chip img { object-fit: cover; box-shadow: var(--shadow-xs); }

.actor-chip-fallback {
  display: grid;
  place-items: center;
  background: var(--surface-2);
  color: var(--ink-tertiary);
  font-size: 11px;
}

.actor-chip-info { min-width: 0; display: grid; gap: 2px; }

.actor-chip-info strong {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
}

.actor-chip-info span {
  color: var(--ink-tertiary);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Actor Editor Rows ── */
.actor-list-editor { gap: 12px; }

.actor-row {
  padding: 14px;
  background: var(--surface-1);
  display: grid;
  gap: 12px;
}

.actor-row-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.actor-row-head strong, .mapping-row-head strong {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-secondary);
}

.actor-row-grid, .mapping-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.actor-editor-hint { margin-top: -2px; }

/* ── Preview Context ── */
.preview-context {
  padding: 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface-1);
  display: grid;
  gap: 14px;
}

.preview-context-head { display: grid; gap: 6px; }

.preview-context-kicker {
  color: var(--accent);
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.preview-status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.preview-status-card {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-0);
  display: grid;
  gap: 4px;
}

.preview-status-card strong[data-state="ok"] { color: var(--success); }
.preview-status-card strong[data-state="warn"] { color: var(--warn); }
.preview-status-card strong[data-state="idle"] { color: var(--ink-tertiary); }

/* ── Art Cards ── */
.art-grid { gap: 14px; }

.art-card {
  margin: 0;
  overflow: hidden;
  background: var(--surface-1);
}

.art-card figcaption {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 12px;
}

.art-card img {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  background: var(--surface-2);
}

.art-card.wide img { aspect-ratio: 16 / 9; }

.art-placeholder {
  min-height: 160px;
  display: grid;
  place-items: center;
  gap: 8px;
  padding: 28px;
  color: var(--ink-placeholder);
  font-size: 12px;
  text-align: center;
}

/* ── XML Block ── */
.xml-block {
  overflow: hidden;
  background: var(--surface-code);
  border-color: var(--surface-code);
}

.xml-head {
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
}

.xml-head strong {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.6);
}

.xml-head .button.ghost {
  color: rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.1);
}

.xml-head .button.ghost:hover:not(:disabled) {
  color: rgba(255, 255, 255, 0.8);
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.15);
}

.xml-preview {
  margin: 0;
  padding: 16px;
  max-height: 480px;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.85;
  white-space: pre;
  color: rgba(255, 255, 255, 0.75);
  tab-size: 2;
}

/* ── Modals ── */
body.modal-open { overflow: hidden; }

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(26, 24, 22, 0.35);
  backdrop-filter: blur(12px);
  animation: fadeIn 180ms ease;
}

.modal-dialog {
  width: min(880px, 100%);
  max-height: calc(100vh - 48px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-2xl);
  border: 1px solid var(--border);
  background: var(--surface-0);
  box-shadow: var(--shadow-xl);
  animation: slideUp 280ms cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding: 24px 24px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-head h3 {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 400;
}

.modal-head .muted { margin-top: 6px; }

.modal-body {
  padding: 20px 24px;
  overflow: auto;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  gap: 16px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-1);
}

/* ── Settings Block ── */
.settings-block {
  padding: 18px;
  background: var(--surface-1);
  display: grid;
  gap: 14px;
}

.compact-head { margin-bottom: 0; }
.mapping-list { gap: 12px; }

.mapping-row {
  padding: 14px 16px;
  background: var(--surface-0);
  display: grid;
  gap: 12px;
}

.mapping-row-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.drama-modal .lookup-group > span {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-secondary);
}

/* ── Toast ── */
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 50;
  min-width: 200px;
  max-width: min(420px, calc(100vw - 48px));
  padding: 14px 20px;
  border-radius: var(--radius-lg);
  background: var(--surface-code);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--ink-inverse);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.5;
  animation: toastIn 250ms cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.error {
  background: #C44B4B;
  border-color: transparent;
  color: #FFF;
}

/* ── Editor subtitle state ── */
#editorSubtitle[data-state="dirty"] { color: var(--coral); }
#editorSubtitle[data-state="ready"] { color: var(--success); }

/* ── Dirty state accent on hero ── */
body[data-ui-state="dirty"] .hero-panel { border-color: var(--coral-border); }
body[data-ui-state="dirty"] .hero-panel::before { background: linear-gradient(90deg, var(--coral) 0%, var(--warn) 100%); }
body[data-app-mode="standalone"] .page-shell { padding-top: calc(8px + env(safe-area-inset-top)); }

/* ═══════════════════════════════════════════════════════
   Responsive Breakpoints
   ═══════════════════════════════════════════════════════ */

@media (max-width: 1640px) {
  .workspace {
    grid-template-columns: minmax(280px, 320px) minmax(0, 1fr);
  }

  .sidebar {
    position: static;
  }

  .preview {
    position: static;
    grid-column: span 2;
  }

  .art-grid {
    grid-template-columns: 280px minmax(0, 1fr);
  }
}

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

  .sidebar {
    position: static;
    max-height: none;
  }
}

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 1fr; }
  .preview { grid-column: auto; }

  .summary-strip, .lookup-meta, .actor-chip-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid-two, .actor-row-grid, .mapping-grid,
  .lookup-candidate-body, .hero-footer {
    grid-template-columns: 1fr;
  }

  .overview-foot { grid-template-columns: 1fr; }
  .preview-status-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .overview-foot-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .overview-foot .button { width: 100%; }
}

@media (max-width: 768px) {
  :root {
    --panel-padding: 16px;
    --radius-2xl: 16px;
    --radius-xl: 14px;
  }

  .page-shell {
    width: min(100% - 16px, 100%);
    margin: 12px auto 20px;
    padding-bottom: calc(72px + env(safe-area-inset-bottom));
  }

  .masthead { gap: 12px; margin-bottom: 12px; }

  .brand-copy, .root-card, .panel { border-radius: var(--radius-xl); }

  .brand-copy { padding: 20px 16px; gap: 16px; }

  .eyebrow-row { grid-template-columns: 1fr; }
  .status-banner { justify-self: start; }

  h1 { font-size: 32px; max-width: none; }
  h2 { font-size: 22px; }
  h3 { font-size: 17px; }
  .subtitle { font-size: 13px; line-height: 1.8; }

  .stat-grid, .summary-strip, .grid-two,
  .lookup-meta, .actor-chip-grid, .art-grid {
    grid-template-columns: 1fr;
  }

  .hero-foot-card {
    padding: 14px;
    border-radius: var(--radius-md);
  }

  .root-card { padding: 16px; gap: 14px; }
  .stat-card { padding: 14px; border-radius: var(--radius-md); }

  .theme-panel { padding: 12px 14px; border-radius: var(--radius-md); }
  .theme-switch-btn { min-height: 30px; padding: 0 12px; font-size: 11px; }

  .panel-head, .section-head, .lookup-head, .modal-head {
    flex-direction: column;
    align-items: stretch;
  }

  .editor-subnav {
    padding: 10px;
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .editor-subnav::-webkit-scrollbar { display: none; }
  .workspace { display: block; }
  .panel { padding: 14px; }

  .masthead,
  .mobile-context,
  .mobile-settings-panel,
  .sidebar,
  .editor,
  .preview { display: none; }

  body[data-mobile-tab="overview"] .masthead { display: grid; }
  body[data-mobile-tab="shows"] .sidebar { display: grid; }
  body[data-mobile-tab="editor"] .editor { display: block; }
  body[data-mobile-tab="preview"] .preview { display: grid; }
  body[data-mobile-tab="settings"] .mobile-settings-panel { display: grid; }
  body[data-mobile-tab="editor"] .mobile-context,
  body[data-mobile-tab="preview"] .mobile-context { display: grid; }
  body[data-mobile-tab="overview"] .workspace,
  body[data-mobile-tab="overview"] .mobile-settings-panel,
  body[data-mobile-tab="settings"] .workspace { display: none; }

  /* ── Mobile Context Bar ── */
  .mobile-context {
    gap: 12px;
    align-items: stretch;
    margin: 0 0 12px;
    padding: 12px 14px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: var(--surface-0);
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 8px;
    z-index: 10;
  }

  .mobile-context-copy { min-width: 0; display: grid; gap: 6px; }

  .mobile-context-copy-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  .mobile-context-copy-head span {
    color: var(--ink-tertiary);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .mobile-context-copy strong {
    font-size: 14px;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--ink);
  }

  .mobile-context-copy-head .button {
    flex: 0 0 auto;
    min-height: 40px;
    padding: 6px 12px;
  }

  .mobile-context-actions {
    display: grid;
    gap: 8px;
  }

  .mobile-context-actions .button {
    width: 100%;
    min-height: 44px;
    padding: 10px 14px;
  }

  .mobile-settings-panel {
    gap: 14px;
    margin-bottom: 12px;
  }

  .mobile-settings-panel .panel-head { margin-bottom: 0; }
  .overview-panel .theme-panel,
  .overview-panel .overview-foot { display: none; }

  .sidebar {
    grid-template-rows: auto auto minmax(0, 1fr);
    overflow: hidden;
    max-height: calc(100dvh - 102px - env(safe-area-inset-bottom));
  }

  .show-list {
    overflow: auto;
    max-height: calc(100dvh - 290px - env(safe-area-inset-bottom));
    padding-right: 2px;
  }

  .show-item {
    grid-template-columns: 60px minmax(0, 1fr);
    padding: 10px;
    gap: 10px;
  }

  .show-item-media {
    width: 60px;
    height: 84px;
    border-radius: var(--radius-sm);
  }

  .sidebar-summary { grid-template-columns: 1fr; }

  .editor-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-flow: row;
  }

  .editor-actions .button, .mini-actions .button { width: 100%; }

  .section-chip, .shortcut-chip {
    min-height: 32px;
    padding: 0 12px;
    font-size: 12px;
    flex: 0 0 auto;
  }

  .summary-item, .form-section, .lookup-note,
  .lookup-result, .actor-row, .mapping-row,
  .settings-block { border-radius: var(--radius-md); }

  .summary-item, .form-section { padding: 14px; }

  input, textarea, select { padding: 11px 12px; font-size: 16px; }
  textarea { min-height: 96px; }

  .lookup-candidate-body { grid-template-columns: 80px minmax(0, 1fr); }

  .lookup-candidate-cover, .lookup-candidate-cover-fallback {
    width: 80px;
    height: 106px;
    border-radius: var(--radius-sm);
  }

  .xml-preview { max-height: 240px; padding: 14px; font-size: 11px; }

  .toast {
    left: 12px;
    right: 12px;
    bottom: calc(80px + env(safe-area-inset-bottom));
    max-width: none;
    text-align: center;
  }

  .modal-overlay { padding: 10px; }

  .modal-dialog {
    width: 100%;
    max-height: calc(100vh - 20px - env(safe-area-inset-bottom));
    border-radius: var(--radius-xl);
  }

  .modal-head, .modal-body, .modal-actions { padding-left: 16px; padding-right: 16px; }
  .modal-head { padding-top: 16px; padding-bottom: 14px; }
  .modal-body { padding-top: 14px; padding-bottom: calc(14px + env(safe-area-inset-bottom)); }

  .modal-actions {
    flex-direction: column;
    padding-top: 12px;
    padding-bottom: 16px;
  }

  .modal-actions .button { width: 100%; }

  /* ── Mobile Nav ── */
  .mobile-nav {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 20;
    padding: 6px;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.92);
    box-shadow: var(--shadow-xl);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
  }

  .mobile-nav-button {
    min-height: 42px;
    padding: 0 6px;
    border: 0;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--ink-tertiary);
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 150ms ease;
  }

  .mobile-nav-button.active {
    color: var(--ink-inverse);
    background: var(--accent);
    box-shadow: var(--shadow-sm);
  }

  body[data-app-mode="standalone"] .mobile-context {
    top: calc(8px + env(safe-area-inset-top));
  }
}

@media (max-width: 520px) {
  .page-shell { width: min(100% - 10px, 100%); }

  .brand-copy, .root-card, .panel { border-radius: var(--radius-lg); }

  .brand-copy, .root-card, .panel, .form-section, .summary-item { padding: 12px; }

  h1 { font-size: 28px; }

  .empty-state { padding: 24px 16px; min-height: 220px; }

  .show-item-top, .lookup-candidate-head,
  .actor-row-head, .mapping-row-head { display: grid; gap: 8px; }

  .actor-row-grid, .mapping-grid { grid-template-columns: 1fr; }
  .lookup-candidate-body { grid-template-columns: 1fr; }
  .preview-status-grid { grid-template-columns: 1fr; }

  .lookup-candidate-cover, .lookup-candidate-cover-fallback {
    width: 100%;
    height: auto;
    aspect-ratio: 3 / 4;
  }

  .mobile-context { padding: 10px 12px; }

  .mobile-context-copy-head {
    align-items: start;
    gap: 8px;
  }

  .mobile-context-copy-head .button {
    min-height: 40px;
    padding: 6px 10px;
  }

  .mobile-nav { left: 6px; right: 6px; gap: 4px; padding: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ═══════════════════════════════════════════════════════
   Theme Switch — Segmented Control
   ═══════════════════════════════════════════════════════ */

.eyebrow-row-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.theme-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface-1);
}

.theme-panel > span {
  color: var(--ink-tertiary);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.theme-switch {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.theme-switch-btn {
  min-height: 32px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--ink-tertiary);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 180ms ease;
  white-space: nowrap;
}

.theme-switch-btn:hover:not(.active) {
  color: var(--ink-secondary);
  background: var(--surface-hover);
}

.theme-switch-btn.active {
  background: var(--surface-0);
  color: var(--ink);
  border-color: var(--border);
  box-shadow: var(--shadow-xs);
}

/* ═══════════════════════════════════════════════════════
   Theme Transition — Smooth crossfade
   Only applied during toggle, not on initial page load
   ═══════════════════════════════════════════════════════ */

html.theme-transitioning,
html.theme-transitioning *,
html.theme-transitioning *::before,
html.theme-transitioning *::after {
  transition:
    background-color 0.4s cubic-bezier(0.4, 0, 0.2, 1),
    border-color 0.35s cubic-bezier(0.4, 0, 0.2, 1),
    color 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    box-shadow 0.35s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.35s ease !important;
}

/* ═══════════════════════════════════════════════════════
   Dark Theme — Deep charcoal editorial palette
   ═══════════════════════════════════════════════════════ */

html[data-theme="dark"] {
  /* Surfaces — deep charcoal to slate */
  --bg: #141517;
  --bg-hero: linear-gradient(168deg, #1A1B1E 0%, #16171A 48%, #1C1D20 100%);
  --surface-0: #1E1F23;
  --surface-1: #232428;
  --surface-2: #2A2B30;
  --surface-3: #333439;
  --surface-hover: #2E2F34;
  --surface-code: #F7F6F3;

  /* Text — soft warm whites */
  --ink: #E8E6E3;
  --ink-secondary: #A8A4A0;
  --ink-tertiary: #787470;
  --ink-placeholder: #5A5753;
  --ink-inverse: #1A1B1E;

  /* Primary accent — brighter teal for dark bg */
  --accent: #3CC9B6;
  --accent-light: #5EDAC9;
  --accent-soft: rgba(60, 201, 182, 0.12);
  --accent-softer: rgba(60, 201, 182, 0.06);
  --accent-border: rgba(60, 201, 182, 0.25);

  /* Secondary — brighter coral for dark bg */
  --coral: #F0845C;
  --coral-soft: rgba(240, 132, 92, 0.12);
  --coral-border: rgba(240, 132, 92, 0.22);

  /* Semantic — brighter on dark */
  --success: #4CBB8A;
  --success-soft: rgba(76, 187, 138, 0.12);
  --success-border: rgba(76, 187, 138, 0.25);
  --warn: #E0A840;
  --warn-soft: rgba(224, 168, 64, 0.12);
  --warn-border: rgba(224, 168, 64, 0.25);
  --danger: #E86060;
  --danger-soft: rgba(232, 96, 96, 0.1);
  --danger-border: rgba(232, 96, 96, 0.22);

  /* Section colors — brightened for dark mode */
  --section-douban: #E0A840;
  --section-drama: #3CC9B6;
  --section-basics: #6B9BE0;
  --section-synopsis: #A88BD4;
  --section-taxonomy: #4CBB8A;
  --section-actors: #F0845C;
  --section-advanced: #9A9590;

  /* Borders — subtle on dark */
  --border: #2E3035;
  --border-strong: #3A3C42;
  --border-light: #262830;

  /* Shadows — deeper, cooler cast */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.24), 0 1px 2px rgba(0, 0, 0, 0.16);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.28), 0 1px 4px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.32), 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.24);
  --shadow-card: 0 2px 12px rgba(0, 0, 0, 0.16), 0 0 0 1px rgba(255, 255, 255, 0.03);
  --shadow-focus: 0 0 0 3px var(--accent-soft), 0 0 0 1px var(--accent);
}

/* ── Dark mode texture overlay adjustment ── */
html[data-theme="dark"] body::before {
  opacity: 0.08;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.02'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

/* ── Dark mode XML block — inverted to light ── */
html[data-theme="dark"] .xml-block {
  background: var(--surface-code);
  border-color: var(--border);
}

html[data-theme="dark"] .xml-head {
  border-bottom-color: rgba(0, 0, 0, 0.08);
  background: rgba(0, 0, 0, 0.04);
}

html[data-theme="dark"] .xml-head strong {
  color: rgba(0, 0, 0, 0.5);
}

html[data-theme="dark"] .xml-head .button.ghost {
  color: rgba(0, 0, 0, 0.45);
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.1);
}

html[data-theme="dark"] .xml-head .button.ghost:hover:not(:disabled) {
  color: rgba(0, 0, 0, 0.7);
  background: rgba(0, 0, 0, 0.08);
  border-color: rgba(0, 0, 0, 0.15);
}

html[data-theme="dark"] .xml-preview {
  color: rgba(0, 0, 0, 0.7);
}

html[data-theme="dark"] .xml-preview::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
}

/* ── Dark mode toast ── */
html[data-theme="dark"] .toast {
  background: #E8E6E3;
  color: #1A1B1E;
  border-color: rgba(0, 0, 0, 0.06);
}

html[data-theme="dark"] .toast.error {
  background: #E86060;
  color: #FFF;
  border-color: transparent;
}

/* ── Dark mode modal overlay ── */
html[data-theme="dark"] .modal-overlay {
  background: rgba(0, 0, 0, 0.55);
}

/* ── Dark mode mobile nav ── */
@media (max-width: 768px) {
  html[data-theme="dark"] .mobile-nav {
    background: rgba(30, 31, 35, 0.92);
    border-color: var(--border);
  }

  html[data-theme="dark"] .mobile-context {
    background: var(--surface-0);
  }
}

/* ── Dark mode poster fallback gradient ── */
html[data-theme="dark"] .show-item-poster-fallback {
  background: linear-gradient(145deg, var(--surface-2) 0%, var(--surface-3) 100%);
}
