:root {
  --bg: #f3f1ec;
  --surface: #ffffff;
  --surface-2: #f8f7f4;
  --text: #1c1b19;
  --muted: #6b675f;
  --border: #e2ded5;
  --accent: #b4441c;
  --accent-soft: #f6e5dc;
  --focus: #2f5fd0;
  /* slide palette stays "paper" in both themes, like a printed deck */
  --paper: #fbf9f4;
  --ink: #1d1b17;
  --ink-2: #57524a;
  --rule: #d9d3c6;
  --s-accent: #b4441c;
  --s-accent-2: #285e61;
  --serif: "Fraunces", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161513;
    --surface: #1f1e1b;
    --surface-2: #262521;
    --text: #ece9e2;
    --muted: #a19c92;
    --border: #36342f;
    --accent: #e0774c;
    --accent-soft: #3a2a22;
    --focus: #7aa2ff;
  }
}
:root[data-theme="dark"] {
  --bg: #161513; --surface: #1f1e1b; --surface-2: #262521; --text: #ece9e2;
  --muted: #a19c92; --border: #36342f; --accent: #e0774c; --accent-soft: #3a2a22; --focus: #7aa2ff;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- chrome ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px; border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.brand { font: 600 17px var(--serif); letter-spacing: -0.01em; }
.source { color: var(--muted); font-size: 13px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.source a { color: inherit; }

.layout { display: grid; grid-template-columns: 320px 1fr; min-height: calc(100vh - 49px); }
.panel {
  border-right: 1px solid var(--border); background: var(--surface);
  padding: 16px; display: flex; flex-direction: column; gap: 18px;
  position: sticky; top: 49px; height: calc(100vh - 49px); overflow-y: auto;
}
.panel h3 { margin: 0 0 8px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px;
  padding: 4px 10px; font-size: 12.5px; cursor: pointer;
}
.chip:hover { border-color: var(--accent); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.dial { padding: 10px 0; border-bottom: 1px solid var(--border); }
.dial:last-child { border-bottom: 0; }
.dial-head { display: flex; align-items: baseline; gap: 6px; margin-bottom: 6px; }
.dial-name { font-weight: 600; flex: 1; }
.dial-tag { font-size: 11px; color: var(--muted); }
.dial-x { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 2px; font-size: 15px; line-height: 1; }
.dial-x:hover { color: var(--accent); }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface-2); padding: 5px 0; cursor: pointer; font-size: 12.5px; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent); color: #fff; font-weight: 600; }
.dial-desc { margin-top: 6px; font-size: 12px; color: var(--muted); line-height: 1.4; }

.add-dim summary { cursor: pointer; color: var(--accent); font-size: 13px; margin-top: 10px; }
.add-dim form { display: grid; gap: 8px; margin-top: 10px; }
.add-dim label { display: grid; gap: 3px; font-size: 12px; color: var(--muted); }
.add-dim input { border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; background: var(--surface-2); }

.actions { margin-top: auto; display: grid; gap: 8px; position: sticky; bottom: -16px; background: var(--surface); padding: 12px 0 16px; border-top: 1px solid var(--border); }
.change-note { font-size: 12.5px; color: var(--muted); min-height: 18px; }
.change-note b { color: var(--accent); }
.fine { font-size: 11.5px; color: var(--muted); }

.btn {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px;
  padding: 7px 12px; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; padding: 10px 12px; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.primary:disabled { opacity: .55; cursor: progress; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 9px; font-size: 12.5px; }

.main { padding: 16px 24px 48px; min-width: 0; }
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar select { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 6px 8px; max-width: 360px; }
.tabs { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.tab { border: 0; background: var(--surface); padding: 6px 12px; cursor: pointer; color: var(--muted); }
.tab + .tab { border-left: 1px solid var(--border); }
.tab.on { background: var(--text); color: var(--bg); }
.toolbar-right { margin-left: auto; display: flex; gap: 6px; }

.interp { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; }
.interp p { margin: 0 0 8px; }
.interp .meta { font-size: 12px; color: var(--muted); }
.dchips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.dchip { font-size: 11.5px; border-radius: 5px; padding: 2px 7px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.dchip b { color: var(--text); font-weight: 600; }
.dchip.diff { border-color: var(--accent); background: var(--accent-soft); }
.dchip.diff b { color: var(--accent); }

.progress { background: var(--surface); border: 1px solid var(--accent); border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; }
.progress-head { display: flex; align-items: center; gap: 10px; }
.progress-head #progressStatus { flex: 1; font-weight: 500; }
.pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }
.thinking { margin-top: 8px; font-size: 12.5px; color: var(--muted); max-height: 7.5em; overflow: hidden; white-space: pre-wrap; display: flex; flex-direction: column-reverse; }
.thinking:empty { display: none; }
.error { background: var(--accent-soft); border: 1px solid var(--accent); color: var(--text); border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; white-space: pre-wrap; }

/* present view */
.present { max-width: min(1100px, calc((100vh - 300px) * 16 / 9)); min-width: min(100%, 560px); }
.present-nav { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.present-nav .count { color: var(--muted); font-variant-numeric: tabular-nums; }
.notes { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; color: var(--muted); }
.notes b { color: var(--text); font-weight: 600; margin-right: 6px; }
.strip { display: grid; grid-auto-flow: column; grid-auto-columns: 150px; gap: 10px; overflow-x: auto; padding: 14px 2px 6px; }
.thumb { cursor: pointer; border-radius: 6px; outline: 2px solid transparent; outline-offset: 2px; }
.thumb.on { outline-color: var(--accent); }

/* grid + compare */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.compare-col { min-width: 0; display: grid; gap: 12px; align-content: start; }
.compare-col select { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 6px 8px; }
.compare-col .interp { margin: 0; }
.compare-col .grid { grid-template-columns: 1fr; }
.empty { color: var(--muted); padding: 40px; text-align: center; border: 1px dashed var(--border); border-radius: 10px; }

/* ---------- slides ---------- */
.slide {
  --fit: 1;
  position: relative; aspect-ratio: 16 / 9; container-type: inline-size;
  background: var(--paper); color: var(--ink);
  border-radius: 8px; overflow: hidden;
  box-shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 18px rgba(0,0,0,.07);
  font-family: var(--b-font);
  --rule: color-mix(in srgb, var(--ink) 18%, var(--paper));
}
.slide.pending { opacity: .6; }
.s-heading, .l-quote blockquote, .s-stat-value { font-family: var(--h-font); }
.s-inner { position: absolute; inset: 0; padding: 6cqw 7cqw 5.5cqw; display: flex; flex-direction: column; gap: calc(var(--fit) * 1.6cqw); }
.s-num { position: absolute; right: 2.4cqw; bottom: 1.8cqw; font-size: 1.3cqw; color: var(--ink-2); opacity: .7; }
.s-kicker { font-size: calc(var(--fit) * 1.45cqw); font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--s-accent); }
.s-heading { margin: 0; font: 600 calc(var(--fit) * 3.9cqw)/1.12 var(--h-font); letter-spacing: -0.01em; }
.s-body { margin: 0; font-size: calc(var(--fit) * 2.1cqw); line-height: 1.45; color: var(--ink-2); }
.s-bullets { margin: 0.6cqw 0 0; padding: 0; list-style: none; display: grid; gap: calc(var(--fit) * 1.3cqw); }
.s-bullets li { position: relative; padding-left: 2.6cqw; font-size: calc(var(--fit) * 2.2cqw); line-height: 1.35; }
.s-bullets li::before { content: ""; position: absolute; left: 0.4cqw; top: 0.62em; width: 1cqw; height: 0.28cqw; background: var(--s-accent); }
.s-center { margin: auto 0; display: flex; flex-direction: column; gap: calc(var(--fit) * 1.6cqw); }

.l-title .s-inner { justify-content: center; }
.l-title .s-heading { font-size: calc(var(--fit) * 6.4cqw); line-height: 1.04; }
.l-title .s-inner::before { content: ""; width: 7cqw; height: .55cqw; background: var(--s-accent); order: -1; margin-bottom: 1cqw; }

.l-section { background: var(--ink); color: var(--paper); }
.l-section .s-inner { justify-content: flex-end; padding-bottom: 8cqw; }
.l-section .s-kicker { color: color-mix(in srgb, var(--s-accent) 55%, var(--paper)); }
.l-section .s-heading { font-size: calc(var(--fit) * 5.4cqw); }
.l-section .s-num { color: var(--paper); }

.l-statement .s-inner { justify-content: center; }
.l-statement .s-heading { font-size: calc(var(--fit) * 5cqw); line-height: 1.12; max-width: 90%; }
.l-statement .s-body { font-size: calc(var(--fit) * 2.3cqw); max-width: 80%; }

.s-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 2.4cqw; flex: 1; min-height: 0; margin-top: 1cqw; }
.s-side { border-radius: 1cqw; padding: 2.2cqw 2.4cqw; background: var(--s-surface); }
.s-side.b { background: color-mix(in srgb, var(--s-accent-2) 12%, var(--paper)); }
.s-side h4 { margin: 0 0 1.2cqw; font: 600 calc(var(--fit) * 2.2cqw) var(--b-font); color: var(--s-accent); text-transform: uppercase; letter-spacing: .06em; font-size: calc(var(--fit) * 1.5cqw); }
.s-side.b h4 { color: var(--s-accent-2); }
.s-side .s-bullets li { font-size: calc(var(--fit) * 2cqw); }
.s-side.b .s-bullets li::before { background: var(--s-accent-2); }

.l-quote .s-inner { justify-content: center; }
.l-quote blockquote { margin: 0; font: italic 400 calc(var(--fit) * 3.6cqw)/1.3 var(--h-font); position: relative; padding-left: 5cqw; }
.l-quote blockquote::before { content: "“"; position: absolute; left: -0.5cqw; top: -2.4cqw; font-size: 11cqw; color: var(--s-accent); font-style: normal; line-height: 1; }
.l-quote cite { font-style: normal; font-size: calc(var(--fit) * 1.8cqw); color: var(--ink-2); padding-left: 5cqw; }

.s-stat { display: flex; align-items: baseline; gap: 3cqw; flex-wrap: wrap; margin: auto 0; }
.s-stat-value { font: 700 calc(var(--fit) * 10cqw)/1 var(--h-font); color: var(--s-accent); letter-spacing: -0.02em; }
.s-stat-label { font-size: calc(var(--fit) * 2.4cqw); max-width: 45cqw; line-height: 1.35; }

.s-timeline { list-style: none; margin: auto 0; padding: 3.2cqw 0 0; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 1.6cqw; position: relative; }
.s-timeline::before { content: ""; position: absolute; left: 0; right: 0; top: 3.2cqw; height: .3cqw; background: var(--rule); }
.s-timeline li { position: relative; padding-top: 2.4cqw; }
.s-timeline li::before { content: ""; position: absolute; top: -0.65cqw; left: 0; width: 1.6cqw; height: 1.6cqw; border-radius: 50%; background: var(--s-accent); border: .4cqw solid var(--paper); }
.s-when { display: block; font-weight: 600; font-size: calc(var(--fit) * 1.55cqw); color: var(--s-accent); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .8cqw; }
.s-what { display: block; font-size: calc(var(--fit) * 1.9cqw); line-height: 1.35; }

.l-story { background: color-mix(in srgb, var(--s-surface) 60%, var(--paper)); }
.l-story .s-inner { justify-content: center; padding-left: 10cqw; }
.l-story .s-inner::before { content: ""; position: absolute; left: 6cqw; top: 22%; bottom: 22%; width: .4cqw; background: var(--s-accent); }
.l-story .s-body { font: 400 calc(var(--fit) * 2.5cqw)/1.5 var(--h-font); color: var(--ink); max-width: 92%; }

.l-question { background: color-mix(in srgb, var(--s-accent-2) 10%, var(--paper)); }
.l-question .s-inner { justify-content: center; }
.l-question .s-heading { font-size: calc(var(--fit) * 4.8cqw); max-width: 88%; }
.l-question::after { content: "?"; position: absolute; right: 5cqw; bottom: -4cqw; font: 700 30cqw/1 var(--h-font); color: var(--s-accent-2); opacity: .12; }

.l-takeaway .s-inner { border-top: 1.2cqw solid var(--s-accent); }
.l-takeaway .s-heading { font-size: calc(var(--fit) * 4.4cqw); }
.l-takeaway .s-bullets li { font-size: calc(var(--fit) * 2.5cqw); font-weight: 500; }

/* ---------- dialog ---------- */
dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); padding: 0; width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.35); }
.dlg { padding: 18px; display: grid; gap: 12px; }
.dlg h3 { margin: 0; font: 600 17px var(--serif); }
.dlg > p, .dlg p.muted { margin: 0; color: var(--muted); font-size: 13px; }
.dlg input, .dlg textarea { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: var(--surface-2); width: 100%; }
.dlg textarea { font: 12.5px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; }
.dlg #addText { font: 13px/1.5 var(--sans); }
.dlg-actions { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }
.field { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.small-tabs .tab { padding: 5px 12px; font-size: 13px; }
.add-status { font-size: 13px; color: var(--accent); }
.add-status:empty { display: none; }
.review { display: grid; gap: 4px; }
.review h4 { margin: 0; font: 600 16px var(--serif); }
.review p { margin: 0; font-size: 13px; }
.review-secs { margin: 6px 0 0; padding-left: 18px; font-size: 13px; color: var(--muted); max-height: 160px; overflow: auto; }
.library-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 420px; overflow: auto; }
.library-list li { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: var(--surface-2); }
.library-list li.on { border-color: var(--accent); }
.lib-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.lib-main b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-main span { font-size: 12px; }
.btn.danger { color: var(--accent); border-color: var(--accent); }

/* ---------- topbar item picker ---------- */
.item-pick { display: flex; align-items: center; gap: 6px; min-width: 0; }
.item-pick select { border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px; padding: 5px 8px; max-width: 420px; min-width: 0; }
.muted { color: var(--muted); }

/* ---------- generate area ---------- */
.check { display: flex; gap: 6px; align-items: baseline; font-size: 12.5px; }
.check input { margin: 0; }
.cache { font-weight: 600; margin-right: 4px; font-variant-numeric: tabular-nums; }
.cache.warm { color: #2f7d4f; }
.cache.cold { color: var(--muted); }
.chip.researched::after { content: " ✓"; color: #2f7d4f; font-size: 11px; }
.chip.persona.on.researched::after { color: inherit; }

/* ---------- source view ---------- */
.source-view { display: grid; gap: 18px; max-width: 920px; }
.source-view section { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.source-view h2 { margin: 2px 0 6px; font: 600 22px/1.2 var(--serif); }
.source-view h3 { margin: 0 0 10px; font: 600 16px var(--serif); }
.source-view h4 { margin: 12px 0 6px; font-size: 13.5px; }
.source-view p { margin: 0 0 6px; }
.src-kicker { font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
.src-sec ul, .notes-list { margin: 0; padding-left: 18px; display: grid; gap: 4px; font-size: 13.5px; }
.src-sec blockquote { margin: 6px 0; padding-left: 10px; border-left: 3px solid var(--accent); font-style: italic; font-size: 13.5px; }
.src-sec cite { font-style: normal; color: var(--muted); }
.src-nums { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; font-size: 12.5px; }
.src-nums span { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 2px 8px; }
.kind { display: inline-block; font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; border-radius: 4px; padding: 0 5px; margin-right: 6px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.k-prediction, .k-counterpoint { color: var(--accent); border-color: var(--accent); }
.k-fact, .k-reported, .k-verification { color: #2f7d4f; border-color: #2f7d4f; }
.note-src { font-size: 12px; color: var(--muted); margin-top: 2px; }
.note-src a { color: inherit; }

/* ---------- personas ---------- */
.chip.persona { background: var(--surface); }
.chip.persona.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip.suggested { border-style: dashed; }
.persona-brief { font-size: 12px; color: var(--muted); line-height: 1.4; margin-top: 8px; }
.persona-brief:empty { display: none; }
.persona-brief b { color: var(--text); }
.suggested-head { margin-top: 10px; }
#suggested:not(:empty) { margin-top: 8px; }
.dchip.persona-chip { background: var(--text); color: var(--bg); border-color: var(--text); }
.dchip.persona-chip b { color: var(--bg); }

/* ---------- spend ---------- */
.spend { font-variant-numeric: tabular-nums; }
dialog.wide { width: min(760px, calc(100vw - 32px)); }
.spend-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.spend-summary div { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.spend-summary b { display: block; font: 600 20px var(--serif); font-variant-numeric: tabular-nums; }
.spend-summary span { font-size: 12px; color: var(--muted); }
.ledger-wrap { max-height: 320px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.ledger { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.ledger th, .ledger td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.ledger th { position: sticky; top: 0; background: var(--surface); color: var(--muted); font-weight: 600; }
.ledger td.num, .ledger th.num { text-align: right; }
.ledger td.note { white-space: normal; color: var(--muted); }

/* ---------- narrow screens ---------- */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .panel { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .actions { position: static; }
  .main { padding: 16px; }
  .compare { grid-template-columns: 1fr; }
  .toolbar-right { margin-left: 0; }
}
