/* ============================================================================
   base.css — reset, base typography, global states, shared components.
   Owner: frontend. Every value comes from assets/css/tokens.css.
   Load order: tokens → base → layout → sections → diagrams → quiz → motion
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. RESET
   -------------------------------------------------------------------------- */
*,
*::before,
*::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + var(--space-4));
}

body,
h1, h2, h3, h4, h5, h6,
p, figure, blockquote, dl, dd,
ol, ul { margin: 0; }

ol[class],
ul[class] {
  padding: 0;
  list-style: none;
}

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

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

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

textarea { resize: vertical; }

address {
  font-style: normal;
}

:where([hidden]) { display: none !important; }

/* --------------------------------------------------------------------------
   2. BASE TYPOGRAPHY — Fraunces display, Source Sans 3 prose, JetBrains mono
   -------------------------------------------------------------------------- */
body {
  background-color: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  font-weight: var(--fw-regular);
  line-height: var(--lh-body);
  letter-spacing: var(--ls-normal);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition:
    background-color var(--dur-base) var(--ease-standard),
    color var(--dur-base) var(--ease-standard);
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: var(--fw-display);
  color: var(--c-text);
  text-wrap: balance;
}

h1 {
  font-size: var(--fs-4xl);
  line-height: var(--lh-display);
  letter-spacing: var(--ls-display);
}

h2 {
  font-size: var(--fs-2xl);
  line-height: var(--lh-tight);
  letter-spacing: var(--ls-tight);
}

h3 {
  font-size: var(--fs-lg);
  line-height: var(--lh-snug);
  letter-spacing: var(--ls-tight);
}

p { text-wrap: pretty; }

::selection {
  background-color: var(--c-accent-wash-hi);
  color: var(--c-text);
}

/* --------------------------------------------------------------------------
   3. LINKS
   -------------------------------------------------------------------------- */
a {
  color: inherit;
  text-decoration: none;
}

.link {
  color: var(--c-accent-ink);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color var(--dur-fast) var(--ease-standard);
}

.link:hover { color: var(--c-text); }

.link--mono {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  letter-spacing: var(--ls-label);
}

/* --------------------------------------------------------------------------
   4. FOCUS — one composed ring, everywhere, never removed
   -------------------------------------------------------------------------- */
:focus-visible {
  outline: var(--focus-ring-w) solid var(--focus-ring-color);
  outline-offset: var(--focus-ring-off);
  box-shadow: var(--focus-ring-halo);
  border-radius: inherit;
}

/* Keyboard users only: UA default ring stays for browsers without :focus-visible */
:focus:not(:focus-visible) { outline: none; }

/* --------------------------------------------------------------------------
   5. UTILITIES
   -------------------------------------------------------------------------- */
.visually-hidden:not(:focus):not(:active) {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  inset-block-start: var(--space-2);
  inset-inline-start: var(--space-2);
  z-index: var(--z-toast);
  display: inline-flex;
  align-items: center;
  min-height: var(--tap-min);
  padding-inline: var(--space-5);
  border-radius: var(--r-md);
  background-color: var(--c-accent);
  color: var(--c-text-on-accent);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  letter-spacing: var(--ls-label);
  box-shadow: var(--shadow-2);
  transform: translateY(calc(-100% - var(--space-8)));
  transition: transform var(--dur-fast) var(--ease-out-quart);
}

.skip-link:focus { transform: translateY(0); }

/* Section eyebrow / numbering — mono, caps, tracked */
.eyebrow,
.section__num {
  font-family: var(--font-mono);
  font-size: var(--fs-eyebrow);
  font-weight: var(--fw-medium);
  letter-spacing: var(--ls-eyebrow);
  text-transform: uppercase;
  line-height: var(--lh-snug);
}

.eyebrow { color: var(--c-text-faint); }
.section__num { color: var(--c-accent); }

/* --------------------------------------------------------------------------
   6. BUTTONS
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control-h);
  padding-inline: var(--space-6);
  border: 0;
  border-radius: var(--r-md);
  font-family: var(--font-display);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-normal);
  line-height: var(--lh-snug);
  text-align: center;
  cursor: pointer;
  transition:
    transform var(--dur-fast) var(--ease-out-quart),
    background-color var(--dur-fast) var(--ease-standard),
    border-color var(--dur-fast) var(--ease-standard),
    box-shadow var(--dur-fast) var(--ease-out-quart),
    color var(--dur-fast) var(--ease-standard);
}

.btn--lg { min-height: var(--control-h-lg); }

.btn--primary {
  background-color: var(--c-accent);
  color: var(--c-text-on-accent);
  box-shadow: var(--shadow-1);
}

.btn--primary:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-2), var(--glow-accent-md);
}

.btn--ghost {
  background-color: transparent;
  color: var(--c-text);
  border: 1px solid var(--c-border-interactive);
}

.btn--ghost:hover {
  transform: translateY(-1px);
  border-color: var(--c-accent);
  background-color: var(--c-accent-wash);
}

.btn:active { transform: translateY(0) scale(0.985); }

.btn[disabled],
.btn[aria-disabled="true"] {
  background-color: var(--c-surface-raised);
  color: var(--c-text-faint);
  border-color: var(--c-border);
  box-shadow: none;
  transform: none;
  cursor: not-allowed;
}

/* Icon-only control — square, 44px, always labelled */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  inline-size: var(--control-h);
  block-size: var(--control-h);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  color: var(--c-text-muted);
  background-color: transparent;
  transition:
    color var(--dur-fast) var(--ease-standard),
    border-color var(--dur-fast) var(--ease-standard),
    background-color var(--dur-fast) var(--ease-standard);
}

.icon-btn:hover {
  color: var(--c-text);
  border-color: var(--c-border-interactive);
  background-color: var(--c-hover-wash);
}

/* Theme toggle: one glyph per theme, no colour-only signalling */
.icon-btn__icon--sun { display: none; }
[data-theme="light"] .icon-btn__icon--sun { display: block; }
[data-theme="light"] .icon-btn__icon--moon { display: none; }

/* --------------------------------------------------------------------------
   7. CARD (base for .service-card, .case-card, quiz items)
   -------------------------------------------------------------------------- */
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  block-size: 100%;
  padding: var(--space-6);
  border: 1px solid var(--c-border);
  border-radius: var(--r-card);
  background-color: var(--c-surface-raised);
  box-shadow: var(--shadow-1);
  transition:
    transform var(--dur-fast) var(--ease-out-quart),
    border-color var(--dur-fast) var(--ease-standard),
    box-shadow var(--dur-fast) var(--ease-out-quart);
}

/* --------------------------------------------------------------------------
   8. CHIP
   -------------------------------------------------------------------------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-block-size: 28px;
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--c-border);
  border-radius: var(--r-pill);
  background-color: var(--c-surface-raised);
  color: var(--c-text-muted);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: var(--ls-label);
  line-height: var(--lh-snug);
  transition:
    transform var(--dur-fast) var(--ease-spring),
    border-color var(--dur-fast) var(--ease-standard),
    background-color var(--dur-fast) var(--ease-standard);
}

.chip:hover {
  transform: translateY(-1px);
  border-color: var(--c-border-interactive);
  background-color: var(--c-hover-wash);
}

.chip--ok {
  background-color: var(--c-ok-wash);
  border-color: color-mix(in srgb, var(--c-ok) 40%, transparent);
  color: var(--c-text);
}

.chip--accent {
  background-color: var(--c-accent-wash);
  border-color: color-mix(in srgb, var(--c-accent) 40%, transparent);
  color: var(--c-text);
}

.chip__dot {
  inline-size: var(--space-2);
  block-size: var(--space-2);
  border-radius: var(--r-pill);
  background-color: var(--c-ok);
  box-shadow: var(--glow-ok);
  flex: none;
}

/* --------------------------------------------------------------------------
   9. METRIC — mono numeral + label, read as one phrase
   -------------------------------------------------------------------------- */
.metric {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.metric__value {
  font-family: var(--font-mono);
  font-size: var(--fs-xl);
  font-weight: var(--fw-medium);
  line-height: var(--lh-tight);
  letter-spacing: var(--ls-tight);
  color: var(--c-accent-ink);
  font-variant-numeric: tabular-nums;
}

.metric__label {
  font-family: var(--font-mono);
  font-size: var(--fs-eyebrow);
  font-weight: var(--fw-medium);
  letter-spacing: var(--ls-eyebrow);
  text-transform: uppercase;
  line-height: var(--lh-snug);
  color: var(--c-text-faint);
}

/* --------------------------------------------------------------------------
   10. FORM FIELD
   -------------------------------------------------------------------------- */
.field { display: block; }
.field + .field { margin-block-start: var(--space-5); }

.field__label {
  display: block;
  margin-block-end: var(--space-2);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--c-text);
}

.field__input {
  inline-size: 100%;
  min-block-size: var(--control-h);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--c-border-interactive);
  border-radius: var(--r-md);
  background-color: var(--c-surface);
  color: var(--c-text);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  transition:
    border-color var(--dur-fast) var(--ease-standard),
    background-color var(--dur-fast) var(--ease-standard);
}

.field__input--area {
  min-block-size: calc(var(--control-h-lg) * 2);
  padding-block: var(--space-3);
}

.field__input::placeholder { color: var(--c-text-faint); }
.field__input:hover { border-color: var(--c-text-faint); }
.field__input:focus-visible { border-color: var(--c-accent); }

.field__input[aria-invalid="true"] { border-color: var(--c-err); }

.field__hint,
.field__err {
  margin-block-start: var(--space-2);
  font-size: var(--fs-xs);
  line-height: var(--lh-snug);
}

.field__hint { color: var(--c-text-faint); }

.field__err {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--c-err-ink);
}

.field__err svg { flex: none; }

/* --------------------------------------------------------------------------
   11. SMALL SHARED TEXT BLOCKS
   -------------------------------------------------------------------------- */
.disclaimer,
.form-note {
  color: var(--c-text-faint);
  font-size: var(--fs-xs);
  line-height: var(--lh-snug);
  max-inline-size: var(--measure-narrow);
}

.entity {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  line-height: var(--lh-loose);
  letter-spacing: var(--ls-label);
  color: var(--c-text-faint);
}

/* --------------------------------------------------------------------------
   12. SCROLL REVEAL — hidden start state ships under `.js` ONLY.
   Without JavaScript the class is never added and every element stays visible.
   motion.css (loaded last) owns the transition and the revealed state.
   -------------------------------------------------------------------------- */
.js [data-reveal] {
  opacity: 0;
  transform: translateY(var(--reveal-y));
  will-change: opacity, transform;
}

/* --------------------------------------------------------------------------
   13. REDUCED MOTION — global guard.
   motion.js also skips observers, so the hidden start state must be undone
   here or revealed content would never appear.
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto !important; }

  .js [data-reveal] {
    opacity: 1;
    transform: none;
    will-change: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  /* A focus ring is not decoration — it must still appear. */
  :focus-visible {
    outline: var(--focus-ring-w) solid var(--focus-ring-color) !important;
    outline-offset: var(--focus-ring-off) !important;
  }
}
