:root {
  --ink: #1d1d1f;
  --muted: #636b70;
  --line: #d8dcda;
  --accent: #0f6b62;
  --accent-dark: #0b514a;
  --accent-soft: #e8f2ef;
  --exit: #4c5aa3;
  --exit-soft: #eceefa;
  --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, legend { 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: 88ch; margin: 0 0 14px; 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; }

.view-switch { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; width: fit-content; max-width: 100%; margin: 0 0 14px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.view-switch legend { width: 100%; margin-bottom: 0; font-size: 0.82rem; font-weight: 750; }
.view-switch label { display: inline-flex; gap: 6px; align-items: center; margin: 0; padding: 4px 7px; border: 1px solid transparent; border-radius: 7px; color: #3d4145; font-size: 0.82rem; font-weight: 650; cursor: pointer; }
.view-switch label:has(input:checked) { border-color: #9bc8c0; color: var(--accent-dark); background: var(--accent-soft); }
.view-switch input { margin: 0; accent-color: var(--accent); }

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

.dashboard { display: grid; grid-template-columns: minmax(240px, 1.08fr) minmax(245px, 1fr) minmax(245px, 1fr); gap: 14px; align-items: stretch; }
.controls-card, .pupil-card, .method-card { min-width: 0; padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.controls-card { background: #fbfcfa; }
.controls-card fieldset { margin: 0; padding: 0; border: 0; }
.controls-card legend { margin-bottom: 8px; font-size: 0.88rem; font-weight: 750; }
.controls-card label { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: baseline; margin-top: 7px; color: #313538; font-weight: 650; }
.controls-card label > span { min-width: 0; }
.controls-card output { color: var(--accent); font-variant-numeric: tabular-nums; font-weight: 700; text-align: right; }
.controls-card input[type="range"] { width: 100%; margin-top: 0; accent-color: var(--accent); }
.control-group-title { margin: 10px 0 1px; padding-top: 8px; border-top: 1px solid var(--line); color: #4d5559; font-size: 0.77rem; font-weight: 800; letter-spacing: 0.035em; text-transform: uppercase; }
.controls-card button { width: 100%; margin-top: 11px; 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; }
.controls-card button:hover { background: var(--accent-dark); }

.pupil-card { background: #f6f6f4; }
.pupil-card h2, .method-card h2 { margin-bottom: 3px; }
.pupil-status { display: inline-block; margin: 6px 0 8px; padding: 5px 8px; border-radius: 999px; color: var(--accent-dark); background: var(--accent-soft); font-size: 0.8rem; font-weight: 800; }
.pupil-status.is-virtual { color: #7d3c23; background: #fbe9e2; }
.pupil-status.is-infinite { color: #584900; background: #fff2c7; }
.pupil-results { margin: 0; }
.pupil-results > div { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); }
.pupil-results dt { color: #3d4145; font-size: 0.8rem; }
.pupil-results dd { margin: 0; color: var(--ink); font-size: 0.84rem; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.pupil-card > p:last-child { margin: 9px 0 0; color: #3d4145; font-size: 0.79rem; }

.method-card > p { margin-bottom: 8px; color: #3d4145; font-size: 0.8rem; }
.formula-block { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfa; }
.formula-block p { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 0.91rem; line-height: 1.62; }
.construction-note { margin-bottom: 0 !important; color: #4d5559 !important; font-size: 0.78rem !important; }

.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: 10px; padding: 9px 11px; }
.embedded .prediction-card h2 { display: inline; margin-right: 5px; }
.embedded .prediction-card p { display: inline; font-size: 0.78rem; }
.embedded .view-switch { margin-bottom: 10px; padding: 6px 8px; }
.embedded .view-switch legend { font-size: 0.76rem; }
.embedded .view-switch label { padding: 3px 5px; font-size: 0.74rem; }
.embedded .diagram-panel { padding: 10px; }
.embedded .diagram-note { margin-top: 6px; font-size: 0.71rem; }
.embedded .construction-key { margin-top: 6px; font-size: 0.72rem; }
.embedded .dashboard { gap: 10px; }
.embedded .controls-card, .embedded .pupil-card, .embedded .method-card { padding: 11px; }
.embedded .controls-card legend { margin-bottom: 5px; font-size: 0.78rem; }
.embedded .controls-card label { margin-top: 4px; font-size: 0.74rem; line-height: 1.15; }
.embedded .controls-card output, .embedded .controls-card input, .embedded .controls-card button { font-size: 0.75rem; }
.embedded .control-group-title { margin-top: 7px; padding-top: 6px; font-size: 0.7rem; }
.embedded .controls-card button { margin-top: 8px; padding: 7px 8px; }
.embedded .pupil-results > div { padding: 5px 0; }
.embedded .pupil-results dt, .embedded .pupil-results dd, .embedded .pupil-card > p:last-child, .embedded .method-card > p { font-size: 0.72rem; }
.embedded .pupil-status { margin: 5px 0 6px; padding: 4px 7px; font-size: 0.71rem; }
.embedded .formula-block { padding: 6px 8px; }
.embedded .formula-block p { font-size: 0.77rem; }
.embedded .construction-note { font-size: 0.7rem !important; }

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

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