@import url("https://fonts.googleapis.com/css2?family=Manrope:wght@300;400;600;700&family=Space+Grotesk:wght@400;600;700&display=swap");

:root {
  color-scheme: dark;
  --bg: #0b0f17;
  --bg-soft: #121826;
  --card: rgba(18, 24, 38, 0.7);
  --border: rgba(255, 255, 255, 0.08);
  --text: #e6e8ee;
  --muted: rgba(230, 232, 238, 0.65);
  --accent: #6ee7ff;
  --accent-2: #a78bfa;
  --success: #34d399;
  --danger: #f87171;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  font-family: "Manrope", sans-serif;
  color: var(--text);
  background: var(--bg);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 32px 16px;
  overflow-x: hidden;
}

.bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(800px 300px at 15% 20%, rgba(110, 231, 255, 0.15), transparent 70%),
    radial-gradient(700px 300px at 80% 10%, rgba(167, 139, 250, 0.15), transparent 70%),
    radial-gradient(900px 400px at 40% 90%, rgba(52, 211, 153, 0.12), transparent 70%),
    linear-gradient(160deg, #0b0f17 0%, #0e1320 50%, #0b0f17 100%);
  z-index: -2;
}

.app {
  width: min(1080px, 100%);
  display: grid;
  gap: 24px;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo {
  font-family: "Space Grotesk", sans-serif;
  font-size: 24px;
  font-weight: 700;
  width: 54px;
  height: 54px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: linear-gradient(140deg, rgba(110, 231, 255, 0.4), rgba(167, 139, 250, 0.4));
  box-shadow: var(--shadow);
}

.header h1 {
  font-family: "Space Grotesk", sans-serif;
  font-size: 28px;
}

.header p {
  color: var(--muted);
  font-size: 14px;
}

.status {
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(110, 231, 255, 0.12);
  border: 1px solid rgba(110, 231, 255, 0.2);
  color: var(--accent);
  font-weight: 600;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.room {
  display: grid;
  gap: 20px;
}

.room-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.join {
  display: flex;
  gap: 10px;
}

input {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  min-width: 160px;
}

.btn {
  border: none;
  padding: 10px 18px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn.primary {
  background: linear-gradient(135deg, #6ee7ff, #a78bfa);
  color: #0b0f17;
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
}

.room-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.room-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.label {
  font-size: 12px;
  color: var(--muted);
}

.value {
  font-size: 18px;
  font-weight: 700;
}

.game {
  display: grid;
  gap: 24px;
}

.game-header {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
}

.turn {
  background: rgba(255, 255, 255, 0.04);
  border-radius: 16px;
  padding: 14px 16px;
  border: 1px solid var(--border);
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, minmax(84px, 1fr));
  gap: 12px;
  touch-action: none;
  pointer-events: auto;
}

.cell {
  aspect-ratio: 1 / 1;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  font-family: "Space Grotesk", sans-serif;
  font-size: 48px;
  color: var(--text);
  cursor: pointer;
  touch-action: none;
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.25s ease, background 0.25s ease, box-shadow 0.25s ease;
  display: grid;
  place-items: center;
}

.cell:focus-visible {
  outline: 2px solid rgba(110, 231, 255, 0.5);
  outline-offset: 2px;
}

.cell:hover {
  background: rgba(255, 255, 255, 0.08);
  transform: translateY(-2px) scale(1.02);
}

.cell.x {
  color: var(--accent);
  text-shadow: 0 10px 30px rgba(110, 231, 255, 0.4);
}

.cell.o {
  color: var(--accent-2);
  text-shadow: 0 10px 30px rgba(167, 139, 250, 0.4);
}

.cell span {
  animation: pop 0.25s ease;
}

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

.win-line {
  position: absolute;
  height: 6px;
  width: 0;
  background: linear-gradient(90deg, #34d399, #6ee7ff);
  border-radius: 999px;
  top: 50%;
  left: 50%;
  transform-origin: left center;
  transform: translate(-50%, -50%);
  transition: width 0.4s ease;
  box-shadow: 0 10px 20px rgba(52, 211, 153, 0.4);
  pointer-events: none;
  opacity: 0;
}

.win-line.show {
  opacity: 1;
  width: 110%;
}

.game-actions {
  display: flex;
  justify-content: flex-end;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 12, 0.7);
  display: grid;
  place-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: rgba(15, 19, 32, 0.85);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 28px;
  min-width: min(360px, 90vw);
  text-align: center;
  box-shadow: var(--shadow);
  animation: rise 0.35s ease;
}

@keyframes rise {
  from {
    transform: translateY(20px) scale(0.98);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.modal-title {
  font-family: "Space Grotesk", sans-serif;
  font-size: 24px;
  margin-bottom: 12px;
}

.modal-body {
  color: var(--muted);
  margin-bottom: 18px;
}

@media (max-width: 720px) {
  .header {
    flex-direction: column;
    align-items: flex-start;
  }

  .room-info {
    flex-direction: column;
    align-items: flex-start;
  }

  .game-actions {
    justify-content: center;
  }

  .room-actions {
    width: 100%;
  }

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

  input {
    width: 100%;
  }

  .room-buttons {
    width: 100%;
    justify-content: flex-start;
  }

  .board {
    grid-template-columns: repeat(3, minmax(70px, 1fr));
    gap: 10px;
  }

  .cell {
    font-size: 40px;
    border-radius: 16px;
  }
}
