:root {
  --bg: #0d1b2a;
  --panel: #102a43;
  --ink: #e0fbfc;
  --muted: #9fb3c8;
  --accent: #3a86ff;
  --accent-2: #ffb703;
  --border: #1f3a56;
  --maxw: 880px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Helvetica, Arial, sans-serif;
  line-height: 1.6;
  color: #14202c;
  background: #f6f9fc;
}

a { color: var(--accent); }

header.site {
  background: linear-gradient(180deg, var(--bg), var(--panel));
  color: var(--ink);
  padding: 1.25rem 1rem 0.5rem;
}

.bar {
  max-width: var(--maxw);
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
}

.brand {
  font-weight: 700;
  color: var(--ink);
  text-decoration: none;
  font-size: 1.05rem;
}

nav.lang {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  font-size: 0.9rem;
}

nav.site-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.92rem;
}

nav.site-links a {
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
}

nav.site-links a:hover { text-decoration: underline; }

nav.lang a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
}

nav.lang a[aria-current="true"] {
  color: var(--bg);
  background: var(--ink);
  border-color: var(--ink);
  font-weight: 600;
}

.hero {
  max-width: var(--maxw);
  margin: 1rem auto 0;
}

.hero img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 10px;
}

main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

main h1 { font-size: 1.7rem; margin-top: 1.5rem; }
main h2 { font-size: 1.25rem; margin-top: 2rem; }

.lede { font-size: 1.1rem; color: #33485c; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

.card {
  background: #fff;
  border: 1px solid #dce6f0;
  border-radius: 10px;
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
}

.card h3 { margin: 0 0 0.4rem; font-size: 1.05rem; }
.card p { margin: 0; color: #4a5d70; font-size: 0.95rem; }
/* Pin the call-to-action link to the bottom so cards in a grid align. */
.card > p:last-child { margin-top: auto; padding-top: 0.6rem; }
.card > p:last-child > a {
  font-weight: 650;
  text-decoration: none;
}
.card > p:last-child > a:hover { text-decoration: underline; }
.card > p:last-child > a::after {
  content: " \2192";
  display: inline-block;
  transition: transform 160ms ease;
}
.card:hover > p:last-child > a::after { transform: translateX(3px); }

.banner {
  background: #fff4d6;
  border: 1px solid #ffd166;
  color: #5a4a17;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin: 1.25rem 0;
}

footer.site {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
  color: #6b7c8e;
  font-size: 0.9rem;
  border-top: 1px solid #dce6f0;
}

.charts-page { max-width: 1120px; }
.chart-family { margin-top: 2rem; }
.chart-card {
  background: #fff;
  border: 1px solid #dce6f0;
  border-radius: 10px;
  padding: 1rem;
  margin: 1rem 0;
  overflow-x: auto;
}
.chart-card h3 { margin-top: 0; }
.chart-note { color: #4a5d70; margin: 0.5rem 0; }
.ptu-hypothesis { border-left: 4px solid var(--accent-2); padding-left: 0.75rem; }
.quality-guardrail, .quality-pairing { border-left: 4px solid var(--accent); padding-left: 0.75rem; }
.chart-svg { width: 100%; max-width: 760px; height: auto; display: block; margin: 0.9rem 0 0.75rem; }
.chart-svg rect { fill: var(--accent); }
.chart-axis { stroke: #9fb3c8; stroke-width: 1; }
.chart-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; margin-top: 0.75rem; }
.chart-table caption { text-align: left; font-weight: 600; margin-bottom: 0.35rem; }
.chart-table th, .chart-table td { border: 1px solid #dce6f0; padding: 0.35rem 0.45rem; text-align: left; }
.chart-table th { background: #eef5fb; }
.fallback-badge { display: inline-block; }

/* Article narrative layout */
.breadcrumb { color: #53687c; font-size: 0.92rem; }
.article-page h1 { font-size: clamp(2rem, 5vw, 3.25rem); line-height: 1.08; }
.article-kicker,
.section-label {
  color: #386fa4;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin: 1.2rem 0 0.35rem;
  text-transform: uppercase;
}
.article-summary-grid,
.evidence-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  margin: 1.25rem 0;
}
.summary-tile,
.article-figure,
.series-hero,
.decision-box {
  background: #fff;
  border: 1px solid #dce6f0;
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(13, 27, 42, 0.06);
  padding: 1.05rem 1.15rem;
}
.summary-tile h2,
.evidence-grid h3 { font-size: 1rem; margin: 0 0 0.35rem; }
.summary-tile p,
.evidence-grid p { color: #43566a; margin: 0; }
.article-outline {
  align-items: center;
  background: #eaf4ff;
  border: 1px solid #c7ddf3;
  border-radius: 999px;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  margin: 1.4rem 0;
  padding: 0.8rem 1rem;
}
.article-outline a { font-weight: 650; text-decoration: none; }
.article-outline a:hover { text-decoration: underline; }
.article-section {
  border-top: 1px solid #dce6f0;
  margin-top: 2.4rem;
  padding-top: 1.2rem;
}
.article-figure { margin: 1rem 0; overflow-x: auto; }
.article-figure figcaption { color: #34495e; margin-bottom: 0.9rem; }
.article-figure img.wide-chart { min-width: 720px; }
.mini-chart,
.stacked-mini-chart,
.mini-compare,
.ceiling-mini-chart,
.crossover-mini-chart {
  background: linear-gradient(180deg, #f8fbff, #edf5fb);
  border: 1px solid #dce6f0;
  border-radius: 12px;
  min-height: 120px;
  overflow: hidden;
  padding: 1rem;
}
.mini-chart {
  align-items: end;
  display: flex;
  gap: 0.55rem;
}
.mini-chart span {
  background: linear-gradient(180deg, #3a86ff, #1554b7);
  border-radius: 6px 6px 0 0;
  flex: 1;
  min-width: 28px;
}
.bar-xs { height: 22px; }
.bar-sm { height: 34px; }
.bar-md { height: 58px; }
.bar-lg { height: 82px; }
.bar-xl { height: 108px; }
.stacked-mini-chart { align-items: end; display: flex; gap: 0; }
.stacked-mini-chart span { display: block; min-height: 28px; }
.stack-visible {
  background: #8ecae6;
  border-radius: 10px 0 0 10px;
  width: 34%;
}
.stack-reasoning {
  background: #ffb703;
  border-radius: 0 10px 10px 0;
  width: 66%;
}
.mini-compare { align-items: center; display: flex; justify-content: space-around; }
.mini-compare span { border-radius: 999px; display: block; }
.dot-low { background: #9fb3c8; height: 52px; width: 52px; }
.dot-high { background: #06d6a0; height: 86px; width: 86px; }
.ceiling-mini-chart { align-items: end; display: flex; gap: 0.65rem; }
.ceiling-mini-chart span {
  background: linear-gradient(180deg, #06d6a0, #048a67);
  border-radius: 8px 8px 0 0;
  flex: 1;
  height: 92px;
}
.crossover-mini-chart { position: relative; }
.crossover-mini-chart::before,
.crossover-mini-chart::after {
  content: "";
  left: 1rem;
  position: absolute;
  right: 1rem;
  top: 62%;
}
.crossover-mini-chart::before { border-top: 4px solid #3a86ff; transform: rotate(-8deg); }
.crossover-mini-chart::after { border-top: 4px solid #ffb703; transform: rotate(10deg); }
.crossover-mini-chart span {
  background: #102a43;
  border: 3px solid #fff;
  border-radius: 999px;
  box-shadow: 0 0 0 2px #102a43;
  display: block;
  height: 18px;
  left: 49%;
  position: absolute;
  top: 56%;
  width: 18px;
}
.button-link {
  background: var(--accent);
  border-radius: 999px;
  color: #fff;
  display: inline-block;
  font-weight: 700;
  padding: 0.62rem 1rem;
  text-decoration: none;
}
.button-link:hover { background: #1554b7; }
.topic-cards .card p + p { margin-top: 0.75rem; }

/* Topic-detail and chart-explainer additions */
.tbd-card { opacity: 0.86; }
.tbd-badge {
  background: #eef5fb;
  border: 1px solid #c7ddf3;
  border-radius: 999px;
  color: #53687c;
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  margin-left: 0.35rem;
  padding: 0.05rem 0.42rem;
  vertical-align: middle;
}
.muted-note { color: #6b7c8e !important; font-style: italic; }
.topic-page ol { padding-left: 1.35rem; }
.topic-page li + li { margin-top: 0.35rem; }
.chart-explainer {
  background: #f8fbff;
  border: 1px solid #cfe1f3;
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  margin: 0.75rem 0 1rem;
  padding: 0.85rem 1rem;
}
.chart-explainer h4 { margin: 0 0 0.55rem; }
.chart-explainer dl {
  display: grid;
  gap: 0.35rem 0.75rem;
  grid-template-columns: minmax(72px, auto) 1fr;
  margin: 0;
}
.chart-explainer dt { color: #1f3a56; font-weight: 700; }
.chart-explainer dd { color: #43566a; margin: 0; }
.chart-axis-label,
.chart-category-label,
.chart-value-label,
.chart-title {
  font-family: "Segoe UI", system-ui, -apple-system, Helvetica, Arial, sans-serif;
}
.chart-title { fill: #102a43; font-size: 13px; font-weight: 700; }
.chart-axis-label { fill: #53687c; font-size: 11px; font-weight: 700; }
.chart-category-label { fill: #43566a; font-size: 10px; }
.chart-value-label { fill: #102a43; font-size: 9.5px; font-weight: 700; }
.chart-card:target {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(58, 134, 255, 0.18);
}

.chart-reading-guide .evidence-grid { margin-top: 1rem; }
.chart-reading-note {
  background: #f8fbff;
  border: 1px solid #cfe1f3;
  border-left: 4px solid var(--accent-2);
  border-radius: 10px;
  color: #31475e;
  margin: 0.75rem 0 1rem;
  padding: 0.85rem 1rem;
}
.chart-reading-note h3 { margin: 0 0 0.35rem; }
.chart-reading-note p { margin: 0; }
.evidence-table td { vertical-align: top; }


/* Labeled overview mini-charts */
.labeled-mini-chart,
.labeled-stack-chart,
.labeled-dot-chart,
.labeled-ceiling-chart,
.labeled-crossover-chart {
  display: block;
  overflow: visible;
}
.mini-axis-row,
.mini-x-axis,
.mini-legend,
.dot-legend,
.crossover-legend {
  color: #53687c;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.mini-axis-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.55rem;
}
.mini-x-axis { margin-top: 0.55rem; text-align: center; }
.mini-plot,
.ceiling-plot {
  align-items: end;
  border-bottom: 2px solid #9fb3c8;
  border-left: 2px solid #9fb3c8;
  display: flex;
  gap: 0.7rem;
  min-height: 132px;
  padding: 0.35rem 0.3rem 0 0.55rem;
}
.mini-bar-wrap,
.ceiling-bar-wrap {
  align-items: center;
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: flex-end;
  min-width: 44px;
}
.mini-bar-fill,
.ceiling-fill {
  background: linear-gradient(180deg, #3a86ff, #1554b7);
  border-radius: 7px 7px 0 0;
  display: block;
  width: 100%;
}
.bar-label,
.ceiling-label,
.dot-label,
.segment-label,
.crossover-label {
  color: #31475e;
  font-size: 0.76rem;
  font-weight: 700;
  line-height: 1.15;
  margin-top: 0.28rem;
  text-align: center;
}
.labeled-stack-chart .stack-track {
  border: 1px solid #b9cfdf;
  border-radius: 12px;
  display: flex;
  min-height: 68px;
  overflow: hidden;
}
.stack-segment {
  align-items: center;
  display: flex;
  justify-content: center;
  min-width: 74px;
  padding: 0.45rem;
  text-align: center;
}
.stack-input { background: #8ecae6; width: 38%; }
.stack-output { background: #cfe8f7; width: 16%; }
.stack-reason { background: #ffb703; width: 46%; }
.mini-legend,
.dot-legend,
.crossover-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.8rem;
  justify-content: center;
  margin-top: 0.65rem;
}
.dot-plot {
  align-items: end;
  border-bottom: 2px solid #9fb3c8;
  border-left: 2px solid #9fb3c8;
  display: flex;
  justify-content: space-around;
  min-height: 126px;
  padding: 0.4rem 1rem 0;
}
.dot-wrap {
  align-items: center;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.dot-fill { border-radius: 999px; display: block; }
.dot-low { background: #9fb3c8; height: 52px; width: 52px; }
.dot-high { background: #06d6a0; height: 86px; width: 86px; }
.ceiling-fill {
  background: linear-gradient(180deg, #06d6a0, #048a67);
  height: 92px;
}
.ceiling-fill.high { height: 98px; }
.ceiling-fill.flat { height: 96px; }
.labeled-crossover-chart { min-height: 150px; position: relative; }
.labeled-crossover-chart .crossover-point {
  background: #102a43;
  border: 3px solid #fff;
  border-radius: 999px;
  box-shadow: 0 0 0 2px #102a43;
  display: block;
  height: 18px;
  left: 49%;
  position: absolute;
  top: 56%;
  width: 18px;
}
.crossover-label {
  background: rgba(255,255,255,0.86);
  border: 1px solid #dce6f0;
  border-radius: 999px;
  display: inline-block;
  padding: 0.16rem 0.45rem;
}
.crossover-label.payg { color: #1554b7; }
.crossover-label.ptu { color: #8a5b00; }
.crossover-label.point {
  left: 42%;
  position: absolute;
  top: 32%;
}
.labeled-mini-chart .mini-axis-row span {
  background: transparent;
  border-radius: 0;
  flex: 0 1 auto;
  min-width: 0;
}

/* Self-contained, responsive SVG mini-charts (mobile-first). The viewBox
   scales with the container width, so axis and series labels never wrap or
   collide the way absolutely-positioned text can on narrow screens. */
.mini-svg-chart {
  background: linear-gradient(180deg, #f8fbff, #edf5fb);
  border: 1px solid #dce6f0;
  border-radius: 12px;
  display: block;
  height: auto;
  margin: 0 auto;
  max-width: 560px;
  width: 100%;
}

/* --- Interaction affordances: hover lift, keyboard focus rings, motion guard --- */
:where(a, button, .card, .button-link, .chart-card, .summary-tile) {
  transition: transform 160ms ease, box-shadow 160ms ease,
    border-color 160ms ease, background-color 160ms ease, color 160ms ease;
}

.card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: 0 12px 28px rgba(13, 27, 42, 0.12);
}

.button-link:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 22px rgba(58, 134, 255, 0.32);
}
.button-link:active { transform: translateY(0); }

.chart-card:hover {
  border-color: #bcd6f2;
  box-shadow: 0 10px 24px rgba(13, 27, 42, 0.08);
}

nav.site-links a:hover { color: var(--accent); }

footer.site .site-links { margin-bottom: 0.75rem; }
footer.site .site-links a { color: var(--accent); }
footer.site .site-links a:hover { color: #1554b7; }

a:focus-visible,
button:focus-visible,
.card:focus-visible,
.button-link:focus-visible,
nav.site-links a:focus-visible,
nav.lang a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

@media (prefers-reduced-motion: reduce) {
  :where(a, button, .card, .button-link, .chart-card, .summary-tile) {
    transition: none;
  }
  .card:hover,
  .button-link:hover,
  .button-link:active {
    transform: none;
  }
  .card:hover > p:last-child > a::after { transform: none; }
}

/* --- Typographic polish: inline code, text selection, anchored scrolling --- */
code, kbd, samp {
  font-family: ui-monospace, "SF Mono", "Cascadia Code", "Source Code Pro",
    Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.9em;
}
:not(pre) > code {
  background: #eef3f8;
  border: 1px solid #d8e2ee;
  border-radius: 6px;
  padding: 0.08em 0.36em;
  color: #1b3a5b;
  overflow-wrap: break-word;
}
h1 code, h2 code, h3 code, .card h3 code {
  font-size: 0.86em;
  padding: 0.04em 0.3em;
}
kbd {
  background: #102a43;
  border: 1px solid #1f3a56;
  border-bottom-width: 2px;
  border-radius: 6px;
  color: #e0fbfc;
  padding: 0.05em 0.4em;
}

::selection { background: rgba(58, 134, 255, 0.22); color: inherit; }

/* Readable underlines for in-prose links (leave nav/buttons untouched). */
main p a,
.lede a,
.breadcrumb a,
.article-figure figcaption a,
footer.site a {
  text-underline-offset: 0.18em;
  text-decoration-thickness: from-font;
}

html { scroll-behavior: smooth; }
:target,
.article-section,
.chart-card,
[id] > h2,
[id] > h3 { scroll-margin-top: 1.1rem; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
