:root {
  color-scheme: dark;
  --ink: #f8f6ff;
  --muted: #9d9ab6;
  --line: #312e50;
  --cyan: #55f4e7;
  --pink: #ff4ec8;
  --yellow: #ffe45b;
  --red: #ff6278;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  overflow: hidden;
  background: #050611;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

button { color: inherit; font: inherit; }

.app {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  grid-template-rows: 70px minmax(0, 1fr);
  background: radial-gradient(circle at 50% 40%, #18163d, #08091b 50%, #04050d);
}

.topbar {
  position: relative;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
  padding: 8px clamp(11px, 3vw, 28px);
  border-bottom: 1px solid #292645;
  background: rgb(7 8 22 / 90%);
  backdrop-filter: blur(14px);
}

.brand {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  text-decoration: none;
  font-size: clamp(.8rem, 2.4vw, 1.05rem);
  font-weight: 950;
  letter-spacing: -.055em;
  white-space: nowrap;
}

.brand img { width: 25px; height: 34px; filter: drop-shadow(0 0 8px #55f4e788); }
.brand > span > span { color: var(--cyan); }

.battle-stats { display: flex; align-items: center; gap: clamp(15px, 5vw, 56px); }
.battle-stats > div, .run-score { display: grid; justify-items: center; gap: 2px; }
.battle-stats span, .run-score span, .player-loadout span {
  color: var(--muted);
  font-size: .56rem;
  font-weight: 900;
  letter-spacing: .16em;
}
.battle-stats strong, .run-score strong { font-size: clamp(.82rem, 2.6vw, 1.04rem); font-variant-numeric: tabular-nums; }
.run-score { justify-self: end; }

.tower-stat { grid-template-columns: auto auto; grid-template-rows: auto auto; }
.tower-stat > span { grid-column: 1 / -1; }
.tower-stat > strong { font-size: .66rem; }
.meter { width: clamp(70px, 14vw, 150px); height: 8px; overflow: hidden; border: 1px solid #575172; border-radius: 99px; background: #17162d; }
.meter i { display: block; width: 100%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #ff6278, #ffe45b 48%, #55f4e7); transform-origin: left; transition: transform 140ms ease; }

.game-stage {
  position: relative;
  min-height: 0;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  overflow: hidden;
  isolation: isolate;
  touch-action: none;
}

#game { width: 100%; height: 100%; display: block; outline: none; touch-action: none; cursor: grab; }
#game:active { cursor: grabbing; }

.player-loadout {
  position: absolute;
  z-index: 3;
  left: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  gap: 6px;
  pointer-events: none;
}
.player-loadout > div {
  min-width: 72px;
  padding: 7px 9px;
  border: 1px solid #393557;
  border-radius: 10px;
  background: rgb(9 10 27 / 75%);
  backdrop-filter: blur(6px);
}
.player-loadout span, .player-loadout strong { display: block; }
.player-loadout strong { margin-top: 2px; font-size: .64rem; letter-spacing: .03em; }
.player-loadout .active { border-color: #55f4e788; box-shadow: inset 0 0 18px #55f4e710; }

.mobile-controls { display: none; }
.steer-button {
  pointer-events: auto;
  display: grid;
  place-content: center;
  gap: 1px;
  border: 1px solid #8c86b766;
  background: rgb(15 16 39 / 62%);
  color: var(--ink);
  box-shadow: inset 0 1px #ffffff16, 0 8px 24px #0004;
  backdrop-filter: blur(6px);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.steer-button { width: clamp(64px, 19vw, 82px); height: clamp(58px, 17vw, 76px); border-radius: 21px; }
.steer-button b { font-size: 1.7rem; line-height: .85; }
.steer-button small { color: #aaa6c0; font-size: .47rem; font-weight: 900; letter-spacing: .14em; }
.steer-button.pressed { border-color: var(--cyan); background: rgb(29 69 78 / 82%); box-shadow: inset 0 0 18px #55f4e733, 0 0 20px #55f4e733; }

.announcement {
  position: absolute;
  z-index: 4;
  top: 15%;
  left: 50%;
  width: min(90%, 600px);
  translate: -50% -8px;
  color: white;
  font-size: clamp(1.35rem, 5vw, 2.6rem);
  font-weight: 1000;
  line-height: .95;
  letter-spacing: -.055em;
  text-align: center;
  text-shadow: 0 0 24px var(--pink), 0 4px 0 #40285f;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, translate 160ms ease;
}
.announcement.show { opacity: 1; translate: -50% 0; }

.status-chip {
  position: absolute;
  z-index: 4;
  top: 12px;
  left: 50%;
  translate: -50% -12px;
  padding: 7px 12px;
  border: 1px solid #6d68a0;
  border-radius: 99px;
  background: rgb(12 13 34 / 84%);
  color: #c8c4d9;
  font-size: .64rem;
  font-weight: 900;
  letter-spacing: .12em;
  opacity: 0;
  pointer-events: none;
  transition: 160ms ease;
}
.status-chip.show { opacity: 1; translate: -50% 0; }

.overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgb(5 6 18 / 45%);
  backdrop-filter: blur(4px);
  transition: opacity 180ms ease;
}
.overlay.hidden { opacity: 0; pointer-events: none; }
.game-card {
  width: min(100%, 430px);
  padding: clamp(24px, 5vw, 36px);
  border: 1px solid #514b7b;
  border-radius: 25px;
  background: linear-gradient(145deg, rgb(25 23 54 / 97%), rgb(11 11 29 / 97%));
  box-shadow: 0 22px 80px #0009, inset 0 1px #ffffff12;
  text-align: center;
}
.eyebrow { margin: 0 0 11px; color: var(--cyan); font-size: .62rem; font-weight: 900; letter-spacing: .17em; }
.game-card h1 { margin: 0; font-size: clamp(2.25rem, 9vw, 3.6rem); line-height: .92; letter-spacing: -.075em; }
.game-card > p:not(.eyebrow) { margin: 16px auto 0; max-width: 340px; color: #bbb7cc; font-size: .9rem; line-height: 1.5; }
.controls-copy { display: flex; justify-content: center; flex-wrap: wrap; gap: 9px 14px; margin-top: 20px; color: #908ca6; font-size: .57rem; font-weight: 850; letter-spacing: .08em; }
kbd { display: inline-grid; min-width: 20px; height: 20px; margin-right: 2px; place-content: center; border: 1px solid #514d6f; border-radius: 5px; background: #211f3c; color: white; font: inherit; }
.primary-button { width: 100%; margin-top: 22px; padding: 14px 18px; border: 0; border-radius: 12px; background: linear-gradient(110deg, #5aeee2, #9f7aff 56%, #ff62cf); color: #080917; font-weight: 950; cursor: pointer; box-shadow: 0 6px 24px #695ffb45; }
.primary-button:hover { filter: brightness(1.1); transform: translateY(-1px); }

@media (pointer: coarse) {
  .mobile-controls {
    position: absolute;
    z-index: 5;
    right: 13px;
    bottom: max(13px, env(safe-area-inset-bottom));
    left: 13px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    pointer-events: none;
    opacity: 0;
    translate: 0 8px;
    transition: 140ms ease;
  }
  .game-stage.running .mobile-controls { opacity: 1; translate: 0 0; }
  .player-loadout { bottom: calc(max(13px, env(safe-area-inset-bottom)) + 82px); }
}

@media (max-width: 560px) {
  .app { grid-template-rows: 58px minmax(0, 1fr); }
  .topbar { gap: 7px; padding: 5px 9px; }
  .brand img { width: 19px; height: 28px; }
  .brand { font-size: .68rem; gap: 5px; }
  .battle-stats { gap: 10px; }
  .battle-stats span, .run-score span { font-size: .45rem; }
  .battle-stats strong, .run-score strong { font-size: .75rem; }
  .meter { width: 55px; height: 7px; }
  .tower-stat > strong { display: none; }
  .run-score { min-width: 25px; }
  .player-loadout { left: 8px; gap: 4px; }
  .player-loadout > div { min-width: 61px; padding: 6px 7px; }
  .player-loadout span { font-size: .44rem; }
  .player-loadout strong { font-size: .54rem; }
}

@media (max-height: 610px) and (orientation: landscape) {
  .app { grid-template-rows: 52px minmax(0, 1fr); }
  .topbar { padding-block: 4px; }
  .game-card { padding: 18px 24px; }
  .game-card > p:not(.eyebrow) { margin-top: 9px; }
  .controls-copy { margin-top: 11px; }
  .primary-button { margin-top: 12px; padding: 10px; }
  .steer-button { width: 68px; height: 58px; }
  .player-loadout { bottom: 8px; left: 92px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
