/* The Five Y's — built to be easy to read.
 * Body text in DM Sans at a generous size and line height; Newsreader only for titles and
 * headings. No cards, no pictures, no extras: type, hairline rules and whitespace, plus the
 * Y-tree (art.js). Colours are tokens on :root; dark values apply via the OS preference
 * unless the reader picked a theme (data-theme on <html>, set early by theme.js). */

:root {
  color-scheme: light;
  --paper: #f7f4ee;
  --paper-raised: #fffdf9;
  --paper-sunk: #efeae1;
  --ink: #1d211e;
  --ink-soft: #3f4741;
  --muted: #646a64;
  --rule: #e2dcd1;
  --rule-strong: #cfc8bb;
  --accent: #2e5b47;
  --accent-ink: #fbf9f4;
  --accent-soft: #e3ebe4;
  --warm: #a95f2a;
  --focus: #b8672e;
  --art-bg: #ebe3d3;
  --art-2: #d0913f;
  --art-3: #b8563d;
  --art-4: #6f93b5;
  --font-display: "Newsreader", Georgia, "Times New Roman", serif;
  --font-ui: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --topbar-h: 64px;
  --radius: 10px;
  --shadow: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #161a17;
    --paper-raised: #1d221e;
    --paper-sunk: #232924;
    --ink: #ece8df;
    --ink-soft: #cfccc2;
    --muted: #a0a49a;
    --rule: #2d342e;
    --rule-strong: #3b443d;
    --accent: #93c2a6;
    --accent-ink: #12211a;
    --accent-soft: #1f2e26;
    --warm: #e0a36b;
    --focus: #e0a36b;
    --art-bg: #222a24;
    --art-2: #e3a55e;
    --art-3: #d97b62;
    --art-4: #86a9cb;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #161a17;
  --paper-raised: #1d221e;
  --paper-sunk: #232924;
  --ink: #ece8df;
  --ink-soft: #cfccc2;
  --muted: #a0a49a;
  --rule: #2d342e;
  --rule-strong: #3b443d;
  --accent: #93c2a6;
  --accent-ink: #12211a;
  --accent-soft: #1f2e26;
  --warm: #e0a36b;
  --focus: #e0a36b;
  --art-bg: #222a24;
  --art-2: #e3a55e;
  --art-3: #d97b62;
  --art-4: #86a9cb;
}

/* ---- Base ---- */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-padding-top: calc(var(--topbar-h) + 16px); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: clip;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
button, select, input, textarea { color: inherit; font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: 4px; }
[tabindex="-1"]:focus { outline: none; }
::selection { background: var(--accent-soft); color: var(--ink); }
a { color: inherit; }
.skip-link { position: absolute; left: 16px; top: -60px; z-index: 50; padding: 10px 14px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-weight: 600; text-decoration: none; }
.skip-link:focus { top: 12px; }
.eyebrow { margin: 0; color: var(--accent); font: 700 12px/1.3 var(--font-ui); letter-spacing: .12em; text-transform: uppercase; }

/* ---- Buttons ---- */

.button {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 24px;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: 600 16px/1 var(--font-ui);
  text-decoration: none;
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, filter 160ms ease;
}
.button-primary { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.button-primary:hover { filter: brightness(1.08); }
.button-quiet:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* ---- Top bar ---- */

.topbar { position: sticky; top: 0; z-index: 20; background: var(--paper); border-bottom: 1px solid var(--rule); }
.topbar-inner { width: min(1180px, 100%); height: var(--topbar-h); margin: 0 auto; padding: 0 32px; display: flex; justify-content: space-between; align-items: center; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.logo-mark { width: 26px; height: 32px; flex: none; }
.brand-name { font: 600 22px/1 var(--font-display); letter-spacing: -.02em; white-space: nowrap; }
.brand-name em { color: var(--accent); font-style: italic; font-weight: 500; }
.icon-button { display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; color: var(--ink-soft); }
.icon-button:hover { background: var(--paper-sunk); color: var(--ink); }
.icon-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon-sun { display: none; }
:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: block; }
  :root:not([data-theme="light"]) .icon-moon { display: none; }
}

/* ---- Layout ---- */

.layout { flex: 1; width: min(1180px, 100%); margin: 0 auto; padding: 0 32px; display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 72px; align-items: start; }

/* ---- Side column: progress + the five questions ---- */

.rail { position: sticky; top: var(--topbar-h); max-height: calc(100vh - var(--topbar-h)); overflow-y: auto; padding: 40px 0 32px; scrollbar-width: thin; }
.rail-title { margin: 0; font: 500 30px/1.1 var(--font-display); letter-spacing: -.02em; }
.progress { margin-top: 18px; display: flex; align-items: center; gap: 14px; }
.progress-tree { display: block; width: 44px; height: 55px; overflow: visible; }
.progress-tree .tree-branches { stroke: var(--rule-strong); stroke-width: 5; }
.progress-tree .tree-fruit { transform-box: fill-box; transform-origin: center; transition: transform 360ms cubic-bezier(.3, 1.6, .5, 1); }
.progress-tree .tree-fruit circle { transition: fill 260ms ease, stroke 260ms ease; }
.progress-tree .tree-fruit:not(.is-read) circle { fill: var(--paper); stroke: var(--rule-strong); stroke-width: 4; }
.progress-tree .tree-fruit.is-active:not(.is-read) circle { stroke: var(--warm); }
.progress-tree .tree-fruit.is-read { transform: scale(1.12); }
.progress-text { margin: 0; display: grid; gap: 2px; color: var(--muted); font-size: 14px; }
.progress-text strong { color: var(--ink); font-weight: 600; }

.rail-toggle { display: none; }

.question-list { margin: 24px 0 0; padding: 0; list-style: none; border-top: 1px solid var(--rule); }
.question-list li { border-bottom: 1px solid var(--rule); }
.question { width: 100%; display: grid; grid-template-columns: 30px minmax(0, 1fr) 20px; gap: 12px; align-items: start; padding: 14px 0; border: 0; background: transparent; text-align: left; }
.question-number { color: var(--muted); font: italic 500 20px/1.2 var(--font-display); }
.question-copy { display: grid; gap: 4px; min-width: 0; }
.question-title { color: var(--ink); font: 500 16px/1.35 var(--font-ui); }
.question-meta { color: var(--muted); font-size: 13px; }
.question:hover .question-title { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.question.is-active .question-number, .question.is-active .question-title { color: var(--warm); }
.question.is-active .question-title { font-weight: 600; }
.question.is-read:not(.is-active) .question-title { color: var(--muted); }
.question.is-read .question-number { color: var(--accent); }
.question-check { width: 20px; height: 20px; margin-top: 1px; border: 1.5px solid var(--rule-strong); border-radius: 50%; }
.question.is-read .question-check { border-color: var(--accent); background: var(--accent) center / 12px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 12.5 4.5 4.5L19 7.5'/%3E%3C/svg%3E"); }

/* ---- The article ---- */

.reader { min-width: 0; padding: 44px 0 80px; outline: none; }
.reader > * { max-width: 680px; }
.notice { margin: 0 0 28px; padding: 12px 16px; border-left: 3px solid var(--warm); color: var(--ink-soft); font-size: 15px; }

.article-meta { margin: 0; color: var(--muted); font-size: 14px; font-weight: 500; }
.article-title { margin: 10px 0 14px; font: 500 clamp(34px, 4vw, 48px)/1.1 var(--font-display); letter-spacing: -.025em; text-wrap: balance; }
.article-deck { margin: 0; color: var(--ink-soft); font: 400 20px/1.5 var(--font-ui); text-wrap: pretty; }

.listen-button { margin-top: 24px; min-height: 44px; display: inline-flex; align-items: center; gap: 10px; padding: 0 20px 0 14px; border: 1px solid var(--rule-strong); border-radius: 999px; background: transparent; color: var(--ink); font-size: 15px; font-weight: 600; }
.listen-button:hover { border-color: var(--accent); color: var(--accent); }
.listen-button svg { width: 18px; height: 18px; fill: var(--accent); }
.listen-button .pause-icon { display: none; }
.listen-button.is-playing .play-icon { display: none; }
.listen-button.is-playing .pause-icon { display: block; }

.article-body { margin-top: 32px; padding-top: 8px; border-top: 1px solid var(--rule); color: var(--ink); font: 400 18px/1.75 var(--font-ui); }
.article-body section { margin-top: 28px; }
.article-body h3 { margin: 0 0 8px; color: var(--ink); font: 600 22px/1.3 var(--font-display); letter-spacing: -.01em; }
.article-body p { max-width: 66ch; margin: 0 0 1.1em; text-wrap: pretty; }
.article-body section:last-child:not(:first-child) { margin-top: 40px; padding-left: 20px; border-left: 3px solid var(--warm); }
.article-body section:last-child:not(:first-child) h3 { color: var(--warm); }
.article-body section:last-child:not(:first-child) p { font-size: 19px; font-weight: 500; }

.article-sources { margin-top: 40px; padding-top: 18px; border-top: 1px solid var(--rule); }
.article-sources h3 { margin: 0 0 10px; color: var(--muted); font: 600 14px/1.3 var(--font-ui); }
.source-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.source-list li { display: grid; gap: 1px; }
.source-list a { width: fit-content; color: var(--accent); font-size: 16px; font-weight: 500; text-underline-offset: 3px; }
.source-list a::after { content: " ↗"; }
.source-byline, .source-empty { color: var(--muted); font-size: 14px; }

.next-button { margin-top: 40px; }

.done { margin-top: 40px; padding-top: 32px; border-top: 1px solid var(--rule); text-align: center; }
.done-graphic .why-tree { width: min(150px, 45%); }
.done h2 { margin: 8px 0 4px; font: 500 30px/1.15 var(--font-display); }
.done p { margin: 0; color: var(--muted); font-size: 16px; }

/* ---- The Y-tree (empty state + finish) ---- */

.why-tree { display: block; margin: 0 auto; overflow: visible; }
.why-tree .tree-branch { stroke-dasharray: 1; stroke-dashoffset: 1; animation: grow 600ms cubic-bezier(.3, .7, .3, 1) forwards; }
.why-tree .tree-branch:nth-child(1) { animation-duration: 800ms; }
.why-tree .tree-branch:nth-child(2) { animation-delay: 300ms; }
.why-tree .tree-branch:nth-child(3) { animation-delay: 450ms; }
.why-tree .tree-branch:nth-child(4) { animation-delay: 600ms; }
.why-tree .tree-branch:nth-child(5), .why-tree .tree-branch:nth-child(6) { animation-delay: 750ms; }
@keyframes grow { to { stroke-dashoffset: 0; } }
.why-tree .tree-fruit { transform-box: fill-box; transform-origin: center; transform: scale(0); animation: pop 520ms cubic-bezier(.3, 1.6, .5, 1) forwards, bob 3.2s ease-in-out infinite; }
.why-tree .tree-fruit:nth-child(1) { animation-delay: 1150ms, 1700ms; }
.why-tree .tree-fruit:nth-child(2) { animation-delay: 1270ms, 2100ms; }
.why-tree .tree-fruit:nth-child(3) { animation-delay: 1390ms, 1900ms; }
.why-tree .tree-fruit:nth-child(4) { animation-delay: 1510ms, 2400ms; }
.why-tree .tree-fruit:nth-child(5) { animation-delay: 1630ms, 2200ms; }
@keyframes pop { to { transform: scale(1); } }
@keyframes bob { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-4px) scale(1); } }
.why-tree .tree-fruit.is-ripe { animation-name: pop; animation-iteration-count: 1; }

.state { min-height: calc(100vh - var(--topbar-h) - 120px); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; text-align: center; }
.state-graphic .why-tree { width: min(260px, 62vw); }
.state-caption { margin: 0; color: var(--muted); font: 600 13px/1.3 var(--font-ui); letter-spacing: .14em; text-transform: uppercase; }

body.is-empty .layout { grid-template-columns: minmax(0, 1fr); }
body.is-empty .rail { display: none; }
body.is-empty .reader > * { max-width: none; }

/* ---- Loading skeleton ---- */

.skeleton { display: grid; gap: 14px; }
.sk { display: block; height: 16px; border-radius: 6px; background: linear-gradient(90deg, var(--paper-sunk) 0%, var(--rule) 50%, var(--paper-sunk) 100%) 0 0 / 200% 100%; animation: shimmer 1.4s ease-in-out infinite; }
.sk-kicker { width: 200px; height: 14px; }
.sk-title { height: 42px; width: 90%; }
.sk-title.short { width: 60%; margin-bottom: 18px; }
.sk-line { width: 100%; }
.sk.short { width: 70%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---- Responsive ---- */

@media (min-width: 821px) and (max-height: 720px) {
  .rail { position: static; max-height: none; overflow: visible; }
}

@media (max-width: 1080px) {
  .layout { grid-template-columns: 260px minmax(0, 1fr); gap: 48px; }
}

@media (max-width: 820px) {
  :root { --topbar-h: 58px; }
  .topbar-inner { padding: 0 16px; }
  .brand-name { font-size: 20px; }
  .logo-mark { width: 24px; height: 30px; }
  .layout { display: block; padding: 0 20px; }
  .rail { position: static; max-height: none; overflow: visible; padding: 24px 0 0; }
  .rail-title { font-size: 26px; }
  .rail-toggle { width: 100%; min-height: 52px; margin-top: 16px; display: flex; justify-content: space-between; align-items: center; padding: 0; border: 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); background: transparent; color: var(--ink); font-size: 16px; font-weight: 600; }
  .rail-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; transition: transform 180ms ease; }
  .rail-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }
  .question-list { display: none; margin-top: 0; border-top: 0; }
  .question-list.is-open { display: block; }
  .reader { padding: 28px 0 56px; scroll-margin-top: var(--topbar-h); }
  .article-title { font-size: clamp(30px, 8.4vw, 40px); }
  .article-deck { font-size: 19px; }
  .article-body { font-size: 18px; line-height: 1.7; }
  .article-body h3 { font-size: 21px; }
  .article-body section:last-child:not(:first-child) { padding-left: 16px; }
  .next-button { width: 100%; }
}

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

/* ======================================================================
   Editor (admin)
   ====================================================================== */

.topbar-link { padding: 8px 10px; border-radius: 8px; color: var(--ink-soft); font-size: 14px; font-weight: 500; text-decoration: none; }
.topbar-link:hover { color: var(--accent); }
.admin-shell { flex: 1; width: min(100% - 32px, 1000px); margin: 0 auto; padding: 40px 0 120px; }
.admin-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.admin-header h1 { margin: 8px 0 0; font: 500 40px/1.05 var(--font-display); letter-spacing: -.03em; }
.admin-who { margin: 0; color: var(--muted); font-size: 13px; }
.admin-tabs { display: inline-flex; gap: 4px; padding: 4px; border: 1px solid var(--rule); border-radius: 999px; background: var(--paper-raised); }
.admin-tab { min-height: 36px; padding: 0 16px; border: 0; border-radius: 999px; background: transparent; color: var(--ink-soft); font-size: 14px; font-weight: 600; }
.admin-tab:hover { color: var(--ink); }
.admin-tab.is-selected { background: var(--accent); color: var(--accent-ink); }
.admin-panel { padding-top: 24px; }
.admin-toolbar { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; padding: 16px; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--paper-raised); }
.admin-toolbar label { display: grid; gap: 6px; min-width: 190px; color: var(--ink-soft); font-size: 13px; font-weight: 600; }
.status-pill { display: inline-flex; align-items: center; gap: 8px; min-height: 32px; padding: 0 12px; border-radius: 999px; background: var(--paper-sunk); color: var(--ink-soft); font-size: 13px; font-weight: 600; }
.status-pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-pill.is-published { background: var(--accent-soft); color: var(--accent); }
.status-pill.is-published::before { background: var(--accent); }
.status-pill.is-draft::before { background: var(--warm); }
.admin-message { min-height: 20px; margin: 0; color: var(--muted); font-size: 14px; }
.admin-message.has-error { color: #b3261e; }
:root[data-theme="dark"] .admin-message.has-error { color: #f2a197; }
.admin-page input, .admin-page textarea, .admin-page select { width: 100%; min-height: 42px; padding: 10px 12px; border: 1px solid var(--rule-strong); border-radius: 8px; background: var(--paper); color: var(--ink); font: 15px/1.5 var(--font-ui); }
.admin-page textarea { resize: vertical; }
.admin-page textarea.admin-body { font: 17px/1.65 var(--font-display); }
.admin-page input:focus, .admin-page textarea:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
.admin-page input:disabled, .admin-page textarea:disabled { opacity: .7; }
.admin-help { margin: 0 0 16px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.admin-help code { padding: 1px 5px; border-radius: 4px; background: var(--paper-sunk); font-size: 12px; }
.admin-article-fields { display: grid; gap: 16px; }
.admin-card { margin: 0; padding: 20px; min-width: 0; display: grid; grid-template-columns: 160px 1fr; gap: 14px; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--paper-raised); }
.admin-card legend { float: left; width: 100%; grid-column: 1 / -1; padding: 0; display: flex; justify-content: space-between; align-items: baseline; }
.admin-card-number { color: var(--warm); font: italic 500 26px/1 var(--font-display); }
.admin-card-stats { color: var(--muted); font-size: 12px; }
.admin-card label { display: grid; gap: 6px; color: var(--ink-soft); font-size: 13px; font-weight: 600; }
.admin-card .span-2 { grid-column: 1 / -1; }
.admin-actions { position: sticky; bottom: 0; z-index: 5; margin-top: 20px; padding: 14px 0; display: flex; justify-content: flex-end; align-items: center; gap: 10px; flex-wrap: wrap; background: linear-gradient(transparent, var(--paper) 30%); }
.admin-actions .admin-message { margin-right: auto; }
.admin-table-wrap { overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--paper-raised); }
.analytics-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.analytics-table th, .analytics-table td { padding: 12px 16px; border-bottom: 1px solid var(--rule); text-align: left; }
.analytics-table tr:last-child td { border-bottom: 0; }
.analytics-table th { color: var(--muted); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
.analytics-table td:not(:first-child), .analytics-table th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.admin-footnote { color: var(--muted); font-size: 13px; line-height: 1.5; }

@media (max-width: 640px) {
  .admin-header h1 { font-size: 32px; }
  .admin-card { grid-template-columns: 1fr; padding: 16px; }
  .admin-toolbar > * { width: 100%; }
  .admin-actions { justify-content: stretch; }
  .admin-actions .button { flex: 1; }
}
