:root {
  color-scheme: light;
  font-family: "Aptos", "Segoe UI", system-ui, sans-serif;
  color: #18362f;
  background: #edf2ed;
  --muted: #4d655e;
  --line: #d2dfd6;
  --accent: #14584a;
  --dark: #173d35;
  --alert: #8e3822;
  --alert-bg: #fff2e7;
  --river: #28a8d7;
  --penstock: #36cab2;
  --grid: #f4bb50;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
h1, h2, h3, p, dl, dd, ol { margin: 0; }
button { font: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid #0d7865; outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.shell { width: min(100%, 1240px); margin-inline: auto; padding-inline: clamp(14px, 3.5vw, 42px); }
main.shell { padding-bottom: 42px; }
.site-header { background: var(--dark); color: #fff; }
.site-inner { min-height: 54px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.site-inner a { display: inline-flex; align-items: center; gap: .25em; min-height: 44px; color: inherit; text-decoration: none; }
.site-inner a:focus-visible { outline-color: #c4f0c9; }
.brand { font-size: clamp(1.05rem, 2.05vw, 1.4rem); font-weight: 800; letter-spacing: -.055em; }
.brand span { color: #b5e5b5; margin-left: -.25em; }
.site-nav { display: flex; gap: clamp(10px, 2vw, 22px); white-space: nowrap; }
.home-link { font-size: .86rem; font-weight: 650; }
.home-link:hover { text-decoration: underline; }
.intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; padding-block: clamp(15px, 2.4vw, 29px) clamp(13px, 1.7vw, 21px); }
.lab-name { color: #386250; font-size: .8rem; font-weight: 800; letter-spacing: .055em; }
h1 { font-size: clamp(1.85rem, 4.4vw, 3.55rem); line-height: 1; letter-spacing: -.065em; margin-block: 3px 7px; }
.objective { max-width: 66ch; color: var(--muted); line-height: 1.42; font-size: clamp(.85rem, 1.6vw, 1rem); }
.objective strong { color: #204c3d; white-space: nowrap; }
.clock { flex: none; background: #dfece0; border: 1px solid #c9dccc; border-radius: 12px; padding: 6px 14px 8px; text-align: center; line-height: 1.05; }
.clock span { display: block; font-size: .76rem; color: #395a4a; font-weight: 750; }
.clock time { display: block; margin-top: 3px; font-size: clamp(1.19rem, 2.7vw, 1.9rem); font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.04em; }
.indicators { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: clamp(8px, 1.6vw, 18px); margin-bottom: clamp(10px, 1.6vw, 18px); }
.indicator, .card { min-width: 0; border: 1px solid var(--line); border-radius: 14px; background: #fcfdfb; }
.indicator { padding: clamp(9px, 1.42vw, 15px) clamp(9px, 1.8vw, 20px); border-top: 3px solid #2f846c; }
.indicator + .indicator { border-top-color: #2b81a6; }
.indicator dt { font-size: clamp(.84rem, 1.55vw, 1.02rem); font-weight: 760; }
.reading { white-space: nowrap; letter-spacing: -.025em; line-height: 1.08; }
.reading span { font-size: clamp(1.36rem, 3.7vw, 2.37rem); font-weight: 800; font-variant-numeric: tabular-nums; }
.reading small { color: #445b54; font-size: clamp(.73rem, 1.75vw, 1.09rem); font-weight: 670; }
.metric-label { font-size: .7rem; color: var(--muted); margin-top: 3px; }
.metric-status { padding-top: 4px; font-size: clamp(.7rem, 1.4vw, .82rem); font-weight: 750; color: #1d6046; }
.indicator[data-alert] { border-top-color: #b44e31; background: #fffaf5; }
.indicator[data-alert] .metric-status { color: var(--alert); }

.workspace { display: grid; grid-template-columns: minmax(0, 1.67fr) minmax(315px, 1fr); align-items: start; gap: clamp(10px, 1.6vw, 18px); }
.controls { grid-column: 2; grid-row: 1; padding: clamp(11px, 1.6vw, 19px); scroll-margin-top: 12px; }
.scene { grid-column: 1; grid-row: 1; overflow: hidden; }
.card-heading { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 6px 10px; }
h2 { font-size: clamp(1.19rem, 2.2vw, 1.55rem); letter-spacing: -.035em; line-height: 1.11; }
.mode { border-radius: 6px; background: #e5efe6; color: #2f5847; font-size: .75rem; font-weight: 750; padding: 4px 7px; }
.controls[data-mode="paused"] .mode { color: #73461d; background: #f4ead6; }
progress { display: block; width: 100%; height: 5px; margin-top: 10px; border: 0; border-radius: 10px; appearance: none; overflow: hidden; background: #e6ede7; }
progress::-webkit-progress-bar { background: #e6ede7; border-radius: 10px; }
progress::-webkit-progress-value { background: #488b72; border-radius: 10px; }
progress::-moz-progress-bar { background: #488b72; border-radius: 10px; }
.phase-note { color: var(--muted); font-size: .82rem; line-height: 1.4; margin-block: 9px 10px; }
.gate-state { display: flex; flex-wrap: wrap; gap: 4px 16px; color: var(--muted); font-size: .75rem; }
.gate-state div { display: flex; gap: 4px; align-items: baseline; }
.gate-state dd { color: #254d40; font-weight: 780; }
fieldset { border: 0; padding: 0; margin: 11px 0 0; min-width: 0; }
legend { padding: 0; margin-bottom: 5px; font-size: .82rem; font-weight: 770; }
legend span { color: var(--muted); font-size: .71rem; font-weight: 500; }
.gate-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
.gate-options label { position: relative; min-width: 0; cursor: pointer; }
.gate-options input { opacity: 0; position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.gate-options label > span { display: flex; min-height: 48px; padding: 4px; flex-direction: column; justify-content: center; align-items: center; border-radius: 7px; border: 1px solid #cdded4; background: #f6faf6; line-height: 1.15; }
.gate-options strong { font-size: clamp(.75rem, 2.7vw, .91rem); }
.gate-options small { color: var(--muted); font-size: .69rem; margin-top: 2px; }
.gate-options input:checked + span { background: #e0efe6; color: #145340; border-color: #3e806b; box-shadow: inset 0 -2px #3e806b; }
.gate-options input:focus-visible + span { outline: 3px solid #0d7865; outline-offset: 2px; }
.gate-options label:hover > span { border-color: #3e806b; }
.preview { margin-top: 10px; border-radius: 7px; padding: 7px 9px; background: #edf4ef; }
.preview h3 { font-size: .79rem; margin-bottom: 3px; }
.preview dl, .recorded { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 12px; }
.preview dt, .recorded dt { color: var(--muted); font-size: .73rem; }
.preview dd { font-size: .9rem; font-weight: 750; }
.preview dd[data-alert] { color: var(--alert); }
.warnings { display: grid; }
.warnings p { margin-top: 8px; padding: 7px 9px; border-radius: 6px; background: var(--alert-bg); border-left: 3px solid #bd5d3a; color: var(--alert); font-size: .8rem; line-height: 1.36; font-weight: 640; }
.primary, .secondary, .quiet { min-height: 44px; padding: 7px 13px; border-radius: 8px; font-weight: 760; font-size: .88rem; }
.primary { border: 1px solid var(--accent); color: #fff; background: var(--accent); }
.primary:hover { background: #104d40; }
.secondary { border: 1px solid #a5c2b3; color: #205040; background: #f5faf6; }
.secondary:hover, .quiet:hover { background: #e7f2e9; }
.mission-action { width: 100%; margin-top: 10px; }
.recorded { margin-top: 10px; border-top: 1px solid #e0e9e1; padding-top: 7px; }
.recorded dd { font-weight: 750; font-size: .85rem; }

.scene-heading { padding: 0 14px; min-height: 51px; }
.quiet { border: 0; color: #205040; background: transparent; padding-inline: 8px; font-size: .78rem; }
.stage { position: relative; isolation: isolate; overflow: hidden; width: 100%; aspect-ratio: 1.8; min-height: 255px; background: #dae9df; }
.stage canvas { display: none; position: absolute; inset: 0; width: 100%; height: 100%; }
.stage[data-renderer="3d"] canvas { display: block; }
.stage[data-renderer="3d"] .diagram, .stage:not([data-renderer="3d"]) .scene-labels { display: none; }
.scene-labels span { position: absolute; transform: translate(-50%, -100%); pointer-events: none; color: white; background: #18382ff2; border: 1px solid #cbece1a6; border-radius: 5px; padding: 4px 6px; font-size: clamp(.62rem, 1.25vw, .76rem); font-weight: 740; white-space: nowrap; }
.scene-labels [data-label="river"] { color: #143747; background: #d8f5ff; border-color: #73cee9; }
.flow-key { list-style: none; display: flex; flex-wrap: wrap; gap: 5px 13px; padding: 10px 14px 0; margin: 0; color: #2f5147; }
.flow-key li { display: flex; gap: 5px; align-items: center; font-size: .74rem; font-weight: 720; }
.flow-key i { display: inline-block; width: 13px; height: 4px; border-radius: 3px; }
.key-river { background: var(--river); }
.key-plant { background: #219786; }
.key-power { background: #bb7515; }
.scene-note { color: var(--muted); font-size: .78rem; padding: 6px 14px 10px; line-height: 1.4; }
.plant-info { background: #f2f7f1; border-top: 1px solid #e0e9e1; padding: 9px 14px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.plant-info dt { color: var(--muted); font-size: .7rem; }
.plant-info dd { font-size: .85rem; font-weight: 750; }
.diagram { min-height: 100%; display: flex; flex-direction: column; justify-content: center; padding: 14px; background: #dfeee7; text-align: center; }
.diagram .source, .diagram .return, .route { background: #f6fcf8; border: 1px solid #afcebf; border-radius: 8px; padding: 7px; font-size: .81rem; }
.diagram .source, .diagram .return { align-self: center; }
.diagram span, .diagram small { display: block; }
.diagram span { font-weight: 750; }
.diagram small { font-size: .69rem; margin-top: 2px; }
.branch { width: 49%; height: 14px; margin-inline: auto; border-top: 2px solid #318d8e; border-inline: 2px solid #318d8e; }
.branch.merge { transform: rotate(180deg); }
.routes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.river-route { border-top: 3px solid var(--river); }
.plant-route { border-top: 3px solid #219786; }

.results { padding: clamp(12px, 2vw, 23px); }
#outcome { display: inline-block; background: #e4f3e7; color: #215e3e; padding: 5px 9px; border-radius: 6px; font-size: .9rem; }
#outcome[data-alert] { color: var(--alert); background: var(--alert-bg); }
#result-summary { margin-block: 8px 13px; line-height: 1.4; color: var(--muted); }
.comparison { width: 100%; border-collapse: collapse; text-align: left; }
.comparison th, .comparison td { border-bottom: 1px solid #dfebe2; padding: 8px 11px; font-size: .86rem; }
.comparison thead { background: #edf4ee; }
.comparison .mobile-label { display: none; }
.comparison-note { color: var(--muted); margin-block: 8px 13px; font-size: .8rem; }
.result-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.history { margin-top: clamp(10px, 1.6vw, 18px); padding-inline: 14px; }
.history summary { min-height: 44px; align-content: center; font-weight: 750; cursor: pointer; }
.history p, .history ol { color: var(--muted); font-size: .82rem; margin-block: 0 11px; }
.history ol { padding-left: 1.4em; }
.history li { padding-block: 3px; line-height: 1.4; }
.quick-controls { display: none; }

@media (max-width: 740px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .controls, .scene { grid-column: auto; grid-row: auto; }
  .stage { aspect-ratio: 1.53; }
  .quick-controls { display: flex; position: fixed; z-index: 2; left: max(10px, env(safe-area-inset-left)); right: max(10px, env(safe-area-inset-right)); bottom: max(9px, env(safe-area-inset-bottom)); align-items: center; justify-content: space-between; gap: 6px; border-radius: 10px; background: #f6fcf5; box-shadow: 0 3px 17px #173d3545; border: 1px solid #adc9b9; padding: 5px 5px 5px 9px; }
  .quick-controls span { font-size: .78rem; font-weight: 750; }
  main.shell { padding-bottom: 78px; }
}

@media (max-width: 520px) {
  .intro { align-items: flex-start; gap: 6px; }
  .clock { margin-top: 19px; padding-inline: 7px; }
  .plant-info { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .comparison, .comparison tbody { display: block; }
  .comparison thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .comparison tbody tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); padding-block: 5px; border-bottom: 1px solid #dfebe2; }
  .comparison th, .comparison td { border: 0; padding: 3px 5px; }
  .comparison th { grid-column: 1 / -1; background: #edf4ee; }
  .comparison .mobile-label { display: block; color: var(--muted); font-size: .69rem; line-height: 1.13; margin-bottom: 2px; }
}
