/* ===================================================================
   article.css, read-more page (long-form essay)
   Layers: tokens-fallback, article, chart, chart-typ, chart-debt, mobile
   ===================================================================
   Tokens (var(--bg), var(--ink), --accent, etc.) come from shared.css.
   This file provides fallbacks so the page renders in isolation if
   shared.css is absent during local testing.
   ================================================================ */

@layer tokens-fallback, article, chart, chart-typ, chart-debt, mobile;

/* ---------- token fallbacks (only used if shared.css absent) ---------- */
@layer tokens-fallback {
  :root {
    --bg:          oklch(0.975 0.008 80);
    --bg-tint:     oklch(0.955 0.012 78);
    --paper:       oklch(0.99  0.005 80);
    --ink:         oklch(0.20 0.012 60);
    --ink-2:       oklch(0.36 0.012 60);
    --ink-3:       oklch(0.54 0.010 60);
    --ink-4:       oklch(0.72 0.008 60);
    --rule:        oklch(0.86 0.010 70);
    --accent:      oklch(0.62 0.20 35);
    --accent-deep: oklch(0.52 0.21 33);
    --accent-soft: oklch(0.88 0.06 40);

    --line-tx:   oklch(0.36 0.020 250);
    --line-dfw:  oklch(0.52 0.015 80);
    --line-dal:  var(--accent);
    --line-d2m:  oklch(0.42 0.18 35);

    --maxw: 1180px;
    --col-body: 76ch;

    --step--1: clamp(0.74rem, 0.70rem + 0.18vw, 0.84rem);
    --step-0:  clamp(0.98rem, 0.94rem + 0.18vw, 1.05rem);
    --step-1:  clamp(1.08rem, 1.00rem + 0.30vw, 1.20rem);
    --step-2:  clamp(1.30rem, 1.15rem + 0.65vw, 1.55rem);
    --step-3:  clamp(1.60rem, 1.35rem + 1.10vw, 2.10rem);
    --step-4:  clamp(2.00rem, 1.60rem + 1.80vw, 2.80rem);
    --step-5:  clamp(2.60rem, 2.00rem + 2.40vw, 3.80rem);
  }
}

/* ---------- article layout ---------- */
@layer article {
  .article {
    max-width: var(--maxw);
    margin: 0 auto;
    padding: clamp(28px, 4vw, 64px) clamp(20px, 4vw, 56px) clamp(56px, 8vw, 96px);
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    row-gap: clamp(30px, 4vw, 56px);
  }

  /* article head, title + dek + byline, aligned with body column */
  .article-head {
    border-bottom: 1px solid var(--rule);
    padding-bottom: clamp(20px, 3vw, 36px);
    max-width: var(--col-body);
    margin-inline: auto;
  }
  .article-eyebrow {
    font-family: "Inter Tight", system-ui, sans-serif;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-3);
    margin-bottom: 14px;
  }
  .article-eyebrow::before {
    content: "";
    display: inline-block;
    width: 0.5em;
    height: 0.5em;
    background: var(--accent);
    margin-right: 0.7em;
    transform: translateY(-2px);
  }
  .article-title {
    font-family: "Inter Tight", system-ui, sans-serif;
    font-size: var(--step-5);
    font-weight: 800;
    line-height: 1.0;
    letter-spacing: -0.035em;
    color: var(--ink);
    margin: 0 0 clamp(12px, 1.8vw, 22px);
  }
  .article-title .soft {
    font-weight: 400;
    font-style: italic;
    font-family: "Source Serif 4", Georgia, serif;
    letter-spacing: -0.015em;
    color: var(--ink-3);
  }
  .article-dek {
    font-family: "Source Serif 4", Georgia, serif;
    font-size: var(--step-1);
    line-height: 1.32;
    font-style: italic;
    color: var(--ink-2);
    max-width: 56ch;
    margin-bottom: clamp(16px, 2.4vw, 26px);
  }
  .article-byline {
    font-family: "Inter Tight", system-ui, sans-serif;
    font-size: 0.72rem;
    letter-spacing: 0.10em;
    text-transform: uppercase;
    color: var(--ink-3);
  }
  .article-byline strong {
    color: var(--ink-2);
    font-weight: 600;
  }

  /* body, centered inside the article container */
  .article-body {
    max-width: var(--col-body);
    margin-inline: auto;
    font-family: "Source Serif 4", Georgia, "Times New Roman", serif;
    font-size: var(--step-0);
    line-height: 1.62;
    color: var(--ink);
  }
  .article-body p {
    margin: 0 0 1.1em;
    text-align: justify;
    hyphens: auto;
    -webkit-hyphens: auto;
    hanging-punctuation: first last;
  }
  .article-body p + p {
    text-indent: 1.6em;
  }
  .article-body p.no-indent,
  .article-body h2 + p,
  .article-body section > p:first-of-type {
    text-indent: 0;
  }

  /* drop cap, only the first paragraph */
  .article-body .dropcap {
    text-indent: 0;
  }
  .article-body .drop {
    font-family: "Source Serif 4", Georgia, "Times New Roman", serif;
    font-weight: 600;
    font-size: 3.1em;
    line-height: 0.88;
    float: left;
    padding: 0.05em 0.12em 0 0.02em;
    margin: 0.05em 0.1em -0.05em 0;
    color: var(--accent);
    letter-spacing: -0.02em;
  }

  /* numbered punchline (1.3M) */
  .punchline {
    font-family: "Source Serif 4", serif;
    font-size: var(--step-2);
    line-height: 1.2;
    font-weight: 500;
    color: var(--ink);
    margin: 1.4em 0 1.2em !important;
    padding-top: 1.0em;
    border-top: 1px solid var(--rule);
    text-indent: 0 !important;
    letter-spacing: -0.005em;
  }
  .accent-dal {
    color: var(--accent-deep);
    font-style: italic;
    font-weight: 500;
  }

  /* kicker paragraph after Chart 1 */
  .kicker-para {
    font-family: "Source Serif 4", serif;
    font-size: var(--step-1);
    line-height: 1.42;
    color: var(--ink);
    text-indent: 0 !important;
  }
  .kicker-para strong {
    font-weight: 500;
    font-style: italic;
    color: var(--accent-deep);
  }

  .d2m-term {
    font-family: "Inter Tight", system-ui, sans-serif;
    font-weight: 700;
    font-style: normal;
    letter-spacing: 0.02em;
    color: var(--accent-deep);
  }

  /* section heading (## from think-piece.md) */
  .article-body .section-head {
    margin: clamp(28px, 4vw, 56px) 0 clamp(14px, 2vw, 24px);
    padding-top: clamp(14px, 2vw, 22px);
    border-top: 0;
    position: relative;
  }
  .article-body .section-head::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 48px;
    height: 2px;
    background: var(--accent);
  }
  .article-body .section-head h2 {
    font-family: "Inter Tight", system-ui, sans-serif;
    font-size: var(--step-3);
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -0.02em;
    color: var(--ink);
    margin: 0;
  }

  /* divider used by markdown's `---` */
  .article-body .section-rule {
    border: 0;
    border-top: 1px solid var(--rule);
    margin: clamp(28px, 4vw, 56px) 0;
    max-width: 6rem;
  }
}

/* ---------- chart block (figure shell, shared across all 3) ---------- */
@layer chart {
  .article-chart {
    grid-column: 1 / -1;
    background: var(--paper);
    border-top: 2px solid var(--ink);
    border-bottom: 1px solid var(--rule);
    padding: clamp(24px, 3.5vw, 44px) 0 clamp(20px, 3vw, 32px);
    margin: clamp(8px, 2vw, 20px) 0;
  }
  .article-chart-head {
    max-width: 72ch;
    padding: 0 clamp(12px, 1.5vw, 16px) clamp(16px, 2.2vw, 24px);
  }
  .article-chart-eyebrow {
    display: inline-block;
    font-family: "Inter Tight", system-ui, sans-serif;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--ink-3);
    background: var(--bg-tint);
    border: 1px solid var(--rule);
    padding: 3px 9px;
    margin-bottom: 12px;
  }
  .article-chart-title {
    font-family: "Inter Tight", system-ui, sans-serif;
    font-size: var(--step-3);
    font-weight: 700;
    line-height: 1.08;
    letter-spacing: -0.02em;
    color: var(--ink);
    margin: 0;
  }
  .article-chart-wrap {
    width: 100%;
    overflow: visible;
    padding: 0 clamp(4px, 1vw, 12px);
  }
  .article-chart-wrap svg {
    width: 100%;
    height: auto;
    display: block;
    overflow: visible;
  }
  .article-chart-source {
    padding: 14px clamp(12px, 1.5vw, 16px) 0;
    font-family: "Inter Tight", system-ui, sans-serif;
    font-size: 0.66rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-3);
    line-height: 1.6;
    border-top: 1px solid var(--rule);
    margin-top: 12px;
  }

  /* shared SVG primitives */
  .axis-line { stroke: var(--ink); stroke-width: 1.25; fill: none; }
  .grid-line { stroke: var(--rule); stroke-width: 1; fill: none; }
  .grid-line.zero { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 2 3; }

  .tick-label {
    font-family: "Inter Tight", sans-serif;
    font-size: 12px;
    fill: var(--ink-3);
    letter-spacing: 0.04em;
  }
  .axis-title {
    font-family: "Inter Tight", sans-serif;
    font-size: 11px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    fill: var(--ink-3);
    font-weight: 600;
  }
  .splitter-label {
    font-family: "Inter Tight", sans-serif;
    font-size: 10.5px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    fill: var(--ink-3);
    font-weight: 600;
  }
  .splitter-line {
    stroke: var(--ink-4);
    stroke-width: 1;
    stroke-dasharray: 2 4;
  }

  /* chart-pop specific line classes */
  .line { fill: none; stroke-linecap: round; stroke-linejoin: round; }
  .line-tx   { stroke: var(--line-tx);  stroke-width: 2.25; }
  .line-dfw  { stroke: var(--line-dfw); stroke-width: 2.25; }
  .line-dal  { stroke: var(--line-dal); stroke-width: 3.25; }
  .line-d2m  { stroke: var(--line-d2m); stroke-width: 2; stroke-dasharray: 1 5; fill: none; }

  .band-tx   { fill: var(--line-tx);  opacity: 0.10; }

  .endpoint {
    stroke: var(--paper);
    stroke-width: 2;
  }

  .label {
    font-family: "Inter Tight", sans-serif;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.02em;
  }
  .label-tx  { fill: var(--line-tx); }
  .label-dfw { fill: var(--line-dfw); }
  .label-dal { fill: var(--line-dal); }

  .annot-d2m {
    font-family: "Inter Tight", sans-serif;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    fill: var(--line-d2m);
  }
}

/* ---------- chart-typology (Chart 2) ---------- */
@layer chart-typ {
  .typ-cat-label {
    font-family: "Inter Tight", sans-serif;
    font-size: 14px;
    font-weight: 600;
    fill: var(--ink-2);
    letter-spacing: 0.01em;
  }
  .typ-bar {
    fill: var(--ink-3);
  }
  .typ-bar-accent {
    fill: var(--accent);
  }
  .typ-value {
    font-family: "Inter Tight", sans-serif;
    font-size: 15px;
    font-weight: 700;
    fill: var(--ink);
    letter-spacing: 0.01em;
  }
  .typ-value-accent {
    fill: var(--accent-deep);
  }
  .typ-annot-line {
    stroke: var(--accent-deep);
    stroke-width: 1;
    fill: none;
  }
  .typ-annot {
    font-family: "Inter Tight", sans-serif;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    fill: var(--accent-deep);
  }
  .typ-annot-strong {
    font-family: "Source Serif 4", Georgia, serif;
    font-size: 14px;
    font-style: italic;
    font-weight: 500;
    letter-spacing: 0;
    text-transform: none;
    fill: var(--ink);
  }
}

/* ---------- chart-debt (Chart 3) ---------- */
@layer chart-debt {
  .debt-bar {
    /* sharp corners, no radius */
  }
  .debt-bar-13 { fill: var(--ink-3); }
  .debt-bar-20 { fill: var(--accent); }

  .debt-value {
    font-family: "Inter Tight", sans-serif;
    font-size: 18px;
    font-weight: 700;
    fill: var(--ink);
    letter-spacing: 0;
  }
  .debt-value-accent {
    fill: var(--accent-deep);
  }
  .debt-pop-label {
    font-family: "Inter Tight", sans-serif;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    fill: var(--ink-3);
  }
  .debt-pop-label-accent {
    fill: var(--accent-deep);
  }
  .debt-group-label {
    font-family: "Inter Tight", sans-serif;
    font-size: 14px;
    font-weight: 600;
    fill: var(--ink-2);
  }
  .debt-group-total {
    font-family: "Source Serif 4", Georgia, serif;
    font-size: 12.5px;
    font-style: italic;
    fill: var(--ink-3);
  }
  .debt-arrow {
    stroke: var(--accent);
    stroke-width: 1.25;
    fill: none;
    stroke-dasharray: 3 4;
    opacity: 0.55;
  }
  .debt-arrow-head {
    stroke: var(--accent);
    stroke-width: 1.5;
    fill: none;
    opacity: 0.7;
  }
  .debt-delta {
    font-family: "Inter Tight", sans-serif;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.04em;
    fill: var(--accent-deep);
  }
}

/* ---------- mobile ---------- */
@layer mobile {
  @media (max-width: 720px) {
    .article-title {
      letter-spacing: -0.025em;
      line-height: 1.04;
      font-size: clamp(2.10rem, 8vw, 2.80rem);
    }
    .article-body .drop { font-size: 2.7em; }
    .article-head { padding-bottom: 20px; }
    .article-chart {
      padding-left: 0;
      padding-right: 0;
      margin-left: -12px;
      margin-right: -12px;
    }
    .article-chart-head,
    .article-chart-source { padding-left: 14px; padding-right: 14px; }
    .article-chart-wrap { padding-left: 0; padding-right: 0; }

    /* SVG text scales DOWN with viewBox at narrow widths. At a 380px-wide
       viewport with a viewBox-width of 1200, the scale ratio is ~0.32, so
       we need viewBox-font-size of ~40px to render at ~13px on screen.
       SVG text uses user-space units, so these px values are inside the
       viewBox. */
    .tick-label       { font-size: 34px; }
    .axis-title       { font-size: 32px; }
    .splitter-label   { font-size: 30px; }
    .label            { font-size: 38px; }
    .annot-d2m        { font-size: 30px; }

    .typ-cat-label    { font-size: 38px; }
    .typ-value        { font-size: 40px; }
    .typ-annot        { font-size: 28px; }
    .typ-annot-strong { font-size: 34px; }

    .debt-value       { font-size: 44px; }
    .debt-pop-label   { font-size: 28px; }
    .debt-group-label { font-size: 34px; }
    .debt-group-total { font-size: 28px; }
    .debt-delta       { font-size: 36px; }

  }

  @media (max-width: 480px) {
    .article-chart-title {
      font-size: clamp(1.3rem, 6.5vw, 1.7rem);
    }
  }
}
