/* The Learn pages (statlab.cc/learn/ and /es/aprende/): articles, hubs and the 404 page.
   Same colors as the app (src/styles.css), in light and dark. */

:root {
  color-scheme: light dark;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --border: #d8dce2;
  --text: #1b1f24;
  --text-muted: #57606b;
  --accent: #1f4fbf;
  --accent-hover: #183f99;
  --accent-text: #ffffff;
  --accent-soft: #e3eafa;
  --gold: #b7791f;
  --danger: #b42318;
  --good: #1a7f4b;
  --badge-bg: #eceef2;
  --badge-text: #4b5360;
  --ready-bg: #dff3e7;
  --ready-text: #155f39;
  --grid: #e7eaee;
  --bar: #8fa9e6;
  --s0: #1f4fbf;
  --s1: #c2410c;
  --s2: #1a7f4b;
  --s3: #7c3aed;
  --s4: #b7791f;
  --s5: #0e7490;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1a1d22;
    --border: #2f343c;
    --text: #e4e7eb;
    --text-muted: #9ea7b2;
    --accent: #6f9bff;
    --accent-hover: #8db0ff;
    --accent-text: #0b1530;
    --accent-soft: #24324f;
    --gold: #f0b54a;
    --danger: #ff8a80;
    --good: #5fd39a;
    --badge-bg: #2a2e35;
    --badge-text: #b6bec8;
    --ready-bg: #173826;
    --ready-text: #8fe3b4;
    --grid: #272b31;
    --bar: #3f5a99;
    --s0: #6f9bff;
    --s1: #fb923c;
    --s2: #5fd39a;
    --s3: #b794f6;
    --s4: #f0b54a;
    --s5: #5ec8dc;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.65 var(--font);
}

a {
  color: var(--accent);
  text-underline-offset: 2px;
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip {
  position: absolute;
  left: 12px;
  top: -48px;
  padding: 8px 12px;
  background: var(--surface);
  border-radius: var(--radius);
  z-index: 10;
}

.skip:focus {
  top: 12px;
}

/* ---- Header and footer ---------------------------------------------------- */

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  padding: 12px max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

/* In the Home Screen app, iOS 26 blurs the top of the page unless a full-width, opaque bar that
   is fixed or sticky covers the top edge (see the app's styles.css). */
@media (display-mode: standalone) {
  .site-header {
    position: sticky;
    top: 0;
    z-index: 10;
  }
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.3px;
}

.brand__edition {
  padding: 0 6px;
  border: 2px solid var(--gold);
  border-radius: 6px;
  color: var(--gold);
  font-size: 12px;
  line-height: 18px;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  font-size: 15px;
}

.site-nav a:not(.button) {
  color: var(--text);
  text-decoration: none;
}

.site-nav a:not(.button):hover {
  text-decoration: underline;
}

.button {
  display: inline-block;
  padding: 7px 16px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  text-decoration: none;
  line-height: 1.4;
}

.button:hover {
  background: var(--accent-hover);
  color: var(--accent-text);
}

.button--large {
  padding: 11px 24px;
  font-size: 18px;
}

.site-footer {
  margin-top: 48px;
  padding: 24px 16px 40px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
}

.site-footer p {
  margin: 4px 0;
}

.site-footer__note {
  max-width: 640px;
  margin: 12px auto 0 !important;
  font-size: 12.5px;
}

/* ---- Page ----------------------------------------------------------------- */

.page {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 16px 0;
}

.page--wide {
  max-width: 1040px;
}

.crumbs ol {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 0 0 8px;
  padding: 0;
  list-style: none;
  font-size: 14px;
}

.crumbs li + li::before {
  content: '›';
  margin-right: 4px;
  color: var(--text-muted);
}

.crumbs a {
  color: var(--text-muted);
}

h1,
h2,
h3 {
  line-height: 1.25;
  letter-spacing: -0.2px;
  /* Room above a heading that a link jumps to, such as a section of the formulas page. */
  scroll-margin-top: 16px;
}

h1 {
  margin: 0 0 8px;
  font-size: clamp(28px, 5vw, 38px);
}

h2 {
  margin: 40px 0 12px;
  font-size: 25px;
}

h3 {
  margin: 28px 0 8px;
  font-size: 19px;
}

.meta {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
}

.lede {
  font-size: 19px;
  color: var(--text-muted);
}

.prose {
  margin-top: 24px;
}

.prose li + li {
  margin-top: 4px;
}

.prose code,
.formula code {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

.prose :not(pre, .formula) > code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--badge-bg);
}

.formula {
  margin: 16px 0;
  padding: 12px 16px;
  overflow-x: auto;
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--surface);
  font-size: 18px;
  white-space: pre-wrap;
}

.formula code {
  font-size: 1em;
}

pre {
  overflow-x: auto;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}

.table-wrap {
  margin: 16px 0;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

tbody tr:last-child td {
  border-bottom: 0;
}

th {
  background: var(--badge-bg);
  font-weight: 600;
}

blockquote {
  margin: 16px 0;
  padding: 4px 16px;
  border-left: 3px solid var(--border);
  color: var(--text-muted);
}

/* ---- Reference pages: the table of constants and the glossary -------------- */

table.constants caption {
  padding: 8px 12px;
  text-align: left;
  color: var(--text-muted);
  font-size: 14px;
}

table.constants {
  font-size: 14px;
}

table.constants td,
table.constants th {
  padding: 6px 8px;
}

table.constants td,
table.constants th[scope='col'] {
  text-align: right;
}

table.constants tbody th {
  font-weight: 600;
}

table.constants tbody tr:last-child th {
  border-bottom: 0;
}

.glossary dt {
  margin-top: 20px;
  font-weight: 600;
  scroll-margin-top: 16px;
}

.glossary dt:target {
  color: var(--accent);
}

.glossary__other {
  margin-left: 6px;
  font-weight: 400;
  color: var(--text-muted);
}

.glossary dd {
  margin: 4px 0 0;
}

.glossary dd p {
  margin: 0;
}

/* ---- The "In StatLab" box, related articles, call to action --------------- */

.toolbox {
  margin: 24px 0 8px;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.toolbox h2 {
  margin: 0 0 8px;
  font-size: 17px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
}

.toolbox ul {
  margin: 0 0 8px;
  padding: 0;
  list-style: none;
}

.toolbox li {
  margin: 4px 0;
}

.toolbox p {
  margin: 8px 0 12px;
  color: var(--text-muted);
  font-size: 15px;
}

.menu-path {
  font-weight: 600;
}

.badge {
  display: inline-block;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--badge-bg);
  color: var(--badge-text);
  font-size: 13px;
  white-space: nowrap;
}

.badge--ready {
  background: var(--ready-bg);
  color: var(--ready-text);
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.cards li {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.cards a {
  font-weight: 600;
  text-decoration: none;
}

.cards a:hover {
  text-decoration: underline;
}

.cards p {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.5;
}

.cta {
  margin-top: 48px;
  padding: 24px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  text-align: center;
}

.cta h2 {
  margin-top: 0;
}

/* ---- Hub ------------------------------------------------------------------ */

.hub-header {
  margin-bottom: 16px;
}

.hub-toc ul {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.hub-toc a {
  display: inline-block;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 15px;
  text-decoration: none;
}

.hub-section h2 {
  scroll-margin-top: 16px;
}

/* ---- Charts --------------------------------------------------------------- */

.chart {
  margin: 20px 0;
  padding: 12px 8px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.chart__svg {
  display: block;
  width: 100%;
  height: auto;
  font-family: var(--font);
}

.chart figcaption {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
}

.c-grid {
  stroke: var(--grid);
  stroke-width: 1;
}

.c-axis {
  stroke: var(--text-muted);
  stroke-width: 1;
}

.c-tick,
.c-limit-label {
  fill: var(--text-muted);
  font-size: 12px;
}

.c-label {
  fill: var(--text);
  font-size: 13px;
}

.c-line,
.c-series {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.6;
  stroke-linejoin: round;
}

.c-point {
  fill: var(--accent);
}

.c-line--accent {
  stroke: var(--s1);
}

.c-point--accent {
  fill: var(--s1);
}

.c-out {
  fill: var(--danger);
  stroke: var(--surface);
  stroke-width: 1;
}

.c-center {
  fill: none;
  stroke: var(--good);
  stroke-width: 1.4;
}

.c-limit {
  fill: none;
  stroke: var(--danger);
  stroke-width: 1.4;
  stroke-dasharray: 6 4;
}

.c-spec {
  stroke: var(--danger);
  stroke-width: 1.6;
  stroke-dasharray: 6 4;
}

.c-target {
  stroke: var(--good);
  stroke-width: 1.6;
  stroke-dasharray: 2 3;
}

.c-fit {
  fill: none;
  stroke: var(--s1);
  stroke-width: 2;
}

.c-bar {
  fill: var(--bar);
}

.c-box {
  fill: var(--accent-soft);
  stroke: var(--accent);
  stroke-width: 1.4;
}

.c-whisker {
  stroke: var(--text-muted);
  stroke-width: 1.4;
}

.c-median {
  stroke: var(--accent);
  stroke-width: 2.4;
}

.c-flag {
  fill: var(--danger);
  font-size: 11px;
  font-weight: 700;
}

.c-divider {
  stroke: var(--text-muted);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.c-phase {
  fill: var(--text-muted);
  font-size: 12px;
}

.c-curve {
  fill: none;
  stroke: var(--s1);
  stroke-width: 2;
  stroke-linejoin: round;
}

.c-area {
  fill: var(--accent);
  fill-opacity: 0.28;
}

.c-area-label {
  fill: var(--text);
  font-size: 15px;
  font-weight: 700;
  paint-order: stroke;
  stroke: var(--surface);
  stroke-width: 4px;
  stroke-linejoin: round;
}

.c-bound {
  stroke: var(--accent);
  stroke-width: 1.6;
}

.c-marker {
  stroke: var(--text);
  stroke-width: 1.6;
  stroke-dasharray: 2 3;
}

.c-s0 { stroke: var(--s0); fill: var(--s0); }
.c-s1 { stroke: var(--s1); fill: var(--s1); }
.c-s2 { stroke: var(--s2); fill: var(--s2); }
.c-s3 { stroke: var(--s3); fill: var(--s3); }
.c-s4 { stroke: var(--s4); fill: var(--s4); }
.c-s5 { stroke: var(--s5); fill: var(--s5); }

path.c-series {
  fill: none;
}

/* ---- Interactive demos (```demo blocks; src/site/demos.ts and demoClient.ts) ---- */

.demo {
  margin: 24px 0;
  padding: 14px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.demo__title {
  margin: 0 4px 8px;
  font-weight: 600;
  line-height: 1.4;
}

/* The controls show once the script starts them; without it the chart and summary stand alone. */
.demo__controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 12px 4px 0;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.demo__controls[hidden] {
  display: none;
}

.demo__control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    'label value'
    'slider slider';
  align-items: center;
  gap: 0 12px;
  font-size: 15px;
}

.demo__control label {
  grid-area: label;
}

.demo__control input {
  grid-area: slider;
  width: 100%;
  min-width: 0;
  height: 32px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.demo__control output {
  grid-area: value;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

@media (min-width: 600px) {
  .demo__control {
    grid-template-columns: 12.5em minmax(0, 1fr) 6.5em;
    grid-template-areas: 'label slider value';
  }
}

.demo__reset {
  align-self: flex-start;
  padding: 5px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.demo__reset:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.demo__stats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  margin: 12px 4px 0;
  font-size: 14px;
}

.demo__stats div {
  display: flex;
  gap: 6px;
}

.demo__stats dt {
  color: var(--text-muted);
}

.demo__stats dd {
  margin: 0;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.demo__summary {
  margin: 10px 4px 0;
  font-size: 15px;
  line-height: 1.55;
}

@media (max-width: 560px) {
  body {
    font-size: 16px;
  }

  .site-nav {
    font-size: 14px;
    gap: 8px 14px;
  }

  .lede {
    font-size: 17px;
  }
}
