:root {
  --page: #f7f8f9;
  --surface: #ffffff;
  --ink: #222f3a;
  --ink-soft: #5f6c78;
  --line: #dbe2e8;
  --line-strong: #cbd5de;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Source Serif 4", Georgia, serif;
  color: var(--ink);
  background: var(--page);
  line-height: 1.64;
}

main {
  padding: 2.2rem 0 3rem;
}

.hero,
.textbook-nav,
.story-copy,
footer p {
  width: min(100% - 2.2rem, 780px);
  margin-inline: auto;
}

.hero {
  margin-bottom: 1.5rem;
}

.eyebrow {
  margin: 0 0 0.45rem;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  font-size: 0.71rem;
  color: #6e8396;
  font-family: "IBM Plex Sans", "Avenir Next", sans-serif;
}

h1,
h2 {
  margin: 0;
  line-height: 1.1;
  font-weight: 600;
  letter-spacing: -0.01em;
}

h1 {
  font-size: clamp(2rem, 4.5vw, 3.3rem);
}

h2 {
  font-size: clamp(1.35rem, 2.4vw, 1.95rem);
}

.lede {
  margin: 0.9rem 0 0;
  color: var(--ink-soft);
  font-size: clamp(1.02rem, 1.7vw, 1.16rem);
}

.textbook-nav {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 9px;
  padding: 0.8rem 0.9rem;
  margin-bottom: 2rem;
}

.textbook-nav h2 {
  font-size: 1.07rem;
  font-family: "IBM Plex Sans", "Avenir Next", sans-serif;
  font-weight: 600;
}

.textbook-nav ol {
  margin: 0.6rem 0 0;
  padding-left: 1.1rem;
}

.textbook-nav li + li {
  margin-top: 0.22rem;
}

.textbook-nav li.outline-part {
  list-style: none;
  margin: 0.62rem 0 0.18rem -0.9rem;
  padding: 0.2rem 0.55rem;
  border-left: 2px solid var(--line-strong);
  color: #4d6274;
  font: 600 0.76rem/1.35 "IBM Plex Sans", "Avenir Next", sans-serif;
  letter-spacing: 0.02em;
}

.textbook-nav a {
  color: #325978;
  text-decoration: none;
  border-bottom: 1px dotted transparent;
}

.textbook-nav a:hover {
  border-bottom-color: currentColor;
}

.story {
  margin: 0 0 3rem;
}

.part-banner {
  margin-bottom: 1.6rem;
}

.part-banner .story-copy {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  padding: 0.8rem 0.9rem;
}

.story-grid {
  display: block;
}

.chapter-number {
  margin: 0 0 0.36rem;
  font: 600 0.73rem/1 "IBM Plex Sans", "Avenir Next", sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #6a8196;
}

.story-copy p {
  margin: 0.75rem 0 0;
  color: var(--ink-soft);
}

.guide-block {
  margin-top: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfdff;
  padding: 0.62rem 0.72rem;
}

.guide-title {
  margin: 0;
  color: #334d63;
  font: 600 0.83rem/1.3 "IBM Plex Sans", "Avenir Next", sans-serif;
  letter-spacing: 0.02em;
}

.guide-list {
  margin: 0.45rem 0 0;
  padding-left: 1.05rem;
  color: #4d6070;
}

.guide-list li + li {
  margin-top: 0.28rem;
}

.implementation-block {
  margin-top: 0.86rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfdff;
  padding: 0.62rem 0.7rem;
}

.implementation-block pre {
  margin: 0.5rem 0 0;
  padding: 0.54rem 0.62rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7fafc;
  overflow-x: auto;
}

.implementation-block code {
  font: 0.8rem/1.45 "IBM Plex Mono", monospace;
  color: #344a5e;
}

.equation-block {
  margin: 0.72rem 0 0;
  padding: 0.62rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfdff;
  color: #2d3e4d;
  font-size: 1rem;
  line-height: 1.45;
  overflow-x: auto;
}

.note-block {
  margin-top: 0.85rem;
  border-left: 2px solid var(--line-strong);
  padding-left: 0.75rem;
  font-size: 0.98rem;
  color: #4f5f6e;
}

.viz-panel {
  width: min(1240px, calc(100vw - 2rem));
  margin: 1.05rem auto 0;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  overflow: hidden;
  position: relative;
}

canvas {
  width: 100%;
  display: block;
  border-bottom: 1px solid var(--line);
  background: #fdfefe;
}

.canvas-play-overlay {
  position: absolute;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, rgba(248, 251, 254, 0.56) 0%, rgba(241, 246, 251, 0.78) 70%);
  pointer-events: none;
}

.canvas-play-overlay.is-hidden {
  display: none;
}

.canvas-play-button {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  border: 1px solid #a9b9c7;
  background: rgba(255, 255, 255, 0.96);
  color: #1f3344;
  border-radius: 999px;
  padding: 0.72rem 1.12rem;
  font: 600 1.05rem "IBM Plex Sans", "Avenir Next", sans-serif;
  box-shadow: 0 10px 24px rgba(67, 88, 106, 0.2);
}

.canvas-play-button:hover {
  background: #ffffff;
}

.canvas-play-button__icon {
  width: 0;
  height: 0;
  border-top: 0.42rem solid transparent;
  border-bottom: 0.42rem solid transparent;
  border-left: 0.67rem solid #2f668e;
  margin-left: 0.12rem;
}

.controls {
  padding: 0.7rem 0.78rem 0.8rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 0.65rem 0.9rem;
  font-family: "IBM Plex Sans", "Avenir Next", sans-serif;
  font-size: 0.88rem;
}

.controls label {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.55rem;
  color: #3b4b59;
}

.controls label input[type="range"] {
  grid-column: 1 / -1;
}

.controls input[type="range"] {
  accent-color: #637f96;
}

.controls span {
  font-family: "IBM Plex Mono", monospace;
  color: #4e6a81;
}

.control-help {
  margin: 0;
  color: #465a69;
  font: 0.85rem/1.45 "IBM Plex Sans", "Avenir Next", sans-serif;
}

.control-value {
  font-family: "IBM Plex Mono", monospace;
  color: #4e6a81;
  align-self: center;
}

.button-row {
  display: flex;
  gap: 0.52rem;
  align-items: center;
  flex-wrap: wrap;
}

.controls .button-row,
.controls .checkbox {
  grid-column: 1 / -1;
}

button {
  appearance: none;
  border: 1px solid #c3ced8;
  background: #f4f7fa;
  color: #24303c;
  border-radius: 5px;
  padding: 0.35rem 0.72rem;
  font: 500 0.82rem "IBM Plex Sans", "Avenir Next", sans-serif;
  cursor: pointer;
}

button:hover {
  background: #edf2f7;
}

button.secondary {
  background: #fafcfe;
}

#linkedNext {
  background: #e7f0f8;
  border-color: #adc3d6;
  font-weight: 600;
}

#linkedNext:hover {
  background: #dbe9f6;
}

.checkbox {
  grid-template-columns: auto 1fr;
  gap: 0.4rem;
}

.checkbox input[type="checkbox"] {
  width: 0.95rem;
  height: 0.95rem;
  accent-color: #637f96;
}

footer {
  margin: 0 auto 2.2rem;
  color: #6b7784;
  font-size: 0.92rem;
}

@media (max-width: 980px) {
  main {
    padding-top: 1.8rem;
  }

  .hero,
  .textbook-nav,
  .story-copy,
  footer p {
    width: min(100% - 1.25rem, 780px);
  }

  .viz-panel {
    width: calc(100vw - 1.2rem);
    margin-top: 0.95rem;
    border-radius: 6px;
  }

  .controls {
    grid-template-columns: 1fr;
    gap: 0.58rem;
  }
}
