/* ══════════════════════════════════════════════════════════════
   Anima Apnea — Article template (editorial layout)
   Loaded after style.css. Reuses its theme tokens (dark + sepia).
   ══════════════════════════════════════════════════════════════ */

:root {
  /* Anima app palette (lib/theme/app_colors.dart) and its meanings */
  --co2: #6F9CAF;      /* AppColors.cyan: CO2 table, primary accent */
  --o2: #6FAFAC;       /* AppColors.aqua: O2 table */
  --teal: #70AAAF;     /* AppColors.teal */
  --breath: #70AF84;   /* AppColors.green: recovery, breathing */
  --apnea: #FFCF56;    /* AppColors.yellow: apnea, records, contractions */
  --warn: #FFCF56;
  --danger: #FF5252;   /* AppColors.red */
  --rest: rgba(112,175,132,0.42);
  --grid: rgba(255,255,255,0.08);
  --surface-hi: #112035;
  --serif: var(--sys);
  --mono: var(--sys);
}

html.sepia {
  --co2: #5B8799;      /* AppColors.cyanDim: keeps contrast on paper */
  --o2: #5E9C99;
  --teal: #5F9A9F;
  --breath: #5E9C72;
  --apnea: #BF8705;    /* app yellow in light/sepia */
  --warn: #BF8705;
  --danger: #D84040;
  --rest: rgba(112,175,132,0.45);
  --grid: rgba(58,56,40,0.10);
  --surface-hi: #EBEAE3;
}

html { scroll-behavior: smooth; scroll-padding-top: 5.5rem; }

/* ── Reading progress ── */
.read-progress {
  position: fixed; top: 0; left: 0; height: 2px; width: 0;
  background: linear-gradient(90deg, var(--co2), var(--o2));
  z-index: 101; transition: width 0.1s linear;
}

/* ── Layout ── */
main.article-main {
  max-width: 1160px;
  padding: 7.5rem 2rem 4rem;
}

.article-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px;
  gap: 4rem;
  align-items: start;
}

.article-body { max-width: 700px; min-width: 0; }

/* ── Hero ── */
.article-hero { margin-bottom: 2.5rem; max-width: 820px; }

.breadcrumb {
  display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap;
  font-size: 0.8rem; color: var(--text-muted); margin-bottom: 1.4rem;
}
.breadcrumb a { color: var(--text-muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent); }

.kicker {
  display: block; font-size: 0.95rem; font-weight: 500;
  color: var(--co2); margin-bottom: 1rem;
}

.article-hero h1 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(2rem, 4.6vw, 3.1rem);
  letter-spacing: -0.03em;
  line-height: 1.08;
  margin-bottom: 1.2rem;
}
.article-hero h1 em { font-style: normal; }

.dek {
  font-size: clamp(1.05rem, 2vw, 1.25rem);
  line-height: 1.6;
  color: var(--text-secondary);
  margin-bottom: 1.8rem;
  max-width: 680px;
}

.byline {
  display: flex; align-items: center; gap: 0.9rem; flex-wrap: wrap;
  padding-top: 1.4rem; border-top: 1px solid var(--border-mid);
  font-size: 0.85rem; color: var(--text-muted);
}
.byline .avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, var(--co2), var(--o2));
  color: var(--bg); font-weight: 700; font-size: 0.85rem;
  display: grid; place-items: center; flex-shrink: 0;
}
.byline strong { color: var(--text-primary); font-weight: 600; display: block; font-size: 0.9rem; }
.byline .dot { opacity: 0.5; }

/* ── Body typography ── */
.article-body > p,
.article-body li { font-size: 1.065rem; line-height: 1.78; }
.article-body strong { color: var(--text-primary); font-weight: 600; }
.article-body a { color: var(--co2); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.article-body a:hover { text-decoration-thickness: 2px; }

.article-body h2 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(1.45rem, 2.8vw, 1.8rem);
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin: 3.5rem 0 1.1rem;
}
.article-body h2 .num {
  display: block; font-family: var(--mono); font-size: 0.75rem;
  letter-spacing: 0.1em; color: var(--accent); margin-bottom: 0.5rem;
}
.article-body h3 { font-size: 1.12rem; margin-top: 2.2rem; color: var(--text-primary); }

/* ── Key takeaways ── */
.takeaways {
  background: var(--surface);
  border: 1px solid var(--border-mid);
  border-radius: 18px;
  padding: 1.6rem 1.8rem;
  margin: 0 0 2.8rem;
}
.takeaways h2 {
  font-family: inherit !important; font-size: 1rem !important; font-weight: 600 !important;
  color: var(--text-primary);
  margin: 0 0 1rem !important;
}
.takeaways ul { list-style: none; padding: 0; margin: 0; }
.takeaways li {
  position: relative; padding-left: 1.7rem; margin-bottom: 0.7rem;
  font-size: 0.98rem !important; line-height: 1.6 !important;
}
.takeaways li::before {
  content: ''; position: absolute; left: 0; top: 0.55em;
  width: 0.7rem; height: 0.7rem; border-radius: 50%;
  border: 2px solid var(--accent);
}

/* ── Stats row ── */
.stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.8rem; margin: 2rem 0;
}
.stat {
  background: var(--surface); border: 1px solid var(--border-mid);
  border-radius: 14px; padding: 1.1rem 1.2rem;
}
.stat .v {
  font-weight: 100; font-size: 2.2rem; line-height: 1; color: var(--text-primary);
  margin-bottom: 0.4rem; font-variant-numeric: tabular-nums;
}
.stat .l { font-size: 0.8rem; color: var(--text-muted); line-height: 1.4; }

/* ── Figures / charts ── */
figure.fig {
  margin: 2.4rem 0;
  background: var(--surface);
  border: 1px solid var(--border-mid);
  border-radius: 18px;
  padding: 1.4rem 1.4rem 1.1rem;
}
figure.fig.bleed { margin-left: -2.5rem; margin-right: -2.5rem; }
.fig-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.9rem; }
.fig-title { font-weight: 600; font-size: 0.95rem; color: var(--text-primary); }
.fig-legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: 0.78rem; color: var(--text-muted); }
.fig-legend span { display: inline-flex; align-items: center; gap: 0.4rem; }
.fig-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.fig-legend i.line { height: 3px; width: 14px; border-radius: 2px; }
figure.fig svg { width: 100%; height: auto; display: block; overflow: visible; }
figure.fig figcaption {
  margin-top: 0.9rem; padding-top: 0.8rem; border-top: 1px solid var(--border);
  font-size: 0.82rem; line-height: 1.55; color: var(--text-muted);
}
figure.fig figcaption b { color: var(--text-secondary); font-weight: 600; }

/* SVG paint classes (theme-aware) */
.c-grid { stroke: var(--grid); stroke-width: 1; }
.c-axis { stroke: var(--border-mid); stroke-width: 1; }
.c-tick { fill: var(--text-muted); font-size: 11px; font-family: var(--sys); font-variant-numeric: tabular-nums; }
.c-lab { fill: var(--text-secondary); font-size: 12px; font-family: var(--sys); font-weight: 500; }
.c-lab-strong { fill: var(--text-primary); font-size: 13px; font-family: var(--sys); font-weight: 600; }
.c-rest { fill: var(--rest); }
.c-hold { fill: var(--co2); }
.c-hold-o2 { fill: var(--o2); }
.c-co2-line { stroke: var(--co2); stroke-width: 2.5; fill: none; }
.c-o2-line { stroke: var(--o2); stroke-width: 2.5; fill: none; }
.c-co2-area { fill: var(--co2); opacity: 0.1; }
.c-warn { stroke: var(--warn); stroke-width: 1.5; stroke-dasharray: 4 4; fill: none; }
.c-warn-t { fill: var(--warn); font-size: 11px; font-family: var(--sys); font-weight: 600; }
.c-zone { fill: var(--warn); opacity: 0.08; }
.c-node { fill: var(--surface-hi); stroke: var(--border-mid); stroke-width: 1; }
.c-node-accent { fill: var(--surface-hi); stroke: var(--co2); stroke-width: 1.5; }
.c-arrow { stroke: var(--text-muted); stroke-width: 1.5; fill: none; }
.c-arrow-head { fill: var(--text-muted); }
.c-dot { fill: var(--apnea); }
.c-in-bar { fill: var(--co2); opacity: 0.85; }

/* ── Callouts ── */
.callout {
  display: grid; grid-template-columns: auto 1fr; gap: 1rem;
  border-radius: 14px; padding: 1.2rem 1.3rem; margin: 2rem 0;
  border: 1px solid; font-size: 0.97rem;
}
.callout p { margin: 0 0 0.5rem; font-size: 0.97rem !important; line-height: 1.65 !important; }
.callout p:last-child { margin-bottom: 0; }
.callout .ic {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  font-weight: 700; font-size: 0.95rem;
}
.callout .ct { font-weight: 600; color: var(--text-primary); margin-bottom: 0.3rem; display: block; }
.callout.tip { background: color-mix(in srgb, var(--co2) 6%, transparent); border-color: color-mix(in srgb, var(--co2) 22%, transparent); }
.callout.tip .ic { background: color-mix(in srgb, var(--co2) 18%, transparent); color: var(--co2); }
.callout.warning { background: color-mix(in srgb, var(--warn) 7%, transparent); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.callout.warning .ic { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.callout.science { background: color-mix(in srgb, var(--o2) 6%, transparent); border-color: color-mix(in srgb, var(--o2) 22%, transparent); }
.callout.science .ic { background: color-mix(in srgb, var(--o2) 18%, transparent); color: var(--o2); }

/* ── Pull quote ── */
blockquote.pull {
  font-weight: 600; font-size: 1.3rem; line-height: 1.45; letter-spacing: -0.01em;
  color: var(--text-primary); border-left: 2px solid var(--accent);
  padding: 0.2rem 0 0.2rem 1.5rem; margin: 2.5rem 0;
}

/* ── Steps ── */
ol.steps { list-style: none; padding: 0; counter-reset: s; margin: 1.6rem 0; }
ol.steps > li {
  counter-increment: s; position: relative; padding: 0 0 1.4rem 3.2rem; margin: 0;
}
ol.steps > li::before {
  content: counter(s); position: absolute; left: 0; top: 0;
  width: 2.1rem; height: 2.1rem; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 1rem; font-weight: 300; font-variant-numeric: tabular-nums;
  color: var(--co2); border: 1px solid color-mix(in srgb, var(--co2) 40%, transparent);
  background: var(--bg);
}
ol.steps > li::after {
  content: ''; position: absolute; left: 1.05rem; top: 2.3rem; bottom: 0.2rem;
  width: 1px; background: var(--border-mid);
}
ol.steps > li:last-child::after { display: none; }
ol.steps > li strong { display: block; margin-bottom: 0.15rem; }

/* ── Data tables ── */
.data-table { margin: 1.8rem 0; overflow-x: auto; border: 1px solid var(--border-mid); border-radius: 14px; }
.data-table table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.data-table caption {
  text-align: left; padding: 0.9rem 1.1rem; font-size: 0.85rem; font-weight: 600;
  color: var(--text-primary); background: var(--surface); border-bottom: 1px solid var(--border-mid);
}
.data-table th {
  text-align: left; font-size: 0.8rem; font-weight: 600;
  color: var(--text-muted); padding: 0.7rem 1.1rem; border-bottom: 1px solid var(--border-mid);
}
.data-table td { padding: 0.65rem 1.1rem; font-size: 0.92rem; color: var(--text-secondary); border-bottom: 1px solid var(--border); }
.data-table tr:last-child td { border-bottom: none; }
.data-table td.hl { color: var(--co2); font-weight: 600; }
.data-table tfoot td { color: var(--text-primary); font-weight: 600; background: var(--surface); }

/* ── Calculator ── */
.calc {
  margin: 2.4rem 0; border-radius: 20px; padding: 1.6rem;
  background:
    radial-gradient(120% 140% at 100% 0%, color-mix(in srgb, var(--co2) 12%, transparent), transparent 60%),
    var(--surface);
  border: 1px solid color-mix(in srgb, var(--co2) 26%, transparent);
}
.calc-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.calc-head .t { font-weight: 600; color: var(--text-primary); font-size: 1.05rem; }
.calc-head .s { font-size: 0.82rem; color: var(--text-muted); margin-top: 0.2rem; }
.calc-input { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; }
.calc-input label { font-size: 0.82rem; color: var(--text-secondary); }
.calc-pr {
  font-size: 2.2rem; font-weight: 100; color: var(--text-primary); font-variant-numeric: tabular-nums;
  min-width: 4.2ch; text-align: center;
}
.calc input[type=range] { width: 100%; accent-color: var(--co2); margin: 0.6rem 0 1.2rem; }
.calc-out { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem; margin-bottom: 1.2rem; }
.calc-out div { background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 0.8rem 0.9rem; }
.calc-out b { display: block; font-size: 1.1rem; color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; }
.calc-out span { font-size: 0.75rem; color: var(--text-muted); }
.calc-note { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.8rem; line-height: 1.5; }

/* ── FAQ ── */
.faq { margin: 1.5rem 0; border-top: 1px solid var(--border-mid); }
.faq details { border-bottom: 1px solid var(--border-mid); }
.faq summary {
  cursor: pointer; list-style: none; padding: 1.15rem 2rem 1.15rem 0; position: relative;
  font-weight: 600; color: var(--text-primary); font-size: 1rem; line-height: 1.5;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after {
  content: '+'; position: absolute; right: 0.2rem; top: 1rem;
  font-size: 1.3rem; font-weight: 300; color: var(--accent); transition: transform 0.2s;
}
.faq details[open] summary::after { transform: rotate(45deg); }
.faq details p { font-size: 0.98rem !important; padding-bottom: 1.1rem; margin: 0; }

/* ── References ── */
.refs { margin-top: 3.5rem; padding-top: 1.5rem; border-top: 1px solid var(--border-mid); }
.refs h2 { font-family: inherit !important; font-size: 1rem !important; font-weight: 600; color: var(--text-primary) !important; margin: 0 0 1rem !important; }
.refs ol { padding-left: 1.3rem; }
.refs li { font-size: 0.84rem !important; line-height: 1.6 !important; color: var(--text-muted); margin-bottom: 0.5rem; }
.refs li i { color: var(--text-secondary); }
sup.ref a { font-size: 0.7rem; font-weight: 600; text-decoration: none !important; padding: 0 0.1rem; }

/* ── Author box ── */
.author-box {
  display: grid; grid-template-columns: auto 1fr; gap: 1.1rem; align-items: start;
  margin-top: 3rem; padding: 1.4rem; border-radius: 16px; background: var(--surface); border: 1px solid var(--border-mid);
}
.author-box .avatar {
  width: 52px; height: 52px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: var(--bg); font-weight: 700; display: grid; place-items: center;
}
.author-box strong { color: var(--text-primary); display: block; margin-bottom: 0.25rem; }
.author-box p { font-size: 0.9rem !important; margin: 0; line-height: 1.6 !important; }

/* ── CTA ── */
.cta-app {
  margin-top: 3rem; border-radius: 22px; padding: 2rem;
  display: grid; grid-template-columns: 1fr auto; gap: 1.5rem; align-items: center;
  background:
    radial-gradient(100% 160% at 0% 0%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 55%),
    var(--surface);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
}
.cta-app .t { font-weight: 700; letter-spacing: -0.02em; font-size: 1.35rem; color: var(--text-primary); line-height: 1.25; margin-bottom: 0.5rem; }
.cta-app p { font-size: 0.95rem !important; margin: 0; }
.cta-app .cta-button { white-space: nowrap; text-decoration: none !important; color: #040B15 !important; }

/* ── Related ── */
.related { margin-top: 4rem; }
.related h2 { font-family: inherit !important; font-size: 1rem !important; font-weight: 600; color: var(--text-primary) !important; margin: 0 0 1rem !important; }
.related-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.9rem; }
.related-grid a {
  display: block; padding: 1.2rem; border-radius: 14px; text-decoration: none !important;
  background: var(--surface); border: 1px solid var(--border-mid); transition: border-color 0.2s, transform 0.2s;
}
.related-grid a:hover { border-color: color-mix(in srgb, var(--accent) 40%, transparent); transform: translateY(-2px); }
.related-grid .k { font-size: 0.8rem; color: var(--co2); font-weight: 500; }
.related-grid .h { display: block; margin-top: 0.4rem; color: var(--text-primary); font-weight: 600; line-height: 1.4; font-size: 0.98rem; }

/* ── TOC (sticky sidebar) ── */
.toc { position: sticky; top: 6rem; font-size: 0.84rem; }
.toc .tl { font-size: 0.85rem; color: var(--text-primary); font-weight: 600; margin-bottom: 0.9rem; }
.toc ol { list-style: none; padding: 0; margin: 0; border-left: 1px solid var(--border-mid); }
.toc li { margin: 0; }
.toc a {
  display: block; padding: 0.42rem 0 0.42rem 1rem; margin-left: -1px;
  color: var(--text-muted); text-decoration: none; line-height: 1.4;
  border-left: 1px solid transparent; transition: color 0.15s, border-color 0.15s;
}
.toc a:hover { color: var(--text-primary); }
.toc a.active { color: var(--accent); border-left-color: var(--accent); }
.toc .toc-cta {
  display: block; margin-top: 1.5rem; padding: 1rem; border-radius: 12px; text-decoration: none;
  background: var(--surface); border: 1px solid var(--border-mid); color: var(--text-secondary); line-height: 1.45;
}
.toc .toc-cta b { color: var(--accent); display: block; margin-top: 0.4rem; font-weight: 600; }

/* ── Responsive ── */
@media (max-width: 1000px) {
  .article-layout { grid-template-columns: 1fr; }
  .toc { display: none; }
  .article-body { margin: 0 auto; }
  .article-hero { margin-left: auto; margin-right: auto; max-width: 700px; }
  figure.fig.bleed { margin-left: 0; margin-right: 0; }
}

@media (max-width: 600px) {
  main.article-main { padding: 6rem 1rem 3rem; }
  .stats, .calc-out { grid-template-columns: 1fr 1fr; }
  .stats .stat:last-child { grid-column: span 2; }
  .calc-out div:last-child { grid-column: span 2; }
  .related-grid { grid-template-columns: 1fr; }
  .cta-app { grid-template-columns: 1fr; text-align: left; }
  figure.fig { padding: 1rem 0.9rem 0.9rem; border-radius: 14px; }
  .takeaways { padding: 1.3rem; }
  nav.blog-nav { padding: 0.9rem 1rem; }
}

/* ── Brand nav (shared with the landing) ── */
nav.blog-nav { padding: 0 2rem; height: 64px; }
nav.blog-nav .nav-left { display: flex; align-items: center; gap: 1.4rem; }
nav.blog-nav a.blog-brand { display: flex; align-items: center; gap: 0.6rem; color: var(--text-primary); font-weight: 600; font-size: 0.98rem; }
nav.blog-nav a.blog-brand img { width: 28px; height: 28px; border-radius: 8px; }
nav.blog-nav a.blog-home { color: var(--text-secondary); font-weight: 400; font-size: 0.9rem; }
nav.blog-nav a.blog-home:hover { color: var(--text-primary); opacity: 1; }
.blog-theme-btn { display: inline-flex; align-items: center; justify-content: center; color: var(--text-primary); }
.blog-theme-btn svg { width: 16px; height: 16px; }
:focus-visible { outline: 2px solid var(--co2); outline-offset: 3px; border-radius: 6px; }
@media (max-width: 600px) { nav.blog-nav { padding: 0 1rem; } nav.blog-nav a.blog-home { display: none; } }

/* App-semantic paint helpers */
.c-apnea { fill: var(--apnea); }
.c-breath { fill: var(--breath); }
.c-danger { fill: var(--danger); }
.c-apnea-line { stroke: var(--apnea); stroke-width: 2; fill: none; }
.c-danger-line { stroke: var(--danger); stroke-width: 1.5; stroke-dasharray: 4 4; fill: none; }

@media (max-width: 600px) { .byline .dot { display: none; } }
