:root {
  --c-a: #1d4ed8;
  --c-a1: #1d4ed8;
  --c-a2: #1d4ed8;
  --c-b: #15803d;
  --c-p: #d9480f;
  --c-e: #dc2626;
  --ink: #1c2230;
  --muted: #5d6677;
  --bg: #f4f5f8;
  --card: #fff;
  --line: #e3e6ec;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

header, main, footer {
  max-width: 1360px;
  margin: 0 auto;
  padding-left: 24px;
  padding-right: 24px;
}
header { padding-top: 28px; padding-bottom: 6px; }
h1 { font-size: 2rem; margin: 0 0 2px; letter-spacing: -0.015em; }
.sub { color: var(--muted); margin: 0; font-size: 1.05rem; }

.tabs { display: flex; gap: 8px; margin-top: 18px; }
.tab {
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 18px;
  cursor: pointer;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

main { padding-top: 12px; padding-bottom: 24px; }
.panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 18px;
  align-items: start;
}
.panel[hidden] { display: none; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04),
    0 6px 20px rgba(16, 24, 40, .05);
}

.stage {
  position: sticky;
  top: 12px;
  height: min(80vh, 760px);
  min-height: 440px;
  overflow: hidden;
}
.stage svg {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.hint {
  position: absolute;
  left: 14px;
  bottom: 12px;
  font-size: .86rem;
  color: var(--muted);
  background: rgba(255, 255, 255, .9);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 12px;
  pointer-events: none;
}

.legend {
  position: absolute;
  left: 12px;
  top: 12px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 9px;
  align-items: baseline;
  max-width: min(420px, calc(100% - 24px));
  font-size: .86rem;
  line-height: 1.35;
  background: rgba(255, 255, 255, .92);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 11px;
  pointer-events: none;
}
.legend[hidden] { display: none; }
.legend > div { display: contents; }
.legend > div > span:first-child { white-space: nowrap; justify-self: start; }
.legend .reg { color: var(--muted); }

.side { display: flex; flex-direction: column; gap: 14px; }
.side .card { padding: 16px 18px; }
.side h2 { font-size: 1.12rem; margin: 0 0 8px; }
.side h3 {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  margin: 12px 0 6px;
}
.side .readout h3 { margin-top: 0; }
.side p { margin: 0 0 10px; }

.va, .va1 { color: var(--c-a1); }
.va2 { color: var(--c-a2); }
.vb { color: var(--c-b); }
.vp { color: var(--c-p); }
.ve { color: var(--c-e); }

.formula {
  font-family: "STIX Two Text", "Cambria", Georgia, serif;
  font-size: 1.1rem;
  text-align: center;
  background: #f6f7fa;
  border-radius: 10px;
  padding: 10px;
  margin: 6px 0 10px;
}
.formula b { font-family: system-ui, sans-serif; }
.implies { margin: 0 .45em; color: var(--muted); }
.frac {
  display: inline-flex;
  flex-direction: column;
  vertical-align: middle;
  text-align: center;
  line-height: 1.25;
}
.frac > span:first-child {
  border-bottom: 1.3px solid currentColor;
  padding: 0 .25em 1px;
}
.frac > span:last-child { padding-top: 1px; }

ul.try { margin: 0 0 10px; padding-left: 1.1em; }
ul.try li { margin: 3px 0; }
.ols {
  font-size: .94rem;
  background: #f3f6ff;
  border-left: 3px solid var(--c-a);
  border-radius: 0 8px 8px 0;
  padding: 8px 10px;
  margin-bottom: 0 !important;
}

.chip {
  display: inline-block;
  min-width: 1.5em;
  padding: 0 .45em;
  border-radius: 999px;
  color: #fff;
  font-weight: 650;
  font-size: .9em;
  line-height: 1.55;
  text-align: center;
}
.chip.a, .chip.a1 { background: var(--c-a1); }
.chip.a2 { background: var(--c-a2); }
.chip.b { background: var(--c-b); }
.chip.p { background: var(--c-p); }
.chip.e { background: var(--c-e); }

.readout { font-variant-numeric: tabular-nums; }
.readout .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 5px 0;
  border-bottom: 1px dashed var(--line);
}
.readout .row:last-child { border-bottom: 0; }
.readout .val { font-weight: 600; white-space: nowrap; }
.readout .frac { font-size: .9em; }
.readout .frac .chip { font-size: .85em; }
.muted { color: var(--muted); font-size: .88em; }
.ok { color: #15803d; font-weight: 600; margin-left: .3em; }
.warn { color: #9a3412; margin: 0; }
.mat {
  display: inline-grid;
  column-gap: .8em;
  text-align: right;
  padding: 0 .4em;
  border-left: 1.5px solid var(--ink);
  border-right: 1.5px solid var(--ink);
  border-radius: 5px;
  line-height: 1.35;
}

.controls label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
  cursor: pointer;
}
.controls input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--ink);
}
.buttons { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 10px; }
button:not(.tab) {
  font: inherit;
  font-size: .92rem;
  font-weight: 600;
  color: var(--ink);
  background: #fff;
  border: 1px solid #cfd4dd;
  border-radius: 8px;
  padding: 5px 12px;
  cursor: pointer;
}
button:not(.tab):hover { background: #f3f4f7; }
button:not(.tab):active { background: #e9ebf0; }

.vec-inputs {
  display: grid;
  grid-template-columns: auto repeat(3, minmax(0, 1fr));
  gap: 6px 8px;
  align-items: center;
  margin-bottom: 10px;
}
.vec-inputs .hd {
  text-align: center;
  color: var(--muted);
  font-style: italic;
  font-family: Georgia, serif;
}
.vec-inputs input {
  width: 100%;
  font: inherit;
  font-variant-numeric: tabular-nums;
  padding: 3px 6px;
  border: 1px solid #cfd4dd;
  border-radius: 7px;
  text-align: right;
}

footer {
  padding-top: 4px;
  padding-bottom: 28px;
  color: var(--muted);
  font-size: .9rem;
}
footer a { color: inherit; }

/* ---------------------------------------------------------------- SVG */
.grid { stroke: #edf0f4; stroke-width: 1; }
.axis { stroke: #a3abb9; stroke-width: 1.3; }
.tick { fill: #9aa2b1; font-size: 11px; }
.origin { fill: var(--ink); }
.span-line {
  stroke: var(--c-a);
  stroke-opacity: .38;
  stroke-width: 2;
  stroke-dasharray: 8 6;
}
.span-label {
  fill: var(--c-a);
  fill-opacity: .8;
  font-size: 13px;
  font-weight: 600;
  font-style: italic;
}
.right-angle {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.5;
  stroke-linejoin: round;
}
.plane {
  fill: rgba(29, 78, 216, .13);
  stroke: rgba(29, 78, 216, .42);
  stroke-width: 1.2;
}
.plane-grid { stroke: rgba(29, 78, 216, .15); stroke-width: 1; }
.axis3.neg {
  stroke: #98a1b1;
  stroke-width: 1.3;
  stroke-dasharray: 4 5;
  stroke-opacity: .7;
}
.axis-label {
  fill: #6b7385;
  font: italic 600 17px Georgia, serif;
}
.guide {
  stroke: #7d8697;
  stroke-width: 1.4;
  stroke-dasharray: 4 4;
}

@media (max-width: 1000px) {
  .panel { grid-template-columns: 1fr; }
  .stage { position: relative; top: 0; height: 64vh; min-height: 360px; }
}
