:root {
  color-scheme: dark;
  --page: #0c1520;
  --surface: #122435;
  --line: #315166;
  --text: #f0f6f8;
  --muted: #bfced7;
  --live: #8af5d3;
  --gold: #ffe3a1;
  --focus: #fff0bb;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: radial-gradient(ellipse at 78% 0%, #173b49 0%, var(--page) 42rem);
  color: var(--text);
  font: 1rem/1.6 system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  accent-color: var(--live);
}
a { color: var(--live); text-underline-offset: .19em; }
a:hover { color: white; }
:is(a, button, input, canvas):focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
button {
  color: var(--text);
  background: #18384a;
  border: 1px solid #597788;
  border-radius: 9px;
  padding: .48rem .85rem;
  min-height: 44px;
  font: inherit;
  font-weight: 680;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--live); background: #22505c; }
button:disabled { opacity: .55; cursor: default; }
p { margin: .65rem 0; }
h1, h2, h3 { line-height: 1.16; margin: 0; }
h1 { font-size: clamp(2.5rem, 7vw, 4.65rem); letter-spacing: -.052em; }
h2 { font-size: clamp(1.65rem, 4.6vw, 2.5rem); letter-spacing: -.028em; }
h3 { font-size: 1.15rem; }
.game-page { width: min(calc(100% - 32px), 1060px); margin-inline: auto; padding: 1.5rem 0 4rem; }
.game-nav { display: flex; flex-wrap: wrap; gap: .55rem 1.25rem; font-size: .94rem; }
.game-title { padding: clamp(2rem, 6vw, 4rem) 0 1.6rem; }
.game-title p { max-width: 65ch; color: var(--muted); font-size: clamp(1.02rem, 2vw, 1.2rem); }
.game-title .subject { color: var(--live); font-size: .92rem; font-weight: 700; margin: 0 0 .65rem; }
.learning-section { border-top: 1px solid var(--line); padding: clamp(1.4rem, 4vw, 2.3rem) 0; }
.learning-section > h2 { margin-bottom: .85rem; }
.reading { max-width: 76ch; }
.reading p, .takeaways { color: var(--muted); }
.terms { margin: .1rem 0 0; }
.terms > div {
  display: grid;
  grid-template-columns: minmax(10rem, 1fr) minmax(0, 3fr);
  gap: .28rem 1rem;
  padding: .49rem 0;
  border-bottom: 1px solid #233d51;
}
.terms > div:last-child { border-bottom: 0; }
.terms dt { color: var(--text); font-weight: 700; }
.terms dd { color: var(--muted); margin: 0; }
.application-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .65rem 1rem; }
.instructions { max-width: 80ch; margin: .55rem 0 1.15rem; color: var(--muted); }
.instructions p { margin: .35rem 0; }
.takeaways { max-width: 76ch; padding-left: 1.25rem; }
.takeaways li + li { margin-top: .62rem; }
.course-footer { margin: 0; border-top: 1px solid var(--line); padding-top: 1.3rem; font-size: 1.07rem; }
.stats {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: .4rem 1.3rem;
  background: #162935;
  border: 1px solid var(--line);
  border-radius: 12px 12px 0 0;
  padding: .58rem clamp(.65rem, 2vw, 1rem);
  font-variant-numeric: tabular-nums;
}
.stat { flex: 1 1 auto; min-width: 5.5rem; font-size: .83rem; line-height: 1.4; color: var(--muted); }
.stat strong { display: block; color: var(--text); font-size: clamp(.94rem, 2.2vw, 1.24rem); }
.stats + .world, .stats + .console { border-radius: 0 0 14px 14px; border-top: 0; }
.world, .console {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #122a34;
  position: relative;
  overflow: hidden;
}
.world {
  width: 100%;
  aspect-ratio: var(--wide-ratio, 16 / 9);
  isolation: isolate;
}
.world canvas { display: block; width: 100%; height: 100%; }
.world.canvas-control canvas { touch-action: none; cursor: crosshair; outline-offset: -4px; }
.world[data-dragging=true] { cursor: grabbing; }
.world[data-dragging=true] button { cursor: grabbing; }
.map-legend, .controls-text { color: var(--muted); font-size: .92rem; }
.map-legend { display: flex; flex-wrap: wrap; gap: .25rem 1.2rem; margin: .64rem 0 .3rem; }
.legend-line { display: inline-block; vertical-align: middle; width: 1.4rem; margin-right: .3rem; border-top: .16rem solid var(--live); }
.legend-line.dark { border-top: .16rem dashed #a4aebb; }
.legend-mark { color: var(--gold); }
.readout {
  min-height: 2.7rem;
  margin: .55rem 0;
  color: var(--gold);
  font-weight: 580;
}
.phase { margin: .65rem 0 .25rem; color: var(--live); font-weight: bold; }
.result {
  border-left: 3px solid var(--live);
  padding: .2rem 0 .2rem .85rem;
  margin-top: .85rem;
}
.result p, .notes { color: var(--muted); }
.map-pin {
  position: absolute;
  z-index: 2;
  transform: translate(-50%, -50%);
  min-width: 44px;
  width: max-content;
  max-width: var(--label-width, 26%);
  display: grid;
  place-items: center;
  background: none;
  border: 1px solid transparent;
  color: var(--text);
  padding: .25rem;
  text-align: center;
  line-height: 1.12;
  font-size: clamp(.7rem, 2.18vw, .93rem);
  font-weight: 740;
  touch-action: manipulation;
}
.map-pin:disabled { opacity: 1; }
button.map-pin:hover:not(:disabled) { background: #0f233b85; border-color: var(--focus); }
.map-pin > strong, .map-pin > small {
  display: block;
  background: #0b1925;
  border-radius: .29rem;
  padding: .16em .33em;
  color: #edf8fb;
  max-width: 100%;
}
.map-pin > small { color: var(--muted); font-size: .88em; }
.map-pin.live > small { color: var(--live); }
.map-pin.fault > small { color: #ffc7ad; }
.map-pin.landmark { padding-top: clamp(1.25rem, 3vw, 2.05rem); }
.map-pin.source { touch-action: none; cursor: grab; max-width: 29%; }
.plug {
  display: grid;
  place-items: center;
  width: clamp(34px, 6vw, 54px);
  height: clamp(34px, 6vw, 54px);
  border: 2px solid var(--plug-color, var(--live));
  border-radius: 50%;
  background: radial-gradient(circle at 38% 29%, #405d73, #112735 72%);
  color: var(--plug-color, var(--live));
  box-shadow: 0 0 0 4px #0f2239ab, 0 0 18px #87e9df4d;
  font-size: clamp(.7rem, 2vw, .95rem);
}
.source[aria-pressed=true] .plug { background: var(--plug-color); color: #102431; }
.map-pin.drop-target { border-color: #d9f7ea85; }
.map-pin.drop-hover { border-color: var(--focus); background: #264a5fba; }
.handle {
  --lever: #adbfcc;
  display: grid;
  place-items: center;
  gap: .11rem;
  width: 46px;
  min-height: 49px;
  padding: 3px 2px;
  border-radius: 9px;
  border-color: #8ea3b3;
  background: linear-gradient(135deg,#385466,#122639 72%);
  box-shadow: 1px 4px 10px #061821a9;
  touch-action: none;
  color: #eff6f9;
}
.handle:hover:not(:disabled) { background: #2c5261; }
.handle.is-live { --lever: var(--live); border-color: var(--live); }
.handle.is-trip { --lever: #ffc3a0; border-color: #ffa282; }
.handle-type { text-transform: uppercase; letter-spacing: .065em; font-size: .62rem; }
.handle-track {
  display: block;
  width: 28px;
  height: 13px;
  position: relative;
  border-radius: 9px;
  background: #0b1b2a;
  border: 1px solid #6d879a;
}
.handle-track::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 1px;
  width: 8px;
  height: 8px;
  background: var(--lever);
  border-radius: 50%;
  transform: translateX(var(--travel, 0px));
  transition: transform .12s ease;
}
.handle[aria-pressed=true] .handle-track { --travel: 15px; }
.handle[data-sliding] .handle-track { --travel: var(--slide); }
.handle[data-sliding] .handle-track::after { transition: none; }
.handle-state { font-size: .61rem; font-weight: 760; line-height: 1; }
.action-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.action-bar .primary, .console .primary { background: #92e8c8; border-color: #b6f9e2; color: #102c31; }
.action-bar .primary:hover:not(:disabled), .console .primary:hover:not(:disabled) { background: #b6f9e2; color: #102c31; }
.console { padding: clamp(.6rem, 2.25vw, 1.1rem); background: linear-gradient(150deg,#203a48,#142333 72%); }
.console-art {
  display: block;
  width: 100%;
  aspect-ratio: 2.4;
  border: 1px solid #526c7b;
  border-radius: 10px;
  background: #0b2534;
}
.demand-strip {
  list-style: none;
  padding: 0;
  margin: .85rem 0;
  display: grid;
  grid-template-columns: repeat(6,minmax(0,1fr));
  gap: 4px;
  font-variant-numeric: tabular-nums;
}
.demand-strip li { text-align: center; font-size: clamp(.67rem, 2.2vw, .88rem); padding: .25rem 0; color: var(--muted); border-bottom: 2px solid #527587; }
.demand-strip li[aria-current=step] { background: #473a29; color: var(--gold); border-color: var(--gold); }
.demand-strip li[data-past] { opacity: .7; }
.demand-strip b { display: block; color: var(--live); }
.demand-strip .deficit b { color: #ffcfaa; }
.console-controls { display: flex; align-items: end; flex-wrap: wrap; gap: .4rem .85rem; }
.control-track { flex: 1 1 17rem; min-width: 0; }
.control-track label { display: block; font-weight: 730; margin: .15rem 0 .2rem; }
.control-track input {
  display: block;
  margin: 0;
  width: 100%;
  min-height: 44px;
  background: transparent;
  cursor: ew-resize;
  appearance: none;
  touch-action: pan-y;
}
.control-track input::-webkit-slider-runnable-track {
  height: 11px;
  background: linear-gradient(90deg,#3487a2,#456371 50%,#5bbb96);
  border: 1px solid #8cb4be;
  border-radius: 14px;
}
.control-track input::-moz-range-track {
  height: 10px;
  background: linear-gradient(90deg,#3487a2,#456371 50%,#5bbb96);
  border: 1px solid #8cb4be;
  border-radius: 14px;
}
.control-track input::-webkit-slider-thumb {
  appearance: none; width: 30px; height: 34px; margin-top: -12px;
  border-radius: 6px; border: 2px solid #ddede9;
  background: repeating-linear-gradient(90deg,#dfeae9 0 2px,#486373 2px 5px);
  box-shadow: 0 3px 7px #050d14b9;
}
.control-track input::-moz-range-thumb {
  width: 28px; height: 32px; border-radius: 6px; border: 2px solid #ddede9;
  background: repeating-linear-gradient(90deg,#dfeae9 0 2px,#486373 2px 5px);
}
.scale { display: flex; justify-content: space-between; gap: .25rem; font-size: .82rem; color: var(--muted); }
.output-line { font-variant-numeric: tabular-nums; color: var(--gold); font-weight: 650; margin-top: .35rem; }
.steering { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: .55rem; }
.steering button { min-width: 44px; padding: .2rem .55rem; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  padding: 0; border: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
dialog { color: var(--text); background: #162d40; border: 1px solid #6c8f9f; border-radius: 13px; width: min(calc(100% - 1.5rem), 32rem); padding: 1.4rem; }
dialog::backdrop { background: #06121fce; }
dialog form { display: flex; flex-wrap: wrap; gap: .52rem; margin-top: 1rem; }
@media (max-width: 570px) {
  .game-page { width: calc(100% - 24px); }
  .terms > div { grid-template-columns: 1fr; gap: .11rem; }
  .world { aspect-ratio: var(--phone-ratio, 5 / 6); }
  .world.route-world { aspect-ratio: 9 / 7; }
  .world.crew-world { aspect-ratio: 1; }
  .console-art { aspect-ratio: 1.9; }
  .handle { width: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.utility-win {
  max-height: calc(100vh - 2rem);
  padding: clamp(1.1rem, 4vw, 2rem);
  text-align: center;
  border-color: #b99c62;
  box-shadow: 0 20px 96px #030c18bd, 0 0 34px #eac77525;
  background: radial-gradient(ellipse at 50% 0, #3d4952, #1b3447 45%, #14293e 82%);
}
.utility-win[open] { animation: win-enter .24s ease-out both; }
.utility-win h2 { position: relative; color: #ffe1a0; font-size: clamp(2rem, 7vw, 3.1rem); }
.utility-win p { position: relative; margin: .7rem 0; }
.utility-win .win-course { color: var(--muted); font-size: .94rem; }
.utility-win form { position: relative; justify-content: center; }
.utility-win .win-primary { color: #172c35; background: #ffe0a1; border-color: #ffedc8; }
.utility-win .win-primary:hover { color: #142a32; background: #ffedc8; }
.win-celebration { position: relative; width: 0; height: 65px; margin: 0 auto .2rem; }
.win-celebration span {
  position: absolute;
  left: 0;
  top: 1px;
  transform: translateX(-50%);
  font-size: 2.6rem;
  line-height: 1.4;
  filter: drop-shadow(0 0 13px #ffe0a67c);
}
.win-celebration i {
  position: absolute;
  left: 0;
  top: 30px;
  width: 5px;
  height: 10px;
  border-radius: 2px;
  background: var(--chip);
  opacity: 0;
}
.utility-win[open] .win-celebration i { animation: win-confetti .76s var(--start) ease-out both; }
.builder-actions { margin: 0 0 .7rem; }
@keyframes win-enter { from { opacity: .5; transform: scale(.94); } to { opacity: 1; transform: scale(1); } }
@keyframes win-confetti {
  from { opacity: 0; transform: translate(0, 0); }
  18% { opacity: 1; }
  to { opacity: 0; transform: translate(var(--x), var(--y)) rotate(var(--spin)); }
}
