:root {
  color-scheme: light;
  --bg: #f5f6f4;
  --rail: #fbfcfa;
  --panel: #ffffff;
  --ink: #20242a;
  --muted: #68717d;
  --line: #d8ddd5;
  --accent: #0b6f77;
  --accent-soft: #dcefed;
  --path: #d0342c;
  --amber: #a56500;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.tetra-app {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  min-height: 100vh;
}

.control-rail {
  border-right: 1px solid var(--line);
  background: var(--rail);
  padding: 20px;
  overflow-y: auto;
}

.brand-block {
  display: grid;
  gap: 8px;
}

.back-link {
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.back-link:hover {
  text-decoration: underline;
}

.page-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}

h1,
h2,
h3,
p,
dl {
  margin: 0;
}

.brand-block h1 {
  font-size: 23px;
  line-height: 1.12;
  letter-spacing: 0;
}

.brand-block p,
#orbitSubtitle,
.panel-heading span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.field {
  display: grid;
  gap: 7px;
  margin-top: 18px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

select,
input[type="search"] {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
}

#resetCamera,
#playAnimation {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

#playAnimation {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: #064c50;
}

#playAnimation.is-running {
  border-color: #8b2c24;
  background: #f8dfdb;
  color: #6b1f1a;
}

.summary-block {
  margin-top: 20px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.summary-block dl,
.orbit-details {
  display: grid;
  grid-template-columns: minmax(92px, auto) minmax(0, 1fr);
  gap: 8px 12px;
  font-size: 13px;
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
  min-width: 0;
  word-break: break-word;
}

.viewer-area {
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 14px;
  padding: 22px;
}

.top-strip {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

.top-strip > div {
  min-width: 0;
}

.top-strip h2 {
  margin-bottom: 4px;
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

#orbitSubtitle {
  overflow-wrap: anywhere;
}

#resetCamera {
  padding: 0 14px;
  white-space: nowrap;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: end;
}

.top-actions button {
  padding: 0 14px;
  white-space: nowrap;
}

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

.visual-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

.visual-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.visual-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
}

.visual-heading h3 {
  font-size: 13px;
  letter-spacing: 0;
}

.visual-heading span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  text-align: right;
}

.visual-panel canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #fff;
}

.stage-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.stage-note {
  position: absolute;
  left: 14px;
  bottom: 14px;
  max-width: min(420px, calc(100% - 28px));
  border: 1px solid #f0c27a;
  border-radius: 6px;
  background: #fff7e8;
  color: #7a3b00;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.35;
}

.is-hidden {
  display: none !important;
}

.lower-layout {
  display: grid;
  grid-template-columns: minmax(580px, 1.55fr) minmax(260px, 0.7fr);
  gap: 16px;
}

.inventory-panel,
.details-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 12px 14px;
}

.panel-heading h3 {
  font-size: 14px;
  letter-spacing: 0;
}

.orbit-table-wrap {
  max-height: 420px;
  overflow: auto;
}

.orbit-table {
  width: 100%;
  min-width: 1040px;
  border-collapse: collapse;
  font-size: 12px;
  table-layout: fixed;
}

.orbit-table th,
.orbit-table td {
  border-bottom: 1px solid var(--line);
  padding: 9px 12px;
  vertical-align: top;
}

.orbit-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f7f9f6;
  color: var(--muted);
  font-weight: 750;
  text-align: left;
  white-space: nowrap;
}

.sort-header {
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 12px;
  font-weight: 750;
  padding: 0;
  text-align: left;
}

.sort-header:hover,
.sort-header.is-active {
  color: var(--accent);
}

.sort-symbol {
  font-size: 11px;
  font-weight: 850;
}

.orbit-row {
  cursor: pointer;
}

.orbit-row:hover,
.orbit-row.is-selected {
  background: var(--accent-soft);
}

.orbit-row.is-singular {
  box-shadow: inset 4px 0 0 #ffb45f;
}

.orbit-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.period-cell,
.numeric-cell,
.deg-cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.numeric-cell {
  text-align: right;
}

.word-cell,
.exact-cell {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.exact-cell {
  max-width: 170px;
  color: var(--muted);
}

.word-letter {
  color: var(--letter-color);
  display: inline-block;
  font-weight: 850;
  min-width: 0.68em;
  text-align: center;
}

.word-separator {
  color: var(--muted);
}

.word-space {
  display: inline-block;
  width: 0.5em;
}

.source-cell {
  color: var(--muted);
  white-space: nowrap;
}

.deg-cell {
  color: var(--muted);
}

.orbit-table th:nth-child(1),
.orbit-table td:nth-child(1) {
  width: 70px;
}

.orbit-table th:nth-child(2),
.orbit-table td:nth-child(2) {
  width: 250px;
}

.orbit-table th:nth-child(3),
.orbit-table td:nth-child(3) {
  width: 112px;
}

.orbit-table th:nth-child(4),
.orbit-table td:nth-child(4) {
  width: 105px;
}

.orbit-table th:nth-child(5),
.orbit-table td:nth-child(5) {
  width: 145px;
}

.orbit-table th:nth-child(6),
.orbit-table td:nth-child(6) {
  width: 98px;
}

.orbit-table th:nth-child(7),
.orbit-table td:nth-child(7) {
  width: 92px;
}

.orbit-table th:nth-child(8),
.orbit-table td:nth-child(8) {
  width: 90px;
}

.orbit-table th:nth-child(9),
.orbit-table td:nth-child(9) {
  width: 82px;
}

.details-panel {
  padding-bottom: 14px;
}

.orbit-details {
  padding: 14px;
  max-height: 250px;
  overflow-y: auto;
}

.point-panel {
  border-top: 1px solid var(--line);
  padding: 12px 14px 14px;
}

.panel-subheading {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.point-rows {
  display: grid;
  gap: 5px;
  max-height: 230px;
  overflow: auto;
}

.point-row {
  display: grid;
  grid-template-columns: 34px 42px minmax(180px, 1fr) minmax(135px, 0.85fr);
  gap: 8px;
  align-items: start;
  width: 100%;
  border: 1px solid var(--line);
  border-left: 6px solid var(--point-color);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 7px 8px;
  text-align: left;
  cursor: pointer;
}

.point-row:hover,
.point-row.is-selected {
  background: color-mix(in srgb, var(--point-color) 13%, white);
  border-color: color-mix(in srgb, var(--point-color) 50%, var(--line));
}

.point-index,
.point-label {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.point-coords,
.point-xyz {
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.mono {
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, Menlo, monospace;
}

@media (max-width: 1020px) {
  .tetra-app,
  .lower-layout {
    grid-template-columns: 1fr;
  }

  .control-rail {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .viewer-area {
    grid-template-rows: auto auto auto;
  }

  .stage {
    min-height: 320px;
  }

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

  .visual-heading {
    align-items: start;
    flex-direction: column;
    gap: 3px;
  }

  .visual-heading span {
    text-align: left;
  }
}

@media (max-width: 640px) {
  .orbit-table {
    min-width: 1120px;
  }

  .orbit-table-wrap,
  .orbit-details {
    max-height: 360px;
  }

  .point-row {
    grid-template-columns: 32px 40px minmax(170px, 1fr);
  }

  .point-xyz {
    grid-column: 3;
  }
}

.essay-body {
  background: #f3f5f1;
}

.essay-shell {
  width: min(1120px, calc(100% - 36px));
  margin: 0 auto;
  padding: 26px 0 46px;
}

.essay-hero {
  padding: 18px 0 28px;
}

.essay-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin-bottom: 42px;
}

.essay-nav a,
.essay-footer a {
  color: var(--accent);
  font-size: 13px;
  font-weight: 750;
  text-decoration: none;
}

.essay-nav a:hover,
.essay-footer a:hover {
  text-decoration: underline;
}

.essay-kicker {
  margin-bottom: 10px;
  color: var(--amber);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.essay-hero h1 {
  max-width: 920px;
  font-size: clamp(34px, 6vw, 68px);
  line-height: 0.98;
  letter-spacing: 0;
}

.essay-lede {
  max-width: 780px;
  margin-top: 22px;
  color: #3f4853;
  font-size: 19px;
  line-height: 1.6;
}

.essay-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 24px;
}

.essay-inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.essay-button {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 14px;
  font-size: 14px;
  font-weight: 750;
  text-decoration: none;
}

.essay-button-primary {
  border-color: #085f66;
  background: var(--accent);
  color: #fff;
}

.diagram-band {
  display: grid;
  grid-template-columns: minmax(260px, 0.74fr) minmax(0, 1.26fr);
  gap: 26px;
  align-items: center;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 28px 0;
}

.diagram-copy h2,
.essay-article h2 {
  margin: 0;
  font-size: 25px;
  line-height: 1.2;
  letter-spacing: 0;
}

.diagram-copy p {
  margin-top: 12px;
  color: #46505b;
  font-size: 15px;
  line-height: 1.6;
}

.three-scene,
.normal-scene,
.unfold-scene,
.smooth-scene,
.fixed-limit-scene {
  min-width: 0;
}

.scene-toolbar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  margin-bottom: 10px;
}

.scene-tab,
.smooth-tab,
.fixed-limit-tab,
.scene-control-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 750;
}

.scene-tab.is-active,
.smooth-tab.is-active,
.fixed-limit-tab.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: #064c50;
}

.scene-control-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.fixed-limit-scene .scene-toolbar {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.scene-frame {
  position: relative;
  height: 430px;
  min-height: 430px;
  background: #fff;
  overflow: hidden;
}

#normalConeCanvas,
#unfoldCanvas,
#smoothCanvas,
#fixedLimitCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.scene-readout {
  position: absolute;
  top: 12px;
  right: 12px;
  width: min(285px, calc(100% - 24px));
  border: 1px solid rgba(216, 221, 213, 0.92);
  border-radius: 8px;
  background: rgba(251, 252, 250, 0.92);
  padding: 12px;
  backdrop-filter: blur(8px);
}

.scene-readout h3 {
  margin: 0 0 9px;
  font-size: 15px;
  line-height: 1.25;
  letter-spacing: 0;
}

.scene-readout dl {
  display: grid;
  grid-template-columns: minmax(92px, auto) minmax(0, 1fr);
  gap: 6px 10px;
  font-size: 12px;
  line-height: 1.35;
}

.scene-caption {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.scene-controls {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  margin-top: 10px;
}

.scene-control-button {
  padding: 0 14px;
}

.scene-step-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.scene-step-controls .scene-control-button {
  min-width: 104px;
}

.scene-slider {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.scene-slider input {
  width: 100%;
}

.reflection-diagram {
  margin: 0;
  min-width: 0;
}

.reflection-diagram svg {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.reflection-diagram figcaption {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.svg-heading {
  fill: var(--ink);
  font: 700 18px Inter, ui-sans-serif, system-ui, sans-serif;
}

.svg-label {
  fill: var(--muted);
  font: 600 13px Inter, ui-sans-serif, system-ui, sans-serif;
}

.svg-wall {
  stroke: #20242a;
  stroke-width: 4;
  stroke-linecap: round;
}

.svg-path {
  fill: none;
  stroke: #d0342c;
  stroke-width: 5;
  stroke-linecap: round;
}

.svg-normal {
  stroke: var(--accent);
  stroke-width: 3;
  stroke-dasharray: 8 8;
}

.svg-cone {
  fill: #fff2dc;
  stroke: #e0a64c;
  stroke-width: 2;
}

.svg-cone-ray {
  stroke: var(--amber);
  stroke-width: 3;
  stroke-dasharray: 7 7;
}

.svg-hit {
  fill: #fff;
  stroke: #d0342c;
  stroke-width: 4;
}

.svg-angle {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
}

.essay-article {
  max-width: 860px;
  margin: 34px auto 0;
}

.essay-article section {
  margin-top: 34px;
}

.essay-article section:first-child {
  margin-top: 0;
}

.essay-article p {
  margin: 13px 0 0;
  color: #2f3740;
  font-size: 16px;
  line-height: 1.72;
}

.essay-article code {
  border: 1px solid #dfe4dc;
  border-radius: 5px;
  background: #fbfcfa;
  padding: 1px 5px;
  color: #243036;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, Menlo, monospace;
  font-size: 0.92em;
}

.formula-line {
  border-left: 4px solid var(--accent);
  background: #edf6f5;
  padding: 12px 14px;
}

.math-block {
  margin: 16px 0 0;
  overflow-x: auto;
  border-left: 4px solid var(--accent);
  background: #edf6f5;
  padding: 12px 14px;
  color: #243036;
  font-size: 15px;
  line-height: 1.5;
}

.math-block mjx-container {
  margin: 0 !important;
  min-width: max-content;
}

.reason-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.reason-grid section {
  min-width: 0;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 16px;
}

.reason-grid h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.3;
  letter-spacing: 0;
}

.reason-grid p {
  margin-top: 8px;
  font-size: 14px;
  line-height: 1.6;
}

.reason-grid-two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.example-table-wrap {
  margin-top: 16px;
  overflow-x: auto;
}

.example-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 14px;
}

.example-table th,
.example-table td {
  border-bottom: 1px solid var(--line);
  padding: 11px 12px;
  text-align: left;
  vertical-align: top;
}

.example-table th {
  background: #f7f9f6;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.essay-footer {
  margin-top: 38px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

@media (max-width: 780px) {
  .essay-shell {
    width: min(100% - 28px, 1120px);
  }

  .essay-nav {
    margin-bottom: 30px;
  }

  .essay-hero h1 {
    font-size: 38px;
    line-height: 1.04;
  }

  .essay-lede {
    font-size: 17px;
  }

  .diagram-band,
  .reason-grid {
    grid-template-columns: 1fr;
  }

  .scene-frame {
    height: 360px;
    min-height: 360px;
  }

  .scene-readout {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    border-left: 0;
    border-radius: 0 0 0 0;
    background: #fbfcfa;
  }

  .scene-controls,
  .scene-slider {
    grid-template-columns: 1fr;
  }
}
