:root {
  /* ---- Color ramp (extends the 4 existing brand hues) ---- */
  --ink-950: #131C25;
  --ink-900: #1F2B37;
  --ink-800: #2C3A44;
  --ink-700: #3A4A56;
  --ink-600: #52646F;

  --sage-600: #4A6E56;
  --sage-500: #5A8367;
  --sage-400: #6E9C7B;

  --mint-400: #97D986;
  --mint-300: #B4E9A4;
  --mint-200: #D3F5C9;

  --amber-400: #E8B04B;

  /* ---- Same colors as R G B channel triplets, for Tailwind's
     rgb(var(...) / <alpha-value>) pattern — a color defined as a bare
     var() silently drops Tailwind's opacity modifiers (bg-navy/95 etc
     produce no background at all), so every color the config exposes
     needs a channel-triplet twin. ---- */
  --ink-950-rgb: 19 28 37;
  --ink-900-rgb: 31 43 55;
  --ink-800-rgb: 44 58 68;
  --ink-700-rgb: 58 74 86;
  --ink-600-rgb: 82 100 111;

  --sage-600-rgb: 74 110 86;
  --sage-500-rgb: 90 131 103;
  --sage-400-rgb: 110 156 123;

  --mint-400-rgb: 151 217 134;
  --mint-300-rgb: 180 233 164;
  --mint-200-rgb: 211 245 201;

  --amber-400-rgb: 232 176 75;

  /* ---- Fluid type scale ---- */
  --step--1: clamp(0.83rem, 0.80rem + 0.15vw, 0.90rem);
  --step-0:  clamp(1.00rem, 0.96rem + 0.20vw, 1.13rem);
  --step-1:  clamp(1.25rem, 1.16rem + 0.45vw, 1.50rem);
  --step-2:  clamp(1.56rem, 1.39rem + 0.85vw, 2.00rem);
  --step-3:  clamp(1.95rem, 1.66rem + 1.45vw, 2.66rem);
  --step-4:  clamp(2.44rem, 1.97rem + 2.35vw, 3.55rem);
  --step-5:  clamp(3.05rem, 2.31rem + 3.70vw, 4.74rem);

  /* ---- Radii ---- */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-xl: 24px;

  /* ---- Motion ---- */
  --dur-fast: 150ms;
  --dur: 250ms;
  --dur-slow: 400ms;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);

  /* ---- Fonts ---- */
  --font-heading: 'Bricolage Grotesque', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

@view-transition {
  navigation: auto;
}

/* ===================== Base ===================== */

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  background-color: var(--ink-950);
  font-family: var(--font-body);
}

::selection {
  background: var(--mint-300);
  color: var(--ink-900);
}

h1, h2, h3, h4 {
  font-family: var(--font-heading);
  letter-spacing: -0.02em;
  line-height: 1.05;
  text-wrap: balance;
}

p {
  line-height: 1.65;
  text-wrap: pretty;
}

p.prose-measure {
  max-width: 68ch;
}

a, button, input, textarea, select, [tabindex] {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--mint-300);
  outline-offset: 3px;
  border-radius: 2px;
}

/* ===================== Texture ===================== */

.grain-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch' result='t'/%3E%3CfeColorMatrix in='t' type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 120px 120px;
}

/* Applied to a dedicated decorative layer div (absolute inset-0,
   aria-hidden), never directly to a content-bearing section — two
   background-layer classes can then coexist as sibling layers
   without fighting over the same ::before. */

.grid-texture {
  background-image:
    linear-gradient(rgba(180, 233, 164, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(180, 233, 164, 0.05) 1px, transparent 1px);
  background-size: 44px 44px;
  -webkit-mask-image: radial-gradient(ellipse at 30% 40%, black, transparent 70%);
  mask-image: radial-gradient(ellipse at 30% 40%, black, transparent 70%);
}

.section-glow {
  /* background-image (longhand), not the background shorthand — so it
     layers over an existing background-color (e.g. Tailwind's
     bg-navy-light) instead of resetting it. */
  background-image: radial-gradient(600px circle at 20% -10%, rgba(90, 131, 103, 0.18), transparent 70%);
}

/* ===================== Layout helpers ===================== */

.video-embed {
  aspect-ratio: 16 / 9;
  position: relative;
}

/* ===================== Eyebrow (formula-style label) ===================== */

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-family: var(--font-mono);
  font-size: var(--step--1);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--mint-300);
}

.eyebrow-tag {
  text-transform: none;
  letter-spacing: 0.02em;
}

.eyebrow::before {
  content: '';
  flex-shrink: 0;
  width: 6px;
  height: 6px;
  background: var(--mint-300);
}

.badge-coming-soon {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  font-family: var(--font-mono);
  font-size: var(--step--1);
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--sage-400);
  background: rgba(90, 131, 103, 0.15);
  border: 1px solid rgba(90, 131, 103, 0.35);
  padding: 0.3rem 0.7rem;
  border-radius: var(--r-sm);
}

/* ===================== Buttons ===================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: var(--font-body);
  font-weight: 600;
  padding: 0.875rem 1.75rem;
  border-radius: var(--r-md);
  transition:
    background-color var(--dur) var(--ease),
    color var(--dur) var(--ease),
    border-color var(--dur) var(--ease),
    transform var(--dur-fast) var(--ease),
    box-shadow var(--dur) var(--ease);
}

.btn-primary {
  background: var(--mint-300);
  color: var(--ink-900);
  border: 1px solid var(--mint-300);
}

.btn-primary:hover {
  background: var(--mint-200);
  border-color: var(--mint-200);
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(180, 233, 164, 0.25);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  position: relative;
  background: transparent;
  color: #ffffff;
  border: 1px solid var(--ink-700);
}

.btn-secondary::after {
  content: '';
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 7px;
  height: 7px;
  background: var(--mint-300);
  opacity: 0;
  transition: opacity var(--dur) var(--ease);
}

.btn-secondary:hover,
.btn-secondary:focus-visible {
  border-color: var(--mint-300);
  color: var(--mint-300);
}

.btn-secondary:hover::after,
.btn-secondary:focus-visible::after {
  opacity: 1;
}

/* ===================== Active-cell hover (signature motif) ===================== */

.cell-hover {
  position: relative;
  border: 1px solid var(--ink-700);
  transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.cell-hover::after {
  content: '';
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 7px;
  height: 7px;
  background: var(--mint-300);
  opacity: 0;
  transition: opacity var(--dur) var(--ease);
}

/* Border stays 1px at all times — the "2px mint edge" is painted with
   an inset outline instead of grown border, so the content box never
   resizes and nothing reflows on hover. :focus-within (not just
   :focus-visible) covers wrapper elements like .video-tile whose
   actual focusable control is a descendant button, not the wrapper
   itself. */
.cell-hover:hover,
.cell-hover:focus-visible,
.cell-hover:focus-within {
  border-color: var(--mint-300);
  outline: 1px solid var(--mint-300);
  outline-offset: -2px;
}

.cell-hover:hover::after,
.cell-hover:focus-visible::after,
.cell-hover:focus-within::after {
  opacity: 1;
}

/* ===================== Cards ===================== */

.card {
  display: block;
  background: var(--ink-900);
  border-radius: var(--r-lg);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  padding: 1.5rem;
}

.card-feature {
  background: var(--ink-800);
  padding: 2rem;
}

.card-cta {
  background: rgba(90, 131, 103, 0.12);
  border-color: rgba(90, 131, 103, 0.45) !important;
}

.cell-icon {
  width: 2.5rem;
  height: 2.5rem;
  flex-shrink: 0;
  border-radius: var(--r-sm);
  background: rgba(90, 131, 103, 0.18);
  border: 1px solid var(--mint-300);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: var(--step-0);
  color: var(--mint-300);
}

/* ===================== Video tiles / click-to-load facade ===================== */

.video-tile {
  display: block;
  transition: transform var(--dur) var(--ease);
}

.video-tile:hover {
  transform: translateY(-2px);
}

/* .video-embed carries the radius/clip — kept off the outer
   .cell-hover wrapper so its fill-handle square (offset outside the
   border) doesn't get clipped by overflow:hidden. */
.video-embed {
  border-radius: var(--r-lg);
  overflow: hidden;
}

.video-thumb {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: none;
  background: var(--ink-800);
  cursor: pointer;
}

.video-embed iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.video-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform var(--dur-slow) var(--ease);
}

.video-tile:hover .video-thumb img,
.video-thumb:focus-visible img {
  transform: scale(1.03);
}

.video-play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(19, 28, 37, 0.28);
  transition: background-color var(--dur) var(--ease);
}

.video-thumb:hover .video-play {
  background: rgba(19, 28, 37, 0.42);
}

.video-play svg {
  width: 3.25rem;
  height: 3.25rem;
  color: var(--mint-300);
  filter: drop-shadow(0 2px 10px rgba(0, 0, 0, 0.45));
}

.video-meta {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  color: var(--sage-400); /* ink-600 measured 2.79:1 on ink-950 — fails AA; sage-400 is 5.49:1 */
  letter-spacing: 0.03em;
}

/* ===================== Small utilities ===================== */

/* A generic vertical divider — used inside .sheet-formula-row. Kept
   separate from any one component so it isn't tied to something that
   might get removed later (the standalone header formula-bar this
   was originally shared with was cut — see D1 in the round-2 review:
   it duplicated the sheet-card's own fx row ~200px away on the same
   viewport). */
.divider-v {
  width: 1px;
  height: 1rem;
  background: var(--ink-700);
  flex-shrink: 0;
}

/* ===================== Row-number gutter (content.html) ===================== */

.row-gutter {
  display: grid;
  grid-template-columns: 3rem 1fr;
  gap: 1.75rem;
}

.row-number {
  font-family: var(--font-mono);
  font-size: var(--step-2);
  color: var(--ink-600);
  text-align: right;
  padding-right: 1.25rem;
  padding-top: 0.1em;
  border-right: 1px solid var(--ink-700);
}

@media (max-width: 767px) {
  .row-gutter {
    grid-template-columns: 1fr;
    gap: 0;
  }
  .row-number {
    display: inline-flex;
    width: fit-content;
    text-align: left;
    border-right: none;
    border-bottom: none;
    padding: 0.15rem 0.6rem;
    margin-bottom: 0.75rem;
    font-size: var(--step--1);
    background: var(--ink-800);
    border-radius: var(--r-sm);
  }
}

/* ===================== Scroll reveal ===================== */

[data-reveal] {
  /* Fully visible by default — hiding only ever happens behind a
     feature query that resolves itself, or a class JS adds. */
}

@supports (animation-timeline: view()) {
  /* No animation-delay here: it's a time-based delay on a
     progress-based timeline, so it doesn't map onto view() the way
     it does on the IntersectionObserver fallback below — likely
     inert in Chrome/Safari. Real per-item stagger for this path would
     need per-item animation-range offsets, which isn't worth the
     added complexity for a 60ms visual nicety; scroll position alone
     already staggers items naturally as the user scrolls past them. */
  [data-reveal] {
    animation: reveal-in var(--dur-slow) var(--ease) both;
    animation-timeline: view();
    animation-range: entry 0% cover 30%;
  }
}

@keyframes reveal-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.js-reveal[data-reveal] {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity var(--dur-slow) var(--ease), transform var(--dur-slow) var(--ease);
  transition-delay: calc(var(--i, 0) * 60ms);
}

.js-reveal[data-reveal].is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* ===================== Sticky header shrink ===================== */

.site-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 80px;
  transition: height var(--dur) var(--ease);
}

@media (max-width: 767px) {
  .site-header-bar { height: 64px; }
}

#site-header.is-scrolled .site-header-bar {
  height: 64px;
}

@media (max-width: 767px) {
  #site-header.is-scrolled .site-header-bar { height: 56px; }
}

#site-header {
  background-color: transparent;
  border-bottom: 1px solid transparent;
  transition:
    background-color var(--dur) var(--ease),
    border-color var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease),
    backdrop-filter var(--dur) var(--ease);
}

#site-header.is-scrolled {
  background-color: rgba(19, 28, 37, 0.85);
  border-bottom-color: var(--ink-700);
  backdrop-filter: blur(16px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.nav-indicator {
  position: absolute;
  bottom: -1px;
  left: 0;
  height: 2px;
  width: 0;
  background: var(--mint-300);
  transform: translateX(0);
  transition: transform var(--dur) var(--ease), width var(--dur) var(--ease), opacity var(--dur) var(--ease);
  opacity: 0;
}

/* ===================== View-transition names ===================== */

#site-header { view-transition-name: site-header; }
.site-logo { view-transition-name: site-logo; }
#site-footer { view-transition-name: site-footer; }

/* ===================== Hero spreadsheet visual ===================== */

.sheet-card {
  border: 1px solid var(--ink-700);
  border-radius: var(--r-xl);
  background: var(--ink-900);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  overflow: hidden;
}

.sheet-formula-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.1rem;
  border-bottom: 1px solid var(--ink-700);
  font-family: var(--font-mono);
  font-size: var(--step--1);
  color: var(--ink-600);
  background: var(--ink-950);
}

.sheet-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}

.sheet-cell {
  aspect-ratio: 1;
  border-right: 1px solid var(--ink-700);
  border-bottom: 1px solid var(--ink-700);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: var(--step--1);
  color: var(--ink-600);
}

.sheet-cell:nth-child(4n) {
  border-right: none;
}

.sheet-cell.is-active {
  position: relative;
  border: 2px solid var(--mint-300);
  color: var(--mint-300);
  font-weight: 600;
  background: rgba(180, 233, 164, 0.06);
}

.sheet-cell.is-active::after {
  content: '';
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 7px;
  height: 7px;
  background: var(--mint-300);
}

/* ===================== Full-bleed CTA band ===================== */

.cta-band {
  position: relative;
  background: linear-gradient(135deg, var(--sage-600) 0%, var(--ink-900) 65%);
  overflow: hidden;
}

/* ===================== Footer wordmark backdrop ===================== */

.footer-wordmark {
  position: absolute;
  right: -0.02em;
  bottom: -0.28em;
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: clamp(4rem, 16vw, 11rem);
  color: rgba(255, 255, 255, 0.03);
  letter-spacing: -0.03em;
  pointer-events: none;
  white-space: nowrap;
  line-height: 1;
  user-select: none;
}

#site-footer {
  position: relative;
  overflow: hidden;
}

/* ===================== Form fields ===================== */

.field-label {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--step--1);
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-600);
  margin-bottom: 0.6rem;
}

/* Wraps each input/textarea so the fill-handle square (an ::after on
   the wrapper) can appear on :focus-within — pseudo-elements don't
   render reliably directly on <input>/<textarea> across browsers. */
.field-wrap {
  position: relative;
}

.field-wrap::after {
  content: '';
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 7px;
  height: 7px;
  background: var(--mint-300);
  opacity: 0;
  transition: opacity var(--dur) var(--ease);
}

.field-wrap:focus-within::after {
  opacity: 1;
}

.field {
  display: block;
  width: 100%;
  background: var(--ink-900);
  border: 1px solid var(--ink-700);
  border-radius: var(--r-md);
  padding: 0.75rem 1rem;
  color: #ffffff;
  font-family: var(--font-body);
  transition: border-color var(--dur) var(--ease), outline-color var(--dur) var(--ease);
}

.field::placeholder {
  color: rgba(255, 255, 255, 0.35);
}

.field:focus {
  outline: 1px solid var(--mint-300);
  outline-offset: -2px;
  border-color: var(--mint-300);
}

/* ===================== Reduced motion ===================== */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    scroll-behavior: auto !important;
  }
  [data-reveal] {
    opacity: 1 !important;
    transform: none !important;
    animation: none !important;
  }
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation: none !important;
  }
}

/* ---------------------------------------------------------------
   Lesson pages
   Self-contained typography for long-form lessons. Deliberately not
   built from Tailwind utilities: assets/css/tailwind.css is a frozen
   compiled build containing only the classes the original five pages
   used, so utilities like list-disc / max-w-3xl / overflow-x-auto do
   not exist in it and fail silently. These rules become the Django
   lesson template's stylesheet later, unchanged.
   --------------------------------------------------------------- */
.lesson {
  max-width: 46rem;
  margin-inline: auto;
}

.lesson-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  font-family: var(--font-mono);
  font-size: var(--step--1);
  color: rgb(255 255 255 / 0.5);
}

.lesson-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border: 1px solid rgb(255 255 255 / 0.15);
  border-radius: 999px;
  white-space: nowrap;
}

.lesson-chip-level {
  border-color: var(--sage-500);
  color: var(--mint-300);
}

.lesson-prose > * + * { margin-top: 1.15rem; }

.lesson-prose p,
.lesson-prose li {
  font-size: var(--step-0);
  line-height: 1.75;
  color: rgb(255 255 255 / 0.78);
}

.lesson-prose h2 {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: var(--step-2);
  line-height: 1.2;
  margin-top: 3rem;
  color: #fff;
}

.lesson-prose h3 {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: var(--step-1);
  margin-top: 2rem;
  color: #fff;
}

.lesson-prose ul,
.lesson-prose ol {
  padding-left: 1.35rem;
}

.lesson-prose ul { list-style: disc; }
.lesson-prose ol { list-style: decimal; }
.lesson-prose li + li { margin-top: 0.5rem; }
.lesson-prose li::marker { color: var(--sage-400); }

.lesson-prose strong { color: #fff; font-weight: 600; }

.lesson-prose a {
  color: var(--mint-300);
  text-underline-offset: 3px;
  text-decoration: underline;
}

.lesson-prose code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  padding: 0.1rem 0.35rem;
  border-radius: var(--r-sm);
  background: rgb(255 255 255 / 0.07);
  color: var(--mint-200);
  white-space: nowrap;
}

/* A formula presented on its own line, the way it is typed into Excel */
.formula-block {
  font-family: var(--font-mono);
  font-size: var(--step-0);
  color: var(--mint-200);
  background: var(--ink-950);
  border: 1px solid rgb(255 255 255 / 0.1);
  border-left: 3px solid var(--sage-500);
  border-radius: var(--r-md);
  padding: 0.9rem 1.1rem;
  overflow-x: auto;
  white-space: pre;
}

/* Callouts: the gotcha, the aside, the warning */
.callout {
  border: 1px solid rgb(255 255 255 / 0.12);
  border-left: 3px solid var(--sage-500);
  border-radius: var(--r-md);
  background: rgb(255 255 255 / 0.03);
  padding: 1.1rem 1.25rem;
}

.callout-warning { border-left-color: var(--amber-400); }

.callout-label {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--step--1);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--mint-300);
  margin-bottom: 0.4rem;
}

.callout-warning .callout-label { color: var(--amber-400); }

/* Tables: scroll on their own rather than breaking the page */
.table-scroll { overflow-x: auto; }

.lesson-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--step--1);
  min-width: 34rem;
}

.lesson-table th,
.lesson-table td {
  text-align: left;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid rgb(255 255 255 / 0.1);
  vertical-align: top;
}

.lesson-table th {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgb(255 255 255 / 0.55);
  font-weight: 500;
}

.lesson-table td:first-child {
  font-family: var(--font-mono);
  color: var(--mint-200);
  white-space: nowrap;
}

.lesson-next {
  display: block;
  border: 1px solid rgb(255 255 255 / 0.12);
  border-radius: var(--r-lg);
  padding: 1.25rem 1.5rem;
  transition: border-color var(--dur) var(--ease);
}

.lesson-next:hover { border-color: var(--sage-500); }
