:root {
  color-scheme: dark;
  --ink: #02080b;
  --panel: rgba(5, 17, 22, 0.94);
  --panel-soft: rgba(8, 25, 31, 0.82);
  --line: rgba(104, 155, 163, 0.26);
  --line-bright: rgba(126, 192, 199, 0.56);
  --text: #dbe7e5;
  --muted: #789398;
  --faint: #47636a;
  --warm: #dfa35b;
  --warm-soft: #a96336;
  --red: #c75d4b;
  --cyan: #7fd5d5;
  --uv: #a887e8;
  font-family: "Arial Narrow", "Avenir Next Condensed", "Segoe UI", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink);
  color: var(--text);
}

body {
  position: relative;
  user-select: none;
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 2px solid var(--warm);
  outline-offset: 3px;
}

#game {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: var(--ink);
}

.screen,
.overlay,
.hud {
  position: fixed;
  inset: 0;
}

.screen {
  z-index: 10;
}

.is-hidden {
  display: none !important;
}

.kicker,
.panel-label {
  margin: 0;
  color: var(--warm);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.title-screen {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(290px, 420px);
  align-items: end;
  gap: clamp(32px, 7vw, 110px);
  padding: clamp(28px, 6vw, 84px);
  background:
    linear-gradient(90deg, rgba(2, 8, 11, 0.24), rgba(2, 8, 11, 0.04) 50%, rgba(2, 8, 11, 0.5)),
    linear-gradient(0deg, rgba(2, 8, 11, 0.86), transparent 58%);
}

.title-copy {
  max-width: 760px;
}

.title-copy h1 {
  margin: 15px 0 20px;
  color: #e9eee9;
  font-size: clamp(64px, 11vw, 154px);
  font-weight: 900;
  letter-spacing: -0.065em;
  line-height: 0.72;
  text-shadow: 0 2px 38px rgba(0, 0, 0, 0.6);
}

.title-copy h1 span {
  color: var(--warm);
  font-size: 0.57em;
  letter-spacing: 0.24em;
}

.title-lede {
  max-width: 610px;
  margin: 0;
  color: #aabcb9;
  font-family: Georgia, serif;
  font-size: clamp(16px, 2vw, 21px);
  line-height: 1.55;
}

.title-actions,
.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 28px;
}

button.primary,
button.quiet,
button.danger,
.icon-button {
  min-height: 43px;
  padding: 0 17px;
  border: 1px solid var(--line);
  border-radius: 2px;
  color: var(--text);
  background: rgba(5, 17, 22, 0.9);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

button.primary {
  border-color: #e8b36e;
  color: #071014;
  background: var(--warm);
}

button.primary:hover {
  background: #f2bd77;
}

button.quiet:hover,
.icon-button:hover {
  border-color: var(--line-bright);
  background: rgba(13, 37, 43, 0.95);
}

button.danger {
  color: #e18b7d;
  border-color: rgba(199, 93, 75, 0.56);
}

.icon-button {
  min-height: 34px;
  padding: 0 11px;
  color: var(--muted);
  font-size: 10px;
}

.save-summary {
  min-height: 1.2em;
  margin: 13px 0 0;
  color: var(--faint);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.controls-card {
  align-self: end;
  width: 100%;
  padding: 22px;
  border-top: 1px solid var(--warm-soft);
  background: rgba(4, 14, 18, 0.84);
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(12px);
}

.control-grid {
  display: grid;
  grid-template-columns: minmax(145px, 1.5fr) 1fr;
  gap: 9px 16px;
  margin-top: 17px;
  color: var(--muted);
  font-size: 11px;
}

.control-grid strong {
  color: #afc3c1;
  font-weight: 700;
}

kbd {
  display: inline-grid;
  min-width: 20px;
  min-height: 19px;
  place-items: center;
  padding: 1px 5px;
  border: 1px solid rgba(119, 158, 164, 0.36);
  border-radius: 2px;
  color: #c3d3d1;
  background: rgba(14, 37, 43, 0.7);
  font: 700 10px/1.2 ui-monospace, monospace;
  box-shadow: inset 0 -1px rgba(0, 0, 0, 0.4);
}

.control-note {
  margin: 18px 0 0;
  color: var(--faint);
  font: italic 12px/1.5 Georgia, serif;
}

.base-screen {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  padding: clamp(16px, 3vw, 36px);
  background:
    linear-gradient(100deg, rgba(3, 10, 13, 0.99) 0%, rgba(4, 14, 17, 0.94) 56%, rgba(4, 11, 13, 0.74) 100%),
    repeating-linear-gradient(90deg, transparent 0 80px, rgba(223, 163, 91, 0.025) 81px 82px);
}

.base-screen::after {
  position: absolute;
  right: 5vw;
  bottom: -25vh;
  width: 38vw;
  height: 66vh;
  border: 1px solid rgba(223, 163, 91, 0.16);
  border-radius: 50% 50% 0 0;
  background: radial-gradient(ellipse at center, rgba(29, 72, 77, 0.23), rgba(1, 6, 8, 0.96) 68%);
  content: "";
  pointer-events: none;
}

.base-header {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.base-header h2 {
  margin: 5px 0 0;
  font-size: clamp(25px, 4vw, 46px);
  letter-spacing: 0.04em;
}

.base-readouts {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: clamp(12px, 3vw, 36px);
}

.base-readouts span {
  display: grid;
  gap: 4px;
}

.base-readouts small,
.launch-stat small {
  color: var(--faint);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.base-readouts strong {
  color: #bed0ce;
  font: 700 15px/1 ui-monospace, monospace;
}

.base-nav {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 2px;
  overflow-x: auto;
  padding: 13px 0 16px;
  scrollbar-width: none;
}

.base-nav::-webkit-scrollbar {
  display: none;
}

.base-nav button {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 14px;
  border: 0;
  border-bottom: 1px solid transparent;
  color: var(--faint);
  background: transparent;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
}

.base-nav button:hover,
.base-nav button.active {
  color: var(--warm);
  border-bottom-color: var(--warm);
}

.base-panel {
  position: relative;
  z-index: 1;
  min-height: 0;
  overflow: auto;
  padding: 6px 8px 50px 0;
  scrollbar-color: var(--faint) transparent;
}

.panel-intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 340px);
  gap: 32px;
  max-width: 1120px;
}

.panel-intro h3,
.section-title {
  margin: 7px 0 10px;
  color: #d9e3e1;
  font-size: clamp(28px, 5vw, 54px);
  line-height: 1;
  letter-spacing: -0.025em;
}

.panel-intro p,
.panel-copy,
.upgrade-card p,
.craft-card p,
.codex-card p,
.log-entry p {
  color: var(--muted);
  font-family: Georgia, serif;
  font-size: 13px;
  line-height: 1.62;
}

.objective-card {
  align-self: start;
  padding: 20px;
  border-left: 2px solid var(--warm);
  background: rgba(10, 27, 31, 0.7);
}

.objective-card strong {
  display: block;
  margin: 7px 0;
  color: #c7d5d2;
  font-size: 16px;
}

.launch-stats,
.ending-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 28px 0;
}

.launch-stat,
.ending-stats span {
  display: grid;
  gap: 7px;
  min-height: 70px;
  padding: 13px;
  border: 1px solid var(--line);
  background: rgba(8, 25, 30, 0.58);
}

.launch-stat strong,
.ending-stats strong {
  color: #c6d6d3;
  font: 700 18px/1 ui-monospace, monospace;
}

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

.loadout-note {
  max-width: 700px;
  margin: 12px 0 0;
  color: var(--faint);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.6;
  text-transform: uppercase;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(245px, 1fr));
  gap: 10px;
  max-width: 1180px;
  margin-top: 22px;
}

.upgrade-card,
.craft-card,
.codex-card {
  position: relative;
  min-height: 192px;
  padding: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(145deg, rgba(9, 28, 34, 0.86), rgba(5, 15, 19, 0.8));
}

.upgrade-card.done {
  border-color: rgba(95, 151, 134, 0.34);
  background: rgba(8, 24, 26, 0.58);
}

.card-kicker {
  color: var(--warm);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.upgrade-card h4,
.craft-card h4,
.codex-card h4 {
  margin: 7px 0;
  color: #cbd9d6;
  font-size: 17px;
  letter-spacing: 0.02em;
}

.cost-line {
  min-height: 32px;
  margin: 14px 0 12px;
  color: #8fabaa;
  font: 700 10px/1.55 ui-monospace, monospace;
  text-transform: uppercase;
}

.cost-line .missing {
  color: #c46d5c;
}

.card-action {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--warm-soft);
  border-radius: 2px;
  color: var(--warm);
  background: rgba(4, 13, 16, 0.72);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
}

.card-action:disabled {
  border-color: var(--line);
  color: var(--faint);
  cursor: not-allowed;
  opacity: 0.65;
}

.codex-card {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  gap: 14px;
  min-height: 225px;
}

.codex-card.unknown {
  opacity: 0.56;
}

.codex-card canvas {
  width: 84px;
  height: 84px;
  border: 1px solid var(--line);
  background: #030b0e;
}

.behavior-list {
  display: grid;
  gap: 4px;
  margin-top: 12px;
}

.behavior-list span {
  color: #7fa09f;
  font-size: 10px;
  line-height: 1.45;
}

.behavior-list span::before {
  margin-right: 6px;
  color: var(--warm);
  content: "◇";
}

.behavior-list .unknown-note {
  color: #425b60;
}

.log-list {
  display: grid;
  gap: 2px;
  max-width: 900px;
  margin-top: 22px;
}

.log-entry {
  display: grid;
  grid-template-columns: 90px minmax(0, 1fr);
  gap: 18px;
  padding: 18px 0;
  border-top: 1px solid var(--line);
}

.log-entry time {
  color: var(--warm-soft);
  font: 700 10px/1.4 ui-monospace, monospace;
}

.log-entry h4 {
  margin: 0 0 6px;
  color: #b9cbc8;
  font-size: 14px;
}

.log-entry p {
  margin: 0;
}

.hud {
  z-index: 20;
  pointer-events: none;
}

.readout-stack,
.depth-stack,
.cargo-stack {
  position: absolute;
  top: 18px;
}

.readout-stack {
  left: 18px;
  display: grid;
  gap: 5px;
  width: min(220px, 27vw);
}

.instrument {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  padding: 8px 10px;
  border-left: 1px solid var(--line-bright);
  background: linear-gradient(90deg, rgba(2, 11, 14, 0.8), transparent);
  text-shadow: 0 1px 6px #000;
}

.instrument span,
.depth-stack span,
.cargo-stack span {
  color: #6e9194;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.13em;
}

.instrument strong {
  color: #c0d3d1;
  font: 700 11px/1 ui-monospace, monospace;
}

.instrument i {
  grid-column: 1 / -1;
  display: block;
  height: 2px;
  background: rgba(68, 104, 108, 0.3);
}

.instrument i b {
  display: block;
  width: 100%;
  height: 100%;
  background: #80bfc0;
  box-shadow: 0 0 6px #5b9c9e;
  transform-origin: left;
}

.instrument.signature i b {
  background: var(--warm);
  box-shadow: 0 0 7px var(--warm-soft);
}

.depth-stack {
  left: 50%;
  display: grid;
  justify-items: center;
  width: 160px;
  transform: translateX(-50%);
}

.depth-stack strong {
  margin-top: 4px;
  color: #c8d7d4;
  font: 700 20px/1 ui-monospace, monospace;
  text-shadow: 0 2px 8px #000;
}

.depth-stack small {
  margin-top: 6px;
  color: #5d7b80;
  font: 700 8px/1 ui-monospace, monospace;
}

.depth-track {
  position: relative;
  width: 150px;
  height: 3px;
  margin-top: 10px;
  background: linear-gradient(90deg, #536f74, #16333a);
}

.depth-track i,
.depth-track b {
  position: absolute;
  top: -3px;
  width: 1px;
  height: 9px;
  background: #d7e5e2;
}

.depth-track b {
  background: var(--red);
}

.depth-track em {
  position: absolute;
  top: -7px;
  right: -3px;
  color: var(--warm);
  font: normal 11px/1 sans-serif;
}

.cargo-stack {
  right: 18px;
  display: grid;
  justify-items: end;
  gap: 5px;
  text-align: right;
}

.cargo-stack strong {
  color: var(--warm);
  font: 700 15px/1 ui-monospace, monospace;
  letter-spacing: 0.1em;
}

.cargo-stack small {
  color: #658084;
  font: 700 8px/1.4 ui-monospace, monospace;
}

.mode-strip {
  position: absolute;
  bottom: 17px;
  left: 50%;
  display: flex;
  gap: 3px;
  transform: translateX(-50%);
  pointer-events: auto;
}

.mode-strip button {
  min-width: 74px;
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid rgba(73, 111, 116, 0.3);
  color: #516e73;
  background: rgba(2, 10, 13, 0.72);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.mode-strip button.active {
  border-color: var(--warm-soft);
  color: var(--warm);
  background: rgba(28, 21, 15, 0.82);
}

.mode-strip button:disabled {
  color: #283e42;
  border-color: rgba(47, 71, 75, 0.18);
}

.mode-strip kbd {
  min-width: 15px;
  min-height: 15px;
  padding: 0 3px;
  border-color: currentColor;
  color: inherit;
  background: transparent;
  font-size: 8px;
}

.mission-message,
.dock-prompt {
  position: absolute;
  left: 50%;
  margin: 0;
  padding: 7px 12px;
  border-left: 1px solid var(--warm-soft);
  color: #a9bcb9;
  background: rgba(3, 13, 16, 0.7);
  font: 700 10px/1.4 ui-monospace, monospace;
  letter-spacing: 0.07em;
  text-align: center;
  text-transform: uppercase;
  transform: translateX(-50%);
  transition: opacity 0.25s;
}

.mission-message {
  bottom: 58px;
  opacity: 0;
}

.mission-message.visible {
  opacity: 1;
}

.dock-prompt {
  top: 92px;
  color: var(--warm);
}

.fps-readout {
  position: absolute;
  right: 18px;
  bottom: 18px;
  color: rgba(80, 111, 115, 0.48);
  font: 700 8px/1 ui-monospace, monospace;
}

.overlay {
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(1, 6, 8, 0.72);
  backdrop-filter: blur(10px);
}

.overlay-card {
  width: min(560px, 100%);
  padding: clamp(24px, 5vw, 42px);
  border-top: 1px solid var(--warm);
  background: rgba(5, 17, 21, 0.97);
  box-shadow: 0 30px 100px #000;
}

.overlay-card h2 {
  margin: 9px 0 15px;
  color: #d4e0dd;
  font-size: clamp(30px, 6vw, 52px);
  line-height: 1;
}

.overlay-card > p:not(.panel-label) {
  color: var(--muted);
  font: 14px/1.65 Georgia, serif;
}

.control-grid.compact {
  margin: 22px 0 8px;
}

.tether-line {
  position: relative;
  height: 54px;
  margin: 22px 0;
  overflow: hidden;
  border-inline: 1px solid var(--line);
}

.tether-line::before {
  position: absolute;
  top: 26px;
  left: 0;
  width: 100%;
  height: 1px;
  background: var(--line);
  content: "";
}

.tether-line i {
  position: absolute;
  top: 19px;
  width: 14px;
  height: 14px;
  border: 1px solid var(--warm);
  background: #17282b;
  animation: tether 2.8s ease-in-out infinite;
}

@keyframes tether {
  from { left: 0; }
  to { left: calc(100% - 14px); }
}

.ending-screen {
  z-index: 60;
  overflow: auto;
  background: rgba(0, 4, 6, 0.92);
}

.ending-light {
  position: fixed;
  bottom: -16vh;
  left: 50%;
  width: min(1100px, 130vw);
  height: 65vh;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(223, 163, 91, 0.2), rgba(34, 75, 77, 0.09) 32%, transparent 68%);
  transform: translateX(-50%);
  animation: first-light 8s ease-out both;
}

@keyframes first-light {
  from { opacity: 0; transform: translateX(-50%) scale(0.12); }
  to { opacity: 1; transform: translateX(-50%) scale(1); }
}

.ending-copy {
  position: relative;
  z-index: 1;
  width: min(820px, 100%);
  margin: auto;
  padding: max(42px, 7vh) 24px;
  text-align: center;
}

.ending-copy h2 {
  margin: 10px 0 22px;
  color: #e2e9e5;
  font: 400 clamp(42px, 8vw, 84px)/1 Georgia, serif;
}

.ending-log {
  max-width: 680px;
  margin: 0 auto;
  color: #9fb1ae;
  font: 16px/1.8 Georgia, serif;
}

.ending-stats {
  margin-top: 34px;
  text-align: left;
}

.ending-stats small {
  color: var(--faint);
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.title-card {
  display: grid;
  gap: 7px;
  margin: 34px 0 25px;
  color: var(--warm);
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 0.14em;
}

.title-card span {
  color: var(--faint);
  font-size: 8px;
  letter-spacing: 0.4em;
}

.toast {
  position: fixed;
  z-index: 100;
  right: 20px;
  bottom: 20px;
  max-width: min(390px, calc(100vw - 40px));
  padding: 12px 15px;
  border-left: 2px solid var(--warm);
  color: #b9cbc8;
  background: rgba(4, 16, 20, 0.96);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  font: 700 10px/1.5 ui-monospace, monospace;
  letter-spacing: 0.05em;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: 0.22s ease;
}

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

@media (max-width: 760px) {
  .title-screen {
    grid-template-columns: 1fr;
    align-items: end;
    gap: 22px;
    overflow: auto;
    padding: 26px 18px;
  }

  .title-copy h1 {
    margin-block: 10px 15px;
    font-size: clamp(58px, 20vw, 98px);
  }

  .title-lede {
    font-size: 15px;
  }

  .controls-card {
    padding: 15px;
  }

  .control-grid {
    gap: 6px 10px;
  }

  .base-header {
    align-items: start;
  }

  .base-readouts span:nth-child(n + 3) {
    display: none;
  }

  .panel-intro {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .launch-stats,
  .ending-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .readout-stack {
    top: 10px;
    left: 9px;
    width: 150px;
  }

  .instrument {
    padding: 6px 8px;
  }

  .depth-stack {
    top: 10px;
    left: auto;
    right: 9px;
    width: 130px;
    transform: none;
  }

  .depth-track {
    width: 120px;
  }

  .cargo-stack {
    top: 115px;
    right: 9px;
  }

  .mode-strip {
    bottom: 8px;
    width: calc(100% - 16px);
  }

  .mode-strip button {
    flex: 1;
    min-width: 0;
    padding-inline: 3px;
  }

  .mission-message {
    bottom: 47px;
    width: min(88%, 420px);
  }

  .fps-readout {
    display: none;
  }

  .codex-card {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .codex-card canvas {
    width: 64px;
    height: 64px;
  }
}

@media (max-height: 640px) {
  .title-screen {
    align-items: center;
    padding-block: 20px;
  }

  .title-copy h1 {
    font-size: clamp(56px, 15vh, 100px);
  }

  .controls-card {
    max-height: calc(100vh - 40px);
    overflow: auto;
  }

  .base-screen {
    padding-block: 12px;
  }
}

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