:root {
  --bg: #0f1020;
  --bg-2: #1a1b32;
  --fg: #eaeaf2;
  --muted: #9ba0b4;
  --accent: #f7c948;
  --pill: rgba(255, 255, 255, 0.06);
  --pill-border: rgba(255, 255, 255, 0.12);
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(1200px 800px at 50% 0%, #1c1d36 0%, var(--bg) 70%);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

#hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  gap: 8px;
  flex-wrap: wrap;
}

.hud-left,
.hud-right {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.pill {
  background: var(--pill);
  border: 1px solid var(--pill-border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  line-height: 1;
  white-space: nowrap;
}

.pill.muted {
  color: var(--muted);
}

.pill-btn {
  cursor: pointer;
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  -webkit-tap-highlight-color: transparent;
}

.pill-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

#stage {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  justify-content: center;
  gap: 12px;
  padding: 0 10px 10px;
  min-height: 0;
}

.stage-main {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
}

#game {
  position: relative;
  aspect-ratio: 1 / 1;
  width: min(92vw, calc(100dvh - 220px), calc(100vw - 220px));
  max-width: 720px;
  max-height: 720px;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  background: #0b0c1a;
}

#game canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  image-rendering: pixelated;
}

#game.spectator-pan {
  cursor: grab;
  touch-action: none;
}

#game.spectator-pan:active {
  cursor: grabbing;
}

.side-panel {
  width: 200px;
  min-width: 180px;
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 4px;
}

.side-panel-backdrop {
  display: none;
}

.side-panel-inner {
  width: 100%;
  max-height: min(720px, calc(100dvh - 120px));
  overflow-y: auto;
  border-radius: 12px;
  background: rgba(15, 16, 32, 0.75);
  border: 1px solid var(--pill-border);
  padding: 12px 14px;
}

.side-panel-mobile-header {
  display: none;
}

.leaderboard {
  margin-bottom: 14px;
}

.display-options {
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.display-heading {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 8px;
}

.display-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  margin-bottom: 8px;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.display-row:last-child {
  margin-bottom: 0;
}

.display-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.lb-heading,
.host-heading {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 8px;
}

.lb-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.lb-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 14px;
}

.lb-list li:last-child {
  border-bottom: none;
}

.lb-name {
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-score {
  color: #ffffff;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.host-panel {
  padding-top: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.host-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  margin-bottom: 10px;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.host-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.host-rounds {
  cursor: default;
}

.host-rounds input[type="number"] {
  width: 64px;
  margin-left: auto;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--pill-border);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 14px;
}

.host-action {
  width: 100%;
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--pill-border);
  background: var(--pill);
  color: var(--fg);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.host-action.primary {
  background: rgba(247, 201, 72, 0.18);
  border-color: rgba(247, 201, 72, 0.45);
  color: var(--accent);
}

.host-action:hover {
  background: rgba(255, 255, 255, 0.1);
}

.host-action.primary:hover {
  background: rgba(247, 201, 72, 0.28);
}

.lobby-wait {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
}

#game.lobby-dim {
  opacity: 0.72;
}

@media (max-width: 720px) {
  #stage {
    flex-direction: column;
    align-items: center;
    padding-bottom: 8px;
  }

  #sidePanelBtn {
    display: inline-flex !important;
  }

  .side-panel {
    display: none;
  }

  .side-panel.mobile-open {
    position: fixed;
    inset: 0;
    z-index: 260;
    display: flex;
    align-items: center;
    justify-content: center;
    width: auto;
    min-width: 0;
    padding: 16px;
  }

  .side-panel.mobile-open .side-panel-inner {
    width: min(92vw, 420px);
    max-height: min(78dvh, 640px);
    border-radius: 14px;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
    background: rgba(15, 16, 32, 0.95);
  }

  .side-panel.mobile-open .side-panel-mobile-header {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 8px;
  }

  .side-panel-close-btn {
    color: var(--muted);
  }

  #game {
    width: min(92vw, calc(100dvh - 280px));
  }

  .side-panel-backdrop.mobile-open {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 250;
    background: rgba(8, 9, 18, 0.72);
    backdrop-filter: blur(5px);
  }
}

#banner {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 16, 32, 0.92);
  border: 1px solid var(--pill-border);
  color: var(--fg);
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.2px;
  text-align: center;
  backdrop-filter: blur(6px);
  pointer-events: none;
}

#banner.hidden {
  display: none;
}

#sessionModal.hidden {
  display: none;
}

.session-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(8, 9, 18, 0.82);
  backdrop-filter: blur(8px);
}

.session-card {
  width: 100%;
  max-width: 360px;
  padding: 28px 24px;
  border-radius: 16px;
  background: var(--bg-2);
  border: 1px solid var(--pill-border);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
}

.session-title {
  text-align: center;
  margin: 0 0 20px;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

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

.session-primary {
  width: 100%;
  margin-bottom: 20px;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid rgba(247, 201, 72, 0.45);
  background: linear-gradient(180deg, rgba(247, 201, 72, 0.2) 0%, rgba(247, 201, 72, 0.08) 100%);
  color: var(--fg);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.session-primary:last-of-type {
  margin-bottom: 0;
}

.session-primary:active {
  transform: scale(0.98);
}

.session-join {
  margin-top: 8px;
  margin-bottom: 12px;
}

.session-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

#playerName {
  width: 100%;
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--pill-border);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.06em;
}

#joinCode {
  width: 100%;
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--pill-border);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.session-error {
  margin: 12px 0 0;
  font-size: 13px;
  color: #fca5a5;
  line-height: 1.35;
}

.session-error.hidden {
  display: none;
}

#roomPill {
  margin: 0;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

#roomPill.pill-btn {
  color: var(--muted);
}

#roomPill.pill-btn:hover,
#roomPill.pill-btn:focus-visible {
  color: var(--fg);
}

#roomPill.pill-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#banner .accent {
  color: var(--accent);
}

#touchControls {
  display: none;
  padding: 8px 16px 16px;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.dpad {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  align-items: center;
  justify-items: center;
}

.dpad-row {
  display: flex;
  gap: 64px;
}

.btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 1px solid var(--pill-border);
  background: var(--pill);
  color: var(--fg);
  font-size: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease;
}

.btn:active {
  background: rgba(255, 255, 255, 0.16);
  transform: scale(0.94);
}

.btn.fire {
  width: 76px;
  height: 76px;
  font-size: 28px;
  color: #f87171;
  background: rgba(248, 113, 113, 0.15);
  border-color: rgba(248, 113, 113, 0.4);
}

.btn.fire:active {
  background: rgba(248, 113, 113, 0.3);
}

.btn.fire.overheated {
  color: #64748b;
  background: rgba(100, 116, 139, 0.15);
  border-color: rgba(100, 116, 139, 0.4);
  opacity: 0.65;
}

.btn.fire.depleted,
.btn.fire:disabled {
  color: #64748b;
  background: rgba(71, 85, 105, 0.15);
  border-color: rgba(71, 85, 105, 0.4);
  opacity: 0.4;
  cursor: not-allowed;
}

#firePill {
  font-variant-numeric: tabular-nums;
  transition: color 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

#firePill.ready {
  color: #86efac;
  border-color: rgba(134, 239, 172, 0.35);
  background: rgba(134, 239, 172, 0.08);
}

#firePill.overheated {
  color: #fca5a5;
  border-color: rgba(252, 165, 165, 0.45);
  background: rgba(248, 113, 113, 0.12);
}

#firePill.depleted {
  color: #94a3b8;
  border-color: rgba(148, 163, 184, 0.45);
  background: rgba(71, 85, 105, 0.18);
  font-weight: 600;
}

/* Show virtual dpad on touch devices (and small screens as a fallback). */
@media (hover: none) and (pointer: coarse) {
  #touchControls {
    display: flex;
  }
  #game {
    width: min(92vw, calc(100dvh - 280px));
  }
}

@media (max-width: 640px) {
  #touchControls {
    display: flex;
  }
  .pill {
    font-size: 12px;
    padding: 5px 10px;
  }
}
