:root {
  --bg: rgba(8, 12, 20, 0.7);
  --panel: rgba(17, 23, 34, 0.74);
  --panel-strong: rgba(12, 18, 29, 0.9);
  --border: rgba(255, 255, 255, 0.12);
  --text: #edf2f4;
  --muted: rgba(237, 242, 244, 0.72);
  --accent: #ffd166;
  --accent-2: #54d4ff;
  --ok: #06d6a0;
  --danger: #ff5d73;
  --shadow: 0 16px 50px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  overflow: hidden;
  background: radial-gradient(circle at top, #1b2435 0%, #0b0f14 60%);
  color: var(--text);
  font-family: Inter, system-ui, sans-serif;
}
button { font: inherit; }
#game { width: 100vw; height: 100vh; display: block; }

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  display: grid;
  grid-template-columns: 320px 1fr 340px;
  grid-template-rows: auto auto 1fr;
  gap: 12px;
  padding: 12px;
}
.panel {
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02)), var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px 16px;
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
  pointer-events: auto;
}
.brand-panel, .hero-panel { background: linear-gradient(135deg, rgba(84,212,255,0.12), rgba(255,209,102,0.08)), var(--panel-strong); }
.title { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.title h1, .panel h2, .panel h3 { margin: 0 0 8px; }
.title p, .panel p, li { color: var(--muted); }
.eyebrow { text-transform: uppercase; letter-spacing: 0.16em; font-size: 11px; color: var(--accent-2); }
.info { grid-column: 2; display: flex; flex-direction: column; gap: 10px; align-self: start; }
.hero-topline { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.meta-row { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 14px; }
.debug-row { align-items: center; }

.boost-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.boost-meter {
  position: relative;
  flex: 1 1 240px;
  height: 16px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.14);
}
.boost-meter-fill,
.boost-meter-glow {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: inherit;
  transition: width 120ms ease;
}
.boost-meter-fill {
  background: linear-gradient(90deg, #06d6a0, #80ed99, #d9ff70);
}
.boost-meter-glow {
  opacity: 0.32;
  filter: blur(10px);
  background: #80ed99;
}
.boost-sidecar { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; min-width: 120px; }
.boost-label {
  min-width: 110px;
  text-align: right;
  font-size: 13px;
  font-weight: 800;
  color: #d9ff70;
}
.airtime-badge { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.impact-badge, .hazard-badge { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; transition: color 140ms ease, text-shadow 140ms ease, opacity 140ms ease; }
.impact-badge { color: #ffd166; }
.impact-badge.hot { color: #ff7b7b; text-shadow: 0 0 14px rgba(255, 107, 107, 0.55); }
.hazard-badge { color: #9ad1ff; opacity: 0.72; }
.hazard-badge.active { opacity: 1; }
.hazard-badge.hot { color: #fca5a5; text-shadow: 0 0 14px rgba(252, 165, 165, 0.45); }
.hazard-edge-arrow {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 16;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 74px;
  pointer-events: none;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 0 16px rgba(0, 0, 0, 0.45));
}
.hazard-edge-arrow.hidden { display: none; }
.hazard-edge-arrow[data-kind="trap"] { color: #fbbf24; }
.hazard-edge-arrow[data-kind="oil"] { color: #93c5fd; }
.hazard-edge-arrow.hot .hazard-edge-icon { text-shadow: 0 0 18px currentColor; }
.hazard-edge-icon {
  display: block;
  font-size: 24px;
  line-height: 1;
  font-weight: 900;
}
.hazard-edge-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  background: rgba(8, 12, 20, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #f8fafc;
  white-space: nowrap;
}
.debug-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  color: var(--text);
}
.debug-stats.hidden { display: none; }
.debug-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(84, 212, 255, 0.12);
  border: 1px solid rgba(84, 212, 255, 0.2);
}
.timer-pill, .badge {
  display: inline-flex; align-items: center; gap: 8px;
  border-radius: 999px; padding: 6px 10px; background: rgba(255,255,255,0.08); font-weight: 700;
}
.hero-actions, .camera-controls-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.camera-controls-inline label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent-2);
}
.camera-controls-inline select {
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.16);
  background: rgba(255,255,255,0.08);
  color: var(--text);
  padding: 8px 10px;
}
.scoreboard { grid-column: 3; grid-row: 1 / span 2; }
.browser-panel { grid-column: 2; grid-row: 2; }
.chat { grid-column: 1; grid-row: 2 / span 2; overflow: hidden; }
.shop { grid-column: 2; grid-row: 3; align-self: end; display: none; max-width: 900px; }
.shop.active { display: block; }
.panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

#scoreboard, #chat { list-style: none; padding: 0; margin: 0; }
#scoreboard li, #chat li {
  display: flex; justify-content: space-between; gap: 10px; padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.08); font-size: 14px;
}
#chat li { display: block; }

.card-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.card-row.compact { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.info-card, .shop-card, .profile-card {
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04);
  border-radius: 14px;
  padding: 10px;
}
.info-card.active { outline: 2px solid rgba(84,212,255,0.45); background: rgba(84,212,255,0.08); }
.shop-group { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.shop-card { width: 180px; }
.shop-card button, .primary-button, .ghost-button {
  margin-top: 8px; border-radius: 10px; padding: 10px 12px; font-weight: 700; cursor: pointer;
}
.shop-card button, .primary-button { width: 100%; background: linear-gradient(135deg, var(--accent), #ffb703); color: #111; border: 0; }
.ghost-button { background: rgba(255,255,255,0.06); color: var(--text); border: 1px solid rgba(255,255,255,0.14); }
.small { width: auto; padding: 8px 10px; font-size: 13px; }
.lobby-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 12px; }
.lobby-actions.compact-actions { margin-top: 12px; }
.room-card { display: grid; gap: 8px; }
.room-meta { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); }
.room-badge-row { display: flex; flex-wrap: wrap; gap: 6px; }
.room-badge { padding: 4px 8px; border-radius: 999px; background: rgba(255,255,255,0.08); font-size: 12px; }
.room-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.room-actions button {
  flex: 1 1 120px;
  margin-top: 0;
  border-radius: 10px;
  padding: 10px 12px;
  font-weight: 700;
  cursor: pointer;
  border: 0;
  background: linear-gradient(135deg, var(--accent), #ffb703);
  color: #111;
}
.room-actions button:disabled { opacity: 0.45; cursor: not-allowed; }
.shop-card button:disabled { opacity: 0.45; cursor: not-allowed; }
.stat-line { display: flex; justify-content: space-between; font-size: 13px; opacity: 0.92; }
.ok { color: var(--ok); } .danger { color: var(--danger); }
.profile-card { display: grid; gap: 10px; }
.profile-pill-row { display: flex; flex-wrap: wrap; gap: 8px; }
.profile-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 999px;
  background: rgba(255,255,255,0.08); font-size: 13px;
}
.profile-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.profile-stat {
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 8px;
  background: rgba(255,255,255,0.03);
}
.profile-stat strong { display: block; font-size: 18px; margin-bottom: 4px; }
.profile-hint { font-size: 13px; color: var(--muted); }

.overlay {
  position: fixed; inset: 0; z-index: 25; display: none; align-items: center; justify-content: center;
  background: radial-gradient(circle at top, rgba(84,212,255,0.12), rgba(0,0,0,0.7)); padding: 18px;
}
.overlay.active { display: flex; }
.overlay-card {
  width: min(1100px, 100%); max-height: min(90vh, 920px); overflow: auto;
  background: linear-gradient(180deg, rgba(14,20,32,0.98), rgba(10,14,24,0.98)); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 24px; padding: 20px; box-shadow: 0 24px 60px rgba(0,0,0,0.4);
}
.menu-header { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 20px; }
.menu-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.menu-grid { display: grid; gap: 18px; }
.control-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.control-columns ul { margin: 8px 0 0; padding-left: 18px; }

#crosshair {
  position: fixed; left: 50%; top: 50%; width: 8px; height: 8px; border-radius: 50%;
  transform: translate(-50%, -50%); border: 1px solid rgba(255,255,255,0.4); opacity: 0.3; pointer-events: none;
}

body.desktop-focused .gameplay-overlay-panel {
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}
body.desktop-focused.show-gameplay-overlays .gameplay-overlay-panel,
body.desktop-focused.overlay-open .gameplay-overlay-panel,
body.desktop-focused.menu-open .gameplay-overlay-panel,
body.desktop-focused .shop.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.meta-overlay-dock {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 21;
  display: flex;
  gap: 8px;
  pointer-events: auto;
}
.meta-overlay-panel {
  position: fixed;
  right: 14px;
  top: 88px;
  width: min(380px, calc(100vw - 28px));
  max-height: calc(100vh - 120px);
  overflow: auto;
  z-index: 22;
  border-radius: 20px;
  padding: 14px;
  background: linear-gradient(180deg, rgba(14,20,32,0.97), rgba(10,14,24,0.95));
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}
.meta-overlay-panel.hidden { display: none; }
.meta-overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.meta-overlay-section {
  display: grid;
  gap: 10px;
}
body.menu-open .meta-overlay-dock,
body.menu-open .meta-overlay-panel {
  display: none;
}

body.active-match .brand-panel,
body.active-match .gameplay-overlay-panel,
body.active-match #metaOverlayDock,
body.active-match #metaOverlayPanel,
body.active-match #overlayToggleButton,
body.active-match .hero-panel .camera-controls-inline {
  display: none;
}
body.active-match .hero-panel {
  max-width: min(760px, calc(100vw - 24px));
}
body.active-match .hero-topline {
  align-items: flex-start;
}
body.active-match .hero-actions {
  justify-content: flex-end;
}
body.active-match .meta-row {
  gap: 8px;
}
body.active-match .hero-panel #inputSummary {
  display: none;
}
body.active-match:not(.intermission-active) .shop {
  display: none !important;
}
body.using-touch.active-match #hud {
  display: none;
}
body.using-touch.active-match .menu-shell,
body.using-touch.active-match .gameplay-overlay-panel,
body.using-touch.active-match .meta-overlay-dock,
body.using-touch.active-match .meta-overlay-panel {
  display: none !important;
}
body.using-touch.active-match.mobile-menu-open #hud {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto auto auto;
  gap: 8px;
  padding: 8px;
}
body.using-touch.active-match.mobile-menu-open .panel {
  display: block;
}
body.using-touch.active-match.mobile-menu-open .brand-panel,
body.using-touch.active-match.mobile-menu-open .hero-panel,
body.using-touch.active-match.mobile-menu-open .shop,
body.using-touch.active-match.mobile-menu-open .meta-overlay-panel {
  pointer-events: auto;
}
body.using-touch.active-match.mobile-menu-open .brand-panel,
body.using-touch.active-match.mobile-menu-open .hero-panel,
body.using-touch.active-match.mobile-menu-open .shop {
  grid-column: 1;
}
body.using-touch.active-match.mobile-menu-open .brand-panel {
  grid-row: 1;
}
body.using-touch.active-match.mobile-menu-open .hero-panel {
  grid-row: 2;
}
body.using-touch.active-match.mobile-menu-open .shop.active {
  grid-row: 3;
  display: block !important;
}
body.using-touch.active-match.mobile-menu-open .menu-shell,
body.using-touch.active-match.mobile-menu-open .gameplay-overlay-panel,
body.using-touch.active-match.mobile-menu-open .meta-overlay-dock,
body.using-touch.active-match.mobile-menu-open .meta-overlay-panel {
  display: none !important;
}
body.using-touch.active-match:not(.mobile-menu-open) .shop {
  display: none !important;
}
.touch-left-column {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
}
.touch-button.utility {
  width: 96px;
  height: 52px;
  border-radius: 18px;
  background: rgba(8, 12, 20, 0.72);
  backdrop-filter: blur(12px);
}

.touch-hud {
  position: fixed; inset: 0; z-index: 20; pointer-events: none; display: flex; justify-content: space-between; align-items: flex-end; padding: 20px;
}
.touch-hud.hidden { display: none; }
.touch-zone, .touch-button { pointer-events: auto; user-select: none; touch-action: none; }
.stick-zone {
  width: 150px; height: 150px; position: relative; border-radius: 50%; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.12);
}
.stick-ring { position: absolute; inset: 18px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.12); }
.stick-knob { position: absolute; left: 50%; top: 50%; width: 60px; height: 60px; border-radius: 50%; transform: translate(-50%, -50%); background: rgba(255,255,255,0.18); }
.touch-right-column { display: flex; flex-direction: column; align-items: flex-end; gap: 14px; }
.look-zone {
  width: 190px; height: 110px; border-radius: 20px; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); position: relative;
}
.zone-label { position: absolute; right: 12px; top: 10px; font-size: 12px; letter-spacing: 0.14em; color: var(--muted); }
.touch-buttons { display: grid; gap: 10px; }
.touch-buttons-top { grid-template-columns: repeat(2, 88px); }
.touch-buttons-bottom { grid-template-columns: repeat(2, 88px); }
.touch-button { height: 88px; border-radius: 20px; border: 1px solid rgba(255,255,255,0.14); color: white; font-weight: 800; }
.touch-button.primary { background: rgba(6,214,160,0.24); }
.touch-button.secondary { background: rgba(255,209,102,0.18); }
.touch-button.action { background: rgba(84,212,255,0.22); }
.touch-button.boost { background: rgba(128,237,153,0.26); color: #f3ffe8; box-shadow: 0 0 18px rgba(128,237,153,0.18); }
.touch-button.active { transform: scale(0.97); filter: brightness(1.15); }

@media (max-width: 1180px) {
  #hud { grid-template-columns: 1fr; grid-template-rows: auto auto auto auto auto; }
  .info, .scoreboard, .chat, .shop, .browser-panel { grid-column: 1; grid-row: auto; }
  .control-columns { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  #hud { padding: 8px; gap: 8px; }
  .panel { padding: 12px; border-radius: 16px; }
  .title, .hero-topline, .menu-header { flex-direction: column; }
  .scoreboard, .chat, .browser-panel { display: none; }
  .meta-row { font-size: 13px; }
  .meta-overlay-dock { right: 8px; bottom: 8px; }
  .meta-overlay-panel { top: auto; bottom: 64px; right: 8px; width: calc(100vw - 16px); max-height: 58vh; }
}
@media (pointer: coarse) and (max-width: 1024px) {
  #crosshair { display: none; }
}
