:root {
  --bg: #070b16;
  --bg2: #0c1224;
  --panel: rgba(14, 22, 42, 0.78);
  --panel-border: rgba(125, 180, 255, 0.14);
  --text: #e8eefc;
  --muted: #8b9bb8;
  --cyan: #22d3ee;
  --rose: #f472b6;
  --lime: #a3e635;
  --amber: #fbbf24;
  --danger: #fb7185;
  --ok: #34d399;
  --glow-cyan: 0 0 24px rgba(34, 211, 238, 0.35);
  --glow-rose: 0 0 24px rgba(244, 114, 182, 0.35);
  --font-display: "Orbitron", system-ui, sans-serif;
  --font-body: "Outfit", system-ui, sans-serif;
  --radius: 16px;
  --radius-sm: 10px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
}

#bg-orbs {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 60% 40% at 20% 10%, rgba(34, 211, 238, 0.12), transparent 60%),
    radial-gradient(ellipse 50% 40% at 80% 20%, rgba(244, 114, 182, 0.1), transparent 55%),
    radial-gradient(ellipse 50% 50% at 50% 100%, rgba(56, 89, 180, 0.18), transparent 60%),
    var(--bg);
}

.screen {
  display: none;
  position: relative;
  z-index: 1;
  min-height: 100dvh;
}

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px 40px;
}

/* ---- Menu ---- */
.menu-shell {
  width: min(520px, 100%);
  text-align: center;
}

.hero {
  margin-bottom: 28px;
}

.logo-mark {
  width: 84px;
  height: 84px;
  margin: 0 auto 18px;
  position: relative;
}

.logo-mark .ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid transparent;
}

.logo-mark .r1 {
  border-color: rgba(34, 211, 238, 0.55);
  animation: spin 12s linear infinite;
  box-shadow: inset 0 0 12px rgba(34, 211, 238, 0.15);
}

.logo-mark .r2 {
  inset: 12px;
  border-color: rgba(244, 114, 182, 0.55);
  border-style: dashed;
  animation: spin 8s linear infinite reverse;
}

.logo-mark .core {
  position: absolute;
  inset: 30px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff, var(--cyan) 45%, #0e7490);
  box-shadow: var(--glow-cyan);
  animation: pulse 2.4s ease-in-out infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.08);
    opacity: 0.85;
  }
}

.title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.6rem, 8vw, 3.6rem);
  letter-spacing: 0.18em;
  margin: 0 0 8px;
  background: linear-gradient(120deg, #fff 10%, var(--cyan) 45%, var(--rose) 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-size: 0.85rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}

.lede {
  margin: 0 auto;
  max-width: 40ch;
  color: #b7c4de;
  line-height: 1.55;
  font-weight: 300;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  backdrop-filter: blur(12px);
  margin-bottom: 16px;
  text-align: left;
}

.name-panel label {
  display: block;
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

input {
  width: 100%;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(125, 180, 255, 0.18);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font: inherit;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus {
  border-color: rgba(34, 211, 238, 0.55);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.12);
}

#join-code {
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-family: var(--font-display);
  text-align: center;
}

.actions {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 12px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 1rem;
  padding: 12px 18px;
  cursor: pointer;
  color: var(--text);
  transition: transform 0.12s, box-shadow 0.12s, background 0.12s, border-color 0.12s;
  background: rgba(255, 255, 255, 0.06);
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn.primary {
  background: linear-gradient(135deg, #0891b2, #22d3ee 50%, #67e8f9);
  color: #042f2e;
  box-shadow: var(--glow-cyan);
}

.btn.secondary {
  background: linear-gradient(135deg, rgba(244, 114, 182, 0.2), rgba(244, 114, 182, 0.08));
  border-color: rgba(244, 114, 182, 0.45);
  color: #fce7f3;
}

.btn.ghost {
  background: transparent;
  border-color: rgba(125, 180, 255, 0.2);
  color: var(--muted);
}

.btn.ghost:hover {
  color: var(--text);
  border-color: rgba(125, 180, 255, 0.4);
}

.btn.xl {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
}

.btn-kicker {
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  opacity: 0.75;
  font-weight: 500;
}

.btn.sm {
  padding: 8px 12px;
  font-size: 0.85rem;
}

.btn.action {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-start;
  margin-bottom: 8px;
  background: rgba(0, 0, 0, 0.28);
  border-color: rgba(125, 180, 255, 0.16);
}

.btn.action .cost {
  margin-left: auto;
  font-family: var(--font-display);
  font-size: 0.75rem;
  color: var(--cyan);
}

.btn.action kbd {
  font-family: var(--font-display);
  font-size: 0.7rem;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  padding: 2px 6px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.join-code-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 20px;
}

.menu-links {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  color: var(--muted);
  font-size: 0.92rem;
}

.linkish {
  background: none;
  border: none;
  color: var(--cyan);
  cursor: pointer;
  font: inherit;
  text-decoration: none;
  padding: 0;
}

.linkish:hover {
  text-decoration: underline;
}

.dot {
  opacity: 0.4;
}

/* ---- How to play ---- */
#screen-how {
  justify-content: flex-start;
}

.how-shell {
  width: min(960px, 100%);
}

.how-shell h2 {
  font-family: var(--font-display);
  letter-spacing: 0.08em;
  margin: 12px 0 8px;
}

.how-intro {
  color: #b7c4de;
  line-height: 1.6;
  max-width: 70ch;
}

.how-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin: 20px 0;
}

.how-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 16px 18px;
  backdrop-filter: blur(10px);
}

.how-card h3 {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  color: var(--cyan);
}

.how-card ul {
  margin: 0;
  padding-left: 18px;
  color: #c5d0e6;
  line-height: 1.55;
  font-size: 0.95rem;
}

.how-card li {
  margin-bottom: 6px;
}

.how-card kbd {
  font-family: var(--font-display);
  font-size: 0.75rem;
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 6px;
  border-radius: 4px;
}

.how-footer {
  color: #b7c4de;
  line-height: 1.55;
}

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

.muted.sm {
  font-size: 0.85rem;
}

/* ---- Wait ---- */
.wait-shell {
  text-align: center;
  width: min(420px, 100%);
}

.wait-shell h2 {
  font-family: var(--font-display);
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

.pulse-loader {
  width: 64px;
  height: 64px;
  margin: 0 auto 20px;
  border-radius: 50%;
  border: 3px solid rgba(34, 211, 238, 0.15);
  border-top-color: var(--cyan);
  border-right-color: var(--rose);
  animation: spin 1s linear infinite;
}

.code-block {
  margin: 20px 0;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
}

.code-block.hidden,
.hidden {
  display: none !important;
}

.code-label {
  display: block;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.code-row {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
}

.code {
  font-family: var(--font-display);
  font-size: 1.8rem;
  letter-spacing: 0.28em;
  color: var(--cyan);
  text-shadow: var(--glow-cyan);
}

.wait-players {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 16px 0;
}

.wait-player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--panel);
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  text-align: left;
}

.wait-player .swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: 0 0 10px currentColor;
}

.wait-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ---- Game ---- */
#screen-game {
  padding: 0;
  justify-content: flex-start;
  min-height: 100dvh;
}

.game-top {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(125, 180, 255, 0.1);
  background: rgba(7, 11, 22, 0.75);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand-mini {
  font-family: var(--font-display);
  letter-spacing: 0.18em;
  font-size: 0.85rem;
  color: var(--cyan);
}

.phase-banner {
  font-family: var(--font-display);
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #c4d4f0;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(125, 180, 255, 0.12);
}

.top-right {
  display: flex;
  gap: 10px;
  align-items: center;
}

.pill {
  font-family: var(--font-display);
  font-size: 0.75rem;
  letter-spacing: 0.16em;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(244, 114, 182, 0.12);
  border: 1px solid rgba(244, 114, 182, 0.35);
  color: #fbcfe8;
}

.timer {
  font-family: var(--font-display);
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  color: var(--amber);
  min-width: 4ch;
  text-align: right;
}

.game-layout {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 220px 1fr 240px;
  gap: 12px;
  padding: 12px;
  flex: 1;
  align-items: start;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.players-panel,
.flux-panel,
.core-hold,
.controls-panel,
.log-panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 12px;
  backdrop-filter: blur(10px);
}

.player-card {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.player-card:last-child {
  border-bottom: none;
}

.player-card .swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  box-shadow: 0 0 8px currentColor;
}

.player-card .meta {
  min-width: 0;
}

.player-card .name {
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-card .stats {
  font-size: 0.75rem;
  color: var(--muted);
}

.player-card .nodes {
  font-family: var(--font-display);
  font-size: 0.85rem;
  color: var(--cyan);
}

.player-card.you .name::after {
  content: " (you)";
  color: var(--muted);
  font-weight: 400;
  font-size: 0.75rem;
}

.player-card.disconnected {
  opacity: 0.45;
}

.flux-label {
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.flux-bar {
  height: 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.4);
  overflow: hidden;
  border: 1px solid rgba(125, 180, 255, 0.12);
}

.flux-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #0891b2, var(--cyan));
  box-shadow: 0 0 12px rgba(34, 211, 238, 0.5);
  transition: width 0.15s linear;
}

.flux-bar.core .flux-fill {
  background: linear-gradient(90deg, #a21caf, var(--rose), var(--amber));
}

.flux-text {
  margin-top: 6px;
  font-size: 0.85rem;
  color: #c5d0e6;
  font-variant-numeric: tabular-nums;
}

.controls-panel h3,
.log-panel h3 {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-weight: 500;
}

.hint {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
  margin: 8px 0 0;
}

#event-log {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 220px;
  overflow: auto;
  font-size: 0.82rem;
  color: #b7c4de;
}

#event-log li {
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  line-height: 1.35;
}

.arena-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: min(72vh, 720px);
  background:
    radial-gradient(circle at center, rgba(34, 211, 238, 0.06), transparent 55%),
    rgba(8, 12, 24, 0.5);
  border: 1px solid var(--panel-border);
  border-radius: calc(var(--radius) + 4px);
  overflow: hidden;
}

#arena {
  width: min(100%, 720px);
  height: auto;
  max-height: min(72vh, 720px);
  cursor: crosshair;
  touch-action: manipulation;
}

.toast {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 16, 32, 0.9);
  border: 1px solid rgba(34, 211, 238, 0.35);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.9rem;
  pointer-events: none;
  z-index: 4;
  box-shadow: var(--glow-cyan);
  animation: toast-in 0.25s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, -8px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

.countdown-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: clamp(4rem, 15vw, 7rem);
  color: #fff;
  text-shadow: 0 0 40px rgba(34, 211, 238, 0.8);
  background: rgba(5, 8, 16, 0.35);
  z-index: 3;
  pointer-events: none;
}

.end-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(5, 8, 16, 0.78);
  backdrop-filter: blur(8px);
  z-index: 4;
  text-align: center;
  padding: 24px;
}

.end-overlay h2 {
  font-family: var(--font-display);
  letter-spacing: 0.1em;
  margin: 0;
  font-size: clamp(1.4rem, 4vw, 2rem);
}

.end-overlay p {
  color: #c5d0e6;
  max-width: 36ch;
  line-height: 1.5;
}

.end-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

/* Responsive */
@media (max-width: 980px) {
  .game-layout {
    grid-template-columns: 1fr;
  }

  .side.left,
  .side.right {
    order: 2;
  }

  .arena-wrap {
    order: 1;
    min-height: min(60vh, 520px);
  }

  .side.right {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .log-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  .side.right {
    grid-template-columns: 1fr;
  }

  .join-code-row {
    grid-template-columns: 1fr;
  }

  .game-top {
    flex-wrap: wrap;
    justify-content: center;
  }
}
