:root {
  --bg-0: #071326;
  --bg-1: #0c1e3c;
  --bg-2: #143364;
  --reading-measure: 80ch;
  --page-pad-x: 1.35rem;
  --sidebar-width: 13.5rem;
  --layout-gap: 1.2rem;
  --surface: #f4f8ff;
  --surface-soft: #eaf1ff;
  --surface-elevated: #ffffff;
  --ink: #142746;
  --muted: #475f84;
  --line: rgba(20, 59, 120, 0.18);
  --line-strong: rgba(20, 59, 120, 0.28);
  --accent: #1d4ed8;
  --accent-soft: #3b82f6;
  --accent-faint: rgba(59, 130, 246, 0.12);
  --invest: #1d4ed8;
  --dep: #0284c7;
  --shock: #7dd3fc;
  --math-mtext-font: "Times New Roman", Times, serif;
  --inline-math-offset: 0.15ex;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Source Sans 3", "Helvetica Neue", Helvetica, Arial, sans-serif;
  line-height: 1.52;
  background:
    radial-gradient(1100px 650px at 8% -20%, #1e3a8a 0%, transparent 55%),
    radial-gradient(900px 540px at 92% -18%, #164e63 0%, transparent 58%),
    linear-gradient(180deg, var(--bg-0) 0%, var(--bg-1) 52%, var(--bg-2) 100%);
}

h1,
h2,
h3,
button,
legend,
label,
.eyebrow {
  font-family: "IBM Plex Sans", "Avenir Next", "Gill Sans", "Trebuchet MS", sans-serif;
}

.page {
  max-width: calc(
    var(--reading-measure) + (var(--page-pad-x) * 2) + var(--sidebar-width) + var(--layout-gap)
  );
  width: min(100%, 1220px);
  margin: 1.35rem auto;
  padding: 1.35rem var(--page-pad-x) 2rem;
  background: linear-gradient(180deg, rgba(247, 250, 255, 0.96), rgba(240, 246, 255, 0.96));
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow:
    0 24px 60px rgba(2, 10, 28, 0.34),
    0 2px 0 rgba(255, 255, 255, 0.55) inset;
  backdrop-filter: blur(3px);
}

.page-header {
  padding: 1rem 1.1rem 0.95rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(
    125deg,
    rgba(59, 130, 246, 0.13) 0%,
    rgba(14, 165, 233, 0.1) 42%,
    rgba(255, 255, 255, 0) 100%
  );
}

.page-header h1 {
  margin: 0.3rem 0 0.45rem;
  font-size: 2.05rem;
  color: #102349;
  letter-spacing: -0.015em;
}

.page-header p {
  margin: 0;
  color: var(--muted);
}

.chapter-nav {
  display: none;
}

.chapter-link {
  display: inline-block;
  padding: 0.34rem 0.7rem;
  border-radius: 999px;
  border: 1px solid rgba(29, 78, 216, 0.26);
  background: rgba(255, 255, 255, 0.64);
  color: #1d3d70;
  text-decoration: none;
  font-family: "IBM Plex Sans", "Avenir Next", "Gill Sans", "Trebuchet MS", sans-serif;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
}

.chapter-link:hover {
  background: rgba(29, 78, 216, 0.1);
}

.chapter-link.is-active {
  background: rgba(29, 78, 216, 0.16);
  border-color: rgba(29, 78, 216, 0.42);
  color: #102f63;
  font-weight: 600;
}

.eyebrow {
  margin: 0;
  color: #38507a;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.layout {
  margin-top: 1rem;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  gap: var(--layout-gap);
  align-items: start;
}

.section-nav {
  position: sticky;
  top: 1rem;
  z-index: 5;
  align-self: start;
  max-height: calc(100vh - 1.6rem);
  overflow: auto;
  padding: 0.15rem 0.2rem 0.45rem 0;
  border-right: 1px solid var(--line);
}

.sidebar-block + .sidebar-block {
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
}

.section-nav-title {
  margin: 0 0 0.5rem;
  padding-right: 0.55rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: #2f4b79;
}

.section-nav-links {
  display: grid;
  gap: 0.2rem;
  padding-right: 0.45rem;
}

.chapter-rail-links {
  display: grid;
  gap: 0.26rem;
  padding-right: 0.45rem;
}

.chapter-rail-link {
  display: block;
  padding: 0.4rem 0.4rem;
  border-radius: 8px;
  color: #1f3d6a;
  text-decoration: none;
  font-family: "IBM Plex Sans", "Avenir Next", "Gill Sans", "Trebuchet MS", sans-serif;
  font-size: 0.82rem;
  line-height: 1.3;
  border: 1px solid rgba(29, 78, 216, 0.2);
  background: rgba(255, 255, 255, 0.58);
  cursor: pointer;
}

.chapter-rail-link:hover {
  background: rgba(29, 78, 216, 0.1);
  border-color: rgba(29, 78, 216, 0.3);
}

.chapter-rail-link.is-active {
  background: rgba(29, 78, 216, 0.18);
  border-color: rgba(29, 78, 216, 0.4);
  color: #102f63;
  font-weight: 600;
}

.section-nav-group-label {
  margin: 0.46rem 0 0.2rem;
  font-family: "IBM Plex Sans", "Avenir Next", "Gill Sans", "Trebuchet MS", sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #47618b;
}

.section-nav-group-link {
  display: block;
  text-decoration: none;
  border-radius: 8px;
  padding: 0.16rem 0.42rem;
  border: 1px solid transparent;
  cursor: pointer;
}

.section-nav-group-link:hover {
  background: rgba(29, 78, 216, 0.08);
  border-color: rgba(29, 78, 216, 0.18);
}

.section-nav-group-link.is-active {
  background: rgba(29, 78, 216, 0.16);
  border-color: rgba(29, 78, 216, 0.3);
  color: #123264;
  box-shadow: inset 2px 0 0 rgba(29, 78, 216, 0.45);
}

.section-nav-link {
  display: block;
  padding: 0.3rem 0.46rem;
  border-radius: 8px;
  color: #29416a;
  text-decoration: none;
  font-family: "IBM Plex Sans", "Avenir Next", "Gill Sans", "Trebuchet MS", sans-serif;
  font-size: 0.82rem;
  line-height: 1.3;
  border: 1px solid transparent;
  cursor: pointer;
}

.section-nav-link:hover {
  background: rgba(29, 78, 216, 0.08);
  border-color: rgba(29, 78, 216, 0.18);
}

.section-nav-link.is-active {
  background: rgba(29, 78, 216, 0.19);
  border-color: rgba(29, 78, 216, 0.34);
  color: #0f2f62;
  font-weight: 600;
  box-shadow: inset 2px 0 0 rgba(29, 78, 216, 0.5);
}

.section-nav-link-break {
  color: #2b5b8d;
}

.lesson-panel,
.chart-card {
  background: transparent;
  border: 0;
  border-radius: 0;
}

.lesson-panel {
  padding: 0.15rem 0.2rem 0.4rem;
  min-width: 0;
  position: relative;
  z-index: 1;
}

.lesson-panel h2 {
  margin: 0.15rem 0 0.8rem;
  font-size: 1.45rem;
}

.chart-card {
  margin: 1rem 0;
  padding: 0.7rem 0.85rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(241, 247, 255, 0.95));
}

.chart-card h3 {
  margin: 0.08rem 0 0.38rem;
  font-size: 1.02rem;
}

.chart {
  min-height: 320px;
  position: relative;
}

.chart svg {
  display: block;
  width: 100%;
  height: auto;
}

.chart-note {
  margin: 0.55rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.notes-flow {
  display: grid;
  gap: 1rem;
}

.status-card {
  width: min(100%, var(--reading-measure));
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(235, 244, 255, 0.92));
  padding: 0.75rem 0.85rem;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}

.status-card h3 {
  margin: 0 0 0.2rem;
  font-size: 1rem;
  color: #102f63;
}

.status-card p {
  margin: 0;
  color: #2f4b79;
}

.status-card.status-loading {
  border-color: rgba(29, 78, 216, 0.28);
  background: linear-gradient(180deg, rgba(245, 250, 255, 0.98), rgba(229, 241, 255, 0.98));
}

.status-card.status-error {
  border-color: rgba(190, 24, 93, 0.26);
  background: linear-gradient(180deg, rgba(255, 246, 250, 0.98), rgba(255, 236, 245, 0.98));
}

.status-card.status-error h3 {
  color: #9d174d;
}

.status-card.status-error p {
  color: #831843;
}

.notes-major-heading {
  margin: 0.45rem 0 0.05rem;
  padding: 0.1rem 0 0.35rem;
  font-size: 1.34rem;
  color: #102349;
  border-bottom: 1px solid var(--line);
  width: min(100%, var(--reading-measure));
}

.note-section {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0.1rem 0 1rem;
  scroll-margin-top: 4.6rem;
}

.note-section.is-active {
  padding-left: 0.72rem;
  border-left: 3px solid rgba(29, 78, 216, 0.45);
  background: linear-gradient(90deg, rgba(29, 78, 216, 0.08), rgba(29, 78, 216, 0));
}

.note-section h3 {
  margin: 0;
  font-size: 1.2rem;
  color: #11284f;
}

.note-section > h3,
.note-section > .note-body,
.note-section > .note-equation,
.note-section > .note-checks,
.note-section > .equation-builder {
  width: min(100%, var(--reading-measure));
}

.note-body p {
  margin: 0 0 0.62rem;
}

.note-body {
  line-height: 1.58;
}

.figure-placeholder {
  margin: 0.35rem 0 0.6rem;
  color: #55709a;
  font-size: 0.84rem;
  font-style: italic;
}

.equation-builder {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(233, 242, 255, 0.9));
  padding: 0.68rem;
  margin: 0.7rem 0;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}

.equation-builder-label {
  font-size: 0.84rem;
  color: #29416a;
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.equation-builder-equation {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  border: 1px solid rgba(37, 99, 235, 0.22);
  border-radius: 10px;
  background: var(--surface-elevated);
  padding: 0.5rem 0.55rem;
}

.equation-builder-equation .is-hidden {
  display: none;
}

.builder-term {
  border-radius: 6px;
  padding: 0.11rem 0.24rem;
  transition: background 140ms ease, opacity 140ms ease, box-shadow 140ms ease;
}

.builder-term.is-active {
  background: rgba(29, 78, 216, 0.14);
  box-shadow: inset 0 0 0 1px rgba(29, 78, 216, 0.3);
}

.builder-term.is-muted {
  opacity: 0.72;
}

.equation-builder-statements {
  margin-top: 0.5rem;
  min-height: 2.5rem;
}

.builder-statement {
  display: none;
  width: 100%;
  text-align: center;
  appearance: none;
  border: 1px solid rgba(37, 99, 235, 0.26);
  border-radius: 10px;
  background: rgba(59, 130, 246, 0.11);
  color: #113260;
  padding: 0.43rem 0.56rem;
  font-size: 0.92rem;
  line-height: 1.3;
  cursor: default;
  pointer-events: none;
}

.builder-statement.is-active {
  display: block;
}

.equation-builder[data-builder-mode="single"] .equation-builder-statements {
  display: grid;
  gap: 0.32rem;
  min-height: 0;
}

.equation-builder[data-builder-mode="single"] .builder-statement {
  display: block;
  pointer-events: auto;
  cursor: pointer;
  opacity: 0.72;
  text-align: left;
}

.equation-builder[data-builder-mode="single"] .builder-statement.is-active {
  opacity: 1;
  border-color: rgba(37, 99, 235, 0.38);
  background: rgba(59, 130, 246, 0.2);
  cursor: default;
}

.equation-builder[data-builder-mode="single"].graph-builder-graph .equation-builder-statements {
  display: block;
  min-height: 0;
}

.equation-builder[data-builder-mode="single"].graph-builder-graph .builder-statement {
  display: none;
  pointer-events: none;
  cursor: default;
  text-align: center;
  opacity: 1;
}

.equation-builder[data-builder-mode="single"].graph-builder-graph .builder-statement.is-active {
  display: block;
}

.graph-builder .equation-builder-equation {
  display: block;
  padding: 0.46rem;
}

.graph-stage-canvas {
  width: 100%;
}

.builder-graph-svg {
  display: block;
  width: 100%;
  height: auto;
}

.builder-graph-sequence-frame {
  width: 100%;
}

.builder-graph-sequence-frame svg,
.builder-graph-sequence-frame img {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 auto;
}

.builder-graph-label,
.builder-graph-marker text {
  font-family: "IBM Plex Sans", "Avenir Next", "Gill Sans", "Trebuchet MS", sans-serif;
}

.builder-math-label-layer {
  pointer-events: none;
}

.builder-math-label-layer .math-graph-label {
  visibility: visible;
  pointer-events: none;
  font-weight: 500;
  line-height: 1.05;
}

.graph-builder .builder-term {
  display: block;
  width: 100%;
  padding: 0;
}

.graph-builder .builder-term svg,
.graph-builder .builder-term img {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 auto;
}

.equation-builder-controls {
  margin-top: 0.58rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: 0.45rem;
}

.builder-progress {
  margin-right: auto;
  font-family: "IBM Plex Sans", "Avenir Next", "Gill Sans", "Trebuchet MS", sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #27426d;
}

.builder-control {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid rgba(29, 78, 216, 0.34);
  border-radius: 999px;
  background-color: rgba(255, 255, 255, 0.9);
  background-image: none;
  color: #1e3a68;
  -webkit-text-fill-color: currentColor;
  padding: 0.36rem 0.8rem;
  font-size: 0.86rem;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.builder-control:hover:not(:disabled):not(.builder-control-next) {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(30, 58, 138, 0.14);
  background-color: #ffffff;
}

.builder-control-next,
.builder-control[data-builder-next] {
  border-color: #1d4ed8;
  background-color: #1d4ed8;
  background-image: none;
  color: #ffffff;
}

.builder-control-next:hover:not(:disabled),
.builder-control[data-builder-next]:hover:not(:disabled) {
  border-color: #1e40af;
  background-color: #1e40af;
  background-image: none;
  color: #ffffff;
}

.builder-control-next:active:not(:disabled),
.builder-control-next:focus-visible:not(:disabled),
.builder-control[data-builder-next]:active:not(:disabled),
.builder-control[data-builder-next]:focus-visible:not(:disabled) {
  border-color: #1e3a8a;
  background-color: #1e3a8a;
  background-image: none;
  color: #ffffff;
}

.builder-control-next:disabled,
.builder-control[data-builder-next]:disabled {
  border-color: #8da8df;
  background-color: #8da8df;
  background-image: none;
}

.builder-control[data-builder-reset] {
  border-color: rgba(36, 68, 117, 0.28);
}

.builder-control:disabled {
  opacity: 0.56;
  cursor: default;
}

.note-equation {
  border: 0;
  border-left: 3px solid rgba(29, 78, 216, 0.38);
  border-radius: 10px;
  background: linear-gradient(90deg, rgba(29, 78, 216, 0.1), rgba(29, 78, 216, 0.02));
  padding: 0.56rem 0.6rem;
  margin: 0.58rem 0;
  overflow-x: auto;
}

.note-equation-mixed {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.28rem;
}

.note-equation-mixed .mixed-text,
.note-equation-mixed .mixed-op {
  font-family: "Source Sans 3", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 1.04rem;
  line-height: 1.35;
}

.note-equation mjx-mi,
.note-equation mjx-mo,
.note-equation mjx-c {
  pointer-events: auto !important;
}

mjx-container[jax="CHTML"] mjx-mtext,
mjx-container[jax="CHTML"] mjx-utext {
  font-family: var(--math-mtext-font) !important;
  font-style: normal;
}

mjx-container[jax="CHTML"]:not([display="true"]) {
  vertical-align: var(--inline-math-offset) !important;
}

.note-body mjx-mi,
.note-body mjx-mo,
.note-body mjx-c {
  pointer-events: auto !important;
}

.note-equation .eq-term {
  cursor: help;
  border-bottom: 0;
}

.note-body .eq-term {
  cursor: help;
  border-bottom: 0;
}

.note-equation .eq-term.eq-term-active {
  background: transparent;
}

.note-body .eq-term.eq-term-active {
  background: transparent;
}

.note-equation mjx-mtext .eq-term,
.note-equation mjx-utext .eq-term,
.note-body mjx-mtext .eq-term,
.note-body mjx-utext .eq-term {
  border-bottom: 0;
  background: transparent;
  cursor: text;
}

.note-checks {
  margin-top: 0.55rem;
  border-top: 1px dashed rgba(30, 58, 138, 0.26);
  padding-top: 0.45rem;
}

.check-row {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dashed rgba(30, 58, 138, 0.22);
  padding: 0.24rem 0;
  font-size: 0.92rem;
}

.check-row:last-child {
  border-bottom: 0;
}

.interactive-break {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(235, 244, 255, 0.96));
  padding: 0.78rem;
  margin: 0.5rem 0 0.6rem;
  width: min(100%, var(--reading-measure));
  scroll-margin-top: 4.6rem;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.6) inset,
    0 14px 28px rgba(30, 58, 138, 0.09);
}

.interactive-break h3 {
  margin: 0.1rem 0 0.38rem;
  font-size: 1.08rem;
  color: #102349;
}

.axis path,
.axis line {
  stroke: #8ca2c8;
}

.axis text {
  font-size: 0.96rem;
  fill: #2f466c;
}

.axis-label {
  font-size: 0.96rem;
  fill: #2f466c;
}

.axis-title-label {
  font-size: 1.18rem;
  font-weight: 600;
}

.investment-line {
  fill: none;
  stroke: var(--invest);
  stroke-width: 2.8;
}

.depreciation-line {
  fill: none;
  stroke: var(--dep);
  stroke-width: 2.5;
}

.depreciation-shock-line {
  fill: none;
  stroke: var(--shock);
  stroke-width: 2.4;
  stroke-dasharray: 6 3;
}

.curve-label {
  font-size: 0.85rem;
  font-family: "IBM Plex Sans", "Avenir Next", sans-serif;
}

.invest-label {
  fill: var(--invest);
}

.dep-label {
  fill: var(--dep);
}

.dep-shock-label {
  fill: var(--shock);
}

.math-graph-label-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.math-graph-label {
  position: absolute;
  transform: translate(-50%, -100%);
  white-space: nowrap;
  font-size: 1.2rem;
  font-weight: 600;
  line-height: 1;
  pointer-events: auto;
  visibility: hidden;
}

.invest-math-label {
  color: var(--invest);
}

.dep-math-label {
  color: var(--dep);
}

.dep-shock-math-label {
  color: #0369a1;
}

.steady-math-label {
  color: #1e2f50;
}

.k1-math-label {
  color: #1e2f50;
}

.k1-invest-math-label {
  color: var(--invest);
}

.reference-label,
.series-label,
.shock-label {
  font-size: 0.8rem;
  font-family: "IBM Plex Sans", "Avenir Next", sans-serif;
}

.reference-line {
  stroke-width: 1.3;
}

.shock-line {
  stroke: #3b82f6;
  stroke-dasharray: 4 4;
}

.shock-label {
  fill: #1d4ed8;
}

.term-tooltip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  max-width: 300px;
  background: #0d2246;
  color: #e8f0ff;
  border: 1px solid rgba(147, 197, 253, 0.35);
  border-radius: 8px;
  padding: 0.48rem 0.58rem;
  font-size: 0.82rem;
  line-height: 1.32;
  box-shadow: 0 14px 26px rgba(2, 8, 23, 0.34);
}

@media (max-width: 1180px) {
  .page {
    max-width: calc(var(--reading-measure) + (var(--page-pad-x) * 2));
  }

  .chapter-nav {
    margin-top: 0.72rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.42rem;
  }

  .layout {
    display: block;
  }

  .section-nav {
    display: none;
  }
}

@media (max-width: 820px) {
  .page {
    --page-pad-x: 0.82rem;
    margin: 0.8rem auto;
    border-radius: 16px;
    padding: 0.95rem var(--page-pad-x) 1.3rem;
  }

  .page-header h1 {
    font-size: 1.68rem;
  }

  .math-graph-label {
    font-size: 1.04rem;
  }
}

@media (max-width: 640px) {
  .page {
    --page-pad-x: 0.56rem;
    margin: 0.55rem auto;
    padding: 0.7rem var(--page-pad-x) 1rem;
  }

  .interactive-break {
    padding: 0.58rem;
    border-radius: 14px;
  }

  .builder-control {
    padding: 0.32rem 0.66rem;
  }
}
