/* ==========================================================================
   base.css
   Reset, default element styles, section surfaces and shared utilities.
   Every value comes from tokens.css.
   ========================================================================== */

/* ---------- Reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

/* Smooth scrolling for in-page links, only when motion is welcome */
@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

ul,
ol {
  list-style: none;
}

img,
video,
svg {
  display: block;
  max-width: 100%;
}

img,
video {
  height: auto;
}

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

/* ---------- Body ---------- */
body {
  background-color: var(--surface-0);
  color: var(--ink-primary);
  font-family: var(--font-body);
  font-size: var(--text-body);
  line-height: var(--leading-body);
  letter-spacing: var(--tracking-body);
  font-weight: var(--weight-regular);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

p {
  text-align: left; /* paragraphs are never centred */
}

/* ---------- Headings ----------
   Display and h1 are bold. h2 to h4 are semibold.
   Nothing is smaller than h4: h5 and h6 fall back to h4 size. */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-display);
  color: var(--ink-primary);
  text-wrap: balance;
}

h1 {
  font-size: var(--text-h1);
  line-height: var(--leading-h1);
  letter-spacing: var(--tracking-h1);
  font-weight: var(--weight-bold);
}

h2 {
  font-size: var(--text-h2);
  line-height: var(--leading-h2);
  letter-spacing: var(--tracking-h2);
  font-weight: var(--weight-semibold);
}

h3 {
  font-size: var(--text-h3);
  line-height: var(--leading-h3);
  letter-spacing: var(--tracking-h3);
  font-weight: var(--weight-semibold);
}

h4,
h5,
h6 {
  font-size: var(--text-h4);
  line-height: var(--leading-h4);
  letter-spacing: var(--tracking-h4);
  font-weight: var(--weight-semibold);
}

/* Type classes, so a heading's level (for structure) and its size (for looks) can differ */
.t-display {
  font-size: var(--text-display);
  line-height: var(--leading-display);
  letter-spacing: var(--tracking-display);
  font-weight: var(--weight-display);
}

.t-h1 {
  font-size: var(--text-h1);
  line-height: var(--leading-h1);
  letter-spacing: var(--tracking-h1);
  font-weight: var(--weight-bold);
}

.t-h2 {
  font-size: var(--text-h2);
  line-height: var(--leading-h2);
  letter-spacing: var(--tracking-h2);
  font-weight: var(--weight-semibold);
}

.t-h3 {
  font-size: var(--text-h3);
  line-height: var(--leading-h3);
  letter-spacing: var(--tracking-h3);
  font-weight: var(--weight-semibold);
}

.t-h4 {
  font-size: var(--text-h4);
  line-height: var(--leading-h4);
  letter-spacing: var(--tracking-h4);
  font-weight: var(--weight-semibold);
}

.t-body-lg {
  font-size: var(--text-body-lg);
  line-height: var(--leading-body-lg);
  letter-spacing: var(--tracking-body-lg);
}

.t-body {
  font-size: var(--text-body);
  line-height: var(--leading-body);
  letter-spacing: var(--tracking-body);
}

.t-caption {
  font-size: var(--text-caption);
  line-height: var(--leading-caption);
  letter-spacing: var(--tracking-caption);
}

/* Uppercase label: status, metadata, spec grid labels. Not a heading. */
.label {
  font-size: var(--text-micro);
  line-height: var(--leading-micro);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--ink-tertiary);
}

.ink-secondary {
  color: var(--ink-secondary);
}

.measure {
  max-width: var(--measure);
}

/* Figures line up in columns */
.numeric {
  font-feature-settings: "tnum";
}

/* ---------- Links ---------- */
a {
  color: var(--accent-current);
  text-decoration: underline;
  text-underline-offset: 0.2em;
  text-decoration-thickness: var(--border-thin);
}

/* Text link with a trailing arrow, e.g. "Try it →" */
.link-arrow {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--accent-current);
  text-decoration: none;
  font-weight: var(--weight-semibold);
}

.link-arrow::after {
  content: "→";
}

.link-arrow--back::after {
  content: none;
}

.link-arrow--back::before {
  content: "←";
}

.link-arrow:hover {
  text-decoration: underline;
}

/* ---------- Buttons ----------
   Every button is a pill. */
button {
  background: none;
  border: none;
  cursor: pointer;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--button-padding-y) var(--button-padding-x);
  border-radius: var(--radius-pill);
  font-size: var(--text-body);
  line-height: var(--leading-body);
  letter-spacing: var(--tracking-body);
  font-weight: var(--weight-semibold);
  text-decoration: none;
  cursor: pointer;
}

.btn--primary {
  background-color: var(--accent-current);
  color: var(--surface-0);
  border: var(--border-thin) solid var(--accent-current);
}

.btn--primary:hover {
  background-color: var(--ink-primary);
  border-color: var(--ink-primary);
}

.btn--ghost {
  background-color: transparent;
  color: var(--ink-primary);
  border: var(--border-thin) solid var(--ink-primary);
}

.btn--ghost:hover {
  background-color: var(--ink-primary);
  color: var(--surface-0);
}

/* Round icon button, e.g. gallery arrows, video toggle */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--icon-button-size);
  height: var(--icon-button-size);
  border-radius: var(--radius-pill);
  background-color: var(--surface-hover);
  color: var(--ink-primary);
}

.btn-icon:hover {
  background-color: var(--hairline);
}

.btn-icon:disabled {
  opacity: 0;
  pointer-events: none;
}

.btn-icon svg {
  width: var(--icon-sm);
  height: var(--icon-sm);
}

@media (prefers-reduced-motion: no-preference) {
  .btn,
  .btn-icon,
  .link-arrow {
    transition:
      background-color var(--transition-fast) var(--ease-out),
      color var(--transition-fast) var(--ease-out),
      border-color var(--transition-fast) var(--ease-out),
      opacity var(--transition-mid) var(--ease-out);
  }
}

/* ---------- Tags ----------
   Pill, accent text, accent border at 30%. */
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.tag {
  display: inline-block;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  border: var(--border-thin) solid color-mix(in srgb, var(--accent-current) var(--tag-border-mix), transparent);
  color: var(--accent-current);
  font-size: var(--text-micro);
  line-height: var(--leading-micro);
  letter-spacing: var(--tracking-micro);
}

/* ---------- Accent switches ----------
   Put one of these on a card, section or <body> to colour-code it. */
.accent-en { --accent-current: var(--accent-en); }
.accent-ta { --accent-current: var(--accent-ta); }
.accent-hi { --accent-current: var(--accent-hi); }
.accent-kn { --accent-current: var(--accent-kn); }

/* ---------- Focus ring for keyboard users ---------- */
:focus-visible {
  outline: var(--focus-ring-width) solid var(--accent-current);
  outline-offset: var(--focus-ring-offset);
}

:focus:not(:focus-visible) {
  outline: none;
}

/* ---------- Layout ---------- */
.container {
  width: 100%;
  max-width: calc(var(--max-width) + (var(--gutter) * 2));
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* ---------- Sections ----------
   Default section is --surface-0. Swap ONE class to change its surface:
   .section--band    = --surface-1 (dark band)
   .section--inverse = --surface-inverse (light band) */
.section {
  background-color: var(--surface-0);
  padding-block: var(--section-gap);
  scroll-margin-top: var(--header-height);
}

/* Two sections on the same surface in a row share one gap, not two */
.section:not(.section--band, .section--inverse) + .section:not(.section--band, .section--inverse),
.section--band + .section--band,
.section--inverse + .section--inverse {
  padding-top: 0;
}

.section--band {
  background-color: var(--surface-1);
}

/* The light band. Re-points the ink and line tokens so everything inside
   (headings, body, labels, tags, buttons) recolours automatically. */
.section--inverse {
  background-color: var(--surface-inverse);
  color: var(--ink-inverse-primary);
  --ink-primary: var(--ink-inverse-primary);
  --ink-secondary: var(--ink-inverse-secondary);
  --ink-tertiary: var(--ink-inverse-secondary);
  --hairline: var(--hairline-inverse);
  --surface-hover: var(--hairline-inverse);
  --placeholder-fill: var(--placeholder-fill-inverse);
}

/* Primary button text stays dark and flips to light on hover inside the light band */
.section--inverse .btn--primary:hover {
  background-color: var(--ink-inverse-primary);
  border-color: var(--ink-inverse-primary);
  color: var(--surface-inverse);
}

.section--inverse .btn--ghost:hover {
  color: var(--surface-inverse);
}

.section__header {
  margin-bottom: var(--space-8);
}

.section__header > * + * {
  margin-top: var(--space-4);
}

/* ---------- Placeholder image rectangles (v1 only) ----------
   A grey box standing in for an image. Replace with <img> later. */
.ph {
  display: block;
  width: 100%;
  background-color: var(--placeholder-fill);
  border-radius: var(--radius-lg);
}

.ph--16x9 { aspect-ratio: 16 / 9; }
.ph--16x10 { aspect-ratio: 16 / 10; }
.ph--4x3 { aspect-ratio: 4 / 3; }

/* Caption under a figure */
figcaption {
  margin-top: var(--space-3);
  color: var(--ink-secondary);
  font-size: var(--text-caption);
  line-height: var(--leading-caption);
  letter-spacing: var(--tracking-caption);
}

/* ---------- Accessibility helpers ---------- */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 100;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  background-color: var(--surface-inverse);
  color: var(--ink-inverse-primary);
  text-decoration: none;
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: none;
}

/* ---------- Scroll reveal ----------
   Only hides content when JS is running and motion is welcome.
   Without JS or with reduced motion, everything is simply visible. */
@media (prefers-reduced-motion: no-preference) {
  .js [data-reveal] {
    opacity: 0;
    transform: translateY(var(--reveal-distance));
    transition:
      opacity var(--transition-slow) var(--ease-out),
      transform var(--transition-slow) var(--ease-out);
  }

  .js [data-reveal].is-revealed {
    opacity: 1;
    transform: none;
  }
}
