/* ============================================================
   Atomify · v2 · core
   ------------------------------------------------------------
   Foundations only — design tokens, reset, base typography,
   shared layout primitives (masthead, chapter, container) and
   global motion. Every page loads this file first.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600;9..144,700&family=Geist:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ─── 1 · Tokens · light ─────────────────────────────── */
:root,
:root[data-theme="light"] {
  /* Paper — warm cream surfaces */
  --paper:        #F5F1E8;
  --paper-2:      #EDE7D6;
  --paper-3:      #E2DAC4;
  --paper-tint:   rgba(15, 22, 34, 0.04);

  /* Ink — deep blue-black for typography */
  --ink:          #0F1622;
  --ink-2:        #1F2A3D;
  --ink-3:        #4A5568;
  --ink-soft:     rgba(15, 22, 34, 0.62);
  --ink-muted:    rgba(15, 22, 34, 0.45);

  /* Lab green — primary accent */
  --green:        #1F8F5C;
  --green-bright: #2EC27E;
  --green-deep:   #166540;
  --green-tint:   rgba(31, 143, 92, 0.10);

  /* Burnt amber — warning / hot accent */
  --amber:        #C95E2E;
  --amber-bright: #E76F51;
  --amber-tint:   rgba(231, 111, 81, 0.12);

  /* Cobalt — used in cells/badges, not as page color */
  --cobalt:       #2A4A8B;
  --cobalt-tint:  rgba(42, 74, 139, 0.10);

  /* Gold — for gamified elements (achievements, streaks) */
  --gold:         #B8860B;
  --gold-bright:  #D4A017;
  --gold-tint:    rgba(212, 160, 23, 0.12);

  /* Lines */
  --line:         rgba(15, 22, 34, 0.12);
  --line-strong:  rgba(15, 22, 34, 0.22);
  --line-soft:    rgba(15, 22, 34, 0.06);

  /* Shadows */
  --shadow-sm:    0 1px 2px rgba(15, 22, 34, 0.06);
  --shadow-md:    0 8px 24px -8px rgba(15, 22, 34, 0.18);
  --shadow-lg:    0 30px 60px -20px rgba(15, 22, 34, 0.24);
  --focus-ring:   0 0 0 4px rgba(31, 143, 92, 0.18);

  /* Typography stacks */
  --font-display: 'Fraunces', 'Cambria', 'Times New Roman', serif;
  --font-body:    'Geist', 'Söhne', 'Helvetica Neue', system-ui, sans-serif;
  --font-mono:    'JetBrains Mono', ui-monospace, 'SF Mono', monospace;

  /* Spacing scale (4px base) */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px; --s-5: 20px;
  --s-6: 24px; --s-7: 32px; --s-8: 40px; --s-9: 56px; --s-10: 80px;

  /* Radii */
  --r-1: 3px; --r-2: 4px; --r-3: 6px; --r-4: 8px; --r-5: 12px;

  /* Motion */
  --ease-out:     cubic-bezier(.2, .8, .2, 1);
  --ease-soft:    cubic-bezier(.4, 0, .2, 1);
}

/* ─── 1 · Tokens · dark ──────────────────────────────── */
:root[data-theme="dark"],
body.dark-mode {
  --paper:        #0B1220;
  --paper-2:      #131C2D;
  --paper-3:      #1B2638;
  --paper-tint:   rgba(255, 255, 255, 0.04);

  --ink:          #F0EBDF;
  --ink-2:        #D6CFBE;
  --ink-3:        #9BA2AE;
  --ink-soft:     rgba(240, 235, 223, 0.74);
  --ink-muted:    rgba(240, 235, 223, 0.50);

  --green:        #4FE39A;
  --green-bright: #6FF5B0;
  --green-deep:   #2EC27E;
  --green-tint:   rgba(79, 227, 154, 0.14);

  --amber:        #F08263;
  --amber-bright: #FF9A78;
  --amber-tint:   rgba(240, 130, 99, 0.14);

  --cobalt:       #6E94D6;
  --cobalt-tint:  rgba(110, 148, 214, 0.14);

  --gold:         #E5BC5C;
  --gold-bright:  #F5D27A;
  --gold-tint:    rgba(245, 210, 122, 0.14);

  --line:         rgba(240, 235, 223, 0.10);
  --line-strong:  rgba(240, 235, 223, 0.20);
  --line-soft:    rgba(240, 235, 223, 0.05);

  --shadow-sm:    0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md:    0 12px 32px -10px rgba(0, 0, 0, 0.55);
  --shadow-lg:    0 32px 60px -18px rgba(0, 0, 0, 0.7);
  --focus-ring:   0 0 0 4px rgba(79, 227, 154, 0.22);
}

/* ─── 2 · Reset ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  background:
    radial-gradient(ellipse 120% 80% at 50% -10%, var(--paper-2) 0%, transparent 60%),
    var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.005em;
  font-feature-settings: "ss01", "cv11";
  min-height: 100vh;
  position: relative;
}

/* Lab-notebook grain background */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(var(--line-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--line-soft) 1px, transparent 1px);
  background-size: 48px 48px;
  opacity: 0.55;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 35%, black 0%, transparent 100%);
  -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 35%, black 0%, transparent 100%);
}
body > * { position: relative; z-index: 1; }

img, svg { display: block; max-width: 100%; }
button { font: inherit; color: inherit; }
a { color: inherit; }

[hidden] { display: none !important; }

::selection { background: var(--green-tint); color: var(--ink); }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ─── 3 · Typography utilities ─────────────────────── */
.display {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-variation-settings: "opsz" 144;
  font-weight: 500;
  letter-spacing: -0.025em;
  line-height: 0.98;
  color: var(--ink);
}
.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-muted);
}
.label-mono {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-weight: 500;
}
.num {
  font-family: var(--font-mono);
  font-feature-settings: "tnum", "ss01";
  font-variant-numeric: tabular-nums;
}
.ital {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  color: var(--green-deep);
}
[data-theme="dark"] .ital,
body.dark-mode .ital { color: var(--green); }

/* ─── 4 · Layout primitives ─────────────────────────── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding-inline: 2rem;
}
.page-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 4.5rem 2rem 6rem;
}
@media (max-width: 720px) {
  .container, .page-main { padding-inline: 1.25rem; }
  .page-main { padding-block: 2.75rem 4rem; }
}

/* Masthead — page-level title block */
.masthead {
  display: grid;
  grid-template-columns: 80px 1fr auto;
  gap: 2rem;
  align-items: end;
  padding: 1rem 0 3.5rem;
  border-bottom: 1px solid var(--line);
}
.masthead-eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-muted);
  padding-bottom: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.masthead-eyebrow::before {
  content: '';
  width: 18px;
  height: 1px;
  background: var(--line-strong);
}
.masthead-title {
  font-family: var(--font-display);
  font-variation-settings: "opsz" 144;
  font-weight: 500;
  font-size: clamp(2.5rem, 6vw, 4.5rem);
  letter-spacing: -0.035em;
  line-height: 0.95;
  color: var(--ink);
  margin: 0;
}
.masthead-meta {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  color: var(--ink-muted);
  text-transform: uppercase;
  padding-bottom: 0.75rem;
  text-align: right;
  line-height: 1.7;
  white-space: nowrap;
}
@media (max-width: 720px) {
  .masthead {
    grid-template-columns: 1fr;
    gap: 0.75rem;
    padding-bottom: 2.5rem;
  }
  .masthead-eyebrow { padding-bottom: 0; }
  .masthead-meta { text-align: left; padding-bottom: 0; }
}

/* Chapter — numbered section block */
.chapter {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 2rem;
  padding-top: 2.75rem;
  padding-bottom: 2rem;
  border-top: 1px solid var(--line);
}
.chapter:first-of-type {
  border-top: 0;
  padding-top: 2.5rem;
}
.chapter-num {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  color: var(--ink-muted);
  padding-top: 0.45rem;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}
.chapter-num::before {
  content: '';
  width: 18px;
  height: 1px;
  background: var(--line-strong);
  margin-top: 0.55rem;
  flex-shrink: 0;
}
.chapter-head {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(1.4rem, 2.5vw, 1.85rem);
  letter-spacing: -0.022em;
  color: var(--ink);
  margin: 0 0 0.55rem;
  line-height: 1.15;
}
.chapter-sub {
  color: var(--ink-soft);
  font-size: 0.98rem;
  line-height: 1.6;
  max-width: 60ch;
  margin: 0 0 1.75rem;
}
@media (max-width: 720px) {
  .chapter {
    grid-template-columns: 1fr;
    gap: 0.75rem;
    padding-top: 2rem;
  }
  .chapter-num { padding-top: 0; }
}

/* ─── 5 · Reveal motion ─────────────────────────────── */
.reveal {
  opacity: 0;
  transform: translateY(8px);
  animation: reveal 0.7s var(--ease-out) forwards;
}
.reveal-1 { animation-delay: 0.05s; }
.reveal-2 { animation-delay: 0.18s; }
.reveal-3 { animation-delay: 0.32s; }
.reveal-4 { animation-delay: 0.46s; }
.reveal-5 { animation-delay: 0.60s; }
@keyframes reveal { to { opacity: 1; transform: translateY(0); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .reveal { opacity: 1; transform: none; }
}
