/* ------------------------------------------------------------------
   How Machines Sing — design system
   A calm, paper-white page in the spirit of Lightnote: serif ideas,
   sans explanations, soft gray panels where the machine comes alive.
   ------------------------------------------------------------------ */

:root {
  color-scheme: light;
  --font-serif: 'Lora', Georgia, 'Times New Roman', serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;

  --ink: #2b2b2b;
  --ink-2: #4f4f4f;
  --muted: #777;
  --faint: #b9b9b4;
  --bg: #ffffff;
  --panel: #f5f5f3;
  --panel-2: #ecece9;
  --line: #e4e4e0;

  --accent: #2f7fe0;
  --accent-bg: #eaf3fe;
  --play: #2ec466;
  --play-dark: #25a955;
  --stop: #4f4f4f;
  --brand-hl: #ffe84a;

  /* semantic series colours (validated for colour-vision separation) */
  --c-signal: #c98a5a;
  --c-1x: #e34948;
  --c-2x: #2a78d6;
  --c-3x: #eda100;
  --c-4x: #1baf7a;
  --c-5x: #4a3aa7;
  --c-6x: #eb6834;
  --c-bearing: #4a3aa7;
  --c-gear: #1baf7a;
  --c-electric: #eda100;
  --c-noise: #9a9a96;
  --c-disp: #1baf7a;
  --c-vel: #2a78d6;
  --c-acc: #e34948;
  --c-good: #2ec466;
  --c-bad: #e34948;
  --c-warn: #eda100;

  --content-w: 640px;
  --sidebar-w: 200px;
  --gutter: 24px;
  --radius: 8px;
}

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink-2);
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

b, strong { color: var(--ink); font-weight: 600; }
em { font-style: italic; }
code, .mono { font-family: var(--font-mono); font-size: 0.92em; }
sup, sub { line-height: 0; }

/* ---------- layout ---------- */

.page {
  max-width: calc(var(--content-w) + var(--sidebar-w) + 72px + 2 * var(--gutter));
  margin: 0 auto;
  padding: 0 var(--gutter) 120px;
  display: grid;
  grid-template-columns: minmax(0, var(--content-w)) var(--sidebar-w);
  column-gap: 72px;
  justify-content: center;
}

.content { min-width: 0; }

.sidebar {
  position: sticky;
  top: 36px;
  align-self: start;
  padding-top: 44px;
  font-size: 15px;
  max-height: calc(100vh - 36px);
  overflow-y: auto;
}
.sidebar .nav-label {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 26px 0 8px 10px;
  font-weight: 600;
}
.sidebar .nav-label:first-child { margin-top: 0; }
.sidebar a.nav-link {
  display: block;
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--accent);
  line-height: 1.35;
  margin-bottom: 2px;
}
.sidebar a.nav-link:hover { background: #f3f7fd; text-decoration: none; }
.sidebar a.nav-link.active { background: var(--accent-bg); }
.sidebar a.nav-link.module { color: #1f9d55; }
.sidebar a.nav-link.module:hover { background: #effaf3; }

.sound-setting {
  margin: 28px 10px 0;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
}
.sound-setting .seg { margin-top: 6px; }

/* mobile nav (shown only on small screens) */
.mobile-nav { display: none; }

@media (max-width: 900px) {
  .page {
    display: block;
    padding-bottom: 80px;
  }
  .sidebar { display: none; }
  .mobile-nav {
    display: block;
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(255,255,255,0.94);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
    margin: 0 calc(-1 * var(--gutter));
    padding: 8px var(--gutter);
  }
  .mobile-nav summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    color: var(--ink);
    font-weight: 600;
    letter-spacing: 0.04em;
  }
  .mobile-nav summary::-webkit-details-marker { display: none; }
  .mobile-nav summary::after { content: '▾'; color: var(--muted); }
  .mobile-nav[open] summary::after { content: '▴'; }
  .mobile-nav .menu { padding: 8px 0 6px; }
  .mobile-nav .menu a { display: block; padding: 7px 0; font-size: 15px; }
  .mobile-nav .menu .nav-label {
    font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase;
    color: var(--muted); font-weight: 600; margin: 10px 0 4px;
  }
  .mobile-nav .sound-setting { margin: 10px 0 4px; }
}

@media (max-width: 480px) {
  :root { --gutter: 16px; }
  body { font-size: 16px; }
}

/* ---------- hero ---------- */

.hero { text-align: center; padding: 40px 0 10px; }
.brand {
  display: inline-block;
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.22em;
  color: var(--ink);
  background: linear-gradient(transparent 55%, var(--brand-hl) 55%);
  padding: 0 3px;
  text-decoration: none;
}
.brand:hover { text-decoration: none; }
.hero h1 {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 44px;
  line-height: 1.15;
  color: var(--ink);
  margin: 26px 0 6px;
}
.hero .tagline {
  font-family: var(--font-serif);
  font-size: 22px;
  color: var(--muted);
  margin: 0 0 30px;
}
.hero .hero-viz { margin: 0 auto 28px; }
.hero .intro { text-align: left; }
.hero .intro h3 { margin-top: 24px; }
.scroll-hint {
  display: block;
  margin: 10px auto 40px;
  width: 28px; height: 28px;
  color: var(--accent);
}
.scroll-hint svg { width: 100%; height: 100%; }

/* ---------- lessons & steps ---------- */

.lesson { padding-top: 70px; }
.lesson-number {
  font-family: var(--font-serif);
  font-size: 110px;
  line-height: 0.9;
  color: #dededb;
  margin: 0 0 10px -2px;
  user-select: none;
}
.lesson > h2 {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 36px;
  line-height: 1.2;
  color: var(--ink);
  margin: 0 0 6px;
}
.lesson-tagline {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 21px;
  color: var(--muted);
  margin: 0 0 34px;
}

.step { margin: 0 0 76px; }
.step h3 {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 27px;
  line-height: 1.25;
  color: var(--ink);
  margin: 0 0 10px;
}
.step h4 {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.02em;
  color: var(--ink);
  margin: 26px 0 6px;
}
.step p { margin: 0 0 14px; }
.step p.lead { font-size: 18px; color: var(--ink-2); }
.step ul, .step ol { margin: 0 0 14px; padding-left: 22px; }
.step li { margin-bottom: 6px; }
.step .small { font-size: 14.5px; color: var(--muted); }

/* reveal on scroll */
.reveal { opacity: 0; transform: translateY(12px); transition: opacity 0.45s ease, transform 0.45s ease; }
.reveal.in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce), print {
  .reveal { opacity: 1; transform: none; transition: none; }
}

/* ---------- callouts ---------- */

.note {
  margin: 18px 0;
  padding: 2px 0 2px 16px;
  border-left: 3px solid var(--line);
  color: #666;
  font-size: 15.5px;
  line-height: 1.55;
}
.note::before {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 4px;
  color: var(--muted);
}
.note.music { border-color: #d9b98f; }
.note.music::before { content: '♪  In music'; color: #b08552; }
.note.field { border-color: #9ec5f0; }
.note.field::before { content: 'In the field'; color: #3a79c2; }
.note.history { border-color: #d4c7ea; }
.note.history::before { content: 'A little history'; color: #7a62b8; }
.note.try { border-color: #a6dfbb; }
.note.try::before { content: 'Try it'; color: #2a9b57; }
.note.math { border-color: #e2e2de; font-family: var(--font-sans); }
.note.math::before { content: 'The arithmetic'; }
.note p { margin: 0 0 8px; }
.note p:last-child { margin: 0; }

.formula {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 20px;
  color: var(--ink);
  text-align: center;
  margin: 18px 0;
}
.formula .rm { font-style: normal; }
.formula small { font-family: var(--font-sans); font-style: normal; font-size: 13px; color: var(--muted); display: block; margin-top: 4px; }

/* ---------- visualization panels ---------- */

.viz { margin: 18px 0 0; }
.viz-panel {
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
}
.viz-panel canvas, .viz-panel svg.fig { display: block; width: 100%; }
.viz-panel.interactive { cursor: crosshair; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.viz-panel .corner {
  position: absolute; top: 10px; right: 12px;
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--faint); font-weight: 600; pointer-events: none;
}
.viz-caption {
  font-size: 13.5px;
  color: var(--muted);
  margin: 8px 2px 0;
  line-height: 1.45;
}

/* static svg figures */
.fig { overflow: visible; }
.fig text { font-family: var(--font-sans); fill: var(--ink-2); }
.fig .lbl { font-size: 12px; fill: var(--muted); }
.fig .ttl { font-size: 13px; font-weight: 600; fill: var(--ink); }

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

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  align-items: center;
  margin: 12px 0 0;
}
.controls.stack { flex-direction: column; align-items: stretch; gap: 10px; }
.controls .spacer { flex: 1 1 auto; }

.ctl { display: flex; flex-direction: column; gap: 4px; min-width: 150px; flex: 1 1 150px; }
.ctl.fixed { flex: 0 0 auto; }
.ctl-label {
  display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 600;
}
.ctl-value {
  font-family: var(--font-sans); text-transform: none; letter-spacing: 0;
  font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 500; font-size: 13.5px;
}

input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 22px; background: transparent; margin: 0; cursor: pointer;
}
input[type=range]:focus { outline: none; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--line); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px; border-radius: 50%; margin-top: -7px;
  background: #fff; border: 2px solid var(--accent);
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
input[type=range]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: #fff; border: 2px solid var(--accent);
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
input[type=range]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--accent-bg); }
input[type=range].tinted::-webkit-slider-thumb { border-color: var(--tint, var(--accent)); }
input[type=range].tinted::-moz-range-thumb { border-color: var(--tint, var(--accent)); }

.btn-play {
  display: inline-flex; align-items: center; gap: 9px;
  background: var(--play); color: #fff; border: 0; border-radius: 999px;
  padding: 10px 22px 10px 18px; cursor: pointer;
  font-family: var(--font-sans); font-weight: 700; font-size: 13px; letter-spacing: 0.1em;
  transition: background 0.15s ease, transform 0.1s ease;
  flex: 0 0 auto;
}
.btn-play:hover { background: var(--play-dark); }
.btn-play:active { transform: scale(0.98); }
.btn-play .ico { width: 10px; height: 10px; display: inline-block; }
.btn-play .ico::before {
  content: ''; display: block; width: 0; height: 0;
  border-left: 10px solid #fff; border-top: 6px solid transparent; border-bottom: 6px solid transparent;
  margin-top: -1px;
}
.btn-play.playing { background: var(--stop); }
.btn-play.playing .ico::before { border: 0; width: 10px; height: 10px; background: #fff; border-radius: 1px; margin: 0; }
.btn-play:focus-visible { outline: 3px solid var(--accent-bg); outline-offset: 1px; }
.btn-play.small { padding: 7px 16px 7px 13px; font-size: 11.5px; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 16px; cursor: pointer; font-family: var(--font-sans); font-weight: 600; font-size: 13px;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.btn:hover { background: var(--panel); border-color: #cfcfca; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.primary:hover { background: #111; }
.btn.accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn:focus-visible { outline: 3px solid var(--accent-bg); outline-offset: 1px; }

.seg { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  background: #fff; color: var(--ink-2); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 13px; cursor: pointer; font-family: var(--font-sans); font-weight: 500; font-size: 13px;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.seg button:hover { border-color: #cfcfca; background: var(--panel); }
.seg button.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.seg button:focus-visible { outline: 3px solid var(--accent-bg); outline-offset: 1px; }
.seg.tinted button.active { background: var(--tint); border-color: var(--tint); }

.readout {
  font-size: 13.5px; color: var(--muted); display: inline-flex; gap: 8px; align-items: baseline;
  font-variant-numeric: tabular-nums;
}
.readout b { color: var(--ink); font-weight: 600; }
.readouts { display: flex; flex-wrap: wrap; gap: 6px 22px; margin-top: 10px; }

.chip {
  display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12.5px; font-weight: 600;
  background: var(--panel-2); color: var(--ink-2); font-variant-numeric: tabular-nums;
}
.chip.c1 { background: #fde6e5; color: #b2302f; }
.chip.c2 { background: #e4eefc; color: #1d5aa8; }
.chip.c3 { background: #fdf1d4; color: #946000; }
.chip.c4 { background: #ddf5ec; color: #0d7a52; }
.chip.c5 { background: #e8e3f7; color: #3e2f90; }
.chip.c6 { background: #fde7dd; color: #b1441a; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13px; color: var(--muted); margin-top: 8px; }
.legend span::before {
  content: ''; display: inline-block; width: 18px; height: 3px; border-radius: 2px;
  background: var(--sw, var(--muted)); vertical-align: middle; margin-right: 7px;
}

/* key / piano */
.keys { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.key {
  width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer;
  font-family: var(--font-sans); font-weight: 700; font-size: 14px; color: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.12); transition: transform 0.08s ease, filter 0.15s ease;
}
.key:hover { filter: brightness(1.08); }
.key:active, .key.on { transform: scale(0.94); filter: brightness(0.9); }

/* tables */
.tbl { width: 100%; border-collapse: collapse; font-size: 14.5px; margin: 12px 0 6px; }
.tbl th { text-align: left; font-size: 11.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 8px 10px 8px 0; border-bottom: 1px solid var(--line); }
.tbl td { padding: 9px 10px 9px 0; border-bottom: 1px solid var(--line); vertical-align: top; color: var(--ink-2); }
.tbl td:first-child { color: var(--ink); font-weight: 500; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl.compact td, .tbl.compact th { padding-top: 6px; padding-bottom: 6px; }

/* quiz / reveal */
details.answer { margin: 10px 0 0; }
details.answer summary { cursor: pointer; color: var(--accent); font-size: 15px; list-style: none; }
details.answer summary::-webkit-details-marker { display: none; }
details.answer summary::after { content: ' »'; }
details.answer[open] summary::after { content: ' «'; }
details.answer .body { margin-top: 10px; padding: 12px 16px; background: var(--panel); border-radius: var(--radius); font-size: 15.5px; }

/* next lesson */
.next {
  margin-top: 40px; padding-top: 24px; border-top: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.next .label { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.next a.title { font-family: var(--font-serif); font-size: 22px; color: var(--ink); }
.next a.title:hover { color: var(--accent); text-decoration: none; }

/* module cards (end of 101) */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin: 20px 0; }
.card {
  display: block; padding: 20px 22px; border: 1px solid var(--line); border-radius: 10px; color: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.card:hover { text-decoration: none; border-color: #cfcfca; box-shadow: 0 2px 10px rgba(0,0,0,0.05); }
.card .kicker { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: #1f9d55; font-weight: 700; }
.card h4 { font-family: var(--font-serif); font-weight: 400; font-size: 23px; color: var(--ink); margin: 6px 0 6px; }
.card p { font-size: 15px; color: var(--muted); margin: 0; }

footer.site {
  margin-top: 80px; padding-top: 24px; border-top: 1px solid var(--line);
  font-size: 13.5px; color: var(--muted); line-height: 1.6;
}

/* utility */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.tnum { font-variant-numeric: tabular-nums; }
.x1 { color: var(--c-1x); font-weight: 600; }
.x2 { color: var(--c-2x); font-weight: 600; }
.x3 { color: var(--c-3x); font-weight: 600; }
.x4 { color: var(--c-4x); font-weight: 600; }
.x5 { color: var(--c-5x); font-weight: 600; }
.x6 { color: var(--c-6x); font-weight: 600; }
.cb { color: var(--c-bearing); font-weight: 600; }
.cg { color: var(--c-gear); font-weight: 600; }
.ce { color: #b98000; font-weight: 600; }
.cd { color: var(--c-disp); font-weight: 600; }
.cv { color: var(--c-vel); font-weight: 600; }
.ca { color: var(--c-acc); font-weight: 600; }
