:root {
  --ink: #e9f2ff;
  --muted: #8fa5c5;
  --panel: #17213b;
  --panel-deep: #0c1225;
  --line: #34476f;
  --cyan: #4de1ff;
  --violet: #9c7bff;
  --gold: #ffd166;
  --green: #65e89b;
  --danger: #ff6b7d;
  --shadow: #050817;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 0%, #263464 0, transparent 34rem),
    radial-gradient(circle at 90% 100%, #243b53 0, transparent 30rem),
    #080c1a;
  font-family: "Courier New", Courier, monospace;
}

button,
kbd {
  font: inherit;
}

button {
  color: inherit;
}

.game-shell {
  width: min(1400px, 100%);
  margin: 0 auto;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 16px;
}

.eyebrow,
.panel-label,
.modal-label {
  margin: 0 0 7px;
  color: var(--cyan);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.15em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.45rem, 3vw, 2.35rem);
  letter-spacing: -0.06em;
}

h1 span {
  color: var(--gold);
}

.status-strip {
  display: flex;
  border: 2px solid var(--line);
  background: rgba(12, 18, 37, 0.92);
  box-shadow: 5px 5px 0 var(--shadow);
}

.status-strip div {
  min-width: 105px;
  padding: 9px 13px;
  border-right: 1px solid var(--line);
}

.status-strip div:last-child {
  border-right: 0;
}

.status-strip small {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.62rem;
}

.status-strip strong {
  color: var(--gold);
  font-size: 0.82rem;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 270px;
  gap: 16px;
}

.viewport-frame {
  position: relative;
  overflow: hidden;
  border: 4px solid #5b6e9b;
  background: #111a31;
  box-shadow: 9px 9px 0 var(--shadow);
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 18px;
  width: max-content;
  max-width: calc(100% - 30px);
  padding: 9px 14px;
  color: #07101f;
  background: var(--gold);
  border: 3px solid #fff2b9;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.45);
  font-weight: 700;
  text-align: center;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  transition: 160ms ease;
}

.toast.visible {
  transform: translate(-50%, 0);
  opacity: 1;
}

.guide-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel-card {
  padding: 17px;
  border: 2px solid var(--line);
  background: linear-gradient(145deg, #182441, var(--panel-deep));
  box-shadow: 5px 5px 0 var(--shadow);
}

.mission-card {
  border-color: #6c5fbd;
}

.panel-card h2 {
  margin-bottom: 9px;
  color: var(--gold);
  font-size: 1rem;
  line-height: 1.4;
}

.panel-card p:last-child {
  margin-bottom: 0;
  color: #b8c7df;
  font-size: 0.8rem;
  line-height: 1.55;
}

.control-list,
.legend {
  display: grid;
  gap: 11px;
  color: #b8c7df;
  font-size: 0.76rem;
}

kbd {
  display: inline-block;
  padding: 2px 5px;
  color: var(--gold);
  border: 1px solid var(--line);
  background: #080d1d;
}

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

.swatch {
  width: 13px;
  height: 13px;
  border: 2px solid rgba(255, 255, 255, 0.7);
}

.swatch.collectible { background: var(--gold); }
.swatch.npc { background: var(--violet); }
.swatch.nexus { background: var(--cyan); }
.swatch.exit { background: #f5f7ff; }

.modal-backdrop {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(3, 6, 16, 0.78);
  backdrop-filter: blur(3px);
}

.hidden {
  display: none !important;
}

.modal {
  width: min(620px, 100%);
  max-height: min(90vh, 760px);
  overflow-y: auto;
  padding: clamp(20px, 4vw, 34px);
  border: 4px solid #697ba8;
  background: #111a31;
  box-shadow: 10px 10px 0 #02040d;
}

.wide-modal {
  width: min(760px, 100%);
}

.modal h2 {
  color: var(--gold);
  font-size: 1.25rem;
  line-height: 1.4;
}

.modal p {
  color: #c4d1e6;
  line-height: 1.6;
}

.modal-actions,
.market-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 22px;
}

button {
  min-height: 42px;
  padding: 9px 14px;
  border: 2px solid #6c7ca4;
  background: #202d4e;
  box-shadow: 3px 3px 0 #030611;
  cursor: pointer;
}

button:hover,
button:focus-visible {
  border-color: #fff;
  filter: brightness(1.15);
  outline: 0;
  transform: translateY(-1px);
}

button.keyboard-selected {
  color: #07101f;
  border-color: #fff;
  background: var(--gold);
  box-shadow:
    0 0 0 3px #11182e,
    0 0 0 5px var(--cyan),
    4px 4px 0 #030611;
  filter: brightness(1.12);
  transform: translateX(5px);
}

button.keyboard-selected::before {
  content: "▶ ";
}

button:disabled {
  cursor: not-allowed;
  filter: grayscale(0.8);
  opacity: 0.5;
  transform: none;
}

.primary-button {
  color: #03131a;
  border-color: #b4f4ff;
  background: var(--cyan);
}

.accent-button {
  color: #251900;
  border-color: #fff0a7;
  background: var(--gold);
}

.secondary-button {
  margin-top: 20px;
}

.danger-button {
  color: #fff;
  border-color: #ff9aa7;
  background: #702536;
}

.save-settings-status {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  background: #0a1022;
}

.save-settings-status strong {
  color: var(--gold);
}

.save-settings-actions .secondary-button {
  margin-top: 0;
}

.quiz-options {
  display: grid;
  gap: 10px;
}

.mechanic-board {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.mechanic-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px;
  padding: 11px;
  border: 1px solid var(--line);
  background: #0a1022;
}

.mechanic-row strong {
  min-width: 130px;
  color: var(--cyan);
}

.mechanic-meter {
  height: 18px;
  overflow: hidden;
  border: 2px solid var(--line);
  background: #080d1d;
}

.mechanic-meter span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--cyan), var(--green));
  transition: width 160ms ease;
}

.mechanic-board button.selected {
  color: #07101f;
  border-color: #fff;
  background: var(--gold);
}

.mechanic-board .danger-choice.selected {
  background: var(--danger);
}

.quiz-options button {
  text-align: left;
}

.quiz-feedback {
  min-height: 1.5em;
  margin: 14px 0 0;
  color: var(--gold) !important;
}

.inventory-sections,
.quest-list {
  display: grid;
  gap: 16px;
}

.inventory-category {
  padding: 12px;
  border: 1px solid var(--line);
  background: #0a1022;
}

.inventory-category h3,
.quest-card h3 {
  margin: 0 0 10px;
  color: var(--cyan);
  font-size: 0.9rem;
}

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

.inventory-item,
.market-inventory {
  padding: 12px;
  border: 1px solid var(--line);
  background: #0a1022;
}

.inventory-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.inventory-item strong {
  color: var(--gold);
  font-size: 0.7rem;
}

.inventory-item.missing {
  color: #63728d;
}

.inventory-item.missing strong {
  color: #63728d;
}

.inventory-item.collected {
  border-color: #397b68;
}

.credits-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.credits-card h3 {
  margin: 0;
}

.credits-card > strong {
  color: var(--gold);
  font-size: 1.35rem;
}

.quest-card {
  padding: 14px;
  border: 1px solid var(--line);
  background: #0a1022;
}

.quest-card > div {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.quest-card > div span {
  order: 2;
  padding: 4px 7px;
  color: var(--gold);
  border: 1px solid var(--line);
  font-size: 0.64rem;
}

.quest-card p {
  margin-bottom: 6px;
  font-size: 0.8rem;
}

.quest-card.completed {
  border-color: #397b68;
  opacity: 0.78;
}

.market-inventory {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  color: var(--muted);
}

.market-message {
  min-height: 1.6em;
  margin: 15px 0 0;
  color: var(--green) !important;
}

.mobile-controls {
  display: none;
  align-items: center;
  justify-content: space-between;
  margin-top: 20px;
  user-select: none;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: repeat(2, 48px);
  gap: 5px;
}

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

.action-pad {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.action-pad button {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 50%;
}

.action-pad .primary-action {
  width: 62px;
  height: 62px;
  color: #081221;
  border-color: #c6f8ff;
  background: var(--cyan);
}

@media (max-width: 920px) {
  .game-layout {
    grid-template-columns: 1fr;
  }

  .guide-panel {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 680px) {
  .game-shell {
    padding: 12px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
  }

  .status-strip {
    width: 100%;
  }

  .status-strip div {
    flex: 1;
    min-width: 0;
    padding: 8px;
  }

  .status-strip strong {
    font-size: 0.68rem;
  }

  .guide-panel {
    grid-template-columns: 1fr;
  }

  .guide-panel .panel-card:not(.mission-card) {
    display: none;
  }

  .mobile-controls {
    display: flex;
  }

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