html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  background: #0a0806;
  color: #ecdfc8;
  overflow: hidden;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.hidden { display: none !important; }

#lobby-screen {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  box-sizing: border-box;
  background:
    radial-gradient(ellipse at 50% 120%, rgba(255, 157, 77, 0.14), transparent 60%),
    linear-gradient(#0a0806, #120d08);
}

.lobby-panel {
  width: min(760px, 100%);
  background: rgba(20, 14, 9, 0.94);
  border: 1px solid #5a4326;
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
}

.lobby-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 18px;
}

h1 { margin: 0; font-size: 26px; color: #ffb838; }

p { margin: 5px 0 0; color: #b09a78; font-size: 13px; }

.room-pill {
  border: 1px solid #74582f;
  background: #1a130b;
  border-radius: 6px;
  padding: 8px 10px;
  color: #b09a78;
  white-space: nowrap;
}

#room-code { color: #ffffff; font-weight: 700; }

.player-slots {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.player-slot {
  min-height: 92px;
  border: 1px solid #3d2f1c;
  border-left: 4px solid var(--player-color, #3d2f1c);
  border-radius: 8px;
  background: rgba(26, 19, 11, 0.9);
  padding: 10px;
  box-sizing: border-box;
}

.player-slot.connected {
  border-color: color-mix(in srgb, var(--player-color) 70%, #3d2f1c);
}

.player-slot.is-ready {
  background: rgba(58, 44, 20, 0.92);
  border-color: #b58a3a;
  box-shadow: inset 0 0 12px rgba(255, 184, 56, 0.15);
}

.ready-badge {
  background: #7a5c1e;
  color: #ffe8b0;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
  animation: ready-pulse 1.5s ease-in-out infinite;
}

@keyframes ready-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.slot-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: #b09a78;
  font-size: 11px;
}

.slot-name {
  margin: 14px 0 4px;
  color: #ffffff;
  font-size: 15px;
  min-height: 18px;
}

.lobby-help {
  margin-top: 14px;
  padding: 10px 12px;
  border: 1px dashed #4a3820;
  border-radius: 6px;
  color: #b09a78;
  font-size: 12px;
  line-height: 1.5;
}

.lobby-actions { display: flex; gap: 10px; margin-top: 16px; }

button {
  height: 38px;
  border: 1px solid #74582f;
  border-radius: 6px;
  background: #241a10;
  color: #ecdfc8;
  font: inherit;
  cursor: pointer;
}

button:disabled { cursor: default; opacity: 0.55; }

.ready-btn { flex: 1; background: #5a3f16; border-color: #c89540; }
.ready-btn.is-ready { background: #2c4a1e; border-color: #8ac860; }

.copy-btn { width: 190px; }

.lobby-status {
  margin-top: 12px;
  color: #b09a78;
  font-size: 12px;
  min-height: 16px;
  transition: all 0.2s ease;
}

.lobby-status.countdown-active {
  font-size: 28px;
  font-weight: 700;
  color: #ffb838;
  text-align: center;
  padding: 16px 0;
  animation: countdown-pulse 1s ease-in-out infinite;
}

@keyframes countdown-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.05); opacity: 0.9; }
}

#game-wrap {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #0a0806;
}

#game {
  display: block;
  aspect-ratio: 16 / 9;
  width: min(1280px, 100vw, 177.7778vh);
  width: min(1280px, 100vw, 177.7778dvh);
  height: auto;
  max-height: min(720px, 100vh);
  max-height: min(720px, 100dvh);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: crosshair;
  background: #0a0806;
}

#game-wrap:fullscreen,
#game-wrap:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0a0806;
}

#game-wrap:fullscreen #game,
#game-wrap:-webkit-full-screen #game {
  width: min(1280px, 100vw, 177.7778vh);
  width: min(1280px, 100vw, 177.7778dvh);
  height: auto;
  max-height: min(720px, 100vh);
  max-height: min(720px, 100dvh);
}

/* Device badge in lobby */
.device-badge {
  margin-top: 10px;
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 4px;
  display: inline-block;
}
.device-badge.is-mobile { background: #2a1f3d; border: 1px solid #8a6abf; color: #c8a8f0; }
.device-badge.is-desktop { background: #2a2213; border: 1px solid #8a7040; color: #d8c090; }

/* ── Touch controls overlay ─────────────────────────────────────────────── */
.touch-controls {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  --touch-edge-margin: clamp(34px, 5vmin, 48px);
  --touch-safe-bottom: max(var(--touch-edge-margin), env(safe-area-inset-bottom));
  --touch-safe-side: max(var(--touch-edge-margin), env(safe-area-inset-left));
  --touch-safe-right: max(var(--touch-edge-margin), env(safe-area-inset-right));
  --touch-size: clamp(163px, 38.5vw, 218px);
  --fire-size: clamp(132px, 24.75vw, 171px);
  --touch-btn-size: clamp(70px, 13vw, 84px);
  --touch-gap: clamp(18px, 3.2vw, 26px);
  --upper-action-gap: clamp(14px, 2.4vw, 20px);
}
#game-wrap:fullscreen .touch-controls,
#game-wrap:-webkit-full-screen .touch-controls {
  --touch-edge-margin: clamp(48px, 8vmin, 72px);
}
.joystick-zone {
  position: absolute;
  bottom: var(--touch-safe-bottom);
  width: var(--touch-size);
  height: var(--touch-size);
  pointer-events: auto;
  touch-action: none;
  --stick-x: 0px;
  --stick-y: 0px;
  --stick-scale: 1;
  opacity: 0.5;
}
.joystick-left { left: var(--touch-safe-side); }
.joystick-left::before,
.joystick-left::after,
.fire-control::before,
.fire-control::after {
  content: "";
  position: absolute;
  pointer-events: none;
}
.joystick-left::before {
  inset: 10px;
  border: 3px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  background:
    radial-gradient(circle at center, rgba(255, 255, 255, 0.2) 0 24%, transparent 25%),
    rgba(28, 22, 14, 0.66);
  box-shadow: 0 0 22px rgba(0, 0, 0, 0.5), inset 0 0 24px rgba(255, 200, 120, 0.12);
}
.joystick-left::after {
  left: 50%;
  top: 50%;
  width: 34%;
  height: 34%;
  transform: translate(calc(-50% + var(--stick-x)), calc(-50% + var(--stick-y))) scale(var(--stick-scale));
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.68);
  background: rgba(240, 230, 210, 0.58);
  box-shadow: 0 5px 16px rgba(0, 0, 0, 0.38);
  transition: transform 70ms ease-out;
}
.joystick-left.is-active::before {
  border-color: rgba(255, 216, 130, 0.8);
  box-shadow: 0 0 28px rgba(255, 184, 56, 0.22), inset 0 0 26px rgba(255, 200, 120, 0.22);
}
.joystick-right {
  right: var(--touch-safe-right);
  width: var(--fire-size);
  height: var(--fire-size);
  border-radius: 50%;
  z-index: 3;
}
.fire-control::before {
  inset: 0;
  border: 3px solid rgba(255, 224, 138, 0.88);
  border-radius: 50%;
  background:
    radial-gradient(circle at center, transparent 0 16%, rgba(255, 224, 138, 0.52) 17% 19%, transparent 20%),
    linear-gradient(rgba(255, 224, 138, 0.34), rgba(255, 122, 62, 0.3)),
    rgba(54, 38, 18, 0.84);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5), inset 0 0 18px rgba(255, 224, 138, 0.26);
}
.fire-control::after {
  left: 50%;
  top: 50%;
  width: 48%;
  height: 48%;
  transform: translate(calc(-50% + var(--stick-x)), calc(-50% + var(--stick-y))) scale(var(--stick-scale));
  border: 3px solid rgba(255, 245, 190, 0.9);
  border-radius: 50%;
  background:
    linear-gradient(90deg, transparent 0 45%, rgba(255, 245, 190, 0.9) 46% 54%, transparent 55%),
    linear-gradient(0deg, transparent 0 45%, rgba(255, 245, 190, 0.9) 46% 54%, transparent 55%);
  box-shadow: 0 0 16px rgba(255, 226, 122, 0.28);
  transition: transform 70ms ease-out;
}
.fire-control.is-active::before {
  border-color: rgba(255, 246, 170, 0.98);
  box-shadow: 0 0 30px rgba(255, 195, 74, 0.34), inset 0 0 24px rgba(255, 232, 120, 0.34);
}
.joystick-zone .nipple { opacity: 0.88 !important; }

.touch-btn {
  position: absolute;
  pointer-events: auto;
  width: var(--touch-btn-size);
  height: var(--touch-btn-size);
  border-radius: 50%;
  font-size: clamp(12px, 2.6vw, 15px);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(255,255,255,0.66);
  background: rgba(50, 38, 22, 0.84);
  color: #ffffff;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.44), inset 0 0 14px rgba(255, 255, 255, 0.08);
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  z-index: 2;
  opacity: 0.5;
  transition: transform 70ms ease-out, background 90ms ease;
}
.touch-btn:active,
.touch-btn.is-pressed {
  transform: scale(0.94);
  border-color: rgba(255, 230, 170, 0.92);
  background: rgba(150, 110, 50, 0.95);
}
.touch-fullscreen {
  width: clamp(48px, 9vw, 58px);
  height: clamp(48px, 9vw, 58px);
  right: var(--touch-safe-right);
  top: max(14px, env(safe-area-inset-top));
  background: rgba(30, 26, 18, 0.84);
  z-index: 4;
}
.fullscreen-icon {
  display: block;
  width: clamp(24px, 4.6vw, 30px);
  height: clamp(24px, 4.6vw, 30px);
  background:
    linear-gradient(#ffffff, #ffffff) left top / 10px 3px no-repeat,
    linear-gradient(#ffffff, #ffffff) left top / 3px 10px no-repeat,
    linear-gradient(#ffffff, #ffffff) right top / 10px 3px no-repeat,
    linear-gradient(#ffffff, #ffffff) right top / 3px 10px no-repeat,
    linear-gradient(#ffffff, #ffffff) left bottom / 10px 3px no-repeat,
    linear-gradient(#ffffff, #ffffff) left bottom / 3px 10px no-repeat,
    linear-gradient(#ffffff, #ffffff) right bottom / 10px 3px no-repeat,
    linear-gradient(#ffffff, #ffffff) right bottom / 3px 10px no-repeat;
}
/* SEAT sits left of the fire stick, UPG + FIX above it, DROP above the move stick */
.touch-seat {
  right: calc(var(--touch-safe-right) + var(--fire-size) + var(--touch-gap));
  bottom: var(--touch-safe-bottom);
}
.touch-upgrade {
  right: calc(var(--touch-safe-right) + (var(--fire-size) - var(--touch-btn-size) * 2 - var(--upper-action-gap)) / 2 + var(--touch-btn-size) + var(--upper-action-gap));
  bottom: min(
    calc(var(--touch-safe-bottom) + var(--fire-size) + var(--upper-action-gap)),
    calc(100dvh - var(--touch-btn-size) - 8px)
  );
}
.touch-repair {
  right: calc(var(--touch-safe-right) + (var(--fire-size) - var(--touch-btn-size) * 2 - var(--upper-action-gap)) / 2);
  bottom: min(
    calc(var(--touch-safe-bottom) + var(--fire-size) + var(--upper-action-gap)),
    calc(100dvh - var(--touch-btn-size) - 8px)
  );
}
.touch-drop {
  left: var(--touch-safe-side);
  bottom: calc(var(--touch-safe-bottom) + var(--touch-size) + var(--upper-action-gap));
}

/* ── portrait rotate prompt (mobile only) ──────────────────────────────── */
#rotate-overlay {
  position: fixed; inset: 0;
  display: none;
  flex-direction: column; align-items: center; justify-content: center;
  gap: 14px;
  background: #14100a;
  z-index: 200;
  text-align: center;
}
#rotate-phone {
  width: 42px; height: 72px;
  border: 4px solid #ecdfc8;
  border-radius: 8px;
  animation: rotate-hint 1.8s ease-in-out infinite;
}
@keyframes rotate-hint {
  0%, 25%  { transform: rotate(0deg); }
  60%, 90% { transform: rotate(-90deg); }
  100%     { transform: rotate(-90deg); }
}
#rotate-text { font-size: 20px; font-weight: bold; letter-spacing: 2px; color: #ecdfc8; }
#rotate-sub  { font-size: 12px; color: #8a8478; }
@media (orientation: portrait) and (pointer: coarse) {
  #rotate-overlay { display: flex; }
}

#reconnect-banner {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  background: #a02818; color: #fff;
  font-size: 13px; font-weight: bold; letter-spacing: 2px;
  padding: 8px 20px; border-radius: 4px;
  z-index: 40;
}

@media (max-width: 720px) {
  #lobby-screen { align-items: stretch; padding: 12px; overflow: auto; }
  .lobby-header, .lobby-actions { flex-direction: column; }
  .player-slots { grid-template-columns: 1fr 1fr; }
  .copy-btn { width: 100%; }
  #game {
    cursor: default;
    width: min(100vw, 177.7778vh);
    width: min(100vw, 177.7778dvh);
    height: auto;
    max-height: 100vh;
    max-height: 100dvh;
  }
}
