/* Doublespeak v8 — Volume Map (treemap).
   Aesthetic target: data physical mass — cell area encodes corpus_posts.
   Single-screen, 4 horizontal bands by chapter_role, cells flex-grow by volume.
   Bottom slide-in detail panel on click (different from v4 inline / v5 bottom-section / v6 mode-switch / v7 right-side).
   Color palette: saturated role colors with cream text — distinct from v7's pale-tints + ink-text. */

:root {
  /* Surface */
  --paper:        #f8f6f0;
  --paper-2:      #f1ede4;
  --ink:          #1c1916;
  --muted:        #6a6256;
  --faint:        #a59c8e;
  --line:         #e1d9c8;
  --line-strong:  #2c2520;

  /* Saturated role colors — the cell fills */
  --seed-red:     #b91c1c;
  --lead-amber:   #b0852f;
  --grss-blue:    #2c5fa3;
  --slnt-gray:    #5a554d;

  /* Cream text against the saturated cells */
  --cell-text:    #f5f0e2;
  --cell-text-dim: rgba(245, 240, 226, 0.65);

  --max:    1640px;
  --pad-x:  clamp(14px, 1.8vw, 28px);

  --font-display: "Helvetica Neue", "Helvetica Neue Condensed", "Arial Narrow", Helvetica, Arial, sans-serif;
  --font-text:    "Helvetica Neue", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono:    ui-monospace, "SF Mono", Menlo, "JetBrains Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  padding-top: 52px;
  padding-bottom: 96px;
  min-height: 100vh;
  overflow: hidden;     /* v8 is zero-scroll on L1 */
}
a { color: inherit; text-decoration: none; }
button { font: inherit; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ===== Top + bottom bars ===== */
.bar {
  position: fixed; left: 0; right: 0; z-index: 200;
  display: flex; align-items: center;
  background: var(--paper);
}
.bar-top {
  top: 0; height: 52px;
  padding: 0 clamp(14px, 1.8vw, 28px);
  border-bottom: 1px solid var(--line-strong);
  justify-content: space-between;
}
.bar-bottom {
  bottom: 0; min-height: 60px;
  padding: 8px clamp(14px, 1.8vw, 28px);
  border-top: 1px solid var(--line-strong);
  flex-direction: column; align-items: stretch; gap: 4px;
}

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-mark {
  width: 28px; height: 28px;
  background: var(--ink); color: var(--paper);
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 800; font-size: 12px; letter-spacing: 0.04em;
}
.brand-name {
  color: var(--ink); font-family: var(--font-display); font-weight: 700;
  font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase;
}
.bar-nav { display: none; }
.bar-status {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.12em;
  color: var(--muted); text-transform: uppercase;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--seed-red); }

.bar-bottom-skus {
  display: flex; gap: 14px; flex-wrap: wrap;
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.12em;
  color: var(--muted); text-transform: uppercase;
}
.bar-bottom-skus span::before { content: "▸ "; color: var(--seed-red); }
.bar-bottom-form { display: flex; align-items: center; gap: 8px; width: 100%; }
#leadEmail {
  flex: 1 1 auto; min-width: 0;
  background: var(--paper); color: var(--ink);
  border: 1px solid var(--line-strong);
  padding: 9px 12px; font: 14px var(--font-mono); letter-spacing: 0.02em;
  outline: none;
}
#leadEmail:focus { border-color: var(--seed-red); border-width: 2px; padding: 8px 11px; }
#leadEmail::placeholder { color: var(--faint); }
.lead-submit {
  background: var(--ink); color: var(--paper);
  border: 1px solid var(--ink);
  padding: 9px 18px; cursor: pointer;
  font: 700 12px var(--font-display); letter-spacing: 0.1em; text-transform: uppercase;
  transition: background 0.15s;
}
.lead-submit:hover { background: var(--seed-red); border-color: var(--seed-red); }
.lead-qr {
  background: transparent; color: var(--ink);
  border: 1px solid var(--line-strong);
  width: 38px; height: 38px;
  display: grid; place-items: center;
  cursor: pointer; padding: 0;
}
.lead-qr svg { width: 18px; height: 18px; fill: currentColor; }
.lead-qr:hover { border-color: var(--seed-red); color: var(--seed-red); }
.bar-bottom-msg { font-family: var(--font-mono); font-size: 11px; color: var(--muted); min-height: 14px; }

.app-loading { padding: 60px 32px; color: var(--muted); font-family: var(--font-mono); letter-spacing: 0.08em; }

/* ===== Main app frame — single-screen, no scroll ===== */
#appMain {
  display: grid;
  grid-template-rows: auto 1fr;
  height: calc(100vh - 52px - 96px);
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 var(--pad-x) clamp(8px, 1vh, 16px);
  position: relative;
  gap: clamp(10px, 1.4vh, 18px);
}

/* ===== Masthead ===== */
.v8-masthead {
  padding: clamp(14px, 1.8vh, 22px) 0 clamp(10px, 1.4vh, 16px);
  border-bottom: 1px solid var(--line-strong);
  display: flex; flex-direction: column; gap: 8px;
}
.v8m-row {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 12px; flex-wrap: wrap;
}
.v8m-eyebrow, .v8m-folio {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--muted);
}
.v8m-folio { color: var(--seed-red); font-weight: 700; }
.v8m-title {
  font-family: var(--font-display); font-weight: 800;
  font-size: clamp(28px, 3.2vw, 50px);
  line-height: 1; letter-spacing: -0.025em;
  color: var(--ink); margin: 0;
  text-wrap: balance;
}
.v8m-title em {
  font-style: italic; font-weight: 400;
  color: var(--seed-red);
  font-family: "Iowan Old Style Text", Charter, Georgia, serif;
}
.v8m-deck {
  font-family: var(--font-text); font-size: clamp(13px, 1.05vw, 16px);
  line-height: 1.45; color: var(--muted);
  margin: 0; max-width: 80ch;
}

/* ===== Treemap — 4 horizontal bands ===== */
.v8-treemap {
  display: flex; flex-direction: column;
  min-height: 0; flex: 1;
  gap: 4px;     /* white gaps between bands */
}
.vm-band {
  display: flex; flex-direction: column;
  min-height: 0;
  /* flex: <total volume in band>  set inline */
}
.vm-band-label {
  display: flex; align-items: baseline; gap: 14px;
  padding: 4px 8px;
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--muted);
  flex: 0 0 auto;
}
.vm-band-key {
  font-family: var(--font-display); font-weight: 800; font-size: 12.5px;
  letter-spacing: 0.18em;
  color: var(--ink);
  padding: 2px 8px;
  border: 1px solid var(--ink);
}
.vm-band.band-seed .vm-band-key { background: var(--seed-red); color: var(--cell-text); border-color: var(--seed-red); }
.vm-band.band-lead .vm-band-key { background: var(--lead-amber); color: var(--cell-text); border-color: var(--lead-amber); }
.vm-band.band-grss .vm-band-key { background: var(--grss-blue); color: var(--cell-text); border-color: var(--grss-blue); }
.vm-band.band-slnt .vm-band-key { background: var(--slnt-gray); color: var(--cell-text); border-color: var(--slnt-gray); }
.vm-band-name { color: var(--muted); font-weight: 600; }
.vm-band-share { color: var(--faint); margin-left: auto; font-size: 11px; letter-spacing: 0.12em; }
.vm-band-share b { color: var(--ink); font-weight: 700; }

.vm-band-cells {
  display: flex;
  flex: 1; min-height: 0;
  gap: 2px;     /* white gaps between cells */
  padding: 0;
}

/* ===== Cell ===== */
.vm-cell {
  /* flex: <vol> set inline */
  position: relative;
  overflow: hidden;
  display: flex;
  background: var(--slnt-gray);
  color: var(--cell-text);
  cursor: pointer;
  transition: filter 0.15s, transform 0.12s, opacity 0.2s;
  container-type: inline-size;
  container-name: vmcell;
  min-width: 24px;
}
.vm-cell.role-seed { background: var(--seed-red); }
.vm-cell.role-lead { background: var(--lead-amber); }
.vm-cell.role-grss { background: var(--grss-blue); }
.vm-cell.role-slnt { background: var(--slnt-gray); }

.vm-cell:hover {
  filter: brightness(1.12);
  z-index: 5;
}
.vm-cell.is-faded {
  filter: grayscale(0.7) brightness(0.85);
  opacity: 0.5;
  pointer-events: none;
}
.vm-cell.is-active {
  outline: 3px solid var(--ink);
  outline-offset: -3px;
  z-index: 6;
}

.vm-cell-inner {
  padding: 12px 14px;
  display: flex; flex-direction: column;
  justify-content: space-between;
  height: 100%; width: 100%;
  min-height: 0;
}
.vm-num {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.16em;
  color: var(--cell-text-dim);
  font-weight: 700;
}
.vm-name {
  font-family: var(--font-display); font-weight: 800;
  font-size: clamp(14px, 1.4vw, 22px);
  line-height: 1.05; letter-spacing: -0.012em;
  color: var(--cell-text);
  margin-top: 4px;
  /* clamp to 3 lines */
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.vm-vol {
  font-family: var(--font-display); font-weight: 800;
  font-size: clamp(14px, 1.4vw, 22px);
  letter-spacing: -0.01em;
  color: var(--cell-text);
  margin-top: auto;
  font-variant-numeric: tabular-nums;
}

/* Cell-size adaptive content (container queries) */
@container vmcell (max-width: 100px) {
  .vm-name { display: none; }
  .vm-cell-inner { padding: 8px 6px; }
}
@container vmcell (max-width: 60px) {
  .vm-vol { display: none; }
  .vm-num { font-size: 9.5px; }
}
@container vmcell (max-width: 220px) {
  .vm-name { font-size: 13px; -webkit-line-clamp: 2; }
}
@container vmcell (min-width: 380px) {
  .vm-name { font-size: 26px; -webkit-line-clamp: 4; }
  .vm-vol  { font-size: 26px; }
}
@container vmcell (min-width: 600px) {
  .vm-name { font-size: 36px; }
  .vm-vol  { font-size: 36px; }
}

/* ===== Bottom slide-up detail panel ===== */
.v8-detail {
  position: fixed;
  left: 0; right: 0; bottom: 96px;
  top: 30vh;        /* leave the top 30% of viewport visible behind */
  z-index: 100;
  background: var(--paper);
  color: var(--ink);
  border-top: 4px solid var(--seed-red);
  box-shadow: 0 -28px 64px rgba(28, 25, 22, 0.25);
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.34s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.v8-detail.is-open { transform: translateY(0); }
.v8-detail[hidden] { display: block; }

.vd-loading {
  padding: 48px 32px; color: var(--muted);
  font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.12em;
  text-transform: uppercase;
}
.vd-error { color: var(--seed-red); }

.vd-close {
  position: sticky; top: 0; left: 0;
  z-index: 5;
  display: block; width: 100%;
  background: var(--ink); color: var(--paper);
  border: 0;
  padding: 12px 18px;
  font: 700 11px var(--font-mono); letter-spacing: 0.18em; text-transform: uppercase;
  cursor: pointer; text-align: left;
  transition: background 0.15s;
}
.vd-close:hover { background: var(--seed-red); }

/* Cluster detail content rendered inside the panel */
.v8-detail .cluster-detail { background: transparent; padding: 0; border: 0; color: var(--ink); }
.v8-detail .cluster-back-wrap { display: none; }

.v8-detail .cluster-banner {
  padding: clamp(20px, 3vh, 32px) clamp(20px, 3vw, 40px);
  border-bottom: 1px solid var(--line);
}
.v8-detail .cluster-banner-top {
  display: flex; justify-content: space-between; align-items: baseline;
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--muted);
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px; margin-bottom: 16px;
}
.v8-detail .cluster-banner-top .vol { color: var(--seed-red); font-weight: 700; }
.v8-detail .cluster-banner-top .role-tag { color: var(--lead-amber); font-weight: 700; }
.v8-detail .cluster-name {
  font-family: var(--font-display); font-weight: 800;
  font-size: clamp(28px, 3vw, 48px); line-height: 1;
  letter-spacing: -0.025em; color: var(--ink);
  margin: 0 0 12px; max-width: 22ch;
}
.v8-detail .cluster-punch {
  font-family: var(--font-text); font-weight: 500;
  font-size: clamp(15px, 1.2vw, 20px); line-height: 1.45;
  color: var(--ink);
  border-left: 4px solid var(--seed-red);
  padding-left: 16px;
  margin: 0 0 18px;
  max-width: 60ch;
}
.v8-detail .cluster-stats {
  display: grid; grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--line);
  padding-top: 16px; gap: 16px;
}
.v8-detail .cstat .v {
  display: block;
  font-family: var(--font-display); font-weight: 800;
  font-size: clamp(22px, 2.2vw, 36px); line-height: 1;
  color: var(--ink); letter-spacing: -0.02em;
}
.v8-detail .cstat .l {
  display: block; margin-top: 6px;
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.12em;
  color: var(--muted); text-transform: uppercase;
}
.v8-detail .cluster-triad, .v8-detail .stories-section {
  padding: clamp(18px, 2.4vh, 28px) clamp(20px, 3vw, 40px);
  border-bottom: 1px solid var(--line);
}
.v8-detail .triad-eyebrow {
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--lead-amber);
}

/* ===== Story drawer (L3) ===== */
.drawer { position: fixed; inset: 0; z-index: 300; display: none; }
.drawer[aria-hidden="false"] { display: block; }
.drawer-backdrop {
  position: absolute; inset: 0;
  background: rgba(28, 25, 22, 0.6);
  backdrop-filter: blur(2px);
  border: 0; cursor: pointer;
}
.drawer-panel {
  position: absolute; right: 0; top: 0; bottom: 0;
  width: min(720px, 92vw);
  background: var(--paper); color: var(--ink);
  overflow-y: auto;
  border-left: 1px solid var(--line-strong);
  box-shadow: -16px 0 48px rgba(0, 0, 0, 0.18);
}

/* ===== QR popover ===== */
.qr-popover { position: fixed; inset: 0; z-index: 400; display: grid; place-items: center;
  background: rgba(28, 25, 22, 0.6); backdrop-filter: blur(2px); }
.qr-popover[hidden] { display: none; }
.qr-popover-card {
  background: var(--paper); color: var(--ink);
  border: 1px solid var(--line-strong);
  padding: 24px; max-width: 360px; text-align: center;
  font-family: var(--font-text);
}
.qr-popover-card strong { display: block; margin-bottom: 12px; font-family: var(--font-display); font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; }
.qr-canvas { width: 200px; height: 200px; margin: 0 auto 12px; background: white; }
.qr-close {
  margin-top: 14px; background: var(--ink); color: var(--paper);
  border: 0; padding: 8px 16px; cursor: pointer;
  font: 700 11px var(--font-mono); letter-spacing: 0.16em; text-transform: uppercase;
}
.qr-close:hover { background: var(--seed-red); }

/* ===== Responsive ===== */
@media (max-width: 980px) {
  body { overflow-y: auto; padding-bottom: 96px; }
  #appMain { height: auto; min-height: calc(100vh - 52px - 96px); }
  .v8-treemap { gap: 8px; }
  .vm-band-cells { gap: 1px; }
}

/* end v8 */
