/* ==========================================================================
   Bezier Splines — design system
   Elegant, slightly retro: warm paper, terracotta + teal, serif display,
   monospace technical voice. Light/dark via tokens.
   ========================================================================== */

:root {
  color-scheme: light dark;

  /* Light (default) — warm paper */
  --bg:        #f3ead6;
  --bg-grid:   #e3d6ba;
  --surface:   #fbf6ea;
  --surface-2: #f1e7d2;
  --ink:       #2c2620;
  --muted:     #877c66;
  --accent:    #c4553a;   /* terracotta */
  --accent-ink:#ffffff;
  --accent-2:  #2a7d7b;   /* teal */
  --line:      #ddd0b4;
  --line-soft: #e8ddc4;
  --shadow:    rgba(60, 48, 28, 0.14);

  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", "JetBrains Mono", "Fira Mono", ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;

  --radius: 14px;
  --radius-sm: 9px;
  --maxw: 1080px;
}

:root[data-theme="dark"] {
  --bg:        #1b1813;
  --bg-grid:   #2a251c;
  --surface:   #242019;
  --surface-2: #2c271e;
  --ink:       #ece2cd;
  --muted:     #a4977c;
  --accent:    #e08a5d;
  --accent-ink:#1b1813;
  --accent-2:  #5db6b2;
  --line:      #38322796;
  --line-soft: #322d23;
  --shadow:    rgba(0, 0, 0, 0.4);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #1b1813;
    --bg-grid:   #2a251c;
    --surface:   #242019;
    --surface-2: #2c271e;
    --ink:       #ece2cd;
    --muted:     #a4977c;
    --accent:    #e08a5d;
    --accent-ink:#1b1813;
    --accent-2:  #5db6b2;
    --line:      #38322796;
    --line-soft: #322d23;
    --shadow:    rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-body);
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: 28px 28px;
  background-position: -1px -1px;
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

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

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 1.25rem 1.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.brand:hover { text-decoration: none; }
.brand img { width: 28px; height: 28px; display: block; }
.brand .brand-mark-2 { color: var(--accent); font-style: italic; }

.nav {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.nav a { color: var(--muted); }
.nav a:hover, .nav a[aria-current="page"] { color: var(--ink); text-decoration: none; }

.theme-toggle {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--accent); }

main { max-width: var(--maxw); margin: 0 auto; padding: 0 1.5rem 4rem; }

.site-footer {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
}

/* ---- Hero ---------------------------------------------------------------- */

.hero { text-align: center; padding: 1rem 0 2rem; }
.hero .eyebrow {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent-2);
  margin: 0 0 0.6rem;
}
.hero h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(2rem, 5vw, 3.1rem);
  line-height: 1.1;
  margin: 0 0 0.7rem;
}
.hero h1 em { color: var(--accent); font-style: italic; }
.hero p {
  max-width: 46ch;
  margin: 0 auto;
  color: var(--muted);
  font-size: 1.05rem;
}

/* ---- Player -------------------------------------------------------------- */

.player {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 1.25rem;
  margin-top: 1.5rem;
}

.stage-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 18px 40px -28px var(--shadow);
  overflow: hidden;
}

.stage-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.1rem 0.4rem;
}
.stage-head .demo-counter {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  color: var(--accent-2);
  text-transform: uppercase;
}
.stage-head h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.3rem;
  margin: 0.1rem 0 0;
}

.canvas-frame {
  position: relative;
  margin: 0.3rem 1.1rem 0.6rem;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  overflow: hidden;
}
.canvas-frame canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 10;
  touch-action: none;
}

.demo-blurb {
  padding: 0 1.1rem 1rem;
  color: var(--muted);
  font-size: 0.95rem;
  min-height: 3.2em;
}
.demo-blurb strong { color: var(--ink); font-weight: 600; }

/* ---- Transport controls -------------------------------------------------- */

.controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 1.1rem;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.45rem 0.7rem;
  min-width: 2.4rem;
  height: 2.4rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.05s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.btn.primary:hover { color: var(--accent-ink); filter: brightness(1.05); }
.btn svg { width: 16px; height: 16px; fill: currentColor; }

.scrubber {
  flex: 1 1 120px;
  appearance: none;
  -webkit-appearance: none;
  height: 6px;
  border-radius: 999px;
  background: var(--line);
  cursor: pointer;
  outline: none;
}
.scrubber::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: 0 1px 3px var(--shadow);
}
.scrubber::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
}

.toggle-loop {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  white-space: nowrap;
}
.toggle-loop[aria-pressed="true"] {
  color: var(--accent-2);
  border-color: var(--accent-2);
}

.speed {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.4rem 0.55rem;
  cursor: pointer;
}

/* ---- Demo selector list -------------------------------------------------- */

.demo-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.demo-list .list-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.1rem;
}
.demo-item {
  text-align: left;
  width: 100%;
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  color: var(--ink);
  transition: border-color 0.15s, background 0.15s, transform 0.05s;
}
.demo-item:hover { border-color: var(--accent); transform: translateX(2px); }
.demo-item .idx {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
}
.demo-item .t {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.2;
}
.demo-item[aria-current="true"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
}
.demo-item[aria-current="true"] .idx { color: var(--accent); }

.progress-rail {
  height: 3px;
  border-radius: 999px;
  background: var(--line);
  margin-top: 0.55rem;
  overflow: hidden;
}
.progress-rail > span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.08s linear;
}
.demo-item[aria-current="true"] .progress-rail { background: var(--line-soft); }

/* ---- Generic prose / about page ----------------------------------------- */

.prose { max-width: 70ch; margin: 0 auto; }
.prose h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.9rem, 4vw, 2.6rem);
  line-height: 1.15;
  margin: 0.5rem 0 0.3rem;
}
.prose .eyebrow {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent-2);
  margin: 0;
}
.prose h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.5rem;
  margin: 2.4rem 0 0.5rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--line);
}
.prose h3 { font-family: var(--font-display); font-size: 1.15rem; margin: 1.6rem 0 0.3rem; }
.prose p, .prose li { font-size: 1.04rem; }
.prose .lead { font-size: 1.18rem; color: var(--muted); }
.prose code, .prose .mono {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0.08em 0.35em;
}
.prose figure {
  margin: 1.6rem 0;
  padding: 1.1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.prose figure svg { display: block; width: 100%; height: auto; }
.prose figcaption {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-top: 0.7rem;
  text-align: center;
}

.callout {
  background: color-mix(in srgb, var(--accent-2) 12%, var(--surface));
  border-left: 3px solid var(--accent-2);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1.1rem;
  margin: 1.6rem 0;
}
.callout p { margin: 0; }

.back-cta {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 2.5rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

/* ---- Responsive ---------------------------------------------------------- */

@media (max-width: 820px) {
  .player { grid-template-columns: 1fr; }
  .demo-list {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .demo-list .list-label { width: 100%; }
  .demo-item { flex: 1 1 140px; }
  .progress-rail { display: none; }
}

@media (max-width: 520px) {
  .site-header { flex-wrap: wrap; }
  .controls { gap: 0.4rem; }
  .btn { min-width: 2.2rem; height: 2.2rem; padding: 0.4rem 0.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .demo-item, .btn { transition: none; }
}

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