:root {
  --deep: #041822;
  --mid: #0a3a4a;
  --foam: #c8f0ea;
  --accent: #2ec4b6;
  --warn: #ff6b4a;
  --ink: #e8fbff;
  --muted: #8eb8c4;
  --panel: rgba(6, 28, 38, 0.82);
  --line: rgba(46, 196, 182, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--deep);
  color: var(--ink);
  font-family: "Outfit", system-ui, sans-serif;
}

.screen {
  min-height: 100vh;
  position: relative;
}

#lobby {
  display: grid;
  place-content: start center;
  gap: 1.5rem;
  padding: 4rem 1.25rem 3rem;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(46, 196, 182, 0.22), transparent 60%),
    linear-gradient(180deg, #063447 0%, #041822 55%, #021018 100%);
  overflow: hidden;
}

.bg-glow {
  position: absolute;
  inset: auto -20% -30% -20%;
  height: 55vh;
  background: radial-gradient(ellipse at center, rgba(20, 90, 110, 0.35), transparent 70%);
  pointer-events: none;
}

.brand {
  position: relative;
  text-align: center;
  max-width: 40rem;
  z-index: 1;
}

.brand-mark {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  letter-spacing: 0.28em;
  font-size: clamp(1.6rem, 5vw, 2.6rem);
  color: var(--foam);
}

.brand h1 {
  margin: 0.6rem 0 0;
  font-size: clamp(1.1rem, 2.8vw, 1.55rem);
  font-weight: 600;
  color: var(--ink);
}

.lede {
  margin: 0.75rem auto 0;
  max-width: 32rem;
  color: var(--muted);
  line-height: 1.45;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.panel {
  position: relative;
  z-index: 1;
  width: min(420px, 100%);
  padding: 1.25rem;
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  display: grid;
  gap: 0.9rem;
}

.panel.center { text-align: center; margin: auto; }

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

input {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 1px solid rgba(200, 240, 234, 0.18);
  background: rgba(2, 16, 24, 0.65);
  color: var(--ink);
  font: inherit;
  outline: none;
}

input:focus { border-color: var(--accent); }

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: stretch;
}

.join-row {
  display: flex;
  gap: 0.45rem;
  flex: 1;
  min-width: 180px;
}

button {
  border: 0;
  padding: 0.75rem 1rem;
  background: var(--accent);
  color: #042028;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease;
}

button:hover { filter: brightness(1.08); transform: translateY(-1px); }
button.ghost {
  background: transparent;
  color: var(--foam);
  border: 1px solid var(--line);
}

.error {
  margin: 0;
  color: var(--warn);
  font-size: 0.9rem;
}

.muted { margin: 0; color: var(--muted); font-size: 0.85rem; }

.visibility {
  margin: 0 0 0.85rem;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--line);
}

.visibility legend {
  padding: 0 0.35rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.visibility .radio {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0.35rem 0;
  font-weight: 600;
  cursor: pointer;
}

.visibility input {
  width: auto;
  margin: 0;
}

button.small {
  padding: 0.4rem 0.7rem;
  font-size: 0.8rem;
}

.public-list-title {
  margin: 0.15rem 0 0;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: 1.05rem;
}

.public-lobby-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.public-lobby-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  background: rgba(2, 16, 24, 0.35);
}

.public-lobby-meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.public-lobby-meta strong {
  font-family: "Space Grotesk", sans-serif;
  color: var(--foam);
}

.public-lobby-meta span {
  font-size: 0.8rem;
  color: var(--muted);
}

.public-empty {
  margin: 0.75rem 0 0;
}

.code {
  margin: 0.2rem 0 0;
  font-family: "Space Grotesk", sans-serif;
  font-size: 2rem;
  letter-spacing: 0.2em;
  color: var(--foam);
}

.room-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: end;
}

.player-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

.player-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid rgba(200, 240, 234, 0.12);
  background: rgba(0, 0, 0, 0.2);
  font-size: 0.92rem;
}

.role-btns { display: flex; gap: 0.4rem; flex-wrap: wrap; }

button.role {
  flex: 1;
  background: rgba(46, 196, 182, 0.12);
  color: var(--foam);
  border: 1px solid transparent;
  font-weight: 600;
}

button.role.active {
  border-color: var(--accent);
  background: rgba(46, 196, 182, 0.28);
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

#gameWrap {
  background: #021018;
}

#phaser-game {
  display: block;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

#phaser-game canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

#hud {
  position: fixed;
  inset: 0;
  z-index: 30;
  pointer-events: none;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.hud-top {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.55);
}

#hudGold {
  color: #f4d35e;
  letter-spacing: 0.06em;
}

#hudKits {
  color: #7dd3fc;
  letter-spacing: 0.04em;
}

#hudAmmo {
  color: #ffb4a2;
  letter-spacing: 0.04em;
}

#hudEnergy {
  color: #9ef01a;
  letter-spacing: 0.04em;
}

.alert-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 25;
  box-shadow: inset 0 0 0 10px rgba(255, 40, 40, 0.55);
  animation: alertPulse 0.55s ease-in-out infinite alternate;
}

@keyframes alertPulse {
  from { box-shadow: inset 0 0 0 8px rgba(255, 30, 30, 0.35); }
  to { box-shadow: inset 0 0 0 18px rgba(255, 50, 50, 0.75); }
}

.radar-screen {
  position: absolute;
  inset: 0;
  z-index: 22;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background:
    radial-gradient(ellipse at center, rgba(6, 40, 28, 0.92) 0%, rgba(2, 12, 18, 0.97) 70%),
    #021018;
  pointer-events: none;
}

.radar-screen[hidden] {
  display: none !important;
}

#radarCanvas {
  width: min(72vmin, 520px);
  height: min(72vmin, 520px);
  border-radius: 50%;
  box-shadow:
    0 0 0 3px rgba(158, 240, 26, 0.35),
    0 0 40px rgba(46, 196, 182, 0.25);
  background: #031810;
}

.radar-meta {
  text-align: center;
  font-family: "Space Grotesk", sans-serif;
}

.radar-title {
  margin: 0;
  letter-spacing: 0.2em;
  color: #9ef01a;
  font-size: 0.95rem;
}

.radar-status {
  margin: 0.25rem 0 0;
  color: rgba(200, 240, 234, 0.75);
  font-size: 0.85rem;
}

.radar-guide {
  margin: 0.35rem 0 0;
  color: #ffd166;
  font-size: 0.82rem;
  line-height: 1.35;
  font-family: "Space Grotesk", sans-serif;
  letter-spacing: 0.02em;
}

.radar-cd {
  margin: 0.2rem 0 0;
  color: #f4d35e;
  font-size: 0.8rem;
}

.guided-compass {
  position: absolute;
  bottom: 1rem;
  z-index: 46;
  width: 11.5rem;
  padding: 0.55rem 0.65rem 0.7rem;
  background: rgba(2, 16, 24, 0.92);
  border: 1px solid rgba(255, 209, 102, 0.45);
  pointer-events: auto;
  font-family: "Outfit", sans-serif;
  text-align: center;
}

.guided-compass.side-l {
  left: 1rem;
  right: auto;
}

.guided-compass.side-r {
  right: 1rem;
  left: auto;
}

.guided-compass.flash {
  border-color: #9ef01a;
  box-shadow: 0 0 18px rgba(158, 240, 26, 0.35);
}

.guided-compass-title {
  margin: 0 0 0.25rem;
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: #ffd166;
  text-transform: uppercase;
}

.guided-compass-canvas {
  display: block;
  width: 9.5rem;
  height: 9.5rem;
  margin: 0 auto;
  border-radius: 50%;
  cursor: crosshair;
  touch-action: none;
}

.guided-compass.readonly .guided-compass-canvas {
  cursor: default;
}

.guided-compass-deg {
  margin: 0.3rem 0 0;
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.95rem;
  color: #e8fbff;
}

.guided-compass-send {
  margin-top: 0.4rem;
  width: 100%;
  font-size: 0.82rem;
}

.bay-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 45;
  width: min(16rem, calc(100vw - 2rem));
  padding: 0.85rem 1rem;
  background: rgba(2, 16, 24, 0.94);
  border: 1px solid rgba(46, 196, 182, 0.45);
  pointer-events: auto;
  font-family: "Outfit", sans-serif;
}

.bay-title {
  margin: 0 0 0.4rem;
  font-family: "Space Grotesk", sans-serif;
  color: #f4d35e;
  letter-spacing: 0.06em;
}

.bay-stock {
  margin: 0 0 0.55rem;
  font-size: 0.82rem;
  color: rgba(232, 251, 255, 0.8);
  line-height: 1.4;
}

.bay-actions {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.55rem;
}

.bay-actions button {
  width: 100%;
  margin: 0;
  text-align: left;
  font-size: 0.82rem;
}

.bay-msg {
  margin: 0 0 0.45rem;
  color: #ff6b4a;
  font-size: 0.78rem;
}

.hud-help {
  max-width: 28rem;
  margin-left: 9rem;
  color: rgba(232, 251, 255, 0.78);
  font-size: 0.88rem;
  line-height: 1.4;
}

.hud-helm {
  position: absolute;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  letter-spacing: 0.06em;
  font-size: 1.05rem;
  color: #c8f0ea;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.65);
  background: rgba(2, 16, 24, 0.55);
  border: 1px solid rgba(46, 196, 182, 0.35);
  padding: 0.55rem 1.1rem;
  pointer-events: none;
}

.captain-shop {
  position: absolute;
  right: 1.25rem;
  bottom: 5.5rem;
  width: min(18rem, calc(100vw - 2.5rem));
  max-height: min(70vh, 28rem);
  overflow-y: auto;
  background: rgba(2, 16, 24, 0.92);
  border: 1px solid rgba(244, 211, 94, 0.4);
  padding: 0.85rem 1rem;
  pointer-events: auto;
  z-index: 40;
  font-family: "Outfit", sans-serif;
}

.captain-shop button {
  pointer-events: auto;
  cursor: pointer;
}

.captain-shop-title {
  margin: 0 0 0.35rem;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  color: #f4d35e;
  letter-spacing: 0.04em;
}

.captain-shop-hint {
  margin: 0 0 0.55rem;
  font-size: 0.75rem;
  color: rgba(232, 251, 255, 0.65);
  line-height: 1.35;
}

.shop-tabs {
  display: flex;
  gap: 0.35rem;
  margin: 0 0 0.65rem;
}

.shop-tab {
  flex: 1;
  margin: 0;
  padding: 0.4rem 0.5rem;
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: rgba(232, 251, 255, 0.7);
  background: rgba(8, 36, 48, 0.85);
  border: 1px solid rgba(46, 196, 182, 0.25);
  border-radius: 0;
  cursor: pointer;
}

.shop-tab.active {
  color: #041822;
  background: #f4d35e;
  border-color: #f4d35e;
}

.shop-panel[hidden] {
  display: none !important;
}

.shop-section-label {
  margin: 0.65rem 0 0.35rem;
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(200, 240, 234, 0.55);
}

.shop-panel > .shop-section-label:first-child {
  margin-top: 0.15rem;
}

.shop-items {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.shop-items button {
  width: 100%;
  text-align: left;
  font-size: 0.82rem;
  padding: 0.5rem 0.65rem;
  line-height: 1.35;
}

.shop-items button small {
  display: block;
  font-weight: 400;
  opacity: 0.7;
  font-size: 0.72rem;
}

.shop-items button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.shop-msg {
  margin: 0.55rem 0 0;
  font-size: 0.8rem;
  color: #ff6b4a;
}

.shop-empty {
  margin: 0;
  font-size: 0.85rem;
  color: rgba(200, 240, 234, 0.75);
}

.hud-cargo {
  position: absolute;
  left: 50%;
  top: 3.5rem;
  transform: translateX(-50%);
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: 0.92rem;
  letter-spacing: 0.04em;
  color: #f4d35e;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.65);
  background: rgba(2, 16, 24, 0.6);
  border: 1px solid rgba(244, 211, 94, 0.4);
  padding: 0.4rem 0.9rem;
  pointer-events: none;
  white-space: nowrap;
}

.shop-cargo-active {
  margin: 0;
  padding: 0.55rem 0.65rem;
  font-size: 0.82rem;
  line-height: 1.4;
  color: #c8f0ea;
  background: rgba(46, 196, 182, 0.12);
  border: 1px solid rgba(46, 196, 182, 0.35);
}

.shop-cargo-active strong {
  color: #f4d35e;
}

.sfx-credit {
  position: fixed;
  left: 0.6rem;
  bottom: 0.35rem;
  z-index: 5;
  margin: 0;
  font-size: 0.65rem;
  color: rgba(142, 184, 196, 0.55);
  pointer-events: none;
}

.admin-panel {
  position: fixed;
  top: 3.5rem;
  left: 0.75rem;
  z-index: 80;
  width: min(18.5rem, calc(100vw - 1.5rem));
  max-height: min(78vh, 36rem);
  overflow-y: auto;
  padding: 0.75rem 0.85rem;
  background: rgba(2, 16, 24, 0.94);
  border: 1px solid rgba(255, 107, 74, 0.55);
  font-family: "Outfit", sans-serif;
  font-size: 0.82rem;
  color: var(--ink);
  pointer-events: auto;
}

.admin-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.55rem;
  color: #ff6b4a;
  font-family: "Space Grotesk", sans-serif;
}

.admin-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.35rem 0;
}

.admin-row button {
  flex: 1 1 auto;
  min-width: 5.5rem;
  margin: 0;
  padding: 0.35rem 0.45rem;
  font-size: 0.72rem;
}

.admin-hint {
  margin: 0.35rem 0 0.55rem;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.35;
}

.admin-checklist {
  margin: 0 0 0.65rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid rgba(46, 196, 182, 0.25);
  background: rgba(0, 0, 0, 0.25);
  font-size: 0.72rem;
  color: rgba(200, 240, 234, 0.85);
}

.admin-checklist summary {
  cursor: pointer;
  color: #f4d35e;
  font-family: "Space Grotesk", sans-serif;
  letter-spacing: 0.04em;
}

.admin-checklist ol {
  margin: 0.4rem 0 0;
  padding-left: 1.1rem;
  line-height: 1.45;
}

.admin-hint kbd,
.admin-hint code {
  font-size: 0.7rem;
  color: #f4d35e;
}

.admin-msg {
  margin: 0.4rem 0 0;
  color: #ff6b4a;
  font-size: 0.78rem;
}

.admin-status {
  margin: 0.55rem 0 0;
  padding: 0.45rem;
  font-size: 0.68rem;
  line-height: 1.35;
  color: #c8f0ea;
  background: rgba(0, 0, 0, 0.35);
  white-space: pre-wrap;
  word-break: break-word;
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(2, 10, 16, 0.72);
  z-index: 20;
}

.settings-panel {
  width: min(420px, calc(100vw - 2rem));
  position: relative;
  z-index: 1;
  margin: 0;
  pointer-events: auto;
}

.settings-fab {
  position: fixed;
  top: 1rem;
  left: 1rem;
  right: auto;
  z-index: 85;
  width: 2.65rem;
  height: 2.65rem;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(6, 28, 38, 0.92);
  color: var(--foam);
  border: 1px solid var(--line);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  pointer-events: auto;
  cursor: pointer;
}

.settings-fab:hover {
  color: var(--accent);
  border-color: rgba(46, 196, 182, 0.45);
}

.settings-fab[aria-expanded="true"] {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(6, 36, 44, 0.96);
}

.settings-icon {
  display: block;
}

.settings-modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 1rem;
  pointer-events: auto;
}

.settings-modal[hidden] {
  display: none !important;
}

.settings-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 10, 16, 0.62);
  backdrop-filter: blur(3px);
}

.settings-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}

.settings-close {
  flex-shrink: 0;
  min-width: 2rem;
  padding: 0.35rem 0.5rem;
}

.settings-title {
  margin: 0;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
}

.vol-row {
  display: grid;
  grid-template-columns: 5.5rem 1fr 2.6rem;
  align-items: center;
  gap: 0.55rem;
  color: var(--foam);
  font-size: 0.82rem;
}

.vol-row input[type='range'] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.vol-val {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.78rem;
}

[hidden] { display: none !important; }
