:root {
  --bg-a: #0f172a;
  --bg-b: #12233f;
  --bg-c: #1f2f57;
  --card: rgba(255, 255, 255, 0.94);
  --text: #1c2432;
  --muted: #64748b;
  --accent: #ef476f;
  --accent-2: #06d6a0;
  --accent-3: #ffd166;
  --player-1: #ff4d6d;
  --player-2: #2ec4b6;
  --board: #16324f;
  --slot: #e2e8f0;
  --shadow: 0 20px 50px rgba(13, 25, 45, 0.25);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Nunito", sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 600px at 10% 0%, #273e70 0%, var(--bg-a) 60%),
    linear-gradient(135deg, var(--bg-a) 0%, var(--bg-b) 50%, var(--bg-c) 100%);
  overflow-x: hidden;
}

.bg-glow {
  position: fixed;
  border-radius: 999px;
  filter: blur(60px);
  opacity: 0.35;
  pointer-events: none;
}

.bg-glow-a {
  width: 280px;
  height: 280px;
  background: #f43f5e;
  top: -80px;
  right: -80px;
}

.bg-glow-b {
  width: 320px;
  height: 320px;
  background: #22d3ee;
  bottom: -120px;
  left: -100px;
}

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding-top: max(24px, calc(env(safe-area-inset-top) + 10px));
  padding-right: max(16px, env(safe-area-inset-right));
  padding-bottom: 32px;
  padding-left: max(16px, env(safe-area-inset-left));
}

.hero h1 {
  font-family: "Bungee", cursive;
  font-size: clamp(2rem, 5vw, 3rem);
  margin: 8px 0 0;
  color: #f8fafc;
  letter-spacing: 1px;
}

.hero p {
  color: #d7e0ef;
  margin-top: 8px;
}

.card {
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 20px;
  margin-top: 16px;
  backdrop-filter: blur(2px);
}

.hidden {
  display: none !important;
}

.field label {
  font-weight: 700;
  display: block;
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  border-radius: 12px;
  border: 2px solid #dbe4ef;
  padding: 12px;
  font-size: 1rem;
  outline: none;
}

.field input:focus {
  border-color: #4f46e5;
}

.lobby-step {
  margin-top: 6px;
}

.step-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  margin: 0 0 8px;
  font-size: 0.8rem;
  font-weight: 900;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: #9a3412;
  background: linear-gradient(135deg, #fde68a 0%, #fed7aa 100%);
}

.lobby-options {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.option-card {
  border-radius: 14px;
  border: 2px solid #dbe4ef;
  background: rgba(248, 250, 252, 0.75);
  padding: 12px;
}

.option-card h3 {
  margin: 0 0 8px;
  font-size: 1.05rem;
}

.option-copy {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.95rem;
}

.option-card .btn {
  width: 100%;
}

.join-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.buttons-row {
  margin-top: 14px;
}

.btn {
  border: none;
  border-radius: 12px;
  font-weight: 800;
  cursor: pointer;
  padding: 11px 16px;
  transition: transform 0.15s ease, filter 0.2s ease;
}

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

.btn:disabled {
  cursor: not-allowed;
  filter: grayscale(0.2);
  opacity: 0.6;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, #ef476f 0%, #f77f00 100%);
}

.btn-secondary {
  color: #fff;
  background: linear-gradient(135deg, #0ea5e9 0%, #2563eb 100%);
}

.btn-tertiary {
  color: #1e293b;
  background: linear-gradient(135deg, #e2e8f0 0%, #cbd5e1 100%);
}

.divider {
  display: flex;
  align-items: center;
  margin: 16px 0;
  color: var(--muted);
  font-weight: 700;
}

.divider::before,
.divider::after {
  content: "";
  height: 2px;
  background: #d5deea;
  flex: 1;
}

.divider span {
  padding: 0 10px;
}

.error {
  color: #b42318;
  margin-top: 10px;
  min-height: 20px;
}

.top-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status {
  margin: 8px 0 4px;
  font-weight: 800;
}

.turn {
  margin: 0 0 12px;
  font-weight: 700;
  color: #334155;
}

.small-muted {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.95rem;
}

.board-shell {
  --cell-size: clamp(24px, 8.2vw, 52px);
  position: relative;
  width: 100%;
  margin-top: 12px;
  padding: 2px 4px 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  user-select: none;
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell-size));
  grid-template-rows: repeat(var(--rows), var(--cell-size));
  gap: 6px;
  background: linear-gradient(160deg, #194165 0%, #0e2640 100%);
  padding: 10px;
  border-radius: 16px;
  box-shadow: inset 0 4px 0 rgba(255, 255, 255, 0.08), 0 18px 30px rgba(8, 16, 30, 0.35);
  width: max-content;
  margin: 0 auto;
  position: relative;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #f8fafc 0%, #e2e8f0 45%, #c7d2e0 100%);
  position: relative;
  overflow: hidden;
  border: none;
  padding: 0;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
}

.cell.p1::after,
.cell.p2::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  transform: scale(0.5);
  animation: pop-in 0.25s ease forwards;
  z-index: 2;
}

.cell.p1::after {
  background: radial-gradient(circle at 32% 30%, #ff9ab0 0%, #ff4d6d 48%, #cb2f52 100%);
}

.cell.p2::after {
  background: radial-gradient(circle at 32% 30%, #7de7df 0%, #2ec4b6 48%, #0f9f95 100%);
}

.cell.clickable {
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.cell.clickable:hover {
  transform: scale(1.06);
  filter: brightness(1.04);
}

.cell:disabled {
  cursor: default;
}

.cell.win-cell::before {
  content: "";
  position: absolute;
  inset: 1px;
  border-radius: 50%;
  border: 3px solid #ffe066;
  box-shadow: 0 0 14px rgba(255, 224, 102, 0.85);
  animation: win-ring 0.8s ease-in-out infinite;
  z-index: 3;
}

.win-line {
  position: absolute;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, #fff6bf 0%, #ffe066 35%, #ffb703 100%);
  box-shadow: 0 0 16px rgba(255, 217, 102, 0.95);
  transform-origin: left center;
  animation: draw-line 0.45s ease-out forwards;
  pointer-events: none;
  z-index: 4;
}

.pulse {
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(239, 71, 111, 0.4);
  }
  50% {
    box-shadow: 0 0 0 10px rgba(239, 71, 111, 0);
  }
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.3);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes draw-line {
  from {
    opacity: 0;
    width: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes win-ring {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}

@media (max-width: 780px) {
  .page {
    padding-top: max(18px, calc(env(safe-area-inset-top) + 8px));
    padding-right: max(14px, env(safe-area-inset-right));
    padding-bottom: 24px;
    padding-left: max(14px, env(safe-area-inset-left));
  }

  .card {
    padding: 16px;
  }

  .board-shell {
    --cell-size: max(20px, min(34px, calc((100vw - 118px) / 9)));
    padding: 2px 3px 8px;
  }

  .board-grid {
    gap: 4px;
    padding: 9px;
  }

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

  .join-grid .btn {
    width: 100%;
  }

  .lobby-options {
    grid-template-columns: 1fr;
  }

  .top-row {
    flex-direction: column;
    align-items: stretch;
  }

  .top-row .btn {
    width: 100%;
  }

  .top-actions {
    flex-direction: column;
    width: 100%;
  }
}

@media (max-width: 420px) {
  .page {
    padding-top: max(16px, calc(env(safe-area-inset-top) + 6px));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-left: max(12px, env(safe-area-inset-left));
  }

  .board-shell {
    --cell-size: max(18px, min(30px, calc((100vw - 104px) / 9)));
    padding: 2px 2px 8px;
  }

  .board-grid {
    gap: 3px;
    padding: 8px;
  }
}
