@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;700&family=JetBrains+Mono:wght@400;500;700&family=Press+Start+2P&display=swap');

:root {
  --bg: #0b0c0f;
  --panel: #15171c;
  --gold: #F0B90B;
  --magenta: #ff3d7f;
  --cyan: #38e8d4;
  --text: #eef0f3;
  --muted: #8a8f9a;
  --display: 'Space Grotesk', sans-serif;
  --mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--display);
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

.hidden { display: none !important; }

.screen {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

/* ---------- Login / Game Over card ---------- */

.login-card {
  background: var(--panel);
  border: 1px solid #24272e;
  border-radius: 14px;
  padding: 40px 44px;
  max-width: 480px;
  width: 90%;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0,0,0,0.5);
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 6px;
}

.brand-mark {
  color: var(--gold);
  font-size: 22px;
}

.brand-name {
  font-family: 'Press Start 2P', var(--mono);
  font-weight: 700;
  letter-spacing: 2px;
  font-size: 15px;
  line-height: 1.6;
  text-transform: uppercase;
  background: linear-gradient(180deg, #ffe27a 0%, var(--gold) 40%, #ff5a1a 72%, var(--magenta) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 18px rgba(255,90,26,0.45);
  animation: blazeFlicker 3.4s ease-in-out infinite;
}

.brand-name.hero {
  font-size: 30px;
  line-height: 1.8;
  letter-spacing: 3px;
  text-shadow: 0 0 26px rgba(255,90,26,0.55), 0 0 60px rgba(255,61,127,0.28);
}

@keyframes blazeFlicker {
  0%, 100% { filter: brightness(1); }
  46% { filter: brightness(1.08); }
  50% { filter: brightness(0.9); }
  54% { filter: brightness(1.05); }
}

@media (max-width: 520px) {
  .brand-name.hero { font-size: 18px; }
}

.tagline {
  color: var(--gold);
  font-family: var(--mono);
  font-size: 14px;
  margin: 6px 0 4px;
}

.sub {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  margin: 0 0 26px;
}

.login-btn {
  display: inline-block;
  background: var(--gold);
  color: #12100a;
  font-weight: 700;
  padding: 13px 30px;
  border-radius: 999px;
  text-decoration: none;
  letter-spacing: 0.5px;
  font-size: 14px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.login-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(240,185,11,0.25);
}

.rules {
  margin-top: 30px;
  text-align: left;
  border-top: 1px solid #24272e;
  padding-top: 20px;
  display: grid;
  gap: 9px;
}

.rule {
  font-size: 13px;
  color: var(--muted);
  font-family: var(--mono);
}

.tag {
  display: inline-block;
  background: #1f2229;
  color: var(--cyan);
  border-radius: 5px;
  padding: 2px 7px;
  margin-right: 8px;
  font-size: 12px;
}

/* ---------- War-torn title screen backdrop ---------- */

.screen.war-theme {
  background: linear-gradient(180deg, #2a1710 0%, #1a0f0c 45%, #0d0705 78%, #050303 100%);
  overflow: hidden;
}

.war-bg { position: absolute; inset: 0; z-index: 0; overflow: hidden; }
.login-card, .start-card { position: relative; z-index: 1; }

.war-glow {
  position: absolute;
  width: 46vw;
  height: 46vw;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,120,40,0.4), rgba(255,90,26,0) 70%);
  filter: blur(6px);
  animation: warGlowPulse 5s ease-in-out infinite;
}
.war-glow-a { top: -12%; left: -10%; }
.war-glow-b {
  bottom: -18%;
  right: -12%;
  background: radial-gradient(circle, rgba(255,61,80,0.3), rgba(255,61,80,0) 70%);
  animation-delay: 1.6s;
}

@keyframes warGlowPulse {
  0%, 100% { opacity: 0.55; transform: scale(1); }
  50% { opacity: 0.9; transform: scale(1.08); }
}

.war-smoke {
  position: absolute;
  width: 60vw;
  height: 30vh;
  bottom: 0;
  background: radial-gradient(ellipse at center, rgba(60,50,45,0.35), rgba(60,50,45,0) 72%);
  filter: blur(4px);
  animation: warSmokeDrift 22s linear infinite;
}
.war-smoke-a { left: -20%; animation-duration: 26s; }
.war-smoke-b { left: 40%; bottom: -6%; animation-duration: 34s; animation-delay: -8s; }

@keyframes warSmokeDrift {
  0% { transform: translateX(-8%); }
  50% { transform: translateX(8%); }
  100% { transform: translateX(-8%); }
}

.fire-layer {
  position: absolute;
  left: -2%; right: -2%; bottom: -8%;
  height: 46%;
  display: flex;
  align-items: flex-end;
  z-index: 0;
}

.flame {
  flex: 1 0 auto;
  height: 55%;
  margin: 0 -4%;
  border-radius: 50% 50% 42% 42% / 62% 62% 38% 38%;
  background: radial-gradient(ellipse at 50% 100%, #fff6c8 0%, #ffcf3d 20%, #ff8a1a 46%, #ff3d1a 74%, rgba(255,20,10,0) 100%);
  mix-blend-mode: screen;
  opacity: 0.9;
  transform-origin: bottom center;
  animation: flameFlicker 2.4s ease-in-out infinite;
}
.flame:nth-child(1) { height: 62%; animation-duration: 2.1s; }
.flame:nth-child(2) { height: 48%; animation-duration: 1.7s; animation-delay: -0.3s; }
.flame:nth-child(3) { height: 70%; animation-duration: 2.6s; animation-delay: -0.9s; }
.flame:nth-child(4) { height: 52%; animation-duration: 1.9s; animation-delay: -1.4s; }
.flame:nth-child(5) { height: 66%; animation-duration: 2.3s; animation-delay: -0.6s; }
.flame:nth-child(6) { height: 45%; animation-duration: 2s; animation-delay: -1.7s; }
.flame:nth-child(7) { height: 60%; animation-duration: 2.5s; animation-delay: -1.1s; }
.flame:nth-child(8) { height: 50%; animation-duration: 1.8s; animation-delay: -0.4s; }

@keyframes flameFlicker {
  0%, 100% { transform: scaleY(1) scaleX(1) skewX(0deg); }
  25% { transform: scaleY(1.1) scaleX(0.94) skewX(-3deg); }
  50% { transform: scaleY(0.9) scaleX(1.06) skewX(3deg); }
  75% { transform: scaleY(1.06) scaleX(0.96) skewX(-2deg); }
}

.embers { position: absolute; inset: 0; z-index: 0; overflow: hidden; }
.ember {
  position: absolute;
  left: var(--left);
  bottom: 8%;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: #ffd27a;
  box-shadow: 0 0 6px 2px rgba(255,150,40,0.85);
  opacity: 0;
  animation: emberRise var(--dur) ease-in infinite;
  animation-delay: var(--delay);
}

@keyframes emberRise {
  0% { transform: translate(0, 0) scale(1); opacity: 0; }
  12% { opacity: 1; }
  100% { transform: translate(var(--drift), -75vh) scale(0.25); opacity: 0; }
}

.war-wire {
  position: absolute;
  left: 0; right: 0; bottom: 6%;
  height: 34px;
  opacity: 0.35;
  background-repeat: repeat-x;
  background-size: 90px 34px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='90' height='34'><line x1='0' y1='17' x2='90' y2='17' stroke='%23000' stroke-width='2'/><g stroke='%23000' stroke-width='2'><line x1='15' y1='9' x2='25' y2='25'/><line x1='19' y1='9' x2='9' y2='25'/><line x1='45' y1='9' x2='55' y2='25'/><line x1='49' y1='9' x2='39' y2='25'/><line x1='75' y1='9' x2='85' y2='25'/><line x1='79' y1='9' x2='69' y2='25'/></g></svg>");
}

/* ---------- Start / title screen ---------- */

.start-profile {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 18px 0 26px;
}
.start-profile .avatar { width: 30px; height: 30px; }
.start-profile .hud-name { font-family: var(--mono); color: var(--muted); }

.play-btn {
  border: none;
  cursor: pointer;
  font-family: 'Press Start 2P', var(--mono);
  font-size: 13px;
  padding: 16px 34px;
  animation: playPulse 1.8s ease-in-out infinite;
}

@keyframes playPulse {
  0%, 100% { box-shadow: 0 0 0 rgba(240,185,11,0); }
  50% { box-shadow: 0 0 26px rgba(240,185,11,0.55); }
}

/* ---------- Game screen ---------- */

#game-screen {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
}

#hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 26px;
  background: linear-gradient(180deg, rgba(11,12,15,0.95), rgba(11,12,15,0));
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 5;
}

.hud-left, .hud-right { display: flex; align-items: center; gap: 10px; }
.hud-right { flex-direction: row-reverse; text-align: right; }

.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  object-fit: cover;
  background: #222;
}

.hud-stack { display: flex; flex-direction: column; line-height: 1.2; }
.hud-name { font-weight: 700; font-size: 14px; }
.hud-label { font-family: var(--mono); font-size: 10px; color: var(--muted); letter-spacing: 1px; }

.hud-center { display: flex; align-items: center; gap: 10px; }
.health-track {
  width: 220px; height: 10px;
  background: #1f2229;
  border-radius: 6px;
  overflow: hidden;
}
.health-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--magenta), var(--gold));
  transition: width 0.2s ease;
}
#health-text { font-family: var(--mono); font-size: 12px; color: var(--muted); }

.score {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 700;
  color: var(--gold);
}

.mute-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #1f2229;
  border: 1px solid #2c303a;
  color: var(--gold);
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
}
.mute-btn:hover { border-color: var(--gold); }

#game-canvas {
  flex: 1;
  width: 100%;
  height: 100%;
  display: block;
  background: #0b0c0f;
  cursor: crosshair;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  touch-action: none;
}

.scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    rgba(0,0,0,0.12) 0px,
    rgba(0,0,0,0.12) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: multiply;
  z-index: 4;
}

.hud-name, .score, #health-text {
  font-family: 'Press Start 2P', var(--mono);
}

.hud-name { font-size: 11px; }
.score { font-size: 16px; }
#health-text { font-size: 10px; }

.pill {
  position: absolute;
  top: 60px; left: 50%;
  transform: translateX(-50%);
  background: #1f2229;
  border: 1px solid #2c303a;
  padding: 6px 14px;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  z-index: 5;
}

.pill.live { border-color: var(--gold); color: var(--gold); }

.wave-pill {
  left: auto;
  right: 26px;
  transform: none;
  border-color: var(--gold);
  color: var(--gold);
  font-family: 'Press Start 2P', var(--mono);
  font-size: 10px;
}

.weapon-pill {
  left: auto;
  right: 26px;
  top: 100px;
  transform: none;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 1px;
}

.weapon-bar-track {
  width: 50px;
  height: 5px;
  background: #1f2229;
  border-radius: 3px;
  overflow: hidden;
}

.weapon-bar-fill {
  height: 100%;
  width: 100%;
  background: currentColor;
  transition: width 0.1s linear;
}

.shield-pill {
  left: auto;
  right: 26px;
  top: 140px;
  transform: none;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 1px;
}

.shield-pill.ready { border-color: var(--cyan); color: var(--cyan); }
.shield-pill.cooldown { border-color: #2c303a; color: var(--muted); }

/* ---------- Mobile touch controls ---------- */

.mobile-controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
}

.joystick-base {
  position: absolute;
  left: 30px;
  bottom: calc(46px + env(safe-area-inset-bottom));
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(21,23,28,0.6);
  border: 2px solid #2c303a;
  pointer-events: auto;
  touch-action: none;
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  margin-left: -26px;
  margin-top: -26px;
  border-radius: 50%;
  background: rgba(240,185,11,0.35);
  border: 2px solid var(--gold);
  pointer-events: none;
}

.joystick-knob.active { background: rgba(240,185,11,0.6); }

.shoot-btn {
  position: absolute;
  right: 30px;
  bottom: calc(40px + env(safe-area-inset-bottom));
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: rgba(255,61,127,0.2);
  border: 2px solid var(--magenta);
  color: var(--magenta);
  font-size: 24px;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.shoot-btn:active, .shoot-btn.active { background: rgba(255,61,127,0.5); }

.shield-btn {
  position: absolute;
  right: 118px;
  bottom: calc(60px + env(safe-area-inset-bottom));
  width: 54px;
  height: 54px;
  border-radius: 50%;
  font-size: 18px;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.shield-btn.ready {
  background: rgba(56,232,212,0.2);
  border: 2px solid var(--cyan);
  color: var(--cyan);
}

.shield-btn.cooldown {
  background: rgba(31,34,41,0.85);
  border: 2px solid #2c303a;
  color: var(--muted);
}

.shield-btn.ready:active { background: rgba(56,232,212,0.5); }

/* Signature element: a stream-chat ticker fused to the bottom of the arena,
   so the thing driving the gameplay is always visibly present on screen. */
.ticker {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 40px;
  background: rgba(11,12,15,0.9);
  border-top: 1px solid #24272e;
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 0 18px;
  overflow: hidden;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  z-index: 5;
}

.ticker-item { display: inline-flex; gap: 6px; align-items: center; opacity: 0; animation: tickerIn 0.25s ease forwards; }
.ticker-item b { color: var(--gold); }
.ticker-item.effect b { color: var(--cyan); }

@keyframes tickerIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.leaderboard {
  margin-top: 24px;
  text-align: left;
  border-top: 1px solid #24272e;
  padding-top: 16px;
}

.lb-row {
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 13px;
  padding: 5px 0;
  color: var(--muted);
}

.lb-row.me { color: var(--gold); }
.lb-row span:first-child { color: var(--text); }

/* ---------- Narrow-screen fixes (HUD overflow + pill overlap) ---------- */

@media (max-width: 520px) {
  #hud { padding: 10px 12px; }
  .hud-stack { max-width: 110px; overflow: hidden; }
  .hud-name { font-size: 9px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
  .avatar { width: 26px; height: 26px; }
  .health-track { width: 100px; }
  #health-text { font-size: 8px; }
  .score { font-size: 12px; }

  .pill { font-size: 9px; padding: 5px 9px; }

  #connection-pill {
    left: 12px;
    right: auto;
    top: 60px;
    transform: none;
    max-width: 44%;
    text-align: left;
  }

  .wave-pill { top: 60px; }
  .weapon-pill { top: 96px; }
  .shield-pill { top: 132px; }

  .joystick-base {
    left: 18px;
    bottom: calc(46px + env(safe-area-inset-bottom));
  }
  .shoot-btn {
    right: 18px;
    bottom: calc(46px + env(safe-area-inset-bottom));
  }
  .shield-btn {
    right: 106px;
    bottom: calc(60px + env(safe-area-inset-bottom));
  }
}

/* Landscape / short viewport - height is the constraint here, not width.
   Compacts the HUD further and shrinks + tucks the touch controls so
   nothing overlaps the bottom chat ticker in the reduced vertical space. */
@media (max-height: 500px) {
  #hud { padding: 6px 10px; }
  .hud-stack { max-width: 90px; overflow: hidden; }
  .hud-name { font-size: 8px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
  .avatar { width: 22px; height: 22px; }
  .health-track { width: 80px; height: 8px; }
  #health-text { font-size: 7px; }
  .score { font-size: 11px; }

  .pill { font-size: 8px; padding: 3px 7px; }

  #connection-pill {
    left: 10px;
    right: auto;
    top: 38px;
    transform: none;
    max-width: 38%;
    text-align: left;
  }

  .wave-pill { top: 38px; }
  .weapon-pill { top: 64px; }
  .shield-pill { top: 90px; }

  .ticker { height: 24px; font-size: 9px; gap: 10px; padding: 0 10px; }

  .joystick-base {
    left: 14px;
    bottom: calc(30px + env(safe-area-inset-bottom));
  }
  .shoot-btn {
    right: 14px;
    bottom: calc(30px + env(safe-area-inset-bottom));
  }
  .shield-btn {
    right: 102px;
    bottom: calc(44px + env(safe-area-inset-bottom));
  }
}
