/* ==========================================================================
   UPIQAL · Design Tokens
   Single source of truth for palette, type, spacing, radius, motion, elevation.
   Works with both the analyzer (index.html) and the paper (paper.html).
   ========================================================================== */

:root {
  color-scheme: dark light;

  /* -- Palette: muted historical / earthy tones (accent used sparingly) -----
     Faded Brick      #7A3731 — primary accent, used sparingly
     Weathered Timber #3E3129 — dark raised surfaces, dividers
     Cold Concrete    #8C9295 — muted text, secondary structural lines
     Oxidized Iron    #5E3A23 — secondary accent
     Barren Earth     #635B4C — neutral drab fill                            */
  --surface-0: #1a1612;   /* page background — near-black with warm undertone */
  --surface-1: #221c17;   /* card / panel */
  --surface-2: #2d261f;   /* nested surface / input */
  --surface-3: #3E3129;   /* hover / selected — Weathered Timber */
  --hairline:  #322a23;
  --hairline-strong: #4a3d33;

  --text-0: #ede6d9;      /* warm near-white primary */
  --text-1: #b8b0a3;      /* secondary */
  --text-2: #8C9295;      /* muted — Cold Concrete */
  --text-3: #635B4C;      /* disabled / faint — Barren Earth */

  --accent:       #7A3731;   /* Faded Brick */
  --accent-hot:   #5E3A23;   /* Oxidized Iron */
  --accent-soft:  rgba(122, 55, 49, 0.14);
  --accent-ring:  rgba(122, 55, 49, 0.35);
  --accent-contrast: #f7f2e8;

  --success: #7f8f5e;
  --warning: #b08953;
  --danger:  #7A3731;

  /* Subdued two-stop gradient. Restrained on purpose. */
  --gradient-brand: linear-gradient(135deg, #7A3731 0%, #5E3A23 100%);
  --gradient-fade:  linear-gradient(180deg, rgba(122,55,49,0.06) 0%, rgba(122,55,49,0) 100%);

  /* -- Typography --------------------------------------------------------- */
  --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --font-serif: 'Newsreader', 'Source Serif Pro', Georgia, serif;

  --text-xs:   0.75rem;   /* 12 */
  --text-sm:   0.875rem;  /* 14 */
  --text-base: 1rem;      /* 16 */
  --text-md:   1.0625rem; /* 17 */
  --text-lg:   1.25rem;   /* 20 */
  --text-xl:   1.5rem;    /* 24 */
  --text-2xl:  2rem;      /* 32 */
  --text-3xl:  2.75rem;   /* 44 */
  --text-4xl:  3.75rem;   /* 60 */
  --text-5xl:  4.5rem;    /* 72 */

  --leading-tight: 1.15;
  --leading-snug:  1.35;
  --leading-body:  1.6;
  --leading-prose: 1.75;

  /* -- Spacing scale ------------------------------------------------------ */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-7: 32px; --sp-8: 40px;
  --sp-9: 56px; --sp-10: 72px; --sp-11: 96px; --sp-12: 128px;

  /* -- Radius ------------------------------------------------------------- */
  --r-sm:  6px;
  --r-md:  10px;
  --r-lg:  14px;
  --r-xl:  20px;
  --r-2xl: 28px;
  --r-full: 9999px;

  /* -- Elevation ---------------------------------------------------------- */
  --elev-1: 0 1px 2px rgba(0,0,0,0.25), 0 2px 6px rgba(0,0,0,0.18);
  --elev-2: 0 4px 12px rgba(0,0,0,0.30), 0 10px 30px rgba(0,0,0,0.22);
  --elev-3: 0 12px 40px rgba(0,0,0,0.40), 0 30px 80px rgba(0,0,0,0.28);
  --elev-glow: 0 0 0 1px var(--accent-ring), 0 8px 30px rgba(122,55,49,0.25);

  /* -- Motion ------------------------------------------------------------- */
  --dur-fast: 140ms;
  --dur-med:  260ms;
  --dur-slow: 420ms;
  --ease-out-expo:   cubic-bezier(0.19, 1, 0.22, 1);
  --ease-out-quint:  cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring:     cubic-bezier(0.34, 1.56, 0.64, 1);

  /* -- Layout ------------------------------------------------------------- */
  --content-max: 1200px;
  --prose-max: 72ch;
  --nav-h: 64px;
}

/* Light-mode override — parchment-neutral variant of the same palette. */
html[data-theme="light"] {
  --surface-0: #f3efe8;
  --surface-1: #ffffff;
  --surface-2: #ebe5d8;
  --surface-3: #d9d2c2;
  --hairline:  #c8c0b3;
  --hairline-strong: #aaa194;
  --text-0: #1a1612;
  --text-1: #3E3129;      /* Weathered Timber */
  --text-2: #635B4C;      /* Barren Earth */
  --text-3: #8C9295;      /* Cold Concrete */
  --accent-soft: rgba(122, 55, 49, 0.08);
  --gradient-fade: linear-gradient(180deg, rgba(122,55,49,0.05) 0%, rgba(122,55,49,0) 100%);
  --elev-1: 0 1px 2px rgba(62,49,41,0.05), 0 2px 6px rgba(62,49,41,0.04);
  --elev-2: 0 4px 12px rgba(62,49,41,0.06), 0 10px 30px rgba(62,49,41,0.06);
  --elev-3: 0 12px 40px rgba(62,49,41,0.08), 0 30px 80px rgba(62,49,41,0.08);
  color-scheme: light;
}

/* ==========================================================================
   Base reset + body
   ========================================================================== */

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

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

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  color: var(--text-0);
  background: var(--surface-0);
  letter-spacing: -0.011em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Gradient wash behind the hero, subtle */
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto 0;
  height: 60vh;
  background: var(--gradient-fade);
  pointer-events: none;
  z-index: 0;
}

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

a { color: inherit; text-decoration: none; }
a:focus-visible, button:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

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

/* Balanced text wrap on headings & tighter leading */
h1, h2, h3, h4 {
  font-weight: 700;
  line-height: var(--leading-tight);
  letter-spacing: -0.02em;
  text-wrap: balance;
}

/* Code */
code, kbd, pre { font-family: var(--font-mono); }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ==========================================================================
   Shared utility components
   ========================================================================== */

.eyebrow {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-2);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-1);
  line-height: 1;
}

.chip--accent {
  background: var(--accent-soft);
  border-color: var(--accent-ring);
  color: var(--accent);
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--r-xl);
  box-shadow: var(--elev-1);
  transition: border-color var(--dur-med) var(--ease-out-quint),
              transform var(--dur-med) var(--ease-out-quint),
              box-shadow var(--dur-med) var(--ease-out-quint);
}
.card:hover { border-color: var(--hairline-strong); }
.card--inset { background: var(--surface-0); }

.divider { height: 1px; background: var(--hairline); border: 0; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 22px;
  border-radius: var(--r-full);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: -0.01em;
  transition: transform var(--dur-fast) var(--ease-out-quint),
              background var(--dur-fast) var(--ease-out-quint),
              box-shadow var(--dur-fast) var(--ease-out-quint),
              color var(--dur-fast) var(--ease-out-quint),
              opacity var(--dur-fast) var(--ease-out-quint);
  white-space: nowrap;
}
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn:not([disabled]):active { transform: translateY(1px) scale(0.99); }

.btn--primary {
  background: var(--gradient-brand);
  color: var(--accent-contrast);
  box-shadow: 0 10px 30px -10px rgba(94,58,35,0.55), 0 0 0 1px rgba(237,230,217,0.06) inset;
}
.btn--primary:not([disabled]):hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 40px -10px rgba(122,55,49,0.7), 0 0 0 1px rgba(237,230,217,0.08) inset;
}

.btn--secondary {
  background: var(--surface-2);
  color: var(--text-0);
  border: 1px solid var(--hairline-strong);
}
.btn--secondary:not([disabled]):hover {
  background: var(--surface-3);
  border-color: var(--accent-ring);
}

.btn--ghost {
  background: transparent;
  color: var(--text-1);
  border: 1px solid transparent;
  padding: 8px 14px;
}
.btn--ghost:not([disabled]):hover { color: var(--text-0); background: var(--surface-2); }

/* Icon-only square button (nav icons, close buttons) */
.icon-btn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-md);
  color: var(--text-1);
  border: 1px solid transparent;
  background: transparent;
  transition: all var(--dur-fast) var(--ease-out-quint);
}
.icon-btn:hover {
  color: var(--text-0);
  background: var(--surface-2);
  border-color: var(--hairline);
}
.icon-btn svg { width: 18px; height: 18px; }

/* Links */
.link {
  color: var(--text-0);
  border-bottom: 1px solid var(--hairline-strong);
  transition: border-color var(--dur-fast) var(--ease-out-quint), color var(--dur-fast) var(--ease-out-quint);
}
.link:hover { color: var(--accent); border-color: var(--accent); }
.link--accent { color: var(--accent); border-color: var(--accent-ring); }

/* ==========================================================================
   Layout containers
   ========================================================================== */

.container {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 32px);
}

/* ==========================================================================
   Navigation (shared between analyzer and paper)
   ========================================================================== */

.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  background: color-mix(in oklab, var(--surface-0) 78%, transparent);
  border-bottom: 1px solid var(--hairline);
}
.nav__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--nav-h);
  gap: 16px;
}
.nav__brand {
  display: inline-flex; align-items: center; gap: 12px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-0);
}
.nav__brand img { width: 32px; height: 32px; border-radius: 10px; box-shadow: var(--elev-1); }
.nav__brand small { display: block; font-weight: 500; font-size: 11px; color: var(--text-2); letter-spacing: 0.04em; }

.nav__links {
  display: inline-flex; align-items: center; gap: 4px;
}
.nav__link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--r-md);
  font-size: var(--text-sm);
  color: var(--text-1);
  line-height: 1;
  transition: all var(--dur-fast) var(--ease-out-quint);
}
.nav__link svg {
  display: inline-block;
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}
.nav__link:hover { color: var(--text-0); background: var(--surface-2); }
.nav__link[aria-current="page"] {
  color: var(--text-0);
  background: var(--surface-2);
  border: 1px solid var(--hairline);
}
.nav__actions { display: inline-flex; align-items: center; gap: 4px; }

@media (max-width: 640px) {
  .nav__links { display: none; }
  .nav__brand small { display: none; }
}

/* ==========================================================================
   Footer
   ========================================================================== */

.footer {
  margin-top: var(--sp-12);
  padding: var(--sp-9) 0 var(--sp-8);
  border-top: 1px solid var(--hairline);
  color: var(--text-2);
  font-size: var(--text-xs);
  position: relative;
  z-index: 1;
}
.footer__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}
.footer__links { display: inline-flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.footer__links a { color: var(--text-1); transition: color var(--dur-fast) var(--ease-out-quint); }
.footer__links a:hover { color: var(--accent); }

/* ==========================================================================
   Animation primitives (used with or without Motion One)
   ========================================================================== */

@keyframes fade-up {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-up { animation: fade-up var(--dur-slow) var(--ease-out-expo) both; }
.fade-up-2 { animation-delay: 80ms; }
.fade-up-3 { animation-delay: 160ms; }
.fade-up-4 { animation-delay: 240ms; }
.fade-up-5 { animation-delay: 320ms; }

@keyframes bar-grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }
