:root {
  --ink: #f4f1e8;
  --muted: #a8afa7;
  --panel: rgba(15, 17, 19, 0.74);
  --panel-strong: rgba(10, 11, 12, 0.9);
  --line: rgba(244, 241, 232, 0.16);
  --hot: #ff5a6c;
  --acid: #b7ff3c;
  --aqua: #4be3d5;
  --gold: #ffd166;
  --violet: #c076ff;
  --void: #070808;
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

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

button,
canvas {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

#shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  min-height: 520px;
  overflow: hidden;
  background:
    radial-gradient(circle at 22% 12%, rgba(183, 255, 60, 0.1), transparent 26%),
    radial-gradient(circle at 84% 70%, rgba(255, 90, 108, 0.11), transparent 24%),
    #070808;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

.topbar {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  z-index: 4;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) repeat(4, minmax(88px, auto));
  gap: 8px;
  pointer-events: none;
}

.brand,
.stat,
.hud,
.modal {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 14px 60px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(16px);
}

.brand,
.stat {
  min-height: 56px;
  border-radius: 8px;
  padding: 10px 12px;
}

.brand {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  letter-spacing: 0;
}

.brand strong {
  font-size: 20px;
  line-height: 1;
}

.brand span,
.stat span,
.eyebrow,
.meterLabel span,
.panelBlock h2,
dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.stat {
  display: grid;
  align-content: center;
  justify-items: end;
}

.stat strong {
  font-size: 22px;
  line-height: 1.05;
}

.stat.danger strong {
  color: var(--gold);
}

.hud {
  position: absolute;
  top: 84px;
  right: 14px;
  z-index: 3;
  width: min(320px, calc(100vw - 28px));
  max-height: calc(100vh - 110px);
  overflow: hidden;
  border-radius: 8px;
  padding: 14px;
  pointer-events: none;
}

.meter + .meter,
.panelBlock {
  margin-top: 14px;
}

.meterLabel {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.meterLabel strong {
  font-size: 12px;
  color: var(--ink);
}

.meterTrack {
  height: 9px;
  overflow: hidden;
  border: 1px solid rgba(244, 241, 232, 0.12);
  border-radius: 99px;
  background: rgba(244, 241, 232, 0.08);
}

.meterTrack span {
  display: block;
  width: 0%;
  height: 100%;
  transition: width 120ms linear;
}

.meterTrack .hp {
  background: linear-gradient(90deg, var(--hot), var(--gold));
}

.meterTrack .xp {
  background: linear-gradient(90deg, var(--aqua), var(--acid));
}

.panelBlock h2 {
  margin: 0 0 8px;
}

.compactList,
.patchFeed {
  margin: 0;
  padding: 0;
  list-style: none;
}

.compactList li,
.patchFeed li {
  border-top: 1px solid rgba(244, 241, 232, 0.1);
  padding: 8px 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.25;
}

.compactList li:first-child,
.patchFeed li:first-child {
  border-top: 0;
  padding-top: 0;
}

.compactList span,
.patchFeed span {
  color: var(--muted);
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background:
    linear-gradient(rgba(7, 8, 8, 0.16), rgba(7, 8, 8, 0.46)),
    rgba(7, 8, 8, 0.22);
}

.overlay.open {
  display: flex;
}

.modal {
  width: min(960px, 100%);
  border-radius: 8px;
  padding: 22px;
}

.startModal,
.endModal {
  max-width: 560px;
  background: var(--panel-strong);
}

.startModal h1,
.endModal h2,
.upgradeModal h2 {
  margin: 0;
  letter-spacing: 0;
}

.startModal h1 {
  margin-top: 8px;
  font-size: clamp(44px, 9vw, 82px);
  line-height: 0.9;
}

.upgradeModal h2,
.endModal h2 {
  font-size: clamp(28px, 4vw, 46px);
  line-height: 0.95;
}

.memoryLine {
  min-height: 42px;
  margin: 18px 0 22px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.45;
}

.primaryButton,
.upgradeCard {
  border: 1px solid rgba(244, 241, 232, 0.2);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(244, 241, 232, 0.08);
}

.primaryButton {
  min-width: 172px;
  min-height: 48px;
  padding: 0 18px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
}

.primaryButton:hover,
.primaryButton:focus-visible {
  border-color: rgba(183, 255, 60, 0.72);
  background: rgba(183, 255, 60, 0.14);
  outline: none;
}

.modalHeader {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.mutationPreview {
  max-width: 320px;
  margin: 0;
  color: var(--gold);
  font-size: 13px;
  line-height: 1.35;
  text-align: right;
}

.upgradeChoices {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.upgradeCard {
  min-height: 250px;
  padding: 16px;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 12px;
  text-align: left;
  cursor: pointer;
}

.upgradeCard:hover,
.upgradeCard:focus-visible {
  border-color: var(--aqua);
  background: rgba(75, 227, 213, 0.12);
  outline: none;
  transform: translateY(-1px);
}

.upgradeCard strong {
  font-size: 22px;
  line-height: 1.02;
}

.upgradeCard p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.38;
}

.upgradeCard .effect {
  color: var(--ink);
}

.rarity {
  width: max-content;
  max-width: 100%;
  padding: 4px 7px;
  border-radius: 999px;
  color: #101112;
  background: var(--acid);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.rarity.uncommon {
  background: var(--aqua);
}

.rarity.rare {
  background: var(--gold);
}

.rarity.broken {
  background: var(--hot);
  color: var(--ink);
}

.summaryGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 22px 0 10px;
}

.summaryGrid div {
  min-height: 74px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(244, 241, 232, 0.06);
}

dt,
dd {
  margin: 0;
}

dd {
  margin-top: 5px;
  font-size: 18px;
  font-weight: 800;
  line-height: 1.1;
}

@media (max-width: 820px) {
  #shell {
    min-height: 620px;
  }

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

  .brand {
    grid-column: 1 / -1;
  }

  .stat {
    min-height: 48px;
    padding: 8px;
    justify-items: start;
  }

  .stat strong {
    font-size: 18px;
  }

  .hud {
    top: auto;
    left: 14px;
    bottom: 14px;
    width: calc(100vw - 28px);
    max-height: 218px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .meter + .meter,
  .panelBlock {
    margin-top: 0;
  }

  .panelBlock {
    min-width: 0;
  }

  .patchFeed li:nth-child(n + 3),
  .compactList li:nth-child(n + 4) {
    display: none;
  }

  .modal {
    padding: 16px;
  }

  .modalHeader {
    display: block;
  }

  .mutationPreview {
    max-width: none;
    margin-top: 8px;
    text-align: left;
  }

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

  .upgradeCard {
    min-height: 170px;
  }
}

@media (max-width: 520px) {
  .topbar {
    gap: 6px;
    top: 8px;
    left: 8px;
    right: 8px;
  }

  .hud {
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: calc(100vw - 16px);
    grid-template-columns: 1fr;
    max-height: 190px;
    padding: 10px;
  }

  .panelBlock {
    display: none;
  }

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