:root {
  --bg: #080c0e;
  --panel: #0d1316;
  --panel-2: #111a1e;
  --text: #edf4f2;
  --muted: #82928f;
  --line: #243136;
  --line-strong: #34464c;
  --green: #63e6b1;
  --green-soft: rgba(99, 230, 177, .1);
  --amber: #ffbd66;
  --amber-soft: rgba(255, 189, 102, .11);
  --red: #ff7179;
  --blue: #6ac8ff;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; }
html { color-scheme: dark; scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; color: var(--text); background: radial-gradient(circle at 18% -10%, rgba(66, 126, 107, .14), transparent 32rem), var(--bg); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input { font: inherit; }
button { color: inherit; }
a { color: inherit; text-decoration: none; }

.topbar { height: 72px; padding: 0 clamp(18px, 3vw, 42px); display: flex; align-items: center; justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--line); background: rgba(8, 12, 14, .9); backdrop-filter: blur(16px); position: sticky; top: 0; z-index: 20; }
.brand { display: inline-flex; align-items: center; gap: 12px; }
.brand-mark { width: 40px; height: 40px; display: grid; place-items: center; color: var(--green); border: 1px solid var(--line-strong); font: 800 .8rem/1 var(--mono); letter-spacing: .12em; }
.brand b, .brand small { display: block; }
.brand b { font-size: .9rem; }
.brand small { margin-top: 2px; color: var(--muted); font: 600 .58rem/1 var(--mono); letter-spacing: .14em; text-transform: uppercase; }
.topbar-actions { display: flex; align-items: center; gap: 22px; color: var(--muted); font-size: .76rem; }
.topbar-actions a:hover { color: var(--text); }
.session-state { color: var(--green); font: 700 .61rem/1 var(--mono); letter-spacing: .12em; }
.session-state i { display: inline-block; width: 6px; height: 6px; margin-right: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 10px var(--green); }

main { width: min(1480px, calc(100% - 36px)); margin: 0 auto; }
.intro { min-height: 300px; display: grid; grid-template-columns: 1.1fr .75fr; gap: 60px; align-items: end; padding: 72px 0 48px; }
.kicker, .panel-heading span, .card-label, .control-head, .explain-box > span, .learning-note > span { color: var(--green); font: 700 .62rem/1.3 var(--mono); letter-spacing: .14em; text-transform: uppercase; }
h1 { margin: 12px 0 0; max-width: 820px; font-size: clamp(2.8rem, 6.6vw, 6.8rem); line-height: .9; letter-spacing: -.07em; }
h1 em { color: var(--muted); font-style: normal; font-weight: 420; }
.intro-copy { max-width: 570px; margin: 0 0 10px; color: #aebbb8; font-size: clamp(1rem, 1.6vw, 1.22rem); line-height: 1.65; }

.system-tabs { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); background: var(--panel); }
.system-tab { min-width: 0; min-height: 94px; padding: 18px 20px; display: grid; grid-template-columns: auto 1fr; gap: 13px; align-items: center; text-align: left; border: 0; border-right: 1px solid var(--line); background: transparent; cursor: pointer; position: relative; }
.system-tab:last-child { border-right: 0; }
.system-tab::after { content: ""; position: absolute; left: 0; right: 100%; bottom: -1px; height: 2px; background: var(--green); transition: right .3s ease; }
.system-tab:hover { background: rgba(255,255,255,.02); }
.system-tab.active { background: linear-gradient(180deg, var(--green-soft), transparent); }
.system-tab.active::after { right: 0; }
.tab-number { color: #50605e; font: 700 .64rem var(--mono); }
.system-tab b, .system-tab small { display: block; }
.system-tab b { font-size: .87rem; }
.system-tab small { margin-top: 4px; overflow: hidden; color: var(--muted); font-size: .67rem; text-overflow: ellipsis; white-space: nowrap; }
.tab-state { grid-column: 2; color: var(--green); font: 700 .55rem var(--mono); letter-spacing: .1em; font-style: normal; }
.system-tab.fault .tab-state { color: var(--red); }

.system-panel { padding: 52px 0 26px; }
.system-panel[hidden] { display: none; }
.panel-heading { display: grid; grid-template-columns: 1fr .8fr; gap: 30px; align-items: end; margin-bottom: 24px; }
.panel-heading h2 { margin: 7px 0 0; font-size: clamp(2rem, 4vw, 3.8rem); line-height: 1; letter-spacing: -.055em; }
.panel-heading p { max-width: 610px; justify-self: end; margin: 0; color: var(--muted); line-height: 1.6; }
.lab-grid { display: grid; grid-template-columns: minmax(0, 1.62fr) minmax(330px, .78fr); border: 1px solid var(--line); background: var(--panel); }
.schematic-card { min-width: 0; padding: 20px 22px 0; border-right: 1px solid var(--line); background: radial-gradient(circle at 50% 30%, rgba(75, 122, 108, .08), transparent 45%); }
.card-label, .control-head { display: flex; justify-content: space-between; align-items: center; min-height: 28px; }
.card-label > span, .control-head > span { color: var(--muted); }
.card-label b { color: var(--green); font-weight: 700; }
.schematic { width: 100%; height: auto; max-height: 530px; display: block; }
.schematic text, .pressure-map text { fill: var(--muted); font: 600 12px var(--mono); text-anchor: middle; }
.wire, .pressure, .fuel-line, .pump-line { fill: none; stroke: #334247; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; transition: stroke .25s, opacity .25s; }
.wire.live, .pressure.live, .fuel-line.live, .pump-line.live { stroke: var(--green); filter: drop-shadow(0 0 5px rgba(99, 230, 177, .55)); stroke-dasharray: 9 7; animation: flow 1s linear infinite; }
.wire.failed, .pressure.failed, .fuel-line.failed { stroke: var(--red); stroke-dasharray: 4 7; opacity: .8; }
@keyframes flow { to { stroke-dashoffset: -32; } }
.source-node rect, .component rect, .load rect, .tank path:first-child { fill: #10191c; stroke: var(--line-strong); stroke-width: 2; }
.source-node circle, .distributor circle, .component circle { fill: #111b1e; stroke: var(--line-strong); stroke-width: 2; }
.source-node.active rect, .source-node.active circle, .component.active rect, .component.active circle, .load.active rect { stroke: var(--green); }
.source-node.failed rect, .component.failed rect, .load.failed rect { stroke: var(--red); }
.source-node text, .distributor text, .component text, .load text, .tank text { fill: #bcc8c5; font-size: 11px; }
.source-node.active circle { fill: var(--green); filter: url(#glow-green); animation: pulse 1s ease-in-out infinite alternate; }
@keyframes pulse { to { opacity: .35; } }
.distributor circle { fill: #0d1518; }
.engine-block rect { fill: #11191c; stroke: var(--line-strong); stroke-width: 2; }
.engine-block path { stroke: #405156; fill: none; }
.engine-block circle { fill: #0a0f11; stroke: #405156; }
.spark path { fill: none; stroke: #48585c; stroke-width: 3; }
.spark.active path { stroke: var(--amber); filter: drop-shadow(0 0 5px rgba(255,189,102,.8)); }
.ground-note path, .vent { fill: none; stroke: #405156; stroke-width: 2; stroke-dasharray: 4 5; }
.ground-note text { text-anchor: start; font-size: 10px; }
.bus path { stroke: #46575b; stroke-width: 7; }
.bus.live path { stroke: var(--green); filter: drop-shadow(0 0 5px rgba(99,230,177,.5)); }
.breaker circle { fill: #10181b; stroke: var(--green); stroke-width: 3; }
.breaker.tripped circle:nth-child(2) { stroke: var(--red); fill: rgba(255,113,121,.2); }

.readout-strip { min-height: 88px; display: grid; grid-template-columns: repeat(3, 1fr); margin: 0 -22px; border-top: 1px solid var(--line); }
.readout-strip > div { display: flex; flex-direction: column; justify-content: center; padding: 15px 22px; border-right: 1px solid var(--line); }
.readout-strip > div:last-child { border-right: 0; }
.readout-strip span { color: var(--muted); font: 700 .55rem var(--mono); letter-spacing: .12em; }
.readout-strip strong { margin-top: 8px; font: 700 1.2rem var(--mono); }
.readout-strip small { color: var(--muted); font-size: .6em; }

.control-card { min-width: 0; padding: 20px 22px; background: #0b1113; }
.reset-button { padding: 7px 9px; color: var(--muted); border: 1px solid var(--line); background: transparent; font: 700 .56rem var(--mono); letter-spacing: .1em; cursor: pointer; }
.reset-button:hover { color: var(--text); border-color: var(--line-strong); }
fieldset { min-width: 0; margin: 24px 0 0; padding: 0; border: 0; }
legend, .range-label { width: 100%; margin-bottom: 10px; display: flex; justify-content: space-between; color: var(--muted); font: 700 .58rem var(--mono); letter-spacing: .1em; text-transform: uppercase; }
.range-label { margin-top: 23px; }
.range-label output { color: var(--text); }
.key-switch { display: grid; grid-template-columns: repeat(5, 1fr); border: 1px solid var(--line); }
.key-switch button { min-height: 42px; padding: 7px 4px; border: 0; border-right: 1px solid var(--line); background: transparent; color: var(--muted); font: 700 .61rem var(--mono); cursor: pointer; }
.key-switch button:last-child { border-right: 0; }
.key-switch button:hover, .key-switch button.active { color: #08100d; background: var(--green); }
.fuel-selector { grid-template-columns: repeat(4, 1fr); }
input[type="range"] { width: 100%; height: 4px; margin: 4px 0 2px; appearance: none; border-radius: 0; outline: 0; background: linear-gradient(90deg, var(--green) 0 var(--value, 50%), #263338 var(--value, 50%)); }
input[type="range"]::-webkit-slider-thumb { width: 15px; height: 15px; appearance: none; border: 2px solid #0a1012; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 1px var(--green); cursor: pointer; }
.toggle-row { display: flex; flex-wrap: wrap; gap: 10px 20px; }
.toggle { display: inline-flex; align-items: center; gap: 8px; color: #b9c5c2; font: 700 .62rem var(--mono); cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle span { width: 34px; height: 18px; padding: 2px; display: inline-flex; justify-content: flex-start; border: 1px solid var(--line-strong); background: #11191c; transition: .2s; }
.toggle span::after { content: ""; width: 12px; height: 12px; background: #5b6867; transition: .2s; }
.toggle input:checked + span { justify-content: flex-end; border-color: var(--green); background: var(--green-soft); }
.toggle input:checked + span::after { background: var(--green); box-shadow: 0 0 7px rgba(99,230,177,.6); }
.fault-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.fault-grid button { min-height: 38px; padding: 8px; color: #b2bfbc; border: 1px solid var(--line); background: #11181a; font: 700 .56rem/1.2 var(--mono); letter-spacing: .04em; cursor: pointer; }
.fault-grid button:hover { border-color: rgba(255,113,121,.5); }
.fault-grid button.active { color: var(--red); border-color: var(--red); background: rgba(255,113,121,.08); }
.explain-box { margin-top: 24px; padding: 17px; border-left: 2px solid var(--green); background: var(--green-soft); }
.explain-box.warning { border-color: var(--red); background: rgba(255,113,121,.07); }
.explain-box.warning > span { color: var(--red); }
.explain-box b { display: block; margin-top: 8px; font-size: .83rem; }
.explain-box p { margin: 6px 0 0; color: var(--muted); font-size: .72rem; line-height: 1.5; }
.annunciators { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 20px; }
.annunciators span { padding: 7px 9px; color: #5c6665; border: 1px solid #2b3436; background: #111719; font: 700 .54rem var(--mono); }
.annunciators span.active { color: var(--red); border-color: rgba(255,113,121,.55); background: rgba(255,113,121,.1); box-shadow: inset 0 0 12px rgba(255,113,121,.08); }

.instrument-bay { min-height: 405px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; place-items: center; padding: 35px 12px 16px; }
.mini-gauge { width: min(100%, 225px); text-align: center; }
.gauge-title, .mini-gauge > span:last-child { display: block; color: var(--muted); font: 700 .55rem var(--mono); letter-spacing: .1em; }
.dial { aspect-ratio: 1; margin: 10px 0; display: grid; place-content: center; border: 8px solid #1e292d; border-radius: 50%; background: repeating-conic-gradient(from -120deg, #536267 0 1deg, transparent 1deg 15deg), radial-gradient(circle, #11191c 0 58%, #090e10 59%); box-shadow: inset 0 0 30px #000, 0 8px 30px rgba(0,0,0,.3); position: relative; }
.dial::after { content: ""; position: absolute; inset: 8%; border: 1px solid rgba(255,255,255,.06); border-radius: 50%; }
.dial i { position: absolute; z-index: 2; left: calc(50% - 2px); bottom: 50%; width: 4px; height: 35%; border-radius: 3px 3px 0 0; background: var(--text); transform: rotate(var(--angle, 0deg)); transform-origin: 50% 100%; transition: transform .35s cubic-bezier(.2,.7,.2,1); box-shadow: 0 0 5px rgba(255,255,255,.5); }
.dial i::after { content: ""; position: absolute; left: -4px; bottom: -6px; width: 12px; height: 12px; border-radius: 50%; background: var(--text); }
.dial b, .dial small { position: relative; z-index: 3; display: block; }
.dial b { margin-top: 28px; font: 700 clamp(1.1rem, 2.3vw, 1.75rem) var(--mono); }
.dial small { margin-top: 2px; color: var(--muted); font: 700 .46rem var(--mono); letter-spacing: .12em; }
.pressure-map { width: 100%; display: block; }
.pressure-map rect { fill: #10181b; stroke: var(--line-strong); stroke-width: 2; }

.fuel-schematic .tank text { position: relative; }
.fuel-level { fill: rgba(99,230,177,.22); stroke: var(--green); stroke-width: 1; transition: d .3s; }
.vent { stroke-dasharray: 4 5; }
.vent.failed { stroke: var(--red); }
.pump { fill: #111a1d; stroke: var(--line-strong); stroke-width: 2; }
.pump.active { stroke: var(--green); }
.engine-symbol path { fill: #111a1d; stroke: var(--line-strong); stroke-width: 2; }

.learning-note { margin: 32px 0 70px; padding: 22px 24px; display: grid; grid-template-columns: 150px 1fr; gap: 30px; align-items: start; border: 1px solid var(--line); background: rgba(255,255,255,.02); }
.learning-note p { max-width: 900px; margin: 0; color: var(--muted); font-size: .78rem; line-height: 1.6; }
footer { min-height: 76px; padding: 0 clamp(18px, 3vw, 42px); display: flex; align-items: center; justify-content: space-between; gap: 20px; color: #60706d; border-top: 1px solid var(--line); font-size: .68rem; }

@media (max-width: 1050px) {
  .intro { grid-template-columns: 1fr; gap: 24px; min-height: auto; }
  .system-tabs { grid-template-columns: repeat(2, 1fr); }
  .system-tab:nth-child(2) { border-right: 0; }
  .system-tab:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .lab-grid { grid-template-columns: 1fr; }
  .schematic-card { border-right: 0; border-bottom: 1px solid var(--line); }
  .control-card { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 28px; }
  .control-head, .explain-box, .annunciators { grid-column: 1 / -1; }
}

@media (max-width: 700px) {
  .topbar { height: 64px; padding: 0 13px; }
  .brand small, .session-state, .topbar-actions a:first-of-type { display: none; }
  .topbar-actions { gap: 12px; }
  main { width: min(100% - 22px, 1480px); }
  .intro { padding: 46px 2px 34px; }
  h1 { font-size: clamp(2.7rem, 14vw, 4.5rem); }
  .system-tabs { grid-template-columns: 1fr 1fr; }
  .system-tab { min-height: 82px; padding: 13px 11px; }
  .system-tab small { display: none; }
  .tab-state { font-size: .48rem; }
  .panel-heading { grid-template-columns: 1fr; }
  .panel-heading p { justify-self: start; }
  .system-panel { padding-top: 38px; }
  .schematic-card { padding: 14px 12px 0; overflow: hidden; }
  .schematic { min-width: 610px; transform: translateX(-12%); }
  .readout-strip { margin: 0 -12px; }
  .readout-strip > div { padding: 12px 9px; }
  .readout-strip strong { font-size: .9rem; }
  .control-card { display: block; padding: 17px 15px; }
  .instrument-bay { grid-template-columns: 1fr; }
  .mini-gauge { width: 190px; }
  .pressure-map { min-width: 600px; transform: translateX(-13%); }
  .learning-note { grid-template-columns: 1fr; gap: 8px; }
  footer { align-items: flex-start; flex-direction: column; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .001ms !important; }
}
