:root {
  color-scheme: dark;
  --ink: #f4fbf7;
  --muted: #a8c7c7;
  --deep: #071b24;
  --panel: #0c2e38;
  --panel-2: #123e47;
  --line: rgba(194, 243, 234, 0.18);
  --mint: #76ead5;
  --yellow: #ffd757;
  --orange: #ff934f;
  --shadow: rgba(0, 0, 0, 0.4);
  font-family: "Trebuchet MS", "Avenir Next", Avenir, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: #06151d;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% -20%, rgba(64, 202, 190, 0.24), transparent 45%),
    linear-gradient(145deg, #081923, #092934 55%, #07161f);
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 3px solid #fff3a6;
  outline-offset: 3px;
}

.page-shell {
  width: min(1040px, calc(100% - 28px));
  margin: 0 auto;
  padding: 26px 0 44px;
}

.site-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding: 0 4px 16px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--mint);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.75rem, 5vw, 3.15rem);
  line-height: 0.98;
  letter-spacing: -0.045em;
}

.header-actions,
.control-buttons,
.dialog-actions {
  display: flex;
  gap: 9px;
}

.icon-button,
.deck-button,
.game-button {
  border: 1px solid var(--line);
  color: var(--ink);
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

.icon-button:hover,
.deck-button:hover,
.game-button:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 255, 255, 0.42);
}

.icon-button {
  padding: 10px 13px;
  border-radius: 11px;
  background: rgba(10, 42, 51, 0.78);
  font-size: 0.84rem;
  font-weight: 800;
}

.game-card {
  overflow: hidden;
  border: 1px solid rgba(163, 235, 225, 0.23);
  border-radius: 22px;
  background: #05131a;
  box-shadow: 0 28px 80px var(--shadow), inset 0 1px rgba(255, 255, 255, 0.08);
}

.game-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: #071a24;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  image-rendering: auto;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(18px, 4vw, 42px);
}

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

.screen--loading {
  flex-direction: column;
  gap: 18px;
  background: radial-gradient(circle, #18444b, #071a24 70%);
  font-weight: 900;
  letter-spacing: 0.04em;
}

.loader {
  width: 54px;
  height: 54px;
  border: 7px solid rgba(255, 255, 255, 0.14);
  border-top-color: var(--mint);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.screen--menu {
  justify-content: flex-end;
  flex-direction: column;
  background:
    linear-gradient(to bottom, rgba(2, 10, 15, 0.02) 34%, rgba(2, 12, 17, 0.88) 100%);
}

.menu-logo {
  position: absolute;
  top: 2%;
  left: 50%;
  width: min(54%, 430px);
  transform: translateX(-50%);
  filter: drop-shadow(0 10px 12px rgba(0, 0, 0, 0.42));
}

.menu-panel {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, minmax(130px, 1fr));
  gap: 10px;
  width: min(690px, 96%);
  padding: 17px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 18px;
  background: rgba(5, 28, 35, 0.88);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(7px);
}

.menu-kicker {
  grid-column: 1 / -1;
  margin: 0 0 2px;
  color: #b6d9d7;
  font-size: 0.8rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-align: center;
  text-transform: uppercase;
}

.game-button {
  min-height: 46px;
  padding: 11px 17px;
  border-radius: 12px;
  background: #17454e;
  font-weight: 900;
}

.game-button--primary {
  border-color: #ffd35c;
  color: #172126;
  background: linear-gradient(#ffe97f, #f6b735);
  box-shadow: inset 0 1px #fff8bf, 0 5px 0 #ac642a;
}

.game-button--danger {
  border-color: #ffab84;
  background: #8e3529;
}

.screen--dialog {
  z-index: 4;
  background: rgba(1, 11, 15, 0.72);
  backdrop-filter: blur(5px);
}

.dialog-card {
  width: min(580px, 94%);
  max-height: 94%;
  overflow: auto;
  padding: clamp(20px, 4vw, 34px);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 22px;
  background: linear-gradient(155deg, rgba(20, 64, 71, 0.98), rgba(6, 29, 38, 0.98));
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}

.dialog-eyebrow {
  margin: 0 0 5px;
  color: var(--yellow);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.dialog-card h2 {
  margin: 0 0 13px;
  font-size: clamp(1.6rem, 4vw, 2.5rem);
  letter-spacing: -0.04em;
}

.dialog-body {
  color: #d3e8e5;
  line-height: 1.55;
}

.dialog-body p {
  margin: 0 0 12px;
}

.dialog-body kbd {
  padding: 2px 7px;
  border: 1px solid rgba(255,255,255,.25);
  border-bottom-width: 3px;
  border-radius: 6px;
  background: rgba(255,255,255,.08);
  font: inherit;
  font-size: .85em;
  font-weight: 900;
}

.dialog-actions {
  flex-wrap: wrap;
  margin-top: 21px;
}

.dialog-actions .game-button {
  flex: 1 1 145px;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 7px;
  margin-top: 17px;
}

.level-chip {
  aspect-ratio: 1;
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  color: #fff;
  background: #1a5058;
  cursor: pointer;
  font-weight: 900;
}

.level-chip[disabled] {
  color: #68868a;
  background: #102f36;
  cursor: not-allowed;
}

.level-chip:not([disabled]):hover {
  background: #2c7174;
}

.mode-tabs { display: flex; gap: 8px; margin: 4px 0 14px; }
.mode-tabs .game-button { flex: 1; }
.mode-tabs .is-active { border-color: var(--yellow); color: #18272b; background: var(--yellow); }
.factory-map { display: grid; gap: 12px; }
.factory-stage { padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: rgba(0, 0, 0, .13); }
.factory-stage h3 { margin: 0 0 8px; color: #fff3b0; font-size: .88rem; }
.factory-stage .level-grid { margin-top: 0; }
.story-card { display: grid; gap: 14px; min-height: 180px; align-content: center; padding: 20px; border: 1px solid rgba(255, 232, 139, .24); border-radius: 14px; background: radial-gradient(circle at 20% 0, rgba(118, 234, 213, .14), transparent 55%), rgba(0, 0, 0, .15); text-align: center; }
.story-card strong { color: #ffe276; font-size: 1.25rem; }
.store-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; }
.store-item { display: grid; gap: 3px; min-height: 88px; padding: 10px; border: 1px solid var(--line); border-radius: 11px; color: var(--ink); background: #123e47; cursor: pointer; text-align: left; }
.store-item:hover:not([disabled]) { border-color: var(--yellow); transform: translateY(-1px); }
.store-item[disabled] { opacity: .48; cursor: not-allowed; }
.store-item strong { font-size: .78rem; }
.store-item small { color: var(--muted); font-size: .66rem; }
.store-item b { color: var(--yellow); font-size: .72rem; }

.control-deck {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 17px;
  border-top: 1px solid var(--line);
  background: linear-gradient(110deg, var(--panel), #0a252e);
}

.power-belt { display: flex; gap: 7px; }
.power-slot { width: 62px; min-height: 50px; padding: 5px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: #16454e; cursor: pointer; font-size: .62rem; font-weight: 900; }
.power-slot.is-used { opacity: .4; filter: grayscale(1); }
.power-slot.is-armed { border-color: var(--yellow); background: #70432b; box-shadow: 0 0 0 3px rgba(255, 210, 115, .12); }
.save-code { width: 100%; min-height: 92px; padding: 9px; border: 1px solid var(--line); border-radius: 8px; color: #dff8ef; background: #061b22; resize: vertical; font: 11px/1.35 ui-monospace, monospace; }

.control-status {
  display: flex;
  align-items: center;
  gap: clamp(18px, 4vw, 45px);
}

.control-status span {
  display: grid;
}

.control-status strong {
  font-size: 1rem;
  line-height: 1.1;
}

.control-status small,
.deck-button small {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
}

.deck-button {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 120px;
  padding: 8px 12px;
  border-radius: 11px;
  background: #16454e;
  text-align: left;
}

.deck-button span:last-child {
  display: grid;
}

.deck-key {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid rgba(255,255,255,.24);
  border-radius: 8px;
  color: var(--yellow);
  background: rgba(0,0,0,.16);
  font-weight: 900;
}

.deck-button--bomb[aria-pressed="true"] {
  border-color: #ffd273;
  background: #7a3c25;
  box-shadow: 0 0 0 3px rgba(255, 190, 74, .15);
}

.help-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 19px 7px 0;
  color: #c4dcda;
  font-size: 0.86rem;
  line-height: 1.45;
}

.help-strip p {
  margin: 0;
}

.help-meta {
  flex: 0 0 auto;
  color: #7da4a6;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

@media (max-width: 720px) {
  .page-shell {
    width: min(100% - 16px, 680px);
    padding-top: 14px;
  }

  .site-header {
    align-items: center;
  }

  .icon-button {
    padding: 8px 10px;
    font-size: 0.74rem;
  }

  .game-card {
    border-radius: 14px;
  }

  .menu-panel {
    grid-template-columns: 1fr 1fr;
    padding: 12px;
  }

  .menu-panel .game-button--primary {
    grid-column: 1 / -1;
  }

  .control-deck {
    align-items: stretch;
    flex-direction: column;
    gap: 11px;
  }

  .control-status,
  .control-buttons {
    justify-content: space-between;
  }

  .control-status {
    gap: 12px;
    padding: 0 4px;
  }

  .deck-button {
    flex: 1;
  }

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

  .help-strip {
    align-items: flex-start;
    flex-direction: column;
    gap: 7px;
  }
}

@media (max-width: 470px) {
  .site-header {
    align-items: flex-start;
  }

  .site-header h1 {
    font-size: 1.6rem;
  }

  .header-actions {
    gap: 5px;
  }

  .icon-button span {
    display: none;
  }

  .level-grid {
    grid-template-columns: repeat(8, 1fr);
  }

  .menu-kicker {
    display: none;
  }

  .menu-panel {
    gap: 7px;
  }

  .game-button {
    min-height: 38px;
    padding: 8px;
    font-size: .78rem;
  }
}

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