:root {
  --paper: #f4f0e8;
  --paper-2: #ebe4d8;
  --ink: #202420;
  --muted: #666961;
  --line: rgba(32, 36, 32, 0.16);
  --accent: #f6c84c;
  --coral: #ff6d5a;
  --blue: #3978f6;
  --green: #b6df74;
  --cyan: #a9e4df;
  --white: #fffdf7;
  --mono: 'SFMono-Regular', 'Roboto Mono', Menlo, Consolas, monospace;
  --sans: 'PingFang SC', 'Noto Sans CJK SC', 'Microsoft YaHei', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --shadow: 0 24px 70px rgba(42, 38, 29, 0.11);
  --radius: 28px;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: 98px;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: inherit; }

.skip-link {
  position: fixed;
  left: 16px;
  top: -80px;
  z-index: 1000;
  padding: 10px 16px;
  background: var(--ink);
  color: white;
  border-radius: 8px;
}

.skip-link:focus { top: 16px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4vw;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.brand > span:last-child { display: grid; line-height: 1.2; }
.brand strong { font-size: 17px; letter-spacing: 0.05em; }
.brand small { color: var(--muted); font-size: 10px; letter-spacing: 0.12em; margin-top: 4px; }

.brand-mark {
  position: relative;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 50%;
  background: var(--ink);
}

.brand-mark i {
  width: 4px;
  margin: 0 2px;
  border-radius: 4px;
  background: var(--accent);
}

.brand-mark i:nth-child(1) { height: 11px; }
.brand-mark i:nth-child(2) { height: 22px; background: var(--coral); }
.brand-mark i:nth-child(3) { height: 16px; }

.top-actions { display: flex; align-items: center; gap: 12px; }
.button {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 20px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: transform .2s ease, box-shadow .2s ease, background .2s ease;
}

.button:hover { transform: translateY(-2px); box-shadow: 0 10px 25px rgba(32,36,32,.12); }
.button:active { transform: translateY(0); }
.button-dark { background: var(--ink); color: var(--white); border-color: var(--ink); }
.button-light { background: var(--white); color: var(--ink); border-color: transparent; }
.button-accent { background: var(--accent); color: var(--ink); border-color: transparent; }
.button-ghost { background: rgba(255,255,255,.28); }
.button.full { width: 100%; }
.button:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #8e948d;
  box-shadow: 0 0 0 4px rgba(255,255,255,.08);
}

.status-dot.connected { background: #72db67; }

.progress-chip {
  height: 46px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
}

.progress-chip > span {
  --progress: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: conic-gradient(var(--coral) calc(var(--progress) * 1%), var(--paper-2) 0);
  position: relative;
}

.progress-chip > span::after { content: ''; position: absolute; inset: 5px; border-radius: 50%; background: var(--paper); }
.progress-chip b { font: 500 12px var(--mono); }

.hero {
  min-height: calc(100vh - 82px);
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(420px, .95fr);
  align-items: center;
  gap: 7vw;
  padding: 8vh max(5vw, 40px) 110px;
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  width: 42vw;
  height: 42vw;
  left: -18vw;
  bottom: -29vw;
  border-radius: 50%;
  background: var(--coral);
  opacity: .92;
}

.hero-copy { position: relative; z-index: 2; max-width: 760px; }
.eyebrow { font: 500 12px var(--mono); text-transform: uppercase; letter-spacing: .12em; }
.eyebrow span { display: inline-grid; place-items: center; width: 29px; height: 29px; margin-right: 9px; background: var(--ink); color: white; border-radius: 50%; letter-spacing: 0; }
.hero h1 { margin: 22px 0; font-size: clamp(54px, 5.8vw, 88px); line-height: .99; letter-spacing: -.075em; font-weight: 900; }
.hero h1 em { color: var(--coral); font-style: normal; }
.hero-lead { max-width: 620px; font-size: clamp(17px, 1.5vw, 22px); color: var(--muted); }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 32px; }

.hero-orbit {
  position: relative;
  aspect-ratio: 1;
  max-width: 650px;
  width: 100%;
  justify-self: center;
}

.orbit-grid {
  position: absolute;
  inset: 5%;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: repeating-radial-gradient(circle, transparent 0 44px, rgba(32,36,32,.08) 45px 46px);
}

.orbit { position: absolute; inset: 12%; border: 1px solid rgba(32,36,32,.24); border-radius: 50%; animation: orbitSpin 14s linear infinite; }
.orbit span { position: absolute; top: -20px; left: 50%; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; background: var(--accent); font: 600 15px var(--mono); }
.orbit-b { inset: 25%; animation-duration: 9s; animation-direction: reverse; border-style: dashed; }
.orbit-b span { background: var(--coral); color: white; }
.orbit-c { inset: 37%; animation-duration: 6s; }
.orbit-c span { background: var(--blue); color: white; }
.orbit-center { position: absolute; inset: 40%; z-index: 3; display: grid; place-content: center; text-align: center; border-radius: 50%; background: var(--ink); color: white; box-shadow: var(--shadow); }
.orbit-center b { font: 500 clamp(23px,3vw,42px) var(--mono); white-space: nowrap; }
.orbit-center small { color: var(--accent); }
.orbit-caption { position: absolute; right: 0; bottom: 7%; padding: 13px 16px; background: var(--white); border: 1px solid var(--line); box-shadow: var(--shadow); font-size: 13px; transform: rotate(3deg); }
@keyframes orbitSpin { to { transform: rotate(360deg); } }

.hero-equation {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 74px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: clamp(11px, 3vw, 50px);
  background: var(--ink);
  color: white;
  font-size: clamp(14px, 1.5vw, 21px);
}
.hero-equation b { color: #81877f; font-weight: 400; }
.hero-equation strong { color: var(--accent); }

.chapter-nav {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  padding: 0 4vw;
  background: var(--white);
  border-bottom: 1px solid var(--line);
}
.chapter-nav a { min-height: 88px; display: grid; align-content: center; gap: 4px; padding-left: 18px; border-right: 1px solid var(--line); text-decoration: none; transition: background .2s; }
.chapter-nav a:first-child { border-left: 1px solid var(--line); }
.chapter-nav a:hover { background: var(--accent); }
.chapter-nav b { font: 500 10px var(--mono); color: var(--muted); }
.chapter-nav span { font-weight: 700; }

.lesson { padding: 120px max(6vw, 28px); border-bottom: 1px solid var(--line); }
.lesson-warm { background: #efc2a7; }
.lesson-ink { background: var(--ink); color: var(--white); }
.lesson-green { background: var(--green); }
.lesson-blue { background: var(--blue); color: var(--white); }
.lesson-heading { display: grid; grid-template-columns: 140px minmax(0, .85fr) minmax(320px, .55fr); gap: 28px; align-items: start; max-width: 1440px; margin: 0 auto 58px; }
.lesson-no { margin: 12px 0 0; font: 500 12px var(--mono); letter-spacing: .1em; text-transform: uppercase; }
.lesson-heading h2 { margin: 0; font-size: clamp(40px, 5vw, 78px); line-height: 1.08; letter-spacing: -.055em; }
.lesson-heading > p:last-child { margin: 12px 0 0; color: var(--muted); font-size: 17px; }
.lesson-ink .lesson-heading > p:last-child, .lesson-blue .lesson-heading > p:last-child { color: rgba(255,255,255,.65); }

.lab-card { max-width: 1280px; margin: 0 auto; background: var(--white); color: var(--ink); border: 1px solid rgba(32,36,32,.18); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.lesson-ink .lab-card { background: #2b302c; color: white; border-color: rgba(255,255,255,.14); }
.lesson-blue .lab-card { background: #245ec8; color: white; border-color: rgba(255,255,255,.18); }
.lab-play { margin-top: 24px; }

.rhythm-lab { display: grid; grid-template-columns: .85fr 1.15fr; min-height: 500px; }
.lab-copy { padding: 54px; }
.formula-card { display: flex; align-items: center; justify-content: center; gap: 18px; min-height: 100px; margin-bottom: 35px; border: 1px solid var(--line); border-radius: 18px; font: 500 17px var(--mono); }
.formula-card strong { width: 58px; height: 58px; display: grid; place-items: center; border-radius: 50%; background: var(--coral); color: white; font-size: 26px; }
.formula-card b { color: #999; }
.control-group, .beat-controls { display: grid; gap: 12px; }
label { font-weight: 700; }
label output { float: right; color: var(--coral); font: 500 13px var(--mono); }
input[type='range'] { width: 100%; accent-color: var(--coral); cursor: pointer; }
.segmented { display: flex; margin-top: 24px; padding: 5px; border-radius: 14px; background: var(--paper-2); }
.segmented button { flex: 1; min-height: 44px; padding: 0 10px; border: 0; border-radius: 10px; background: transparent; font-weight: 700; cursor: pointer; }
.segmented button.active { background: var(--ink); color: white; box-shadow: 0 6px 16px rgba(0,0,0,.12); }
.segmented.wrap { flex-wrap: wrap; }
.segmented.wrap button { flex-basis: 40%; }

.pulse-stage { display: grid; place-content: center; gap: 30px; padding: 50px; background: var(--ink); color: white; text-align: center; }
.pulse-track { width: min(42vw, 520px); height: 190px; display: flex; align-items: center; justify-content: space-around; gap: 20px; }
.pulse-dot { width: 72px; height: 72px; border-radius: 50%; background: var(--accent); transform: scale(.66); opacity: .34; transition: transform .12s, opacity .12s, box-shadow .12s; }
.pulse-dot:nth-child(2n) { background: var(--coral); }
.pulse-dot.active { opacity: 1; transform: scale(1); box-shadow: 0 0 0 18px rgba(246,200,76,.12); }
.pulse-stage p { color: rgba(255,255,255,.65); }
.pulse-stage p b { color: white; }
.insight { max-width: 1280px; margin: 22px auto 0; padding: 19px 24px; display: flex; gap: 35px; flex-wrap: wrap; border: 1px solid rgba(32,36,32,.2); border-radius: 15px; font-size: 13px; }
.insight b { font: 500 11px var(--mono); text-transform: uppercase; }

.frequency-lab { padding: 55px; }
.ratio-display { display: flex; justify-content: center; align-items: center; gap: clamp(25px, 8vw, 110px); text-align: center; }
.ratio-display div { display: grid; grid-template-columns: auto auto; align-items: baseline; column-gap: 6px; }
.ratio-display small { grid-column: 1 / -1; color: var(--muted); }
.ratio-display strong { font: 500 clamp(50px, 7vw, 100px) var(--mono); letter-spacing: -.08em; }
.ratio-display b { padding: 9px 14px; border-radius: 9px; background: var(--accent); font: 500 18px var(--mono); transform: rotate(-4deg); }
.wave-pair { height: 180px; margin: 35px 0 20px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); overflow: hidden; }
.wave-pair svg { width: 100%; height: 100%; }
.wave { fill: none; stroke-width: 3; vector-effect: non-scaling-stroke; }
.base-wave { stroke: var(--coral); }
.target-wave { stroke: var(--blue); opacity: .7; }
.ratio-controls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.ratio-controls button { min-height: 82px; border: 1px solid var(--line); border-radius: 14px; background: transparent; cursor: pointer; display: grid; place-content: center; }
.ratio-controls button.active { background: var(--ink); color: white; border-color: var(--ink); }
.ratio-controls b { font: 500 18px var(--mono); }
.ratio-controls span { font-size: 12px; opacity: .65; }

.temperament-lab { padding: 65px; }
.equation-large { text-align: center; font: 400 clamp(24px, 4.2vw, 64px) var(--mono); letter-spacing: -.05em; }
.equation-large strong { color: var(--accent); }
.step-viz { display: flex; align-items: end; gap: 6px; height: 180px; margin: 50px 0 35px; }
.step-viz i { flex: 1; min-width: 3px; border-radius: 5px 5px 0 0; background: rgba(255,255,255,.16); transition: height .2s, background .2s; }
.step-viz i.active { background: var(--accent); }
.temperament-lab label { display: block; max-width: 750px; margin: 0 auto 10px; }
.temperament-lab input { display: block; max-width: 750px; margin: auto; accent-color: var(--accent); }
.temperament-lab .lab-play { display: flex; margin: 28px auto 0; }

.clock-lab { display: grid; grid-template-columns: 1fr .8fr; padding: 50px; align-items: center; gap: 70px; }
.pitch-clock { position: relative; width: min(50vw, 520px); aspect-ratio: 1; border: 1px solid var(--line); border-radius: 50%; background: radial-gradient(circle, var(--paper) 0 25%, transparent 25.5% 100%); }
.pitch-clock::after { content: 'mod 12'; position: absolute; inset: 38%; display: grid; place-items: center; border-radius: 50%; background: var(--ink); color: white; font: 500 15px var(--mono); }
.clock-note { position: absolute; width: 52px; height: 52px; left: calc(50% - 26px); top: calc(50% - 26px); border: 1px solid var(--line); border-radius: 50%; background: var(--white); font: 500 13px var(--mono); cursor: pointer; transform: rotate(calc(var(--i) * 30deg)) translateY(-215px) rotate(calc(var(--i) * -30deg)); z-index: 2; }
.clock-note.root { background: var(--coral); color: white; border-color: transparent; }
.clock-note.result { box-shadow: 0 0 0 7px var(--accent); }
.clock-equation { font: 500 clamp(24px, 3.5vw, 50px) var(--mono); }
.clock-equation strong { color: var(--coral); }
.clock-equation small { display: block; color: var(--muted); font-size: 14px; margin-top: 10px; }
.clock-copy label { display: block; margin-top: 40px; }
.microcopy { color: var(--muted); font-size: 14px; }

.chord-lab { display: grid; grid-template-columns: 1fr 1fr; }
.chord-result { min-height: 420px; padding: 58px; display: grid; align-content: center; background: var(--ink); color: white; }
.chord-result small { color: var(--green); font: 500 12px var(--mono); }
.chord-result > p { margin: 18px 0 6px; font: 500 clamp(35px,5vw,70px) var(--mono); letter-spacing: -.06em; }
.chord-result h3 { margin: 0 0 30px; font-size: 22px; }
.note-pills { display: flex; gap: 9px; }
.note-pills span { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 50%; background: var(--green); color: var(--ink); font-weight: 800; }
.chord-controls { padding: 58px; align-content: center; display: grid; }
select { width: 100%; min-height: 50px; margin-top: 8px; padding: 0 15px; border: 1px solid var(--line); border-radius: 12px; background: var(--white); color: var(--ink); }

.harmonic-lab { padding: 40px 45px 50px; }
#harmonicCanvas { width: 100%; height: 280px; border-radius: 18px; background: var(--ink); }
.harmonic-controls { display: grid; grid-template-columns: repeat(8, 1fr); gap: 14px; margin-top: 28px; }
.harmonic-slider { display: grid; justify-items: center; gap: 9px; }
.harmonic-slider input { width: 100%; }
.harmonic-slider b { font: 500 11px var(--mono); }
.harmonic-slider span { font-size: 11px; color: var(--muted); }
.harmonic-actions { display: flex; gap: 10px; justify-content: center; margin-top: 28px; }

.beat-lab { display: grid; grid-template-columns: .8fr 1.2fr; padding: 55px; gap: 80px; align-items: center; }
.beat-orb { width: min(32vw, 350px); aspect-ratio: 1; display: grid; place-content: center; justify-self: center; text-align: center; border-radius: 50%; background: var(--accent); color: var(--ink); animation: breathe 500ms ease-in-out infinite alternate; box-shadow: 0 0 0 30px rgba(246,200,76,.08), 0 0 0 60px rgba(246,200,76,.04); }
.beat-orb span { font: 500 clamp(65px, 8vw, 110px) var(--mono); line-height: 1; }
.beat-orb small { font-weight: 700; }
@keyframes breathe { from { transform: scale(.93); } to { transform: scale(1.03); } }
.beat-controls { gap: 15px; }
.beat-controls label output { color: var(--accent); }
.beat-controls input { accent-color: var(--accent); }
.beat-formula { padding: 20px; border: 1px solid rgba(255,255,255,.18); border-radius: 14px; font: 500 22px var(--mono); text-align: center; }
.beat-formula strong { color: var(--accent); }

.transform-lab { padding: 50px; }
.melody-grid { position: relative; height: 300px; display: grid; grid-template-columns: repeat(8, 1fr); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; background: repeating-linear-gradient(to bottom, transparent 0 calc(12.5% - 1px), var(--line) calc(12.5% - 1px) 12.5%); }
.melody-grid::after { content: ''; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px dashed var(--coral); opacity: .6; }
.melody-column { position: relative; border-right: 1px solid var(--line); }
.melody-note { position: absolute; width: 38px; height: 38px; left: calc(50% - 19px); display: grid; place-items: center; border-radius: 50%; background: var(--coral); color: white; font: 500 10px var(--mono); transform: translateY(-50%); transition: top .35s cubic-bezier(.2,.8,.2,1); }
.melody-note.playing { box-shadow: 0 0 0 12px rgba(255,109,90,.2); transform: translateY(-50%) scale(1.15); }
.transform-controls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 28px 0; }
.transform-controls button { min-height: 78px; border: 1px solid var(--line); border-radius: 14px; background: transparent; cursor: pointer; }
.transform-controls button.active { background: var(--ink); color: white; }
.transform-controls b { display: block; font-size: 22px; }
.transform-controls span { font-size: 12px; }

.finale { padding: 150px 7vw 190px; background: var(--accent); text-align: center; }
.finale-copy { max-width: 900px; margin: auto; }
.finale h2 { font-size: clamp(43px, 6vw, 88px); line-height: 1.05; letter-spacing: -.06em; margin: 20px 0 30px; }
.finale-copy > p:last-child { max-width: 680px; margin: auto; font-size: 18px; }
.finale-map { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 15px; margin: 58px auto 38px; font: 500 15px var(--mono); }
.finale-map span, .finale-map strong { padding: 12px 17px; border: 1px solid rgba(32,36,32,.35); border-radius: 999px; }
.finale-map strong { background: var(--coral); color: white; border-color: transparent; }
.finale-map i { font-style: normal; }

.keyboard-dock { position: fixed; left: 0; right: 0; bottom: 0; z-index: 90; background: rgba(24,27,24,.97); color: white; box-shadow: 0 -15px 50px rgba(0,0,0,.2); transform: translateY(0); transition: transform .3s; }
.keyboard-dock.collapsed { transform: translateY(calc(100% + 38px)); }
.dock-toggle { position: absolute; top: -38px; right: 4vw; height: 38px; padding: 0 18px; border: 0; border-radius: 12px 12px 0 0; background: rgba(24,27,24,.97); color: white; cursor: pointer; }
.dock-toggle span { margin-right: 9px; font-size: 12px; }
.keyboard-shell { padding: 9px 4vw 12px; }
.keyboard-status { height: 24px; display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: rgba(255,255,255,.58); }
.keyboard-status button { border: 0; background: transparent; color: var(--accent); cursor: pointer; font-size: 11px; }
.piano { position: relative; height: 112px; width: 100%; max-width: 1300px; margin: auto; user-select: none; touch-action: none; }
.piano-key { position: absolute; top: 0; border: 1px solid #a5a49f; cursor: pointer; transition: background .08s, transform .08s, box-shadow .08s; }
.piano-key.white { height: 108px; z-index: 1; background: #f9f7ef; border-radius: 0 0 6px 6px; color: #777; }
.piano-key.black { height: 68px; z-index: 2; background: #272b27; border-color: #111; border-radius: 0 0 5px 5px; color: #bbb; box-shadow: 0 5px 8px rgba(0,0,0,.35); }
.piano-key span { position: absolute; bottom: 5px; left: 50%; transform: translateX(-50%); font: 500 8px var(--mono); pointer-events: none; }
.piano-key.lit { background: var(--key-color, var(--accent)); color: var(--ink); box-shadow: 0 0 18px var(--key-color, var(--accent)); }
.piano-key.pressed { transform: translateY(3px); filter: brightness(.82); }

.midi-dialog { width: min(92vw, 560px); padding: 0; border: 0; border-radius: 24px; background: var(--white); color: var(--ink); box-shadow: 0 30px 100px rgba(0,0,0,.35); }
.midi-dialog::backdrop { background: rgba(18,20,18,.68); backdrop-filter: blur(8px); }
.midi-dialog form { position: relative; padding: 42px; }
.midi-dialog h2 { margin: 12px 0; font-size: 34px; line-height: 1.18; letter-spacing: -.04em; }
.midi-dialog form > p:not(.eyebrow):not(.dialog-note) { color: var(--muted); }
.dialog-close { position: absolute; right: 20px; top: 18px; width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 50%; background: transparent; font-size: 24px; cursor: pointer; }
.connection-state { display: flex; align-items: center; gap: 15px; margin: 28px 0; padding: 17px; border-radius: 15px; background: var(--paper); }
.connection-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; background: var(--ink); color: var(--accent); font-size: 23px; }
.connection-state div { display: grid; }
.connection-state small { color: var(--muted); }
.select-label { display: block; font-size: 13px; }
.midi-dialog select { margin-bottom: 16px; }
.dialog-note { margin: 16px 0 0; text-align: center; color: var(--muted); font-size: 12px; }

footer { min-height: 220px; display: grid; grid-template-columns: 1fr auto; align-content: center; gap: 8px 35px; padding: 55px 6vw 150px; background: var(--ink); color: rgba(255,255,255,.6); font-size: 12px; }
.footer-brand { grid-row: span 2; color: white; }
footer p { margin: 0; text-align: right; }
footer a { color: var(--accent); }

.toast { position: fixed; left: 50%; bottom: 175px; z-index: 200; max-width: min(90vw, 520px); padding: 12px 18px; border-radius: 999px; background: var(--ink); color: white; font-size: 13px; box-shadow: var(--shadow); opacity: 0; transform: translate(-50%, 15px); pointer-events: none; transition: opacity .25s, transform .25s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.reveal { opacity: 0; transform: translateY(24px); transition: opacity .7s ease, transform .7s ease; }
.reveal.visible { opacity: 1; transform: translateY(0); }

@media (max-width: 1050px) {
  .hero { grid-template-columns: 1fr; padding-top: 80px; }
  .hero-orbit { width: min(76vw, 560px); }
  .chapter-nav { grid-template-columns: repeat(4, 1fr); }
  .lesson-heading { grid-template-columns: 90px 1fr; }
  .lesson-heading > p:last-child { grid-column: 2; }
  .clock-note { transform: rotate(calc(var(--i) * 30deg)) translateY(-20vw) rotate(calc(var(--i) * -30deg)); }
}

@media (max-width: 760px) {
  html { scroll-padding-top: 72px; }
  .topbar { height: 68px; padding: 0 16px; }
  .brand small { display: none; }
  .brand strong { font-size: 15px; }
  .brand-mark { width: 34px; height: 34px; }
  .progress-chip { display: none; }
  .top-actions .button { min-height: 40px; padding: 0 13px; font-size: 12px; }
  .hero { min-height: auto; grid-template-columns: 1fr; gap: 40px; padding: 70px 22px 118px; }
  .hero h1 { font-size: 44px; }
  .hero-actions { display: grid; }
  .hero-orbit { width: 94vw; margin-left: -8vw; }
  .orbit-center { inset: 38%; }
  .orbit-grid { inset: 8%; }
  .orbit { inset: 14%; }
  .orbit-b { inset: 27%; }
  .orbit-c { inset: 39%; }
  .orbit-caption { right: 8%; }
  .hero-equation { gap: 8px; height: 62px; font-size: 11px; }
  .chapter-nav { grid-template-columns: repeat(4, 1fr); padding: 0; }
  .chapter-nav a { min-height: 67px; padding-left: 13px; }
  .lesson { padding: 82px 18px; }
  .lesson-heading { grid-template-columns: 1fr; gap: 10px; margin-bottom: 35px; }
  .lesson-heading > p:last-child { grid-column: auto; }
  .lesson-heading h2 { font-size: 42px; }
  .lab-card { border-radius: 20px; }
  .rhythm-lab, .clock-lab, .chord-lab, .beat-lab { grid-template-columns: 1fr; }
  .lab-copy, .frequency-lab, .temperament-lab, .clock-lab, .chord-result, .chord-controls, .harmonic-lab, .beat-lab, .transform-lab { padding: 28px 20px; }
  .pulse-stage { padding: 35px 20px; }
  .pulse-track { width: 100%; height: 120px; }
  .pulse-dot { width: 54px; height: 54px; }
  .formula-card { gap: 8px; font-size: 13px; }
  .formula-card strong { width: 48px; height: 48px; }
  .insight { gap: 12px; }
  .ratio-display { gap: 12px; }
  .ratio-display strong { font-size: 45px; }
  .ratio-controls { grid-template-columns: repeat(2, 1fr); }
  .equation-large { font-size: 25px; }
  .step-viz { height: 120px; }
  .pitch-clock { width: calc(100vw - 76px); }
  .clock-note { width: 40px; height: 40px; left: calc(50% - 20px); top: calc(50% - 20px); transform: rotate(calc(var(--i) * 30deg)) translateY(calc((100vw - 112px) / -2)) rotate(calc(var(--i) * -30deg)); }
  .clock-copy { text-align: center; }
  .clock-copy label { text-align: left; }
  .note-pills span { width: 42px; height: 42px; }
  #harmonicCanvas { height: 190px; }
  .harmonic-controls { grid-template-columns: repeat(4, 1fr); }
  .harmonic-actions { flex-direction: column; }
  .beat-lab { gap: 50px; }
  .beat-orb { width: 230px; }
  .transform-controls { grid-template-columns: repeat(2, 1fr); }
  .melody-grid { height: 230px; }
  .finale { padding: 100px 22px 155px; }
  .finale h2 { font-size: 43px; }
  .piano { height: 90px; overflow-x: auto; }
  .piano-key.white { height: 86px; }
  .piano-key.black { height: 53px; }
  .keyboard-shell { padding-inline: 8px; }
  .midi-dialog form { padding: 34px 22px; }
  footer { grid-template-columns: 1fr; padding: 50px 24px 145px; }
  footer p { text-align: left; }
}

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