:root {
  color-scheme: dark;
  --bg: #070a0c;
  --panel: #0d1214;
  --panel-strong: #12191c;
  --ink: #e7f0ec;
  --muted: #8fa19d;
  --dim: #52605e;
  --line: #203033;
  --line-hot: #1f5d5d;
  --signal: #47e0c3;
  --warning: #d5a649;
  --danger: #d76f5f;
  --blue: #83a8c6;
  --shadow: rgba(0, 0, 0, 0.35);
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(71, 224, 195, 0.07), transparent 34rem),
    radial-gradient(circle at 80% 0%, rgba(131, 168, 198, 0.12), transparent 28rem),
    var(--bg);
  color: var(--ink);
}

button,
a {
  font: inherit;
}

.corebound-shell {
  width: min(1180px, calc(100vw - 24px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 0 22px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
}

.topline {
  display: grid;
  grid-template-columns: minmax(116px, 1fr) auto minmax(116px, 1fr);
  align-items: end;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(13, 18, 20, 0.88);
  box-shadow: 0 18px 60px var(--shadow);
  padding: 14px;
}

.backlink {
  color: var(--muted);
  text-decoration: none;
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0;
}

.backlink:focus-visible,
.backlink:hover {
  color: var(--signal);
}

.identity {
  text-align: center;
}

.eyebrow,
.run-state,
.readout span,
.ledger-head span {
  display: block;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.68rem;
  letter-spacing: 0;
}

h1 {
  margin: 2px 0 0;
  font-size: clamp(1.7rem, 4vw, 3.8rem);
  line-height: 0.95;
  letter-spacing: 0;
  font-weight: 600;
}

.run-state {
  justify-self: end;
  border: 1px solid var(--line-hot);
  border-radius: 4px;
  color: var(--signal);
  padding: 7px 9px;
  background: rgba(71, 224, 195, 0.06);
}

.header-actions {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-actions .run-state {
  justify-self: auto;
}

.help-toggle {
  width: 38px;
  height: 34px;
  border: 1px solid var(--line-hot);
  border-radius: 4px;
  background: rgba(71, 224, 195, 0.08);
  color: var(--signal);
  cursor: pointer;
}

.help-toggle:focus-visible,
.help-toggle:hover {
  background: rgba(71, 224, 195, 0.16);
}

.playfield {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 14px;
  align-items: stretch;
}

.viewport-frame,
.hud {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(13, 18, 20, 0.9);
  box-shadow: 0 18px 60px var(--shadow);
}

.viewport-frame {
  min-height: 420px;
  height: min(72vh, 680px);
  display: grid;
  padding: 10px;
  position: relative;
  overflow: hidden;
}

.viewport-frame::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px solid rgba(71, 224, 195, 0.16);
  pointer-events: none;
}

#corebound-canvas {
  width: 100%;
  height: 100%;
  min-height: 420px;
  display: block;
  background: #050708;
}

.hud {
  min-width: 0;
  padding: 12px;
  display: grid;
  grid-template-rows: auto auto auto auto auto auto auto auto minmax(150px, 1fr) auto auto;
  gap: 12px;
}

.meter-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.readout,
.resource-ledger,
.objective-panel,
.contract-panel,
.charter-panel,
.route-panel,
.archive-panel,
.facility-panel,
.surface-panel,
.signal-log {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel-strong);
}

.readout {
  min-height: 74px;
  padding: 10px;
  display: grid;
  align-content: space-between;
}

.readout strong {
  font-size: clamp(1rem, 1.8vw, 1.25rem);
  font-weight: 600;
  color: var(--ink);
}

.readout .meter-label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud-icon {
  width: 18px;
  height: 18px;
  display: inline-block;
  flex: 0 0 auto;
  background-image: url("assets/hud/hud-icon-atlas.png");
  background-size: 90px 18px;
  background-repeat: no-repeat;
  image-rendering: auto;
}

.hud-icon-hull {
  background-position: 0 0;
}

.hud-icon-energy {
  background-position: -18px 0;
}

.hud-icon-heat {
  background-position: -36px 0;
}

.hud-icon-cargo {
  background-position: -54px 0;
}

.hud-icon-depth {
  background-position: -72px 0;
}

.resource-ledger,
.objective-panel,
.contract-panel,
.charter-panel,
.route-panel,
.archive-panel,
.facility-panel,
.surface-panel {
  min-height: 150px;
  padding: 10px;
  overflow: hidden;
}

.contract-panel,
.charter-panel,
.route-panel,
.archive-panel,
.objective-panel,
.facility-panel {
  min-height: 0;
}

.surface-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 9px;
}

.surface-scene {
  border: 1px solid rgba(71, 224, 195, 0.2);
  background: #071011;
  aspect-ratio: 4 / 1;
  min-height: 52px;
  overflow: hidden;
}

.surface-scene img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.ledger-head,
.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--line);
}

.ledger-head strong,
.panel-head strong {
  color: var(--signal);
  font-size: 0.78rem;
  font-weight: 600;
}

.panel-head span {
  display: block;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.68rem;
  letter-spacing: 0;
}

.resource-bank {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 8px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
}

#ore-list {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
  display: grid;
  gap: 6px;
}

#ore-list li {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

#ore-list li.ore-empty {
  grid-template-columns: minmax(0, 1fr) auto;
}

#ore-list strong {
  color: var(--ink);
  font-weight: 500;
}

.objective-progress {
  margin: 8px 0;
  color: var(--blue);
  font-size: 0.76rem;
  line-height: 1.35;
}

#objective-title {
  display: block;
  margin-top: 8px;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 600;
}

#objective-list,
#contract-list,
#charter-list,
#route-list,
#archive-list,
#utility-list,
#help-quick-start,
#help-system-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.objective-step,
.panel-lock-row,
.help-system-row,
.contract-row,
.charter-row,
.route-row,
.archive-row,
.utility-row {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 7px;
  background: rgba(7, 10, 12, 0.36);
}

.objective-step {
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
}

.contract-row,
.charter-row,
.route-row {
  grid-template-columns: minmax(0, 1fr) 68px;
  align-items: center;
}

.utility-row {
  grid-template-columns: minmax(0, 1fr) 64px;
  align-items: center;
}

.contract-row.active,
.charter-row.active,
.route-row.active,
.archive-row.unlocked,
.utility-row.ready,
.objective-step.current {
  border-color: rgba(71, 224, 195, 0.34);
}

.objective-step.done {
  border-color: rgba(131, 168, 198, 0.32);
}

.objective-step i {
  width: 8px;
  height: 8px;
  display: block;
  justify-self: center;
  border: 1px solid var(--line-hot);
  background: rgba(71, 224, 195, 0.08);
}

.objective-step.done i {
  background: var(--signal);
}

.objective-step span {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
}

.objective-step.current span {
  color: var(--ink);
}

.panel-lock-row {
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.35;
  text-transform: uppercase;
}

.panel-locked {
  min-height: 82px;
}

.panel-locked .panel-head {
  padding-bottom: 7px;
}

.contract-row.complete,
.charter-row.complete,
.route-row.complete {
  border-color: rgba(131, 168, 198, 0.32);
}

.help-system-row div,
.panel-lock-row div,
.contract-row div,
.charter-row div,
.route-row div,
.archive-row div,
.utility-row div {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.contract-row span,
.contract-row small,
.charter-row span,
.charter-row small,
.route-row span,
.route-row small,
.archive-row span,
.archive-row small,
.help-system-row span,
.help-system-row small,
.utility-row span,
.utility-row small {
  color: var(--muted);
  font-size: 0.66rem;
  text-transform: uppercase;
}

.contract-row strong,
.charter-row strong,
.route-row strong,
.archive-row strong,
.help-system-row strong,
.utility-row strong {
  color: var(--ink);
  font-size: 0.76rem;
  font-weight: 600;
}

.contract-row small,
.charter-row small,
.route-row small,
.archive-row small,
.help-system-row small,
.utility-row small {
  overflow-wrap: anywhere;
}

.contract-row button,
.charter-row button,
.route-row button,
.utility-row button {
  min-width: 0;
  min-height: 30px;
  border: 1px solid var(--line-hot);
  border-radius: 4px;
  background: rgba(71, 224, 195, 0.07);
  color: var(--signal);
  cursor: pointer;
  text-transform: uppercase;
  font-size: 0.66rem;
  letter-spacing: 0;
}

.contract-row button:disabled,
.charter-row button:disabled,
.route-row button:disabled,
.utility-row button:disabled {
  border-color: var(--line);
  color: var(--dim);
  background: rgba(32, 48, 51, 0.24);
  cursor: default;
}

.archive-track {
  height: 5px;
  border: 1px solid rgba(71, 224, 195, 0.24);
  background: #071011;
}

.archive-fill {
  display: block;
  height: 100%;
  width: var(--archive-progress, 0%);
  background: var(--signal);
}

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

.surface-actions button,
.upgrade-row button {
  min-width: 0;
  border: 1px solid var(--line-hot);
  border-radius: 4px;
  background: rgba(71, 224, 195, 0.07);
  color: var(--signal);
  cursor: pointer;
  text-transform: uppercase;
  font-size: 0.68rem;
  letter-spacing: 0;
}

.surface-actions button {
  min-height: 34px;
}

.surface-actions button:disabled,
.upgrade-row button:disabled {
  border-color: var(--line);
  color: var(--dim);
  background: rgba(32, 48, 51, 0.24);
  cursor: default;
}

.surface-lists {
  min-height: 0;
  display: grid;
  gap: 7px;
  max-height: 300px;
  overflow: auto;
  scrollbar-color: var(--line-hot) transparent;
}

#upgrade-list,
#research-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.upgrade-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 74px;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 7px;
  background: rgba(7, 10, 12, 0.36);
}

.upgrade-row.installed {
  border-color: rgba(71, 224, 195, 0.34);
}

.asset-icon {
  width: 32px;
  height: 32px;
  display: block;
  align-self: center;
  justify-self: center;
  border: 1px solid rgba(71, 224, 195, 0.18);
  background-color: rgba(5, 7, 8, 0.72);
  background-repeat: no-repeat;
}

.asset-icon-empty {
  background-image: linear-gradient(135deg, rgba(71, 224, 195, 0.16), transparent);
}

.upgrade-row.installed .asset-icon {
  border-color: rgba(71, 224, 195, 0.62);
  box-shadow: 0 0 0 1px rgba(71, 224, 195, 0.18), 0 0 18px rgba(71, 224, 195, 0.14);
}

.ore-icon {
  border-color: rgba(213, 166, 73, 0.2);
}

.research-row {
  border-color: rgba(131, 168, 198, 0.32);
}

.upgrade-row div {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.upgrade-row span,
.upgrade-row small {
  color: var(--muted);
  font-size: 0.66rem;
  text-transform: uppercase;
}

.upgrade-row strong {
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 600;
}

.upgrade-row small {
  overflow-wrap: anywhere;
}

.upgrade-row button {
  min-height: 30px;
}

.signal-log {
  min-height: 72px;
  padding: 10px;
  color: var(--blue);
  font-size: 0.8rem;
  line-height: 1.45;
}

.help-surface {
  position: fixed;
  top: 86px;
  right: max(12px, calc((100vw - 1180px) / 2));
  z-index: 20;
  width: min(440px, calc(100vw - 24px));
  max-height: calc(100vh - 108px);
  overflow: auto;
  border: 1px solid var(--line-hot);
  border-radius: 6px;
  background: rgba(13, 18, 20, 0.98);
  box-shadow: 0 18px 60px var(--shadow);
  padding: 12px;
}

.help-surface[hidden] {
  display: none;
}

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

.help-head span,
.help-block span {
  display: block;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.68rem;
  letter-spacing: 0;
}

.help-head strong,
.help-current strong {
  display: block;
  margin-top: 3px;
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 600;
}

.help-head button,
.help-actions button {
  min-height: 32px;
  border: 1px solid var(--line-hot);
  border-radius: 4px;
  background: rgba(71, 224, 195, 0.07);
  color: var(--signal);
  cursor: pointer;
  text-transform: uppercase;
  font-size: 0.68rem;
  letter-spacing: 0;
}

.help-head button {
  width: 34px;
  flex: 0 0 auto;
}

.help-actions button:disabled {
  border-color: var(--line);
  color: var(--dim);
  background: rgba(32, 48, 51, 0.24);
  cursor: default;
}

.help-grid {
  display: grid;
  gap: 9px;
  padding-top: 10px;
}

.help-block {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel-strong);
  padding: 9px;
}

.help-block p {
  margin: 0;
  color: var(--blue);
  font-size: 0.74rem;
  line-height: 1.4;
}

.help-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.control-pad {
  display: grid;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(2, 42px);
  justify-content: center;
  gap: 6px;
}

.control-pad button {
  border: 1px solid var(--line-hot);
  border-radius: 4px;
  background: rgba(71, 224, 195, 0.07);
  color: var(--signal);
  min-width: 0;
  min-height: 0;
  cursor: pointer;
  touch-action: none;
}

.control-pad button:active {
  background: rgba(71, 224, 195, 0.2);
}

.control-pad button:nth-child(1) {
  grid-column: 2;
}

.control-pad button:nth-child(2) {
  grid-column: 1;
  grid-row: 2;
}

.control-pad button:nth-child(3) {
  grid-column: 2;
  grid-row: 2;
}

.control-pad button:nth-child(4) {
  grid-column: 3;
  grid-row: 2;
}

@media (max-width: 860px) {
  .corebound-shell {
    width: min(100vw - 16px, 680px);
    padding-top: 8px;
  }

  .topline {
    grid-template-columns: 1fr;
    align-items: center;
  }

  .identity {
    text-align: left;
  }

  .run-state {
    justify-self: stretch;
    text-align: center;
  }

  .header-actions {
    justify-self: stretch;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 42px;
  }

  .playfield {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .viewport-frame {
    height: min(58vh, 420px);
    min-height: 360px;
  }

  #corebound-canvas {
    height: 100%;
    min-height: 0;
  }

  .hud {
    grid-template-rows: auto auto auto auto auto auto auto auto auto auto auto;
  }

  .help-surface {
    top: auto;
    right: 8px;
    left: 8px;
    bottom: 8px;
    width: auto;
    max-height: min(72vh, 640px);
  }
}

@media (max-width: 520px) {
  .meter-grid {
    grid-template-columns: 1fr;
  }

  .viewport-frame {
    height: 300px;
    min-height: 300px;
  }
}
