:root {
  --ink: #1d1d1f;
  --muted: #636b70;
  --line: #d8dcda;
  --accent: #0f6b62;
  --accent-dark: #0b514a;
  --accent-soft: #e8f2ef;
  --candidate: #b2482c;
  --candidate-soft: #fbe9e2;
  --paper: #fffefa;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; }
button, input { font: inherit; }
.explorer { padding: 28px; }
.explorer-app { display: none; }
.file-fallback { display: block; max-width: 920px; padding: 24px; border: 1px solid var(--line); border-radius: 12px; background: #f6f6f4; }
.file-fallback h1 { margin: 0 0 10px; font-family: Georgia, "Times New Roman", serif; font-size: 2rem; font-weight: 500; letter-spacing: -0.03em; }
.file-fallback p { margin: 0 0 18px; line-height: 1.55; }
.file-fallback figure { margin: 0; }
.file-fallback img { display: block; width: 100%; border: 1px solid var(--line); border-radius: 9px; background: var(--paper); }
.file-fallback figcaption { margin-top: 10px; color: var(--muted); font-size: 0.9rem; line-height: 1.5; }
.js .explorer-app { display: block; }
.js .file-fallback { display: none; }
.show-fallback .explorer-app { display: none; }
.show-fallback .file-fallback { display: block; }

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.8rem, 3.6vw, 2.7rem); font-weight: 500; letter-spacing: -0.035em; line-height: 1.04; }
h2 { margin-bottom: 7px; font-size: 1rem; }
p, label, button, dt, dd { font-size: 0.92rem; line-height: 1.48; }
.explorer-header { max-width: 76ch; margin-bottom: 18px; }
.explorer-header > p:last-child { margin-bottom: 0; color: #3d3d40; }
.kicker { margin: 0 0 8px; color: var(--accent); font-size: 0.74rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }

.prediction-card { max-width: 84ch; margin: 0 0 18px; padding: 12px 14px; border-left: 4px solid var(--accent); border-radius: 0 9px 9px 0; background: var(--accent-soft); }
.prediction-card h2 { margin-bottom: 2px; color: var(--accent-dark); font-size: 0.88rem; }
.prediction-card p { margin: 0; color: #294f49; font-size: 0.84rem; }

.explorer-layout { display: grid; gap: 16px; }
.diagram-panel { min-width: 0; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
#aperture-diagram { display: block; width: 100%; height: auto; }
.diagram-note { margin: 8px 2px 0; color: var(--muted); font-size: 0.78rem; line-height: 1.4; }
.ray-key { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 9px 2px 0; color: #3d4145; font-size: 0.79rem; }
.ray-key-item { display: inline-flex; align-items: center; gap: 6px; }
.ray-key-swatch { display: block; flex: 0 0 30px; width: 30px; height: 14px; }

.dashboard { display: grid; grid-template-columns: minmax(230px, 0.95fr) minmax(255px, 1fr) minmax(250px, 1fr); gap: 14px; align-items: stretch; }
.controls-card, .limits-card, .trace-card { min-width: 0; padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.controls-card { background: #fbfcfa; }
fieldset { margin: 0; padding: 0; border: 0; }
legend { margin-bottom: 9px; font-size: 0.88rem; font-weight: 700; }
label { display: block; margin-top: 8px; font-weight: 650; }
label:first-of-type { margin-top: 0; }
label > span { display: block; }
output { display: block; margin-top: 1px; color: var(--accent); font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; margin-top: 2px; accent-color: var(--accent); }
button { width: 100%; margin-top: 12px; padding: 8px 9px; border: 1px solid var(--accent); border-radius: 8px; color: #fff; background: var(--accent); font-size: 0.84rem; font-weight: 700; cursor: pointer; }
button:hover { background: var(--accent-dark); }

.limits-card { background: #f6f6f4; }
.limits-card h2, .trace-card h2 { margin-bottom: 3px; }
.trace-context { margin-bottom: 8px; color: var(--muted); font-size: 0.8rem; }
.bound-list { margin: 0; }
.bound-list > div { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); }
.bound-list > div:last-child { padding-bottom: 4px; }
.bound-list dt { color: #3d4145; font-size: 0.8rem; }
.bound-list dd { margin: 0; color: var(--ink); font-size: 0.84rem; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.stop-status { display: inline-block; margin: 10px 0 7px; padding: 5px 8px; border-radius: 999px; color: var(--accent-dark); background: var(--accent-soft); font-size: 0.8rem; font-weight: 800; }
.stop-status.is-downstream { color: #8a3c1f; background: var(--candidate-soft); }
.stop-status.is-tie { color: #584900; background: #fff2c7; }
.limits-card > p:last-child { margin: 0; color: #3d4145; font-size: 0.8rem; }

.trace-card > p { margin-bottom: 8px; color: #3d4145; font-size: 0.8rem; }
.trace-equations { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfa; }
.trace-equations p { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 0.87rem; line-height: 1.55; }
.candidate-summary { margin: 10px 0 0 !important; color: #7f391f !important; font-size: 0.79rem !important; font-weight: 650; }

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

html.embedded, html.embedded body { min-height: 100%; }
.embedded .explorer { padding: 14px; }
.embedded .explorer-header { display: none; }
.embedded .prediction-card { margin-bottom: 12px; padding: 9px 11px; }
.embedded .prediction-card h2 { display: inline; margin-right: 5px; }
.embedded .prediction-card p { display: inline; font-size: 0.78rem; }
.embedded .diagram-panel { padding: 10px; }
.embedded .diagram-note { margin-top: 6px; font-size: 0.71rem; }
.embedded .ray-key { margin-top: 6px; font-size: 0.72rem; }
.embedded .dashboard { gap: 10px; }
.embedded .controls-card, .embedded .limits-card, .embedded .trace-card { padding: 11px; }
.embedded label { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; margin-top: 4px; font-size: 0.76rem; line-height: 1.15; }
.embedded label > span { display: inline; }
.embedded label output { grid-column: 2; grid-row: 1; margin: 0; text-align: right; }
.embedded label + input { margin-top: 0; }
.embedded legend { font-size: 0.8rem; }
.embedded output, .embedded input, .embedded button { font-size: 0.77rem; }
.embedded button { margin-top: 8px; padding: 7px 8px; }
.embedded .trace-context, .embedded .trace-card > p, .embedded .limits-card > p:last-child { font-size: 0.72rem; }
.embedded .bound-list > div { padding: 5px 0; }
.embedded .bound-list dt, .embedded .bound-list dd { font-size: 0.72rem; }
.embedded .stop-status { margin: 7px 0 5px; padding: 4px 7px; font-size: 0.72rem; }
.embedded .trace-equations { padding: 6px 8px; }
.embedded .trace-equations p { font-size: 0.75rem; }
.embedded .candidate-summary { margin-top: 7px !important; font-size: 0.7rem !important; }

@media (max-width: 840px) {
  .dashboard { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .trace-card { grid-column: 1 / -1; }
}

@media (max-width: 620px) {
  .explorer { padding: 18px; }
  .dashboard { grid-template-columns: 1fr; }
  .trace-card { grid-column: auto; }
  .embedded .explorer { padding: 10px; }
  .embedded .dashboard { grid-template-columns: 1fr; }
}
