:root {
  color-scheme: light;
  --paper: #f5f2e9;
  --paper-deep: #ebe6d8;
  --ink: #17211d;
  --muted: #59635e;
  --forest: #0b5748;
  --forest-dark: #073e35;
  --teal: #187a74;
  --orange: #b65f2f;
  --blue: #345f73;
  --native: #e5a649;
  --correction: #65c895;
  --resultant: #62b8ce;
  --line: rgba(23, 33, 29, 0.17);
  --white: #fffdf7;
  --shadow: 0 18px 45px rgba(23, 33, 29, 0.09);
  font-family: "IBM Plex Sans", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-width: 0;
  background: transparent;
  color: var(--ink);
}

body {
  padding: 1px;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  border: 1px solid rgba(23, 33, 29, 0.25);
  border-radius: 999px;
  background: var(--white);
  color: var(--ink);
}

button {
  min-height: 42px;
  padding: 0.65rem 1rem;
  cursor: pointer;
  font-weight: 700;
}

button:hover {
  border-color: var(--forest);
  color: var(--forest);
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid #f4a261;
  outline-offset: 3px;
}

.demo-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 26px;
  background:
    linear-gradient(rgba(11, 87, 72, 0.026) 1px, transparent 1px),
    linear-gradient(90deg, rgba(11, 87, 72, 0.026) 1px, transparent 1px),
    var(--paper);
  background-size: 42px 42px;
  box-shadow: var(--shadow);
}

.demo-header,
.factorization,
.example {
  padding: clamp(1.4rem, 3.5vw, 3.5rem);
}

.demo-header {
  position: relative;
  overflow: hidden;
  background: var(--forest-dark);
  color: var(--white);
}

.demo-header::after {
  position: absolute;
  top: -85px;
  right: -70px;
  width: 330px;
  height: 330px;
  border: 1px solid rgba(255, 253, 247, 0.15);
  border-radius: 50%;
  box-shadow: 0 0 0 46px rgba(255, 253, 247, 0.028), 0 0 0 92px rgba(255, 253, 247, 0.02);
  content: "";
}

.kicker {
  margin: 0 0 0.75rem;
  color: var(--teal);
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.demo-header .kicker {
  color: #9bd8ca;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
h2,
h3 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
}

h1 {
  position: relative;
  z-index: 1;
  max-width: 850px;
  margin-bottom: 1rem;
  font-size: clamp(2.5rem, 6vw, 5.4rem);
  line-height: 0.98;
  letter-spacing: -0.045em;
}

.lede {
  position: relative;
  z-index: 1;
  max-width: 850px;
  margin: 0;
  color: rgba(255, 253, 247, 0.77);
  font-size: clamp(1rem, 1.6vw, 1.18rem);
  line-height: 1.72;
}

.factorization {
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 247, 0.78);
}

.section-heading h2 {
  max-width: 780px;
  margin: 0;
  font-size: clamp(1.9rem, 3.4vw, 3rem);
  line-height: 1.08;
  letter-spacing: -0.03em;
}

.section-heading.split {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
  align-items: end;
  gap: 2rem;
}

.section-heading.split > p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.factorization-flow {
  display: grid;
  grid-template-columns: minmax(110px, 0.7fr) minmax(175px, 1.3fr) minmax(180px, 1fr) minmax(70px, 0.4fr) minmax(130px, 0.75fr);
  align-items: center;
  gap: 0.75rem;
  margin-top: 2.2rem;
}

.flow-node {
  display: grid;
  min-height: 106px;
  padding: 1rem;
  border: 1px solid rgba(11, 87, 72, 0.24);
  border-radius: 16px;
  background: var(--white);
  place-content: center;
  text-align: center;
}

.flow-node span,
.factorization-result span,
.equation-label {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.flow-node strong {
  margin-top: 0.4rem;
  color: var(--forest);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.4rem;
  font-weight: 500;
}

.flow-node.output {
  border-color: rgba(24, 122, 116, 0.48);
  background: rgba(24, 122, 116, 0.08);
}

.flow-arrow {
  display: grid;
  justify-items: center;
  color: var(--muted);
  text-align: center;
}

.flow-arrow span {
  font-size: 0.72rem;
}

.flow-arrow b {
  color: var(--teal);
  font-size: 2rem;
  font-weight: 400;
  line-height: 1;
}

.identity-line {
  width: fit-content;
  margin: 1.2rem auto 0;
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  background: var(--forest);
  color: var(--white);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.05rem;
}

.identity-line span {
  margin-right: 0.7rem;
  color: #9bd8ca;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.factorization-result {
  display: grid;
  grid-template-columns: repeat(5, auto);
  align-items: stretch;
  justify-content: center;
  gap: 0.8rem;
  margin-top: 1.8rem;
}

.factorization-result > div {
  display: grid;
  min-height: 86px;
  padding: 0.9rem 1rem;
  border-top: 2px solid var(--teal);
  background: rgba(24, 122, 116, 0.065);
}

.factorization-result strong {
  align-self: end;
  margin-top: 0.55rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1rem, 1.5vw, 1.25rem);
  font-weight: 500;
  white-space: nowrap;
}

.factorization-result > i {
  align-self: center;
  color: var(--orange);
  font-size: 1.4rem;
  font-style: normal;
}

.example {
  background: rgba(245, 242, 233, 0.74);
}

.equation {
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--white);
}

.plant-equation {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.1rem;
  margin: 1.8rem 0;
  padding: 1rem 1.25rem;
  overflow-x: auto;
}

.plant-equation strong {
  display: flex;
  align-items: center;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1rem, 1.9vw, 1.35rem);
  font-weight: 500;
  white-space: nowrap;
}

.matrix {
  position: relative;
  display: inline-grid;
  margin-left: 0.6rem;
  padding: 0.15rem 0.75rem;
  gap: 0.12rem;
}

.matrix::before,
.matrix::after {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 7px;
  border-top: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  content: "";
}

.matrix::before {
  left: 0;
  border-left: 1.5px solid currentColor;
}

.matrix::after {
  right: 0;
  border-right: 1.5px solid currentColor;
}

.animation-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 0.85rem;
  margin-bottom: 1rem;
  padding: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(255, 253, 247, 0.86);
}

.animation-controls label {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.animation-controls input {
  flex: 1 1 220px;
  accent-color: var(--teal);
}

.animation-controls output {
  min-width: 4.5rem;
  color: var(--forest);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.78rem;
  font-weight: 700;
}

.animation-controls select {
  min-height: 38px;
  padding: 0.4rem 0.8rem;
}

.motion-note {
  width: 100%;
  color: var(--muted);
  font-size: 0.78rem;
}

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

.trajectory-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid rgba(23, 33, 29, 0.15);
  border-radius: 19px;
  background: var(--white);
  box-shadow: 0 10px 30px rgba(23, 33, 29, 0.07);
}

.trajectory-card header {
  min-height: 178px;
  padding: 1.1rem 1.1rem 0.95rem;
  border-top: 4px solid var(--teal);
}

.card-uncontrolled header {
  border-top-color: var(--orange);
}

.card-controlled header {
  border-top-color: var(--correction);
}

.trajectory-card header > span {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.trajectory-card h3 {
  margin: 0.35rem 0 0.5rem;
  font-size: clamp(1.25rem, 2vw, 1.65rem);
  line-height: 1.08;
}

.trajectory-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.55;
}

.trajectory-card canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1.12 / 1;
  background: #071c18;
}

.vector-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 0.8rem;
  padding: 0.75rem 1rem;
  background: #071c18;
  color: rgba(255, 253, 247, 0.78);
  font-size: 0.67rem;
}

.vector-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.vector-legend i {
  width: 15px;
  height: 2px;
  background: currentColor;
}

.vector-legend .native {
  color: var(--native);
}

.vector-legend .correction {
  color: var(--correction);
}

.vector-legend .resultant {
  color: var(--resultant);
}

.control-construction {
  display: grid;
  grid-template-columns: 0.7fr 1.25fr 1.35fr;
  gap: 1rem;
  margin-top: 1rem;
}

.control-construction .equation {
  display: grid;
  align-content: center;
  min-width: 0;
  min-height: 122px;
  padding: 1rem;
  overflow-x: auto;
}

.control-construction strong {
  margin-top: 0.55rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(0.98rem, 1.55vw, 1.22rem);
  font-weight: 500;
  white-space: nowrap;
}

.native-text {
  color: #9b581f;
  text-decoration-color: var(--native);
  text-decoration-line: underline;
  text-decoration-thickness: 3px;
  text-underline-offset: 5px;
}

.correction-text {
  color: #25704f;
  text-decoration-color: var(--correction);
  text-decoration-line: underline;
  text-decoration-thickness: 3px;
  text-underline-offset: 5px;
}

.target,
.target-text {
  color: #176e83;
  text-decoration-color: var(--resultant);
  text-decoration-line: underline;
  text-decoration-thickness: 3px;
  text-underline-offset: 5px;
}

.operator {
  margin: 0 0.28rem;
  color: var(--ink);
}

.radicand {
  display: inline-block;
  padding: 0.1rem 0.15rem 0;
  border-top: 1px solid currentColor;
}

.technical-note {
  margin: 1rem 0 0;
  padding: 0.9rem 1rem;
  border-left: 3px solid var(--teal);
  background: rgba(24, 122, 116, 0.08);
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.65;
}

.sr-only {
  position: absolute;
  overflow: hidden;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

@media (max-width: 980px) {
  .factorization-flow {
    grid-template-columns: minmax(110px, 0.8fr) minmax(170px, 1.2fr) minmax(180px, 1fr);
  }

  .flow-arrow.short,
  .flow-node.output {
    display: none;
  }

  .factorization-result {
    grid-template-columns: 1fr;
  }

  .factorization-result > i {
    justify-self: center;
    transform: rotate(90deg);
  }

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

  .trajectory-card {
    display: grid;
    grid-template-columns: minmax(220px, 0.58fr) minmax(300px, 1fr);
  }

  .trajectory-card header {
    min-height: 0;
  }

  .vector-legend {
    grid-column: 1 / -1;
  }

  .control-construction {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  body {
    padding: 0;
  }

  .demo-shell {
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .section-heading.split {
    grid-template-columns: 1fr;
    align-items: start;
    gap: 1rem;
  }

  .factorization-flow {
    grid-template-columns: 125px 180px 190px 70px 145px;
    overflow-x: auto;
    padding-bottom: 0.55rem;
  }

  .flow-arrow {
    min-height: 0;
  }

  .flow-node.output,
  .flow-arrow.short {
    display: grid;
  }

  .identity-line {
    border-radius: 12px;
    text-align: center;
  }

  .identity-line span {
    display: block;
    margin: 0 0 0.2rem;
  }

  .plant-equation {
    align-items: flex-start;
    justify-content: flex-start;
  }

  .trajectory-card {
    display: block;
  }

  .trajectory-card canvas {
    height: 250px;
    aspect-ratio: auto;
  }

  .animation-controls input {
    flex-basis: 100%;
    order: 2;
  }

  .animation-controls output {
    order: 3;
  }
}

@media (max-width: 480px) {
  .demo-header,
  .factorization,
  .example {
    padding: 1.1rem;
  }

  .trajectory-card canvas {
    height: 220px;
  }

  .factorization-result > div {
    min-height: 76px;
  }

  .control-construction {
    grid-template-columns: repeat(3, minmax(255px, 1fr));
    overflow-x: auto;
    padding-bottom: 0.45rem;
    scroll-snap-type: x proximity;
  }

  .control-construction .equation {
    scroll-snap-align: start;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
