/* ============================================================
   Kit v1 base: neutral reset and base styles on tokens only.
   Load after the brand theme (theme.css, from theme.template.css).
   No colour values here: every colour is a semantic token.
   ============================================================ */

/* ---- reset ---- */
*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-wrap: break-word;
}
body, h1, h2, h3, h4, h5, h6, p, figure, blockquote, dl, dd, ul, ol { margin: 0; }
ul[role="list"], ol[role="list"] { list-style: none; padding: 0; }
img, picture, video, svg, canvas { display: block; max-width: 100%; height: auto; }
input, button, textarea, select { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; }
table { border-collapse: collapse; }
[hidden] { display: none !important; }

/* ---- Chinese (both scripts): taller lines, wider spacing, no capitals,
   no negative spacing, CJK serif never below 400 (house-style 3 and 7).
   Applies to any element with a zh lang, so a zh block inside an en page
   gets the same rules. The CJK font family swap per script is in the theme. */
:lang(zh) {
  /* a brand may set --zh-fw-display / --zh-fw-heading in tokens.json "overrides" (heavy Chinese headings) */
  --fw-display: var(--zh-fw-display, 400); --fw-heading: var(--zh-fw-heading, 500);
  --lh-display: 1.3; --lh-h1: 1.35; --lh-heading: 1.4; --lh-h3: 1.5; --lh-h4: 1.5;
  --lh-lead: 1.8; --lh-body: 1.8; --lh-small: 1.7; --lh-label: 1.6;
  --ls-display: 0.04em; --ls-heading: 0.04em; --ls-body: 0.02em; --ls-label: 0.2em;
  --label-case: none;
  --display-scale: 0.85;
  line-break: strict;
}
:lang(zh) em, :lang(zh) i, :lang(zh) cite { font-style: normal; }
/* No 1-2 character last line in Chinese: headings share their lines evenly,
   paragraphs avoid a short last line (browsers without text-wrap ignore it). */
:is(h1, h2, h3, h4, .t-display, .t-h1, .t-h2, .t-h3, .t-h4):lang(zh) { text-wrap: balance; }
:is(p, li, .t-lead):lang(zh) { text-wrap: pretty; }

/* ---- page ---- */
html {
  background: var(--bg);
  color: var(--fg);
}
/* Re-resolve the text tokens wherever the language changes
   (:where keeps specificity at 0 so headings still win). */
html, :where([lang]) {
  font-family: var(--font-body);
  font-size: var(--fs-body);
  font-weight: var(--fw-body);
  line-height: var(--lh-body);
  letter-spacing: var(--ls-body);
}
body {
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
::selection { background: var(--accent); color: var(--bg); }

/* ---- bands (sections): background change marks a new section ---- */
.band {
  background: var(--bg);
  color: var(--fg);
  padding-block: var(--section-y);
}
.band--quiet { --bg: var(--surface-quiet); }
.band--raised { --bg: var(--surface); }
/* .band--dark is defined in the theme, where the dark map lives. */

/* ---- container and grid ---- */
.container {
  width: 100%;
  max-width: calc(var(--container) + 2 * var(--margin));
  margin-inline: auto;
  padding-inline: max(var(--margin), 16px);
}
.container--wide { max-width: calc(var(--container-wide) + 2 * var(--margin)); }
.measure { max-width: var(--measure); }

.grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  column-gap: var(--gutter);
  row-gap: var(--space-7);
}
@media (min-width: 640px) { .grid { grid-template-columns: repeat(8, minmax(0, 1fr)); } }
@media (min-width: 960px) { .grid { grid-template-columns: repeat(12, minmax(0, 1fr)); } }
@media (max-width: 639px) { :root { --gutter: 16px; } }

/* ---- type scale ---- */
.t-display, h1, h2, h3 {
  font-family: var(--font-display);
  color: var(--fg);
}
.t-display {
  font-size: calc(var(--fs-display) * var(--display-scale));
  font-weight: var(--fw-display);
  line-height: var(--lh-display);
  letter-spacing: var(--ls-display);
}
h1, .t-h1 {
  font-family: var(--font-display);
  font-size: var(--fs-h1);
  font-weight: var(--fw-display);
  line-height: var(--lh-h1);
  letter-spacing: var(--ls-display);
}
h2, .t-h2 {
  font-family: var(--font-display);
  font-size: var(--fs-h2);
  font-weight: var(--fw-heading);
  line-height: var(--lh-heading);
  letter-spacing: var(--ls-heading);
}
h3, .t-h3 {
  font-family: var(--font-display);
  font-size: var(--fs-h3);
  font-weight: var(--fw-heading);
  line-height: var(--lh-h3);
  letter-spacing: var(--ls-heading);
}
h4, .t-h4 {
  font-family: var(--font-body);
  font-size: var(--fs-h4);
  font-weight: var(--fw-ui);
  line-height: var(--lh-h4);
}
.t-lead {
  font-size: var(--fs-lead);
  line-height: var(--lh-lead);
  color: var(--fg-soft);
}
p { max-width: var(--measure); }
.t-soft { color: var(--fg-soft); }
.t-small {
  font-size: var(--fs-small);
  line-height: var(--lh-small);
  color: var(--fg-muted);
}
.t-label {
  font-size: var(--fs-label);
  font-weight: var(--fw-ui);
  line-height: var(--lh-label);
  letter-spacing: var(--ls-label);
  text-transform: var(--label-case);
  color: var(--accent);
}
.t-stat {
  font-family: var(--font-body);
  font-size: var(--fs-stat);
  font-weight: 300;
  line-height: var(--lh-stat);
  font-variant-numeric: tabular-nums;
}

/* ---- links ---- */
a {
  color: var(--accent);
  text-decoration-line: underline;
  text-decoration-thickness: var(--hairline);
  text-underline-offset: 4px;
  transition: color var(--t-fast) var(--ease);
}
a:hover { color: var(--fg); }

/* ---- focus: always visible, never removed ---- */
:focus-visible {
  outline: var(--focus-width) solid var(--accent);
  outline-offset: var(--focus-offset);
}

/* ---- buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control-h);
  min-width: var(--tap-min);
  padding: 0 var(--space-5);
  border: var(--hairline) solid var(--action);
  border-radius: var(--radius-pill);
  background: var(--action);
  color: var(--on-action);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  font-weight: var(--fw-ui);
  letter-spacing: 0;
  text-decoration: none;
  transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.btn:hover { background: var(--action-hover); border-color: var(--action-hover); color: var(--on-action); }
.btn--quiet {
  background: transparent;
  border-color: var(--rule-strong);
  color: var(--fg);
}
.btn--quiet:hover { background: var(--action); border-color: var(--action); color: var(--on-action); }

/* ---- form fields: underline only, label always visible ---- */
.field { display: grid; gap: var(--space-2); }
.field__label {
  font-size: var(--fs-small);
  line-height: var(--lh-small);
  color: var(--fg-soft);
}
.field__input {
  width: 100%;
  min-height: var(--control-h);
  padding: var(--space-2) 0;
  border: 0;
  border-bottom: var(--hairline) solid var(--rule-strong);
  border-radius: 0;
  background: transparent;
  color: var(--fg);
  font-size: 1rem; /* 16px stops phone zoom */
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
textarea.field__input { min-height: calc(var(--control-h) * 3); resize: vertical; }
.field__input::placeholder { color: var(--fg-muted); opacity: 1; }
.field__input:focus { border-bottom-color: var(--accent); box-shadow: 0 1px 0 0 var(--accent); }
.field__input[aria-invalid="true"] { border-bottom-color: var(--danger); }
.field__error {
  font-size: var(--fs-small);
  line-height: var(--lh-small);
  color: var(--danger);
}

/* ---- reduced motion: durations to zero (motion kit reads the same tokens) ---- */
@media (prefers-reduced-motion: reduce) {
  :root, .band--dark {
    --t-fast: 0ms;
    --t-reveal: 0ms;
    --reveal-shift: 0px;
  }
  html { scroll-behavior: auto; }
}
