/* ==========================================================================
   base.css — Kai-Signals: normalize, document base, typography foundation
   Loaded after tokens.css / light.css / dark.css.
   ========================================================================== */

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

/* Ensure [hidden] always wins over component display values */
[hidden] { display: none !important; }

/* ── Document ────────────────────────────────────────────────────────────── */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  hanging-punctuation: first last;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

body {
  font-family: var(--font-body);
  font-size: var(--text-body-md-size);
  line-height: var(--text-body-md-line);
  font-weight: var(--text-body-md-weight);
  color: var(--text-primary);
  background-color: var(--surface-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── Headings ────────────────────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-primary);
  text-wrap: balance;
}

h1 { font-size: var(--text-display-md-size); line-height: var(--text-display-md-line); font-weight: var(--text-display-md-weight); }
h2 { font-size: var(--text-display-sm-size); line-height: var(--text-display-sm-line); font-weight: var(--text-display-sm-weight); }
h3 { font-size: var(--text-heading-lg-size); line-height: var(--text-heading-lg-line); font-weight: var(--text-heading-lg-weight); font-family: var(--font-body); }
h4 { font-size: var(--text-heading-md-size); line-height: var(--text-heading-md-line); font-weight: var(--text-heading-md-weight); font-family: var(--font-body); }
h5, h6 { font-size: var(--text-body-lg-size); line-height: var(--text-body-lg-line); font-weight: 600; font-family: var(--font-body); }

/* ── Paragraphs ──────────────────────────────────────────────────────────── */
p {
  font-size: var(--text-body-md-size);
  line-height: var(--text-body-md-line);
  color: var(--text-secondary);
  text-wrap: pretty;
}

p + p { margin-top: var(--space-4); }

/* ── Links ───────────────────────────────────────────────────────────────── */
a {
  color: var(--text-link);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color var(--duration-fast) var(--easing-default);
}

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

a:not([class]) {
  text-decoration-skip-ink: auto;
}

/* ── Focus visible — accessible focus ring ───────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--color-brand-teal);
  outline-offset: 3px;
  border-radius: 3px;
}

/* Remove focus ring for mouse/touch users (progressive) */
:focus:not(:focus-visible) {
  outline: none;
}

/* ── Selection ───────────────────────────────────────────────────────────── */
::selection {
  background-color: var(--color-brand-teal-muted);
  color: var(--color-brand-teal-strong);
}

/* ── Images & media ──────────────────────────────────────────────────────── */
img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

img { height: auto; }

/* ── Lists ───────────────────────────────────────────────────────────────── */
ul, ol {
  list-style: none;
}

/* Prose lists (inside .legal-page, .faq — apply styles via cascade) */
.prose ul, .prose ol,
.legal-page__body ul, .legal-page__body ol,
.risk-disclosure__body ul, .risk-disclosure__body ol,
.methodology__content ul, .methodology__content ol {
  list-style: disc;
  padding-left: var(--space-6);
}

.prose ol, .legal-page__body ol, .risk-disclosure__body ol, .methodology__content ol {
  list-style: decimal;
}

.prose li, .legal-page__body li, .risk-disclosure__body li, .methodology__content li {
  font-size: var(--text-body-md-size);
  line-height: var(--text-body-md-line);
  color: var(--text-secondary);
  margin-top: var(--space-2);
}

/* ── Tables ──────────────────────────────────────────────────────────────── */
table { border-collapse: collapse; width: 100%; }
th, td {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--surface-border);
  font-size: var(--text-body-sm-size);
  line-height: var(--text-body-sm-line);
}
th {
  font-weight: 600;
  color: var(--text-primary);
  background-color: var(--surface-raised);
}
td { color: var(--text-secondary); }
tr:last-child td { border-bottom: none; }
tr:hover td { background-color: var(--surface-raised); }

/* ── Code / pre ──────────────────────────────────────────────────────────── */
code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background-color: var(--surface-raised);
  border: 1px solid var(--surface-border);
  border-radius: 4px;
  padding: 0.1em 0.4em;
  color: var(--text-primary);
}

pre {
  font-family: var(--font-mono);
  font-size: var(--text-mono-sm-size);
  background-color: var(--surface-raised);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-card);
  padding: var(--space-4);
  overflow-x: auto;
  color: var(--text-primary);
}

pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
}

/* ── Horizontal rule ─────────────────────────────────────────────────────── */
hr {
  border: none;
  border-top: 1px solid var(--surface-border);
  margin: var(--space-8) 0;
}

/* ── Blockquote ──────────────────────────────────────────────────────────── */
blockquote {
  border-left: 3px solid var(--color-brand-teal);
  padding-left: var(--space-5);
  margin: var(--space-6) 0;
  color: var(--text-secondary);
  font-style: italic;
}

/* ── Form base ───────────────────────────────────────────────────────────── */
input, textarea, select {
  font-family: var(--font-body);
  font-size: var(--text-body-md-size);
  color: var(--input-text);
  background-color: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-input);
  padding: var(--space-3) var(--space-4);
  width: 100%;
  appearance: none;
  transition: border-color var(--duration-fast) var(--easing-default),
              box-shadow var(--duration-fast) var(--easing-default);
}

input::placeholder, textarea::placeholder {
  color: var(--input-placeholder);
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--input-border-focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-brand-teal) 20%, transparent);
}

label {
  font-family: var(--font-body);
  font-size: var(--text-label-size);
  font-weight: var(--text-label-weight);
  line-height: var(--text-label-line);
  color: var(--text-primary);
  display: block;
  margin-bottom: var(--space-2);
}

/* ── Utility — typography shorthand ─────────────────────────────────────── */
.body-lg    { font-family: var(--font-body); font-size: var(--text-body-lg-size);    line-height: var(--text-body-lg-line);    font-weight: var(--text-body-lg-weight); }
.body-md    { font-family: var(--font-body); font-size: var(--text-body-md-size);    line-height: var(--text-body-md-line);    font-weight: var(--text-body-md-weight); }
.body-sm    { font-family: var(--font-body); font-size: var(--text-body-sm-size);    line-height: var(--text-body-sm-line);    font-weight: var(--text-body-sm-weight); }
.heading-lg { font-family: var(--font-body); font-size: var(--text-heading-lg-size); line-height: var(--text-heading-lg-line); font-weight: var(--text-heading-lg-weight); }
.heading-md { font-family: var(--font-body); font-size: var(--text-heading-md-size); line-height: var(--text-heading-md-line); font-weight: var(--text-heading-md-weight); }
.label      { font-family: var(--font-body); font-size: var(--text-label-size);      line-height: var(--text-label-line);      font-weight: var(--text-label-weight); }
.mono-md    { font-family: var(--font-mono); font-size: var(--text-mono-md-size);    line-height: var(--text-mono-md-line);    font-weight: var(--text-mono-md-weight); }
.mono-sm    { font-family: var(--font-mono); font-size: var(--text-mono-sm-size);    line-height: var(--text-mono-sm-line);    font-weight: var(--text-mono-sm-weight); }

/* ── Utility — accessibility ─────────────────────────────────────────────── */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Utility — semantic colour ───────────────────────────────────────────── */
.text-brand   { color: var(--text-brand); }
.text-muted   { color: var(--text-secondary); }
.text-danger  { color: var(--color-danger); font-size: var(--text-body-sm-size); }
.text-success { color: var(--color-success); }
