:root {
  color-scheme: dark;
  --screen: rgb(12, 16, 22);
  --panel: rgb(20, 27, 36);
  --hud: rgb(18, 24, 32);
  --plot: rgb(8, 11, 16);
  --stroke: rgb(80, 92, 110);
  --stroke-hud: rgb(82, 96, 118);
  --plot-stroke: rgb(72, 84, 102);
  --grid: rgb(30, 38, 50);
  --axis: rgb(90, 104, 124);
  --text: rgb(230, 235, 242);
  --muted: rgb(170, 184, 204);
  --metric: rgb(222, 230, 238);
  --info: rgb(150, 205, 245);
  --hint: rgb(245, 210, 110);
  --footer: rgb(220, 160, 160);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--screen);
  color: var(--text);
  font-family: Menlo, Consolas, Monaco, "Courier New", monospace;
}

button,
select,
input,
a {
  font: inherit;
}

button {
  min-height: 24px;
  border: 1px solid rgb(104, 130, 156);
  border-radius: 4px;
  background: rgb(34, 48, 62);
  color: rgb(220, 234, 246);
  padding: 0 9px;
  cursor: pointer;
}

button.active {
  border-color: rgb(248, 84, 100);
  background: rgb(96, 22, 32);
  color: rgb(255, 220, 224);
}

@media (hover: hover) and (pointer: fine) {
  body:not(.mobile-view) button:hover {
    border-color: rgb(248, 84, 100);
    background: rgb(96, 22, 32);
    color: rgb(255, 220, 224);
  }
}

.music-button.active {
  border-color: rgb(104, 130, 156);
  background: rgb(34, 48, 62);
  color: rgb(220, 234, 246);
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid rgb(96, 174, 224);
  outline-offset: 2px;
}

h1,
p {
  margin: 0;
}

.trainer-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  min-width: 720px;
  min-height: 560px;
  overflow: hidden;
  background: var(--screen);
}

.selector-mode .top-bar,
.selector-mode .game-layout,
.selector-mode .hud-panel,
.selector-mode .touch-controls,
.selector-mode .mobile-speed-controls {
  display: none;
}

.trainer-shell.sandbox-setup-mode .top-bar,
.trainer-shell.sandbox-setup-mode .game-layout,
.trainer-shell.sandbox-setup-mode .hud-panel,
.trainer-shell.sandbox-setup-mode .touch-controls,
.trainer-shell.sandbox-setup-mode .mobile-speed-controls {
  display: none !important;
}

.level-selector {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: 124px minmax(0, 1fr) 76px;
  background: var(--screen);
  padding: 0 42px;
  --selector-accent-bg: rgb(28, 48, 66);
  --selector-accent-border: rgb(96, 174, 224);
  --selector-accent-text: rgb(238, 244, 250);
  --selector-control-bg: rgb(34, 60, 76);
}

.trainer-shell:not(.selector-mode) .level-selector {
  display: none;
}

.selector-operator-mode .level-selector,
.level-selector.operator-mode {
  --selector-accent-bg: rgb(74, 56, 24);
  --selector-accent-border: rgb(245, 210, 110);
  --selector-accent-text: rgb(255, 236, 174);
  --selector-control-bg: rgb(58, 45, 24);
}

.selector-pilot-mode .level-selector,
.level-selector.pilot-mode {
  --selector-inactive-border: rgb(48, 60, 76);
  --selector-inactive-bg: var(--panel);
}

.selector-operator-mode .level-selector,
.level-selector.operator-mode {
  --selector-inactive-border: rgb(48, 60, 76);
  --selector-inactive-bg: var(--panel);
}

.launcher-header {
  position: relative;
  display: grid;
  grid-template-columns: max-content max-content minmax(0, 1fr);
  grid-template-rows: auto auto;
  align-items: start;
  column-gap: 12px;
  row-gap: 6px;
  padding-top: 32px;
}

.launcher-header h1 {
  grid-column: 1;
  grid-row: 1;
  font-size: 30px;
  line-height: 36px;
  text-transform: none;
}

.launcher-header p {
  grid-column: 1;
  grid-row: 2;
  margin-top: 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 22px;
}

.launcher-subtitle {
  display: contents;
}

.launcher-subtitle > span:last-child {
  grid-column: 1 / 4;
  grid-row: 2;
  justify-self: start;
  min-width: 0;
  text-align: left;
}

.preview-badge {
  grid-column: 2;
  grid-row: 1;
  align-self: start;
  justify-self: start;
  margin-top: 4px;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border: 1px solid rgb(96, 174, 224);
  border-radius: 999px;
  background: rgb(28, 48, 66);
  color: rgb(196, 226, 246);
  font-size: 11px;
  line-height: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.launcher-music {
  width: 144px;
  min-height: 30px;
  background: var(--selector-control-bg);
  border-color: var(--selector-accent-border);
  color: var(--selector-accent-text);
}

.launcher-view {
  width: 156px;
  min-height: 30px;
  background: var(--selector-control-bg);
  border-color: var(--selector-accent-border);
  color: var(--selector-accent-text);
}

.launcher-mode {
  width: 132px;
  min-height: 30px;
  background: var(--selector-control-bg);
  border-color: var(--selector-accent-border);
  color: var(--selector-accent-text);
}

.launcher-frame {
  width: 172px;
  min-height: 30px;
  background: var(--selector-control-bg);
  border-color: var(--selector-accent-border);
  color: var(--selector-accent-text);
}

.launcher-frame-mobile {
  display: none;
}

.launcher-actions {
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
  display: flex;
  gap: 10px;
}

.launcher-repo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 170px;
  height: 30px;
  min-height: 30px;
  padding: 0 10px;
  background: var(--selector-control-bg);
  border: 1px solid var(--selector-accent-border);
  border-radius: 4px;
  color: var(--selector-accent-text);
  font-size: 0.88rem;
  line-height: 1;
  text-align: center;
  text-decoration: none;
}

.launcher-repo:hover,
.launcher-repo:focus-visible {
  border-color: var(--selector-accent-border);
  color: var(--selector-accent-text);
}

.launcher-music:hover,
.launcher-view:hover,
.launcher-mode:hover,
.launcher-mode.active,
.launcher-frame:hover,
.launcher-frame.active {
  background: var(--selector-control-bg);
  border-color: var(--selector-accent-border);
  color: var(--selector-accent-text);
}

.launcher-body {
  min-height: 0;
  display: grid;
  grid-template-columns: 424px minmax(420px, 1fr);
  gap: 24px;
}

.launcher-list,
.launcher-preview {
  border: 1px solid rgb(70, 82, 100);
  border-radius: 8px;
  background: var(--hud);
}

.launcher-list {
  padding: 12px;
  display: grid;
  align-content: start;
  gap: 14px;
}

.launcher-option {
  width: 100%;
  min-height: 64px;
  display: grid;
  align-content: center;
  gap: 5px;
  padding: 10px 18px;
  text-align: left;
  border-radius: 8px;
  border-color: var(--selector-inactive-border, rgb(48, 60, 76));
  background: var(--selector-inactive-bg, var(--panel));
}

.launcher-option[hidden] {
  display: none;
}

.launcher-option.active,
.launcher-option:focus-visible {
  background: var(--selector-accent-bg);
  border-color: var(--selector-accent-border);
  color: var(--selector-accent-text);
}

.launcher-option span {
  font-size: 18px;
  line-height: 22px;
  color: rgb(238, 244, 250);
}

.launcher-option .level-beta-badge {
  display: inline-flex;
  align-items: center;
  margin-left: 6px;
  padding: 2px 6px;
  border: 1px solid rgba(87, 202, 255, 0.65);
  border-radius: 999px;
  color: rgb(87, 202, 255);
  font-size: 10px;
  line-height: 1;
  text-transform: uppercase;
  vertical-align: middle;
}

.launcher-option small {
  color: rgb(162, 178, 198);
  font-size: 14px;
  line-height: 17px;
}

.launcher-preview {
  min-width: 0;
  overflow: auto;
  padding: 20px;
}

.launcher-preview-head {
  display: block;
}

.launcher-play-level {
  display: none;
}

.launcher-preview h2 {
  margin: 0 0 14px;
  font-size: 18px;
  line-height: 24px;
  color: rgb(238, 244, 250);
}

.launcher-budget {
  margin: 0 0 22px;
  color: rgb(162, 178, 198);
  font-size: 14px;
  line-height: 18px;
}

.launcher-preview .launcher-scope {
  margin: -8px 0 18px;
  padding: 9px 11px;
  border-left: 3px solid var(--selector-accent-border);
  background: rgba(96, 174, 224, 0.08);
  color: rgb(196, 210, 226);
  font-size: 12px;
  line-height: 17px;
}

.launcher-preview section {
  margin-top: 10px;
}

.launcher-preview h3 {
  margin: 0 0 8px;
  font-size: 14px;
  line-height: 18px;
  color: rgb(238, 244, 250);
}

.launcher-preview p,
.launcher-preview li {
  color: rgb(182, 194, 210);
  font-size: 14px;
  line-height: 18px;
}

.launcher-preview ul {
  margin: 0;
  padding-left: 18px;
}

.leaderboard-panel {
  margin-top: 18px;
  border-top: 1px solid rgb(70, 82, 100);
  padding-top: 14px;
}

.leaderboard-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.leaderboard-head h3 {
  margin: 0;
}

.leaderboard-head button {
  min-height: 28px;
  color: rgb(220, 234, 246);
}

.leaderboard-list {
  display: grid;
  gap: 6px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) max-content 58px;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  border: 1px solid rgb(48, 60, 76);
  border-radius: 6px;
  background: rgb(15, 24, 34);
  color: rgb(226, 235, 244);
  padding: 6px 10px;
}

.leaderboard-rank {
  color: rgb(96, 174, 224);
}

.leaderboard-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-score {
  color: rgb(245, 210, 110);
  text-align: right;
}

.leaderboard-rounds {
  color: rgb(170, 184, 204);
  text-align: right;
}

.leaderboard-empty,
.leaderboard-meta {
  color: rgb(162, 178, 198);
  font-size: 13px;
  line-height: 17px;
}

.leaderboard-empty {
  padding: 4px 0;
}

.leaderboard-meta {
  margin: 8px 0 0;
}

.launcher-footer {
  align-self: center;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  color: var(--footer);
  font-size: 14px;
  line-height: 18px;
}

.launcher-footer-controls {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  min-width: 0;
}

.top-bar {
  position: absolute;
  left: 36px;
  top: 18px;
  right: 36px;
  min-height: 84px;
  border: 2px solid var(--stroke-hud);
  border-radius: 10px;
  background: var(--hud);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  padding: 9px 16px;
}

.primer-mode .top-bar {
  height: 96px;
  grid-template-columns: minmax(0, 1fr) 300px;
  padding: 10px 16px;
}

.top-left {
  min-width: 0;
}

h1 {
  color: var(--text);
  font-size: 26px;
  line-height: 30px;
  font-weight: 700;
  text-transform: uppercase;
}

.top-metrics {
  display: flex;
  flex-wrap: wrap;
  column-gap: 22px;
  row-gap: 3px;
  margin-top: 4px;
  color: var(--metric);
  font-size: 14px;
  line-height: 17px;
}

.top-metrics span {
  white-space: nowrap;
}

.top-metrics span:empty {
  display: none;
}

#topTimingMetric.timing-warning {
  color: var(--hint);
}

.objective-checklist {
  min-width: 0;
  display: grid;
  align-content: center;
  gap: 3px;
  color: var(--metric);
  font-size: 14px;
  line-height: 16px;
}

.objective-heading {
  color: var(--muted);
  font-size: 14px;
  text-transform: uppercase;
}

#objectiveTitle {
  display: block;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#objectiveTitle {
  color: rgb(150, 235, 170);
}

#objectiveText {
  display: block;
  min-width: 0;
  color: var(--info);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#objectiveText:empty {
  display: none;
}

.game-layout {
  position: absolute;
  left: 36px;
  right: 36px;
  top: 124px;
  bottom: 112px;
}

.primer-mode .game-layout {
  top: 136px;
}

.plot-stack {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 36px;
}

.plot-panel {
  position: relative;
  min-width: 200px;
  min-height: 250px;
  border: 1px solid var(--stroke);
  border-radius: 10px;
  background: var(--panel);
  overflow: hidden;
}

.plot-title {
  position: absolute;
  left: 14px;
  right: 14px;
  top: 10px;
  height: 24px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.plot-title span {
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
}

.plot-title small {
  color: var(--muted);
  font-size: 14px;
}

canvas {
  position: absolute;
  left: 24px;
  right: 24px;
  top: 64px;
  bottom: 20px;
  width: calc(100% - 48px);
  height: calc(100% - 84px);
  display: block;
  border: 1px solid var(--plot-stroke);
  background: var(--plot);
}

.hud-panel {
  position: absolute;
  left: 36px;
  right: 36px;
  bottom: 26px;
  height: 86px;
  border: 1px solid var(--stroke-hud);
  border-radius: 10px;
  background: var(--hud);
  color: rgb(235, 240, 245);
  padding: 10px 16px;
  font-size: 14px;
  line-height: 17px;
}

.hud-line {
  position: absolute;
  left: 16px;
  top: 12px;
  right: 620px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 18px;
  line-height: 22px;
}

.hud-top-controls {
  position: absolute;
  right: 12px;
  top: 10px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-actions {
  display: flex;
  gap: 8px;
}

.music-button {
  min-width: 118px;
}

.hint-line {
  position: absolute;
  left: 16px;
  top: 38px;
  right: 16px;
  color: var(--hint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.command-line {
  position: absolute;
  left: 16px;
  bottom: 8px;
  max-width: calc(100% - 650px);
  color: rgb(195, 205, 220);
  line-height: 1.25;
  white-space: pre-wrap;
  overflow: visible;
}

.footer-line {
  position: absolute;
  right: 16px;
  bottom: 8px;
  color: var(--footer);
  white-space: pre;
}

.hud-line,
.hint-line,
.command-line,
.footer-line {
  pointer-events: none;
}

.primer-mode .hud-line {
  right: 700px;
}

.mode-operator .hud-line {
  right: 360px;
}

.primer-mode .hint-line {
  right: 16px;
}

.primer-mode .command-line {
  display: none;
}

.primer-mode .footer-line {
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mode-operator-script .top-bar {
  left: 52px;
  top: 40px;
  right: 52px;
  min-height: 44px;
  border: 0;
  border-radius: 0;
  background: transparent;
  display: block;
  padding: 0;
}

.mode-operator-script .top-left {
  display: flex;
  align-items: baseline;
  gap: 26px;
}

.mode-operator-script #levelLabel {
  margin: 0;
  font-size: 28px;
  line-height: 34px;
  text-transform: none;
  letter-spacing: 0;
}

.mode-operator-script .top-metrics,
.mode-operator-script .objective-checklist {
  display: none;
}

.mode-operator-script .game-layout {
  left: 40px;
  right: 40px;
  top: 106px;
  bottom: 104px;
}

.mode-operator-script .plot-stack {
  bottom: 202px;
  gap: 30px;
}

.mode-operator-script .plot-panel {
  border-radius: 8px;
}

.mode-operator-script canvas {
  top: 64px;
  bottom: 20px;
}

.mode-operator-script .operator-panel {
  left: 0;
  bottom: 0;
  width: calc(100% - 340px);
  max-height: 178px;
  border-width: 2px;
  border-radius: 10px;
  padding: 12px;
}

.mode-operator-script .operator-table {
  max-height: 104px;
}

.mode-operator-script .hud-panel {
  left: auto;
  right: 40px;
  bottom: 104px;
  width: 300px;
  height: 88px;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
}

.mode-operator-script .hud-line,
.mode-operator-script .hint-line,
.mode-operator-script .command-line,
.mode-operator-script .footer-line,
.mode-operator-script #levelSelectButton,
.mode-operator-script .music-button,
.mode-operator-script #viewButton {
  display: none;
}

.mode-operator-script .hud-top-controls {
  position: static;
  display: block;
}

.mode-operator-script .hud-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  justify-content: flex-end;
  gap: 12px;
}

.mode-operator-script .equation-sheet-button {
  display: inline-flex;
  grid-column: 1 / -1;
  width: 100%;
  min-height: 32px;
  align-items: center;
  justify-content: center;
  border-color: rgb(104, 130, 156);
  background: rgb(34, 48, 62);
  color: rgb(220, 234, 246);
}

.mode-operator-script .equation-sheet-button:hover,
.mode-operator-script .equation-sheet-button:focus-visible,
.mode-operator-script .equation-sheet-button[aria-pressed="true"] {
  border-color: rgb(245, 210, 110);
  background: rgb(58, 45, 24);
  color: rgb(255, 236, 174);
}

.mode-operator-script #resetButton {
  order: 1;
}

.mode-operator-script #pauseButton {
  order: 2;
  border-color: rgb(95, 185, 116);
  background: rgb(35, 90, 50);
}

.mode-operator-script #pauseButton:hover,
.mode-operator-script #pauseButton:focus-visible {
  border-color: rgb(115, 215, 138);
  background: rgb(44, 112, 62);
  color: rgb(238, 244, 250);
}

.mode-operator-script #resetButton,
.mode-operator-script #pauseButton {
  width: 100%;
  min-height: 32px;
  font-size: 14px;
}

.equation-sheet {
  position: absolute;
  left: 22px;
  right: 22px;
  top: 28px;
  bottom: 202px;
  z-index: 8;
  border: 2px solid rgb(245, 210, 110);
  border-radius: 10px;
  background: rgba(15, 24, 34, 0.98);
  padding: 18px 22px;
  color: var(--text);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.35);
}

.equation-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.equation-sheet h2 {
  margin: 0;
  font-size: 22px;
  line-height: 28px;
  text-transform: none;
}

.equation-sheet h3 {
  margin: 0 0 12px;
  font-size: 15px;
  line-height: 19px;
  color: rgb(238, 244, 250);
}

.equation-sheet-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 28px;
  margin-top: 20px;
}

.equation {
  margin: 10px 0;
  color: rgb(238, 244, 250);
  font-size: 22px;
  line-height: 30px;
}

.equation-note {
  margin: 16px 0 0;
  color: rgb(170, 184, 204);
  font-size: 13px;
  line-height: 18px;
}

.ric-frame-diagram {
  position: relative;
  height: 210px;
  border: 1px solid rgb(70, 82, 100);
  border-radius: 8px;
  background:
    linear-gradient(90deg, transparent 49.5%, rgba(150, 170, 195, 0.38) 49.5%, rgba(150, 170, 195, 0.38) 50.5%, transparent 50.5%),
    linear-gradient(0deg, transparent 49.5%, rgba(150, 170, 195, 0.38) 49.5%, rgba(150, 170, 195, 0.38) 50.5%, transparent 50.5%),
    rgb(8, 11, 16);
}

.ric-frame-diagram::before,
.ric-frame-diagram::after {
  content: "";
  position: absolute;
  background: rgb(245, 210, 110);
}

.ric-frame-diagram::before {
  left: 50%;
  top: 50%;
  width: 94px;
  height: 2px;
  transform: translateY(-50%);
}

.ric-frame-diagram::after {
  left: 50%;
  bottom: 50%;
  width: 2px;
  height: 74px;
  transform: translateX(-50%);
}

.ric-target {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 12px;
  height: 12px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgb(245, 210, 110);
  color: transparent;
}

.ric-axis {
  position: absolute;
  color: rgb(170, 184, 204);
  font-size: 14px;
  line-height: 18px;
}

.ric-r {
  left: calc(50% + 10px);
  top: 22px;
}

.ric-i {
  right: 34px;
  top: calc(50% + 8px);
}

.ric-c {
  left: 28px;
  top: calc(50% + 8px);
  color: rgb(150, 235, 170);
}

.equation-sheet-button {
  display: none;
}

.hidden-metrics {
  display: none;
}

.sandbox-setup-screen {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 18px;
  padding: 30px 54px 24px;
  overflow: hidden;
  background: var(--screen);
  color: var(--text);
}

.sandbox-setup-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
}

.sandbox-setup-header > div {
  flex: 0 0 auto;
  display: flex;
  align-items: baseline;
  gap: 26px;
  min-width: 0;
}

.sandbox-setup-header h1 {
  flex: 0 0 auto;
  font-size: 30px;
  line-height: 36px;
}

.sandbox-setup-header > div p {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 22px;
  line-height: 28px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sandbox-setup-header > p {
  flex: 1 1 auto;
  max-width: 560px;
  color: var(--muted);
  font-size: 13px;
  line-height: 18px;
  text-align: right;
}

.sandbox-setup-form {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 14px;
}

.sandbox-setup-columns {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
}

.sandbox-setup-group {
  min-width: 0;
  min-height: 0;
  margin: 0;
  border: 1px solid var(--stroke);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px 18px 18px;
  display: grid;
  grid-template-rows: auto repeat(6, minmax(36px, 1fr));
  gap: 5px;
}

.sandbox-setup-group legend {
  padding: 0 6px;
  color: var(--text);
  font-size: 16px;
}

.sandbox-group-title-compact {
  display: none;
}

.sandbox-setup-steps {
  display: none;
}

.sandbox-setup-group > p {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 11px;
  line-height: 15px;
}

.sandbox-setup-group label {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(96px, 142px);
  align-items: center;
  gap: 12px;
  color: rgb(190, 202, 218);
  font-size: 12px;
}

.sandbox-setup-group label > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sandbox-setup-group small {
  color: var(--muted);
  font-size: 10px;
}

.sandbox-setup-group input {
  width: 100%;
  min-width: 0;
  height: 32px;
  border: 1px solid rgb(74, 88, 106);
  border-radius: 5px;
  background: var(--screen);
  color: var(--text);
  padding: 0 9px;
}

.sandbox-setup-group input:focus {
  border-color: rgb(238, 184, 92);
  background: rgb(42, 50, 62);
}

.sandbox-setup-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.sandbox-setup-footer > p {
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 15px;
}

.sandbox-setup-footer > p[data-error="true"] {
  color: rgb(245, 126, 126);
}

.sandbox-setup-footer > div {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
}

.sandbox-setup-footer button {
  min-width: 120px;
  min-height: 36px;
}

.sandbox-setup-back,
.sandbox-setup-next {
  display: none;
}

#sandboxSetupContinue {
  border-color: rgb(238, 184, 92);
  background: rgb(70, 52, 24);
  color: rgb(255, 236, 174);
}

.operator-panel {
  position: absolute;
  left: 18px;
  bottom: 18px;
  z-index: 4;
  width: min(660px, calc(100% - 36px));
  max-height: 190px;
  border: 2px solid rgb(245, 210, 110);
  border-radius: 10px;
  background: rgb(15, 24, 34);
  padding: 12px;
  display: grid;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
}

.operator-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.operator-panel-head div {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

.operator-panel-head span,
#operatorError {
  color: var(--muted);
}

#operatorAddBurn {
  width: 32px;
  min-height: 28px;
  padding: 0;
}

.operator-table {
  display: grid;
  gap: 6px;
  max-height: 100px;
  overflow: auto;
  padding-right: 4px;
}

.operator-row {
  display: grid;
  grid-template-columns: 42px repeat(4, minmax(70px, 1fr)) 32px;
  gap: 6px;
  align-items: end;
}

.operator-row span {
  color: var(--muted);
  font-size: 12px;
}

.operator-header {
  align-items: center;
}

.operator-header span {
  font-weight: 700;
}

.operator-row input {
  min-width: 0;
  height: 28px;
  border: 1px solid rgb(80, 92, 110);
  border-radius: 4px;
  background: rgb(8, 11, 16);
  color: var(--text);
  padding: 0 7px;
}

.operator-row button {
  min-height: 28px;
  padding: 0;
}

#operatorError {
  min-height: 16px;
  margin: 0;
  font-size: 12px;
  line-height: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

select,
input[type="range"] {
  width: 100%;
}

select {
  min-height: 30px;
  border: 1px solid rgb(104, 130, 156);
  border-radius: 4px;
  background: rgb(8, 11, 16);
  color: var(--text);
  padding: 0 8px;
}

.button-row {
  display: flex;
  gap: 8px;
}

.debrief-panel {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 9;
  width: min(620px, calc(100vw - 72px));
  transform: translate(-50%, -50%);
  border: 3px solid rgb(100, 226, 142);
  border-radius: 10px;
  background: rgb(18, 54, 36);
  color: rgb(190, 255, 205);
  padding: 24px;
  display: grid;
  gap: 12px;
}

.debrief-panel a {
  color: rgb(150, 205, 245);
}

.leaderboard-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  grid-template-areas:
    "username email submit"
    "note note note"
    "status status status";
  gap: 10px;
  align-items: end;
}

.leaderboard-form label:first-of-type {
  grid-area: username;
}

.leaderboard-form label:nth-of-type(2) {
  grid-area: email;
}

.leaderboard-form label {
  display: grid;
  gap: 4px;
  color: rgb(220, 255, 230);
  font-size: 0.72rem;
  text-transform: uppercase;
}

.leaderboard-form input {
  width: 100%;
  min-width: 0;
  border: 2px solid rgb(100, 226, 142);
  border-radius: 4px;
  background: rgb(8, 20, 14);
  color: rgb(235, 255, 240);
  font: inherit;
  padding: 7px 8px;
}

.leaderboard-form button {
  grid-area: submit;
  min-height: 38px;
  align-self: end;
  border-color: rgb(100, 226, 142);
  background: rgb(100, 226, 142);
  color: rgb(4, 21, 9);
}

.leaderboard-form p {
  grid-area: status;
  margin: 0;
  color: rgb(220, 255, 230);
  font-size: 0.82rem;
}

.leaderboard-form .leaderboard-form-note {
  grid-area: note;
  margin: 0;
  color: rgb(160, 180, 205);
  font-size: 0.72rem;
  line-height: 1.3;
  max-width: 34rem;
}

.hidden {
  display: none;
}

.touch-controls {
  display: none;
}

.mobile-speed-controls {
  display: none;
}

@media (min-width: 901px) and (max-width: 1120px) {
  .launcher-header {
    grid-template-columns: max-content max-content minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-items: center;
    column-gap: 8px;
  }

  .launcher-header h1 {
    font-size: clamp(22px, calc(4vw - 14px), 30px);
    line-height: 1.2;
  }

  .preview-badge {
    align-self: center;
    margin-top: 0;
    padding-inline: 6px;
    font-size: 10px;
  }

  .launcher-subtitle > span:last-child {
    grid-column: 1 / 4;
  }

  .launcher-actions {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
    gap: 6px;
  }

  .launcher-music {
    width: clamp(105px, 12.5vw, 138px);
  }

  .launcher-view {
    width: clamp(120px, 13.6vw, 150px);
  }

  .launcher-repo {
    width: clamp(135px, 14.8vw, 164px);
  }

  .launcher-music,
  .launcher-view,
  .launcher-repo {
    white-space: nowrap;
  }
}

@media (max-width: 900px), (max-height: 620px) {
  body {
    overflow: auto;
  }

  .trainer-shell {
    min-width: 0;
    min-height: 100vh;
    height: auto;
    overflow: visible;
    padding: 10px;
    display: grid;
    gap: 12px;
  }

  .leaderboard-form {
    grid-template-columns: 1fr;
    grid-template-areas:
      "username"
      "email"
      "note"
      "submit"
      "status";
  }

  .top-bar,
  .game-layout,
  .hud-panel,
  .level-selector {
    position: relative;
    inset: auto;
    left: auto;
    right: auto;
    top: auto;
    bottom: auto;
    width: auto;
  }

  .level-selector {
    min-height: 100vh;
    padding: 10px;
    grid-template-rows: auto auto auto;
    gap: 12px;
  }

  .launcher-header {
    padding-top: 0;
  }

  .launcher-header h1 {
    font-size: 26px;
    line-height: 32px;
  }

  .launcher-music,
  .launcher-view,
  .launcher-mode,
  .launcher-frame,
  .launcher-repo {
    position: static;
    margin-top: 10px;
  }

  .launcher-body {
    grid-template-columns: 1fr;
  }

  .launcher-list {
    gap: 8px;
  }

  .launcher-preview {
    max-height: none;
  }

  .top-bar {
    height: auto;
    grid-template-columns: 1fr;
  }

  .game-layout {
    min-height: 700px;
  }

  .plot-stack {
    grid-template-columns: 1fr;
  }

  .hud-panel {
    height: 150px;
  }

  .hud-line {
    right: 130px;
  }

  .hud-top-controls {
    left: 16px;
    right: auto;
    top: 88px;
    max-width: calc(100% - 32px);
    flex-wrap: wrap;
  }

  .command-line {
    max-width: calc(100% - 32px);
    bottom: 34px;
  }

  .footer-line {
    left: 16px;
    right: auto;
    bottom: 12px;
  }

  .touch-controls {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    position: sticky;
    bottom: 10px;
    z-index: 5;
  }
}

body.mobile-view {
  overflow: hidden;
  touch-action: manipulation;
}

/* Reserve gestures across the display for gameplay, including panel margins. */
html:has(body.mobile-view .trainer-shell:not(.selector-mode):not(.sandbox-setup-mode)),
body.mobile-view:has(.trainer-shell:not(.selector-mode):not(.sandbox-setup-mode)) {
  touch-action: none;
}

body.mobile-view .trainer-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  gap: 8px;
  width: min(100vw, 520px);
  height: 100dvh;
  min-width: 0;
  min-height: 0;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
  overflow: hidden;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

body.mobile-view .trainer-shell:not(.selector-mode),
body.mobile-view .trainer-shell:not(.selector-mode) * {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

body.mobile-view button,
body.mobile-view canvas,
body.mobile-view .plot-panel,
body.mobile-view .touch-controls,
body.mobile-view .mobile-speed-controls,
body.mobile-view .hud-actions {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

body.mobile-view .touch-controls button,
body.mobile-view .mobile-speed-controls button,
body.mobile-view .hud-actions button {
  touch-action: none;
}

body.mobile-view input,
body.mobile-view select,
body.mobile-view textarea {
  -webkit-touch-callout: default;
  -webkit-user-select: text;
  user-select: text;
}

body.mobile-view .trainer-shell.selector-mode {
  display: block;
}

body.mobile-view .level-selector {
  position: relative;
  inset: auto;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 8px;
  min-height: 0;
  height: 100%;
  padding: 0;
  overflow: hidden;
}

body.mobile-view .launcher-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto auto auto auto auto;
  align-items: center;
  column-gap: 8px;
  row-gap: 3px;
  padding-top: 0;
}

body.mobile-view .launcher-header h1 {
  grid-column: 1 / -1;
  font-size: 22px;
  line-height: 25px;
}

body.mobile-view .launcher-header p {
  grid-column: 1 / -1;
  grid-row: 6;
  margin-top: 2px;
  font-size: 13px;
  line-height: 17px;
}

body.mobile-view .launcher-subtitle {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

body.mobile-view .launcher-actions {
  display: contents;
}

body.mobile-view .preview-badge {
  margin-top: 0;
  min-height: 18px;
  padding: 0 6px;
  font-size: 9px;
  line-height: 12px;
}

body.mobile-view .launcher-mode {
  display: none;
}

body.mobile-view .launcher-music {
  grid-column: 1;
  grid-row: 3;
}

body.mobile-view .launcher-view {
  grid-column: 1;
  grid-row: 4;
}

body.mobile-view .launcher-frame {
  grid-column: 1 / -1;
  grid-row: 2;
}

body.mobile-view .launcher-repo {
  grid-column: 1 / -1;
  grid-row: 5;
}

body.mobile-view .launcher-music,
body.mobile-view .launcher-view,
body.mobile-view .launcher-frame,
body.mobile-view .launcher-repo {
  position: relative;
  right: auto;
  top: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 32px;
  margin: 0;
  font-size: 12px;
}

body.mobile-view .launcher-body {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  min-height: 0;
  overflow: hidden;
}

body.mobile-view .launcher-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 8px;
  border-radius: 8px;
}

body.mobile-view .launcher-option {
  min-height: 48px;
  padding: 8px 10px;
}

body.mobile-view .launcher-option span {
  font-size: 15px;
  line-height: 19px;
}

body.mobile-view .launcher-preview {
  min-height: 0;
  max-height: none;
  padding: 12px;
  overflow: auto;
  border-radius: 8px;
}

body.mobile-view .launcher-preview-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
}

body.mobile-view .launcher-play-level {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transform: translateY(-4px);
  min-width: 92px;
  min-height: 32px;
  padding: 0 10px;
  border-color: rgb(94, 190, 245);
  background: rgb(34, 60, 76);
  color: rgb(238, 244, 250);
  font-size: 12px;
  line-height: 14px;
  white-space: nowrap;
}

body.mobile-view .launcher-preview h2 {
  margin-bottom: 8px;
  font-size: 17px;
  line-height: 21px;
}

body.mobile-view .launcher-budget {
  margin-bottom: 12px;
  font-size: 11px;
  line-height: 15px;
}

body.mobile-view .launcher-preview .launcher-scope {
  margin: -4px 0 10px;
  padding: 7px 8px;
  font-size: 11px;
  line-height: 15px;
}

body.mobile-view .launcher-preview p,
body.mobile-view .launcher-preview li {
  font-size: 12px;
  line-height: 16px;
}

body.mobile-view .launcher-preview section {
  margin-top: 9px;
}

body.mobile-view .launcher-preview h3 {
  margin-bottom: 5px;
  font-size: 12px;
  line-height: 15px;
}

body.mobile-view .launcher-footer {
  display: none;
}

body.mobile-view .top-bar {
  position: relative;
  inset: auto;
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  height: auto;
  min-height: 0;
  padding: 8px 10px;
  border: 2px solid var(--stroke-hud);
  border-radius: 10px;
  background: var(--hud);
}

body.mobile-view h1 {
  font-size: 20px;
  line-height: 23px;
}

body.mobile-view .top-metrics {
  gap: 8px;
  font-size: 11px;
  line-height: 14px;
}

body.mobile-view #topRangeMetric,
body.mobile-view #topSpeedMetric {
  display: none;
}

body.mobile-view .objective-checklist {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
  font-size: 12px;
  line-height: 15px;
}

body.mobile-view #objectiveText {
  white-space: normal;
}

body.mobile-view .trainer-shell.primer-mode .top-bar {
  grid-template-columns: minmax(0, 1fr);
  min-height: 0;
}

body.mobile-view .trainer-shell.primer-mode .objective-checklist {
  display: none;
}

body.mobile-view .game-layout {
  position: relative;
  inset: auto;
  min-height: 0;
  overflow: hidden;
}

body.mobile-view .plot-stack {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
}

body.mobile-view .plot-panel {
  min-width: 0;
  min-height: 0;
  border-radius: 8px;
}

body.mobile-view .plot-title {
  left: 10px;
  right: 10px;
  top: 7px;
  height: 20px;
}

body.mobile-view .plot-title span {
  font-size: 13px;
}

body.mobile-view .plot-title small {
  font-size: 10px;
}

body.mobile-view canvas {
  left: 12px;
  right: 12px;
  top: 34px;
  bottom: 10px;
  width: calc(100% - 24px);
  height: calc(100% - 44px);
}

body.mobile-view .hud-panel {
  position: relative;
  inset: auto;
  display: grid;
  gap: 6px;
  height: auto;
  min-height: 0;
  padding: 8px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 15px;
}

body.mobile-view .hud-line,
body.mobile-view .hint-line,
body.mobile-view .command-line,
body.mobile-view .footer-line,
body.mobile-view .hud-top-controls {
  position: static;
  max-width: none;
  width: auto;
  white-space: normal;
}

body.mobile-view .hud-line {
  font-size: 12px;
  line-height: 15px;
}

body.mobile-view .hud-top-controls {
  order: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

body.mobile-view .hud-actions {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  width: 100%;
}

body.mobile-view .hud-actions button,
body.mobile-view .music-button {
  min-width: 0;
  min-height: 34px;
  padding: 4px 5px;
  font-size: 11px;
}

body.mobile-view .music-button {
  width: 100%;
}

body.mobile-view .hint-line {
  color: var(--hint);
  font-size: 11px;
  line-height: 14px;
}

body.mobile-view .command-line,
body.mobile-view .footer-line {
  display: none;
}

body.mobile-view .sandbox-setup-screen {
  position: relative;
  inset: auto;
  min-height: 100%;
  padding: 12px;
  overflow: auto;
}

body.mobile-view .sandbox-setup-header {
  align-items: start;
  flex-direction: column;
  gap: 4px;
}

body.mobile-view .sandbox-setup-header h1 {
  font-size: 22px;
  line-height: 26px;
}

body.mobile-view .sandbox-setup-header > div p {
  font-size: 15px;
  line-height: 20px;
}

body.mobile-view .sandbox-setup-header > p {
  max-width: none;
  font-size: 11px;
  line-height: 15px;
  text-align: left;
}

body.mobile-view .sandbox-setup-form,
body.mobile-view .sandbox-setup-columns {
  min-height: max-content;
}

body.mobile-view .sandbox-setup-columns {
  grid-template-columns: 1fr;
  gap: 10px;
}

body.mobile-view .sandbox-setup-group {
  grid-template-rows: auto repeat(6, 36px);
  padding: 10px 12px 12px;
}

body.mobile-view .sandbox-setup-footer {
  align-items: stretch;
  flex-direction: column;
  gap: 8px;
}

body.mobile-view .sandbox-setup-footer > div,
body.mobile-view .sandbox-setup-footer button {
  width: 100%;
}

@media (orientation: portrait) and (max-width: 760px) {
  body.mobile-view .sandbox-setup-screen {
    align-content: start;
    grid-template-rows: auto auto auto;
    gap: 8px;
    padding: 12px;
  }

  body.mobile-view .sandbox-setup-header {
    gap: 5px;
  }

  body.mobile-view .sandbox-setup-header > div {
    width: 100%;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
  }

  body.mobile-view .sandbox-setup-header h1 {
    font-size: 21px;
    line-height: 25px;
  }

  body.mobile-view .sandbox-setup-header > div p {
    flex: 0 0 auto;
    font-size: 14px;
    line-height: 19px;
  }

  body.mobile-view .sandbox-setup-header > p {
    font-size: 9px;
    line-height: 13px;
  }

  body.mobile-view .sandbox-setup-steps {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  body.mobile-view .sandbox-setup-steps button {
    min-width: 0;
    min-height: 34px;
    border-color: rgb(64, 80, 98);
    background: rgb(19, 29, 40);
    color: var(--muted);
    padding: 4px 8px;
    font-size: 10px;
  }

  body.mobile-view .sandbox-setup-steps button[aria-current="step"] {
    border-color: rgb(94, 190, 245);
    background: rgb(34, 60, 76);
    color: var(--text);
  }

  body.mobile-view .sandbox-setup-form {
    height: auto;
    grid-template-rows: auto auto;
    gap: 7px;
  }

  body.mobile-view .sandbox-setup-columns {
    display: block;
  }

  body.mobile-view .sandbox-setup-group {
    align-content: start;
    min-height: 0;
    grid-template-rows: auto repeat(6, minmax(38px, auto));
    gap: 3px;
    padding: 9px 10px 11px;
  }

  body.mobile-view .sandbox-setup-screen[data-sandbox-step="target"] .sandbox-chaser-group,
  body.mobile-view .sandbox-setup-screen[data-sandbox-step="chaser"] .sandbox-target-group {
    display: none;
  }

  body.mobile-view .sandbox-setup-group legend {
    font-size: 14px;
    line-height: 18px;
    white-space: nowrap;
  }

  body.mobile-view .sandbox-group-title-wide {
    display: none;
  }

  body.mobile-view .sandbox-group-title-compact {
    display: inline;
  }

  body.mobile-view .sandbox-setup-group > p {
    margin: 0 0 2px;
    font-size: 9px;
    line-height: 13px;
  }

  body.mobile-view .sandbox-setup-group label {
    grid-template-columns: minmax(0, 1fr) 122px;
    gap: 8px;
    font-size: 10px;
    line-height: 12px;
  }

  body.mobile-view .sandbox-setup-group label > span {
    overflow: visible;
    line-height: 12px;
    text-overflow: clip;
    white-space: normal;
  }

  body.mobile-view .sandbox-setup-group small {
    font-size: 8px;
  }

  body.mobile-view .sandbox-setup-group input {
    height: 32px;
    padding: 0 8px;
    font-size: 11px;
  }

  body.mobile-view .sandbox-setup-footer {
    gap: 5px;
  }

  body.mobile-view .sandbox-setup-footer > p {
    min-height: 13px;
    font-size: 9px;
    line-height: 13px;
  }

  body.mobile-view .sandbox-setup-footer > div {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  body.mobile-view .sandbox-setup-footer button {
    min-width: 0;
    min-height: 36px;
  }

  body.mobile-view .sandbox-setup-screen[data-sandbox-step="target"] .sandbox-setup-next,
  body.mobile-view .sandbox-setup-screen[data-sandbox-step="chaser"] .sandbox-setup-back {
    display: block;
  }

  body.mobile-view .sandbox-setup-screen[data-sandbox-step="target"] #sandboxSetupContinue,
  body.mobile-view .sandbox-setup-screen[data-sandbox-step="chaser"] #sandboxSetupCancel {
    display: none;
  }
}

body.mobile-view .touch-controls,
body.mobile-view .mobile-speed-controls {
  display: grid;
  gap: 6px;
}

body.mobile-view .trainer-shell.selector-mode .touch-controls,
body.mobile-view .trainer-shell.selector-mode .mobile-speed-controls {
  display: none;
}

body.mobile-view .trainer-shell.selector-mode .top-bar,
body.mobile-view .trainer-shell.selector-mode .game-layout,
body.mobile-view .trainer-shell.selector-mode .hud-panel {
  display: none;
}

body.mobile-view .mobile-speed-controls {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

body.mobile-view .touch-controls {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

body.mobile-view .touch-controls button {
  min-width: 0;
  min-height: 38px;
  padding: 5px;
  font-size: 14px;
  font-weight: 700;
}

body.mobile-view .touch-controls button:hover:not(.active) {
  border-color: rgb(104, 130, 156);
  background: rgb(34, 48, 62);
  color: rgb(220, 234, 246);
}

body.mobile-view .mobile-speed-controls button {
  min-width: 0;
  min-height: 32px;
  padding: 3px 5px;
  font-size: 13px;
  font-weight: 700;
}

body.mobile-view .mobile-speed-controls button.active {
  border-color: rgb(248, 84, 100);
  background: rgb(96, 22, 32);
  color: rgb(255, 220, 224);
}

body.mobile-view .debrief-panel {
  width: calc(100vw - 20px);
  max-height: calc(100dvh - 20px);
  padding: 14px;
  overflow: auto;
}

body.mobile-view .leaderboard-form {
  grid-template-columns: 1fr;
}

@media (max-height: 740px) {
  body.mobile-view .trainer-shell {
    gap: 6px;
    padding-top: max(6px, env(safe-area-inset-top));
    padding-bottom: max(6px, env(safe-area-inset-bottom));
  }

  body.mobile-view h1 {
    font-size: 18px;
    line-height: 21px;
  }

  body.mobile-view .objective-checklist,
  body.mobile-view .hud-panel {
    padding: 6px;
  }

  body.mobile-view .touch-controls button {
    min-height: 34px;
  }

  body.mobile-view .mobile-speed-controls button {
    min-height: 30px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  body.mobile-view .sandbox-setup-screen {
    width: 100%;
    height: 100dvh;
    min-height: 0;
    padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(
        6px,
        env(safe-area-inset-bottom)
      )
      max(8px, env(safe-area-inset-left));
    gap: 5px;
    overflow: hidden;
  }

  body.mobile-view .sandbox-setup-header {
    min-height: 32px;
    align-items: center;
    flex-direction: row;
    gap: 12px;
  }

  body.mobile-view .sandbox-setup-header > div {
    gap: 12px;
  }

  body.mobile-view .sandbox-setup-header h1 {
    font-size: 18px;
    line-height: 22px;
  }

  body.mobile-view .sandbox-setup-header > div p {
    font-size: 12px;
    line-height: 16px;
  }

  body.mobile-view .sandbox-setup-header > p {
    max-width: 330px;
    margin-left: auto;
    font-size: 9px;
    line-height: 12px;
    text-align: right;
  }

  body.mobile-view .sandbox-setup-form {
    min-height: 0;
    grid-template-rows: minmax(0, 1fr) 30px;
    gap: 5px;
  }

  body.mobile-view .sandbox-setup-columns {
    min-height: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  body.mobile-view .sandbox-setup-group {
    min-height: 0;
    grid-template-rows: auto repeat(6, minmax(24px, 1fr));
    gap: 2px;
    padding: 5px 8px 6px;
  }

  body.mobile-view .sandbox-setup-group legend {
    padding: 0 4px;
    font-size: 11px;
  }

  body.mobile-view .sandbox-setup-group > p {
    display: none;
  }

  body.mobile-view .sandbox-setup-group label {
    grid-template-columns: minmax(0, 1fr) 92px;
    gap: 6px;
    font-size: 9px;
  }

  body.mobile-view .sandbox-setup-group small {
    font-size: 8px;
  }

  body.mobile-view .sandbox-setup-group input {
    height: 23px;
    padding: 0 6px;
    font-size: 10px;
  }

  body.mobile-view .sandbox-setup-footer {
    min-height: 0;
    align-items: center;
    flex-direction: row;
    gap: 8px;
  }

  body.mobile-view .sandbox-setup-footer > p {
    overflow: hidden;
    font-size: 9px;
    line-height: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body.mobile-view .sandbox-setup-footer > div {
    width: auto;
    gap: 6px;
  }

  body.mobile-view .sandbox-setup-footer button {
    width: 88px;
    min-width: 88px;
    min-height: 26px;
    font-size: 10px;
  }

  body.mobile-view .trainer-shell.selector-mode {
    width: 100vw;
    height: 100dvh;
    max-width: none;
    padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(
        6px,
        env(safe-area-inset-bottom)
      )
      max(8px, env(safe-area-inset-left));
  }

  body.mobile-view .level-selector {
    grid-template-rows: auto minmax(0, 1fr);
    gap: 6px;
    width: 100%;
    height: 100%;
  }

  body.mobile-view .launcher-header {
    grid-template-columns: minmax(0, 1fr) repeat(4, 94px);
    grid-template-rows: auto auto;
    column-gap: 8px;
    row-gap: 0;
  }

  body.mobile-view .launcher-header h1 {
    grid-column: 1;
    grid-row: 1;
    font-size: 18px;
    line-height: 22px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  body.mobile-view .launcher-header p {
    grid-column: 1;
    grid-row: 2;
    font-size: 11px;
    line-height: 13px;
  }

  body.mobile-view .launcher-subtitle span:last-child {
    display: none;
  }

  body.mobile-view .launcher-music,
  body.mobile-view .launcher-view,
  body.mobile-view .launcher-frame,
  body.mobile-view .launcher-repo {
    min-height: 30px;
    font-size: 11px;
  }

  body.mobile-view .launcher-music {
    grid-column: 3;
    grid-row: 1;
  }

  body.mobile-view .launcher-view {
    grid-column: 4;
    grid-row: 1;
  }

  body.mobile-view .launcher-frame {
    grid-column: 2;
    grid-row: 1;
  }

  body.mobile-view .launcher-repo {
    grid-column: 5;
    grid-row: 1;
  }

  body.mobile-view .launcher-body {
    grid-template-columns: minmax(210px, 0.34fr) minmax(0, 1fr);
    gap: 8px;
  }

  body.mobile-view .launcher-list,
  body.mobile-view .launcher-preview {
    min-height: 0;
    height: 100%;
  }

  body.mobile-view .launcher-list {
    align-content: start;
    padding: 8px;
  }

  body.mobile-view .launcher-option {
    min-height: 54px;
  }

  body.mobile-view .launcher-preview {
    padding: 10px;
  }

  body.mobile-view .launcher-play-level {
    min-width: 86px;
    min-height: 30px;
    font-size: 11px;
  }

  body.mobile-view .launcher-preview h2 {
    margin-bottom: 6px;
    font-size: 16px;
    line-height: 20px;
  }

  body.mobile-view .trainer-shell:not(.selector-mode) {
    width: 100vw;
    height: 100dvh;
    max-width: none;
    grid-template-columns: minmax(0, 1fr) clamp(280px, 36vw, 360px);
    grid-template-rows: auto minmax(92px, 1fr) auto auto;
    grid-template-areas:
      "top top"
      "game game"
      "hud controls"
      "speeds controls";
    gap: 6px;
    padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(
        6px,
        env(safe-area-inset-bottom)
      )
      max(8px, env(safe-area-inset-left));
  }

  body.mobile-view .trainer-shell.sandbox-setup-mode {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: "setup";
  }

  body.mobile-view .trainer-shell.sandbox-setup-mode .sandbox-setup-screen {
    grid-area: setup;
    width: 100%;
    height: 100%;
  }

  body.mobile-view .top-bar {
    grid-area: top;
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
    gap: 3px;
    min-height: 62px;
    padding: 5px 10px;
    border: 2px solid var(--stroke-hud);
    border-radius: 10px;
    background: var(--hud);
  }

  body.mobile-view .top-left {
    min-width: 0;
  }

  body.mobile-view h1 {
    font-size: 15px;
    line-height: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  body.mobile-view .top-metrics {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    font-size: 10px;
    line-height: 12px;
    overflow: hidden;
  }

  body.mobile-view .top-metrics span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body.mobile-view .objective-checklist {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-content: start;
    gap: 1px;
    min-width: 0;
    min-height: 0;
    padding: 0;
    border: 0;
    background: transparent;
    font-size: 9px;
    line-height: 11px;
  }

  body.mobile-view .objective-heading {
    display: block;
    color: var(--muted);
    font-size: 9px;
    line-height: 10px;
    text-transform: uppercase;
  }

  body.mobile-view #objectiveTitle,
  body.mobile-view #objectiveText {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  body.mobile-view #objectiveTitle {
    white-space: nowrap;
  }

  body.mobile-view #objectiveText {
    white-space: normal;
  }

  body.mobile-view .game-layout {
    grid-area: game;
  }

  body.mobile-view .plot-stack {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: minmax(0, 1fr);
    gap: 6px;
  }

  body.mobile-view .plot-title {
    left: 8px;
    right: 8px;
    top: 6px;
    height: 18px;
    gap: 6px;
  }

  body.mobile-view .plot-title span {
    font-size: 12px;
  }

  body.mobile-view .plot-title small {
    font-size: 9px;
  }

  body.mobile-view canvas {
    left: 8px;
    right: 8px;
    top: 30px;
    bottom: 8px;
    width: calc(100% - 16px);
    height: calc(100% - 38px);
  }

  body.mobile-view .hud-panel {
    grid-area: hud;
    align-self: stretch;
    display: grid;
    grid-template-columns: minmax(150px, 0.9fr) minmax(260px, 1.4fr);
    grid-template-rows: auto auto;
    column-gap: 8px;
    row-gap: 4px;
    align-items: start;
    padding: 5px;
    font-size: 10px;
    line-height: 13px;
    overflow: hidden;
  }

  body.mobile-view .hud-line {
    grid-column: 1;
    font-size: 10px;
    line-height: 13px;
  }

  body.mobile-view .hud-top-controls {
    grid-column: 1 / -1;
    grid-row: 2;
    gap: 3px;
  }

  body.mobile-view .hud-actions {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 3px;
  }

  body.mobile-view .hud-actions button,
  body.mobile-view .music-button {
    min-height: 26px;
    padding: 2px 3px;
    font-size: 9px;
    line-height: 10px;
  }

  body.mobile-view .hint-line {
    grid-column: 2;
    grid-row: 1;
    font-size: 10px;
    line-height: 13px;
  }

  body.mobile-view .trainer-shell.mode-arcade .hud-panel,
  body.mobile-view .trainer-shell.mode-tutorial .hud-panel,
  body.mobile-view .trainer-shell.mode-sandbox .hud-panel {
    grid-template-columns: minmax(0, 1fr) max-content;
    column-gap: 4px;
  }

  body.mobile-view .trainer-shell.mode-arcade .hud-line,
  body.mobile-view .trainer-shell.mode-arcade .hint-line,
  body.mobile-view .trainer-shell.mode-tutorial .hud-line,
  body.mobile-view .trainer-shell.mode-tutorial .hint-line,
  body.mobile-view .trainer-shell.mode-sandbox .hud-line,
  body.mobile-view .trainer-shell.mode-sandbox .hint-line {
    font-size: clamp(9px, 1.5vw, 10px);
    white-space: nowrap;
  }

  body.mobile-view .touch-controls {
    grid-area: controls;
    position: static;
    align-self: stretch;
    height: 100%;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
  }

  body.mobile-view .mobile-speed-controls {
    grid-area: speeds;
    align-self: stretch;
    gap: 4px;
  }

  body.mobile-view .touch-controls button,
  body.mobile-view .mobile-speed-controls button {
    min-height: 28px;
    padding: 3px;
    font-size: 13px;
  }
}

body.mobile-view .trainer-shell.mode-arcade .top-bar,
body.mobile-view .trainer-shell.mode-tutorial .top-bar,
body.mobile-view .trainer-shell.mode-sandbox .top-bar {
  grid-template-columns: minmax(0, 1fr) minmax(118px, 0.48fr);
  align-items: start;
  column-gap: 10px;
}

body.mobile-view .trainer-shell.mode-arcade .top-metrics,
body.mobile-view .trainer-shell.mode-tutorial .top-metrics,
body.mobile-view .trainer-shell.mode-sandbox .top-metrics {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1px;
  margin-top: 4px;
}

body.mobile-view .trainer-shell.mode-arcade #topRangeMetric,
body.mobile-view .trainer-shell.mode-arcade #topSpeedMetric,
body.mobile-view .trainer-shell.mode-arcade #topDvMetric {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.mobile-view .trainer-shell.mode-arcade .objective-checklist,
body.mobile-view .trainer-shell.mode-tutorial .objective-checklist,
body.mobile-view .trainer-shell.mode-sandbox .objective-checklist {
  align-self: stretch;
  min-width: 0;
  padding-left: 10px;
  border-left: 1px solid rgb(72, 84, 102);
}

@media (orientation: landscape) and (max-height: 520px) {
  body.mobile-view .trainer-shell.mode-tutorial .top-bar {
    min-height: 0;
  }

  body.mobile-view .trainer-shell.mode-sandbox .top-bar {
    min-height: 0;
  }

  body.mobile-view .trainer-shell.mode-tutorial .objective-checklist,
  body.mobile-view .trainer-shell.mode-sandbox .objective-checklist {
    align-self: start;
  }

  body.mobile-view .trainer-shell.mode-arcade .top-bar {
    min-height: 50px;
  }

  body.mobile-view .trainer-shell.mode-arcade .top-metrics {
    grid-template-columns: max-content max-content max-content;
    align-items: baseline;
    column-gap: 14px;
    row-gap: 0;
  }

  body.mobile-view .trainer-shell.mode-arcade #topRangeMetric {
    grid-column: auto;
  }
}

/* Mouse-only Sandbox camera. Other preview layouts retain their existing panels. */
.sandbox-3d-panel { grid-column: 1 / -1; grid-row: 1 / -1; }
.sandbox-3d-panel[hidden], .camera-3d-toggle[hidden] { display: none !important; }
.camera-3d-toolbar { display: flex; gap: 6px; }
.camera-3d-toolbar button, .camera-3d-toggle { padding: 3px 9px; font-size: 12px; min-height: 25px; }
.sandbox-3d-panel canvas { touch-action: none; cursor: grab; }
.sandbox-3d-panel canvas:active { cursor: grabbing; }
body:not(.mobile-view) .sandbox-3d-panel canvas { bottom: 36px; height: calc(100% - 100px); }
.camera-3d-help { position: absolute; bottom: 8px; left: 14px; font-size: 12px; color: #a5b8c9; pointer-events: none; }

/* Mobile camera gestures belong only to the landscape Sandbox viewport. */
body.mobile-view .sandbox-3d-panel .plot-title { height: 28px; }
body.mobile-view .camera-3d-toolbar { gap: 4px; }
body.mobile-view .camera-3d-toggle { min-height: 36px; min-width: 36px; padding: 4px 6px; }
body.mobile-view .camera-3d-toolbar button { min-height: 28px; min-width: 36px; padding: 2px 6px; }
body.mobile-view .camera-3d-toolbar button[hidden] { display: none; }
body.mobile-view .sandbox-3d-panel canvas {
  top: 38px; bottom: 22px; height: calc(100% - 60px);
}
body.mobile-view .camera-3d-help { bottom: 5px; left: 8px; font-size: 10px; }

/* Desktop gameplay reserves the same space on either side of the plots. */
body.desktop-view .trainer-shell:not(.selector-mode):not(.sandbox-setup-mode):not(.mode-operator-script) {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 22px;
  padding: 18px 36px 26px;
}
body.desktop-view .trainer-shell:not(.mode-operator-script) > .top-bar {
  position: relative;
  inset: auto;
  grid-row: 1;
}
body.desktop-view .trainer-shell:not(.mode-operator-script) > .game-layout {
  position: relative;
  inset: auto;
  min-height: 0;
  grid-row: 2;
}
body.desktop-view .trainer-shell:not(.mode-operator-script) > .hud-panel {
  position: relative;
  inset: auto;
  grid-row: 3;
}

body.desktop-view .top-bar:has(> .camera-3d-toggle:not([hidden])) {
  grid-template-columns: minmax(0, 1fr) minmax(120px, 300px) auto;
}
body.desktop-view .top-bar > .camera-3d-toggle {
  align-self: center;
  min-width: 48px;
  min-height: 34px;
}
@media (max-width: 900px) {
  body.desktop-view .top-bar:has(> .camera-3d-toggle:not([hidden])) {
    grid-template-columns: minmax(0, 1fr) auto;
  }
  body.desktop-view .top-bar:has(> .camera-3d-toggle:not([hidden])) > .top-left {
    grid-column: 1 / -1;
  }
}

@media (orientation: landscape) {
  body.mobile-view .top-bar:has(> .camera-3d-toggle:not([hidden])) {
    grid-template-columns: minmax(0, 1fr) minmax(118px, 0.48fr) auto;
    column-gap: 8px;
  }
  body.mobile-view .top-bar > .camera-3d-toggle {
    grid-column: 3;
    grid-row: 1;
    align-self: center;
    min-width: 44px;
    min-height: 36px;
  }
}
