:root {
  color-scheme: dark;
  font-family: "Space Grotesk", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #191b30;
  color: #e8e9f4;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  width: 100%;
}

body.player-fullscreen {
  background: #191b30;
  overflow: hidden;
}

button {
  border: 1px solid #2f312f;
  background: #f7f4eb;
  color: #202020;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 10px 12px;
}

button:hover {
  background: #ffffff;
}

button:disabled {
  background: #d6d2c8;
  border-color: #9c9689;
  color: #777168;
  cursor: not-allowed;
}

button:disabled:hover {
  background: #d6d2c8;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1280px) minmax(280px, 300px);
  gap: 18px;
  margin: 0 auto;
  max-width: 1634px;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 18px;
  width: 100%;
}

body.player-fullscreen .app-shell {
  align-items: center;
  display: flex;
  justify-content: center;
  max-width: none;
  overflow: hidden;
  padding: 0;
  width: 100vw;
}

body.editor-active .app-shell {
  grid-template-columns: minmax(0, 1280px) minmax(360px, 520px);
  max-width: 1836px;
}

.game-panel,
.sidebar {
  min-width: 0;
}

body.player-fullscreen .game-panel {
  align-items: center;
  display: flex;
  height: 100vh;
  height: 100dvh;
  justify-content: center;
  overflow: hidden;
  width: 100vw;
}

.topbar {
  align-items: end;
  display: none;
  justify-content: space-between;
  margin-bottom: 10px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.1;
}

h2 {
  font-size: 15px;
  margin-bottom: 8px;
}

h3 {
  color: #3f4541;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

#levelName {
  color: #5f625d;
  margin-top: 3px;
}

.status-pill {
  background: #202020;
  color: #fff;
  font-weight: 800;
  min-width: 86px;
  padding: 8px 10px;
  text-align: center;
}

canvas {
  background: #c0a06c;
  border: 2px solid #2f312f;
  display: block;
  height: auto;
  max-width: 100%;
}

body.player-fullscreen .app-shell canvas {
  border: 0;
  max-width: none;
}

.sidebar {
  align-content: start;
  display: grid;
  gap: 14px;
}

body.player-fullscreen .sidebar {
  display: none;
}

body.tester-enabled .sidebar {
  align-self: start;
}

body.tester-enabled:not(.editor-active) .metric-grid,
body.tester-enabled:not(.editor-active) .tools,
body.tester-enabled:not(.editor-active) .upgrades,
body.tester-enabled:not(.editor-active) .controls {
  display: none;
}

body.upgrade-editor-enabled .app-shell {
  display: block;
  max-width: 1240px;
}

body.upgrade-editor-enabled .game-panel,
body.upgrade-editor-enabled .sidebar > :not(.upgrade-settings-panel) {
  display: none;
}

body.upgrade-editor-enabled .sidebar {
  display: block;
}

.metric-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
}

.metric {
  background: #f8f5eb;
  border: 1px solid #b7ad9a;
  padding: 10px;
}

.metric span {
  color: #5e5d58;
  display: block;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 4px;
  text-transform: uppercase;
}

.metric strong {
  font-size: 19px;
}

.canvas-moved {
  display: none;
}

.tools,
.editor-panel,
.tester-panel,
.upgrades,
.upgrade-settings-panel,
.controls {
  background: #f8f5eb;
  border: 1px solid #b7ad9a;
  padding: 12px;
}

.tools {
  display: none;
  gap: 8px;
}

.upgrades {
  display: grid;
  gap: 10px;
}

.upgrade-settings-panel {
  display: grid;
  gap: 10px;
}

.upgrade-settings-header {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto;
}

.upgrade-settings-form {
  overflow-x: auto;
}

.upgrade-settings-table {
  border-collapse: collapse;
  min-width: 960px;
  width: 100%;
}

.upgrade-settings-table th,
.upgrade-settings-table td {
  border-bottom: 1px solid #d0c7b6;
  font-size: 13px;
  line-height: 1.35;
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

.upgrade-settings-table th {
  color: #5e5d58;
  font-weight: 800;
  text-transform: uppercase;
}

.upgrade-settings-table input,
.upgrade-settings-export {
  border: 1px solid #b7ad9a;
  color: #202020;
  font: inherit;
  min-width: 0;
  padding: 8px;
}

.upgrade-settings-table input {
  width: 110px;
}

.upgrade-settings-table code {
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
}

.upgrade-settings-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: auto auto;
}

.upgrade-settings-status {
  color: #5e5d58;
  font-size: 13px;
  font-weight: 800;
  min-height: 18px;
}

.upgrade-settings-export {
  font-family: "Cascadia Mono", Consolas, monospace;
  resize: vertical;
  width: 100%;
}

.level-select {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.level-button {
  align-items: start;
  display: grid;
  gap: 6px;
  min-height: 86px;
  padding: 10px 11px;
  text-align: left;
}

.level-button-top {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.level-button-number {
  font-size: 18px;
  font-weight: 900;
}

.level-button-name {
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
  min-height: 30px;
}

.level-button-status {
  font-size: 18px;
}

.level-button.active {
  background: #1f6f64;
  color: #ffffff;
}

.level-button.locked {
  background: #e0dbcf;
  color: #7f796d;
}

.level-button.locked .level-button-status {
  opacity: 0.8;
}

.tool-button.active {
  background: #1f6f64;
  color: #ffffff;
}

.tool-button,
.speed-button,
#resetLevel {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
}

.material-symbols-outlined {
  direction: ltr;
  display: inline-block;
  font-family: "Material Symbols Outlined";
  font-size: 20px;
  font-style: normal;
  font-weight: normal;
  letter-spacing: normal;
  line-height: 1;
  text-transform: none;
  vertical-align: -4px;
  white-space: nowrap;
  word-wrap: normal;
}

.delete-icon {
  color: #c52a28;
}

.upgrade-selected {
  display: none;
  color: #202020;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.3;
}

.upgrade-details {
  display: none;
  color: #5e5d58;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  min-height: 34px;
}

.upgrade-actions {
  display: none;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
  margin-top: 8px;
}

.speed-button.active {
  background: #1f6f64;
  color: #ffffff;
}

.tester-speed-button.active {
  background: #1f6f64;
  color: #ffffff;
}

.controls {
  display: none;
  gap: 8px;
  grid-template-columns: 1fr;
}

.speed-controls {
  display: none;
  gap: 6px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.speed-button {
  gap: 4px;
  min-width: 0;
  padding-left: 6px;
  padding-right: 6px;
}

.tester-panel {
  align-items: start;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(280px, 300px));
}

.tester-column {
  align-content: start;
  display: grid;
  gap: 10px;
  min-width: 0;
}

.tester-subpanel {
  align-content: start;
  border-top: 1px solid #d0c7b6;
  display: grid;
  gap: 8px;
  padding-top: 10px;
}

.tester-speed-controls {
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.tester-speed-button {
  min-height: 40px;
  padding: 6px 8px;
}

.tester-toggle {
  align-items: center;
  display: flex;
  gap: 8px;
  font-size: 13px;
  font-weight: 800;
}

.tester-toggle input {
  height: 16px;
  width: 16px;
}

.tester-goal-estimate {
  border-collapse: collapse;
  font-size: 13px;
  width: 100%;
}

.tester-goal-estimate th,
.tester-goal-estimate td {
  border-top: 1px solid #d0c7b6;
  padding: 6px 0;
  text-align: left;
  vertical-align: top;
}

.tester-goal-estimate th {
  color: #5e5d58;
  font-weight: 700;
  padding-right: 10px;
  width: 44%;
}

.tester-goal-estimate td {
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.tester-goal-estimate td.ahead {
  color: #1f6f64;
  font-weight: 700;
}

.tester-goal-estimate td.behind {
  color: #9b2f25;
  font-weight: 700;
}

.editor-panel {
  display: grid;
  gap: 10px;
}

body.editor-active .metric-grid,
body.editor-active .tools,
body.editor-active .upgrades,
body.editor-active .controls {
  display: none;
}

.editor-header {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr minmax(180px, 1fr) auto;
}

.editor-title-stack {
  display: grid;
  gap: 4px;
}

.tester-mode-label {
  color: #5e5d58;
  display: none;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

body.tester-enabled .tester-mode-label {
  display: block;
}

.editor-level-picker {
  align-items: start;
  display: grid;
  gap: 4px;
  min-width: 0;
}

.editor-level-picker span {
  color: #5e5d58;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.editor-level-picker select {
  min-width: 0;
}

.editor-header button {
  justify-self: end;
}

.editor-body {
  display: grid;
  gap: 10px;
}

.editor-section-title {
  border-bottom: 1px solid #d0c7b6;
  color: #3f4541;
  font-size: 12px;
  font-weight: 900;
  padding-bottom: 4px;
  text-transform: uppercase;
}

.hidden {
  display: none !important;
}

.editor-tools,
.editor-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.editor-tool-button.active {
  background: #1f6f64;
  color: #ffffff;
}

.editor-form {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.editor-form label,
.resource-demand-fields label {
  display: grid;
  gap: 4px;
}

.editor-form span {
  color: #5e5d58;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.editor-form input,
.editor-form textarea,
.editor-global-upgrade-row input,
.resource-demand-fields input,
.editor-level-picker select,
.editor-export {
  border: 1px solid #b7ad9a;
  color: #202020;
  font: inherit;
  min-width: 0;
  padding: 8px;
}

.editor-form textarea {
  min-height: 74px;
  resize: vertical;
}

.editor-form .editor-form-wide {
  grid-column: 1 / -1;
}

.editor-form input[type="checkbox"] {
  height: 18px;
  padding: 0;
  width: 18px;
}

.editor-global-upgrades {
  display: grid;
  gap: 8px;
}

.editor-global-upgrade-row {
  align-items: center;
  border: 1px solid #d0c7b6;
  display: grid;
  gap: 8px;
  grid-template-columns: auto 1fr;
  padding: 8px;
}

.editor-global-upgrade-row > span:last-child {
  justify-self: end;
}

.editor-global-upgrade-row strong,
.editor-global-upgrade-row small {
  display: block;
}

.editor-global-upgrade-row small {
  color: #5e5d58;
  font-size: 11px;
  font-weight: 700;
  margin-top: 2px;
}

.editor-nodes {
  display: grid;
  gap: 8px;
}

.editor-node-row {
  align-items: center;
  border: 1px solid #d0c7b6;
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto;
  padding: 8px;
}

.editor-node-row strong,
.editor-node-row span {
  display: block;
}

.editor-node-row span {
  color: #5e5d58;
  font-size: 12px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.resource-demand-fields {
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.resource-demand-schedule {
  grid-column: 1 / -1;
  font-size: 11px;
  opacity: 0.75;
}

.modal.editor-node-modal {
  max-height: calc(100vh - 36px);
  max-width: 1100px;
  width: min(calc(100vw - 36px), 1100px);
}

.editor-node-resources {
  display: grid;
  gap: 8px;
  max-height: min(58vh, 560px);
  overflow: auto;
  padding-right: 4px;
}

.editor-node-resource-row {
  align-items: start;
  border: 1px solid #d0c7b6;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(140px, 0.65fr) minmax(0, 2.35fr);
  padding: 10px;
}

.editor-node-resource-row > .resource-demand-fields {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.editor-node-resource-row > .resource-demand-fields label {
  min-width: 0;
}

.editor-node-resource-row > .resource-demand-fields span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-node-resource-toggle {
  align-items: center;
  display: flex;
  gap: 8px;
}

.editor-node-resource-toggle input {
  height: 16px;
  width: 16px;
}

.editor-node-actions {
  grid-template-columns: 1fr 1fr 1fr;
}

.editor-status {
  color: #5e5d58;
  font-size: 13px;
  font-weight: 800;
  min-height: 18px;
}

.editor-status.error {
  color: #a7331e;
}

.editor-export {
  font-family: "Cascadia Mono", Consolas, monospace;
  min-height: 210px;
  resize: vertical;
  width: 100%;
}

.modal-overlay {
  align-items: center;
  background: rgba(19, 18, 16, 0.48);
  bottom: 0;
  display: flex;
  justify-content: center;
  left: 0;
  padding: 18px;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 10;
}

.modal-overlay.hidden {
  display: none;
}

/* The level menu, when opened as the title screen's Menu popup, sits above the
   title overlay (z-index 60) so it shows over the animated backdrop. */
.modal-overlay.above-title {
  z-index: 70;
}

.modal {
  background: #f8f5eb;
  border: 2px solid #2f312f;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.24);
  display: grid;
  gap: 12px;
  max-width: 360px;
  padding: 16px;
  width: min(100%, 360px);
}

.modal-header {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr auto;
}

.level-menu-modal {
  max-width: 420px;
  width: min(100%, 420px);
}

.level-menu-header-actions {
  display: flex;
  gap: 8px;
}
.level-menu-header-actions button.hidden {
  display: none;
}

.end-level-modal {
  max-width: 430px;
  width: min(100%, 430px);
}

.help-modal {
  max-width: 440px;
  width: min(100%, 440px);
}

.help-list {
  display: grid;
  gap: 11px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.help-list li {
  color: rgba(232, 233, 244, 0.82);
  font-size: 14px;
  line-height: 1.42;
  padding-left: 22px;
  position: relative;
}

.help-list li::before {
  background: #25cfa6;
  border-radius: 50%;
  content: "";
  height: 8px;
  left: 3px;
  position: absolute;
  top: 7px;
  width: 8px;
}

.help-list li strong {
  color: #e8e9f4;
}

.level-intro-modal {
  gap: 0;
  grid-template-columns: minmax(180px, 0.85fr) minmax(280px, 1.15fr);
  max-width: 760px;
  overflow: hidden;
  padding: 0;
  width: min(100%, 760px);
}

.level-intro-visual {
  align-content: center;
  background: #6f9653;
  border-right: 2px solid #2f312f;
  display: grid;
  gap: 12px;
  justify-items: center;
  min-height: 320px;
  padding: 22px;
}

.level-intro-track {
  align-items: center;
  background: rgba(248, 245, 235, 0.86);
  border: 1px solid rgba(29, 29, 29, 0.42);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(42px, 1fr));
  gap: 10px;
  padding: 12px;
  width: 100%;
}

.level-intro-track img {
  image-rendering: auto;
  justify-self: center;
  max-height: 44px;
  max-width: 44px;
}

.level-intro-content {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.level-intro-kicker {
  color: #5e5d58;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.06em;
  margin: 0;
  text-transform: uppercase;
}

.level-intro-text,
.level-intro-detail {
  color: #3f4541;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.35;
  margin: 0;
}

.level-intro-detail {
  background: #efe7d7;
  border: 1px solid #d0c7b6;
  padding: 10px;
}

.end-level-message {
  color: #3f4541;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.35;
}

.end-level-stats {
  border: 1px solid #d0c7b6;
  display: grid;
  gap: 7px;
  padding: 10px;
}

.end-level-stat {
  align-items: center;
  color: #202020;
  display: grid;
  font-size: 13px;
  font-weight: 800;
  gap: 10px;
  grid-template-columns: minmax(100px, auto) 1fr;
}

.end-level-stat span:first-child {
  color: #5e5d58;
  font-size: 11px;
  text-transform: uppercase;
}

.filter-options {
  display: grid;
  gap: 8px;
}

.filter-option {
  align-items: center;
  border: 1px solid #b7ad9a;
  cursor: pointer;
  display: flex;
  gap: 9px;
  padding: 8px;
}

.filter-option input {
  height: 16px;
  width: 16px;
}

.filter-error {
  color: #a7331e;
  font-size: 13px;
  font-weight: 800;
  min-height: 18px;
}

.modal-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

.test-runner-shell {
  display: grid;
  min-height: 100vh;
  padding: 18px;
}

.test-runner-panel {
  display: grid;
  gap: 14px;
  max-width: 1120px;
  width: 100%;
}

.test-controls {
  background: #f8f5eb;
  border: 1px solid #b7ad9a;
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto auto;
  padding: 12px;
}

.test-controls select {
  border: 1px solid #b7ad9a;
  color: #202020;
  font: inherit;
  min-width: 0;
  padding: 10px 12px;
}

.test-results {
  display: grid;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.test-result {
  background: #f8f5eb;
  border: 1px solid #b7ad9a;
  display: grid;
  gap: 8px;
  padding: 12px;
}

.test-result.passed {
  border-left: 5px solid #1f6f64;
}

.test-result.failed {
  border-left: 5px solid #a7331e;
}

.test-result pre,
.test-log {
  background: #202020;
  color: #f8f5eb;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
  margin: 0;
  overflow: auto;
  padding: 12px;
  white-space: pre-wrap;
}

.test-log {
  min-height: 220px;
}

#testSummary.error {
  background: #a7331e;
}

.test-game-fixture {
  height: 1px;
  left: -10000px;
  overflow: hidden;
  position: absolute;
  top: 0;
  width: 1px;
}

.test-runner-shell .modal-overlay {
  display: none !important;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body.editor-active .sidebar {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 10px;
  }

  .sidebar,
  .metric-grid,
  .editor-form,
  .editor-tools,
  .editor-actions,
  .resource-demand-fields,
  .editor-node-resource-row,
  .editor-node-resource-row > .resource-demand-fields,
  .editor-node-actions,
  .upgrade-actions,
  .test-controls {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 920px) {
  .modal.editor-node-modal {
    width: calc(100vw - 24px);
  }

  .editor-node-resource-row {
    grid-template-columns: 1fr;
  }

  .editor-node-resource-row > .resource-demand-fields {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .level-intro-modal {
    grid-template-columns: 1fr;
    max-height: calc(100vh - 24px);
    overflow: auto;
    width: calc(100vw - 24px);
  }

  .level-intro-visual {
    border-right: 0;
    border-bottom: 2px solid #2f312f;
    min-height: 150px;
  }
}

@media (max-width: 520px) {
  .editor-node-resource-row > .resource-demand-fields {
    grid-template-columns: 1fr;
  }
}

body.tester-enabled .app-shell {
  align-items: center;
  grid-template-columns: auto minmax(598px, 638px);
  justify-content: center;
  max-width: none;
  min-height: 100vh;
  min-height: 100dvh;
  width: fit-content;
}

body.tester-enabled .game-panel {
  align-items: center;
  display: flex;
  height: calc(100vh - 36px);
  height: calc(100dvh - 36px);
  justify-content: center;
  min-width: 0;
  overflow: hidden;
}

/* ------------------------------------------------------------------------
   "Minimal / coloured trains" restyle — dark-indigo override layer.
   Appended last so it wins over the legacy beige palette above without
   rewriting every rule. Palette: bg #191b30, panels #20223a/#2d3050,
   ink #e8e9f4, muted #7d80a3, train accents #ff5d6c/#25cfa6/#3d9bff.
   ------------------------------------------------------------------------ */

button {
  background: #2d3050;
  border: 1px solid #3a3e63;
  border-radius: 8px;
  color: #e8e9f4;
  font-weight: 600;
}

button:hover {
  background: #3a3e63;
}

button:disabled,
button:disabled:hover {
  background: #20223a;
  border-color: #2d3050;
  color: #7d80a3;
}

.status-pill {
  background: #2d3050;
  color: #e8e9f4;
}

.sidebar section,
.tools,
.upgrades,
.editor-panel,
.tester-panel,
.upgrade-settings-panel {
  background: #20223a;
  border-color: #2d3050;
  color: #e8e9f4;
}

.sidebar h2,
.sidebar h3 {
  color: #e8e9f4;
}

.sidebar span,
.upgrade-selected,
.upgrade-details,
.editor-status,
.editor-section-title {
  color: #7d80a3;
}

.sidebar input,
.sidebar select,
.sidebar textarea {
  background: #191b30;
  border: 1px solid #3a3e63;
  color: #e8e9f4;
}

.modal-overlay {
  background: rgba(11, 12, 24, 0.6);
}

.modal {
  background: #20223a;
  border: 1px solid #2d3050;
  border-radius: 14px;
  color: #e8e9f4;
}

.modal h2,
.modal h3 {
  color: #e8e9f4;
}

.level-intro-kicker,
.level-intro-detail,
.end-level-message {
  color: #7d80a3;
}

.level-intro-detail {
  background: #191b30;
}

.level-intro-visual {
  background: #191b30;
}

.level-intro-track {
  background: #2d3050;
}

.level-button {
  background: #2d3050;
  color: #e8e9f4;
}

.level-button.active {
  background: #e8e9f4;
  color: #191b30;
}

.level-button.locked {
  background: #20223a;
  color: #7d80a3;
}

.end-level-stat {
  color: #e8e9f4;
}

.end-level-stat span {
  color: #7d80a3;
}

.end-level-stats,
.filter-option {
  background: #191b30;
  border-color: #3a3e63;
  color: #e8e9f4;
}

.filter-error {
  color: #ff5d6c;
}

.metric,
.metric strong {
  background: #20223a;
  color: #e8e9f4;
}

.metric span {
  color: #7d80a3;
}

strong,
.end-level-stat,
.metric strong,
.tester-goal-estimate td {
  font-variant-numeric: tabular-nums;
}

.level-intro-modal {
  display: block;
  max-width: 620px;
}

.level-intro-text {
  color: #e8e9f4;
}

/* --- Visual level editor (?editor=1) ------------------------------------- */
body.level-editor-active { background: #12131f; overflow: hidden; }
body.level-editor-active .app-shell { display: none; }

.level-editor { color: #e8e9f4; font-family: "Space Grotesk", system-ui; }
.level-editor.hidden { display: none; }

.le-layout { display: grid; grid-template-columns: 1fr 360px; height: 100vh; height: 100dvh; }
.le-map { overflow: auto; padding: 16px; display: flex; align-items: flex-start; justify-content: center; background: #12131f; }
.le-canvas { background: #191b30; border: 1px solid #2f3350; border-radius: 4px; }

.le-panel { background: #20223a; border-left: 1px solid #2f3350; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.le-title { font-size: 16px; margin: 0; }
.le-field { display: grid; gap: 4px; }
.le-field > span { color: #7d80a3; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.le-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.le-input { background: #12131f; border: 1px solid #3a3e63; color: #e8e9f4; padding: 7px 8px; font: inherit; border-radius: 3px; width: 100%; }
.le-input-sm { padding: 4px 6px; width: 56px; }
.le-select { background: #12131f; border: 1px solid #3a3e63; color: #e8e9f4; padding: 7px 8px; font: inherit; border-radius: 3px; width: 100%; }

.le-section-head { display: flex; align-items: baseline; justify-content: space-between; margin-top: 6px; }
.le-section-head h3 { color: #e8e9f4; font-size: 12px; text-transform: uppercase; margin: 0; }
.le-hint { color: #7d80a3; font-size: 10px; }
.le-empty { color: #7d80a3; font-size: 12px; font-style: italic; }

.le-list { display: flex; flex-direction: column; gap: 4px; max-height: 40vh; overflow-y: auto; }
.le-city { display: flex; align-items: center; gap: 6px; background: #12131f; border: 1px solid #2f3350; border-radius: 3px; padding: 4px 6px; }
.le-num { background: #25cfa6; color: #191b30; font-weight: 700; font-size: 11px; min-width: 18px; height: 18px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; }
.le-city-name { flex: 1; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.le-gap { display: flex; align-items: center; gap: 3px; color: #7d80a3; font-size: 10px; }
.le-icon { background: #2d3050; border: 0; color: #e8e9f4; width: 22px; height: 22px; border-radius: 3px; cursor: pointer; font-size: 13px; line-height: 1; padding: 0; }
.le-icon:hover { background: #3a3e63; }
.le-icon-x { color: #ff8f9c; }

.le-unlocks { display: flex; flex-direction: column; gap: 4px; }
.le-unlock { display: grid; grid-template-columns: 1.5fr repeat(4, 1fr) 26px; gap: 4px; align-items: center; }
.le-unlock .le-input-sm { width: 100%; }
.le-unlock-head span { color: #7d80a3; font-size: 10px; text-align: center; text-transform: uppercase; }

.le-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.le-btn { background: #2d3050; border: 1px solid #3a3e63; color: #e8e9f4; padding: 8px 12px; font: inherit; font-weight: 600; border-radius: 3px; cursor: pointer; }
.le-btn:hover { background: #3a3e63; }
.le-btn-primary { background: #25cfa6; border-color: #25cfa6; color: #10241d; }
.le-btn-primary:hover { background: #4fe0bd; }
.le-btn-sm { padding: 5px 9px; font-size: 12px; align-self: flex-start; }
.le-status { color: #25cfa6; font-size: 11px; min-height: 14px; margin: 0; }

.le-export-overlay { position: fixed; inset: 0; background: rgba(10,11,20,0.7); display: flex; align-items: center; justify-content: center; z-index: 50; }
.le-export { background: #20223a; border: 1px solid #3a3e63; border-radius: 6px; padding: 16px; width: min(680px, 90vw); display: flex; flex-direction: column; gap: 10px; }
.le-export h3 { margin: 0; font-size: 14px; }
.le-export-text { width: 100%; height: 50vh; background: #12131f; border: 1px solid #3a3e63; color: #cfd2ea; font-family: ui-monospace, monospace; font-size: 12px; padding: 8px; border-radius: 3px; resize: none; }

/* --- Volume sliders in the level menu ------------------------------------ */
.audio-controls {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid #3a3e63;
  display: grid;
  gap: 10px;
}
.audio-controls h3 {
  color: #7d80a3;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0;
}
.audio-slider {
  display: grid;
  grid-template-columns: 30px 40px 1fr 44px;
  align-items: center;
  gap: 10px;
}
.audio-slider-name {
  color: #e8e9f4;
  font-size: 13px;
  font-weight: 600;
}
.audio-mute {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid #3a3e63;
  border-radius: 7px;
  background: #20223a;
  color: #e8e9f4;
  cursor: pointer;
}
.audio-mute:hover {
  background: #2d3050;
}
.audio-mute .material-symbols-outlined {
  font-size: 18px;
}
.audio-mute.muted {
  color: #ff5d6c;
  border-color: rgba(255, 93, 108, 0.55);
}
.hints-control {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #3a3e63;
}
.hints-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  color: #e8e9f4;
  font-size: 13px;
  font-weight: 600;
}
.hints-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: #25cfa6;
  cursor: pointer;
}
.audio-slider input[type="range"] {
  width: 100%;
  accent-color: #25cfa6;
  cursor: pointer;
}
.audio-slider output {
  color: #7d80a3;
  font-size: 12px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* --- Title / attract screen ---------------------------------------------- */
.title-screen {
  position: fixed;
  inset: 0;
  z-index: 60;
  overflow: hidden;
  background: #191b30;
  display: flex;
  align-items: center;
  justify-content: center;
}
.title-screen.hidden {
  display: none;
}
/* Live backdrop: the real game (attract level) renders behind the title, so the
   overlay is transparent and its own canvas is hidden. The veil still darkens the
   centre for legibility. */
body.title-live .title-screen {
  background: transparent;
}
body.title-live #titleCanvas {
  display: none;
}
#titleCanvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}
/* Darken the animated backdrop toward the centre so the title stays legible. */
.title-veil {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(60% 55% at 50% 46%, rgba(19, 21, 48, 0.86) 0%, rgba(19, 21, 48, 0.5) 45%, rgba(19, 21, 48, 0.12) 100%),
    linear-gradient(180deg, rgba(19, 21, 48, 0.55) 0%, rgba(19, 21, 48, 0.1) 30%, rgba(19, 21, 48, 0.1) 70%, rgba(19, 21, 48, 0.6) 100%);
}
.title-main {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: 24px;
}
.title-main.title-hidden {
  display: none;
}
.title-kicker {
  margin: 0;
  color: #25cfa6;
  font-size: clamp(11px, 1.6vw, 14px);
  font-weight: 600;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  padding-left: 0.42em;
}
.title-name {
  margin: 4px 0 2px;
  color: #f2f3fb;
  font-size: clamp(38px, 8vw, 92px);
  font-weight: 700;
  line-height: 1.02;
  letter-spacing: -0.01em;
  text-shadow: 0 6px 40px rgba(0, 0, 0, 0.55);
}
.title-tagline {
  margin: 0 0 22px;
  color: #b9bbd6;
  font-size: clamp(13px, 1.9vw, 17px);
  max-width: 30ch;
}
.title-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(280px, 78vw);
}
.title-btn {
  border: 1px solid rgba(146, 150, 190, 0.45);
  border-radius: 12px;
  background: rgba(32, 34, 58, 0.72);
  color: #e8e9f4;
  font-weight: 600;
  font-size: 16px;
  padding: 13px 16px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: background 120ms ease, border-color 120ms ease, transform 80ms ease;
}
.title-btn:hover {
  background: rgba(58, 62, 108, 0.85);
  border-color: rgba(180, 184, 220, 0.7);
}
.title-btn:active {
  transform: translateY(1px);
}
.title-btn-primary {
  background: #f2f3fb;
  border-color: #f2f3fb;
  color: #191b30;
  font-weight: 700;
}
.title-btn-primary:hover {
  background: #ffffff;
  border-color: #ffffff;
}
.title-credits {
  position: relative;
  z-index: 1;
  width: min(420px, 88vw);
  background: rgba(24, 26, 48, 0.9);
  border: 1px solid rgba(146, 150, 190, 0.4);
  border-radius: 16px;
  padding: 24px 26px 22px;
  backdrop-filter: blur(8px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.title-credits.hidden {
  display: none;
}
.title-credits h2 {
  margin: 0 0 16px;
  color: #f2f3fb;
  font-size: 22px;
}
.title-credit-list {
  margin: 0 0 20px;
  display: grid;
  gap: 12px;
}
.title-credit-list > div {
  display: grid;
  grid-template-columns: 42% 1fr;
  gap: 10px;
  align-items: baseline;
}
.title-credit-list dt {
  color: #7d80a3;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.title-credit-list dd {
  margin: 0;
  color: #e8e9f4;
  font-size: 14px;
  font-weight: 600;
}
.title-credits .title-btn {
  width: 100%;
}

/* --- Tutorial coach panel (floats over the canvas, never blocks it) ------- */
.game-panel {
  position: relative;
}
.tutorial-panel {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 8;
  width: min(560px, 92%);
  padding: 12px 16px;
  border: 1px solid rgba(37, 207, 166, 0.55);
  border-radius: 12px;
  background: rgba(25, 27, 48, 0.95);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.45);
  color: #e8e9f4;
  pointer-events: none; /* clicks/drags pass through to the map beneath */
}
.tutorial-panel.hidden {
  display: none;
}
.tutorial-panel .tutorial-step {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
  color: #25cfa6;
}
.tutorial-panel .tutorial-title {
  margin-top: 2px;
  font-size: 18px;
  font-weight: 700;
}
.tutorial-panel .tutorial-text {
  margin-top: 4px;
  font-size: 14px;
  line-height: 1.35;
  color: #c7c9de;
}
.tutorial-panel.is-complete {
  border-color: rgba(37, 207, 166, 0.9);
}
.tutorial-next {
  pointer-events: auto; /* the panel is click-through; this button is not */
  margin-top: 10px;
  padding: 8px 14px;
  border: 0;
  border-radius: 8px;
  background: #25cfa6;
  color: #10121f;
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
.tutorial-next:hover {
  background: #3ee0ba;
}
.tutorial-next.hidden {
  display: none;
}
