/* ==========================================================================
   BASE — Reset, typography, global elements
   ========================================================================== */

/* ── Font face: Inter Variable ───────────────────────────────────────────── */
@font-face {
  font-family: 'Inter var';
  font-weight: 100 900;
  font-display: swap;
  font-style: normal;
  src: url('../fonts/inter-var.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
                 U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122,
                 U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ── Font face: JetBrains Mono ───────────────────────────────────────────── */
@font-face {
  font-family: 'JetBrains Mono';
  font-weight: 400 700;
  font-display: swap;
  font-style: normal;
  src: url('../fonts/jetbrains-mono.woff2') format('woff2');
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  font-size: 16px;
}

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

body {
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: var(--line-body);
  color: var(--color-text);
  background-color: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  transition: background-color var(--duration-normal) var(--ease-out),
              color var(--duration-normal) var(--ease-out);
}

/* ── Headings ─────────────────────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  line-height: var(--line-tight);
  color: var(--color-text);
  font-weight: 700;
  letter-spacing: -0.02em;
}

h1 { font-size: var(--text-h1); }
h2 { font-size: var(--text-h2); }
h3 { font-size: var(--text-h3); }
h4 { font-size: 1.125rem; font-weight: 600; }
h5 { font-size: 1rem;     font-weight: 600; }
h6 { font-size: 0.875rem; font-weight: 600; }

/* ── Body copy ────────────────────────────────────────────────────────────── */
p {
  margin-bottom: var(--space-4);
  max-width: var(--prose-width);
}

p:last-child { margin-bottom: 0; }

/* ── Links ────────────────────────────────────────────────────────────────── */
a {
  color: var(--color-primary);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  transition: color var(--duration-fast) var(--ease-out),
              text-decoration-color var(--duration-fast) var(--ease-out);
}

a:hover {
  color: var(--color-primary-600);
}

a:focus-visible {
  outline: none;
  border-radius: 4px;
  box-shadow: var(--shadow-focus);
}

/* ── Lists ────────────────────────────────────────────────────────────────── */
ul, ol {
  padding-left: var(--space-6);
}

li { margin-bottom: var(--space-1); }

/* ── Inline elements ─────────────────────────────────────────────────────── */
strong, b { font-weight: 700; }
em, i     { font-style: italic; }

small {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

abbr[title] {
  text-decoration: underline dotted;
  cursor: help;
}

mark {
  background-color: rgb(79 70 229 / .15);
  color: var(--color-text);
  padding: 0 3px;
  border-radius: 3px;
}

/* ── Code ─────────────────────────────────────────────────────────────────── */
code, kbd, samp, pre {
  font-family: var(--font-mono);
  font-size: 0.875em;
}

code:not(pre code) {
  background: var(--color-surface-2);
  color: var(--color-primary);
  padding: 0.1em 0.4em;
  border-radius: 5px;
  border: 1px solid var(--color-border);
}

pre {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-input);
  padding: var(--space-4);
  overflow-x: auto;
  tab-size: 2;
}

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

/* ── Media ────────────────────────────────────────────────────────────────── */
img, svg, video, canvas, audio, iframe, embed, object {
  display: block;
  max-width: 100%;
}

img { height: auto; }

/* ── Tables ───────────────────────────────────────────────────────────────── */
table {
  border-collapse: collapse;
  width: 100%;
  font-size: var(--text-sm);
}

th, td {
  padding: var(--space-2) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

th {
  font-weight: 600;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

tr:last-child td { border-bottom: none; }

/* ── Forms (base resets only) ─────────────────────────────────────────────── */
button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

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

button:disabled { cursor: not-allowed; }

input, textarea, select {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-input);
  background: var(--color-bg);
  color: var(--color-text);
  outline: none;
  transition: border-color var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out);
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-focus);
}

input::placeholder,
textarea::placeholder {
  color: var(--color-text-muted);
  opacity: 0.7;
}

fieldset {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-input);
  padding: var(--space-4);
}

legend {
  font-weight: 600;
  font-size: var(--text-sm);
  padding: 0 var(--space-2);
}

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

/* ── Blockquote ──────────────────────────────────────────────────────────── */
blockquote {
  border-left: 4px solid var(--color-primary);
  padding-left: var(--space-4);
  color: var(--color-text-muted);
  font-style: italic;
  margin: var(--space-6) 0;
}

/* ── Selection ────────────────────────────────────────────────────────────── */
::selection {
  background: rgb(79 70 229 / .2);
  color: var(--color-text);
}

[data-theme="dark"] ::selection {
  background: rgb(129 140 248 / .3);
}

/* ── Scrollbar styling (webkit) ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--color-surface); }
::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-pill);
  border: 2px solid var(--color-surface);
}
::-webkit-scrollbar-thumb:hover { background: var(--color-text-muted); }

/* ── Focus visible global ─────────────────────────────────────────────────── */
:focus { outline: none; }

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ── Screen-reader only ───────────────────────────────────────────────────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border-width: 0;
}

/* ── Skip link ────────────────────────────────────────────────────────────── */
.skip-link {
  position: fixed;
  top: var(--space-4);
  left: var(--space-4);
  z-index: var(--z-toast);
  padding: var(--space-2) var(--space-4);
  background: var(--color-primary);
  color: var(--color-primary-fg);
  border-radius: var(--radius-btn);
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-120%);
  transition: transform var(--duration-normal) var(--ease-out);
}

.skip-link:focus {
  transform: translateY(0);
  outline: none;
  box-shadow: var(--shadow-focus);
}

/* ── Utility: visually hidden but present ─────────────────────────────────── */
[hidden] { display: none !important; }

/* ── Prose content wrapper ────────────────────────────────────────────────── */
.prose {
  max-width: var(--prose-width);
}

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

.prose h2 { margin-top: var(--space-8); }
.prose h3 { margin-top: var(--space-6); }
.prose ul, .prose ol { margin-top: var(--space-4); }
