:root {
  --bg-a: #101323;
  --bg-b: #191f36;
  --card: rgba(255, 255, 255, 0.08);
  --card-border: rgba(255, 255, 255, 0.18);
  --text: #f8fbff;
  --muted: #b7c0d8;
  --accent: #7c5cff;
  --accent-2: #18dcff;
  --danger: #ff4757;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 20%, rgba(124, 92, 255, 0.38), transparent 28rem),
    radial-gradient(circle at 82% 18%, rgba(24, 220, 255, 0.24), transparent 24rem),
    linear-gradient(135deg, var(--bg-a), var(--bg-b));
  overflow: hidden;
}

button, input { font: inherit; }

button {
  cursor: pointer;
  border: 0;
  color: white;
  background: rgba(255, 255, 255, 0.13);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 14px;
  padding: 0.82rem 1rem;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease, opacity 160ms ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.28);
}

button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { cursor: not-allowed; opacity: 0.48; }

input {
  width: 100%;
  color: white;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 14px;
  padding: 0.95rem 1rem;
  outline: none;
}

input:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 4px rgba(24, 220, 255, 0.12);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.25rem;
}

.card {
  width: min(500px, 100%);
  padding: clamp(1.2rem, 4vw, 2rem);
  border: 1px solid var(--card-border);
  background: linear-gradient(180deg, rgba(255,255,255,0.12), rgba(255,255,255,0.06));
  border-radius: 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.lobby-card h1 {
  margin: 0;
  font-size: clamp(2.2rem, 8vw, 4rem);
  line-height: 0.93;
  letter-spacing: -0.08em;
}

.eyebrow {
  margin: 0 0 0.55rem;
  color: var(--accent-2);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.76rem;
  font-weight: 800;
}

.lede {
  color: var(--muted);
  line-height: 1.55;
  margin: 1rem 0 1.4rem;
}

.field-label {
  display: block;
  color: var(--muted);
  font-size: 0.88rem;
  margin: 0.9rem 0 0.4rem;
}

.button-row { display: flex; gap: 0.8rem; margin-top: 1rem; }

.primary-btn {
  width: 100%;
  background: linear-gradient(135deg, var(--accent), #4b8dff);
  border-color: rgba(255, 255, 255, 0.22);
  font-weight: 800;
}

.host-btn {
  background: linear-gradient(135deg, #00b894, #00cec9);
  border-color: rgba(255, 255, 255, 0.25);
  font-weight: 800;
}

.divider {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.8rem;
  color: var(--muted);
  font-size: 0.82rem;
  margin: 1.4rem 0 0.4rem;
}

.divider::before, .divider::after {
  content: "";
  height: 1px;
  background: rgba(255, 255, 255, 0.14);
}

.join-row { display: grid; grid-template-columns: 1fr auto; gap: 0.7rem; }
.rounds-row { display: grid; grid-template-columns: 120px 1fr; gap: 0.7rem; align-items: center; color: var(--muted); }
.rounds-row input { text-align: center; font-weight: 900; }

.error-text { min-height: 1.3rem; color: #ffb8c0; margin: 0.9rem 0 0; }
.fine-print { margin: 1.2rem 0 0; color: rgba(255,255,255,0.48); font-size: 0.78rem; }
.hidden { display: none !important; }

.game-shell {
  width: min(1520px, 100vw);
  height: min(920px, 100vh);
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 0.8rem;
}

.game-topbar {
  display: grid;
  grid-template-columns: auto minmax(220px, auto) 1fr;
  align-items: center;
  gap: 1rem;
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.08);
  border-radius: 22px;
  padding: 0.8rem 1rem;
  backdrop-filter: blur(14px);
}

.room-line { display: flex; align-items: center; gap: 0.65rem; flex-wrap: wrap; }
.room-line strong { font-size: 1.55rem; letter-spacing: 0.12em; }
.small-btn { padding: 0.52rem 0.72rem; border-radius: 11px; font-size: 0.86rem; }
.danger-btn { background: rgba(255, 71, 87, 0.18); border-color: rgba(255, 71, 87, 0.32); }

.status-strip { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; }
.status-strip span {
  padding: 0.46rem 0.65rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #e9edff;
  font-weight: 800;
  font-size: 0.82rem;
}

.controls-hint {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.8rem;
}
.controls-hint span {
  padding: 0.38rem 0.55rem;
  background: rgba(0, 0, 0, 0.18);
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.arena-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 286px;
  gap: 0.8rem;
  min-height: 0;
}

.canvas-shell { position: relative; min-width: 0; min-height: 0; }
#arena {
  width: 100%;
  height: 100%;
  min-height: 0;
  border-radius: 24px;
  border: 1px solid var(--card-border);
  background: rgba(2, 6, 23, 0.76);
  box-shadow: var(--shadow);
  display: block;
}

.round-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: radial-gradient(circle at center, rgba(8, 12, 26, 0.25), rgba(8, 12, 26, 0.72));
  border-radius: 24px;
  pointer-events: none;
}

.round-card {
  pointer-events: auto;
  width: min(720px, 96%);
  padding: clamp(1rem, 3vw, 1.6rem);
  border-radius: 24px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(11, 16, 34, 0.88);
  box-shadow: var(--shadow);
  text-align: center;
  backdrop-filter: blur(14px);
}
.round-card h2 { margin: 0.2rem 0 0.5rem; font-size: clamp(1.6rem, 4vw, 2.7rem); letter-spacing: -0.04em; }
.round-card p { color: var(--muted); line-height: 1.45; margin: 0.4rem 0 1rem; }
.round-card .primary-btn { margin: 0.2rem auto 0; max-width: 280px; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}
.ability-card {
  min-height: 180px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 1rem;
  border-radius: 18px;
  text-align: left;
  background: linear-gradient(180deg, rgba(124, 92, 255, 0.22), rgba(255,255,255,0.07));
  border: 1px solid rgba(255,255,255,0.18);
}
.ability-card strong { font-size: 1.05rem; }
.ability-card span { color: var(--muted); font-size: 0.88rem; line-height: 1.35; }
.ability-card small { color: var(--accent-2); font-weight: 900; text-transform: uppercase; letter-spacing: 0.12em; }

.score-panel {
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.08);
  border-radius: 24px;
  padding: 1rem;
  min-height: 0;
  overflow: auto;
  backdrop-filter: blur(14px);
}
.score-panel h2 { margin: 0 0 0.8rem; font-size: 1rem; }
.score-panel h2 + h2 { margin-top: 1.05rem; }
.match-summary {
  padding: 0.7rem;
  background: rgba(0,0,0,0.16);
  border-radius: 16px;
  color: var(--muted);
  line-height: 1.45;
  margin-bottom: 0.9rem;
  font-size: 0.9rem;
}

.score-card {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  gap: 0.6rem;
  align-items: center;
  padding: 0.65rem;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.16);
  margin-bottom: 0.55rem;
}
.swatch { width: 14px; height: 14px; border-radius: 999px; box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.12); }
.player-meta { min-width: 0; }
.player-meta strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-meta span { color: var(--muted); font-size: 0.78rem; }
.player-score { font-weight: 900; font-size: 1.3rem; }
.ability-list { color: rgba(255,255,255,0.64); font-size: 0.73rem; margin-top: 0.18rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 2rem));
  padding: 0.8rem 1rem;
  border-radius: 999px;
  background: rgba(10, 14, 30, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: var(--shadow);
  color: white;
  z-index: 10;
}

@media (max-width: 1050px) {
  body { overflow: auto; }
  .app-shell { align-items: stretch; }
  .game-shell { height: calc(100vh - 2.5rem); }
  .game-topbar { grid-template-columns: 1fr; align-items: flex-start; }
  .status-strip, .controls-hint { justify-content: flex-start; }
  .arena-wrap { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .score-panel { max-height: 220px; }
}

@media (max-width: 650px) {
  .card-grid { grid-template-columns: 1fr; }
  .rounds-row { grid-template-columns: 1fr; }
}
