/* =============================================
   TV DARK THEME — v1.02
   Override toàn bộ màu sắc sang dark base.
   Các biến --tv-* là design tokens mới.
   ============================================= */
:root {
  color-scheme: dark;
  /* Dark base */
  --tv-bg:           #0e0e11;
  --tv-surface:      #18181b;
  --tv-surface-soft: #1f1f24;
  --tv-border:       rgba(255,255,255,0.07);
  --tv-border-mid:   rgba(255,255,255,0.12);
  --tv-text:         #f4f4f5;
  --tv-text-sec:     #a1a1aa;
  --tv-text-muted:   #a1a1aa;
  --tv-text-dim:     #71717a;
  /* Section accent colors */
  --tv-home:   #22d3ee;
  --tv-chart:  #a855f7;
  --tv-xam:    #fbbf24;
  --tv-tarot:  #fb7185;
  /* Default accent = Theme A Cyan */
  --tv-accent:      #22d3ee;
  --tv-secondary:   #a855f7;
  --tv-glow:        rgba(34,211,238,0.22);
  --tv-accent-soft: rgba(34,211,238,0.1);
  /* Remap existing variables to dark */
  --canvas: #0e0e11;
  --bg: #0e0e11;
  --surface: #18181b;
  --surface-soft: #1f1f24;
  --surface-cream: #1f1f24;
  --surface-parchment: #1f1f24;
  --ink: #fafafa;
  --body: #a1a1aa;
  --muted: #71717a;
  --hairline: rgba(255,255,255,0.06);
  --gold-line: rgba(255,200,80,0.3);
  --primary: var(--tv-accent);
  --primary-active: #a33024;
  --coral: #cb997e;
  --red: #f87171;
  --forest: #4ade80;
  --mint: #34d399;
  --yellow: #facc15;
  --link: #60a5fa;
  --danger-soft: rgba(248,113,113,0.12);
  --success-soft: rgba(74,222,128,0.1);
}

/* ── Per-theme accent overrides ──
   A (heritage) = Thiên Thanh · Cyan
   B (classic)  = Tử Tinh · Purple
   C (neutral)  = Kim Vận · Amber                */
[data-theme="heritage"] {
  --tv-accent:      #22d3ee;
  --tv-secondary:   #a855f7;
  --tv-glow:        rgba(34,211,238,0.22);
  --tv-accent-soft: rgba(34,211,238,0.1);
  --primary: #22d3ee;
  --primary-active: #06b6d4;
}
[data-theme="classic"] {
  --tv-accent:      #c084fc;
  --tv-secondary:   #f472b6;
  --tv-glow:        rgba(192,132,252,0.22);
  --tv-accent-soft: rgba(192,132,252,0.1);
  --primary: #c084fc;
  --primary-active: #a855f7;
}
[data-theme="neutral"] {
  --tv-accent:      #fbbf24;
  --tv-secondary:   #fb923c;
  --tv-glow:        rgba(251,191,36,0.22);
  --tv-accent-soft: rgba(251,191,36,0.1);
  --primary: #fbbf24;
  --primary-active: #f59e0b;
}

/* ── Animations ── */
@keyframes tvSpinCW  { to { transform: rotate(360deg); } }
@keyframes tvSpinCCW { to { transform: rotate(-360deg); } }
@keyframes tvFloat   { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes tvPulse   { 0%,100% { opacity:.55; } 50% { opacity:1; } }
@keyframes tvSlideIn { from { opacity:0; transform:translateY(16px); } to { opacity:1; transform:translateY(0); } }
@keyframes tvCardIn  { from { opacity:0; transform:scale(.96) translateY(10px); } to { opacity:1; transform:scale(1) translateY(0); } }

.tvSpinCW  { animation: tvSpinCW  28s linear infinite; }
.tvSpinCCW { animation: tvSpinCCW 20s linear infinite; }
.tvSpinSlow{ animation: tvSpinCCW 14s linear infinite; }
.tvBatQuai { animation: tvFloat 6s ease-in-out infinite; filter: drop-shadow(0 0 32px var(--tv-glow)); }

/* ══════════════════════════════════════════
   APP SHELL — sidebar + main layout
   ══════════════════════════════════════════ */
html, body { height: 100%; }

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--tv-bg);
  color: var(--tv-text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #27272a; border-radius: 99px; }

/* ══════════════════════════════════════════
   TV APP LAYOUT
   ══════════════════════════════════════════ */
.tvApp {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--tv-bg);
  color: var(--tv-text);
  font-family: 'Inter', Inter, ui-sans-serif, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ── SIDEBAR ── */
.tvSidebar {
  width: 220px;
  flex: 0 0 220px;
  background: var(--tv-bg);
  border-right: 1px solid var(--tv-border);
  display: flex;
  flex-direction: column;
  padding: 14px 10px 14px;
  overflow: hidden;
}

.tvSidebarLogo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 20px;
  text-decoration: none;
  color: inherit;
}
.tvLogoMark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  flex: 0 0 36px;
  background: linear-gradient(135deg, var(--tv-accent), var(--tv-secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 0 20px var(--tv-glow);
}
.tvLogoText { line-height: 1.25; }
.tvLogoText strong { display: block; font-size: 13px; font-weight: 700; letter-spacing: .03em; color: var(--tv-text); }
.tvLogoText small  { display: block; font-size: 10px; color: var(--tv-text-dim); margin-top: 1px; }

.tvNavLabel {
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--tv-text-dim);
  padding: 0 10px 8px;
}

/* ── Sidebar nav items ── */
.tvNav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.tvNavItem {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  color: var(--tv-text-sec);
  text-decoration: none;
  position: relative;
  transition: background .15s;
}
.tvNavItem:hover { background: rgba(255,255,255,0.04); }

/* Active bar indicator */
.tvNavItem.isActive::before {
  content: '';
  position: absolute;
  left: -10px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  border-radius: 0 2px 2px 0;
}
.tvNavItem[data-view="landing"].isActive::before { background: var(--tv-home); }
.tvNavItem[data-view="chart"].isActive::before   { background: var(--tv-chart); }
.tvNavItem[data-view="xam"].isActive::before     { background: var(--tv-xam); }

/* Icon containers */
.tvNavIcon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  flex: 0 0 30px;
  background: rgba(255,255,255,0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, box-shadow .15s;
  color: var(--tv-text-muted);
}
.tvNavItem.isActive .tvNavIcon { background: rgba(255,255,255,0.08); }

/* Per-section icon colors */
.tvNavItem[data-view="landing"] .tvNavIcon { color: var(--tv-home); }
.tvNavItem[data-view="landing"].isActive .tvNavIcon {
  background: rgba(34,211,238,0.12);
  box-shadow: 0 0 12px rgba(34,211,238,0.3);
}
.tvNavItem[data-view="chart"] .tvNavIcon { color: var(--tv-chart); }
.tvNavItem[data-view="chart"].isActive .tvNavIcon {
  background: rgba(168,85,247,0.12);
  box-shadow: 0 0 12px rgba(168,85,247,0.3);
}
.tvNavItem[data-view="xam"] .tvNavIcon { color: var(--tv-xam); }
.tvNavItem[data-view="xam"].isActive .tvNavIcon {
  background: rgba(251,191,36,0.12);
  box-shadow: 0 0 12px rgba(251,191,36,0.3);
}
.tvNavItem:not([data-view]) .tvNavIcon { color: var(--tv-tarot); } /* tarot <a> */
.tvNavItem:not([data-view]).isActive .tvNavIcon {
  background: rgba(251,113,133,0.12);
  box-shadow: 0 0 12px rgba(251,113,133,0.3);
}

.tvNavText { flex: 1; min-width: 0; }
.tvNavText span { display: block; font-size: 12.5px; font-weight: 500; color: var(--tv-text-sec); }
.tvNavItem.isActive .tvNavText span { color: var(--tv-text); }
.tvNavText small { display: block; font-size: 10px; color: var(--tv-text-dim); margin-top: 1px; }

.tvNavItem kbd {
  font-family: 'JetBrains Mono', 'Fira Mono', monospace;
  font-size: 9.5px;
  background: #1f1f24;
  border: 1px solid rgba(255,255,255,0.1);
  border-bottom-width: 2px;
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--tv-text-dim);
}

/* ── Sidebar bottom ── */
.tvSidebarBottom {
  margin-top: auto;
  border-top: 1px solid var(--tv-border);
  padding-top: 14px;
}
.tvThemeSection { padding: 0 0 12px; }
.tvThemeBtns {
  display: flex;
  gap: 6px;
  padding: 0 10px;
  margin-bottom: 8px;
}
.tvThemeBtn {
  flex: 1;
  padding: 7px 0;
  text-align: center;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.08);
  background: #17171b;
  color: var(--tv-text-dim);
  font-size: 11px;
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.tvThemeBtn.isActive {
  background: var(--tv-accent-soft);
  border-color: var(--tv-accent);
  color: var(--tv-accent);
}
.tvThemeLabel {
  padding: 0 10px;
  font-size: 10.5px;
  color: var(--tv-text-dim);
  margin: 0;
  line-height: 1.5;
}
.tvSidebarStatus {
  padding: 0 10px 2px;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 10.5px;
  color: var(--tv-text-dim);
}
.tvStatusDot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #10b981;
  animation: tvPulse 2s ease-in-out infinite;
  flex: 0 0 6px;
  display: inline-block;
}
.tvStatusDot.error { background: #ef4444; animation: none; }

/* ── TOPBAR ── */
.tvMain {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}
.tvTopbar {
  height: 52px;
  padding: 0 24px;
  border-bottom: 1px solid var(--tv-border);
  background: var(--tv-bg);
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 0 0 52px;
}
.tvTopbarTitle {
  display: flex;
  align-items: center;
  gap: 10px;
}
.tvTopbarAccent {
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: var(--tv-accent);
  box-shadow: 0 0 8px var(--tv-glow);
  flex: 0 0 5px;
}
.tvTopbarPage {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -.01em;
  color: var(--tv-text);
}
.tvTopbarSub {
  font-size: 11px;
  color: var(--tv-text-dim);
  padding-left: 4px;
}
.tvTopbarSpacer { flex: 1; }
.tvTokenDisplay {
  font-size: 11px;
  color: var(--tv-text-dim);
  font-family: 'JetBrains Mono', monospace;
}
.tvReloadBtn {
  background: none;
  border: 1px solid var(--tv-border);
  color: var(--tv-text-muted);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.tvReloadBtn:hover { background: var(--tv-surface); color: var(--tv-text); }

/* ── Content scroll area ── */
.tvContent {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ══════════════════════════════════════════
   LANDING PAGE — v1.02 dark redesign
   ══════════════════════════════════════════ */
.landingView {
  background: var(--tv-bg);
  min-height: 100%;
}

/* Disclaimer */
.tvDisclaimer {
  background: rgba(245,158,11,0.07);
  border-bottom: 1px solid rgba(245,158,11,0.18);
  padding: 9px 28px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11.5px;
  color: var(--tv-text-sec);
  line-height: 1.5;
}
.tvDisclaimer strong { color: #f59e0b; font-weight: 600; }

/* Hero */
.tvHero {
  display: flex;
  align-items: center;
  gap: 48px;
  padding: 52px 52px 40px;
}
.tvHeroText { flex: 1; min-width: 0; }
.tvHeroEyebrow {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--tv-text-dim);
  margin: 0 0 18px;
}
.tvHeroHeadline {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: clamp(28px, 5vw, 50px);
  font-weight: 800;
  line-height: 1.28;
  letter-spacing: -.02em;
  color: var(--tv-text);
  margin: 0 0 22px;
}
@media (max-width: 768px) {
  .tvHeroHeadline { font-size: clamp(26px, 7vw, 40px); line-height: 1.3; }
  .tvHero { flex-direction: column; padding: 32px 20px 28px; gap: 28px; }
  .tvHeroDesc { font-size: 14px; margin-bottom: 24px; }
}
.tvHeroHeadline em {
  font-style: normal;
  color: var(--tv-accent);
}
.tvHeroDesc {
  font-size: 15px;
  color: var(--tv-text-sec);
  line-height: 1.72;
  margin: 0 0 36px;
  max-width: 400px;
}
.tvHeroCtas { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.tvCtaPrimary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 13px 26px;
  border-radius: 9px;
  background: var(--tv-accent);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  border: none;
  box-shadow: 0 0 28px var(--tv-glow);
  letter-spacing: .01em;
  cursor: pointer;
  transition: opacity .15s;
}
.tvCtaPrimary:hover { opacity: .88; }
.tvCtaSecondary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 13px 24px;
  border-radius: 9px;
  border: 1px solid var(--tv-border-mid);
  color: var(--tv-text-sec);
  font-size: 14px;
  font-weight: 500;
  background: rgba(255,255,255,0.04);
  cursor: pointer;
  transition: background .15s;
}
.tvCtaSecondary:hover { background: rgba(255,255,255,0.08); }

/* Hero visual */
.tvHeroVisual {
  flex: 0 0 300px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Stats row */
.tvStats {
  margin: 0 52px 36px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  border: 1px solid var(--tv-border);
  border-radius: 12px;
  background: var(--tv-surface);
  overflow: hidden;
}
.tvStat {
  padding: 20px 24px;
  border-right: 1px solid var(--tv-border);
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.tvStat:last-child { border-right: none; }
.tvStatNum {
  font-family: 'JetBrains Mono', 'Fira Mono', monospace;
  font-size: 30px;
  font-weight: 600;
  line-height: 1;
}
.tvStatHome  { color: var(--tv-home); }
.tvStatTarot { color: var(--tv-tarot); }
.tvStatXam   { color: var(--tv-xam); }
.tvStatLabel {
  font-size: 11px;
  color: var(--tv-text-muted);
  font-weight: 500;
}

/* Feature cards */
.tvFeatureCards {
  padding: 0 52px 52px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.tvFeatureCard {
  background: var(--tv-surface);
  border: 1px solid var(--tv-border);
  border-radius: 14px;
  padding: 26px;
  cursor: pointer;
  text-align: left;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 0;
  transition: border-color .2s;
}
.tvFeatureCard:hover { border-color: rgba(255,255,255,0.15); }
.tvFeatureIcon {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
}
.tvFeatureIconChart { background: rgba(168,85,247,0.1); color: var(--tv-chart); box-shadow: 0 0 20px rgba(168,85,247,0.2); }
.tvFeatureIconXam   { background: rgba(251,191,36,0.1);  color: var(--tv-xam);   box-shadow: 0 0 20px rgba(251,191,36,0.2); }
.tvFeatureIconTarot { background: rgba(251,113,133,0.1); color: var(--tv-tarot); box-shadow: 0 0 20px rgba(251,113,133,0.2); }
.tvFeatureCard:hover .tvFeatureIconChart { box-shadow: 0 0 30px rgba(168,85,247,0.35); }
.tvFeatureCard:hover .tvFeatureIconXam   { box-shadow: 0 0 30px rgba(251,191,36,0.35); }
.tvFeatureCard:hover .tvFeatureIconTarot { box-shadow: 0 0 30px rgba(251,113,133,0.35); }
.tvFeatureTag {
  font-size: 11px;
  font-weight: 600;
  color: var(--tv-xam);
  letter-spacing: .06em;
  text-transform: uppercase;
  margin-bottom: 6px;
  display: block;
}
.tvFeatureCard h2 {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 10px;
  letter-spacing: -.01em;
  color: var(--tv-text);
}
.tvFeatureCard p {
  font-size: 13px;
  color: var(--tv-text-muted);
  line-height: 1.65;
  margin: 0 0 20px;
  flex: 1;
}
.tvFeatureCta {
  font-size: 12.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
}
.tvFeatureCtaChart { color: var(--tv-chart); }
.tvFeatureCtaXam   { color: var(--tv-xam); }
.tvFeatureCtaTarot { color: var(--tv-tarot); }

/* Philosophy */
.tvPhilosophy {
  margin: 0 52px;
  padding: 28px 0 52px;
  border-top: 1px solid var(--tv-border);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}
.tvPhilosophyItem { display: flex; flex-direction: column; gap: 6px; }
.tvPhilosophyItem strong { font-size: 13px; font-weight: 600; color: var(--tv-text); }
.tvPhilosophyItem span  { font-size: 12px; color: var(--tv-text-muted); line-height: 1.6; }

/* ══════════════════════════════════════════
   DARK OVERRIDES — existing components
   ══════════════════════════════════════════ */

/* Hide old topbar (replaced by sidebar + tvTopbar) */
.topbar { display: none !important; }

/* Forms dark */
input, select, textarea {
  background: var(--tv-surface-soft) !important;
  color: var(--tv-text) !important;
  border-color: var(--tv-border-mid) !important;
}
input::placeholder { color: var(--tv-text-dim) !important; }

/* Primary action button */
.primaryAction {
  background: var(--tv-accent) !important;
  color: #fff !important;
  border: none !important;
  box-shadow: 0 0 20px var(--tv-glow) !important;
}
.secondaryAction {
  background: var(--tv-surface-soft) !important;
  color: var(--tv-text-sec) !important;
  border-color: var(--tv-border-mid) !important;
}

/* Chart builder dark */
.chartBuilder, .chartBuilder * { color-scheme: dark; }
.chartBuilder { background: var(--tv-bg) !important; color: var(--tv-text); }
.chartPanel, .chartToolPane { background: var(--tv-bg) !important; color: var(--tv-text) !important; }
.chartPreview, .readingPanel, .jsonPanel { background: var(--tv-surface) !important; border-color: var(--tv-border) !important; color: var(--tv-text) !important; }
.chartToolTab { background: transparent !important; color: var(--tv-text-muted) !important; border-color: var(--tv-border) !important; }
.chartToolTab.isActive { background: var(--tv-surface) !important; color: var(--tv-text) !important; }
.chartHeader h1, .chartHeader .eyebrow, .chartHeader .intro { color: inherit !important; }
.fieldGroup, .fixturePanel { background: var(--tv-bg) !important; border-color: var(--tv-border) !important; }
.recordToolbar { background: var(--tv-surface) !important; border-color: var(--tv-border) !important; color: var(--tv-text-muted) !important; }
pre#jsonOutput { background: var(--tv-surface) !important; color: #a3e635 !important; border: none !important; }
/* Chart grid cells */
.tuViBoard, .palaceCell, .iztroPalaceCard { background: var(--tv-surface) !important; border-color: var(--tv-border-mid) !important; color: var(--tv-text) !important; }
.boDiagram, .chartOutputPane, #chartPreview { background: var(--tv-bg) !important; color: var(--tv-text) !important; }
/* Empty state & output messages */
.chartEmptyState, .chartPreview > *, .readingPanel > * { color: var(--tv-text-muted) !important; }
p.chartPrompt, .chartPrompt { color: var(--tv-text-muted) !important; background: transparent !important; }

/* Xin Xăm dark */
.xamView { background: var(--tv-bg); }
.xamPickerInner { background: var(--tv-bg); }
.xamSymbol { color: var(--tv-xam); text-shadow: 0 0 30px rgba(251,191,36,0.4); }
.xamTitle { color: var(--tv-text); }
.xamSubtitle { color: var(--tv-text-sec); }
.xamTopic {
  background: var(--tv-surface) !important;
  color: var(--tv-text-sec) !important;
  border: 1px solid var(--tv-border) !important;
}
.xamTopic.isActive {
  background: rgba(251,191,36,0.1) !important;
  color: var(--tv-xam) !important;
  border-color: rgba(251,191,36,0.4) !important;
}
.xamDrawBtn {
  background: rgba(251,191,36,0.1) !important;
  color: var(--tv-xam) !important;
  border: 1px solid rgba(251,191,36,0.4) !important;
  box-shadow: 0 0 24px rgba(251,191,36,0.15) !important;
}
.xamDrawBtn:hover {
  background: rgba(251,191,36,0.18) !important;
}
.xamNote { color: var(--tv-text-dim); }
.xamResultCard { animation: tvCardIn .4s ease-out; }
.xamTho { border-left-color: var(--tv-xam) !important; background: var(--tv-surface) !important; color: var(--tv-text-sec) !important; }
.xamResetBtn { background: var(--tv-surface) !important; color: var(--tv-text-sec) !important; border-color: var(--tv-border-mid) !important; }
.xamHopMenh { background: rgba(251,191,36,0.12) !important; color: var(--tv-xam) !important; border-color: rgba(251,191,36,0.3) !important; }

/* Knowledge view dark */
.appShell { background: var(--tv-bg); }
.filterRail { background: var(--tv-surface); border-color: var(--tv-border); }
.workspace, .detailPane { background: var(--tv-bg); }
.record { background: var(--tv-surface); border-color: var(--tv-border); }
.record:hover, .record.isActive { border-color: var(--tv-accent); }
.badge { background: var(--tv-accent-soft); color: var(--tv-accent); }
.sectionLabel { color: var(--tv-text-dim); }
.eyebrow { color: var(--tv-text-dim); }

/* Responsive: hide sidebar, stack on mobile */
@media (max-width: 768px) {
  .tvSidebar { display: none; }
  .tvHero { flex-direction: column; padding: 32px 20px 24px; gap: 32px; }
  .tvHeroVisual { flex: none; }
  .tvStats { grid-template-columns: repeat(2, 1fr); margin: 0 20px 24px; }
  .tvFeatureCards { grid-template-columns: 1fr; padding: 0 20px 32px; }
  .tvPhilosophy { grid-template-columns: 1fr; margin: 0 20px; }
  .tvDisclaimer { padding: 9px 20px; }
}

/* ── Legacy landing override (ensure old classes don't show) ── */
.landingHero, .landingStats, .landingFeatures, .landingPhilosophy { display: none !important; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 68px;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: rgba(255, 255, 255, .94);
  border-bottom: 1px solid var(--hairline);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
}

.brandMark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.brand strong,
.brand small {
  display: block;
  letter-spacing: 0;
}

.brand strong {
  font-size: 16px;
  font-weight: 600;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.topbarActions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.viewSwitch {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--hairline);
  border-radius: 12px;
  background: var(--surface-soft);
}

.viewButton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border: 0;
  border-radius: 8px;
  padding: 7px 12px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.viewButton.isActive {
  background: var(--canvas);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(15, 23, 42, .12);
}

.syncStatus,
.secondaryAction,
.badge,
.recordType,
.recordMeta span,
.detailTag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
}

.syncStatus {
  background: var(--success-soft);
  color: var(--forest);
  border: 1px solid #c6e7cf;
  white-space: nowrap;
}

.secondaryAction,
.openDetail,
.primaryAction {
  border: 1px solid var(--hairline);
  background: var(--canvas);
  color: var(--ink);
  border-radius: 12px;
  min-height: 40px;
  padding: 8px 14px;
  font-weight: 600;
}

.primaryAction {
  border-color: var(--red);
  background: var(--red);
  color: #fff;
}

.secondaryAction:active,
.openDetail:active,
.primaryAction:active {
  background: var(--surface-soft);
}

.primaryAction:active {
  background: #761d17;
}

.appShell {
  display: grid;
  grid-template-columns: 282px minmax(0, 1fr) 360px;
  min-height: calc(100vh - 68px);
}

.filterRail,
.detailPane {
  background: var(--canvas);
}

.filterRail {
  border-right: 1px solid var(--hairline);
  padding: 22px;
}

.railSection + .railSection {
  margin-top: 28px;
}

.sectionLabel,
.eyebrow {
  margin: 0 0 12px;
  color: var(--coral);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 16px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--canvas);
  color: var(--ink);
}

input:focus,
select:focus,
button:focus-visible,
.record:focus-visible {
  outline: 2px solid #458fff;
  outline-offset: 2px;
}

.sourcePolicy {
  display: grid;
  gap: 8px;
  padding: 16px;
  border-radius: 12px;
  background: var(--surface-cream);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
}

.sourcePolicy span {
  color: var(--body);
}

.workspace {
  min-width: 0;
  padding: 26px;
}

.workspaceHeader {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 320px);
  gap: 24px;
  align-items: end;
  margin-bottom: 18px;
}

h1,
h2,
p {
  letter-spacing: 0;
}

h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(28px, 4vw, 42px);
  font-weight: 500;
  line-height: 1.12;
}

.intro {
  max-width: 720px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
}

.metricGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metricGrid div {
  min-height: 86px;
  padding: 16px;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
}

.metricGrid div:nth-child(2) {
  background: var(--forest);
}

.metricGrid span,
.metricGrid small {
  display: block;
}

.metricGrid span {
  font-size: 24px;
  font-weight: 600;
}

.metricGrid small {
  margin-top: 5px;
  color: rgba(255, 255, 255, .72);
  font-size: 12px;
}

.recordToolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 4px;
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
  color: var(--muted);
  font-size: 13px;
}

.recordToolbar span:first-child {
  color: var(--ink);
  font-weight: 600;
}

.recordList {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.record {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--hairline);
  border-radius: 12px;
  background: var(--surface);
  transition: border-color .16s ease, background-color .16s ease;
}

.record:hover,
.record.isActive {
  border-color: #9297a0;
  background: #fffdfa;
}

.recordType {
  width: max-content;
  background: #eef6ff;
  color: var(--link);
}

.record h2 {
  margin: 10px 0 8px;
  color: var(--ink);
  font-size: 22px;
  font-weight: 500;
  line-height: 1.25;
}

.summaryText {
  margin: 0;
  color: var(--body);
  line-height: 1.55;
}

.recordMeta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
}

.recordMeta span {
  background: var(--surface-soft);
  color: var(--body);
}

.recordSide {
  display: grid;
  justify-items: end;
  align-content: space-between;
  gap: 12px;
}

.badge {
  max-width: 180px;
  justify-content: center;
  background: var(--danger-soft);
  color: var(--coral);
  border: 1px solid #ffd7c4;
  text-align: center;
}

.badge.isGood {
  background: var(--success-soft);
  color: var(--forest);
  border-color: #c6e7cf;
}

.openDetail {
  min-width: 92px;
}

.detailPane {
  position: sticky;
  top: 68px;
  height: calc(100vh - 68px);
  overflow: auto;
  border-left: 1px solid var(--hairline);
  padding: 22px;
}

.detailCard {
  display: grid;
  gap: 18px;
}

.detailHero {
  padding: 22px;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
}

.detailHero .sectionLabel {
  color: var(--yellow);
}

.detailHero h2 {
  margin: 0;
  font-size: 30px;
  font-weight: 500;
  line-height: 1.15;
}

.detailHero p {
  margin: 10px 0 0;
  color: rgba(255, 255, 255, .76);
  line-height: 1.5;
}

.detailBlock {
  padding: 16px;
  border: 1px solid var(--hairline);
  border-radius: 12px;
  background: var(--canvas);
}

.detailBlock h3 {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
}

.detailBlock p,
.detailBlock li {
  color: var(--body);
  line-height: 1.55;
}

.detailBlock p {
  margin: 0;
}

.detailFacts {
  display: grid;
  gap: 8px;
  margin: 0;
}

.detailFacts div {
  display: grid;
  grid-template-columns: minmax(92px, auto) 1fr;
  gap: 10px;
  align-items: baseline;
}

.detailFacts dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.detailFacts dd {
  margin: 0;
  color: var(--body);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.detailSourceList {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.detailSourceList li {
  padding: 10px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.detailTags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.detailTag {
  background: var(--surface-soft);
  color: var(--body);
}

.detailEmpty {
  display: grid;
  gap: 8px;
  padding: 20px;
  border-radius: 12px;
  background: var(--surface-soft);
}

.detailEmpty h2 {
  margin: 0;
  color: var(--ink);
  font-size: 22px;
  font-weight: 500;
}

.detailEmpty p {
  margin: 0;
  line-height: 1.5;
}

.empty {
  padding: 26px;
  border: 1px dashed var(--hairline);
  border-radius: 12px;
  background: var(--canvas);
  color: var(--muted);
}

.chartBuilder {
  display: grid;
  grid-template-columns: minmax(420px, 560px) minmax(0, 1fr);
  gap: 22px;
  min-height: calc(100vh - 68px);
  padding: 26px;
  background:
    linear-gradient(135deg, rgba(143, 36, 29, .07), transparent 28%),
    linear-gradient(315deg, rgba(10, 46, 14, .08), transparent 32%),
    var(--bg);
}

.chartBuilder[hidden] {
  display: none;
}

.chartPanel,
.chartOutput {
  min-width: 0;
}

.chartPanel {
  display: grid;
  gap: 18px;
  align-content: start;
  padding: 24px;
  border: 1px solid #e4d6b5;
  border-radius: 16px;
  background: var(--surface-parchment);
  box-shadow: 0 18px 45px rgba(84, 58, 24, .08);
}

.chartHeader h1 {
  font-size: clamp(30px, 4vw, 44px);
}

.chartForm {
  display: grid;
  gap: 18px;
}

.wideField {
  margin-bottom: 0;
}

.fieldGroup {
  min-width: 0;
  margin: 0;
  padding: 16px;
  border: 1px solid #e4d6b5;
  border-radius: 12px;
  background: rgba(255, 255, 255, .62);
}

.fieldGroup legend {
  padding: 0 8px;
  color: var(--red);
  font-size: 13px;
  font-weight: 800;
}

.inlineFields {
  display: grid;
  gap: 12px;
}

.threeFields {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.radioRow {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin-top: 10px;
  color: var(--ink);
  font-weight: 600;
}

.radioRow label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.radioRow input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--red);
}

.formActions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding-top: 4px;
}

.formActions button {
  min-width: 124px;
}

.formActions button:disabled {
  cursor: not-allowed;
  opacity: .48;
}

.chartOutput {
  display: grid;
  grid-template-rows: minmax(420px, auto) minmax(260px, 1fr);
  gap: 18px;
}

.chartPreview,
.jsonPanel {
  border: 1px solid var(--hairline);
  border-radius: 16px;
  background: var(--canvas);
  overflow: hidden;
}

.previewEmpty {
  height: 100%;
  min-height: 420px;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
}

.previewEmpty h2 {
  margin: 0;
  color: var(--ink);
  font-size: 26px;
  font-weight: 600;
}

.previewEmpty p {
  margin: 0;
  color: var(--muted);
}

.previewBoard {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, minmax(112px, 1fr));
  grid-template-rows: repeat(4, minmax(108px, 1fr));
  gap: 8px;
  min-height: 540px;
  padding: 16px;
  background:
    linear-gradient(90deg, rgba(217, 191, 122, .16) 1px, transparent 1px),
    linear-gradient(rgba(217, 191, 122, .16) 1px, transparent 1px),
    #fffaf0;
  background-size: 22px 22px;
}

.previewCenter {
  z-index: 2;
  grid-row: 2 / span 2;
  grid-column: 2 / span 2;
  display: grid;
  place-content: center;
  gap: 10px;
  padding: 20px;
  border-radius: 16px;
  background: var(--primary);
  color: #fff;
  text-align: center;
}

.previewCenter .sectionLabel {
  margin: 0;
  color: var(--yellow);
}

.previewCenter h2 {
  margin: 0;
  font-size: 30px;
  font-weight: 600;
}

.previewCenter p,
.previewCenter span {
  margin: 0;
  color: rgba(255, 255, 255, .78);
}

.palaceCell {
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--gold-line);
  border-radius: 12px;
  background: rgba(255, 255, 255, .82);
}

.palaceCell strong {
  color: var(--red);
  font-size: 22px;
}

.palaceCell span {
  color: var(--ink);
  font-weight: 700;
}

.palaceCell small {
  color: var(--muted);
}

.jsonPanel {
  display: grid;
  grid-template-rows: auto 1fr;
}

.jsonPanel .recordToolbar {
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
}

.jsonToolbarActions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.toolbarCopyButton {
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid #d9b66f;
  border-radius: 999px;
  background: rgba(255, 248, 231, .92);
  color: var(--red);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.1;
  white-space: nowrap;
}

.jsonToolbarActions .toolbarCopyButton,
.readingToolbarActions .toolbarCopyButton {
  min-height: 30px;
  padding: 5px 10px;
  font-size: .74rem;
}

.toolbarCopyButton:disabled {
  cursor: not-allowed;
  opacity: .45;
}

@media (max-width: 560px) {
  .jsonPanel .recordToolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .jsonToolbarActions {
    width: 100%;
    justify-content: flex-start;
    gap: 6px;
  }

  .jsonToolbarActions #jsonStatus {
    flex: 1 1 100%;
  }

  .jsonToolbarActions .toolbarCopyButton,
  .readingToolbarActions .toolbarCopyButton {
    padding: 5px 8px;
    font-size: .7rem;
  }
}

#jsonOutput {
  min-height: 240px;
  max-height: 420px;
  margin: 0;
  padding: 18px;
  overflow: auto;
  background: #101419;
  color: #dbe8ff;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.55;
}

@media (max-width: 1180px) {
  .appShell {
    grid-template-columns: 260px minmax(0, 1fr);
  }

  .detailPane {
    grid-column: 1 / -1;
    position: static;
    height: auto;
    border-top: 1px solid var(--hairline);
    border-left: none;
  }

  .chartBuilder {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .topbar,
  .topbarActions,
  .record,
  .workspaceHeader,
  .recordToolbar {
    display: grid;
  }

  .topbar {
    align-items: stretch;
  }

  .viewSwitch {
    width: 100%;
  }

  .viewButton {
    flex: 1;
  }

  .topbarActions {
    grid-template-columns: 1fr auto;
  }

  .appShell {
    display: block;
  }

  .filterRail {
    border-right: none;
    border-bottom: 1px solid var(--hairline);
  }

  .workspace {
    padding: 20px;
  }

  .recordSide {
    justify-items: start;
  }

  .metricGrid {
    grid-template-columns: 1fr 1fr;
  }

  .chartBuilder {
    padding: 16px;
  }

  .threeFields,
  .inlineFields {
    grid-template-columns: 1fr;
  }

  .previewBoard {
    grid-template-columns: repeat(4, minmax(72px, 1fr));
    grid-template-rows: repeat(4, minmax(92px, auto));
    min-height: 440px;
    gap: 6px;
    padding: 10px;
  }

  .palaceCell {
    padding: 9px;
  }

  .palaceCell strong {
    font-size: 18px;
  }

  .palaceCell span,
  .palaceCell small {
    font-size: 12px;
  }

  .previewCenter {
    padding: 12px;
  }

  .previewCenter h2 {
    font-size: 20px;
  }
}

/* Warm research-portal redesign inspired by the user's reference site. */
:root {
  --canvas: #fffaf0;
  --bg: #f3e6d1;
  --surface: #fffdf7;
  --surface-soft: #f7ecd7;
  --surface-cream: #efe0c3;
  --surface-parchment: #fff6e4;
  --ink: #261410;
  --body: #4f3a31;
  --muted: #7a675b;
  --hairline: #d7bf8a;
  --gold-line: #c89a3d;
  --primary: #7c2019;
  --primary-active: #5d1712;
  --coral: #9f3a20;
  --red: #8f241d;
  --forest: #16391f;
  --mint: #bcd7b4;
  --yellow: #f2c464;
  --link: #8f241d;
  --danger-soft: #fff0e5;
  --success-soft: #eef7e7;
}

body {
  background:
    linear-gradient(90deg, rgba(124, 32, 25, .035) 1px, transparent 1px),
    linear-gradient(rgba(124, 32, 25, .035) 1px, transparent 1px),
    radial-gradient(circle at 18% 6%, rgba(242, 196, 100, .28), transparent 28%),
    linear-gradient(180deg, #f8eddc 0%, #efe0c8 100%);
  background-size: 28px 28px, 28px 28px, auto, auto;
  color: var(--body);
}

.topbar {
  min-height: 82px;
  padding: 14px clamp(16px, 3vw, 36px);
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto minmax(220px, 1fr);
  background:
    linear-gradient(90deg, rgba(242, 196, 100, .13), transparent 18%, transparent 82%, rgba(242, 196, 100, .13)),
    rgba(72, 24, 18, .96);
  border-bottom: 1px solid rgba(242, 196, 100, .44);
  box-shadow: 0 12px 34px rgba(71, 28, 12, .18);
}

.brand {
  color: #fff7e7;
}

.brandMark {
  width: 46px;
  height: 46px;
  border: 1px solid rgba(242, 196, 100, .76);
  border-radius: 999px;
  background: linear-gradient(180deg, #a23a2a, #64170f);
  box-shadow: inset 0 0 0 3px rgba(255, 246, 224, .08), 0 8px 20px rgba(40, 12, 8, .28);
}

.brand strong {
  color: #fff9ea;
  font-size: 17px;
  font-weight: 800;
}

.brand small {
  color: #e5cfaa;
}

.viewSwitch {
  justify-self: center;
  align-self: center;
  border-color: rgba(200, 154, 61, .7);
  border-radius: 999px;
  background: #f7ead1;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .72), 0 8px 22px rgba(38, 20, 16, .16);
}

.viewButton {
  min-height: 38px;
  border-radius: 999px;
  color: #7c5947;
}

.viewButton.isActive {
  background: linear-gradient(180deg, #9b2d23, #751d17);
  color: #fff8e8;
  box-shadow: 0 5px 16px rgba(124, 32, 25, .28);
}

.topbarActions {
  justify-self: end;
}

.syncStatus {
  border-color: #bdd8a9;
  background: #eef7e7;
  color: #1c4a29;
}

.secondaryAction,
.openDetail,
.primaryAction {
  border-color: rgba(200, 154, 61, .58);
  border-radius: 999px;
  background: #fff7e8;
  color: var(--ink);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .82);
}

.primaryAction {
  border-color: #7c2019;
  background: linear-gradient(180deg, #9b2d23, #741d17);
  color: #fff7e5;
}

.appShell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 22px;
  width: min(1320px, calc(100% - 32px));
  min-height: auto;
  margin: 0 auto;
  padding: 24px 0 46px;
}

.filterRail,
.workspace,
.detailPane {
  min-width: 0;
}

.filterRail {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(260px, .75fr);
  gap: 18px;
  padding: 18px;
  border: 1px solid rgba(200, 154, 61, .45);
  border-radius: 26px;
  background:
    linear-gradient(135deg, rgba(255, 250, 240, .95), rgba(247, 236, 215, .92)),
    var(--surface-parchment);
  box-shadow: 0 20px 48px rgba(79, 52, 23, .12);
}

.railSection {
  min-width: 0;
}

.railSection + .railSection {
  margin-top: 0;
}

.railSection:first-child {
  display: grid;
  grid-template-columns: repeat(3, minmax(170px, 1fr));
  gap: 14px;
  align-items: end;
}

.railSection:first-child .sectionLabel {
  grid-column: 1 / -1;
  margin-bottom: 0;
}

.sectionLabel,
.eyebrow {
  color: var(--coral);
  font-weight: 900;
  letter-spacing: .09em;
}

.field {
  margin-bottom: 0;
  color: var(--ink);
}

input,
select {
  min-height: 46px;
  border-color: rgba(200, 154, 61, .55);
  border-radius: 14px;
  background: rgba(255, 253, 247, .94);
}

input:focus,
select:focus,
button:focus-visible,
.record:focus-visible {
  outline-color: #b15c2f;
}

.sourcePolicy {
  height: 100%;
  border: 1px solid rgba(200, 154, 61, .42);
  border-radius: 20px;
  background: linear-gradient(180deg, #f2e2c6, #ead6b3);
}

.workspace {
  padding: 0;
}

.workspaceHeader {
  align-items: center;
  margin-bottom: 18px;
  padding: clamp(26px, 4vw, 42px);
  border: 1px solid rgba(242, 196, 100, .48);
  border-radius: 30px;
  background:
    linear-gradient(135deg, rgba(242, 196, 100, .16), transparent 34%),
    linear-gradient(180deg, #6f1c16 0%, #32130f 100%);
  box-shadow: 0 26px 60px rgba(70, 27, 13, .18);
}

.workspaceHeader .eyebrow {
  color: #f2c464;
}

.workspaceHeader h1 {
  max-width: 780px;
  color: #fff8e6;
  font-size: clamp(36px, 6vw, 62px);
  font-weight: 800;
}

.workspaceHeader .intro {
  color: #ead9b5;
  font-size: 16px;
}

.metricGrid div {
  min-height: 104px;
  border: 1px solid rgba(242, 196, 100, .42);
  border-radius: 22px;
  background: rgba(255, 247, 231, .1);
}

.metricGrid div:nth-child(2) {
  background: rgba(22, 57, 31, .88);
}

.metricGrid span {
  font-size: 30px;
  font-weight: 800;
}

.recordToolbar {
  padding: 14px 2px;
  border-color: rgba(124, 32, 25, .2);
  color: var(--muted);
}

.recordList {
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.record {
  display: flex;
  min-height: 238px;
  flex-direction: column;
  justify-content: space-between;
  border-color: rgba(200, 154, 61, .46);
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(255, 253, 247, .96), rgba(255, 246, 226, .94)),
    var(--surface);
  box-shadow: 0 18px 42px rgba(79, 52, 23, .09);
}

.record:hover,
.record.isActive {
  border-color: rgba(143, 36, 29, .68);
  background: #fffaf0;
  transform: translateY(-1px);
}

.recordType {
  background: #f6e4c5;
  color: var(--red);
}

.record h2 {
  color: var(--ink);
  font-size: 26px;
  font-weight: 800;
}

.recordMeta span,
.detailTag {
  background: #f3e6d1;
  color: #5a4337;
}

.recordSide {
  display: flex;
  flex-direction: row-reverse;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
}

.badge {
  border-color: #efc8aa;
  background: #fff0e5;
  color: var(--coral);
}

.badge.isGood {
  border-color: #bdd8a9;
  background: #eef7e7;
}

.detailPane {
  position: static;
  height: auto;
  overflow: visible;
  padding: 0;
  border-left: 0;
  background: transparent;
}

.detailCard {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.detailHero {
  grid-column: 1 / -1;
  padding: 28px;
  border: 1px solid rgba(242, 196, 100, .48);
  border-radius: 28px;
  background:
    linear-gradient(135deg, rgba(242, 196, 100, .15), transparent 36%),
    linear-gradient(180deg, #742018, #36130f);
  box-shadow: 0 20px 46px rgba(70, 27, 13, .16);
}

.detailHero h2 {
  color: #fff8e6;
  font-weight: 800;
}

.detailBlock,
.detailEmpty {
  border-color: rgba(200, 154, 61, .44);
  border-radius: 22px;
  background: rgba(255, 253, 247, .9);
  box-shadow: 0 14px 32px rgba(79, 52, 23, .08);
}

.detailSourceList li {
  background: #f4e7d1;
}

.chartBuilder {
  grid-template-columns: minmax(360px, 520px) minmax(0, 1fr);
  gap: 22px;
  width: min(1320px, calc(100% - 32px));
  min-height: auto;
  margin: 0 auto;
  padding: 24px 0 46px;
  background: transparent;
}

.chartBuilder[hidden] {
  display: none;
}

.chartPanel {
  padding: 24px;
  border-color: rgba(200, 154, 61, .54);
  border-radius: 30px;
  background:
    linear-gradient(180deg, rgba(255, 253, 247, .96), rgba(246, 231, 203, .96)),
    var(--surface-parchment);
}

.chartHeader {
  margin: -4px -4px 8px;
  padding: 24px;
  border: 1px solid rgba(242, 196, 100, .42);
  border-radius: 24px;
  background: linear-gradient(180deg, #7d231c, #4b1712);
}

.chartHeader .eyebrow {
  color: #f2c464;
}

.chartHeader h1 {
  color: #fff8e6;
  font-weight: 800;
}

.chartHeader .intro {
  color: #e6d0ac;
}

.fixturePanel {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid rgba(200, 154, 61, .45);
  border-radius: 20px;
  background: rgba(255, 250, 240, .72);
}

.fixturePanel p {
  margin: 0;
  color: var(--body);
  line-height: 1.5;
}

.fixturePanel .sectionLabel {
  margin-bottom: 6px;
}

.fixtureControls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.fixturePanel small {
  color: var(--muted);
  line-height: 1.4;
}

.fieldGroup {
  border-color: rgba(200, 154, 61, .45);
  border-radius: 20px;
  background: rgba(255, 250, 240, .72);
}

.fieldGroup legend {
  color: var(--red);
}

.chartPreview,
.jsonPanel,
.readingPanel {
  border: 1px solid rgba(200, 154, 61, .5);
  border-color: rgba(200, 154, 61, .5);
  border-radius: 26px;
  background: rgba(255, 253, 247, .92);
  box-shadow: 0 18px 42px rgba(79, 52, 23, .1);
}

.chartOutput {
  grid-template-rows: minmax(420px, auto) minmax(260px, auto) auto;
}

.readingPanel {
  overflow: hidden;
}

.readingBody {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.readingBody p {
  margin: 0;
  color: var(--body);
  line-height: 1.55;
}

.readingNotice {
  display: grid;
  gap: 6px;
  padding: 14px;
  border: 1px solid rgba(143, 36, 29, .22);
  border-radius: 18px;
  background: #fff0e5;
}

.readingNotice strong {
  color: var(--ink);
}

.readingNotice span {
  color: var(--body);
  line-height: 1.5;
}

.starLayerStatus {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid rgba(200, 154, 61, .42);
  border-radius: 18px;
  background: #fffaf0;
}

.starLayerStatus > strong {
  color: var(--ink);
}

.starLayerStatusGrid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.starLayerStatusGrid div {
  min-width: 0;
  padding: 10px;
  border: 1px solid rgba(200, 154, 61, .26);
  border-radius: 12px;
  background: rgba(255, 255, 255, .55);
}

.starLayerStatusGrid span {
  display: block;
  margin-bottom: 5px;
  color: var(--coral);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.starLayerStatusGrid p {
  margin: 0;
  color: var(--body);
  font-size: 12px;
  line-height: 1.4;
}

.starLayerStatusGrid .isLocked {
  border-color: rgba(143, 36, 29, .25);
  background: #fff0e5;
}

.starLayerStatusGrid .hasTransit {
  border-color: rgba(26, 111, 53, .24);
  background: #eef8ef;
}

.transitSummary {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid rgba(26, 111, 53, .24);
  border-radius: 18px;
  background: #eef8ef;
}

.transitSummary > strong {
  color: var(--ink);
}

.transitSummaryNote {
  margin: 0;
  color: var(--body);
  font-size: 12px;
  line-height: 1.45;
}

.transitSummaryGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.transitSummaryGroup {
  min-width: 0;
  padding: 10px;
  border: 1px solid rgba(26, 111, 53, .18);
  border-radius: 12px;
  background: rgba(255, 255, 255, .62);
}

.transitSummaryGroup span {
  display: block;
  margin-bottom: 5px;
  color: #0f6b34;
  font-size: 12px;
  font-weight: 800;
}

.transitSummaryGroup p {
  margin: 0;
  color: var(--body);
  font-size: 12px;
  line-height: 1.4;
}

.geminiReadingPanel {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid rgba(200, 154, 61, .28);
  border-left: 4px solid rgba(143, 36, 29, .36);
  border-radius: 12px;
  background: #fffdf8;
}

.geminiReadingPanel[hidden] {
  display: none !important;
}

.geminiReadingHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--ink);
}

.geminiReadingHeader div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.geminiReadingHeader span {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 800;
}

.geminiReadingHeaderActions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.geminiWarningText {
  color: var(--coral) !important;
}

.geminiReadingPanel p {
  margin: 0;
  color: var(--body);
  font-size: .9rem;
  line-height: 1.65;
}

.geminiFallbackNote {
  padding: 10px 12px;
  border: 1px solid rgba(92, 59, 138, .18);
  border-radius: 12px;
  background: rgba(255, 255, 255, .68);
}

.geminiReadingContent {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid rgba(200, 154, 61, .2);
  border-radius: 10px;
  background: #fffaf0;
}

.geminiReadingContent h4 {
  margin: 8px 0 0;
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.3;
}

.geminiReadingContent ul {
  margin: 0;
  padding-left: 18px;
  color: var(--body);
  font-size: .9rem;
  line-height: 1.58;
}

.geminiErrorAction {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(92, 59, 138, .28);
  border-radius: 999px;
  color: #4f2f7f;
  background: #fff;
  font-size: 12px;
  font-weight: 900;
  text-decoration: none;
}

.geminiRawError {
  color: var(--muted);
  font-size: 12px;
}

.geminiRawError p {
  margin-top: 6px;
  font-size: 12px;
}

.geminiReadingButton {
  border-color: rgba(143, 36, 29, .24);
  color: var(--coral);
  background: #fffaf0;
}

.geminiProviderSelect {
  min-height: 32px;
  max-width: 150px;
  padding: 0 28px 0 10px;
  border: 1px solid rgba(143, 36, 29, .2);
  border-radius: 999px;
  background-color: #fff;
  color: var(--coral);
  font-size: 12px;
  font-weight: 800;
}

.geminiPrintButton {
  flex: 0 0 auto;
  border-color: rgba(200, 154, 61, .42);
  color: var(--coral);
  background: #fffaf0;
}

.questionToolPanel,
.oracleToolPanel,
.internalReadingDetails {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid rgba(200, 154, 61, .3);
  border-radius: 12px;
  background: #fffdf8;
}

.internalReadingDetails > summary {
  cursor: pointer;
  color: var(--muted);
  font-size: .86rem;
  font-weight: 900;
}

.toolPanelHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.toolPanelHeader strong {
  color: var(--ink);
  font-size: 1rem;
}

.toolPanelHeader span {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 800;
}

.questionToolGrid {
  display: grid;
  grid-template-columns: minmax(140px, 180px) minmax(220px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.questionToolGrid label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--coral);
  font-size: .78rem;
  font-weight: 900;
}

.questionToolGrid select,
.questionToolGrid input {
  width: 100%;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid rgba(200, 154, 61, .34);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font-size: .9rem;
}

.geminiQuestionPanel,
.oracleResultPanel {
  display: grid;
  gap: 10px;
}

.geminiQuestionPanel[hidden],
.oracleResultPanel[hidden] {
  display: none !important;
}

.oracleCard {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid rgba(26, 111, 53, .22);
  border-radius: 14px;
  background: #eef8ef;
}

.oracleCard p {
  margin: 0;
  color: var(--body);
  font-size: .88rem;
  line-height: 1.55;
}

@media (max-width: 860px) {
  .geminiReadingHeader,
  .toolPanelHeader {
    align-items: flex-start;
    flex-direction: column;
  }

  .questionToolGrid {
    grid-template-columns: 1fr;
  }
}

.daiVanGuide {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid rgba(200, 154, 61, .42);
  border-radius: 18px;
  background: #fffaf0;
}

.daiVanGuide > strong {
  color: var(--ink);
}

.daiVanGuideFacts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.daiVanGuideFacts span {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid rgba(200, 154, 61, .28);
  border-radius: 12px;
  background: rgba(255, 255, 255, .6);
  color: var(--body);
  font-size: 12px;
}

.daiVanGuideFacts b {
  color: var(--ink);
}

.daiVanGuide ol {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 20px;
  color: var(--body);
  font-size: 12px;
  line-height: 1.42;
}

.daiVanGuide p,
.daiVanGuide small {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.42;
}

.readingList {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.readingToolbarActions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.readingToolbarActions span:first-child {
  color: var(--muted);
  font-weight: 600;
}

.chartSignalReading {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(143, 36, 29, .2);
  border-radius: 18px;
  background: rgba(255, 255, 255, .76);
}

.chartSignalReadingHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--ink);
}

.chartSignalReadingHeader span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 800;
}

.chartSignalReadingGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 9px;
}

.chartSignalCard {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 10px 11px;
  border: 1px solid rgba(200, 154, 61, .26);
  border-radius: 14px;
  background: rgba(255, 250, 240, .72);
}

.chartSignalCard small {
  color: var(--accent);
  font-size: .76rem;
  font-weight: 900;
  text-transform: uppercase;
}

.chartSignalCard b {
  color: var(--ink);
  font-size: .94rem;
}

.chartSignalCard span {
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.42;
}

.starPalaceReading {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(65, 135, 95, .28);
  border-radius: 18px;
  background: rgba(239, 251, 242, .78);
}

.starPalaceReading.isEmpty {
  border-color: rgba(200, 154, 61, .28);
  background: rgba(255, 250, 240, .76);
}

.starPalaceReadingHeader,
.starPalaceReadingCardHeader {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
  color: var(--ink);
}

.starPalaceReadingCardHeader {
  grid-template-columns: 1fr;
  gap: 3px;
}

.starPalaceReadingHeader span,
.starPalaceReadingCardHeader small {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 900;
  min-width: 0;
  overflow-wrap: anywhere;
  text-align: right;
}

.starPalaceReadingCardHeader small {
  text-align: left;
}

.starPalaceReadingIntro,
.starPalaceReading > p {
  margin: 0;
  color: var(--body);
  font-size: .9rem;
  line-height: 1.55;
}

.starPalaceReadingStats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 8px;
}

.starPalaceReadingStats div {
  display: grid;
  gap: 2px;
  padding: 9px 10px;
  border: 1px solid rgba(65, 135, 95, .2);
  border-radius: 14px;
  background: rgba(255, 255, 255, .66);
}

.starPalaceReadingStats b {
  color: var(--forest);
  font-size: 1.15rem;
}

.starPalaceReadingStats span {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 800;
}

.starPalaceReadingList {
  display: grid;
  gap: 10px;
}

.starPalaceReadingGroups {
  display: grid;
  gap: 12px;
}

.starPalaceGroup {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid rgba(65, 135, 95, .2);
  border-radius: 17px;
  background: rgba(255, 255, 255, .45);
}

.starPalaceGroupHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--ink);
}

.starPalaceGroupHeader span {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 900;
}

.starPalaceGroupList {
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
}

.starPalaceReadingCard {
  display: grid;
  gap: 7px;
  padding: 11px;
  border: 1px solid rgba(65, 135, 95, .2);
  border-radius: 16px;
  background: rgba(255, 255, 255, .72);
}

.starPalaceReadingCardHeader span {
  color: var(--accent);
  font-size: .78rem;
  font-weight: 900;
  text-transform: uppercase;
  min-width: 0;
  overflow-wrap: anywhere;
}

.starPalaceReadingCard h4,
.starPalaceReadingCard p,
.starPalaceReadingCard dl {
  margin: 0;
}

.starPalaceReadingCard h4 {
  color: var(--ink);
  font-size: 1rem;
}

.starBrightnessStatus {
  width: auto;
  max-width: 100%;
  padding: 3px 8px;
  border-radius: 11px;
  background: rgba(65, 135, 95, .1);
  color: var(--forest);
  font-size: .78rem;
  font-weight: 900;
  line-height: 1.35;
  overflow-wrap: anywhere;
  white-space: normal;
}

.starPalaceSynthesis {
  display: grid;
  gap: 3px;
  padding: 8px 9px;
  border-left: 3px solid rgba(65, 135, 95, .42);
  border-radius: 10px;
  background: rgba(239, 251, 242, .58);
}

.starPalaceSynthesis b {
  color: var(--ink);
  font-size: .82rem;
}

.starPalaceSynthesis span {
  color: var(--body);
  font-size: .84rem;
  line-height: 1.48;
  overflow-wrap: anywhere;
}

.sourceReferenceDetails {
  border: 1px solid rgba(200, 154, 61, .28);
  border-radius: 16px;
  background: rgba(255, 250, 240, .72);
}

.sourceReferenceDetails summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  color: var(--ink);
  font-weight: 900;
}

.sourceReferenceDetails summary small {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 800;
  text-align: right;
}

.sourceReferenceDetails .readingGroup {
  margin: 0 12px 12px;
}

.starPalaceReadingCard p,
.starPalaceReadingCard dd,
.starPalaceReadingCard footer {
  color: var(--body);
  font-size: .86rem;
  line-height: 1.48;
  overflow-wrap: anywhere;
}

.starPalaceReadingCard dl {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 7px 10px;
}

.starPalaceReadingCard dt {
  color: var(--ink);
  font-size: .82rem;
  font-weight: 900;
}

.starPalaceReadingCard dd {
  margin: 2px 0 0;
}

.starPalaceReadingCard footer {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 9px;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
}

.starPalaceMissing {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(200, 154, 61, .32);
  border-radius: 16px;
  background: rgba(255, 250, 240, .78);
}

.starPalaceMissing div:first-child {
  display: grid;
  gap: 4px;
}

.starPalaceMissing strong {
  color: var(--ink);
}

.starPalaceMissing span {
  color: var(--body);
  font-size: .84rem;
  line-height: 1.45;
}

.starPalaceMissingGrid {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.starPalaceMissingGrid span {
  padding: 6px 9px;
  border: 1px solid rgba(200, 154, 61, .24);
  border-radius: 999px;
  background: rgba(255, 255, 255, .72);
  color: var(--muted);
  font-size: .76rem;
  font-weight: 800;
}

.sourceReadingNarrative {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(143, 36, 29, .22);
  border-radius: 18px;
  background: rgba(255, 250, 240, .9);
}

.sourceReadingHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--ink);
}

.sourceReadingHeader span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 800;
}

.sourceReadingIntro,
.sourceReadingSection p {
  margin: 0;
  color: var(--body);
  font-size: .9rem;
  line-height: 1.55;
}

.sourceReadingSection {
  display: grid;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid rgba(200, 154, 61, .24);
}

.sourceReadingSection h4 {
  margin: 0;
  color: var(--accent);
  font-size: .92rem;
}

.sourceReadingSection ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.sourceReadingSection li {
  display: grid;
  gap: 4px;
  padding: 10px 11px;
  border: 1px solid rgba(200, 154, 61, .24);
  border-radius: 14px;
  background: rgba(255, 255, 255, .65);
}

.sourceReadingSection li b {
  color: var(--ink);
  font-size: .9rem;
}

.sourceReadingSection li span,
.sourceReadingSection li small {
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.45;
}

.sourceReadingDetails {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px 12px;
  margin: 4px 0;
  padding-top: 8px;
  border-top: 1px solid rgba(200, 154, 61, .22);
}

.sourceReadingDetails div {
  min-width: 0;
}

.sourceReadingDetails dt {
  color: var(--ink);
  font-size: .78rem;
  font-weight: 900;
}

.sourceReadingDetails dd {
  margin: 2px 0 0;
  color: var(--body);
  font-size: .8rem;
  line-height: 1.42;
}

.sourcePacketPreview {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(65, 135, 95, .28);
  border-radius: 18px;
  background: rgba(239, 251, 242, .78);
}

.sourcePacketPreviewHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--ink);
}

.sourcePacketPreviewHeader span {
  flex: 0 0 auto;
  color: #34724e;
  font-size: .82rem;
  font-weight: 800;
}

.sourcePacketPreviewGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}

.sourcePacketPreviewItem {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid rgba(65, 135, 95, .18);
  border-radius: 12px;
  background: rgba(255, 255, 255, .72);
}

.sourcePacketPreviewItem b {
  color: var(--ink);
  font-size: .84rem;
}

.sourcePacketPreviewItem span,
.sourcePacketPreviewItem small {
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.35;
}

.readingGroup {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(200, 154, 61, .28);
  border-radius: 18px;
  background: rgba(255, 250, 240, .62);
}

.readingGroupHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--ink);
}

.readingGroupHeader strong {
  font-size: .95rem;
}

.readingGroupHeader span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 700;
}

.readingList button {
  width: 100%;
  display: grid;
  gap: 5px;
  padding: 13px;
  border: 1px solid rgba(200, 154, 61, .42);
  border-radius: 16px;
  background: #fffaf0;
  color: var(--body);
  text-align: left;
}

.readingList button:hover {
  border-color: rgba(143, 36, 29, .62);
}

.readingList strong {
  color: var(--ink);
}

.readingList span,
.readingList small {
  color: var(--muted);
}

.readingList em {
  width: fit-content;
  max-width: 100%;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(143, 36, 29, .08);
  color: var(--accent);
  font-size: .78rem;
  font-style: normal;
  line-height: 1.35;
}

.readingEmpty {
  padding: 14px;
  border: 1px dashed rgba(143, 36, 29, .32);
  border-radius: 16px;
  color: var(--muted);
}

.uploadField small {
  color: var(--muted);
  font-weight: 500;
  line-height: 1.45;
}

.fieldHint {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.45;
}

.tuViBoard {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, minmax(118px, 1fr));
  grid-template-rows: repeat(4, minmax(120px, auto));
  gap: 3px;
  min-height: 540px;
  padding: 10px;
  border-radius: 22px;
  background:
    linear-gradient(90deg, rgba(200, 154, 61, .16) 1px, transparent 1px),
    linear-gradient(rgba(200, 154, 61, .16) 1px, transparent 1px),
    #fff8e8;
  background-size: 20px 20px;
}

.tuViCenter {
  z-index: 2;
  grid-row: 2 / span 2;
  grid-column: 2 / span 2;
  display: grid;
  align-content: start;
  gap: 8px;
  overflow: hidden;
  padding: 14px 16px;
  border: 2px solid rgba(124, 32, 25, .38);
  border-radius: 16px;
  background: rgba(255, 253, 247, .88);
  box-shadow: inset 0 0 0 1px rgba(200, 154, 61, .36);
}

.boardBrand {
  margin: 0;
  color: var(--red);
  font-size: clamp(22px, 2.1vw, 30px);
  font-weight: 900;
  line-height: .95;
  text-align: center;
}

.centerFacts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 3px 9px;
  margin: 0;
}

.centerFacts div {
  display: grid;
  gap: 2px;
}

.centerFacts dt {
  color: var(--ink);
  font-size: 10px;
  font-weight: 900;
}

.centerFacts dd {
  margin: 0;
  color: var(--body);
  font-size: 11px;
  line-height: 1.18;
}

.tuViPalace {
  display: grid;
  align-content: start;
  gap: 5px;
  min-width: 0;
  overflow: hidden;
  padding: 8px;
  border: 1px solid rgba(200, 154, 61, .66);
  border-radius: 10px;
  background: rgba(255, 253, 247, .82);
}

.palaceTop {
  display: grid;
  gap: 2px;
}

.palaceTop span {
  color: var(--ink);
  font-size: 11px;
  font-weight: 800;
}

.palaceTop strong {
  color: var(--red);
  font-size: 13px;
  line-height: 1.1;
  text-transform: uppercase;
}

.mainStar,
.minorStar,
.transformStar,
.statusStar {
  margin: 0;
  font-size: 11px;
  line-height: 1.22;
}

.starLayer {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.starLayerCycle {
  gap: 1px;
}

.starLayerTransit {
  margin-top: 1px;
  padding-top: 2px;
  border-top: 1px dashed rgba(143, 36, 29, .22);
  color: #8f241d;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.2;
}

.starLayerTransit p {
  margin: 0;
}

.chartLayerLegend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: center;
  margin: 8px 0 0;
  padding: 7px 9px;
  border: 1px solid rgba(200, 154, 61, .34);
  border-radius: 999px;
  background: rgba(255, 253, 247, .9);
  color: var(--body);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.chartLayerLegend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.chartLayerLegend i {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .8);
}

.legendNative {
  background: var(--ink);
}

.legendTransform {
  background: #0f7a36;
}

.legendCycle {
  background: #8a5a14;
}

.legendTransit {
  background: #8f241d;
}

.mainStar {
  color: var(--ink);
  font-weight: 800;
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.minorStar {
  color: var(--muted);
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.transformStar {
  color: #0f7a36;
  font-weight: 800;
}

.statusStar {
  color: #7a675b;
  font-size: 10px;
}

.trangSinhStage {
  margin: 1px 0 0;
  color: #8a5a14;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.15;
}

.tuViPalace small {
  display: none;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
}

.tuanTrietRow {
  display: flex;
  gap: 5px;
  margin: 1px 0;
}

.tuanBadge,
.trietBadge,
.tuViBadge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .03em;
}

.tuanBadge {
  background: #e8f0fe;
  color: #1b61c9;
  border: 1px solid #a8c7fa;
}

.trietBadge {
  background: #fff0e5;
  color: #aa2d00;
  border: 1px solid #efc8aa;
}

.tuViBadge {
  background: #f3e8ff;
  color: #6b21a8;
  border: 1px solid #d8b4fe;
}

.tuViPalace.hasTuan {
  border-color: #a8c7fa;
  background: rgba(232, 240, 254, .35);
}

.tuViPalace.hasTriet {
  border-color: #efc8aa;
  background: rgba(255, 240, 229, .35);
}

.tuViPalace.hasTuan.hasTriet {
  border-color: #d7bf8a;
  background: rgba(255, 248, 230, .35);
}

.tuViPalace.hasTuVi {
  border-color: #d8b4fe;
  background: rgba(243, 232, 255, .25);
}

.externalChartPreview {
  display: grid;
  gap: 10px;
  margin: 14px 0 0;
  padding: 14px;
  border: 1px solid rgba(200, 154, 61, .52);
  border-radius: 22px;
  background: rgba(255, 253, 247, .9);
}

.externalChartPreview figcaption {
  color: var(--ink);
  font-weight: 800;
}

.externalChartPreview img {
  width: 100%;
  max-height: 780px;
  object-fit: contain;
  border-radius: 14px;
}

.previewBoard {
  border-radius: 26px;
  background:
    linear-gradient(90deg, rgba(200, 154, 61, .22) 1px, transparent 1px),
    linear-gradient(rgba(200, 154, 61, .22) 1px, transparent 1px),
    #fff6e4;
}

.previewCenter {
  border: 1px solid rgba(242, 196, 100, .48);
  border-radius: 24px;
  background: linear-gradient(180deg, #7d231c, #32130f);
}

.palaceCell {
  border-color: rgba(200, 154, 61, .74);
  border-radius: 18px;
  background: rgba(255, 253, 247, .86);
}

#jsonOutput {
  background: #241410;
  color: #ffe9c3;
}

@media (max-width: 1100px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .viewSwitch,
  .topbarActions {
    justify-self: stretch;
  }

  .topbarActions {
    display: grid;
    grid-template-columns: 1fr auto;
  }

  .filterRail {
    grid-template-columns: 1fr;
  }

  .chartBuilder {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .appShell,
  .chartBuilder {
    width: min(100% - 20px, 1320px);
    padding-top: 14px;
  }

  .filterRail,
  .railSection:first-child,
  .workspaceHeader,
  .detailCard {
    grid-template-columns: 1fr;
  }

  .workspaceHeader,
  .chartPanel,
  .detailHero {
    border-radius: 22px;
  }

  .record {
    min-height: auto;
  }

  .tuViBoard {
    grid-template-columns: repeat(4, minmax(70px, 1fr));
    grid-template-rows: repeat(4, minmax(116px, auto));
    height: auto;
    min-height: 520px;
    padding: 8px;
  }

  .tuViCenter {
    padding: 12px;
  }

  .centerFacts {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .tuViPalace {
    padding: 7px;
  }

  .palaceTop strong,
  .mainStar,
  .minorStar {
    font-size: 10px;
  }

  .tuViPalace small {
    display: none;
  }

  .fixtureControls {
    grid-template-columns: 1fr;
  }
}


/* Compact knowledge grid polish. */
.workspaceHeader {
  grid-template-columns: minmax(0, 1fr) minmax(180px, 260px);
}

.workspaceHeader h1 {
  font-size: clamp(34px, 4.3vw, 54px);
  line-height: 1.06;
}

.workspaceHeader h1 span {
  display: block;
}

.recordList {
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
}

.record {
  min-height: 190px;
  padding: 14px;
  border-radius: 20px;
}

.record h2 {
  margin: 8px 0 6px;
  font-size: 21px;
  line-height: 1.18;
}

.summaryText {
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  font-size: 14px;
}

.recordMeta {
  margin-top: 10px;
}

.recordSide {
  margin-top: 12px;
}

.recordType,
.recordMeta span,
.badge,
.detailTag {
  min-height: 25px;
  padding: 4px 9px;
  font-size: 11px;
}

.openDetail {
  min-width: 84px;
  min-height: 36px;
  padding: 7px 12px;
}

@media (min-width: 1500px) {
  .appShell,
  .chartBuilder {
    width: min(1560px, calc(100% - 32px));
  }

  .recordList {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

@media (min-width: 1120px) and (max-width: 1499px) {
  .recordList {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .workspaceHeader h1 {
    font-size: clamp(32px, 10vw, 44px);
  }

  .recordList {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  body {
    overflow-x: hidden;
  }

  .topBar {
    gap: 10px;
    padding: 10px 12px;
  }

  .brandMark {
    width: 44px;
    height: 44px;
  }

  .brandTitle strong {
    font-size: 17px;
    line-height: 1.15;
  }

  .brandTitle span {
    font-size: 12px;
  }

  .viewToggle {
    order: 3;
    width: 100%;
    justify-content: center;
  }

  .secondaryAction {
    min-height: 40px;
    padding: 8px 12px;
  }

  .chartHeader {
    padding: 24px 18px;
  }

  .chartHeader h1 {
    font-size: clamp(34px, 13vw, 52px);
    line-height: .98;
  }

  .chartHeader .intro {
    font-size: 16px;
  }

  .fieldGrid,
  .timeGrid,
  .targetGrid {
    grid-template-columns: 1fr;
  }

  .radioRow {
    gap: 10px;
  }

  .chartActions {
    grid-template-columns: 1fr;
  }

  .chartPreview {
    overflow-x: auto;
    overscroll-behavior-x: contain;
    padding: 10px;
    -webkit-overflow-scrolling: touch;
  }

  .tuViBoard {
    width: 760px;
    min-width: 760px;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, minmax(116px, auto));
    height: auto;
    min-height: 520px;
    padding: 10px;
  }

  .tuViCenter {
    gap: 8px;
    padding: 12px;
  }

  .boardBrand {
    font-size: 26px;
    line-height: 1;
  }

  .centerFacts {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px 8px;
  }

  .centerFacts dt {
    font-size: 10px;
  }

  .centerFacts dd {
    font-size: 11px;
    line-height: 1.25;
  }

  .palaceTop strong {
    font-size: 13px;
  }

  .mainStar,
  .minorStar,
  .transformStar,
  .statusStar {
    font-size: 10px;
  }

  .tuViPalace small {
    display: none;
    font-size: 10px;
  }

  .jsonBox {
    max-height: 420px;
  }
}

@media (max-width: 720px) {
  .workspaceHeader {
    grid-template-columns: 1fr;
    align-items: start;
    gap: 18px;
    margin: 0 0 16px;
    padding: 28px 20px 22px;
    border-radius: 0 0 28px 28px;
  }

  .workspaceHeader .eyebrow {
    margin-bottom: 10px;
    font-size: 12px;
  }

  .workspaceHeader h1 {
    max-width: 100%;
    font-size: clamp(34px, 9vw, 40px);
    line-height: 1.04;
  }

  .workspaceHeader h1 span {
    display: block;
  }

  .workspaceHeader .intro {
    max-width: 100%;
    margin-top: 12px;
    font-size: 15px;
    line-height: 1.45;
  }

  .metricGrid {
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .metricGrid div {
    min-height: 82px;
    padding: 14px;
    border-radius: 18px;
  }

  .metricGrid span {
    font-size: clamp(26px, 8vw, 32px);
    line-height: 1.05;
  }

  .metricGrid small {
    font-size: 12px;
  }
}

@media (max-width: 380px) {
  .workspaceHeader {
    padding-inline: 16px;
  }

  .workspaceHeader h1 {
    font-size: 32px;
  }

  .metricGrid span {
    font-size: 25px;
  }
}

/* Trangs.net-inspired magazine layout pass. */
body {
  background: #fafafa;
  color: #2b2b2b;
}

.topbar {
  min-height: 56px;
  padding: 8px max(24px, calc((100vw - 1320px) / 2));
  background: rgba(255, 255, 255, .96);
  border-bottom: 1px solid #e8e8e8;
  box-shadow: none;
}

.brand {
  gap: 9px;
}

.brandMark {
  width: 34px;
  height: 34px;
  border: 1px solid #e91e63;
  border-radius: 999px;
  background: #fff;
  color: #e91e63;
  font-size: 11px;
  box-shadow: none;
}

.brand strong {
  color: #222;
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.brand small {
  color: #777;
  font-size: 10px;
}

.viewSwitch {
  gap: 4px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.viewButton {
  min-height: 24px;
  padding: 4px 11px;
  border: 1px solid transparent;
  border-radius: 999px;
  color: #555;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.viewButton.isActive {
  border-color: #e91e63;
  background: #fff;
  color: #e91e63;
  box-shadow: none;
}

.syncStatus,
.secondaryAction,
.openDetail,
.primaryAction {
  min-height: 30px;
  border-radius: 999px;
  font-size: 11px;
}

.syncStatus {
  border-color: #d8eadc;
  background: #f4fbf5;
  color: #2f6a3a;
}

.secondaryAction,
.openDetail {
  border-color: #e1e1e1;
  background: #fff;
  color: #333;
  box-shadow: none;
}

.primaryAction {
  border-color: #a5231b;
  background: #a5231b;
  color: #fff;
  box-shadow: none;
}

.appShell,
.chartBuilder {
  width: min(1260px, calc(100% - 48px));
  padding-top: 28px;
}

.filterRail {
  border-color: #ececec;
  border-radius: 0;
  background: #fff;
  box-shadow: none;
}

.sourcePolicy {
  border-color: #eee1cf;
  border-radius: 2px;
  background: #fbf6ec;
}

.sectionLabel,
.eyebrow {
  color: #333;
  font-size: 11px;
  letter-spacing: .04em;
  text-align: center;
}

input,
select {
  min-height: 38px;
  border-color: #ddd;
  border-radius: 2px;
  background: #fff;
}

.workspaceHeader {
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  margin: 22px 0 22px;
  padding: 0;
  border: 0;
  border-top: 1px solid #ddd;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.workspaceHeader > div:first-child {
  padding-top: 16px;
}

.workspaceHeader .eyebrow {
  position: relative;
  width: max-content;
  margin: -9px auto 12px;
  padding: 0 16px;
  background: #fafafa;
  color: #222;
}

.workspaceHeader h1 {
  max-width: 760px;
  margin: 0 auto;
  color: #202020;
  font-size: clamp(24px, 3vw, 36px);
  font-weight: 800;
  line-height: 1.18;
  text-align: center;
}

.workspaceHeader .intro {
  max-width: 640px;
  margin: 10px auto 0;
  color: #777;
  font-size: 13px;
  line-height: 1.55;
  text-align: center;
}

.metricGrid {
  align-self: center;
  min-width: 220px;
}

.metricGrid div,
.metricGrid div:nth-child(2) {
  min-height: 74px;
  border: 1px solid #e6e6e6;
  border-radius: 2px;
  background: #fff;
  color: #222;
}

.metricGrid span {
  color: #222;
  font-size: 24px;
}

.metricGrid small {
  color: #777;
}

.recordToolbar {
  margin-top: 8px;
  padding: 10px 0;
  border-color: #e4e4e4;
  color: #777;
}

.recordList {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
  margin-top: 20px;
}

.record {
  min-height: 178px;
  padding: 15px;
  border-color: #e5e5e5;
  border-radius: 2px;
  background: #fff;
  box-shadow: 0 2px 9px rgba(0, 0, 0, .06);
}

.record:hover,
.record.isActive {
  border-color: #d6b05c;
  background: #fff;
  transform: none;
}

.recordType,
.recordMeta span,
.badge,
.detailTag {
  min-height: 22px;
  border-radius: 999px;
  background: #f6f6f6;
  color: #555;
  font-size: 10px;
}

.record h2 {
  color: #222;
  font-size: 19px;
  font-weight: 800;
}

.summaryText {
  color: #666;
  font-size: 12px;
  line-height: 1.55;
}

.detailHero,
.detailBlock,
.detailEmpty,
.chartPanel,
.chartPreview,
.jsonPanel,
.readingPanel {
  border-color: #e5e5e5;
  border-radius: 2px;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .05);
}

.detailHero {
  background: #fff;
}

.detailHero h2 {
  color: #222;
}

.chartHeader {
  margin: 0 0 10px;
  padding: 0 0 18px;
  border: 0;
  border-bottom: 1px solid #ddd;
  border-radius: 0;
  background: transparent;
}

.chartHeader .eyebrow,
.chartHeader h1,
.chartHeader .intro {
  color: #222;
}

.chartHeader h1 {
  font-size: clamp(26px, 3.4vw, 40px);
}

.chartHeader .intro {
  color: #777;
}

.fixturePanel,
.fieldGroup {
  border-color: #e9e1d4;
  border-radius: 2px;
  background: #fffdf8;
}

@media (max-width: 820px) {
  .topbar {
    padding: 12px 16px;
  }

  .viewSwitch {
    width: 100%;
    justify-content: center;
    border-top: 1px solid #eee;
    padding-top: 10px;
  }

  .appShell,
  .chartBuilder {
    width: min(100% - 24px, 1260px);
  }

  .workspaceHeader {
    grid-template-columns: 1fr;
  }

  .metricGrid {
    width: 100%;
    min-width: 0;
  }
}

/* Compact chart workspace: chart on right, form/json/reading/fixture on left. */
@media (min-width: 1100px) {
  .chartBuilder {
    grid-template-columns: minmax(360px, 0.85fr) minmax(580px, 1.6fr);
    grid-template-rows: auto auto auto auto;
    grid-template-areas:
      "form    chart"
      "json    chart"
      "reading chart"
      "fixture chart";
    align-items: start;
    gap: 14px;
    width: min(1440px, calc(100% - 48px));
  }

  .chartPreview {
    grid-area: chart;
    min-height: 640px;
    position: sticky;
    top: 80px;
  }

  .chartPanel {
    grid-area: form;
    padding: 14px;
  }

  .jsonPanel {
    grid-area: json;
    min-height: 0;
  }

  .readingPanel {
    grid-area: reading;
  }

  .fixturePanel {
    grid-area: fixture;
  }

  .chartHeader {
    margin-bottom: 6px;
    padding-bottom: 10px;
  }

  .chartHeader h1 {
    font-size: clamp(20px, 2vw, 28px);
    line-height: 1.12;
  }

  .chartHeader .intro {
    font-size: 11px;
    line-height: 1.4;
  }

  .chartForm {
    gap: 10px;
  }

  .chartForm .field {
    gap: 4px;
    margin-bottom: 0;
  }

  .chartForm label > span,
  .fieldGroup legend {
    font-size: 11px;
  }

  .fieldGroup {
    padding: 10px;
  }

  .inlineFields,
  .threeFields {
    gap: 6px;
  }

  .chartPanel input,
  .chartPanel select {
    min-height: 30px;
    padding: 5px 8px;
    font-size: 12px;
  }

  .radioRow {
    gap: 10px;
    margin-top: 6px;
    font-size: 12px;
  }

  .fieldHint,
  .uploadField small {
    font-size: 10px;
    line-height: 1.3;
  }

  .formActions {
    gap: 6px;
    padding-top: 2px;
  }

  .formActions button {
    min-width: 0;
    padding: 7px 10px;
    font-size: 11px;
  }

  #jsonOutput {
    min-height: 140px;
    max-height: 220px;
    font-size: 11px;
  }

  .readingBody {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    padding: 12px;
  }

  .readingBody p {
    font-size: 13px;
    margin: 0;
  }

  .fixturePanel {
    gap: 6px;
    padding: 10px;
  }

  .fixturePanel p {
    margin: 0;
    font-size: 11px;
    line-height: 1.4;
  }

  .fixtureControls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
  }

  .fixtureControls select {
    min-height: 30px;
    font-size: 12px;
  }

  .fixtureControls .secondaryAction {
    padding: 5px 10px;
    font-size: 11px;
  }

  #fixtureStatus {
    font-size: 10px;
  }
}

@media (min-width: 1100px) and (max-width: 1280px) {
  .chartBuilder {
    grid-template-columns: minmax(340px, 0.85fr) minmax(480px, 1.4fr);
  }

  .chartPreview {
    min-height: 560px;
  }
}

@media (max-width: 1099px) {
  .chartBuilder {
    grid-template-columns: 1fr;
    grid-template-areas: unset;
  }

  .chartPanel,
  .chartPreview,
  .jsonPanel,
  .readingPanel,
  .fixturePanel {
    width: 100%;
  }
}

/* Final chart layout correction: left controls, right chart, lower review split. */
@media (min-width: 1100px) {
  .chartBuilder {
    grid-template-columns: minmax(340px, .72fr) minmax(660px, 1.68fr);
    grid-template-rows: auto auto auto;
    grid-template-areas:
      "fixture chart"
      "form chart"
      "json reading";
    align-items: start;
    gap: 14px;
  }

  .chartPanel,
  .fixturePanel,
  .readingPanel,
  .chartPreview,
  .jsonPanel {
    min-width: 0;
  }

  .chartPanel {
    grid-area: form;
    height: 584px;
    max-height: none;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .fixturePanel {
    grid-area: fixture;
  }

  .jsonPanel {
    grid-area: json;
    height: 430px;
    min-height: 0;
  }

  .readingPanel {
    grid-area: reading;
    height: 430px;
    max-height: none;
    overflow: hidden;
  }

  .chartPreview {
    grid-area: chart;
    position: relative;
    top: auto;
    height: auto;
    min-height: 0;
    overflow: visible;
    overscroll-behavior: auto;
  }

  .fixtureControls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .fixtureControls small {
    grid-column: 1 / -1;
  }

  #jsonOutput {
    height: calc(100% - 62px);
    min-height: 0;
    max-height: none;
  }

  .readingBody {
    display: grid;
    grid-template-columns: 1fr;
    align-items: start;
    gap: 10px;
    height: calc(100% - 53px);
    max-height: none;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .starPalaceReadingList,
  .readingList,
  .sourceReadingSection ul {
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  }

  .sourceReadingNarrative {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  }

  .sourceReadingHeader,
  .sourceReadingIntro {
    grid-column: 1 / -1;
  }

  .readingBody > * {
    min-width: 0;
  }

  .readingBody > p,
  .readingNotice,
  .readingList {
    height: auto;
  }

  .readingBody > p,
  .readingNotice {
    font-size: 12px;
    line-height: 1.42;
  }

  .starLayerStatus {
    padding: 10px;
    border-radius: 14px;
  }

  .starLayerStatusGrid {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .starLayerStatusGrid div {
    padding: 8px;
  }

  .transitSummaryGrid {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .transitSummaryGroup {
    padding: 8px;
  }

  .readingList {
    gap: 8px;
  }

  .readingList button {
    padding: 10px;
    border-radius: 12px;
  }

  .readingList strong {
    font-size: 13px;
    line-height: 1.25;
  }

  .readingList span,
  .readingList small {
    font-size: 12px;
    line-height: 1.3;
  }
}

@media (min-width: 1281px) {
  .chartPreview {
    min-height: 0;
  }
}

/* Tu Vi reading polish 2026-06-03: keep toolbar/status readable and expose stored notes. */
.jsonPanel .recordToolbar,
.readingPanel .recordToolbar {
  align-items: flex-start;
  gap: 10px 14px;
  padding: 14px 18px;
}

.jsonPanel .recordToolbar {
  align-items: center;
}

.jsonToolbarActions,
.readingToolbarActions {
  row-gap: 8px;
}

#chartStatus {
  display: none;
}

.readingToolbarActions {
  flex: 0 1 auto;
  max-width: 100%;
}

.readingModeBadge {
  line-height: 1.2;
  white-space: nowrap;
}

.readingToolbarActions .toolbarCopyButton,
.jsonToolbarActions .toolbarCopyButton {
  flex: 0 0 auto;
}

.readingPanel .recordToolbar > span:first-child {
  padding-top: 4px;
}

.readingBody {
  padding: 18px 20px 22px;
}

.readingList button p {
  margin: 2px 0 0;
  color: var(--body);
  font-size: .86rem;
  line-height: 1.48;
}

.readingList button dl {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 7px 12px;
  margin: 3px 0 0;
  padding-top: 8px;
  border-top: 1px solid rgba(200, 154, 61, .2);
}

.readingList button dt {
  color: var(--ink);
  font-size: .78rem;
  font-weight: 900;
}

.readingList button dd {
  margin: 2px 0 0;
  color: var(--body);
  font-size: .82rem;
  line-height: 1.42;
}

.starPalaceReadingCard dl {
  padding-top: 8px;
  border-top: 1px solid rgba(65, 135, 95, .16);
}

@media (min-width: 1100px) {
  .readingPanel {
    height: 520px;
  }

  .jsonPanel {
    height: 360px;
  }

  .readingBody {
    height: calc(100% - 64px);
  }
}

@media (max-width: 1099px) {
  .chartPreview {
    position: relative;
    top: auto;
  }
}

/* Compact Tu Vi layout pass 2026-06-05. */
.starReadingVerdict {
  width: auto;
  max-width: 100%;
  padding: 3px 8px;
  border-radius: 11px;
  background: rgba(143, 36, 29, .08);
  color: var(--accent);
  font-size: .78rem;
  font-weight: 900;
  line-height: 1.35;
  overflow-wrap: anywhere;
  white-space: normal;
}

.wholeChartSynthesis {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(65, 135, 95, .28);
  border-radius: 16px;
  background: rgba(239, 251, 242, .82);
}

.wholeChartHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--ink);
}

.wholeChartHeader span {
  color: var(--muted);
  font-size: .8rem;
  font-weight: 800;
}

.wholeChartSynthesis p {
  margin: 0;
  color: var(--body);
  font-size: .88rem;
  line-height: 1.45;
}

.wholeChartLead {
  font-weight: 800;
}

.wholeChartTechnical {
  display: grid;
  gap: 10px;
  border: 1px solid rgba(65, 135, 95, .18);
  border-radius: 12px;
  background: rgba(255, 255, 255, .58);
  overflow: hidden;
}

.wholeChartTechnical summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  color: var(--ink);
  font-weight: 900;
}

.wholeChartTechnical summary small {
  color: var(--muted);
  font-size: .76rem;
  font-weight: 800;
}

.wholeChartTechnical .wholeChartEssay {
  padding: 0 10px 10px;
}

.wholeChartEssay,
.synthesisNarrative {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.wholeChartEssay article,
.synthesisNarrative article {
  display: grid;
  gap: 6px;
  padding: 12px 14px;
  border: 1px solid rgba(65, 135, 95, .18);
  border-radius: 12px;
  background: rgba(255, 255, 255, .72);
}

.wholeChartEssay h4,
.synthesisNarrative h4 {
  margin: 0;
  color: var(--ink);
  font-size: .96rem;
  line-height: 1.2;
}

.wholeChartEssay p,
.synthesisNarrative p {
  font-size: .88rem;
  line-height: 1.58;
}

.essayClosing {
  display: grid;
  gap: 6px;
  padding: 12px 14px;
  border-left: 4px solid rgba(143, 36, 29, .42);
  border-radius: 12px;
  background: rgba(255, 248, 240, .82);
}

.essayClosing strong {
  color: var(--ink);
  font-size: .95rem;
}

.longFormEssay {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid rgba(143, 36, 29, .16);
  border-left: 4px solid rgba(143, 36, 29, .42);
  border-radius: 14px;
  background: rgba(255, 250, 240, .62);
}

.longFormEssay h3 {
  margin: 0;
  color: var(--ink);
  font-size: 1rem;
}

.longFormEssay p {
  margin: 0;
  color: var(--body);
  font-size: .9rem;
  line-height: 1.62;
}

.synthesisActions {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid rgba(143, 36, 29, .12);
  border-radius: 12px;
  background: rgba(255, 248, 240, .76);
}

.synthesisActions strong {
  color: var(--ink);
  font-size: .9rem;
}

.synthesisActions ul {
  display: grid;
  gap: 4px;
  margin: 0;
  padding-left: 18px;
}

.synthesisActions li {
  color: var(--body);
  font-size: .82rem;
  line-height: 1.38;
}

.wholeChartGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 8px;
}

.wholeChartGrid div {
  display: grid;
  gap: 4px;
  padding: 9px;
  border: 1px solid rgba(65, 135, 95, .18);
  border-radius: 12px;
  background: rgba(255, 255, 255, .7);
}

.wholeChartGrid b {
  color: var(--ink);
  font-size: .82rem;
}

.wholeChartGrid span {
  color: var(--body);
  font-size: .8rem;
  line-height: 1.38;
}

.chartHeader {
  padding: 14px 16px;
}

.chartHeader h1 {
  font-size: clamp(24px, 2.6vw, 32px);
  line-height: 1.04;
}

.chartHeader .intro {
  font-size: 13px;
  line-height: 1.42;
}

.chartPanel {
  gap: 12px;
  padding: 16px;
}

.chartForm {
  gap: 12px;
}

.fieldGroup {
  padding: 12px;
}

.chartPreview {
  padding: 10px;
}

.tuViBoard {
  min-height: 0;
  height: min(760px, calc(100vh - 138px));
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: 2px;
  padding: 6px;
}

.tuViCenter {
  gap: 4px;
  padding: 9px 10px;
}

.boardBrand {
  font-size: clamp(18px, 1.55vw, 24px);
}

.centerFacts {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 2px 8px;
}

.centerFacts dt {
  font-size: 8px;
}

.centerFacts dd {
  font-size: 8.8px;
  line-height: 1.08;
}

.tuViPalace {
  gap: 3px;
  padding: 6px;
  border-radius: 8px;
}

.palaceTop span {
  font-size: 10px;
}

.palaceTop strong {
  font-size: 12px;
}

.mainStar,
.minorStar,
.transformStar,
.statusStar {
  font-size: 8.15px;
  line-height: 1.06;
}

.starList {
  display: grid !important;
  gap: 1px 4px;
  min-width: 0;
  overflow: visible !important;
  -webkit-line-clamp: unset !important;
  -webkit-box-orient: unset !important;
}

.starListMajor {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  color: var(--ink);
  font-weight: 900;
}

.starListMinor {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  color: var(--muted);
}

.starList span {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: normal;
}

.starLayerTransit,
.trangSinhStage {
  font-size: 7.8px;
  line-height: 1.05;
}

.tuanBadge,
.trietBadge,
.tuViBadge {
  padding: 1px 5px;
  font-size: 7.8px;
}

.readingGroup {
  gap: 8px;
  padding: 10px;
}

.readingList button {
  padding: 10px;
}

.readingList button dl,
.starPalaceReadingCard dl {
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
}

@media (min-width: 1100px) {
  .chartBuilder {
    grid-template-columns: minmax(320px, .64fr) minmax(640px, 1.78fr);
    gap: 12px;
  }

  .chartPanel {
    height: 520px;
  }

  .readingPanel {
    height: 500px;
  }
}

@media (max-width: 1099px) {
  .synthesisNarrative {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chartHeader {
    padding: 16px;
  }

  .chartHeader h1,
  .workspaceHeader h1 {
    font-size: clamp(24px, 7vw, 34px);
  }

  .chartPanel {
    max-height: none;
    height: auto;
  }

  .tuViBoard {
    height: auto;
    min-height: 600px;
  }
}

@media (max-width: 720px) {
  .synthesisNarrative {
    grid-template-columns: 1fr;
  }

  .chartBuilder {
    width: min(100% - 14px, 1260px);
    padding-bottom: 24px;
  }

  .chartPreview {
    overflow-x: visible;
    padding: 6px;
  }

  .tuViBoard {
    width: 100%;
    min-width: 0;
    min-height: 540px;
    gap: 1px;
    padding: 5px;
  }

  .tuViCenter {
    padding: 8px;
  }

  .boardBrand {
    font-size: 20px;
  }

  .centerFacts {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .centerFacts dt,
  .centerFacts dd {
    font-size: 8px;
  }

  .tuViPalace {
    gap: 2px;
    padding: 4px;
  }

  .palaceTop span,
  .mainStar,
  .minorStar,
  .transformStar,
  .statusStar,
  .starLayerTransit,
  .trangSinhStage {
    font-size: 7.5px;
    line-height: 1.08;
  }

  .palaceTop strong {
    font-size: 9px;
  }

  .mainStar {
    -webkit-line-clamp: unset;
  }

  .minorStar {
    -webkit-line-clamp: unset;
  }

  .starListMajor,
  .starListMinor {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tuanBadge,
  .trietBadge,
  .tuViBadge {
    padding: 1px 3px;
    font-size: 7px;
  }

  .chartLayerLegend {
    border-radius: 10px;
    font-size: 9px;
    line-height: 1.25;
  }
}

/* Keep the Tu Vi reading pane readable when browser/PDF toolbars cover the viewport bottom. */
@media (min-width: 1100px) {
  .readingPanel {
    height: min(760px, calc(100vh - 128px));
    min-height: 500px;
    overflow: hidden;
  }

  .readingBody {
    height: calc(100% - 64px);
    overflow-y: auto;
    padding-bottom: 96px;
    scroll-padding-bottom: 96px;
  }

  .sourceReferenceDetails {
    margin-bottom: 28px;
  }
}
/* Iztro parallel chart engine comparison */
.iztroComparePanel {
  border: 1px solid rgba(128, 90, 213, 0.28);
  border-left: 6px solid #8b5cf6;
  border-radius: 10px;
  background: #fbf7ff;
  padding: 18px 20px;
  margin: 18px 0;
  color: #3d2a24;
}

.iztroComparePanel.pending {
  border-left-color: #b7791f;
  background: #fffaf0;
}

.iztroComparePanel.error {
  border-left-color: #b91c1c;
  background: #fff5f5;
}

.iztroSummaryGrid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.iztroSummaryGrid div {
  border: 1px solid rgba(128, 90, 213, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  padding: 10px 12px;
  min-width: 0;
}

.iztroSummaryGrid strong,
.iztroSummaryGrid span {
  display: block;
}

.iztroSummaryGrid strong {
  font-size: 0.78rem;
  text-transform: uppercase;
  color: #6b4a3f;
}

.iztroSummaryGrid span {
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.iztroDiffList {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.iztroDiffList span {
  border: 1px solid rgba(128, 90, 213, 0.22);
  border-radius: 999px;
  background: #fff;
  padding: 7px 10px;
  font-size: 0.9rem;
}

.iztroPalaceSummary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.iztroPalaceCard {
  border: 1px solid rgba(128, 90, 213, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  padding: 10px 12px;
  min-width: 0;
}

.iztroPalaceHead {
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: #5f4037;
}

.iztroPalaceHead span {
  font-weight: 900;
}

.iztroPalaceHead strong {
  overflow-wrap: anywhere;
}

.iztroMajorLine,
.iztroMinorLine,
.iztroTransformLine,
.iztroCompareLine {
  margin: 6px 0 0;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.iztroMajorLine {
  font-weight: 800;
  color: #2d201d;
}

.iztroTransformLine {
  color: #0f6b34;
  font-weight: 800;
}

.iztroMinorLine {
  color: #6b5b55;
  font-size: 0.92rem;
}

.iztroCompareLine {
  border-top: 1px dashed rgba(128, 90, 213, 0.22);
  padding-top: 7px;
  color: #5f4037;
  font-size: 0.84rem;
}

.iztroCompareLine.isMismatch {
  color: #9a3412;
  font-weight: 700;
}

@media (max-width: 860px) {
  .iztroSummaryGrid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .iztroPalaceSummary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .iztroSummaryGrid,
  .iztroPalaceSummary {
    grid-template-columns: 1fr;
  }
}

/* Authoritative chart workspace layout: keep tools, chart, readings, and oracle as distinct panes. */
:root[data-theme="clean"] {
  --canvas: #ffffff;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #eef2f7;
  --surface-cream: #f7f8fb;
  --surface-parchment: #ffffff;
  --ink: #151923;
  --body: #303742;
  --muted: #687386;
  --hairline: #d8dee8;
  --gold-line: #c9a24e;
  --primary: #1f2937;
  --primary-active: #111827;
  --coral: #9f2c1f;
  --red: #8f241d;
  --danger-soft: #fff1ed;
  --success-soft: #edf8f2;
}

:root[data-theme="sage"] {
  --canvas: #ffffff;
  --bg: #f5f7f4;
  --surface: #ffffff;
  --surface-soft: #eef4ef;
  --surface-cream: #f8f5ec;
  --surface-parchment: #fffdf7;
  --ink: #1b211d;
  --body: #38423b;
  --muted: #68736b;
  --hairline: #dce5dc;
  --gold-line: #d7b66f;
  --primary: #20352a;
  --primary-active: #16251d;
  --coral: #b34a38;
  --red: #9b3328;
  --forest: #1f6f45;
  --mint: #cfe9d8;
  --danger-soft: #fff3ef;
  --success-soft: #ecf8f0;
}

:root[data-theme="neutral"] {
  --canvas: #ffffff;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-soft: #f1f1ee;
  --surface-cream: #f7f4ec;
  --surface-parchment: #fffdf8;
  --ink: #202124;
  --body: #3e3f42;
  --muted: #6f706f;
  --hairline: #deded8;
  --gold-line: #ccb16a;
  --primary: #202124;
  --primary-active: #111214;
  --coral: #a53c30;
  --red: #913027;
  --danger-soft: #fff2ef;
  --success-soft: #eff7ef;
}

:root[data-theme="night"] {
  color-scheme: dark;
  --canvas: #0d0f14;
  --bg: #080a0f;
  --surface: #11141b;
  --surface-soft: #171b24;
  --surface-cream: #151821;
  --surface-parchment: #141820;
  --ink: #f5f2ec;
  --body: #ddd4c9;
  --muted: #a99d92;
  --hairline: rgba(255, 255, 255, .13);
  --gold-line: rgba(215, 177, 86, .5);
  --primary: #f5f2ec;
  --primary-active: #ffffff;
  --coral: #f09074;
  --red: #ffad9d;
  --forest: #84d49b;
  --mint: #274a39;
  --yellow: #f3cf6a;
  --link: #8db7ff;
  --danger-soft: rgba(178, 72, 42, .18);
  --success-soft: rgba(52, 129, 85, .18);
}

:root[data-theme="night"] .topbar,
:root[data-theme="night"] .chartPanel,
:root[data-theme="night"] .chartPreview,
:root[data-theme="night"] .jsonPanel,
:root[data-theme="night"] .readingPanel,
:root[data-theme="night"] .fixturePanel,
:root[data-theme="night"] .recordToolbar,
:root[data-theme="night"] .fieldGroup,
:root[data-theme="night"] .geminiReadingPanel,
:root[data-theme="night"] .questionToolPanel,
:root[data-theme="night"] .oracleToolPanel,
:root[data-theme="night"] .internalReadingDetails,
:root[data-theme="night"] .sourceReferenceDetails,
:root[data-theme="night"] .iztroComparePanel {
  background: var(--surface);
  border-color: var(--hairline);
  box-shadow: none;
}

:root[data-theme="night"] input,
:root[data-theme="night"] select,
:root[data-theme="night"] textarea,
:root[data-theme="night"] #jsonOutput,
:root[data-theme="night"] .geminiReadingContent,
:root[data-theme="night"] .oracleResult,
:root[data-theme="night"] .questionResult,
:root[data-theme="night"] .iztroPalaceCard,
:root[data-theme="night"] .iztroSummaryGrid div {
  background: var(--surface-soft);
  color: var(--body);
  border-color: var(--hairline);
}

.themeToggle {
  min-width: 88px;
}

.questionToolGrid {
  grid-template-columns: minmax(120px, 170px) minmax(220px, 1fr);
}

.questionToolGrid [data-gemini-question] {
  grid-column: 1 / -1;
  justify-self: start;
  max-width: 100%;
}

.oracleToolPanel [data-oracle-draw] {
  width: 100%;
}

.readingToolbarActions {
  min-width: 0;
}

.readingToolbarActions .toolbarCopyButton,
.geminiProviderSelect {
  max-width: 100%;
}

@media (min-width: 1280px) {
  body {
    padding-left: 280px;
  }

  .topbar {
    position: fixed;
    inset: 18px auto 18px 18px;
    width: 244px;
    min-height: 0;
    padding: 18px;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 20px;
    border: 1px solid rgba(217, 221, 228, .86);
    border-radius: 26px;
    background: rgba(255, 255, 255, .9);
    box-shadow: 0 22px 60px rgba(24, 29, 38, .08);
  }

  .brand {
    align-items: flex-start;
  }

  .brandMark {
    flex: 0 0 auto;
    border-radius: 50%;
    background: #fff;
    color: #e83f6f;
    border: 1px solid rgba(232, 63, 111, .38);
  }

  .viewSwitch {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 6px;
    border-radius: 18px;
  }

  .viewButton {
    width: 100%;
    justify-content: flex-start;
    border-radius: 14px;
    padding-inline: 12px;
  }

  .viewButton.isActive {
    color: #e83f6f;
  }

  .topbarActions {
    width: 100%;
    margin-top: auto;
    flex-direction: column;
    align-items: stretch;
  }

  .topbarActions > * {
    width: 100%;
    justify-content: center;
  }

  .appShell,
  .chartBuilder {
    margin-top: 20px;
  }
}

/* Chart tool tabs: keep input/sample and JSON from stacking into tall blank columns. */
.chartUtilityTabs {
  grid-area: tools;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  padding: 5px;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: rgba(255, 255, 255, .82);
  box-shadow: 0 12px 30px rgba(24, 29, 38, .06);
}

.chartToolTab {
  min-height: 34px;
  border: 0;
  border-radius: 999px;
  padding: 7px 16px;
  background: transparent;
  color: var(--muted);
  font-size: .86rem;
  font-weight: 900;
}

.chartToolTab.isActive {
  background: var(--primary);
  color: var(--canvas);
}

body[data-chart-tool-tab="input"] .jsonPanel,
body[data-chart-tool-tab="json"] .chartPanel,
body[data-chart-tool-tab="json"] .fixturePanel {
  display: none !important;
}

@media (min-width: 1100px) {
  .chartBuilder {
    grid-template-areas:
      "tools chart"
      "form chart"
      "fixture reading";
  }

  body[data-chart-tool-tab="json"] .chartBuilder {
    grid-template-areas:
      "tools chart"
      "json chart"
      ". reading";
  }

  .chartPanel {
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 1099px) {
  .chartUtilityTabs {
    order: 1;
    width: 100%;
    justify-content: center;
  }

  .chartPanel {
    order: 2;
  }

  .jsonPanel {
    order: 2;
  }

  .chartPreview {
    order: 3;
  }

  .readingPanel {
    order: 4;
  }

  .fixturePanel {
    order: 5;
  }
}

@media (min-width: 1100px) {
  .chartBuilder {
    width: min(1480px, calc(100% - 48px));
    grid-template-columns: minmax(360px, 430px) minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    grid-template-areas:
      "form chart"
      "json chart"
      "fixture reading";
    align-items: start;
    gap: 16px;
  }

  .chartPanel {
    grid-area: form;
    height: auto;
    max-height: calc(100vh - 104px);
    overflow-y: auto;
  }

  .jsonPanel {
    grid-area: json;
    height: auto;
    max-height: 320px;
    overflow: hidden;
  }

  .fixturePanel {
    grid-area: fixture;
  }

  .chartPreview {
    grid-area: chart;
    position: relative;
    top: auto;
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  .readingPanel {
    grid-area: reading;
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  .readingBody {
    height: auto;
    max-height: none;
    overflow: visible;
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(320px, .9fr);
    align-items: start;
    gap: 14px;
    padding-bottom: 0;
  }

  .readingBody > p,
  .readingBody > .geminiReadingPanel,
  .readingBody > .internalReadingDetails {
    grid-column: 1 / -1;
  }

  .questionToolPanel,
  .oracleToolPanel {
    min-height: 0;
    min-width: 0;
  }
}

@media (max-width: 1280px) and (min-width: 1100px) {
  .readingBody {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1099px) {
  .topbar {
    position: sticky;
    min-height: 64px;
    padding: 10px 14px;
  }

  .topbarActions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .chartBuilder {
    width: min(100% - 20px, 820px);
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    align-items: start;
  }

  .chartPanel,
  .chartPreview,
  .jsonPanel,
  .readingPanel,
  .fixturePanel {
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  .chartPanel {
    order: 1;
  }

  .chartPreview {
    order: 2;
  }

  .readingPanel {
    order: 3;
  }

  .jsonPanel {
    order: 4;
  }

  .fixturePanel {
    order: 5;
  }

  .readingBody {
    height: auto !important;
    overflow: visible !important;
    padding-bottom: 0;
  }
}

@media print {
  .geminiReadingHeaderActions,
  .readingToolbarActions,
  .jsonToolbarActions,
  .topbar,
  .chartPanel,
  .jsonPanel,
  .fixturePanel {
    display: none !important;
  }

  .readingPanel,
  .readingBody,
  .geminiReadingPanel,
  .geminiReadingContent {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    box-shadow: none !important;
  }
}

/* Emergency correction: keep navigation in the top bar and use color-only theme control. */
.themeToggle {
  position: relative;
  width: 44px;
  min-width: 44px;
  height: 36px;
  padding: 0;
  font-size: 0;
  line-height: 0;
}

.themeToggle::before {
  content: "";
  width: 18px;
  height: 18px;
  display: block;
  margin: auto;
  border-radius: 999px;
  background: #e83f6f;
  box-shadow: inset 0 0 0 4px #fff1f4, 0 0 0 1px rgba(232, 63, 111, .35);
}

:root[data-theme="sage"] .themeToggle::before {
  background: #2f8f5b;
  box-shadow: inset 0 0 0 4px #effaf3, 0 0 0 1px rgba(47, 143, 91, .35);
}

:root[data-theme="neutral"] .themeToggle::before {
  background: #4b5563;
  box-shadow: inset 0 0 0 4px #f2f3f5, 0 0 0 1px rgba(75, 85, 99, .35);
}

:root[data-theme="heritage"] {
  --canvas: #fffaf0;
  --bg: #f6e8c8;
  --surface: #fff8ea;
  --surface-soft: #f5e7c9;
  --surface-cream: #f1d9ad;
  --surface-parchment: #fff7e4;
  --ink: #261512;
  --body: #4c342c;
  --muted: #80695d;
  --hairline: #dfbd7d;
  --gold-line: #d3a958;
  --primary: #6b2018;
  --primary-active: #4d1712;
  --coral: #a93024;
  --red: #8d241b;
  --forest: #143d1b;
  --mint: #def1de;
  --yellow: #f5d56b;
  --danger-soft: #fff1e9;
  --success-soft: #edf8ef;
}

:root[data-theme="heritage"] body {
  background:
    linear-gradient(rgba(151, 106, 38, .08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(151, 106, 38, .08) 1px, transparent 1px),
    var(--bg);
  background-size: 32px 32px;
}

:root[data-theme="heritage"] .topbar {
  background: #5b1f18;
  border-bottom-color: rgba(228, 185, 104, .45);
  box-shadow: 0 14px 34px rgba(73, 22, 17, .18);
}

:root[data-theme="heritage"] .brand,
:root[data-theme="heritage"] .brand strong,
:root[data-theme="heritage"] .brand small {
  color: #fff8e7;
}

:root[data-theme="heritage"] .brandMark {
  background: #8c241d;
  color: #fff8e7;
  border: 1px solid rgba(241, 198, 103, .5);
  box-shadow: inset 0 0 0 2px rgba(241, 198, 103, .16);
}

:root[data-theme="heritage"] .viewSwitch {
  background: #fff2cf;
  border-color: rgba(223, 189, 125, .7);
}

:root[data-theme="heritage"] .viewButton {
  color: #7a4c3b;
}

:root[data-theme="heritage"] .viewButton.isActive {
  background: #982b22;
  color: #fff8e7;
  box-shadow: none;
}

:root[data-theme="heritage"] .syncStatus {
  background: #edf8ef;
  color: #214b2b;
  border-color: rgba(20, 61, 27, .14);
}

:root[data-theme="heritage"] .reloadBtn {
  background: #fff8e7;
  color: #6b2018;
  border-color: rgba(211, 169, 88, .66);
}

:root[data-theme="heritage"] .secondaryAction,
:root[data-theme="heritage"] .toolbarCopyButton,
:root[data-theme="heritage"] .geminiProviderSelect {
  background: #fff8e7;
  color: #6b2018;
  border-color: rgba(211, 169, 88, .66);
}

:root[data-theme="heritage"] .chartPanel,
:root[data-theme="heritage"] .chartPreview,
:root[data-theme="heritage"] .jsonPanel,
:root[data-theme="heritage"] .readingPanel,
:root[data-theme="heritage"] .fixturePanel,
:root[data-theme="heritage"] .filterRail,
:root[data-theme="heritage"] .workspaceHeader,
:root[data-theme="heritage"] .detailPane,
:root[data-theme="heritage"] .record,
:root[data-theme="heritage"] .geminiReadingPanel,
:root[data-theme="heritage"] .questionToolPanel,
:root[data-theme="heritage"] .oracleToolPanel,
:root[data-theme="heritage"] .internalReadingDetails {
  background: rgba(255, 248, 234, .94);
  border-color: rgba(211, 169, 88, .55);
  box-shadow: 0 18px 44px rgba(92, 31, 24, .08);
}

:root[data-theme="heritage"] .workspaceHeader {
  background: #6b2018;
  color: #fff8e7;
}

:root[data-theme="heritage"] .workspaceHeader h1,
:root[data-theme="heritage"] .workspaceHeader .eyebrow,
:root[data-theme="heritage"] .workspaceHeader .intro {
  color: #fff8e7;
}

:root[data-theme="heritage"] input,
:root[data-theme="heritage"] select,
:root[data-theme="heritage"] textarea,
:root[data-theme="heritage"] #jsonOutput {
  background: #fffdf6;
  color: var(--ink);
  border-color: rgba(211, 169, 88, .5);
}

:root[data-theme="heritage"] .themeToggle::before {
  background: #8c241d;
  box-shadow: inset 0 0 0 4px #fff2cf, 0 0 0 1px rgba(211, 169, 88, .8);
}

@media (min-width: 1280px) {
  body {
    padding-left: 0;
  }

  .topbar {
    position: sticky;
    inset: auto;
    top: 0;
    width: auto;
    min-height: 68px;
    padding: 12px 24px;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    border: 0;
    border-bottom: 1px solid var(--hairline);
    border-radius: 0;
    background: rgba(255, 255, 255, .94);
    box-shadow: none;
  }

  .brand {
    align-items: center;
  }

  .brandMark {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--primary);
    color: #fff;
    border: 0;
  }

  .viewSwitch {
    width: auto;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    padding: 4px;
    border-radius: 12px;
  }

  .viewButton {
    width: auto;
    justify-content: center;
    border-radius: 8px;
    padding: 7px 12px;
  }

  .viewButton.isActive {
    color: var(--ink);
  }

  .topbarActions {
    width: auto;
    margin-top: 0;
    flex-direction: row;
    align-items: center;
  }

  .topbarActions > * {
    width: auto;
  }

  .appShell,
  .chartBuilder {
    margin-top: 22px;
  }
}

/* Authoritative chart workspace layout. Keep this at the end so older
   experimental layout passes cannot move tabs or create empty columns. */
.chartToolPane {
  grid-area: tools;
  display: grid;
  gap: 14px;
  align-content: start;
  min-width: 0;
  position: relative;
  z-index: 3;
}

.chartToolHeader {
  position: sticky;
  top: 82px;
  z-index: 8;
  display: grid;
  gap: 10px;
  padding: 10px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: 1px solid var(--hairline);
  border-radius: 16px;
  background: rgba(255, 255, 255, .94);
  box-shadow: 0 18px 42px rgba(24, 29, 38, .08);
}

.chartToolPane .chartUtilityTabs {
  position: static;
  inset: auto;
  display: flex !important;
  justify-self: stretch;
  width: 100% !important;
  max-width: 100%;
  margin: 0;
  z-index: auto;
}

.chartToolPane .chartToolTab {
  flex: 1 1 0;
}

body[data-chart-tool-tab="input"] .chartToolPane .jsonPanel {
  display: none !important;
}

body[data-chart-tool-tab="json"] .chartToolPane .chartPanel,
body[data-chart-tool-tab="json"] .chartToolPane .fixturePanel {
  display: none !important;
}

body[data-chart-tool-tab="json"] .chartToolHeader {
  position: static;
}

.questionToolPanel,
.oracleToolPanel {
  min-width: 0;
}

.chartToolPane .chartPanel,
.chartToolPane .jsonPanel,
.chartToolPane .fixturePanel,
.chartToolPane .fieldGroup,
.chartToolPane input,
.chartToolPane select,
.chartToolPane label,
.chartToolPane .chartHeader {
  opacity: 1 !important;
  filter: none !important;
}

.chartToolPane .fixturePanel {
  position: static !important;
  inset: auto !important;
  transform: none !important;
  z-index: auto !important;
}

.chartToolPane .fixtureControls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.chartToolPane .fixtureControls small {
  grid-column: 1 / -1;
}

.chartBuilder .chartPreview {
  isolation: isolate;
  contain: layout paint;
  overflow: auto;
  z-index: 1;
}

.questionToolGrid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  align-items: end;
}

.questionToolGrid label,
.questionToolGrid input,
.questionToolGrid select,
.questionToolGrid button {
  min-width: 0;
  max-width: 100%;
}

.questionToolGrid input {
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.geminiReadingHeaderActions {
  display: none !important;
}

@media (min-width: 900px) {
  .questionToolGrid {
    grid-template-columns: minmax(150px, 220px) minmax(0, 1fr);
  }

  .questionToolGrid [data-gemini-question] {
    justify-self: start;
  }
}

@media (min-width: 1100px) {
  .chartBuilder {
    width: min(1440px, calc(100% - 32px));
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "tools"
      "chart"
      "reading";
    gap: 14px;
    align-items: start;
  }

  .chartBuilder .chartPanel,
  .chartBuilder .jsonPanel,
  .chartBuilder .fixturePanel,
  .chartBuilder .chartPreview,
  .chartBuilder .readingPanel {
    width: 100%;
    max-width: none;
    min-width: 0;
    margin: 0;
  }

  .chartBuilder .chartPreview {
    grid-area: chart;
    position: relative;
    top: auto;
    height: auto;
    min-height: 0;
    overflow: auto;
  }

  .chartBuilder .readingPanel {
    grid-area: reading;
    height: auto;
    overflow: visible;
  }

  .chartBuilder .chartPanel,
  .chartBuilder .jsonPanel {
    max-height: none;
    overflow: visible;
  }
}

@media (min-width: 1280px) {
  .chartBuilder {
    grid-template-columns: minmax(360px, 520px) minmax(0, 1fr);
    grid-template-areas:
      "tools chart"
      "reading reading";
    gap: 16px;
  }
}

@media (max-width: 1099px) {
  .chartBuilder {
    width: min(100% - 20px, 860px);
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }

  .chartToolPane,
  .chartBuilder .chartPreview,
  .chartBuilder .readingPanel {
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .chartToolPane {
    order: 1;
  }

  .chartBuilder .chartPreview {
    order: 2;
  }

  .chartBuilder .readingPanel {
    order: 3;
  }
}

/* Final shared heritage skin. This intentionally sits last so the red-brown
   paper theme applies to every main-app view, not only the chart screen. */
:root[data-theme="heritage"] body {
  background:
    linear-gradient(rgba(128, 88, 31, .10) 1px, transparent 1px),
    linear-gradient(90deg, rgba(128, 88, 31, .10) 1px, transparent 1px),
    #f2dfb7;
  background-size: 48px 48px;
  color: #2b1712;
}

:root[data-theme="heritage"] .topbar {
  background: #641f17 !important;
  border-bottom: 1px solid rgba(230, 190, 118, .42) !important;
  color: #fff8e7;
}

:root[data-theme="heritage"] .brand,
:root[data-theme="heritage"] .brand strong,
:root[data-theme="heritage"] .brand small,
:root[data-theme="heritage"] .topbar .viewButton {
  color: #fff8e7;
}

:root[data-theme="heritage"] .brandMark {
  background: #8c241d !important;
  color: #fff8e7 !important;
  border: 1px solid rgba(241, 198, 103, .58) !important;
  border-radius: 999px !important;
}

:root[data-theme="heritage"] .viewSwitch {
  background: #fff2cf !important;
  border: 1px solid rgba(230, 190, 118, .52);
  border-radius: 999px;
}

:root[data-theme="heritage"] .viewSwitch .viewButton {
  color: #7a4c3b;
  border-radius: 999px;
}

:root[data-theme="heritage"] .viewSwitch .viewButton.isActive {
  background: #982b22 !important;
  color: #fff8e7 !important;
}

:root[data-theme="heritage"] .appShell,
:root[data-theme="heritage"] .chartBuilder {
  background:
    radial-gradient(circle at top left, rgba(255, 248, 234, .72), transparent 34%),
    linear-gradient(rgba(128, 88, 31, .09) 1px, transparent 1px),
    linear-gradient(90deg, rgba(128, 88, 31, .09) 1px, transparent 1px),
    #f2dfb7 !important;
  background-size: auto, 48px 48px, 48px 48px, auto;
}

:root[data-theme="heritage"] .filterRail,
:root[data-theme="heritage"] .workspace,
:root[data-theme="heritage"] .detailPane,
:root[data-theme="heritage"] .record,
:root[data-theme="heritage"] .recordToolbar,
:root[data-theme="heritage"] .chartToolPane,
:root[data-theme="heritage"] .chartPanel,
:root[data-theme="heritage"] .chartPreview,
:root[data-theme="heritage"] .jsonPanel,
:root[data-theme="heritage"] .readingPanel,
:root[data-theme="heritage"] .fixturePanel,
:root[data-theme="heritage"] .fieldGroup,
:root[data-theme="heritage"] .geminiReadingPanel,
:root[data-theme="heritage"] .questionToolPanel,
:root[data-theme="heritage"] .oracleToolPanel,
:root[data-theme="heritage"] .internalReadingDetails,
:root[data-theme="heritage"] .sourceReferenceDetails,
:root[data-theme="heritage"] .iztroComparePanel,
:root[data-theme="heritage"] .chartToolHeader {
  background: rgba(255, 250, 238, .94) !important;
  border-color: rgba(211, 169, 88, .64) !important;
  box-shadow: 0 20px 52px rgba(92, 31, 24, .08);
}

@media (max-width: 760px) {
  .chartToolHeader {
    top: 72px;
  }

  .chartToolPane .fixtureControls {
    grid-template-columns: minmax(0, 1fr);
  }

  .chartToolPane .fixtureControls .secondaryAction {
    width: 100%;
  }
}

:root[data-theme="heritage"] .workspaceHeader {
  background: #6b2018 !important;
  border-color: rgba(211, 169, 88, .55) !important;
  color: #fff8e7;
}

:root[data-theme="heritage"] .workspaceHeader h1,
:root[data-theme="heritage"] .workspaceHeader .eyebrow,
:root[data-theme="heritage"] .workspaceHeader .intro {
  color: #fff8e7 !important;
}

:root[data-theme="heritage"] input,
:root[data-theme="heritage"] select,
:root[data-theme="heritage"] textarea,
:root[data-theme="heritage"] #jsonOutput,
:root[data-theme="heritage"] .geminiReadingContent {
  background: #fffdf6 !important;
  color: #2b1712 !important;
  border-color: rgba(211, 169, 88, .62) !important;
}

/* Final correction: the chart tool area is a real tab panel. The sample
   selector belongs to the input tab; JSON is its own tab. */
.chartBuilder {
  width: min(1440px, calc(100% - 32px)) !important;
  display: grid !important;
  grid-template-columns: minmax(360px, 520px) minmax(0, 1fr) !important;
  grid-template-areas:
    "tools chart"
    "reading reading" !important;
  gap: 16px !important;
  align-items: start !important;
}

.chartToolPane {
  grid-area: tools !important;
  display: grid !important;
  gap: 14px !important;
  min-width: 0 !important;
  align-content: start !important;
}

.chartToolPane .chartUtilityTabs {
  position: static !important;
  inset: auto !important;
  grid-area: auto !important;
  align-self: start !important;
  justify-self: stretch !important;
  display: flex !important;
  height: auto !important;
  min-height: 0 !important;
  width: 100% !important;
  max-width: none !important;
  margin: 0 !important;
  padding: 5px !important;
  border: 1px solid var(--hairline) !important;
  border-radius: 999px !important;
  background: rgba(255, 255, 255, .84) !important;
}

.chartToolPane .chartToolTab {
  flex: 1 1 0 !important;
  min-height: 38px !important;
}

.chartToolPane .chartPanel,
.chartToolPane .jsonPanel {
  grid-area: auto !important;
  align-self: start !important;
  width: 100% !important;
  max-width: none !important;
  min-width: 0 !important;
  margin: 0 !important;
}

.chartToolPane .chartPanel {
  display: grid !important;
  gap: 18px !important;
  max-height: calc(100vh - 150px) !important;
  overflow: auto !important;
}

.chartToolPane .fixturePanel {
  position: static !important;
  inset: auto !important;
  grid-area: auto !important;
  align-self: start !important;
  transform: none !important;
  z-index: auto !important;
  width: 100% !important;
  max-width: none !important;
  margin: 0 !important;
}

.chartToolPane .jsonPanel {
  max-height: calc(100vh - 150px) !important;
  overflow: hidden !important;
}

.chartToolPane #jsonOutput {
  min-height: 360px !important;
  max-height: calc(100vh - 250px) !important;
}

body[data-chart-tool-tab="input"] .chartToolPane > .jsonPanel {
  display: none !important;
}

body[data-chart-tool-tab="json"] .chartToolPane > .chartPanel {
  display: none !important;
}

.chartBuilder .chartPreview {
  grid-area: chart !important;
  width: 100% !important;
  min-width: 0 !important;
  margin: 0 !important;
}

.chartBuilder .readingPanel {
  grid-area: reading !important;
}

@media (max-width: 1099px) {
  .chartBuilder {
    width: min(100% - 20px, 860px) !important;
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-areas:
      "tools"
      "chart"
      "reading" !important;
  }

  .chartToolPane .chartPanel,
  .chartToolPane .jsonPanel {
    max-height: none !important;
    overflow: visible !important;
  }
}

/* =============================================
   STATUS DOT (thay thế full-width status bar)
   ============================================= */
.statusDot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
  cursor: default;
  transition: background 0.3s, box-shadow 0.3s;
}
.statusDot[data-mode="ready"]   { background: #22c55e; box-shadow: 0 0 0 2px rgba(34,197,94,.18); }
.statusDot[data-mode="loading"] { background: #f59e0b; }
.statusDot[data-mode="error"]   { background: #ef4444; box-shadow: 0 0 0 2px rgba(239,68,68,.18); }
.statusDot[data-mode="empty"]   { background: var(--muted); }

/* Ẩn legacy syncStatus text khỏi giao diện (vẫn accessible với screen reader) */
.syncStatus {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Nút reload icon nhỏ gọn */
.reloadBtn {
  min-width: 36px;
  font-size: 16px;
  padding: 0 10px;
  border-radius: 10px;
}

/* =============================================
   TOKEN COST BADGE
   ============================================= */
.tokenCostBadge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 8px 0 4px;
  padding: 5px 10px;
  border-radius: 8px;
  background: var(--surface-soft);
  border: 1px solid var(--hairline);
  font-size: 11px;
  color: var(--muted);
  line-height: 1.3;
}
.tokenCostActual {
  background: var(--success-soft);
  border-color: #c6e7cf;
  color: var(--forest);
}
.tokenCostLabel { font-weight: 700; }
.tokenCostValue { font-variant-numeric: tabular-nums; }

:root[data-theme="heritage"] .tokenCostBadge {
  background: rgba(255, 248, 234, .7);
  border-color: rgba(211,169,88,.45);
  color: var(--muted);
}
:root[data-theme="heritage"] .tokenCostActual {
  background: #edf8ef;
  border-color: rgba(20,61,27,.18);
  color: #214b2b;
}

/* =============================================
   TOPBAR LAYOUT FIX (specificity override)
   :root .topbar = 0,2,0 > .topbar = 0,1,0
   Prevents media-query grid collapse at medium viewports.
   ============================================= */
:root .topbar {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}
:root .viewSwitch {
  width: auto;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  padding: 4px;
}
:root .viewButton {
  width: auto;
}
.topbar .topbarActions {
  display: flex;
  flex-direction: row;
  align-items: center;
  width: auto;
  margin-top: 0;
  gap: 8px;
}
.topbar .topbarActions > * {
  flex-shrink: 0;
}

/* =============================================
   LANDING PAGE
   ============================================= */
.landingView {
  min-height: calc(100vh - 68px);
  padding: 0 0 60px;
}

.landingHero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 40px;
  max-width: 960px;
  margin: 0 auto;
  padding: 64px 32px 48px;
}

.landingHeroText { flex: 1; }

.landingHeroText h1 {
  margin: 8px 0 16px;
  font-size: clamp(28px, 4vw, 44px);
  font-weight: 800;
  line-height: 1.15;
  color: var(--ink);
  letter-spacing: -.02em;
}

.landingIntro {
  margin: 0 0 28px;
  font-size: 16px;
  color: var(--body);
  line-height: 1.65;
  max-width: 520px;
}

.landingHeroActions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.landingCtaPrimary {
  display: inline-flex;
  align-items: center;
  min-height: 46px;
  padding: 10px 22px;
  border: 0;
  border-radius: 12px;
  background: var(--red);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
}
.landingCtaPrimary:hover { background: var(--primary-active, #4d1712); }

.landingCtaSecondary {
  display: inline-flex;
  align-items: center;
  min-height: 46px;
  padding: 10px 22px;
  border: 1px solid var(--hairline);
  border-radius: 12px;
  background: var(--canvas);
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s;
}
.landingCtaSecondary:hover { background: var(--surface-soft); }

.landingHeroBadge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 120px;
  height: 120px;
  border-radius: 24px;
  border: 2px solid var(--hairline);
  background: var(--canvas);
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
  flex-shrink: 0;
}
.landingBadgeIcon { font-size: 36px; line-height: 1; }

/* Cards */
.landingCards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 32px;
}

.landingCard {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 24px;
  border-radius: 16px;
  border: 1px solid var(--hairline);
  background: var(--canvas);
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  text-align: left;
  font: inherit;
  transition: box-shadow 0.18s, transform 0.18s;
  box-shadow: 0 2px 8px rgba(17,24,39,.05);
}
.landingCard:hover {
  box-shadow: 0 8px 28px rgba(17,24,39,.1);
  transform: translateY(-2px);
}
.landingCardSoon { opacity: .6; cursor: default; }
.landingCardSoon:hover { box-shadow: 0 2px 8px rgba(17,24,39,.05); transform: none; }

.landingCardHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.landingCardIcon { font-size: 22px; line-height: 1; }

.landingCardTag {
  font-size: 11px;
  font-weight: 700;
  color: var(--coral);
  letter-spacing: .05em;
  text-transform: uppercase;
}
.landingCardTagSoon { color: var(--muted); }

.landingCard h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.25;
}

.landingCard p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--body);
  line-height: 1.55;
  flex: 1;
}

.landingCardCta {
  margin-top: 12px;
  font-size: 13px;
  font-weight: 700;
  color: var(--coral);
}
.comingSoon { color: var(--muted); }

/* Philosophy */
.landingPhilosophy {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
  max-width: 960px;
  margin: 40px auto 0;
  padding: 0 32px;
}

.philosophyItem {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 20px;
  border-radius: 12px;
  background: var(--surface-soft);
}
.philosophyIcon { font-size: 20px; }
.philosophyItem strong { font-size: 13px; font-weight: 700; color: var(--ink); }
.philosophyItem span  { font-size: 12px; color: var(--body); line-height: 1.5; }

/* Footer link về kho tri thức */
.landingFooter {
  text-align: center;
  margin-top: 40px;
}
.landingKnowledgeLink {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.landingKnowledgeLink:hover { color: var(--body); }

/* Heritage theme overrides for landing */
:root[data-theme="heritage"] .landingView {
  background:
    linear-gradient(rgba(151,106,38,.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(151,106,38,.07) 1px, transparent 1px),
    var(--bg);
  background-size: 32px 32px;
}
:root[data-theme="heritage"] .landingHeroText h1 { color: var(--ink); }
:root[data-theme="heritage"] .landingCtaPrimary {
  background: var(--red);
  color: #fff8e7;
}
:root[data-theme="heritage"] .landingCtaPrimary:hover { background: var(--primary-active); }
:root[data-theme="heritage"] .landingCtaSecondary {
  background: #fff8e7;
  border-color: rgba(211,169,88,.6);
  color: var(--ink);
}
:root[data-theme="heritage"] .landingCard {
  background: rgba(255,248,234,.9);
  border-color: rgba(211,169,88,.45);
  box-shadow: 0 4px 16px rgba(92,31,24,.07);
}
:root[data-theme="heritage"] .landingCard:hover {
  box-shadow: 0 10px 32px rgba(92,31,24,.14);
}
:root[data-theme="heritage"] .landingHeroBadge {
  background: #fff8e7;
  border-color: rgba(211,169,88,.55);
  color: var(--muted);
}
:root[data-theme="heritage"] .philosophyItem {
  background: rgba(255,248,234,.7);
  border: 1px solid rgba(211,169,88,.35);
}

/* Responsive */
@media (max-width: 700px) {
  .landingHero { flex-direction: column; padding: 36px 20px 32px; }
  .landingHeroBadge { display: none; }
  .landingCards, .landingPhilosophy { grid-template-columns: 1fr; padding: 0 20px; }
}

/* =============================================
   THEME COLORS — PHÂN BIỆT RÕ RÀNG
   Mỗi theme có topbar màu tối riêng biệt.
   Specificity 0,2,0 thắng flat .topbar 0,1,0 ở trên.
   ============================================= */

/* CLASSIC — Đất Nung (Terracotta) */
:root[data-theme="classic"] {
  --primary: #8b5435;
  --primary-active: #7a4428;
  --coral: #cb997e;
  --red: #b07050;
  --canvas: #ffffff;
  --bg: #fdf8f4;
  --surface: #ffffff;
  --surface-soft: #f4e8dc;
  --surface-cream: #f8f0e8;
  --surface-parchment: #fdf9f6;
  --ink: #2a140a;
  --body: #5a3525;
  --muted: #9e7b67;
  --hairline: #e8d2bf;
  --link: #8b5435;
  --success-soft: #eaf4ea;
  --danger-soft: #fde8e4;
}
:root[data-theme="classic"] .topbar {
  background: #3a1f0c;
  border-bottom-color: rgba(203, 153, 126, .35);
  box-shadow: 0 8px 28px rgba(42, 20, 10, .28);
}
:root[data-theme="classic"] .brand,
:root[data-theme="classic"] .brand strong,
:root[data-theme="classic"] .brand small,
:root[data-theme="classic"] .topbar .viewButton {
  color: #f4dfd0;
}
:root[data-theme="classic"] .brandMark {
  background: #cb997e;
  color: #fff;
  border: 1px solid rgba(203, 153, 126, .5);
}
:root[data-theme="classic"] .viewButton.isActive {
  background: rgba(139, 84, 53, .45);
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}
:root[data-theme="classic"] .themeToggle::before {
  background: #cb997e;
  box-shadow: inset 0 0 0 4px #eddcd2, 0 0 0 1px rgba(203,153,126,.7);
}

/* SAGE — Lam Đêm (Midnight Blue) */
:root[data-theme="sage"] {
  --primary: #0f2460;
  --primary-active: #091848;
  --coral: #1a4fc4;
  --red: #1540a8;
  --canvas: #ffffff;
  --bg: #edf2ff;
  --surface: #ffffff;
  --surface-soft: #d8e3ff;
  --surface-cream: #edf2ff;
  --surface-parchment: #f5f7ff;
  --ink: #060e2a;
  --body: #1a2d5a;
  --muted: #4a5e8c;
  --hairline: #b8c8f0;
  --link: #1540a8;
  --forest: #0f2460;
  --mint: #c2d0f0;
  --success-soft: #e6f4ea;
  --danger-soft: #fde8e8;
}
:root[data-theme="sage"] .topbar {
  background: #091545;
  border-bottom-color: rgba(80, 140, 240, .35);
  box-shadow: 0 8px 28px rgba(5, 15, 60, .28);
}
:root[data-theme="sage"] .brand,
:root[data-theme="sage"] .brand strong,
:root[data-theme="sage"] .brand small,
:root[data-theme="sage"] .topbar .viewButton {
  color: #c8d8ff;
}
:root[data-theme="sage"] .brandMark {
  background: #1a4fc4;
  color: #dde8ff;
  border: 1px solid rgba(80, 140, 240, .5);
}
:root[data-theme="sage"] .viewButton.isActive {
  background: rgba(26, 79, 196, .5);
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}
:root[data-theme="sage"] .themeToggle::before {
  background: #1a4fc4;
  box-shadow: inset 0 0 0 4px #90b0f0, 0 0 0 1px rgba(80,140,240,.7);
}

/* NEUTRAL — Kem Ngà (#EDDCD2) */
:root[data-theme="neutral"] {
  --primary: #8c6850;
  --primary-active: #7a5840;
  --coral: #c8a878;
  --red: #b09060;
  --canvas: #ffffff;
  --bg: #faf5ee;
  --surface: #ffffff;
  --surface-soft: #f5ebe0;
  --surface-cream: #faf2e8;
  --surface-parchment: #fdfaf5;
  --ink: #2a1c0e;
  --body: #5c4838;
  --muted: #9c8878;
  --hairline: #e8d8c8;
  --link: #8c6850;
  --success-soft: #eaf4ea;
  --danger-soft: #fde8e4;
}
:root[data-theme="neutral"] .topbar {
  background: #362212;
  border-bottom-color: rgba(200, 168, 120, .35);
  box-shadow: 0 8px 28px rgba(20, 10, 4, .28);
}
:root[data-theme="neutral"] .brand,
:root[data-theme="neutral"] .brand strong,
:root[data-theme="neutral"] .brand small,
:root[data-theme="neutral"] .topbar .viewButton {
  color: #f8eed8;
}
:root[data-theme="neutral"] .brandMark {
  background: #c8a878;
  color: #fff;
  border: 1px solid rgba(200, 168, 120, .5);
}
:root[data-theme="neutral"] .viewButton.isActive {
  background: rgba(140, 104, 80, .45);
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}
:root[data-theme="neutral"] .themeToggle::before {
  background: #eddcd2;
  box-shadow: inset 0 0 0 4px #f8eed8, 0 0 0 1px rgba(200,168,120,.7);
}

/* Also fix body backgrounds per theme when needed */
:root[data-theme="classic"] body {
  background:
    linear-gradient(rgba(203, 153, 126, .05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(203, 153, 126, .05) 1px, transparent 1px),
    var(--bg);
  background-size: 32px 32px;
}
:root[data-theme="neutral"] body {
  background:
    linear-gradient(rgba(200, 168, 120, .05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(200, 168, 120, .05) 1px, transparent 1px),
    var(--bg);
  background-size: 32px 32px;
}

/* ============================================================
   LANDING PAGE v2 — Full redesign (overrides old landing CSS)
   ============================================================ */

/* Reset old hero structure — break out of 960px max-width constraint */
.landingHero {
  display: flex !important;
  align-items: center;
  gap: 56px;
  padding: clamp(56px, 12vh, 100px) max(6vw, 40px) clamp(48px, 10vh, 88px);
  max-width: none !important;
  margin: 0 !important;
  background: linear-gradient(150deg, var(--primary) 0%, #040202 68%) !important;
  position: relative;
  overflow: hidden;
  box-shadow: none;
  border-radius: 0;
}

/* Also override old philosophy max-width — it uses full-width grid now */
.landingPhilosophy {
  max-width: none !important;
  margin: 0 !important;
}

/* Warm glow behind the grid */
.landingHero::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 50% 80% at 75% 50%, rgba(220,150,50,.10) 0%, transparent 65%),
    radial-gradient(ellipse 60% 60% at 20% 80%, rgba(0,0,0,.25) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.landingHeroContent {
  flex: 1;
  min-width: 0;
  position: relative;
  z-index: 1;
}

.landingHeroVisual {
  flex: 0 0 280px;
  width: 280px;
  position: relative;
  z-index: 1;
}

.landingPalaceGrid {
  width: 100%;
  height: auto;
  filter: drop-shadow(0 0 24px rgba(220,160,50,.18)) drop-shadow(0 0 6px rgba(220,160,50,.08));
}

/* Eyebrow */
.landingEyebrow {
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255,215,140,.65);
  margin: 0 0 18px;
  font-weight: 500;
}

/* Headline */
.landingHeadline {
  font-size: clamp(2rem, 4.5vw, 3.4rem) !important;
  font-weight: 800 !important;
  line-height: 1.08 !important;
  color: #ffffff !important;
  margin: 0 0 22px !important;
  letter-spacing: -0.025em;
}

.landingHeadline em {
  font-style: normal;
  color: rgba(255,210,110,.95);
}

/* Intro text */
.landingIntroText {
  font-size: 1.05rem;
  line-height: 1.65;
  color: rgba(255,255,255,.65);
  margin: 0 0 36px;
  max-width: 46ch;
}

/* CTA button — golden */
.landingCta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 15px 34px;
  background: rgba(230,185,55,.92);
  color: #1a0c02;
  font-size: 0.95rem;
  font-weight: 700;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: background 0.18s, transform 0.14s, box-shadow 0.18s;
  box-shadow: 0 4px 18px rgba(200,150,30,.35);
}

.landingCta:hover {
  background: rgba(240,200,70,1);
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(200,150,30,.45);
}

.landingCta:active { transform: translateY(0); }

/* Per-theme hero gradient adjustments */
:root[data-theme="classic"] .landingHero {
  background: linear-gradient(150deg, #5a2c10 0%, #120602 68%) !important;
}
:root[data-theme="classic"] .landingCta {
  background: rgba(203,153,126,.92);
  color: #2a140a;
  box-shadow: 0 4px 18px rgba(139,84,53,.4);
}
:root[data-theme="classic"] .landingCta:hover {
  background: rgba(220,170,145,1);
}
:root[data-theme="classic"] .landingEyebrow { color: rgba(237,220,210,.65); }
:root[data-theme="classic"] .landingHeadline em { color: rgba(237,220,210,.95); }

:root[data-theme="neutral"] .landingHero {
  background: linear-gradient(150deg, #3a2410 0%, #120804 68%) !important;
}
:root[data-theme="neutral"] .landingCta {
  background: rgba(200,168,120,.92);
  color: #2a1c0e;
  box-shadow: 0 4px 18px rgba(140,104,80,.4);
}
:root[data-theme="neutral"] .landingCta:hover { background: rgba(220,188,140,1); }
:root[data-theme="neutral"] .landingEyebrow { color: rgba(248,238,216,.65); }
:root[data-theme="neutral"] .landingHeadline em { color: rgba(237,220,210,.95); }

/* SVG grid color tweaks per theme */
:root[data-theme="classic"] .landingPalaceGrid {
  filter: drop-shadow(0 0 24px rgba(203,153,126,.28)) hue-rotate(18deg) saturate(0.75);
}
:root[data-theme="neutral"] .landingPalaceGrid {
  filter: drop-shadow(0 0 24px rgba(200,168,120,.22)) hue-rotate(30deg) saturate(0.6);
}

/* ── STATS STRIP ── */
.landingStats {
  display: grid !important;
  grid-template-columns: repeat(4, 1fr);
  background: #0e0e0f;
  border-top: 1px solid rgba(255,255,255,.06);
}

.landingStat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 30px 16px;
  gap: 5px;
  border-right: 1px solid rgba(255,255,255,.06);
}

.landingStat:last-child { border-right: none; }

.landingStat strong {
  font-size: 2.2rem;
  font-weight: 800;
  color: rgba(235,185,70,.95);
  line-height: 1;
  letter-spacing: -0.02em;
}

.landingStat span {
  font-size: 0.68rem;
  color: rgba(255,255,255,.4);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 500;
}

:root[data-theme="classic"] .landingStat strong { color: rgba(237,220,210,.9); }
:root[data-theme="neutral"] .landingStat strong { color: rgba(235,215,185,.9); }

/* ── FEATURES ── */
.landingFeatures {
  display: grid !important;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--hairline);
  border-top: 1px solid var(--hairline);
}

.lFeature {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 44px 36px;
  background: var(--canvas);
  border: none;
  cursor: pointer;
  text-align: left;
  text-decoration: none;
  color: inherit;
  transition: background 0.18s;
}

.lFeature:hover:not(.lFeatureSoon) { background: var(--surface-soft); }

.lFeature.lFeatureSoon {
  cursor: default;
  opacity: 0.55;
}

.lFeatureTag {
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--coral);
  font-weight: 600;
}

.lFeatureTagSoon { color: var(--muted); }

.lFeature h2 {
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.lFeature p {
  font-size: 0.88rem;
  line-height: 1.65;
  color: var(--body);
  margin: 0;
  flex: 1;
}

.lFeatureCta {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--coral);
  margin-top: 4px;
}

.lFeatureCtaSoon { color: var(--muted); }

/* ── PHILOSOPHY ── */
.landingPhilosophy {
  display: grid !important;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--hairline);
  border-top: 1px solid var(--hairline);
  padding: 0 !important;
}

.philosophyItem {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 36px;
  background: var(--surface-soft);
}

.philosophyItem strong {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ink);
}

.philosophyItem span {
  font-size: 0.83rem;
  line-height: 1.6;
  color: var(--muted);
}

/* Remove old landing footer */
.landingFooter { display: none !important; }

/* ── RESPONSIVE ── */
@media (max-width: 860px) {
  .landingHero { flex-direction: column; gap: 40px; min-height: 70vh; padding: 56px 24px 48px; }
  .landingHeroVisual { width: 220px; flex: none; }
}

@media (max-width: 640px) {
  .landingHeroVisual { display: none; }
  .landingStats { grid-template-columns: repeat(2, 1fr); }
  .landingFeatures { grid-template-columns: 1fr; }
  .landingPhilosophy { grid-template-columns: 1fr !important; }
  .lFeature { padding: 32px 24px; }
  .philosophyItem { padding: 28px 24px; }
}

/* Session token counter badge */
.tokenSessionTotal {
  background: rgba(124,58,237,.08);
  border-color: rgba(124,58,237,.28);
  color: var(--body);
}
.tokenSessionTotal .tokenCostLabel { color: var(--primary); }
:root[data-theme="heritage"] .tokenSessionTotal {
  background: rgba(180,130,50,.08);
  border-color: rgba(180,130,50,.28);
}
:root[data-theme="classic"] .tokenSessionTotal {
  background: rgba(203,153,126,.1);
  border-color: rgba(139,84,53,.28);
}
:root[data-theme="neutral"] .tokenSessionTotal {
  background: rgba(200,168,120,.1);
  border-color: rgba(140,104,80,.28);
}

/* ── XIN XĂM VIEW ── */
.xamView {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow-y: auto;
}
.xamShell {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 48px 24px 80px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}
.xamPickerInner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  text-align: center;
}
.xamSymbol {
  font-size: 3.5rem;
  line-height: 1;
  color: var(--primary);
  opacity: 0.25;
  font-family: serif;
}
.xamTitle {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -0.02em;
  margin: 0;
}
.xamSubtitle {
  font-size: 0.92rem;
  color: var(--body);
  margin: 0;
  line-height: 1.6;
}
.xamTopicGrid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
}
.xamTopic {
  padding: 13px 10px;
  border: 1.5px solid var(--hairline);
  border-radius: 8px;
  background: var(--surface);
  color: var(--body);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  min-height: 44px;
}
.xamTopic:hover { border-color: var(--primary); color: var(--primary); }
.xamTopic.isActive {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}
.xamDrawBtn {
  padding: 16px 48px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 52px;
  letter-spacing: 0.01em;
  transition: background 0.15s, transform 0.12s;
  width: 100%;
  max-width: 260px;
}
.xamDrawBtn:hover { background: var(--primary-active); transform: translateY(-1px); }
.xamDrawBtn:active { transform: translateY(0); }
.xamDrawBtn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.xamNote {
  font-size: 0.76rem;
  color: var(--muted);
  margin: 0;
  line-height: 1.55;
}
/* Result card */
.xamResultCard {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  padding: 28px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.xamQueHeader {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.xamQueNum {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.xamQueMeta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.xamCapBadge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 20px;
  border: 1px solid;
}
.xamCapThuong { background: #e8f5e9; color: #2e7d32; border-color: #a5d6a7; }
.xamCapTrung  { background: #fff8e1; color: #f57f17; border-color: #ffe082; }
.xamCapHa     { background: #fce4ec; color: #c62828; border-color: #f48fb1; }
.xamHopMenh {
  font-size: 0.72rem;
  color: var(--coral);
  font-weight: 600;
}
.xamQueTen {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--ink);
  margin: 0;
  letter-spacing: -0.01em;
}
.xamTho {
  white-space: pre-line;
  font-size: 0.9rem;
  font-style: italic;
  color: var(--body);
  padding: 14px 16px;
  background: var(--surface-soft);
  border-radius: 8px;
  border-left: 3px solid var(--coral);
  line-height: 1.8;
  margin: 0;
}
.xamLoiGiaiChung {
  font-size: 0.88rem;
  color: var(--body);
  margin: 0;
  line-height: 1.65;
  font-weight: 500;
}
.xamMatSection {
  border-top: 1px solid var(--hairline);
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.xamChuDeLabel {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--coral);
}
.xamNhinNhan {
  font-size: 0.88rem;
  color: var(--body);
  margin: 0;
  line-height: 1.65;
}
.xamBuocList {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.xamBuocList li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 0.88rem;
  color: var(--body);
  line-height: 1.6;
}
.xamBuocNum {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}
.xamDongVien {
  margin: 0;
  padding: 12px 16px;
  border-left: 3px solid var(--primary);
  background: var(--surface-soft);
  border-radius: 0 8px 8px 0;
  font-size: 0.86rem;
  font-style: italic;
  color: var(--primary);
  font-weight: 500;
  line-height: 1.6;
}
.xamDisclaimer {
  font-size: 0.74rem;
  color: var(--muted);
  margin: 0;
  line-height: 1.5;
  border-top: 1px solid var(--hairline);
  padding-top: 12px;
}
.xamResultActions {
  display: flex;
  justify-content: center;
}
.xamResetBtn {
  padding: 12px 28px;
  border: 1.5px solid var(--hairline);
  border-radius: 8px;
  background: var(--surface);
  color: var(--body);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  min-height: 44px;
  transition: border-color 0.15s, color 0.15s;
}
.xamResetBtn:hover { border-color: var(--primary); color: var(--primary); }

/* Advisory insight block */
.xamAdvisory {
  border-top: 1px solid var(--hairline);
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.xamAdvisoryTitle {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}
.xamAdvisoryInsight {
  font-size: 0.86rem;
  color: var(--body);
  margin: 0;
  line-height: 1.65;
  font-style: italic;
}
.xamAdvisoryQ {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.xamAdvisoryQ li {
  font-size: 0.83rem;
  color: var(--muted);
  padding-left: 14px;
  position: relative;
  line-height: 1.55;
}
.xamAdvisoryQ li::before {
  content: "→";
  position: absolute;
  left: 0;
  color: var(--coral);
}

@media (max-width: 480px) {
  .xamShell { padding: 32px 16px 64px; }
  .xamTopicGrid { grid-template-columns: repeat(2, 1fr); }
  .xamResultCard { padding: 20px 16px; }
}

/* ══════════════════════════════════════════════════════════════════
   XIN XĂM — v1.02 3-column redesign
   ══════════════════════════════════════════════════════════════════ */

/* Override old full-page xamView */
.xamView {
  background: var(--tv-bg) !important;
  min-height: 0 !important;
  height: 100% !important;
  overflow-y: auto !important;
  display: block !important;
}

.xamLayout {
  display: grid;
  grid-template-columns: 220px 1fr 200px;
  height: 100%;
  min-height: calc(100vh - 52px);
}

/* Left column */
.xamColLeft {
  border-right: 1px solid var(--tv-border);
  overflow-y: auto;
  padding: 28px 20px;
  background: var(--tv-bg);
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* Center column */
.xamColCenter {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 32px;
  gap: 18px;
  background: var(--tv-bg);
  position: relative;
}

/* Right column */
.xamColRight {
  border-left: 1px solid var(--tv-border);
  padding: 28px 20px;
  background: var(--tv-bg);
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
}

.xamColLabel {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--tv-text-dim);
  margin: 0 0 12px;
}

.xamColSection { display: flex; flex-direction: column; }

/* Topic list (left col) */
.xamTopicList {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.xamTopicList .xamTopic {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--tv-text-sec);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background .15s, color .15s, border-color .15s;
}
.xamTopicList .xamTopic:hover {
  background: rgba(255,255,255,0.04);
}
.xamTopicList .xamTopic.isActive {
  background: rgba(251,191,36,0.1);
  color: var(--tv-xam);
  border-color: rgba(251,191,36,0.3);
}
.xamTopicIcon {
  width: 20px;
  text-align: center;
  opacity: 0.7;
  flex: 0 0 20px;
}

/* Classification */
.xamClassList { display: flex; flex-direction: column; gap: 8px; }
.xamClassItem {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--tv-text-sec);
}
.xamDot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 8px;
}
.xamDotDaiCat  { background: #22c55e; }
.xamDotCat     { background: #86efac; }
.xamDotBinh    { background: #fbbf24; }
.xamDotHung    { background: #fb923c; }
.xamDotDaiHung { background: #ef4444; }
.xamClassSub { margin-left: auto; font-size: 11px; color: var(--tv-text-dim); }
.xamSourceNote { font-size: 11.5px; color: var(--tv-text-dim); line-height: 1.6; margin: 0; }

/* Center: Active topic badge */
.xamActiveBadge {
  padding: 5px 14px;
  border-radius: 99px;
  background: rgba(251,191,36,0.1);
  border: 1px solid rgba(251,191,36,0.25);
  color: var(--tv-xam);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
}

/* Jar */
.xamJarWrap {
  position: relative;
  width: 200px;
  height: 260px;
  flex: 0 0 260px;
}
.xamJarSvg {
  width: 200px;
  height: 260px;
  filter: drop-shadow(0 8px 32px rgba(251,191,36,0.2));
}
.xamJarWrap.isShaking {
  animation: xamShake 0.55s ease-in-out;
}
@keyframes xamShake {
  0%   { transform: rotate(0deg) translateX(0); }
  10%  { transform: rotate(-8deg) translateX(-4px); }
  25%  { transform: rotate(10deg) translateX(5px); }
  40%  { transform: rotate(-9deg) translateX(-4px); }
  55%  { transform: rotate(7deg) translateX(3px); }
  70%  { transform: rotate(-5deg) translateX(-2px); }
  85%  { transform: rotate(3deg) translateX(1px); }
  100% { transform: rotate(0deg) translateX(0); }
}
/* Sticks wave during shake */
.xamJarWrap.isShaking .xamSticks {
  animation: xamSticksWave 0.55s ease-in-out;
}
@keyframes xamSticksWave {
  0%   { transform: rotate(0deg); transform-origin: 100px 100px; }
  30%  { transform: rotate(-5deg); transform-origin: 100px 100px; }
  60%  { transform: rotate(4deg); transform-origin: 100px 100px; }
  100% { transform: rotate(0deg); transform-origin: 100px 100px; }
}

.xamJarHint {
  text-align: center;
  font-size: 13px;
  color: var(--tv-text-muted);
  line-height: 1.6;
  margin: 0;
  max-width: 300px;
}
.xamDrawBtn {
  padding: 14px 36px;
  border-radius: 12px;
  background: rgba(251,191,36,0.1) !important;
  border: 1px solid rgba(251,191,36,0.35) !important;
  color: var(--tv-xam) !important;
  font-size: 15px !important;
  font-weight: 600 !important;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: background .2s, box-shadow .2s;
  box-shadow: 0 0 24px rgba(251,191,36,0.12) !important;
  width: 100%;
  max-width: 300px;
}
.xamDrawBtn:hover:not(:disabled) {
  background: rgba(251,191,36,0.18) !important;
  box-shadow: 0 0 36px rgba(251,191,36,0.22) !important;
}
.xamDrawBtn:disabled {
  opacity: 0.6;
  cursor: wait;
}
.xamNote {
  font-size: 11.5px;
  color: var(--tv-text-dim);
  text-align: center;
  margin: 0;
}

/* Right: History */
.xamHistoryList { min-height: 80px; }
.xamHistoryEmpty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 8px;
  color: var(--tv-text-dim);
  font-size: 12px;
  text-align: center;
  line-height: 1.5;
}
.xamStatRow {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--tv-border);
  font-size: 12.5px;
  color: var(--tv-text-sec);
}
.xamStatRow:last-child { border-bottom: none; }
.xamStatVal { color: var(--tv-xam); font-weight: 700; font-family: 'JetBrains Mono', monospace; }

/* Result display */
.xamResult {
  max-width: 640px;
  margin: 0 auto;
  padding: 40px 24px 80px;
  width: 100%;
}
.xamResultActions {
  text-align: center;
  margin-top: 24px;
}

/* Mobile: stack to 1 column */
@media (max-width: 900px) {
  .xamLayout {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    min-height: unset;
  }
  .xamColLeft   { border-right: none; border-bottom: 1px solid var(--tv-border); padding: 20px 16px; flex-direction: row; flex-wrap: wrap; gap: 16px; }
  .xamColCenter { padding: 32px 16px; }
  .xamColRight  { border-left: none; border-top: 1px solid var(--tv-border); padding: 20px 16px; flex-direction: row; gap: 24px; }
  .xamClassification, .xamSourceNote-wrap { display: none; }
  .xamTopicList { flex-direction: row; flex-wrap: wrap; gap: 6px; }
  .xamTopicList .xamTopic { width: auto; padding: 7px 14px; }
}

/* ══════════════════════════════════════════════════════════════════
   MOBILE BOTTOM NAV BAR (≤768px, when sidebar is hidden)
   ══════════════════════════════════════════════════════════════════ */
.tvMobileBar {
  display: none; /* hidden by default */
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(9,9,11,0.96);
  border-top: 1px solid rgba(255,255,255,0.08);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 0 0 env(safe-area-inset-bottom);
  height: calc(56px + env(safe-area-inset-bottom));
  align-items: stretch;
  justify-content: space-around;
  gap: 0;
}

@media (max-width: 768px) {
  .tvMobileBar { display: flex; }
  /* Push content up so it's not hidden behind the mobile bar */
  .tvContent { padding-bottom: calc(56px + env(safe-area-inset-bottom)); }
  .xamLayout { min-height: unset; }
}

.tvMobileTab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 4px 6px;
  background: none;
  border: none;
  color: #52525b;
  font-size: 10px;
  font-weight: 500;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  text-decoration: none;
  transition: color .15s;
}
.tvMobileTab svg { transition: stroke .15s; }
.tvMobileTab:hover { color: #a1a1aa; }

.tvMobileTab.isActive { color: var(--tv-home); }
.tvMobileTab[data-view="chart"].isActive  { color: var(--tv-chart); }
.tvMobileTab[data-view="xam"].isActive    { color: var(--tv-xam); }
.tvMobileTab:not([data-view]).isActive    { color: var(--tv-tarot); }

/* ══════════════════════════════════════════════════════════════════
   v1.02 DARK LOCK — Placed last to win cascade over all old theme CSS.
   The old codebase had light-themed :root[data-theme="heritage"] blocks
   (lines ~1618, ~5690) that override our dark vars. This block forces
   dark base on every theme variant so the redesign is always dark.
   ══════════════════════════════════════════════════════════════════ */

/* Force dark base colors for ALL theme variants */
:root,
:root[data-theme],
:root[data-theme="heritage"],
:root[data-theme="classic"],
:root[data-theme="neutral"],
:root[data-theme="clean"],
:root[data-theme="sage"] {
  --canvas:            #09090b !important;
  --bg:                #09090b !important;
  --surface:           #111114 !important;
  --surface-soft:      #17171b !important;
  --surface-cream:     #1a1a20 !important;
  --surface-parchment: #17171b !important;
  --ink:               #fafafa !important;
  --body:              #a1a1aa !important;
  --muted:             #71717a !important;
  --hairline:          rgba(255,255,255,0.06) !important;
  color-scheme: dark !important;
}

html, body {
  background: #09090b !important;
  color: #fafafa !important;
}

/* Override old heritage-cream grid pattern on landingView */
.landingView,
:root[data-theme] .landingView,
:root[data-theme="heritage"] .landingView,
:root[data-theme="classic"] .landingView,
:root[data-theme="neutral"] .landingView {
  background: #09090b !important;
}

/* Old landing components — force hidden (overrides line 6871 which has
   `.landingHero { display: flex !important }` earlier in this file) */
.landingHero,
.landingStats,
.landingFeatures,
.landingPhilosophy,
.landingHeroBadge,
.landingCards,
.landingCard,
.landingHeaderActions,
.landingFooter,
.landingKnowledgeLink,
.landingCtaPrimary,
.landingCtaSecondary,
.landingIntro,
.landingCta {
  display: none !important;
}

/* Input / select readability on dark bg */
input[type="text"],
input[type="search"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="email"],
input[type="password"],
input[type="tel"],
select,
textarea {
  background: #1c1c22 !important;
  color: #e4e4e7 !important;
  border-color: rgba(255,255,255,0.14) !important;
}
input::placeholder { color: #52525b !important; }
/* System date/time picker icons — invert to be visible on dark */
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
  filter: invert(0.75);
}
select option { background: #1c1c22 !important; color: #e4e4e7 !important; }

/* Radio / checkbox */
input[type="radio"],
input[type="checkbox"] { accent-color: var(--tv-accent, #c0392b); }

/* Form labels */
.field > span,
label > span,
fieldset > legend {
  color: #a1a1aa !important;
}

/* Chart form gender buttons */
.genderBtn {
  background: #1c1c22 !important;
  color: #e4e4e7 !important;
  border: 1px solid rgba(255,255,255,0.14) !important;
}
.genderBtn.isActive {
  background: var(--tv-chart, #a855f7) !important;
  color: #fff !important;
  border-color: var(--tv-chart, #a855f7) !important;
}

/* Calendar / lunar toggle */
.radioRow label { color: #a1a1aa !important; }

/* ═══════════════════════════════════════════════════
   DARK THEME NUCLEAR OVERRIDE  v1.03
   Beats :root[data-theme="heritage"] .X { !important } at (0,3,0,0)
   by matching specificity and appearing later in source order.
   ═══════════════════════════════════════════════════ */
:root[data-theme] .appShell,
:root[data-theme="heritage"] .appShell,
:root[data-theme="classic"]  .appShell,
:root[data-theme="neutral"]  .appShell  { background: var(--tv-bg) !important; }

:root[data-theme] .tvTopbar,
:root[data-theme="heritage"] .tvTopbar,
:root[data-theme="classic"]  .tvTopbar,
:root[data-theme="neutral"]  .tvTopbar  { background: var(--tv-bg) !important; border-color: var(--tv-border) !important; }

:root[data-theme] .tvSidebar,
:root[data-theme="heritage"] .tvSidebar,
:root[data-theme="classic"]  .tvSidebar,
:root[data-theme="neutral"]  .tvSidebar { background: #09090b !important; border-color: var(--tv-border) !important; }

:root[data-theme] .tvDisclaimer,
:root[data-theme="heritage"] .tvDisclaimer,
:root[data-theme="classic"]  .tvDisclaimer,
:root[data-theme="neutral"]  .tvDisclaimer { background: rgba(251,191,36,0.07) !important; border-color: rgba(251,191,36,0.2) !important; }

/* Heritage-overridden inputs → force dark */
:root[data-theme] input,
:root[data-theme="heritage"] input,
:root[data-theme="classic"]  input,
:root[data-theme="neutral"]  input,
:root[data-theme] select,
:root[data-theme="heritage"] select,
:root[data-theme="classic"]  select,
:root[data-theme="neutral"]  select,
:root[data-theme] textarea,
:root[data-theme="heritage"] textarea,
:root[data-theme="classic"]  textarea,
:root[data-theme="neutral"]  textarea   { background: #1c1c22 !important; color: #e4e4e7 !important; border-color: rgba(255,255,255,0.12) !important; }
:root[data-theme] .chartBuilder,
:root[data-theme="heritage"] .chartBuilder,
:root[data-theme="classic"]  .chartBuilder,
:root[data-theme="neutral"]  .chartBuilder  { background: var(--tv-bg) !important; }

:root[data-theme] .chartPanel,
:root[data-theme="heritage"] .chartPanel,
:root[data-theme="classic"]  .chartPanel,
:root[data-theme="neutral"]  .chartPanel,
:root[data-theme] .chartToolPane,
:root[data-theme="heritage"] .chartToolPane,
:root[data-theme="classic"]  .chartToolPane,
:root[data-theme="neutral"]  .chartToolPane { background: var(--tv-bg) !important; color: var(--tv-text) !important; border-color: var(--tv-border) !important; box-shadow: none !important; }

:root[data-theme] .chartPreview,
:root[data-theme="heritage"] .chartPreview,
:root[data-theme="classic"]  .chartPreview,
:root[data-theme="neutral"]  .chartPreview,
:root[data-theme] .readingPanel,
:root[data-theme="heritage"] .readingPanel,
:root[data-theme="classic"]  .readingPanel,
:root[data-theme="neutral"]  .readingPanel,
:root[data-theme] .jsonPanel,
:root[data-theme="heritage"] .jsonPanel,
:root[data-theme="classic"]  .jsonPanel,
:root[data-theme="neutral"]  .jsonPanel     { background: var(--tv-surface) !important; border-color: var(--tv-border) !important; color: var(--tv-text) !important; box-shadow: none !important; }

:root[data-theme] .fieldGroup,
:root[data-theme="heritage"] .fieldGroup,
:root[data-theme="classic"]  .fieldGroup,
:root[data-theme="neutral"]  .fieldGroup,
:root[data-theme] .fixturePanel,
:root[data-theme="heritage"] .fixturePanel,
:root[data-theme="classic"]  .fixturePanel,
:root[data-theme="neutral"]  .fixturePanel  { background: var(--tv-bg) !important; border-color: var(--tv-border) !important; box-shadow: none !important; }

:root[data-theme] .recordToolbar,
:root[data-theme="heritage"] .recordToolbar,
:root[data-theme="classic"]  .recordToolbar,
:root[data-theme="neutral"]  .recordToolbar { background: var(--tv-surface) !important; border-color: var(--tv-border) !important; box-shadow: none !important; }

:root[data-theme] .record,
:root[data-theme="heritage"] .record,
:root[data-theme="classic"]  .record,
:root[data-theme="neutral"]  .record        { background: var(--tv-surface) !important; border-color: var(--tv-border) !important; color: var(--tv-text) !important; box-shadow: none !important; }

:root[data-theme] .workspaceHeader,
:root[data-theme="heritage"] .workspaceHeader,
:root[data-theme="classic"]  .workspaceHeader,
:root[data-theme="neutral"]  .workspaceHeader { background: var(--tv-bg) !important; border-color: var(--tv-border) !important; box-shadow: none !important; color: var(--tv-text) !important; }

:root[data-theme] .workspaceHeader h1,
:root[data-theme="heritage"] .workspaceHeader h1,
:root[data-theme="classic"]  .workspaceHeader h1,
:root[data-theme="neutral"]  .workspaceHeader h1 { color: var(--tv-text) !important; }

:root[data-theme] .workspaceHeader .eyebrow,
:root[data-theme="heritage"] .workspaceHeader .eyebrow,
:root[data-theme="classic"]  .workspaceHeader .eyebrow,
:root[data-theme="neutral"]  .workspaceHeader .eyebrow { color: var(--tv-tarot, #fb7185) !important; }

:root[data-theme] .workspaceHeader .intro,
:root[data-theme="heritage"] .workspaceHeader .intro,
:root[data-theme="classic"]  .workspaceHeader .intro,
:root[data-theme="neutral"]  .workspaceHeader .intro { color: var(--tv-text-sec) !important; }

:root[data-theme] .filterRail,
:root[data-theme="heritage"] .filterRail,
:root[data-theme="classic"]  .filterRail,
:root[data-theme="neutral"]  .filterRail   { background: var(--tv-surface) !important; border-color: var(--tv-border) !important; box-shadow: none !important; }

:root[data-theme] .workspace,
:root[data-theme="heritage"] .workspace,
:root[data-theme="classic"]  .workspace,
:root[data-theme="neutral"]  .workspace    { background: var(--tv-bg) !important; box-shadow: none !important; }

:root[data-theme] .detailPane,
:root[data-theme="heritage"] .detailPane,
:root[data-theme="classic"]  .detailPane,
:root[data-theme="neutral"]  .detailPane   { background: var(--tv-bg) !important; border-color: var(--tv-border) !important; box-shadow: none !important; }

:root[data-theme] .detailEmpty,
:root[data-theme="heritage"] .detailEmpty,
:root[data-theme="classic"]  .detailEmpty,
:root[data-theme="neutral"]  .detailEmpty  { background: transparent !important; border: none !important; box-shadow: none !important; }

:root[data-theme] .detailHero,
:root[data-theme="heritage"] .detailHero,
:root[data-theme="classic"]  .detailHero,
:root[data-theme="neutral"]  .detailHero,
:root[data-theme] .detailBlock,
:root[data-theme="heritage"] .detailBlock,
:root[data-theme="classic"]  .detailBlock,
:root[data-theme="neutral"]  .detailBlock  { background: var(--tv-surface) !important; border-color: var(--tv-border) !important; box-shadow: none !important; }

/* ── NUCLEAR v1.09: MISSING PANEL OVERRIDES ─────────────────────────────── */

/* Tool panels: geminiReadingPanel, questionToolPanel, oracleToolPanel */
:root[data-theme] .geminiReadingPanel,
:root[data-theme="heritage"] .geminiReadingPanel,
:root[data-theme="classic"]  .geminiReadingPanel,
:root[data-theme="neutral"]  .geminiReadingPanel,
:root[data-theme] .questionToolPanel,
:root[data-theme="heritage"] .questionToolPanel,
:root[data-theme="classic"]  .questionToolPanel,
:root[data-theme="neutral"]  .questionToolPanel,
:root[data-theme] .oracleToolPanel,
:root[data-theme="heritage"] .oracleToolPanel,
:root[data-theme="classic"]  .oracleToolPanel,
:root[data-theme="neutral"]  .oracleToolPanel  { background: var(--tv-surface) !important; border-color: var(--tv-border) !important; box-shadow: none !important; color: var(--tv-text) !important; }

/* Reference + compare panels */
:root[data-theme] .internalReadingDetails,
:root[data-theme="heritage"] .internalReadingDetails,
:root[data-theme="classic"]  .internalReadingDetails,
:root[data-theme="neutral"]  .internalReadingDetails,
:root[data-theme] .sourceReferenceDetails,
:root[data-theme="heritage"] .sourceReferenceDetails,
:root[data-theme="classic"]  .sourceReferenceDetails,
:root[data-theme="neutral"]  .sourceReferenceDetails,
:root[data-theme] .iztroComparePanel,
:root[data-theme="heritage"] .iztroComparePanel,
:root[data-theme="classic"]  .iztroComparePanel,
:root[data-theme="neutral"]  .iztroComparePanel,
:root[data-theme] .chartToolHeader,
:root[data-theme="heritage"] .chartToolHeader,
:root[data-theme="classic"]  .chartToolHeader,
:root[data-theme="neutral"]  .chartToolHeader  { background: var(--tv-surface) !important; border-color: var(--tv-border) !important; box-shadow: none !important; color: var(--tv-text) !important; }

/* geminiReadingContent — AI reading text body */
:root[data-theme] .geminiReadingContent,
:root[data-theme="heritage"] .geminiReadingContent { background: transparent !important; color: var(--tv-text) !important; border-color: var(--tv-border) !important; }
:root[data-theme] .geminiReadingContent h4,
:root[data-theme] .geminiReadingContent p,
:root[data-theme] .geminiReadingContent li,
:root[data-theme="heritage"] .geminiReadingContent h4,
:root[data-theme="heritage"] .geminiReadingContent p,
:root[data-theme="heritage"] .geminiReadingContent li { color: var(--tv-text) !important; }

/* viewSwitch — Nhập liệu / JSON tab toggle */
:root[data-theme] .viewSwitch,
:root[data-theme="heritage"] .viewSwitch { background: rgba(255,255,255,0.06) !important; border-color: rgba(255,255,255,0.1) !important; }
:root[data-theme] .viewSwitch .viewButton,
:root[data-theme="heritage"] .viewSwitch .viewButton { color: var(--tv-text-sec) !important; background: transparent !important; }
:root[data-theme] .viewSwitch .viewButton.isActive,
:root[data-theme="heritage"] .viewSwitch .viewButton.isActive { background: var(--tv-chart, #a855f7) !important; color: #fff !important; }

/* #jsonOutput raw textarea / pre — heritage sets cream bg + dark-red text */
:root[data-theme] #jsonOutput,
:root[data-theme="heritage"] #jsonOutput { background: var(--tv-surface-soft, #1c1c22) !important; color: #a3e635 !important; border-color: var(--tv-border) !important; }

/* chartUtilityTabs — plain rule uses rgba(255,255,255,.84) !important at (0,2,0) */
.chartToolPane .chartUtilityTabs { background: rgba(255,255,255,0.05) !important; border-color: rgba(255,255,255,0.08) !important; }
:root[data-theme] .chartUtilityTabs,
:root[data-theme="heritage"] .chartUtilityTabs { background: rgba(255,255,255,0.05) !important; border-color: rgba(255,255,255,0.08) !important; }

/* tokenCostBadge */
:root[data-theme] .tokenCostBadge,
:root[data-theme="heritage"] .tokenCostBadge { background: var(--tv-surface-soft, #1c1c22) !important; border-color: var(--tv-border) !important; color: var(--tv-text-muted) !important; }

/* ── TỬ VI CHART CELLS ──────────────────────────────────────────────────── */

/* tuViPalace — 12 palace cells (cream from base rule, no !important) */
:root[data-theme] .tuViPalace,
:root[data-theme="heritage"] .tuViPalace,
:root[data-theme="classic"]  .tuViPalace,
:root[data-theme="neutral"]  .tuViPalace { background: var(--tv-surface) !important; border-color: var(--tv-border-mid, rgba(255,255,255,0.12)) !important; color: var(--tv-text) !important; }

/* tuViCenter — center cell */
:root[data-theme] .tuViCenter,
:root[data-theme="heritage"] .tuViCenter,
:root[data-theme="classic"]  .tuViCenter,
:root[data-theme="neutral"]  .tuViCenter { background: var(--tv-surface-soft, #1f1f24) !important; border-color: rgba(255,255,255,0.15) !important; color: var(--tv-text) !important; }

/* tuViBoard grid background */
:root[data-theme] .tuViBoard,
:root[data-theme="heritage"] .tuViBoard,
:root[data-theme="classic"]  .tuViBoard,
:root[data-theme="neutral"]  .tuViBoard  { background: var(--tv-bg) !important; border-color: var(--tv-border) !important; }

/* externalChartPreview + previewBoard */
:root[data-theme] .externalChartPreview,
:root[data-theme="heritage"] .externalChartPreview { background: var(--tv-surface) !important; border-color: var(--tv-border) !important; }
:root[data-theme] .previewBoard,
:root[data-theme="heritage"] .previewBoard { background: var(--tv-bg) !important; border-color: var(--tv-border) !important; }

/* ── PALACE CELL TEXT COLORS ─────────────────────────────────────────────── */

:root[data-theme] .palaceTop span,
:root[data-theme="heritage"] .palaceTop span { color: var(--tv-text-sec, #a1a1aa) !important; }
:root[data-theme] .palaceTop strong,
:root[data-theme="heritage"] .palaceTop strong { color: var(--tv-chart, #a855f7) !important; }
:root[data-theme] .boardBrand,
:root[data-theme="heritage"] .boardBrand { color: var(--tv-chart, #a855f7) !important; }
:root[data-theme] .centerFacts dt,
:root[data-theme="heritage"] .centerFacts dt { color: var(--tv-text-muted, #71717a) !important; }
:root[data-theme] .centerFacts dd,
:root[data-theme="heritage"] .centerFacts dd { color: var(--tv-text-sec, #a1a1aa) !important; }
:root[data-theme] .mainStar,
:root[data-theme="heritage"] .mainStar { color: var(--tv-text) !important; }
:root[data-theme] .minorStar,
:root[data-theme="heritage"] .minorStar { color: var(--tv-text-muted, #a1a1aa) !important; }
:root[data-theme] .transformStar,
:root[data-theme="heritage"] .transformStar { color: var(--tv-tarot, #f59e0b) !important; }

/* ── SUMMARY + READING SECTIONS TEXT ────────────────────────────────────── */

:root[data-theme] .sourceReferenceDetails summary,
:root[data-theme="heritage"] .sourceReferenceDetails summary,
:root[data-theme] .internalReadingDetails summary,
:root[data-theme="heritage"] .internalReadingDetails summary { color: var(--tv-text-sec) !important; }
:root[data-theme] .sourceReferenceDetails .readingGroup,
:root[data-theme="heritage"] .sourceReferenceDetails .readingGroup { color: var(--tv-text) !important; }
:root[data-theme] .questionToolGrid label,
:root[data-theme="heritage"] .questionToolGrid label { color: var(--tv-text-sec) !important; }

/* ── SYNTHESIS / READING ESSAY PANELS ───────────────────────────────────── */

/* "Tổng hợp toàn lá số" inner article cards — white bg from base CSS */
:root[data-theme] .synthesisNarrative article,
:root[data-theme="heritage"] .synthesisNarrative article,
:root[data-theme="classic"]  .synthesisNarrative article,
:root[data-theme="neutral"]  .synthesisNarrative article,
:root[data-theme] .wholeChartEssay article,
:root[data-theme="heritage"] .wholeChartEssay article,
:root[data-theme="classic"]  .wholeChartEssay article,
:root[data-theme="neutral"]  .wholeChartEssay article  { background: var(--tv-surface-soft, #1f1f24) !important; border-color: var(--tv-border) !important; }
:root[data-theme] .synthesisNarrative h4,
:root[data-theme="heritage"] .synthesisNarrative h4,
:root[data-theme] .wholeChartEssay h4,
:root[data-theme="heritage"] .wholeChartEssay h4       { color: var(--tv-text) !important; }
:root[data-theme] .synthesisNarrative p,
:root[data-theme="heritage"] .synthesisNarrative p,
:root[data-theme] .wholeChartEssay p,
:root[data-theme="heritage"] .wholeChartEssay p         { color: var(--tv-text-sec) !important; }

/* essayClosing — cream bg with red left border */
:root[data-theme] .essayClosing,
:root[data-theme="heritage"] .essayClosing { background: rgba(168,85,247,0.08) !important; border-left-color: var(--tv-chart, #a855f7) !important; }
:root[data-theme] .essayClosing strong,
:root[data-theme="heritage"] .essayClosing strong { color: var(--tv-text) !important; }

/* ── viewSwitch — active button follows theme A/B/C accent ──────────────── */
/* Override the previous --tv-chart purple with --tv-accent */
:root[data-theme] .viewSwitch .viewButton.isActive,
:root[data-theme="heritage"] .viewSwitch .viewButton.isActive { background: var(--tv-accent) !important; color: #09090b !important; box-shadow: 0 0 8px var(--tv-glow, rgba(34,211,238,0.2)) !important; }
:root[data-theme] .viewSwitch,
:root[data-theme="heritage"] .viewSwitch { border-color: var(--tv-accent-soft, rgba(255,255,255,0.1)) !important; }

/* ── chartToolTab (Nhập liệu/JSON) — accent fill for active ─────────────── */
:root[data-theme] .chartToolTab.isActive,
:root[data-theme="heritage"] .chartToolTab.isActive,
:root[data-theme="classic"]  .chartToolTab.isActive,
:root[data-theme="neutral"]  .chartToolTab.isActive { background: var(--tv-accent) !important; color: #09090b !important; box-shadow: 0 0 8px var(--tv-glow) !important; }
:root[data-theme] .chartUtilityTabs,
:root[data-theme="heritage"] .chartUtilityTabs,
:root[data-theme="classic"]  .chartUtilityTabs,
:root[data-theme="neutral"]  .chartUtilityTabs { border-color: var(--tv-accent-soft, rgba(255,255,255,0.08)) !important; }

/* ── xamTopic active — solid accent fill ────────────────────────────────── */
:root[data-theme] .xamTopic.isActive,
:root[data-theme="heritage"] .xamTopic.isActive { background: var(--tv-accent) !important; color: #09090b !important; border-color: var(--tv-accent) !important; box-shadow: 0 0 12px var(--tv-glow) !important; font-weight: 600 !important; }
:root[data-theme] .xamDrawBtn,
:root[data-theme="heritage"] .xamDrawBtn { background: var(--tv-accent-soft) !important; color: var(--tv-accent) !important; border-color: var(--tv-accent-soft) !important; }

/* ── openDetail / secondaryAction — white bg override ───────────────────── */
/* Hard-coded rgb(255,255,255) rule later in file beats var(--canvas). Fix: */
:root[data-theme] .openDetail,
:root[data-theme="heritage"] .openDetail,
:root[data-theme="classic"]  .openDetail,
:root[data-theme="neutral"]  .openDetail { background: var(--tv-surface-soft, #1f1f24) !important; border-color: var(--tv-border, rgba(255,255,255,0.08)) !important; color: var(--tv-text, #f4f4f5) !important; }
:root[data-theme] .openDetail:hover,
:root[data-theme="heritage"] .openDetail:hover { background: var(--tv-surface, #18181b) !important; border-color: var(--tv-accent-soft) !important; }

/* ── badge / recordType / detailTag — still light-gray hardcoded ─────────── */
:root[data-theme] .badge,
:root[data-theme="heritage"] .badge,
:root[data-theme="classic"]  .badge,
:root[data-theme="neutral"]  .badge { background: var(--tv-accent-soft, rgba(34,211,238,0.1)) !important; color: var(--tv-accent, #22d3ee) !important; border-color: var(--tv-accent-soft) !important; }
:root[data-theme] .badge.major,
:root[data-theme="heritage"] .badge.major { background: rgba(192,132,252,0.12) !important; color: #c084fc !important; }
:root[data-theme] .badge.minor,
:root[data-theme="heritage"] .badge.minor { background: rgba(251,191,36,0.1) !important; color: #fbbf24 !important; }
:root[data-theme] .recordType,
:root[data-theme="heritage"] .recordType,
:root[data-theme="classic"]  .recordType,
:root[data-theme="neutral"]  .recordType { background: var(--tv-accent-soft) !important; color: var(--tv-text-sec, #a1a1aa) !important; border-color: var(--tv-accent-soft) !important; }
:root[data-theme] .detailTag,
:root[data-theme="heritage"] .detailTag { background: var(--tv-surface, #18181b) !important; color: var(--tv-text-sec) !important; border-color: var(--tv-border) !important; }

/* ── sourcePolicy (filter rail info box) ────────────────────────────────── */
:root[data-theme] .sourcePolicy,
:root[data-theme="heritage"] .sourcePolicy { background: var(--tv-surface-soft) !important; border-color: var(--tv-border) !important; color: var(--tv-text-sec) !important; }

/* ── eyebrow pill bg (chart page white pill) ─────────────────────────────── */
:root[data-theme] .eyebrow,
:root[data-theme="heritage"] .eyebrow { background: transparent !important; }

/* Must be last: force [hidden] attribute to always hide elements,
   even when a higher-priority display:grid/flex !important exists above. */
[hidden] { display: none !important; }
