/* ============================================================
   Base: reset, typography, layout utilities, grain overlay
   ============================================================ */

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

html {
  overflow-x: clip;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  overflow-x: clip;
  min-height: 100vh;
  min-height: 100svh;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter Var", "Inter Fallback", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: var(--text-md);
  line-height: 1.6;
  font-synthesis-weight: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--dur-2) ease, color var(--dur-2) ease;
}

/* CJK / Thai / Devanagari read better without negative tracking. */
:lang(zh) body, :lang(ja) body, :lang(th) body, :lang(hi) body,
:lang(zh), :lang(ja), :lang(th), :lang(hi) {
  letter-spacing: 0 !important;
}
:lang(zh) .display, :lang(ja) .display, :lang(th) .display, :lang(hi) .display {
  letter-spacing: 0;
  line-height: 1.25;
}

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

a {
  color: inherit;
  text-decoration: none;
}

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

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

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

::selection {
  background: rgb(43 146 222 / 0.28);
}

h1, h2, h3, h4 {
  line-height: 1.15;
  font-weight: 650;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

p {
  text-wrap: pretty;
}

/* ---------- Typography helpers ---------- */

.display {
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.02;
}

.display-xl { font-size: var(--display-xl); }
.display-lg { font-size: var(--display-lg); }
.display-md { font-size: var(--display-md); letter-spacing: -0.02em; line-height: 1.1; }

.lede {
  font-size: var(--text-xl);
  line-height: 1.55;
  color: var(--text-muted);
  max-width: 40em;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--accent);
}

.eyebrow::before {
  content: "";
  width: 1.5rem;
  height: 2px;
  border-radius: 1px;
  background: var(--gradient-brand);
}

.gradient-text {
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.muted { color: var(--text-muted); }

/* ---------- Layout ---------- */

.container {
  width: 100%;
  max-width: var(--container-main);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.container--wide { max-width: var(--container-wide); }
.container--text { max-width: var(--container-text); }

.section {
  position: relative;
  padding-block: var(--section-pad);
  scroll-margin-top: calc(var(--header-h) + 1.5rem);
}

[id] { scroll-margin-top: calc(var(--header-h) + 1.5rem); }

.section-head {
  max-width: 50rem;
  margin-bottom: clamp(2.5rem, 6vh, 4.5rem);
  display: grid;
  gap: var(--space-4);
}

/* Gradient hairline divider */
.hairline {
  height: 1px;
  border: none;
  background: linear-gradient(90deg, transparent, rgb(43 146 222 / 0.35), rgb(13 176 142 / 0.35), transparent);
}

/* ---------- Grain overlay (single fixed layer) ---------- */

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: var(--z-noise);
  pointer-events: none;
  opacity: var(--noise-opacity);
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 160px 160px;
}

/* ---------- Legal prose pages ---------- */

.prose h1 { margin-bottom: var(--space-2); }
.prose > .muted { font-size: var(--text-sm); }
.prose .prose-note {
  font-size: var(--text-xs);
  border-left: 2px solid var(--border-strong);
  padding-left: var(--space-3);
  margin-top: var(--space-2);
}
.prose section { margin-top: var(--space-7); }
.prose section h2 { font-size: var(--text-lg); margin-bottom: var(--space-3); }
.prose p, .prose li { color: var(--text-muted); font-size: var(--text-sm); line-height: 1.7; }
.prose ul { padding-left: 1.2rem; margin-top: var(--space-3); display: grid; gap: 0.4rem; }
.prose a { color: var(--accent); font-weight: 600; }
.prose a:hover { text-decoration: underline; }

.prose-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-4); }

.table-wrap { overflow-x: auto; margin-top: var(--space-4); }
.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.table-wrap th, .table-wrap td {
  text-align: left;
  padding: 0.55rem 0.8rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  white-space: nowrap;
}
.table-wrap td:nth-child(2) { white-space: normal; }
.table-wrap th {
  color: var(--text);
  font-weight: 650;
  border-bottom: 1px solid var(--border-strong);
}

/* ---------- Accessibility ---------- */

.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  z-index: calc(var(--z-overlay) + 1);
  padding: 0.6rem 1rem;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  font-weight: 600;
}

.skip-link:focus-visible {
  top: 0.75rem;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Honeypot — off-screen but not display:none (bots skip those). */
.hp-field {
  position: absolute !important;
  left: -9999px;
  top: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}
