/* kit.css: the reusable layer. Tokens, type, grid, header, sub-tabs, pagination, number balls, tables,
   controls, charts, ad slot, tooltip. A site overrides tokens in its own stylesheet; components only read
   tokens. Light and dark come from one declaration each through light-dark(), so a section can flip to dark
   with color-scheme: dark.

   One type scale and one spacing scale: every font-size reads a --fs-* or --step-* token and every margin,
   padding and gap reads a --sp-* token (or --m, --gap, --sec, which are built from it). tests/test_kit.py
   fails on a raw value. */

:root {
  color-scheme: light dark;
  --paper: light-dark(#f2f1ec, #0f1114);
  --surface: light-dark(#e6e4dd, #181b20);
  --surface-2: light-dark(#d9d6cd, #22262d);
  --ink: light-dark(#14161b, #ecebe5);
  --muted: light-dark(#4b4f58, #a6aab2);
  --spot: light-dark(#c8203a, #ff6676);
  --spot-ink: light-dark(#ffffff, #1b0609);
  --cool: light-dark(#1d58a6, #74abff);
  --band: light-dark(rgb(20 22 27 / 0.1), rgb(236 235 229 / 0.12));
  --field-ink: #16191e;

  /* number balls: five categorical tones, each numeral/fill pair >= 4.5:1 in light and dark */
  --tone-1: light-dark(#f2b01e, #e2ac24);
  --tone-2: light-dark(#4f97dd, #5c9ee0);
  --tone-3: light-dark(#ec6872, #e86d76);
  --tone-4: light-dark(#a9a69d, #a3a19a);
  --tone-5: light-dark(#86bd45, #88bd4c);
  --tone-1-ink: light-dark(#1d1a12, #0f1114);
  --tone-2-ink: light-dark(#0c1a2a, #0f1114);
  --tone-3-ink: light-dark(#2a0a0e, #0f1114);
  --tone-4-ink: light-dark(#14161b, #0f1114);
  --tone-5-ink: light-dark(#13200a, #0f1114);
  --ball-edge: light-dark(rgb(20 22 27 / 0.14), rgb(0 0 0 / 0));

  --font: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;

  /* the type scale (px): 12 14 16 18 22 28 36 48 */
  --fs-12: 0.75rem;
  --fs-14: 0.875rem;
  --fs-16: 1rem;
  --fs-18: 1.125rem;
  --fs-22: 1.375rem;
  --fs-28: 1.75rem;
  --fs-36: 2.25rem;
  --fs-48: 3rem;
  /* roles: the phone step here, the expanded step from 900px */
  --step-caption: var(--fs-12);
  --step-small: var(--fs-14);
  --step-body: var(--fs-16);
  --step-lead: var(--fs-18);
  --step-sub: var(--fs-18);
  --step-title: var(--fs-22);
  --step-head: var(--fs-28);
  --step-display: var(--fs-36);
  --lh-body: 1.7;
  --lh-head: 1.3;
  --measure: 68ch;

  /* the spacing scale (px): 4 8 12 16 24 32 48 64 */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;
  --sp-8: 64px;
  --m: var(--sp-4);     /* page margin */
  --gap: var(--sp-4);   /* grid gap */
  --sec: var(--sp-6);   /* space between sections */

  --ball: 32px;
  --ball-lg: 40px;
}
@media (min-width: 900px) {
  :root {
    --step-sub: var(--fs-22);
    --step-title: var(--fs-28);
    --step-head: var(--fs-36);
    --step-display: var(--fs-48);
    --m: var(--sp-7);
    --gap: var(--sp-5);
    --sec: var(--sp-7);
    --ball: 36px;
    --ball-lg: 56px;
  }
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: var(--sp-3); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; } }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  min-height: 100vh; display: flex; flex-direction: column;  /* a short page keeps its footer at the bottom */
  font-family: var(--font); font-size: var(--step-body); line-height: var(--lh-body); font-weight: 400; letter-spacing: 0;
  word-break: keep-all; overflow-wrap: break-word; text-rendering: optimizeLegibility;
}
img, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration-thickness: 1.5px; text-underline-offset: 0.18em; }
a:hover { text-decoration-color: var(--spot); }
p { margin: 0 0 var(--sp-4); max-width: var(--measure); }
ul, ol { margin: 0 0 var(--sp-4); padding: 0 0 0 var(--sp-5); }
h1, h2, h3 { margin: 0; font-weight: 700; line-height: var(--lh-head); letter-spacing: -0.02em; }
button { font: inherit; padding: 0; }
:focus-visible { outline: 3px solid var(--spot); outline-offset: 2px; }
::selection { background: var(--spot); color: var(--spot-ink); }
.skip { position: absolute; left: -9999px; top: 0; z-index: 60; background: var(--ink); color: var(--paper); padding: var(--sp-3) var(--sp-4); }
.skip:focus { left: var(--sp-2); top: var(--sp-2); }
.vh { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

/* ---------- type: one role, one step ---------- */
.display { font-size: var(--step-display); line-height: 1.25; letter-spacing: -0.02em; font-weight: 800; }
.head { font-size: var(--step-head); line-height: var(--lh-head); letter-spacing: -0.02em; font-weight: 750; margin: 0 0 var(--sp-3); }
.title { font-size: var(--step-title); line-height: var(--lh-head); letter-spacing: -0.02em; font-weight: 720; margin: 0 0 var(--sp-3); }
.sub { font-size: var(--step-sub); line-height: 1.35; letter-spacing: -0.01em; font-weight: 700; margin: var(--sp-6) 0 var(--sp-3); }
.lead { font-size: var(--step-lead); line-height: var(--lh-body); }
.small, .caption, .legend { font-size: var(--step-small); line-height: 1.65; color: var(--muted); }
.figure { font-size: var(--step-head); line-height: 1.25; letter-spacing: -0.02em; font-weight: 750; margin: 0 0 var(--sp-1); }
.num, .t, .figure, .ball, .tick, .val, .tnum, time { font-variant-numeric: tabular-nums; }
.strong { font-weight: 700; }
.tag { display: inline-block; font-size: var(--step-caption); font-weight: 650; line-height: 1; padding: var(--sp-1) var(--sp-2); background: var(--surface-2); color: var(--ink); vertical-align: 0.15em; }
.empty { color: var(--muted); }

/* ---------- grid: a 12-column page with the axis at 5/12 ---------- */
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); column-gap: var(--gap); padding-inline: var(--m); }
.grid > .side { grid-column: 1 / span 4; min-width: 0; }
.grid > .main { grid-column: 6 / -1; min-width: 0; max-width: 54rem; }
.grid > .wide { grid-column: 1 / -1; min-width: 0; }
.grid + .grid:not(.sec) { margin-top: var(--sp-6); }  /* grids inside one section; sections space themselves */
@media (max-width: 899px) {
  .grid > .side, .grid > .main { grid-column: 1 / -1; }
  .grid > .side { margin-bottom: var(--sp-4); }
}
.sec { padding-block: var(--sec) 0; }
main { flex: 1 0 auto; }
main > :last-child { padding-bottom: var(--sec); }
.field-ink, .field-surface { padding-block: var(--sec); margin-top: var(--sec); }
.field-ink + .sec, .field-surface + .sec { padding-top: var(--sec); }
.field-ink { color-scheme: dark; background: var(--field-ink); color: var(--ink); }
.field-surface { background: var(--surface); }
.field-surface .t tbody tr:nth-child(even) { background: var(--surface-2); }

/* ---------- header bar: one row on desktop; on phones the nav takes its own full-width row ---------- */
.bar { display: flex; align-items: stretch; flex-wrap: wrap; background: var(--paper); box-shadow: inset 0 -1px 0 var(--surface-2); }
.wordmark { display: flex; align-items: center; background: var(--ink); color: var(--paper); padding: var(--sp-3) var(--m); font-size: var(--fs-18); font-weight: 800; letter-spacing: -0.02em; line-height: var(--lh-head); text-decoration: none; }
.nav { display: flex; flex-wrap: nowrap; align-items: stretch; gap: 0 var(--sp-5); padding: 0 var(--sp-5); flex: 1; min-width: 0; }
.nav a { display: flex; align-items: center; min-height: 48px; text-decoration: none; font-weight: 600; white-space: nowrap; box-shadow: inset 0 -3px 0 transparent; }
.nav a:hover { box-shadow: inset 0 -3px 0 var(--surface-2); }
.nav a[aria-current="page"] { font-weight: 750; box-shadow: inset 0 -3px 0 var(--spot); }
.theme { appearance: none; border: 0; background: transparent; color: var(--ink); width: 48px; min-height: 48px; display: grid; place-items: center; cursor: pointer; }
.theme:hover { background: var(--surface); }
@media (max-width: 719px) {
  .bar { justify-content: space-between; }
  .nav { order: 3; flex-basis: 100%; justify-content: space-between; gap: 0 var(--sp-2); padding: 0 var(--m); overflow-x: auto; scrollbar-width: none; background: var(--surface); }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { min-height: 44px; }
}

/* ---------- sub-tabs: the secondary nav of a menu group ---------- */
.subnav { display: flex; flex-wrap: nowrap; gap: 0 var(--sp-5); padding-inline: var(--m); overflow-x: auto; scrollbar-width: none; box-shadow: inset 0 -1px 0 var(--surface-2); }
.subnav::-webkit-scrollbar { display: none; }
.subnav a { display: flex; align-items: center; min-height: 44px; white-space: nowrap; text-decoration: none; font-size: var(--step-small); font-weight: 600; color: var(--muted); box-shadow: inset 0 -2px 0 transparent; }
.subnav a:hover { color: var(--ink); }
.subnav a[aria-current="page"] { color: var(--ink); font-weight: 750; box-shadow: inset 0 -2px 0 var(--ink); }
.nav a:focus-visible, .subnav a:focus-visible { outline-offset: -3px; }  /* inside the link: both rows scroll, which clips an outer ring */
@media (min-width: 900px) { .subnav a { font-size: var(--step-body); } }

/* ---------- pagination ---------- */
.pagination { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1); margin-top: var(--sp-5); }
.pagination a, .pagination .gap { display: inline-grid; place-items: center; min-width: 44px; min-height: 44px; padding: 0 var(--sp-2); text-decoration: none; font-weight: 650; font-variant-numeric: tabular-nums; }
.pagination a { background: var(--surface); }
.pagination a:hover { background: var(--surface-2); }
.pagination a[aria-current="page"] { background: var(--ink); color: var(--paper); }
.pagination .gap { color: var(--muted); min-width: 0; }
.pagination .step { padding: 0 var(--sp-3); }
.pagination .step[aria-disabled="true"] { color: var(--muted); background: transparent; pointer-events: none; }

/* ---------- number balls: circles with bold tabular numerals, one tone per value range ---------- */
.balls { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1); vertical-align: middle; }
.ball { --tone: var(--surface-2); --tone-ink: var(--ink);
  display: inline-grid; place-items: center; flex: none; width: var(--ball); height: var(--ball); border-radius: 50%;
  background: var(--tone); color: var(--tone-ink); box-shadow: inset 0 0 0 1px var(--ball-edge);
  font-size: var(--fs-16); font-weight: 750; line-height: 1; letter-spacing: 0; text-decoration: none; }
.ball.t1 { --tone: var(--tone-1); --tone-ink: var(--tone-1-ink); }
.ball.t2 { --tone: var(--tone-2); --tone-ink: var(--tone-2-ink); }
.ball.t3 { --tone: var(--tone-3); --tone-ink: var(--tone-3-ink); }
.ball.t4 { --tone: var(--tone-4); --tone-ink: var(--tone-4-ink); }
.ball.t5 { --tone: var(--tone-5); --tone-ink: var(--tone-5-ink); }
.ball.dim { --tone: transparent; --tone-ink: var(--muted); box-shadow: inset 0 0 0 2px var(--surface-2); font-weight: 600; }  /* not a match: hollow, so it differs from every tone by shape, not colour alone */
a.ball:hover { box-shadow: inset 0 0 0 3px var(--tone-ink); }
.balls .ball-sep { display: inline-flex; align-items: center; margin: 0 var(--sp-1); color: var(--muted); font-weight: 700; line-height: 1; }
.ball.extra { outline: 2px solid var(--muted); outline-offset: 2px; }
a.ball.extra:focus-visible, a.ball:focus-visible { outline: 3px solid var(--spot); outline-offset: 2px; }
.balls.lg { gap: var(--sp-1); }
@media (min-width: 900px) { .balls.lg { gap: var(--sp-2); } }
.balls.lg .ball { width: var(--ball-lg); height: var(--ball-lg); font-size: var(--step-title); }
.balls.lg .ball-sep { margin: 0 var(--sp-2); font-size: var(--step-title); }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 var(--sp-5); border: 0; border-radius: 0;
  background: var(--spot); color: var(--spot-ink); font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
  transition: transform 120ms ease, background-color 120ms ease; }
.btn:hover { background: color-mix(in oklab, var(--spot) 86%, var(--ink)); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: inherit; box-shadow: inset 0 0 0 2px currentColor; }
.btn.ghost:hover { background: color-mix(in oklab, currentColor 10%, transparent); }
.btn[disabled] { opacity: 0.45; cursor: default; }
.link { font-weight: 650; }
.field { display: inline-flex; flex-direction: column; gap: var(--sp-1); font-size: var(--step-small); color: var(--muted); }
.field input, .field select { font: inherit; font-size: var(--fs-16); color: var(--ink); background: var(--paper); border: 2px solid var(--surface-2); border-radius: 0; min-height: 48px; padding: 0 var(--sp-3); }
.field input:focus, .field select:focus { border-color: var(--ink); outline: none; }
.field input::placeholder { color: color-mix(in oklab, var(--muted) 75%, transparent); }
.row-btns { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: var(--sp-3); }
.controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--sp-3) var(--sp-4); margin-bottom: var(--sp-4); }
.controls .field { flex: 1 1 160px; max-width: 320px; }
.controls .count { margin: 0 0 var(--sp-3); color: var(--muted); font-size: var(--step-small); }
.more { margin-top: var(--sp-5); display: flex; flex-wrap: wrap; gap: var(--sp-4); align-items: center; }

/* ---------- tables: tone steps, no rules ---------- */
.table-wrap { overflow-x: auto; max-width: 100%; }
.t { border-collapse: collapse; width: 100%; font-size: var(--fs-16); }
.t caption { caption-side: top; text-align: left; font-size: var(--step-small); color: var(--muted); padding-bottom: var(--sp-2); }
.t th, .t td { padding: var(--sp-2) var(--sp-3); text-align: left; vertical-align: middle; }
.t thead th { font-size: var(--step-small); font-weight: 650; color: var(--muted); padding-block: var(--sp-2); }
.t tbody tr:nth-child(even) { background: var(--surface); }
.t tbody th { font-weight: 650; }
.t .num { text-align: right; white-space: nowrap; }
@media (max-width: 719px) { .t { font-size: var(--fs-14); } .t th, .t td { padding: var(--sp-2); } .t .opt { display: none; } .t thead th.num { white-space: normal; } }

/* ---------- ad slot (only rendered while ads are on) ---------- */
.ad { margin: var(--sec) auto 0; max-width: 1000px; padding-inline: var(--m); min-height: calc(var(--ad-h, 250px) + var(--sp-6)); }
.ad-label { font-size: var(--step-caption); color: var(--muted); margin: 0 0 var(--sp-1); }
.ad ins { background: var(--surface); }

/* ---------- tooltip ---------- */
.kit-tip { position: fixed; z-index: 70; pointer-events: none; max-width: 280px; padding: var(--sp-2) var(--sp-3); background: var(--ink); color: var(--paper);
  font-size: var(--step-small); line-height: 1.4; font-weight: 600; box-shadow: 0 8px 28px rgb(0 0 0 / 0.22); opacity: 0; transition: opacity 90ms ease; }
.kit-tip.on { opacity: 1; }

/* ---------- charts (rendered by kit/charts.py) ---------- */
.chart { --mark: var(--ink); --flag: var(--spot); margin: var(--sp-2) 0 var(--sp-3); }
.chart.cols { display: grid; grid-template-columns: 3em minmax(0, 1fr); grid-template-rows: auto auto; }
.chart.cols .yaxis { position: relative; grid-row: 1; grid-column: 1; }
.chart.cols .plot { position: relative; grid-row: 1; grid-column: 2; height: clamp(200px, 22vw, 300px); }
.chart.cols.spark .plot { height: clamp(110px, 12vw, 150px); }
.chart.cols.spark { grid-template-columns: 0 minmax(0, 1fr); }
.chart.cols .xaxis { grid-row: 2; grid-column: 2; display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); gap: 0; margin-top: var(--sp-2); font-size: var(--step-caption); color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }
.chart.cols .xaxis span { display: flex; justify-content: center; white-space: nowrap; overflow-wrap: normal; }
.chart.cols.spark .xaxis span.minor { visibility: hidden; }
.chart.cols.spark .xaxis span:first-child { text-align: left; white-space: nowrap; }
.chart.cols.spark .xaxis span:last-child { text-align: right; white-space: nowrap; direction: rtl; }
@media (max-width: 899px) { .chart.cols .xaxis span.minor { visibility: hidden; } }
.chart .tick { position: absolute; right: var(--sp-2); bottom: var(--b); transform: translateY(50%); font-size: var(--step-caption); color: var(--muted); }
.chart .band { position: absolute; left: 0; right: 0; bottom: var(--b); height: var(--h); background: var(--band); }
.chart .base { position: absolute; left: 0; right: 0; bottom: var(--b); border-top: 1.5px solid var(--muted); }
.chart .base.ref { border-top-style: dashed; border-color: var(--spot); }
.chart .marks { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); gap: 0; }
.chart .col { position: relative; outline: none; cursor: default; }
.chart .col::before { content: ""; position: absolute; left: 50%; transform: translateX(-50%); width: min(24px, 76%); bottom: var(--b); height: var(--h); background: var(--mark); border-radius: 4px 4px 0 0; transition: background-color 100ms ease; }
.chart .col.down::before { border-radius: 0 0 4px 4px; }
.chart .col.flag::before { background: var(--flag); }
.chart .col:hover::before, .chart .col:focus-visible::before { background: var(--cool); }

.rowchart { display: grid; gap: 0; }
.rowchart .row { display: grid; grid-template-columns: minmax(9em, 15em) minmax(0, 1fr) 4em; align-items: center; column-gap: var(--sp-3); min-height: 40px; }
.rowchart .lab { font-size: var(--step-small); }
.rowchart .val { text-align: right; font-weight: 650; }
.rowchart .track { position: relative; height: 40px; }
.rowchart .track::after { content: ""; position: absolute; top: 0; bottom: 0; left: var(--ref, -10px); width: 2px; background: var(--spot); }
.rowchart .axis { min-height: 32px; }
.rowchart .axis .track { height: 32px; }
.rowchart .axis .track::after { bottom: 60%; }
.rowchart .tick { position: absolute; left: var(--x); right: auto; bottom: auto; top: 50%; transform: translateX(-50%); }
.rowchart .reflab { position: absolute; left: var(--x); top: 45%; transform: translateX(-50%); white-space: nowrap; font-size: var(--step-caption); font-weight: 650; color: var(--ink); background: var(--paper); padding: 0 var(--sp-1); }
.dots .whisker { position: absolute; top: 50%; left: var(--l); right: calc(100% - var(--r)); height: 2px; transform: translateY(-50%); background: var(--muted); border-radius: 2px; }
.dots .dot { position: absolute; top: 50%; left: var(--x); width: 14px; height: 14px; transform: translate(-50%, -50%); border-radius: 50%; background: var(--mark); box-shadow: 0 0 0 2px var(--paper); }
.dots .dot::after { content: ""; position: absolute; inset: calc(-1 * var(--sp-2)); border-radius: 50%; }
.dots .dot:hover, .dots .dot:focus-visible { background: var(--cool); }
.dots .tick { top: 2px; }
.dots .axis, .dots .axis .track { min-height: 48px; height: 48px; }
.dots .reflab { top: 24px; color: var(--spot); }
.hbars .track::after { left: var(--z); background: var(--muted); width: 1.5px; }
.hbars.banded .track::before { content: ""; position: absolute; top: 0; bottom: 0; left: var(--bl); width: var(--bw); background: var(--band); }
.hbars .bar { position: absolute; top: 50%; height: 22px; transform: translateY(-50%); left: var(--l); width: var(--w); background: var(--mark); border-radius: 0 4px 4px 0; }
.hbars .bar.neg { border-radius: 4px 0 0 4px; }
.hbars .bar.flag { background: var(--flag); }
.hbars .bar:hover, .hbars .bar:focus-visible { background: var(--cool); }
.hbars .axis .track::after { display: none; }
.hbars .reflab { top: 4px; color: var(--muted); font-weight: 600; background: transparent; }
@media (max-width: 599px) {
  .rowchart .row { grid-template-columns: minmax(0, 1fr) 3.4em; row-gap: 0; }
  .rowchart .lab { grid-column: 1 / -1; padding-top: var(--sp-2); }
  .rowchart .track { grid-column: 1; height: 28px; }
  .rowchart .axis .lab { display: none; }
}

.legend .key { display: inline-block; width: 14px; height: 14px; vertical-align: -2px; margin: 0 var(--sp-2) 0 0; }
.legend .key:not(:first-child) { margin-left: var(--sp-4); }
.legend .key-band { background: var(--band); box-shadow: inset 0 0 0 1px var(--muted); }
.legend .key-flag { background: var(--spot); border-radius: 3px 3px 0 0; }
.legend .key-ref { height: 0; width: 20px; border-top: 2px dashed var(--spot); vertical-align: 4px; }
