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

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --primary: #6c63ff;
  --primary-hover: #5a52d5;
  --accent: #ff6584;
  --text: #eaeaea;
  --text-dim: #8888aa;
  --x-color: #6c63ff;
  --o-color: #ff6584;
  --win-glow: #ffd700;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
}

#app {
  width: 100%;
  max-width: 420px;
  padding: 24px;
}

.screen { display: none; flex-direction: column; align-items: center; gap: 18px; }
.screen.active { display: flex; }

h1 {
  font-size: 2.4rem;
  letter-spacing: 2px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

h2 { font-size: 1.6rem; color: var(--text); }

.subtitle { color: var(--text-dim); font-size: 1rem; }

input[type="text"] {
  background: var(--surface);
  border: 2px solid #2a2a4a;
  border-radius: 12px;
  color: var(--text);
  padding: 12px 16px;
  font-size: 1rem;
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
  width: 100%;
  max-width: 260px;
}

input[type="text"]:focus {
  border-color: var(--primary);
}

.code-input {
  font-size: 1.8rem;
  letter-spacing: 8px;
  text-transform: uppercase;
  font-weight: 700;
  max-width: 200px;
}

.btn {
  padding: 14px 32px;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  min-width: 180px;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

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

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

.btn-secondary {
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
}

.btn-secondary:hover {
  background: rgba(108, 99, 255, 0.1);
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  min-width: auto;
  padding: 10px 20px;
}

.btn-ghost:hover {
  color: var(--text);
}

.home-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.error {
  color: var(--accent);
  font-size: 0.9rem;
  min-height: 1.2em;
}

.lobby-code {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: 12px;
  color: var(--primary);
  font-family: monospace;
}

.qr-container {
  background: white;
  padding: 12px;
  border-radius: 12px;
}

.qr-container canvas { display: block; }

.share-hint {
  color: var(--text-dim);
  font-size: 0.85rem;
}

.lobby-players {
  display: flex;
  gap: 24px;
  margin: 8px 0;
}

.player-slot {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 1rem;
}

.player-icon { font-size: 1.2rem; }

.scores {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-dim);
}

/* Game */
.game-header {
  text-align: center;
  width: 100%;
}

.game-info {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 4px;
}

.game-scores {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  font-size: 1.1rem;
}

.score-name { color: var(--text-dim); font-size: 0.85rem; }
.score-val { font-weight: 700; font-size: 1.4rem; }
.score-dash { color: var(--text-dim); }

.game-status {
  font-size: 1.2rem;
  font-weight: 600;
  min-height: 1.5em;
  padding: 6px 0;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  width: 300px;
  height: 300px;
}

.cell {
  background: var(--surface);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.8rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

.cell:hover:not(.taken) {
  background: #24244a;
}

.cell.taken {
  cursor: default;
}

.cell.x { color: var(--x-color); }
.cell.o { color: var(--o-color); }

.cell.win {
  animation: winPulse 0.6s ease-in-out 2;
  box-shadow: 0 0 20px var(--win-glow);
}

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

.result-detail {
  font-size: 1.6rem;
  font-weight: 700;
  text-align: center;
}

.result-scores {
  font-size: 1.2rem;
  color: var(--text-dim);
  text-align: center;
}

.or-divider {
  color: var(--text-dim);
  font-size: 0.85rem;
}

#qr-video {
  width: 200px;
  height: 200px;
  border-radius: 12px;
  object-fit: cover;
  display: none;
  background: #000;
}

@media (max-width: 440px) {
  #app { padding: 16px; }
  .board { width: 280px; height: 280px; }
  .lobby-code { font-size: 2.4rem; letter-spacing: 8px; }
}
