:root {
  color-scheme: light;
  --page: #ffffff;
  --bg: #f4f5f7;
  --ink: #17212b;
  --muted: #5d6b78;
  --line: #d9dee5;
  --line-strong: #c5ccd6;
  --field: #f1f3f6;
  --accent: #285f9f;
  --accent-soft: #e8f1fb;
  --max: 1440px;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-md: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.5rem;
  --text-2xl: 2rem;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Arial, Helvetica, sans-serif;
}

.site-top {
  background: var(--page);
  border-bottom: 1px solid var(--line);
  margin-bottom: 1rem;
}

.site-top-inner {
  width: min(var(--max), 96vw);
  margin: 0 auto;
  padding: 0.7rem 0;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
}

.site-mark {
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
}

.site-footer-panel {
  margin-top: 2rem;
  border-top: 1px solid var(--line);
  background: #eef1f5;
}

.site-footer-inner {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(280px, 0.7fr);
  gap: 1.5rem;
  width: min(var(--max), 96vw);
  margin: 0 auto;
  padding: 1.1rem 0 1.4rem;
  align-items: start;
}

.site-footer-copy {
  display: grid;
  gap: 0.35rem;
}

.site-footer-copy strong {
  color: var(--ink);
  font-size: var(--text-sm);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.site-footer-copy p {
  margin: 0;
  max-width: 52rem;
  color: var(--muted);
  font-size: var(--text-sm);
}

.site-footer-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  justify-content: flex-end;
  align-content: start;
}

.site-footer-link {
  color: var(--ink);
  font-size: var(--text-sm);
  text-decoration: none;
}

.site-footer-link.is-active {
  color: var(--accent);
  font-weight: 700;
}

.site-path {
  color: var(--muted);
  font-size: var(--text-sm);
}

.layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 1.25rem;
  width: min(var(--max), 96vw);
  margin: 0 auto;
  align-items: start;
}

.toc-drawer {
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow: auto;
  padding: 0.8rem;
  background: var(--page);
  border: 1px solid var(--line);
}

.toc-drawer h2 {
  margin: 0 0 0.65rem;
  color: var(--ink);
  font-size: var(--text-sm);
}

.toc-toggle {
  display: none;
}

.toc-section {
  margin: 1rem 0 0.35rem;
  color: var(--accent);
  font-size: var(--text-xs);
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.toc-link {
  display: block;
  padding: 0.28rem 0 0.28rem 1ch;
  color: var(--ink);
  font-size: var(--text-sm);
  line-height: 1.35;
  text-decoration: none;
}

.toc-link.is-active {
  color: var(--accent);
  font-weight: 800;
}

.sheet {
  margin-bottom: 3rem;
  padding: clamp(1.1rem, 2.2vw, 2.15rem);
  border: 1px solid var(--line);
  background: var(--page);
}

.sheet-head {
  padding-bottom: 1.15rem;
  border-bottom: 2px solid var(--line-strong);
}

.kicker {
  margin: 0 0 0.35rem;
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(1.6rem, 3vw, var(--text-2xl));
  line-height: 1.15;
}

.lede {
  max-width: 980px;
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: var(--text-md);
  line-height: 1.6;
}

section {
  padding: 1.35rem 0;
  border-bottom: 1px solid var(--line);
}

section:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

h2 {
  margin: 0 0 0.8rem;
  color: var(--accent);
  font-size: var(--text-lg);
  line-height: 1.3;
}

p { line-height: 1.6; }

.fact-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--line);
  background: var(--page);
}

.fact-table th,
.fact-table td {
  padding: 0.72rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  line-height: 1.5;
}

.fact-table th {
  background: var(--field);
  color: #314253;
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.fact-table td { font-size: var(--text-sm); }

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

.box,
.steps,
.calculator-output {
  display: grid;
  gap: 0.55rem;
  padding: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
}

.box {
  gap: 0.15rem;
  padding: 0.3rem 0.4rem;
}

.box strong,
.calculator-output strong {
  display: block;
  color: #314253;
  font-size: 10pt;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.math-field,
.steps span,
.math-line {
  font-size: 10pt;
}

.math-field {
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  padding: 0.1rem 0;
  background: transparent;
  overflow-x: auto;
  text-align: center;
}

.note {
  margin-top: 0.8rem;
  padding: 0.8rem;
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  color: #26394d;
  line-height: 1.6;
}

.section-stack {
  display: grid;
  gap: 0.85rem;
}

.examples {
  display: grid;
  gap: 0.85rem;
}

.example {
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) minmax(0, 1.2fr);
  gap: 0.85rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.example > div:first-child {
  display: grid;
  gap: 0.65rem;
  align-content: start;
}

.example h3 {
  margin: 0;
  color: var(--ink);
  font-size: var(--text-md);
}

.example p {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-sm);
}

.strategy {
  display: grid;
  gap: 0.15rem;
  padding: 0.65rem 0.7rem;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  color: #26394d;
  font-size: var(--text-sm);
  line-height: 1.55;
}

.strategy strong {
  display: block;
  color: #314253;
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.steps {
  gap: 0.1rem;
  align-content: start;
}

.steps span {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
}

.steps mjx-container[display="true"] {
  margin: 0;
  text-align: left !important;
}

.solve-flow {
  display: grid;
  gap: 0.6rem;
}

.switch-note {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 1.55;
}

.triangle-diagram {
  min-height: 180px;
  justify-content: center;
}

.calculator {
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) minmax(0, 1.35fr);
  gap: 0.85rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.calculator-controls,
.calculator-output {
  display: grid;
  gap: 0.75rem;
  align-content: start;
}

.calculator h3 {
  margin: 0;
  color: var(--ink);
  font-size: var(--text-md);
  line-height: 1.3;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.35rem;
}

.mode-tabs button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--page);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.mode-tabs button.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.calculator-inputs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.55rem;
}

.calculator-inputs.three {
  grid-template-columns: repeat(3, 1fr);
}

.calculator label {
  display: grid;
  gap: 0.25rem;
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.calculator input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 0.45rem 0.55rem;
  color: var(--ink);
  background: var(--page);
  font: inherit;
  font-size: var(--text-md);
}

.calculator-output strong {
  color: #314253;
}

.calculator-output {
  min-height: 150px;
  align-content: start;
}

.math-line {
  margin: 0;
  padding: 0.16rem 0;
  overflow-x: auto;
  color: var(--ink);
}

.math-line mjx-container[display="true"] {
  margin: 0;
  text-align: left !important;
}

.calculator-output.is-centered .math-line mjx-container[display="true"] {
  text-align: center !important;
}

.math-line.is-centered mjx-container[display="true"] {
  text-align: center !important;
}

.calculator-output.is-centered .hint {
  text-align: center;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 1.55;
}

.geometry-diagram {
  display: grid;
  min-height: 220px;
  align-items: center;
}

.geometry-diagram svg {
  display: block;
  width: min(100%, 420px);
  height: auto;
  margin: 0 auto;
  overflow: visible;
  color: var(--ink);
}

.geometry-shape,
.geometry-angle,
.geometry-right-angle {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.geometry-label rect {
  fill: transparent;
  stroke: transparent;
}

.geometry-label text {
  fill: currentColor;
  font-size: 14px;
  font-weight: 700;
}

.geometry-angle-label text {
  font-style: italic;
}

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

.graph-cue-card {
  display: grid;
  gap: 0.65rem;
  align-content: start;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.graph-cue-card h3,
.graph-cue-card h4 {
  margin: 0;
  color: var(--ink);
  font-size: var(--text-md);
  line-height: 1.3;
}

.graph-cue-card p {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 1.5;
}

.graph-cue {
  width: 100%;
}

.graph-cue svg {
  display: block;
  width: 100%;
  height: auto;
  margin: 0;
}

.graph-grid-minor {
  stroke: rgba(20, 35, 43, 0.08);
  stroke-width: 1;
}

.graph-grid-major {
  stroke: rgba(20, 35, 43, 0.14);
  stroke-width: 1.2;
}

.graph-axis {
  stroke: rgba(0, 0, 0, 0.5);
  stroke-width: 1.2;
  stroke-linecap: round;
}

.graph-curve {
  fill: none;
  stroke: #285f9f;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.graph-curve-alt {
  fill: none;
  stroke: #0aa888;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.graph-dashed {
  stroke-dasharray: 7 6;
}

.graph-region {
  fill: rgba(40, 95, 159, 0.14);
}

.graph-region-alt {
  fill: rgba(10, 168, 136, 0.16);
}

.graph-point {
  fill: #d9485f;
  stroke: #ffffff;
  stroke-width: 2;
}

.graph-zero {
  fill: #285f9f;
  stroke: #ffffff;
  stroke-width: 2;
}

.graph-extrema {
  fill: #0aa888;
  stroke: #ffffff;
  stroke-width: 2;
}

.graph-label text {
  fill: #314253;
  font-size: 0.75rem;
  font-weight: 700;
}

.graph-label rect {
  fill: rgba(255, 255, 255, 0.96);
  stroke: rgba(20, 35, 43, 0.12);
}

.graph-arrow {
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.demo-tool {
  display: grid;
  grid-template-columns: minmax(260px, 0.85fr) minmax(0, 1.15fr);
  gap: 0.85rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.demo-tool-panel,
.demo-tool-output {
  display: grid;
  gap: 0.75rem;
  align-content: start;
}

.demo-tool-output {
  min-width: 0;
}

.demo-tool-inputs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.55rem;
}

.demo-tool-inputs.three {
  grid-template-columns: repeat(3, 1fr);
}

.demo-tool-panel label {
  display: grid;
  gap: 0.25rem;
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.demo-tool-panel input,
.demo-tool-panel select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 0.45rem 0.55rem;
  color: var(--ink);
  background: var(--page);
  font: inherit;
  font-size: var(--text-md);
}

.demo-tool-preview {
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
}

.demo-tool-preview svg {
  display: block;
  width: 100%;
  height: auto;
}

.demo-tool-code {
  margin: 0;
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: 0.84rem/1.55 "SFMono-Regular", Menlo, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

.example-visual {
  display: grid;
  gap: 0.65rem;
  align-content: start;
}

.thumb-gallery {
  display: grid;
  gap: 0.85rem;
}

.thumb-gallery + .thumb-gallery {
  margin-top: 0.85rem;
}

.thumb-nav {
  display: grid;
  gap: 0.55rem;
}

.thumb-nav a {
  display: grid;
  gap: 0.35rem;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--page);
  color: inherit;
  text-decoration: none;
}

.thumb-nav strong {
  color: var(--ink);
}

.thumb-nav span {
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 1.45;
}

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

.thumb-card {
  display: grid;
  align-content: start;
  gap: 0.7rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.thumb-card h3,
.thumb-card h4 {
  margin: 0;
  color: var(--ink);
  font-size: var(--text-md);
  line-height: 1.3;
}

.thumb-card p {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-sm);
}

.thumb-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.thumb-pill {
  display: inline-flex;
  align-items: center;
  min-height: 1.65rem;
  padding: 0.2rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--field);
  color: #314253;
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.thumb-stage {
  position: relative;
  min-height: 190px;
  padding: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: linear-gradient(180deg, #ffffff 0%, #f7f9fc 100%);
  overflow: hidden;
}

.thumb-stage svg,
.thumb-stage canvas,
.thumb-stage .thumb-html-plane {
  display: block;
  width: 100%;
  height: auto;
}

.thumb-caption {
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 1.55;
}

.thumb-html-plane {
  position: relative;
  aspect-ratio: 1 / 1;
  background:
    linear-gradient(to right, rgba(23, 33, 43, 0.09) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(23, 33, 43, 0.09) 1px, transparent 1px),
    linear-gradient(to right, rgba(23, 33, 43, 0.18) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(23, 33, 43, 0.18) 1px, transparent 1px),
    #ffffff;
  background-size: 10% 10%, 10% 10%, 20% 20%, 20% 20%, auto;
  background-position: center center;
}

.thumb-html-plane::before,
.thumb-html-plane::after {
  content: "";
  position: absolute;
  background: rgba(23, 33, 43, 0.6);
}

.thumb-html-plane::before {
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
}

.thumb-html-plane::after {
  left: 0;
  right: 0;
  top: 50%;
  height: 2px;
  transform: translateY(-50%);
}

.thumb-html-layer {
  position: absolute;
  inset: 0;
}

.thumb-html-region {
  position: absolute;
  inset: 0;
  background: rgba(40, 95, 159, 0.14);
}

.thumb-html-line {
  position: absolute;
  height: 3px;
  transform-origin: center center;
  border-radius: 999px;
  background: #285f9f;
}

.thumb-html-curve {
  position: absolute;
  border: 3px solid #285f9f;
  border-color: #285f9f transparent transparent transparent;
  border-radius: 50%;
}

.thumb-html-point {
  position: absolute;
  width: 14px;
  height: 14px;
  margin-left: -7px;
  margin-top: -7px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: #d9485f;
  box-shadow: 0 0 0 1px rgba(23, 33, 43, 0.18);
}

.thumb-html-label {
  position: absolute;
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  color: #314253;
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}

@media (max-width: 760px) {
  body {
    background: var(--page);
  }

  .site-top {
    position: sticky;
    top: 0;
    z-index: 5;
    margin-bottom: 0;
  }

  .site-top-inner {
    width: 100%;
    padding: 0.72rem 1rem;
    justify-content: flex-start;
    gap: 0.35rem;
  }

  .site-mark {
    flex: 0 0 auto;
  }

  .site-mark::after {
    content: " \\ ";
    color: var(--muted);
    font-weight: 400;
  }

  .site-path {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .layout,
  .formula-row,
  .graph-cue-grid,
  .thumb-grid,
  .demo-tool,
  .calculator,
  .example {
    grid-template-columns: 1fr;
  }

  .calculator-inputs,
  .calculator-inputs.three,
  .demo-tool-inputs,
  .demo-tool-inputs.three {
    grid-template-columns: 1fr;
  }

  .layout {
    width: 100%;
    gap: 0;
  }

  .site-footer-inner {
    grid-template-columns: 1fr;
    width: 100%;
    padding: 1rem;
  }

  .site-footer-nav {
    justify-content: flex-start;
  }

  main {
    min-width: 0;
  }

  .sheet {
    margin-bottom: 0;
    padding: 1rem;
    border: 0;
  }

  .sheet-head {
    padding-top: 0.35rem;
  }

  h1 {
    font-size: clamp(1.5rem, 8vw, 1.85rem);
  }

  .lede {
    font-size: var(--text-md);
  }

  section {
    padding: 1rem 0;
  }

  .toc-drawer {
    position: static;
    max-height: none;
    padding: 0;
    border: 0;
  }

  .toc-toggle {
    display: flex;
    flex: 0 0 auto;
    width: 2.35rem;
    height: 2.35rem;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--page);
    color: var(--ink);
    font: inherit;
    font-size: 1.2rem;
    font-weight: 800;
    line-height: 1;
    padding: 0;
  }

  .toc-drawer h2 {
    display: none;
  }

  .toc-drawer nav {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    padding: 0 1rem;
    transform: translateY(-0.35rem);
    transition:
      max-height 300ms ease,
      opacity 240ms ease,
      padding 300ms ease,
      transform 300ms ease;
  }

  .toc-drawer.is-open nav {
    max-height: 70vh;
    overflow: auto;
    opacity: 1;
    padding: 0.2rem 1rem 0.9rem;
    transform: translateY(0);
    border-bottom: 1px solid var(--line);
  }

  .toc-section {
    margin-top: 0.9rem;
  }

  .toc-link {
    padding: 0.42rem 0;
  }

  .steps span {
    width: 100%;
  }

  .steps {
    padding: 0.55rem;
  }

  .math-field {
    width: 100%;
    padding: 0.1rem 0;
  }

  .fact-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}

@media (max-width: 760px) and (prefers-reduced-motion: reduce) {
  .toc-drawer nav {
    transition: none;
  }
}
