:root {
  --bg: #10131a;
  --bg-soft: #171b25;
  --panel: #1d2230;
  --panel-2: #242a3b;
  --line: #2f374b;
  --text: #eef1f7;
  --muted: #9aa4bb;
  --accent: #ffc914;
  --accent-2: #17bebb;
  --danger: #e4572e;
  --ok: #76b041;
  --radius: 14px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(23, 190, 187, 0.16), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(255, 201, 20, 0.12), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.screen[hidden],
.overlay[hidden],
.banner[hidden],
.error-message[hidden] {
  display: none !important;
}

/* ---------- Shared ---------- */

.card {
  background: linear-gradient(180deg, var(--panel), var(--bg-soft));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 11px 18px;
  font: inherit;
  font-weight: 650;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  color: var(--text);
  background: var(--panel-2);
}

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

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

.btn:focus-visible {
  outline: 3px solid rgba(23, 190, 187, 0.6);
  outline-offset: 2px;
}

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

.btn-primary {
  background: linear-gradient(180deg, #ffd84d, var(--accent));
  color: #1a1400;
}

.btn-secondary {
  background: var(--panel-2);
  border-color: var(--line);
}

.btn-danger {
  background: rgba(228, 87, 46, 0.16);
  border-color: rgba(228, 87, 46, 0.55);
  color: #ffb59f;
}

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}

.btn-icon {
  padding: 9px 12px;
  background: var(--panel-2);
  border-color: var(--line);
}

/* ---------- Join ---------- */

.join-screen {
  width: min(460px, 100%);
}

.join-card {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.logo {
  margin: 0;
  font-size: clamp(2.2rem, 6vw, 3rem);
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.join-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.text-input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0d1017;
  color: var(--text);
  font: inherit;
  font-size: 1.05rem;
}

.text-input:focus {
  outline: none;
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(23, 190, 187, 0.22);
}

.error-message {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(228, 87, 46, 0.14);
  border: 1px solid rgba(228, 87, 46, 0.5);
  color: #ffc2b0;
  font-weight: 600;
}

/* ---------- Lobby ---------- */

.lobby-screen {
  width: min(620px, 100%);
}

.lobby-card {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.lobby-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-title {
  margin: 0;
  font-size: 1.6rem;
}

.pill {
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.player-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player-row {
  display: grid;
  grid-template-columns: 18px 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}

.player-row.is-lead {
  border-color: rgba(255, 201, 20, 0.45);
}

.player-row.is-me {
  border-color: rgba(23, 190, 187, 0.6);
}

.swatch {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  background: var(--muted);
}

.player-name {
  font-weight: 650;
}

.badges {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.ready-badge {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: rgba(154, 164, 187, 0.14);
  color: var(--muted);
}

.ready-badge.is-ready {
  background: rgba(118, 176, 65, 0.2);
  color: #b6e08a;
}

.lobby-status {
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(23, 190, 187, 0.1);
  border: 1px solid rgba(23, 190, 187, 0.35);
  color: #b8f1ef;
  font-weight: 600;
}

.lobby-status.is-blocked {
  background: rgba(255, 201, 20, 0.08);
  border-color: rgba(255, 201, 20, 0.35);
  color: #ffe08a;
}

.lobby-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.lobby-actions .btn-primary {
  margin-left: auto;
}

/* ---------- Game ---------- */

.game-screen {
  width: min(1320px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
}

.hud-left {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.hud-label {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.timer {
  font-size: 1.9rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.timer.is-low {
  color: #ff8a6b;
}

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

.connection-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  background: rgba(154, 164, 187, 0.12);
}

.connection-status::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.connection-status[data-status='open'] {
  color: #b6e08a;
  background: rgba(118, 176, 65, 0.16);
}

.connection-status[data-status='closed'] {
  color: #ffb199;
  background: rgba(228, 87, 46, 0.16);
}

.banner {
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(255, 201, 20, 0.14);
  border: 1px solid rgba(255, 201, 20, 0.45);
  color: #ffe9a3;
  font-weight: 700;
  text-align: center;
}

.banner-pop {
  animation: banner-pop 0.28s ease-out;
}

@keyframes banner-pop {
  from {
    transform: scale(0.97);
    opacity: 0.4;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.game-body {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.stage {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  justify-content: center;
}

.arena {
  position: relative;
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  overflow: hidden;
  background:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px) 0 0 / 48px 48px,
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px) 0 0 / 48px 48px,
    radial-gradient(700px 400px at 50% 40%, #1f2636, #12151d 75%);
  box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.55);
  contain: layout paint style;
}

.layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.player {
  position: absolute;
  top: 0;
  left: 0;
  will-change: transform;
}

.pickup {
  position: absolute;
  top: 0;
  left: 0;
  will-change: transform;
}

.player-body {
  width: 100%;
  height: 100%;
  border-radius: 9px;
  background: var(--color, #fff);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35), 0 6px 14px rgba(0, 0, 0, 0.4);
}

.player.is-me .player-body {
  box-shadow: 0 0 0 3px #fff, 0 0 18px var(--color, #fff);
}

.player.is-lead .player-body::after {
  content: '';
  position: absolute;
  top: -9px;
  left: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  transform: translateX(-50%);
}

.player.is-disconnected {
  opacity: 0.35;
}

.player .player-name {
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text);
  text-shadow: 0 1px 3px #000;
}

.pickup {
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6c9, var(--accent) 55%, #b8860b);
  box-shadow: 0 0 14px rgba(255, 201, 20, 0.75);
  animation: pickup-pulse 1.4s ease-in-out infinite;
}

@keyframes pickup-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.72;
  }
}

.side-panel {
  width: 260px;
  flex: 0 0 260px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.scoreboard {
  list-style: none;
  margin: 0;
  padding: 10px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--panel-2);
  border-left: 4px solid var(--color, var(--line));
}

.score-row.is-me {
  outline: 1px solid rgba(23, 190, 187, 0.6);
}

.score-row.is-leader .score-value {
  color: var(--accent);
}

.score-name {
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-value {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.event-feed {
  list-style: none;
  margin: 0;
  padding: 10px;
  border-radius: var(--radius);
  background: rgba(29, 34, 48, 0.7);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 80px;
  font-size: 0.85rem;
  color: var(--muted);
}

.feed-item {
  line-height: 1.35;
}

/* ---------- Overlays ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 10, 15, 0.72);
  backdrop-filter: blur(3px);
  border-radius: var(--radius);
  z-index: 5;
}

.overlay-card {
  width: min(380px, 90%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
  align-items: stretch;
}

.overlay-title {
  margin: 0;
  font-size: 1.5rem;
}

.overlay-title.is-draw {
  color: var(--accent-2);
}

.overlay-text {
  margin: 0;
  color: var(--muted);
  font-weight: 600;
}

.result-scores {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.result-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--panel-2);
}

.result-row.is-winner {
  background: rgba(255, 201, 20, 0.16);
  border: 1px solid rgba(255, 201, 20, 0.5);
  font-weight: 700;
}

.result-score {
  font-variant-numeric: tabular-nums;
}

@media (max-width: 900px) {
  .game-body {
    flex-direction: column;
  }

  .side-panel {
    width: 100%;
    flex-basis: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pickup,
  .banner-pop {
    animation: none;
  }
}
