@import url('https://fonts.googleapis.com/css2?family=Sora:wght@400;600;700;800&family=DM+Mono:wght@400;500&display=swap');

:root {
  color-scheme: light dark;
  --bg-1: #f5f2e9;
  --bg-2: #ece7dc;
  --ink: #132433;
  --muted: #4f687b;
  --panel: rgba(255, 255, 255, 0.72);
  --line: rgba(20, 35, 43, 0.12);
  --accent: #0aa888;
  --accent-2: #3b82f6;
  --accent-3: #60a5fa;
  --math-ink: #075985;
  --math-bg: rgba(14, 116, 144, 0.1);
  --shadow: 0 14px 40px rgba(16, 37, 45, 0.15);
  --radius: 18px;
  --card-bg: rgba(255, 255, 255, 0.74);
  --input-bg: #ffffff;
  --graph-bg-top: rgba(255, 255, 255, 0.94);
  --graph-bg-bottom: rgba(242, 249, 255, 0.94);
  --legend-bg: rgba(255, 255, 255, 0.9);
  --live-bg: rgba(255, 255, 255, 0.45);

  --grid-major: rgba(20, 35, 43, 0.2);
  --grid-minor: rgba(20, 35, 43, 0.09);
  --axis-color: rgba(17, 34, 49, 0.6);
  --point-stroke: #ffffff;

  --color-original: #0aa888;
  --color-transformed: #3b82f6;
  --color-basis-alpha: rgba(96, 165, 250, 0.7);
  --color-transformed-alpha: rgba(59, 130, 246, 0.72);

  /* Textbook scale */
  --tb-space-1: 0.5rem;
  --tb-space-2: 1rem;
  --tb-space-3: 1.5rem;
  --tb-space-4: 2rem;
  --tb-space-5: 3rem;
  --tb-indent: 1.5rem;
  --tb-leading: 1.9;
  --tb-body-size: 1rem;
  --tb-h2-size: 1.2rem;
  --tb-h3-size: 1rem;
  --tb-max-width: 980px;
}

[data-theme="dark"] {
  color-scheme: dark;
}

[data-theme="light"] {
  color-scheme: light;
  --bg-1: #f5f2e9;
  --bg-2: #ece7dc;
  --ink: #132433;
  --muted: #4f687b;
  --panel: rgba(255, 255, 255, 0.72);
  --line: rgba(20, 35, 43, 0.12);
  --shadow: 0 14px 40px rgba(16, 37, 45, 0.15);
  --card-bg: rgba(255, 255, 255, 0.74);
  --input-bg: #ffffff;
  --graph-bg-top: rgba(255, 255, 255, 0.94);
  --graph-bg-bottom: rgba(242, 249, 255, 0.94);
  --legend-bg: rgba(255, 255, 255, 0.9);
  --live-bg: rgba(255, 255, 255, 0.45);
  --grid-major: rgba(20, 35, 43, 0.2);
  --grid-minor: rgba(20, 35, 43, 0.09);
  --axis-color: rgba(17, 34, 49, 0.6);
  --point-stroke: #ffffff;
  --math-ink: #075985;
  --math-bg: rgba(14, 116, 144, 0.1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-1: #0b1117;
    --bg-2: #151f2a;
    --ink: #e9f2f8;
    --muted: #9bb3c2;
    --panel: rgba(18, 28, 38, 0.82);
    --line: rgba(178, 214, 232, 0.16);
    --shadow: 0 14px 44px rgba(0, 0, 0, 0.45);
    --card-bg: rgba(20, 33, 45, 0.72);
    --input-bg: #101a24;
    --graph-bg-top: rgba(9, 14, 20, 0.92);
    --graph-bg-bottom: rgba(13, 21, 31, 0.94);
    --legend-bg: rgba(13, 22, 31, 0.86);
    --live-bg: rgba(9, 16, 24, 0.78);

    --grid-major: rgba(187, 221, 236, 0.2);
    --grid-minor: rgba(187, 221, 236, 0.09);
    --axis-color: rgba(227, 241, 248, 0.6);
    --point-stroke: #09121a;
    --math-ink: #e0f2fe;
    --math-bg: rgba(125, 211, 252, 0.1);
  }
}

[data-theme="dark"] {
  --bg-1: #0b1117;
  --bg-2: #151f2a;
  --ink: #e9f2f8;
  --muted: #9bb3c2;
  --panel: rgba(18, 28, 38, 0.82);
  --line: rgba(178, 214, 232, 0.16);
  --shadow: 0 14px 44px rgba(0, 0, 0, 0.45);
  --card-bg: rgba(20, 33, 45, 0.72);
  --input-bg: #101a24;
  --graph-bg-top: rgba(9, 14, 20, 0.92);
  --graph-bg-bottom: rgba(13, 21, 31, 0.94);
  --legend-bg: rgba(13, 22, 31, 0.86);
  --live-bg: rgba(9, 16, 24, 0.78);
  --grid-major: rgba(187, 221, 236, 0.2);
  --grid-minor: rgba(187, 221, 236, 0.09);
  --axis-color: rgba(227, 241, 248, 0.6);
  --point-stroke: #09121a;
  --math-ink: #e0f2fe;
  --math-bg: rgba(125, 211, 252, 0.1);
}

[data-theme="light"] {
  color-scheme: light;
  --bg-1: #f5f2e9;
  --bg-2: #ece7dc;
  --ink: #132433;
  --muted: #4f687b;
  --panel: rgba(255, 255, 255, 0.72);
  --line: rgba(20, 35, 43, 0.12);
  --shadow: 0 14px 40px rgba(16, 37, 45, 0.15);
  --card-bg: rgba(255, 255, 255, 0.74);
  --input-bg: #ffffff;
  --graph-bg-top: rgba(255, 255, 255, 0.94);
  --graph-bg-bottom: rgba(242, 249, 255, 0.94);
  --legend-bg: rgba(255, 255, 255, 0.9);
  --live-bg: rgba(255, 255, 255, 0.45);
  --grid-major: rgba(20, 35, 43, 0.2);
  --grid-minor: rgba(20, 35, 43, 0.09);
  --axis-color: rgba(17, 34, 49, 0.6);
  --point-stroke: #ffffff;
  --math-ink: #075985;
  --math-bg: rgba(14, 116, 144, 0.1);
}

.site-shell {
  display: grid;
  grid-template-columns: auto 1fr;
  min-height: calc(100vh - 3.5rem);
}

.site-drawer-main {
  width: 0;
  overflow: hidden;
  transition: width 333ms ease;
}

.site-drawer-main.is-open {
  width: 320px;
  padding: 1rem;
}

.drawer-panel {
  height: calc(100vh - 2rem);
  overflow: auto;
  padding: 0.2rem 0.2rem 1rem;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  backdrop-filter: none;
  opacity: 0;
  transform: translateX(-16px);
  transition: opacity 333ms ease, transform 333ms ease;
}

.site-drawer-main.is-open .drawer-panel {
  opacity: 1;
  transform: translateX(0);
}

.drawer-head {
  color: var(--ink);
  font-size: 1.1rem;
  margin: 0 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--line);
}

.drawer-sub {
  color: var(--accent-2);
  font-size: 0.9rem;
  font-weight: 800;
  text-transform: none;
  margin: 1.5rem 0 0.5rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--line);
  letter-spacing: 0;
}

.drawer-shell-link {
  display: block;
  text-decoration: none;
  color: var(--ink);
  border: 0;
  border-left: 2px solid transparent;
  padding: 0.35rem 0.5rem;
  margin-bottom: 0.3rem;
  font-size: 0.9rem;
  line-height: 1.5;
  background: transparent;
}

.drawer-shell-link.is-active {
  color: var(--accent-3);
  border-left-color: var(--accent-2);
  font-weight: 800;
}

.drawer-shell-link.is-placeholder {
  color: var(--muted);
}

.main-stage {
  min-width: 0;
}

.top-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 3.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--bg-1);
}

.book-heading {
  color: var(--ink);
  font-weight: 800;
  letter-spacing: 0.02em;
  font-size: 0.95rem;
  font-family: 'DM Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

.top-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.top-left button {
  width: auto;
  min-width: 5rem;
}

.top-controls {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
}

.header-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
}

.header-toggle input {
  width: auto;
  margin: 0;
}

.theme-mark {
  width: 1rem;
  height: 1rem;
  border-radius: 999px;
  background: radial-gradient(circle at 65% 35%, transparent 0 38%, currentColor 40% 100%);
  color: var(--muted);
}

.textbook-page {
  width: min(var(--tb-max-width), 94vw);
  margin: var(--tb-space-2) auto var(--tb-space-4);
}

.chapter-banner {
  border-bottom: 2px solid rgba(96, 165, 250, 0.55);
  padding: var(--tb-space-2) 0 var(--tb-space-2);
  margin-bottom: var(--tb-space-4);
}

.chapter-title {
  margin: 0;
  color: #7dd3fc;
  font-size: 1.7rem;
  line-height: 1.15;
  font-weight: 800;
}

.chapter-subtitle {
  margin: 0.5rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.home-banner {
  padding-top: var(--tb-space-3);
}

.home-kicker {
  margin: 0 0 0.45rem;
  color: #bbf7d0;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.home-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 1rem;
}

.home-actions .link-btn {
  width: auto;
  min-width: 9.5rem;
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 0.75rem;
}

.home-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.48);
  padding: 0.9rem;
}

.home-card h3 {
  margin: 0 0 0.45rem;
}

.home-card p {
  margin: 0;
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.6;
}

.home-card a {
  display: inline-block;
  margin-top: 0.7rem;
  color: #7dd3fc;
  font-size: 0.84rem;
  font-weight: 800;
  text-decoration: none;
}

.topic-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.6rem;
}

.topic-list a {
  display: block;
  min-height: 7.3rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(2, 6, 23, 0.22);
  padding: 0.75rem;
  color: var(--ink);
  text-decoration: none;
}

.topic-list strong,
.topic-list span {
  display: block;
}

.topic-list strong {
  color: #a5f3fc;
  font-size: 0.92rem;
}

.topic-list span {
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.problem-catalog {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.6rem;
  margin: var(--tb-space-2) 0;
}

.problem-chip {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(125, 211, 252, 0.08);
  padding: 0.65rem 0.75rem;
}

.problem-chip strong,
.problem-chip span {
  display: block;
}

.problem-chip strong {
  color: #a5f3fc;
  font-size: 0.86rem;
}

.problem-chip span {
  margin-top: 0.25rem;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.45;
}

.mini-lab {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card-bg);
  padding: 0.85rem;
  margin: var(--tb-space-2) 0 var(--tb-space-2) var(--tb-indent);
}

.mini-lab h3 {
  margin-top: 0;
}

.mini-lab-graph {
  width: 100%;
  min-height: 180px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, transparent 49%, var(--axis-color) 50%, transparent 51%),
    linear-gradient(0deg, transparent 49%, var(--axis-color) 50%, transparent 51%),
    repeating-linear-gradient(90deg, var(--grid-minor) 0 1px, transparent 1px 28px),
    repeating-linear-gradient(0deg, var(--grid-minor) 0 1px, transparent 1px 28px),
    var(--graph-bg-top);
  position: relative;
  overflow: hidden;
}

.mini-line {
  position: absolute;
  left: 5%;
  right: 5%;
  top: 48%;
  height: 3px;
  background: var(--color-transformed);
  transform: rotate(-22deg);
  transform-origin: center;
}

.mini-lab-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.mini-lab-controls label {
  display: grid;
  gap: 0.3rem;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: none;
  letter-spacing: 0;
}

.textbook-section {
  padding: 0;
  margin-bottom: var(--tb-space-4);
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  backdrop-filter: none;
}

.textbook-section h2 {
  margin: 0 0 var(--tb-space-2);
  color: #86efac;
  font-size: var(--tb-h2-size);
  border-bottom: 1px solid var(--line);
  padding-bottom: var(--tb-space-1);
}

.textbook-section h3 {
  margin: var(--tb-space-4) 0 var(--tb-space-1);
  font-size: var(--tb-h3-size);
  color: #a5f3fc;
  text-transform: none;
  letter-spacing: 0;
}

.prose {
  font-size: var(--tb-body-size);
  line-height: var(--tb-leading);
  color: var(--ink);
}

.math-inline {
  display: inline-block;
  padding: 0 0.22em;
  border-radius: 4px;
  background: var(--math-bg);
  color: var(--math-ink);
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1.04em;
  line-height: 1.25;
}

.keyfact {
  margin: var(--tb-space-2) 0 var(--tb-space-1);
  padding-left: 1rem;
  font-size: var(--tb-body-size);
  line-height: var(--tb-leading);
  color: var(--ink);
}

.key-heading {
  margin: var(--tb-space-2) 0 var(--tb-space-1);
  margin-left: var(--tb-indent);
  font-size: 0.98rem;
  font-weight: 700;
  color: #bbf7d0;
}

.key-text {
  margin: 0 0 var(--tb-space-2);
  margin-left: var(--tb-indent);
  font-size: var(--tb-body-size);
  line-height: var(--tb-leading);
}

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.55rem;
}

.thumb-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--input-bg);
  padding: 0.45rem;
}

.thumb-title {
  font-size: 0.8rem;
  font-weight: 700;
  margin-bottom: 0.3rem;
}

.thumb-canvas {
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.thumb-note {
  margin-top: 0.3rem;
  font-size: 0.74rem;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Sora', 'Avenir Next', 'Trebuchet MS', sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg-1), var(--bg-2));
  overflow: hidden;
}

body.page-doc {
  overflow: auto;
}

.app {
  width: min(1900px, 99vw);
  margin: 0.6rem auto;
  display: grid;
  grid-template-columns: clamp(440px, 38vw, 700px) 1fr;
  height: calc(100vh - 1.2rem);
  min-height: 0;
  align-items: stretch;
  gap: 1rem;
  animation: riseIn 520ms ease-out;
}

.lab-app {
  width: min(1600px, 96vw);
  height: calc(100vh - 5.8rem);
  margin-top: 0.75rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.controls {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  min-height: 0;
  height: 100%;
  overflow: auto;
}

.title {
  margin: 0;
  line-height: 1.12;
  font-size: 1.35rem;
  font-weight: 800;
}

.sub {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.87rem;
}

.card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.75rem;
  background: var(--card-bg);
  animation: fadeIn 360ms ease-out both;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  align-items: center;
}

.shape-switch {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
  gap: 0.35rem;
}

.shape-btn {
  border: 1px solid var(--line);
  background: var(--input-bg);
  color: var(--ink);
  border-radius: 9px;
  padding: 0.44rem 0.5rem;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.shape-btn.is-active {
  background: linear-gradient(135deg, var(--accent-2), #60a5fa);
  border-color: transparent;
  color: #fff;
}

label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 0.25rem;
  display: block;
}

input,
select,
button {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--line);
  font: inherit;
  padding: 0.48rem 0.55rem;
  background: var(--input-bg);
  color: var(--ink);
}

.link-btn {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--line);
  font: inherit;
  padding: 0.48rem 0.55rem;
  background: var(--input-bg);
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 150ms ease;
  display: block;
  text-align: center;
  text-decoration: none;
}

input:focus,
select:focus,
button:focus {
  outline: 2px solid rgba(59, 130, 246, 0.5);
  outline-offset: 1px;
}

.link-btn:focus {
  outline: 2px solid rgba(59, 130, 246, 0.5);
  outline-offset: 1px;
}

.matrix {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.matrix3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
}

.matrix input,
.mono {
  font-family: 'DM Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: 0.55rem;
}

.btn-row.single {
  grid-template-columns: 1fr;
}

button {
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 150ms ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 7px 18px rgba(0, 0, 0, 0.25);
}

.link-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 7px 18px rgba(0, 0, 0, 0.25);
}

button.secondary {
  background: linear-gradient(135deg, var(--accent-2), #60a5fa);
  color: white;
  border-color: transparent;
}

.link-btn.secondary {
  background: linear-gradient(135deg, var(--accent-2), #60a5fa);
  color: white;
  border-color: transparent;
}

button.ghost {
  background: var(--input-bg);
  color: var(--ink);
}

.formula {
  font-family: 'DM Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  color: var(--ink);
  line-height: 1.45;
  white-space: pre-wrap;
}

.tiny {
  margin-top: 0.3rem;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}

.vertex-list {
  display: grid;
  gap: 0.4rem;
  max-height: 190px;
  overflow: auto;
  padding-right: 0.15rem;
}

.vertex-item {
  display: grid;
  grid-template-columns: 24px 1fr 1fr;
  gap: 0.35rem;
  align-items: center;
  font-size: 0.8rem;
}

.vertex-list-3d .vertex-item {
  grid-template-columns: 24px 1fr 1fr 1fr;
}

.vertex-item span {
  font-family: 'DM Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--muted);
}

.canvas-wrap {
  position: relative;
  display: flex;
  padding: 0.75rem;
  min-height: 0;
  overflow: hidden;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: linear-gradient(to bottom, var(--graph-bg-top), var(--graph-bg-bottom));
}

.legend {
  position: absolute;
  top: 1.45rem;
  right: 1.45rem;
  background: var(--legend-bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.45rem 0.6rem;
  font-size: 0.74rem;
  color: var(--ink);
  backdrop-filter: blur(4px);
}

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  margin-right: 0.35rem;
  vertical-align: middle;
}

.dot-original { background: var(--color-original); }
.dot-transformed { background: var(--color-transformed); }
.dot-basis { background: var(--accent-3); }

.live-box {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--live-bg);
  padding: 0.6rem;
  font-family: 'DM Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.76rem;
  line-height: 1.4;
  color: var(--ink);
  max-height: 180px;
  overflow: auto;
}

body.page-3d {
  overflow: hidden;
}

body.page-3d .app {
  height: calc(100vh - 1.2rem);
  min-height: 0;
}

body.page-3d .controls {
  min-height: 0;
  height: 100%;
  overflow: auto;
}

body.page-3d .canvas-wrap {
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

body.page-3d canvas {
  aspect-ratio: 1 / 1;
  width: min(100%, calc(100vh - 3.1rem));
  height: auto;
  max-width: 100%;
  max-height: 100%;
}

body.page-doc {
  overflow: auto;
}

.doc-page {
  width: min(1240px, 96vw);
  margin: 0.8rem auto 1.2rem;
  display: grid;
  gap: 0.9rem;
}

.doc-layout {
  display: grid;
  grid-template-columns: minmax(220px, 260px) minmax(0, 1fr);
  gap: 0.9rem;
  align-items: start;
}

.site-drawer {
  position: sticky;
  top: 0.75rem;
  padding: 0.8rem;
}

.drawer-title {
  margin: 0 0 0.45rem;
  font-size: 0.88rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

.drawer-nav {
  display: grid;
  gap: 0.28rem;
}

.drawer-link {
  display: block;
  text-decoration: none;
  color: var(--ink);
  background: var(--input-bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0.35rem 0.45rem;
  font-size: 0.8rem;
  font-weight: 600;
}

.drawer-link:hover {
  border-color: var(--accent-2);
}

.chapter-flow {
  display: grid;
  gap: 0.9rem;
}

.transform-btns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.35rem;
  margin-top: 0.45rem;
}

.point-controls {
  display: grid;
  grid-template-columns: auto minmax(80px, 120px) auto minmax(80px, 120px);
  gap: 0.45rem;
  align-items: center;
  margin-top: 0.45rem;
}

.point-controls label {
  margin: 0;
  font-size: 0.72rem;
}

.combo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.35rem;
  margin-top: 0.45rem;
}

.combo-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--input-bg);
  padding: 0.42rem 0.5rem;
  font-size: 0.79rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
}

.combo-item input {
  width: auto;
  margin: 0;
}

.transform-canvas-wrap {
  margin-top: 0.6rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(to bottom, var(--graph-bg-top), var(--graph-bg-bottom));
}

#transformCanvas {
  width: 100%;
  height: 430px;
  display: block;
}

.matrix-vis {
  display: inline-flex;
  align-items: stretch;
  vertical-align: middle;
  min-width: 118px;
}

.matrix-bracket {
  width: 8px;
  border-top: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
}

.matrix-bracket.left {
  border-left: 2px solid var(--ink);
  border-right: 0;
  border-radius: 3px 0 0 3px;
}

.matrix-bracket.right {
  border-right: 2px solid var(--ink);
  border-left: 0;
  border-radius: 0 3px 3px 0;
}

.matrix-core {
  display: grid;
  grid-template-columns: repeat(2, minmax(34px, 1fr));
  grid-template-rows: repeat(2, 1fr);
  column-gap: 0.45rem;
  row-gap: 0.2rem;
  padding: 0.12rem 0.35rem;
}

.matrix-cell {
  text-align: center;
  font-family: 'DM Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.79rem;
  min-width: 2ch;
}

.doc-hero {
  padding: 1rem 1.05rem;
}

.doc-hero h1 {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.15;
}

.doc-hero p {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.doc-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.doc-card {
  padding: 0.9rem;
}

.doc-card h2 {
  margin: 0 0 0.55rem;
  font-size: 1rem;
}

.doc-card h3 {
  margin: 0.7rem 0 0.35rem;
  font-size: 0.82rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.doc-list {
  margin: 0;
  padding-left: 1rem;
  font-size: 0.86rem;
  line-height: 1.5;
}

.math-box {
  margin-top: var(--tb-space-1);
  padding: var(--tb-space-2) var(--tb-space-2);
  border: 0;
  border-left: 0;
  border-radius: 0;
  background: transparent;
  font-size: var(--tb-body-size);
  line-height: 1.7;
}

.math-display,
.math-note,
.math-formula {
  margin-top: var(--tb-space-1);
  padding: var(--tb-space-2);
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: var(--tb-body-size);
  line-height: 1.7;
}

.math-note {
  color: var(--muted);
}

.core-concept {
  margin: var(--tb-space-2) 0 var(--tb-space-2) var(--tb-indent);
  border-left: 4px solid #22c55e;
  border-radius: 8px;
  background: rgba(34, 197, 94, 0.12);
  padding: 0.85rem 1rem;
}

.core-concept strong {
  display: block;
  color: #bbf7d0;
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.core-concept p {
  margin: 0.35rem 0 0;
  color: var(--ink);
  font-size: 0.92rem;
  line-height: 1.55;
}

.site-ad-rail {
  position: fixed;
  right: 0.75rem;
  top: 5.2rem;
  width: 150px;
  z-index: 4;
}

.site-ad-box {
  display: block;
  min-height: 260px;
  border: 1px dashed rgba(125, 211, 252, 0.55);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.48);
  padding: 0.85rem;
  color: var(--muted);
  text-align: center;
  text-decoration: none;
}

.site-ad-box strong,
.site-ad-box span {
  display: block;
}

.site-ad-box strong {
  color: #a5f3fc;
  font-size: 0.78rem;
}

.site-ad-box span {
  margin-top: 0.45rem;
  font-size: 0.72rem;
  line-height: 1.45;
}

.site-footer-note {
  width: min(var(--tb-max-width), 94vw);
  margin: 0 auto var(--tb-space-4);
  color: var(--muted);
  font-size: 0.74rem;
  text-align: center;
}

.formula-list,
.solution-steps {
  margin: var(--tb-space-2) 0 var(--tb-space-2) var(--tb-indent);
  line-height: var(--tb-leading);
  color: var(--ink);
}

.solution-steps li + li {
  margin-top: 0.7rem;
}

.step-math {
  display: block;
  width: fit-content;
  max-width: 100%;
  margin-top: 0.25rem;
  padding: 0.35rem 0.55rem;
  border-radius: 6px;
  background: var(--math-bg);
  color: var(--math-ink);
  font-family: Georgia, 'Times New Roman', serif;
  line-height: 1.5;
}

.worked-example {
  margin-left: var(--tb-indent);
  margin-top: var(--tb-space-2);
}

.worked-example h4 {
  margin: 0;
  color: #a5f3fc;
  font-size: 1rem;
  line-height: var(--tb-leading);
}

.worked-example h4 + .prose {
  margin-top: 0;
}

.calculator-panel {
  margin-left: var(--tb-indent);
  padding: var(--tb-space-2) 0;
}

/* Section indentation for textbook prose flow */
.textbook-section > .prose,
.textbook-section > .keyfact,
.textbook-section > .math-box,
.textbook-section > .math-display,
.textbook-section > .math-note,
.textbook-section > .math-formula,
.textbook-section > .row,
.textbook-section > .doc-table {
  margin-left: var(--tb-indent);
}

.answer-grid {
  margin-left: var(--tb-indent);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--tb-space-2) var(--tb-space-3);
}

.answer-item {
  line-height: 1.8;
}

.answer-num {
  font-weight: 800;
}

input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type=number] {
  -moz-appearance: textfield;
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.doc-table th,
.doc-table td {
  border: 1px solid var(--line);
  padding: 0.44rem 0.45rem;
  text-align: left;
  vertical-align: top;
}

.doc-table th {
  background: var(--live-bg);
}


.membrane {
  display: grid;
  gap: 0.6rem;
}

.mem-group {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.5rem;
  background: var(--live-bg);
}

.mem-title {
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.mem-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 0.35rem;
}

.matrix-tile {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--input-bg);
  color: var(--ink);
  padding: 0.4rem;
  text-align: left;
}

.matrix-tile:hover {
  border-color: var(--accent-2);
}

.tile-matrix {
  font-family: 'DM Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.76rem;
  line-height: 1.2;
  white-space: pre;
}

.tile-note {
  margin-top: 0.25rem;
  font-size: 0.66rem;
  color: var(--muted);
}

@media (max-width: 980px) {
  .site-ad-rail {
    display: none;
  }

  body {
    overflow: auto;
  }

  .app {
    grid-template-columns: 1fr;
    height: auto;
    min-height: auto;
  }

  .site-shell {
    grid-template-columns: 1fr;
  }

  .site-drawer-main {
    width: 100% !important;
  }

  .drawer-panel {
    height: auto;
  }

  .controls {
    height: auto;
    overflow: visible;
  }

  canvas {
    height: 64vh;
  }

  body.page-3d {
    overflow: auto;
  }

  body.page-3d .app {
    height: auto;
  }

  body.page-3d .controls {
    overflow: visible;
  }

  body.page-3d canvas {
    width: 100%;
    aspect-ratio: auto;
    height: 64vh;
  }

  .doc-grid {
    grid-template-columns: 1fr;
  }

  .doc-layout {
    grid-template-columns: 1fr;
  }

  .site-drawer {
    position: static;
  }

  #transformCanvas {
    height: 58vh;
    min-height: 340px;
  }

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

}

@keyframes riseIn {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}


ul, ol {
  padding-left: 2rem;
}

ul {
  list-style-type: square;
}
