:root {
  color-scheme: dark;
  --ink: #f4f7ed;
  --muted: #abb6ad;
  --panel: rgba(12, 17, 15, 0.78);
  --panel-strong: rgba(10, 13, 12, 0.92);
  --line: rgba(244, 247, 237, 0.18);
  --green: #7efc8d;
  --teal: #5ad8cf;
  --amber: #f4c75d;
  --red: #ff6670;
  --violet: #b78cff;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #08100e;
  color: var(--ink);
  letter-spacing: 0;
}

button {
  font: inherit;
}

.game-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  min-width: 320px;
  min-height: 480px;
  overflow: hidden;
  background: #08100e;
}

#game {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.minimap {
  position: absolute;
  right: 14px;
  bottom: 44px;
  z-index: 4;
  width: 164px;
  height: 164px;
  border: 1px solid rgba(244, 247, 237, 0.18);
  border-radius: 8px;
  background: rgba(6, 10, 9, 0.72);
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.28);
  pointer-events: none;
}

.hud {
  position: absolute;
  z-index: 3;
  pointer-events: none;
}

.top-hud {
  top: 14px;
  left: 14px;
  right: 14px;
  min-height: 58px;
  display: grid;
  grid-template-columns: minmax(176px, 1fr) repeat(4, minmax(92px, max-content));
  gap: 8px;
  align-items: stretch;
}

.brand,
.stat,
.side-hud {
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(12px);
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  font-size: 0.95rem;
  font-weight: 800;
}

.brand-mark {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 38% 32%, #fff8c7 0 14%, transparent 15%),
    conic-gradient(from 20deg, var(--green), var(--teal), var(--amber), var(--red), var(--green));
  box-shadow: 0 0 22px rgba(126, 252, 141, 0.55);
}

.stat {
  min-width: 96px;
  padding: 9px 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
}

.stat span,
.trait-grid span,
.threat-row span,
.panel-title,
.mutation-kicker {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.stat strong,
.threat-row strong,
.trait-grid strong {
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.1;
  white-space: nowrap;
}

.side-hud {
  top: 88px;
  width: 238px;
  padding: 14px;
}

.gene-hud {
  left: 14px;
}

.leaderboard-hud {
  top: 356px;
  left: 14px;
}

.threat-hud {
  right: 14px;
}

.diplomacy-hud {
  top: 336px;
  right: 14px;
}

.panel-title {
  margin-bottom: 10px;
}

.genome-text {
  min-height: 46px;
  padding: 10px;
  border: 1px solid rgba(126, 252, 141, 0.22);
  border-radius: 6px;
  background: rgba(6, 10, 9, 0.58);
  color: var(--green);
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.45;
  word-break: break-all;
}

.trait-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.trait-grid div,
.threat-row {
  padding: 9px;
  border: 1px solid rgba(244, 247, 237, 0.12);
  border-radius: 6px;
  background: rgba(244, 247, 237, 0.05);
}

.trait-grid div {
  min-height: 54px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.threat-row {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.race-list {
  display: grid;
  gap: 8px;
}

.leaderboard-list {
  display: grid;
  gap: 7px;
}

.leader-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 38px;
  padding: 7px 8px;
  border: 1px solid rgba(244, 247, 237, 0.12);
  border-radius: 6px;
  background: rgba(244, 247, 237, 0.05);
}

.leader-row.player-lineage {
  border-color: rgba(126, 252, 141, 0.68);
  background: rgba(126, 252, 141, 0.12);
}

.leader-row.player-lineage .leader-rank::after {
  content: "*";
  color: var(--green);
}

.leader-row.remote-player {
  border-color: rgba(90, 216, 207, 0.4);
  background: rgba(90, 216, 207, 0.09);
}

.leader-rank {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
}

.leader-main {
  min-width: 0;
}

.leader-name {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leader-meta {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
}

.leader-score {
  color: var(--green);
  font-size: 0.86rem;
  font-weight: 900;
}

.race-row {
  min-height: 54px;
  padding: 8px;
  border: 1px solid rgba(244, 247, 237, 0.12);
  border-radius: 6px;
  background: rgba(244, 247, 237, 0.05);
}

.race-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
}

.race-name {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 7px;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 800;
}

.race-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 14px currentColor;
}

.race-value {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.race-bar {
  height: 5px;
  border-radius: 5px;
  background: rgba(244, 247, 237, 0.12);
  overflow: hidden;
}

.race-bar span {
  display: block;
  width: 50%;
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
  transition: width 160ms linear;
}

.policy-note {
  margin-top: 10px;
  padding: 9px;
  border: 1px solid rgba(244, 247, 237, 0.12);
  border-radius: 6px;
  background: rgba(126, 252, 141, 0.07);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.policy-note span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.policy-note strong {
  color: var(--ink);
  font-size: 0.9rem;
  text-align: right;
}

.bottom-hud {
  position: absolute;
  left: 50%;
  bottom: 18px;
  z-index: 3;
  width: min(560px, calc(100vw - 28px));
  transform: translateX(-50%);
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.menu-layer {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(5, 9, 8, 0.54), rgba(5, 9, 8, 0.74)),
    radial-gradient(circle at 50% 28%, rgba(126, 252, 141, 0.14), transparent 42%);
  backdrop-filter: blur(5px);
}

.menu-panel {
  width: min(440px, 100%);
  padding: 26px;
  border: 1px solid rgba(244, 247, 237, 0.18);
  border-radius: 8px;
  background: rgba(8, 13, 12, 0.9);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.46);
}

.menu-kicker,
.player-key span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.menu-panel h1 {
  margin: 8px 0 10px;
  font-size: clamp(2rem, 7vw, 3.1rem);
  line-height: 1;
  letter-spacing: 0;
}

.menu-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.player-key {
  margin: 18px 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(126, 252, 141, 0.2);
  border-radius: 6px;
  background: rgba(126, 252, 141, 0.07);
}

.world-key {
  margin-top: -10px;
  border-color: rgba(90, 216, 207, 0.2);
  background: rgba(90, 216, 207, 0.06);
}

.server-key {
  margin-top: -10px;
  border-color: rgba(244, 199, 93, 0.2);
  background: rgba(244, 199, 93, 0.06);
}

.player-key code {
  color: var(--green);
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.82rem;
  word-break: break-all;
}

.name-field {
  margin: -4px 0 20px;
  display: grid;
  gap: 7px;
}

.name-field span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.name-field input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid rgba(244, 247, 237, 0.18);
  border-radius: 6px;
  background: rgba(244, 247, 237, 0.06);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  outline: none;
}

.name-field input:focus {
  border-color: rgba(126, 252, 141, 0.68);
  background: rgba(126, 252, 141, 0.1);
}

.menu-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 9px;
}

.menu-button {
  min-height: 46px;
  border: 1px solid rgba(244, 247, 237, 0.18);
  border-radius: 6px;
  background: rgba(244, 247, 237, 0.06);
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
}

.menu-button.primary {
  border-color: rgba(126, 252, 141, 0.65);
  background: rgba(126, 252, 141, 0.18);
  color: #f4fff3;
}

.menu-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.meter {
  height: 12px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(5, 8, 7, 0.75);
  overflow: hidden;
}

.meter span {
  display: block;
  width: 50%;
  height: 100%;
  border-radius: 6px;
  transition: width 120ms linear;
}

.health-meter span {
  background: linear-gradient(90deg, var(--red), var(--amber));
}

.dna-meter span {
  background: linear-gradient(90deg, var(--teal), var(--green));
}

.mutation-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(4, 8, 7, 0.5);
  backdrop-filter: blur(6px);
}

.mutation-layer.hidden {
  display: none;
}

.hidden {
  display: none !important;
}

.mutation-panel {
  width: min(760px, 100%);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

.mutation-panel h1 {
  margin: 4px 0 18px;
  font-size: 2rem;
  line-height: 1.05;
}

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

.mutation-card {
  min-height: 148px;
  padding: 14px;
  border: 1px solid rgba(244, 247, 237, 0.16);
  border-radius: 8px;
  background: rgba(244, 247, 237, 0.06);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease;
}

.mutation-card:hover,
.mutation-card:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(126, 252, 141, 0.6);
  background: rgba(126, 252, 141, 0.12);
  outline: none;
}

.mutation-card strong {
  display: block;
  margin-bottom: 9px;
  font-size: 1.08rem;
}

.mutation-card span {
  display: block;
  color: var(--muted);
  line-height: 1.4;
}

.mutation-card code {
  display: inline-block;
  margin-top: 12px;
  color: var(--green);
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.83rem;
}

.diplomacy-panel {
  width: min(840px, 100%);
}

.diplomacy-text {
  max-width: 680px;
  margin: -6px 0 18px;
  color: var(--muted);
  line-height: 1.5;
}

.game-over-panel {
  width: min(520px, 100%);
}

.game-over-panel p {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.5;
}

.primary-action {
  min-height: 52px;
  width: 100%;
  text-align: center;
  font-weight: 800;
  background: rgba(126, 252, 141, 0.18);
}

@media (max-width: 820px) {
  .top-hud {
    grid-template-columns: 1fr 1fr;
  }

  .brand {
    grid-column: 1 / -1;
    min-height: 46px;
  }

  .side-hud {
    top: auto;
    bottom: 56px;
    width: calc(50vw - 18px);
    padding: 10px;
  }

  .gene-hud {
    left: 10px;
  }

  .leaderboard-hud {
    top: 174px;
    bottom: auto;
    left: 10px;
    right: auto;
    display: block;
    width: min(210px, calc(50vw - 18px));
    padding: 9px;
  }

  .threat-hud {
    right: 10px;
  }

  .diplomacy-hud {
    display: none;
  }

  .minimap {
    top: 174px;
    right: 10px;
    bottom: auto;
    width: 132px;
    height: 132px;
  }

  .trait-grid {
    display: none;
  }

  .genome-text {
    min-height: 38px;
    max-height: 58px;
    overflow: hidden;
  }

  .mutation-options {
    grid-template-columns: 1fr;
  }
}

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

  .stat {
    min-width: 0;
    padding: 8px;
  }

  .stat strong,
  .threat-row strong,
  .trait-grid strong {
    font-size: 0.9rem;
  }

  .side-hud {
    display: none;
  }

  .leaderboard-hud {
    top: 174px;
    left: 8px;
    right: auto;
    display: block;
    width: min(178px, calc(100vw - 16px));
    padding: 8px;
  }

  .leaderboard-hud .panel-title {
    margin-bottom: 5px;
    font-size: 0.66rem;
  }

  .leaderboard-list {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .leader-row {
    grid-template-columns: 18px minmax(0, 1fr) auto;
    min-height: 28px;
    padding: 5px;
  }

  .leader-row:nth-child(n + 4) {
    display: none;
  }

  .leader-name {
    font-size: 0.74rem;
  }

  .leader-score {
    font-size: 0.74rem;
  }

  .leader-meta {
    display: none;
  }

  .minimap {
    top: 174px;
    right: 8px;
    bottom: auto;
    width: 112px;
    height: 112px;
  }

  .mutation-panel {
    padding: 16px;
  }

  .mutation-panel h1 {
    font-size: 1.55rem;
  }
}
