:root {
  --paper: #f6f2e9;
  --ink: #20242a;
  --muted: #77756d;
  --line: #d8d0c0;
  --panel: #fffcf4;
  --blue: #2f80ed;
  --red: #e14a3b;
  --green: #25a36f;
  --yellow: #e8b84e;
  --purple: #8067c8;
  --black: #111318;
  --shadow: 0 18px 55px rgba(32, 36, 42, 0.13);
  --route-bg: #fffcf4;
  --route-main: #d7cab4;
  --route-ink: #27313a;
  --map-grid: rgba(32, 36, 42, 0.045);
  --panel-glass: rgba(255, 252, 244, 0.88);
  --bubble-glass: rgba(255, 255, 255, 0.34);
  --bubble-highlight: rgba(255, 255, 255, 0.78);
  --bubble-shadow: 0 16px 42px rgba(32, 36, 42, 0.15);
}

body[data-theme="night"] {
  --paper: #15171c;
  --ink: #f4efe4;
  --muted: #a8a294;
  --line: #3a3f47;
  --panel: #20242a;
  --black: #f4efe4;
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.34);
  --route-bg: #242932;
  --route-main: #6e7785;
  --route-ink: #f4efe4;
  --map-grid: rgba(244, 239, 228, 0.055);
  --panel-glass: rgba(32, 36, 42, 0.9);
  --bubble-glass: rgba(32, 36, 42, 0.46);
  --bubble-highlight: rgba(255, 255, 255, 0.2);
  --bubble-shadow: 0 18px 48px rgba(0, 0, 0, 0.36);
}

body[data-theme="blueprint"] {
  --paper: #eaf2f8;
  --ink: #183245;
  --muted: #617484;
  --line: #a9bdca;
  --panel: #f7fbff;
  --black: #173245;
  --shadow: 0 18px 55px rgba(24, 50, 69, 0.16);
  --route-bg: #f7fbff;
  --route-main: #9fb4c4;
  --route-ink: #173245;
  --map-grid: rgba(24, 50, 69, 0.07);
  --panel-glass: rgba(247, 251, 255, 0.9);
  --bubble-glass: rgba(247, 251, 255, 0.4);
  --bubble-highlight: rgba(255, 255, 255, 0.78);
  --bubble-shadow: 0 16px 42px rgba(24, 50, 69, 0.17);
}

body[data-theme="signal"] {
  --paper: #f3f4ed;
  --ink: #16251f;
  --muted: #667068;
  --line: #c8cec0;
  --panel: #fffef6;
  --black: #16251f;
  --shadow: 0 18px 55px rgba(22, 37, 31, 0.15);
  --route-bg: #fffef6;
  --route-main: #b9c2ad;
  --route-ink: #16251f;
  --map-grid: rgba(22, 37, 31, 0.055);
  --panel-glass: rgba(255, 254, 246, 0.9);
  --bubble-glass: rgba(255, 254, 246, 0.4);
  --bubble-highlight: rgba(255, 255, 255, 0.76);
  --bubble-shadow: 0 16px 42px rgba(22, 37, 31, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  appearance: none;
  border: 0;
  border-radius: 8px;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

button:focus-visible,
canvas:focus-visible {
  outline: 3px solid rgba(47, 128, 237, 0.45);
  outline-offset: 3px;
}

.shell {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 320px;
}

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 18px;
  border-bottom: 0;
  background: transparent;
  backdrop-filter: none;
  z-index: 2;
}

.eyebrow {
  margin: 0 0 2px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1;
  font-weight: 900;
}

.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(72px, 1fr));
  gap: 8px;
  min-width: min(650px, 62vw);
}

.stats span,
.readout div,
.status-card,
.run-card,
.event-card,
.legend,
.meters {
  border: 1px solid color-mix(in srgb, var(--line) 62%, rgba(255, 255, 255, 0.6));
  background:
    radial-gradient(circle at 24% 16%, var(--bubble-highlight), transparent 34%),
    linear-gradient(135deg, var(--bubble-glass), color-mix(in srgb, var(--panel-glass) 46%, transparent));
  box-shadow:
    inset 0 1px 0 var(--bubble-highlight),
    inset 0 -18px 32px rgba(255, 255, 255, 0.12),
    var(--bubble-shadow);
  backdrop-filter: blur(18px) saturate(1.25);
  -webkit-backdrop-filter: blur(18px) saturate(1.25);
}

.stats span {
  min-height: 48px;
  border-radius: 18px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.stats b {
  font-size: 18px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.stats small,
.readout span,
.legend span,
.status-card p,
.status-card span,
.run-card p,
.run-card span,
.event-card p,
.event-card span,
.contract span,
.meters label {
  font-size: 10px;
  line-height: 1.1;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--muted);
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 188px minmax(0, 1fr) 162px;
}

.panel {
  min-height: 0;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-color: transparent;
  background: transparent;
  z-index: 1;
}

.left-panel {
  border-right: 0;
}

.right-panel {
  border-left: 0;
}

.tool-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tool {
  min-height: 76px;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid color-mix(in srgb, var(--ink) 18%, rgba(255, 255, 255, 0.62));
  border-radius: 999px;
  background:
    radial-gradient(circle at 28% 18%, var(--bubble-highlight), transparent 32%),
    linear-gradient(135deg, var(--bubble-glass), color-mix(in srgb, var(--panel-glass) 44%, transparent));
  box-shadow:
    inset 0 1px 0 var(--bubble-highlight),
    inset 0 -16px 28px rgba(255, 255, 255, 0.12),
    var(--bubble-shadow);
  backdrop-filter: blur(18px) saturate(1.25);
  -webkit-backdrop-filter: blur(18px) saturate(1.25);
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.tool span {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  font-size: 24px;
  line-height: 1;
}

.tool small {
  max-width: 100%;
  font-size: 10px;
  font-weight: 850;
  text-transform: uppercase;
  color: var(--muted);
}

.tool.active {
  color: var(--ink);
  border-color: color-mix(in srgb, var(--blue) 66%, rgba(255, 255, 255, 0.72));
  background:
    radial-gradient(circle at 28% 18%, rgba(255, 255, 255, 0.84), transparent 32%),
    linear-gradient(135deg, color-mix(in srgb, var(--blue) 24%, transparent), var(--bubble-glass));
  box-shadow:
    inset 0 1px 0 var(--bubble-highlight),
    inset 0 -16px 28px color-mix(in srgb, var(--blue) 12%, transparent),
    0 16px 42px color-mix(in srgb, var(--blue) 24%, rgba(32, 36, 42, 0.14));
}

.tool.active small {
  color: color-mix(in srgb, var(--ink) 72%, var(--blue));
}

.tool.locked {
  opacity: 0.48;
  filter: grayscale(0.65);
  cursor: not-allowed;
}

.tool.tutorial-focus,
.upgrade.tutorial-focus,
.pulse {
  animation: focus-pulse 950ms ease-in-out;
  border-color: color-mix(in srgb, var(--yellow) 80%, white) !important;
  box-shadow:
    inset 0 1px 0 var(--bubble-highlight),
    0 0 0 4px color-mix(in srgb, var(--yellow) 28%, transparent),
    var(--bubble-shadow) !important;
}

.readout {
  display: grid;
  gap: 8px;
}

.readout div {
  min-height: 52px;
  border-radius: 18px;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.readout b {
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.meters {
  margin-top: auto;
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 12px;
}

.meters label {
  display: grid;
  gap: 7px;
}

meter {
  width: 100%;
  height: 8px;
}

.map-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(var(--map-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--map-grid) 1px, transparent 1px),
    var(--paper);
  background-size: 36px 36px;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

body[data-drag-mode="pan"] canvas {
  cursor: grabbing;
}

.toast {
  position: absolute;
  left: 18px;
  bottom: 18px;
  max-width: min(340px, calc(100% - 36px));
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--line) 62%, rgba(255, 255, 255, 0.6));
  border-radius: 999px;
  background:
    radial-gradient(circle at 22% 18%, var(--bubble-highlight), transparent 32%),
    linear-gradient(135deg, var(--bubble-glass), color-mix(in srgb, var(--panel-glass) 50%, transparent));
  box-shadow:
    inset 0 1px 0 var(--bubble-highlight),
    var(--bubble-shadow);
  backdrop-filter: blur(18px) saturate(1.25);
  -webkit-backdrop-filter: blur(18px) saturate(1.25);
  color: var(--ink);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.objective,
.tutorial {
  position: absolute;
  z-index: 3;
  max-width: min(380px, calc(100% - 36px));
  border: 1px solid color-mix(in srgb, var(--line) 62%, rgba(255, 255, 255, 0.6));
  background:
    radial-gradient(circle at 22% 18%, var(--bubble-highlight), transparent 32%),
    linear-gradient(135deg, var(--bubble-glass), color-mix(in srgb, var(--panel-glass) 54%, transparent));
  box-shadow:
    inset 0 1px 0 var(--bubble-highlight),
    var(--bubble-shadow);
  backdrop-filter: blur(18px) saturate(1.25);
  -webkit-backdrop-filter: blur(18px) saturate(1.25);
  color: var(--ink);
}

.objective {
  top: 16px;
  left: 18px;
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border-radius: 8px;
}

.objective b,
.tutorial b {
  font-size: 12px;
  line-height: 1.1;
  font-weight: 950;
  text-transform: uppercase;
}

.objective span,
.tutorial span {
  font-size: 12px;
  line-height: 1.35;
  font-weight: 750;
  color: var(--muted);
}

.tutorial {
  right: 18px;
  bottom: 18px;
  display: grid;
  gap: 9px;
  padding: 12px;
  border-radius: 8px;
}

.tutorial.hidden {
  display: none;
}

.tutorial div {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tutorial button {
  min-height: 34px;
  padding: 8px 11px;
  border: 1px solid color-mix(in srgb, var(--ink) 16%, rgba(255, 255, 255, 0.62));
  border-radius: 999px;
  background: var(--panel-glass);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

#tutorial-action,
#mode.active {
  border-color: color-mix(in srgb, var(--blue) 66%, rgba(255, 255, 255, 0.72));
  background:
    radial-gradient(circle at 28% 18%, rgba(255, 255, 255, 0.84), transparent 32%),
    linear-gradient(135deg, color-mix(in srgb, var(--blue) 24%, transparent), var(--bubble-glass));
}

@keyframes focus-pulse {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }
  50% {
    transform: translateY(-2px) scale(1.04);
  }
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(246, 242, 233, 0.72);
  backdrop-filter: blur(8px);
}

.overlay.hidden {
  display: none;
}

.help-modal {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(17, 19, 24, 0.22);
  backdrop-filter: blur(5px);
}

.help-modal.hidden {
  display: none;
}

.help-sheet {
  width: min(860px, 100%);
  max-height: min(760px, calc(100dvh - 36px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid color-mix(in srgb, var(--line) 62%, rgba(255, 255, 255, 0.6));
  border-radius: 24px;
  background:
    radial-gradient(circle at 18% 10%, var(--bubble-highlight), transparent 32%),
    linear-gradient(135deg, var(--bubble-glass), color-mix(in srgb, var(--panel-glass) 56%, transparent));
  box-shadow:
    inset 0 1px 0 var(--bubble-highlight),
    var(--bubble-shadow);
  backdrop-filter: blur(22px) saturate(1.25);
  -webkit-backdrop-filter: blur(22px) saturate(1.25);
  overflow: hidden;
}

.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.help-head p,
.help-head h2,
.help-body h3,
.help-body p,
.help-body ul {
  margin: 0;
}

.help-head p {
  margin-bottom: 4px;
  font-size: 10px;
  font-weight: 850;
  text-transform: uppercase;
  color: var(--muted);
}

.help-head h2 {
  font-size: 24px;
  line-height: 1;
  font-weight: 950;
}

#help-close {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border: 1px solid color-mix(in srgb, var(--ink) 16%, rgba(255, 255, 255, 0.62));
  border-radius: 999px;
  background:
    radial-gradient(circle at 28% 18%, var(--bubble-highlight), transparent 32%),
    linear-gradient(135deg, var(--bubble-glass), color-mix(in srgb, var(--panel-glass) 44%, transparent));
  box-shadow:
    inset 0 1px 0 var(--bubble-highlight),
    0 12px 30px rgba(32, 36, 42, 0.12);
  backdrop-filter: blur(18px) saturate(1.25);
  -webkit-backdrop-filter: blur(18px) saturate(1.25);
  font-size: 24px;
  line-height: 1;
  font-weight: 850;
}

.help-body {
  min-height: 0;
  overflow: auto;
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.help-body section {
  min-width: 0;
  border: 1px solid color-mix(in srgb, var(--line) 62%, rgba(255, 255, 255, 0.6));
  border-radius: 18px;
  padding: 12px;
  background:
    radial-gradient(circle at 22% 16%, var(--bubble-highlight), transparent 34%),
    linear-gradient(135deg, var(--bubble-glass), color-mix(in srgb, var(--panel-glass) 38%, transparent));
}

.help-body h3 {
  margin-bottom: 8px;
  font-size: 12px;
  line-height: 1;
  font-weight: 950;
  text-transform: uppercase;
}

.help-body p,
.help-body li {
  font-size: 13px;
  line-height: 1.42;
  color: var(--ink);
}

.help-body ul {
  padding-left: 18px;
}

.help-body li + li {
  margin-top: 5px;
}

.overlay.failure {
  place-items: start center;
  align-content: start;
  gap: 8px;
  padding-top: 112px;
  background: rgba(246, 242, 233, 0.12);
  backdrop-filter: none;
}

.overlay.failure #overlay-kicker,
.overlay.failure #overlay-title,
.overlay.failure #overlay-copy,
.overlay.failure #restart {
  align-self: auto;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-glass);
  box-shadow: var(--shadow);
}

.overlay.failure #overlay-kicker {
  padding: 6px 10px;
}

.overlay.failure #overlay-title {
  padding: 10px 14px;
  font-size: clamp(28px, 6vw, 64px);
}

.overlay.failure #overlay-copy {
  padding: 8px 10px;
  max-width: min(620px, calc(100vw - 28px));
  font-size: 13px;
}

.overlay.failure #restart {
  padding: 10px 14px;
  color: var(--ink);
}

.overlay > * {
  grid-column: 1;
}

.overlay p,
.overlay h2 {
  margin: 0;
  text-align: center;
}

#overlay-kicker {
  align-self: end;
  margin-bottom: 86px;
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
  color: var(--muted);
}

#overlay-title {
  font-size: clamp(42px, 8vw, 118px);
  line-height: 0.92;
  max-width: 840px;
  font-weight: 950;
}

#overlay-copy {
  align-self: start;
  margin-top: 92px;
  font-size: 16px;
  font-weight: 800;
}

#restart {
  align-self: start;
  margin-top: 142px;
  padding: 12px 20px;
  border: 1px solid color-mix(in srgb, var(--blue) 66%, rgba(255, 255, 255, 0.72));
  border-radius: 999px;
  background:
    radial-gradient(circle at 28% 18%, rgba(255, 255, 255, 0.84), transparent 32%),
    linear-gradient(135deg, color-mix(in srgb, var(--blue) 24%, transparent), var(--bubble-glass));
  box-shadow:
    inset 0 1px 0 var(--bubble-highlight),
    0 16px 42px color-mix(in srgb, var(--blue) 24%, rgba(32, 36, 42, 0.14));
  color: var(--ink);
  font-weight: 900;
  text-transform: uppercase;
}

.status-card {
  min-height: 120px;
  border-radius: 22px;
  padding: 13px;
  display: grid;
  align-content: space-between;
}

.run-card,
.event-card,
.contracts {
  border-radius: 18px;
  padding: 10px;
}

.run-card,
.event-card {
  display: grid;
  gap: 6px;
}

.run-card p,
.run-card span,
.event-card p,
.event-card span {
  margin: 0;
}

.run-card p,
.event-card p {
  color: var(--ink);
}

.contracts {
  display: grid;
  gap: 6px;
}

.contract {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 7px 8px;
  border: 1px solid color-mix(in srgb, var(--line) 58%, rgba(255, 255, 255, 0.62));
  border-radius: 18px;
  background:
    radial-gradient(circle at 22% 16%, var(--bubble-highlight), transparent 34%),
    linear-gradient(135deg, var(--bubble-glass), color-mix(in srgb, var(--panel-glass) 42%, transparent));
  box-shadow:
    inset 0 1px 0 var(--bubble-highlight),
    0 10px 26px rgba(32, 36, 42, 0.09);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
}

.contract-title {
  min-width: 0;
}

.contract-rule {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.15;
}

.contract b {
  font-size: 11px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.contract.complete {
  border-color: var(--green);
}

.contract.breached {
  border-color: var(--red);
  background:
    radial-gradient(circle at 22% 16%, var(--bubble-highlight), transparent 34%),
    linear-gradient(135deg, color-mix(in srgb, var(--red) 16%, transparent), var(--bubble-glass));
}

.contract.breached .contract-rule {
  color: var(--red);
}

.status-card b {
  font-size: 34px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.team-picker {
  position: fixed;
  top: clamp(110px, 16vh, 168px);
  right: clamp(178px, 13vw, 220px);
  z-index: 5;
  width: min(178px, calc(100vw - 28px));
  border: 0;
  border-radius: 0;
  padding: 0;
  display: grid;
  gap: 10px;
  background: transparent;
  box-shadow: none;
  pointer-events: none;
}

.team-option {
  min-height: 48px;
  display: grid;
  grid-template-columns: 24px 1fr;
  grid-template-rows: auto auto;
  column-gap: 8px;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid color-mix(in srgb, var(--team-color) 38%, rgba(255, 255, 255, 0.62));
  border-radius: 999px;
  background:
    radial-gradient(circle at 28% 18%, rgba(255, 255, 255, 0.82), transparent 30%),
    linear-gradient(135deg, color-mix(in srgb, var(--team-color) 16%, transparent), rgba(255, 255, 255, 0.18)),
    color-mix(in srgb, var(--panel-glass) 86%, transparent);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.78),
    inset 0 -12px 24px rgba(255, 255, 255, 0.16),
    0 14px 34px rgba(32, 36, 42, 0.16);
  backdrop-filter: blur(18px) saturate(1.35);
  -webkit-backdrop-filter: blur(18px) saturate(1.35);
  text-align: left;
  pointer-events: auto;
  transform: translateY(0);
  transition: border-color 180ms ease, box-shadow 180ms ease, transform 420ms cubic-bezier(0.2, 0.84, 0.18, 1);
}

.team-option:nth-child(even) {
  transform: translateX(-12px);
}

.team-option span {
  grid-row: 1 / 3;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--team-color);
  color: var(--panel);
  font-size: 13px;
  font-weight: 900;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.5),
    0 4px 12px color-mix(in srgb, var(--team-color) 32%, transparent);
}

.team-option b {
  min-width: 0;
  font-size: 10px;
  line-height: 1.05;
  font-weight: 900;
  text-transform: uppercase;
}

.team-option small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 8px;
  line-height: 1.05;
  font-weight: 850;
  text-transform: uppercase;
  color: var(--muted);
}

.team-option.active {
  position: fixed;
  left: var(--team-dock-left, 50vw);
  top: var(--team-dock-top, 50vh);
  width: 18px;
  height: 18px;
  min-height: 18px;
  padding: 0;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  place-items: center;
  border-color: transparent;
  background: transparent;
  color: transparent;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  transform: translate(-50%, -50%);
  z-index: 7;
}

.team-option.active span {
  grid-row: auto;
  width: 18px;
  height: 18px;
  font-size: 9px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.62),
    0 0 0 3px rgba(255, 255, 255, 0.38),
    0 8px 18px color-mix(in srgb, var(--team-color) 38%, rgba(32, 36, 42, 0.16));
}

.team-option.active b,
.team-option.active small {
  display: none;
}

.upgrade-strip {
  border: 0;
  border-radius: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  background: transparent;
  box-shadow: none;
}

.upgrade {
  min-width: 0;
  min-height: 48px;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 18px auto auto;
  justify-items: center;
  gap: 2px;
  padding: 7px 5px;
  border: 1px solid color-mix(in srgb, var(--ink) 16%, rgba(255, 255, 255, 0.62));
  border-radius: 999px;
  background:
    radial-gradient(circle at 28% 18%, var(--bubble-highlight), transparent 32%),
    linear-gradient(135deg, var(--bubble-glass), color-mix(in srgb, var(--panel-glass) 44%, transparent));
  box-shadow:
    inset 0 1px 0 var(--bubble-highlight),
    inset 0 -14px 24px rgba(255, 255, 255, 0.12),
    0 12px 30px rgba(32, 36, 42, 0.12);
  backdrop-filter: blur(18px) saturate(1.25);
  -webkit-backdrop-filter: blur(18px) saturate(1.25);
  text-align: center;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.upgrade span {
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--ink);
  color: var(--panel);
  font-size: 12px;
  font-weight: 900;
}

.upgrade b {
  font-size: 9px;
  line-height: 1;
  font-weight: 900;
}

.upgrade small {
  font-size: 7px;
  line-height: 1;
  font-weight: 850;
  color: var(--muted);
}

.upgrade:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

.upgrade:not(:disabled):not(.maxed) {
  border-color: color-mix(in srgb, var(--green) 58%, rgba(255, 255, 255, 0.7));
  box-shadow:
    inset 0 1px 0 var(--bubble-highlight),
    inset 0 -14px 24px color-mix(in srgb, var(--green) 10%, transparent),
    0 14px 34px color-mix(in srgb, var(--green) 16%, rgba(32, 36, 42, 0.12));
}

.upgrade.maxed {
  opacity: 0.76;
}

.legend {
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 11px;
}

.legend div {
  display: flex;
  align-items: center;
  gap: 9px;
}

.legend i {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  display: inline-block;
}

.legend .ore {
  background: var(--yellow);
}

.legend .crystal {
  background: var(--green);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}

.legend .relic {
  background: var(--paper);
  border: 2px solid var(--purple);
  border-radius: 4px;
}

.legend .water {
  background: var(--blue);
}

.legend .heat {
  background: var(--red);
}

.legend .gate {
  background: var(--purple);
}

.legend .monster {
  background: var(--black);
  box-shadow: inset 0 0 0 3px var(--red);
}

.legend .cart {
  width: 18px;
  height: 12px;
  border-radius: 3px;
  background: var(--purple);
  box-shadow:
    inset 0 -4px 0 var(--black),
    -3px 5px 0 -1px var(--paper),
    3px 5px 0 -1px var(--paper);
}

.commands {
  margin-top: auto;
  border: 0;
  border-radius: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  background: transparent;
  box-shadow: none;
}

.commands button {
  aspect-ratio: 1;
  border: 1px solid color-mix(in srgb, var(--ink) 16%, rgba(255, 255, 255, 0.62));
  border-radius: 999px;
  background:
    radial-gradient(circle at 28% 18%, var(--bubble-highlight), transparent 32%),
    linear-gradient(135deg, var(--bubble-glass), color-mix(in srgb, var(--panel-glass) 44%, transparent));
  box-shadow:
    inset 0 1px 0 var(--bubble-highlight),
    inset 0 -14px 24px rgba(255, 255, 255, 0.12),
    0 12px 30px rgba(32, 36, 42, 0.12);
  backdrop-filter: blur(18px) saturate(1.25);
  -webkit-backdrop-filter: blur(18px) saturate(1.25);
  font-size: 18px;
  font-weight: 900;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.mobile-tabs,
#mobile-actions {
  display: none;
}

.commands button:hover,
.tool:hover,
.team-option:hover,
.upgrade:hover:not(:disabled) {
  border-color: var(--ink);
}

.commands button:hover,
.tool:hover,
.upgrade:hover:not(:disabled) {
  box-shadow:
    inset 0 1px 0 var(--bubble-highlight),
    inset 0 -14px 24px rgba(255, 255, 255, 0.16),
    0 16px 38px rgba(32, 36, 42, 0.16);
  transform: translateY(-2px);
}

.team-option:hover {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.86),
    inset 0 -12px 24px rgba(255, 255, 255, 0.18),
    0 18px 42px color-mix(in srgb, var(--team-color) 22%, rgba(32, 36, 42, 0.18));
  transform: translateY(-2px);
}

.team-option:nth-child(even):hover {
  transform: translateX(-12px) translateY(-2px);
}

.team-option.active:hover {
  border-color: transparent;
  box-shadow: none;
  transform: translate(-50%, -50%);
}

@media (max-width: 920px) {
  html,
  body {
    overflow: auto;
    min-height: 100%;
  }

  .shell {
    min-height: 100%;
    height: auto;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .stats {
    min-width: 0;
    width: 100%;
    grid-template-columns: repeat(5, minmax(54px, 1fr));
  }

  .stats span {
    min-height: 44px;
    padding: 7px;
  }

  .stats b {
    font-size: 15px;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto minmax(520px, 72dvh);
  }

  .left-panel {
    order: 1;
  }

  .right-panel {
    order: 2;
  }

  .map-wrap {
    order: 3;
  }

  .left-panel,
  .right-panel {
    border: 0;
    border-bottom: 1px solid var(--line);
  }

  .panel {
    display: grid;
  }

  .left-panel {
    grid-template-columns: minmax(230px, 1fr) minmax(160px, 0.8fr) minmax(180px, 0.9fr);
  }

  .right-panel {
    grid-template-columns: minmax(150px, 0.6fr) minmax(160px, 0.7fr) minmax(220px, 1.1fr) minmax(120px, 0.6fr) auto;
  }

  .meters {
    display: none;
  }

  .legend {
    grid-template-columns: 1fr 1fr;
  }

  .team-picker {
    top: auto;
    right: 14px;
    bottom: 104px;
    width: min(520px, calc(100vw - 28px));
    grid-template-columns: repeat(5, minmax(72px, 1fr));
    align-items: end;
    overflow: visible;
  }

  .team-option {
    min-width: 0;
    grid-template-columns: 1fr;
    grid-template-rows: 24px auto auto;
    justify-items: center;
    text-align: center;
  }

  .team-option span {
    grid-row: auto;
  }
}

@media (max-width: 620px) {
  html,
  body {
    height: 100dvh;
    overflow: hidden;
  }

  .shell {
    height: 100dvh;
    min-height: 0;
    grid-template-rows: 58px minmax(0, 1fr);
  }

  h1 {
    display: none;
  }

  .topbar {
    min-height: 58px;
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    align-items: center;
    padding: 7px 8px;
    gap: 7px;
  }

  .eyebrow {
    margin: 0;
    font-size: 9px;
    line-height: 1.05;
  }

  .stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
  }

  .stats .stat-depth {
    display: none;
  }

  .stats span {
    min-height: 38px;
    padding: 5px 5px;
    box-shadow: none;
  }

  .stats small {
    font-size: 7px;
  }

  .stats b {
    font-size: 13px;
  }

  .workspace {
    position: relative;
    display: block;
    min-height: 0;
    overflow: hidden;
  }

  .map-wrap {
    position: absolute;
    inset: 0;
    min-height: 0;
  }

  .panel {
    position: absolute;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
    z-index: 3;
  }

  .left-panel {
    left: 8px;
    right: 8px;
    bottom: 8px;
    padding: 8px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .right-panel {
    left: 8px;
    right: 8px;
    top: 8px;
    padding: 0;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 6px;
    border: 0;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
    pointer-events: none;
  }

  .right-panel > * {
    pointer-events: auto;
  }

  .contracts,
  .team-picker,
  .upgrade-strip,
  .commands {
    background: transparent;
    box-shadow: none;
  }

  .status-card {
    min-height: 48px;
    padding: 7px 8px;
    align-content: center;
    gap: 2px;
  }

  .status-card p {
    display: none;
  }

  .status-card b {
    font-size: 20px;
  }

  .status-card span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 7px;
  }

  .team-picker {
    display: none;
  }

  .run-card,
  .contracts,
  .event-card {
    display: none;
  }

  body[data-mobile-panel="crew"] .team-picker {
    position: fixed;
    left: auto;
    right: 8px;
    bottom: 112px;
    z-index: 4;
    display: grid;
    width: min(308px, calc(100vw - 16px));
    min-width: 0;
    min-height: 48px;
    grid-template-columns: repeat(5, minmax(46px, 1fr));
    gap: 8px;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
    overflow: visible;
    scrollbar-width: none;
  }

  body[data-mobile-panel="status"] .run-card,
  body[data-mobile-panel="status"] .contracts,
  body[data-mobile-panel="status"] .event-card {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: 112px;
    z-index: 4;
    display: grid;
    box-shadow: 0 10px 28px rgba(32, 36, 42, 0.13);
    background: var(--panel-glass);
    pointer-events: none;
  }

  body[data-mobile-panel="status"] .run-card {
    bottom: 214px;
  }

  body[data-mobile-panel="status"] .event-card {
    bottom: 270px;
  }

  .team-option {
    min-width: 0;
    min-height: 46px;
    grid-template-columns: 1fr;
    grid-template-rows: 18px auto;
    justify-items: center;
    gap: 2px;
    padding: 8px;
    aspect-ratio: 1;
    text-align: center;
  }

  .team-option span {
    grid-row: auto;
    width: 18px;
    height: 18px;
    font-size: 10px;
  }

  .team-option b {
    display: none;
  }

  .team-option small {
    display: none;
  }

  .legend {
    display: none;
  }

  .commands {
    margin-top: 0;
    padding: 0;
    grid-template-columns: repeat(3, 32px);
    align-content: center;
    gap: 6px;
  }

  #mobile-actions {
    display: block;
  }

  #zoom-out,
  #zoom-in,
  #clear,
  #rush,
  #daily,
  #theme {
    display: none;
  }

  body[data-mobile-panel="actions"] #zoom-out,
  body[data-mobile-panel="actions"] #zoom-in,
  body[data-mobile-panel="actions"] #clear,
  body[data-mobile-panel="actions"] #rush,
  body[data-mobile-panel="actions"] #daily,
  body[data-mobile-panel="actions"] #theme {
    display: block;
  }

  body[data-mobile-panel="actions"] .commands {
    grid-template-columns: repeat(4, 32px);
  }

  .commands button {
    width: 32px;
    height: 38px;
    aspect-ratio: auto;
    font-size: 14px;
  }

  .commands button.active {
    color: var(--ink);
    border-color: color-mix(in srgb, var(--blue) 66%, rgba(255, 255, 255, 0.72));
    background:
      radial-gradient(circle at 28% 18%, rgba(255, 255, 255, 0.84), transparent 32%),
      linear-gradient(135deg, color-mix(in srgb, var(--blue) 24%, transparent), var(--bubble-glass));
    box-shadow:
      inset 0 1px 0 var(--bubble-highlight),
      inset 0 -14px 24px color-mix(in srgb, var(--blue) 12%, transparent),
      0 14px 34px color-mix(in srgb, var(--blue) 24%, rgba(32, 36, 42, 0.14));
  }

  .help-modal {
    padding: 8px;
  }

  .help-sheet {
    max-height: calc(100dvh - 16px);
  }

  .help-head {
    padding: 12px;
  }

  .help-head h2 {
    font-size: 20px;
  }

  .help-body {
    grid-template-columns: 1fr;
    padding: 8px;
    gap: 8px;
  }

  .help-body section {
    padding: 10px;
  }

  .help-body p,
  .help-body li {
    font-size: 12px;
  }

  .tool-grid {
    order: 3;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }

  .mobile-tabs {
    order: 1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
  }

  .mobile-tabs button {
    min-width: 0;
    min-height: 30px;
    padding: 5px 6px;
    border: 1px solid color-mix(in srgb, var(--ink) 16%, rgba(255, 255, 255, 0.62));
    border-radius: 999px;
    background:
      radial-gradient(circle at 28% 18%, var(--bubble-highlight), transparent 32%),
      linear-gradient(135deg, var(--bubble-glass), color-mix(in srgb, var(--panel-glass) 44%, transparent));
    box-shadow:
      inset 0 1px 0 var(--bubble-highlight),
      0 10px 26px rgba(32, 36, 42, 0.12);
    backdrop-filter: blur(16px) saturate(1.2);
    -webkit-backdrop-filter: blur(16px) saturate(1.2);
    color: var(--muted);
    font-size: 10px;
    line-height: 1;
    font-weight: 850;
    text-transform: uppercase;
  }

  .mobile-tabs button.active {
    color: var(--ink);
    border-color: color-mix(in srgb, var(--blue) 66%, rgba(255, 255, 255, 0.72));
    background:
      radial-gradient(circle at 28% 18%, rgba(255, 255, 255, 0.84), transparent 32%),
      linear-gradient(135deg, color-mix(in srgb, var(--blue) 24%, transparent), var(--bubble-glass));
  }

  .tool {
    min-height: 46px;
    padding: 5px 4px;
    gap: 2px;
  }

  .tool span {
    width: 20px;
    height: 20px;
    font-size: 16px;
  }

  .tool small {
    font-size: 7px;
  }

  .upgrade-strip {
    order: 2;
    display: none;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
    padding: 0;
  }

  body[data-mobile-panel="gear"] .upgrade-strip {
    display: grid;
  }

  .upgrade {
    min-height: 36px;
    grid-template-rows: 16px auto;
    padding: 4px 3px;
  }

  .upgrade span {
    width: 16px;
    height: 16px;
    font-size: 10px;
  }

  .upgrade b {
    font-size: 8px;
  }

  .upgrade small {
    display: none;
  }

  .readout {
    order: 2;
    display: none;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
  }

  body[data-mobile-panel="status"] .readout {
    display: grid;
  }

  .readout div {
    min-height: 32px;
    padding: 4px 6px;
  }

  .readout span {
    font-size: 7px;
  }

  .readout b {
    font-size: 13px;
  }

  .meters {
    display: none;
  }

  .toast {
    left: 50%;
    bottom: 108px;
    transform: translate(-50%, 8px);
  }

  body[data-mobile-panel="status"] .toast,
  body[data-mobile-panel="gear"] .toast,
  body[data-mobile-panel="crew"] .toast {
    bottom: 326px;
  }

  .toast.show {
    transform: translate(-50%, 0);
  }
}

@media (max-width: 460px) {
  .topbar {
    gap: 10px;
  }

  .topbar {
    grid-template-columns: 62px minmax(0, 1fr);
  }

  .eyebrow {
    font-size: 8px;
  }

  .stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .stats span {
    min-height: 36px;
    padding: 4px;
  }

  .right-panel {
    display: flex;
    gap: 5px;
  }

  .status-card b {
    font-size: 18px;
  }

  body[data-mobile-panel="crew"] .team-picker {
    left: auto;
    right: 6px;
    bottom: 108px;
    width: min(292px, calc(100vw - 12px));
    grid-template-columns: repeat(5, minmax(40px, 1fr));
  }

  body[data-mobile-panel="status"] .run-card,
  body[data-mobile-panel="status"] .contracts,
  body[data-mobile-panel="status"] .event-card {
    left: 6px;
    right: 6px;
  }

  .team-option {
    min-width: 0;
  }

  .commands {
    grid-template-columns: repeat(3, 28px);
  }

  body[data-mobile-panel="actions"] .commands {
    grid-template-columns: repeat(4, 28px);
  }

  .commands button {
    width: 28px;
  }

  .left-panel {
    left: 6px;
    right: 6px;
    bottom: 6px;
  }
}
