/* ── Reset & Variables ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d0d0d;
  --surface:   #161616;
  --border:    #2a2a2a;
  --x-color:   #ff3b3b;
  --o-color:   #3baaff;
  --text:      #f0f0f0;
  --muted:     #555;
  --accent:    #ffe600;
  --success:   #00e676;

  --cell-size: 130px;
  --gap:       6px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Space Mono', monospace;
  overflow: hidden;
}

/* ── Background ─────────────────────────────────────────────────────── */
.bg-grid {
  position: fixed; inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

.bg-glow {
  position: fixed; inset: 0;
  background: radial-gradient(ellipse 80% 60% at 50% 50%, rgba(255,230,0,0.04) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* ── App / Screens ──────────────────────────────────────────────────── */
.app {
  position: relative; z-index: 1;
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
}

.screen {
  display: none;
  width: 100%; height: 100%;
  align-items: center; justify-content: center;
}
.screen.active { display: flex; }

/* ── LOBBY ──────────────────────────────────────────────────────────── */
.lobby-card {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 48px 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  min-width: 380px;
  box-shadow: 0 0 60px rgba(255,230,0,0.06), 0 20px 60px rgba(0,0,0,0.6);
  animation: slideUp 0.4s cubic-bezier(0.16,1,0.3,1);
}

@keyframes slideUp {
  from { transform: translateY(40px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.game-title {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 5rem;
  letter-spacing: 0.15em;
  color: var(--accent);
  text-shadow: 0 0 30px rgba(255,230,0,0.4), 0 0 80px rgba(255,230,0,0.15);
  line-height: 1;
}

.game-sub {
  font-size: 0.6rem;
  letter-spacing: 0.3em;
  color: var(--muted);
  text-transform: uppercase;
  margin-top: -16px;
}

.lobby-status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.7rem;
  color: var(--muted);
  letter-spacing: 0.1em;
}

.spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Status boxes */
.status-box {
  width: 100%;
  padding: 16px 20px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.status-box-label {
  font-size: 0.5rem;
  letter-spacing: 0.3em;
  color: var(--muted);
  text-transform: uppercase;
}

.status-box-value {
  font-size: 0.8rem;
  letter-spacing: 0.1em;
}

.status-box-value.ok    { color: var(--success); }
.status-box-value.warn  { color: var(--accent); }
.status-box-value.error { color: var(--x-color); }

/* Players mini display */
.lobby-players {
  display: flex;
  gap: 12px;
  width: 100%;
}

.lobby-player-slot {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--border);
  text-align: center;
  font-size: 0.55rem;
  letter-spacing: 0.1em;
}

.lobby-player-slot .sym {
  font-size: 1.4rem;
  display: block;
  margin-bottom: 4px;
}
.lobby-player-slot .sym.x { color: var(--x-color); }
.lobby-player-slot .sym.o { color: var(--o-color); }
.lobby-player-slot.filled { border-color: var(--muted); }
.lobby-player-slot.empty  { opacity: 0.35; border-style: dashed; }

/* Buttons */
.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.btn-action {
  font-family: 'Space Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  padding: 14px 20px;
  border: 1px solid;
  cursor: pointer;
  text-transform: uppercase;
  transition: all 0.15s;
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #000;
  font-weight: 700;
}
.btn-primary:hover {
  background: #fff176;
  box-shadow: 0 0 20px rgba(255,230,0,0.4);
}

.btn-secondary {
  background: transparent;
  border-color: var(--o-color);
  color: var(--o-color);
}
.btn-secondary:hover {
  background: rgba(59,170,255,0.08);
  box-shadow: 0 0 15px rgba(59,170,255,0.2);
}

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

.hidden { display: none !important; }

/* ── GAME SCREEN ────────────────────────────────────────────────────── */
.game-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 24px;
  animation: slideUp 0.35s cubic-bezier(0.16,1,0.3,1);
}

.game-header {
  display: flex;
  align-items: center;
  gap: 20px;
}

.game-title-sm {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 2.8rem;
  letter-spacing: 0.2em;
  color: var(--accent);
  text-shadow: 0 0 20px rgba(255,230,0,0.3);
}

.role-badge {
  font-size: 0.5rem;
  letter-spacing: 0.2em;
  padding: 4px 10px;
  border: 1px solid var(--muted);
  color: var(--muted);
  text-transform: uppercase;
}

/* Status bar */
.status-bar {
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  color: var(--muted);
  text-align: center;
  min-height: 1.4em;
  transition: color 0.3s;
}

/* Players row */
.players-row {
  display: flex;
  align-items: center;
  gap: 24px;
}

.player-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 24px;
  border: 1px solid var(--border);
  background: var(--surface);
  min-width: 120px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.player-card.active-turn {
  border-color: var(--accent);
  box-shadow: 0 0 20px rgba(255,230,0,0.15);
}

.player-sym {
  font-size: 2rem;
  line-height: 1;
  font-family: 'Bebas Neue', sans-serif;
}
.x-sym { color: var(--x-color); text-shadow: 0 0 15px rgba(255,59,59,0.5); }
.o-sym { color: var(--o-color); text-shadow: 0 0 15px rgba(59,170,255,0.5); }

.player-name {
  font-size: 0.5rem;
  letter-spacing: 0.15em;
  color: var(--muted);
  text-transform: uppercase;
}

.vs-badge {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.5rem;
  color: var(--border);
  letter-spacing: 0.1em;
}

/* ── Board ──────────────────────────────────────────────────────────── */
.board-container {
  position: relative;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, var(--cell-size));
  grid-template-rows: repeat(3, var(--cell-size));
  gap: var(--gap);
  background: var(--border);
  border: var(--gap) solid var(--border);
}

.cell {
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-family: 'Bebas Neue', sans-serif;
  font-size: 4.5rem;
  transition: background 0.15s, transform 0.1s;
  user-select: none;
  position: relative;
  overflow: hidden;
}

.cell::after {
  content: '';
  position: absolute; inset: 0;
  background: rgba(255,230,0,0.06);
  opacity: 0;
  transition: opacity 0.15s;
}

.cell:hover:not(.taken)::after { opacity: 1; }
.cell.taken { cursor: default; }

.cell .mark {
  animation: popIn 0.2s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes popIn {
  from { transform: scale(0) rotate(-15deg); opacity: 0; }
  to   { transform: scale(1) rotate(0deg);   opacity: 1; }
}

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

.cell.win-cell {
  background: rgba(255,230,0,0.07);
}

/* Win line SVG */
.win-line-svg {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  overflow: visible;
}

#win-line {
  stroke: var(--accent);
  stroke-width: 0.12;
  stroke-linecap: round;
  opacity: 0;
  transition: opacity 0.3s;
  filter: drop-shadow(0 0 6px rgba(255,230,0,0.8));
}
#win-line.visible {
  opacity: 1;
  stroke-dasharray: 5;
  stroke-dashoffset: 5;
  animation: drawLine 0.4s ease forwards;
}
@keyframes drawLine {
  to { stroke-dashoffset: 0; }
}

/* ── Result banner ──────────────────────────────────────────────────── */
.result-banner {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 2.2rem;
  letter-spacing: 0.2em;
  text-align: center;
  padding: 12px 28px;
  border: 1px solid;
  animation: slideUp 0.3s cubic-bezier(0.16,1,0.3,1);
}

.result-banner.win-x  { color: var(--x-color); border-color: var(--x-color); box-shadow: 0 0 25px rgba(255,59,59,0.25); }
.result-banner.win-o  { color: var(--o-color); border-color: var(--o-color); box-shadow: 0 0 25px rgba(59,170,255,0.25); }
.result-banner.draw   { color: var(--accent);  border-color: var(--accent);  box-shadow: 0 0 25px rgba(255,230,0,0.2); }
.result-banner.my-win { background: rgba(0,230,118,0.05); }

/* ── Game actions ───────────────────────────────────────────────────── */
.game-actions {
  display: flex;
  gap: 12px;
}

.game-actions .btn-action {
  width: auto;
  min-width: 140px;
}

/* ── Spectator ──────────────────────────────────────────────────────── */
.spectator-notice {
  font-size: 0.6rem;
  letter-spacing: 0.15em;
  color: var(--muted);
  padding: 10px 20px;
  border: 1px dashed var(--border);
  text-align: center;
}

/* ── Responsive ─────────────────────────────────────────────────────── */
@media (max-width: 520px) {
  :root { --cell-size: 90px; }
  .cell { font-size: 3rem; }
  .lobby-card { padding: 32px 24px; min-width: 0; width: 92vw; }
  .game-title { font-size: 3.5rem; }
  .score-panel { right: 8px; top: 50%; transform: translateY(-50%); padding: 12px 10px; gap: 8px; }
  .score-value { font-size: 2rem; }
}

/* ── Score Panel ────────────────────────────────────────────────────── */
.score-panel {
  position: fixed;
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 0 40px rgba(0,0,0,0.5), inset 0 0 0 1px rgba(255,255,255,0.03);
  min-width: 72px;
}

.score-panel-label {
  font-size: 0.45rem;
  letter-spacing: 0.35em;
  color: var(--muted);
  text-transform: uppercase;
}

.score-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.score-sym {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.4rem;
  line-height: 1;
}
.score-sym.x { color: var(--x-color); text-shadow: 0 0 10px rgba(255,59,59,0.4); }
.score-sym.o { color: var(--o-color); text-shadow: 0 0 10px rgba(59,170,255,0.4); }

.score-value {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 2.6rem;
  line-height: 1;
  letter-spacing: 0.05em;
  transition: color 0.2s;
}
.x-val { color: var(--x-color); }
.o-val { color: var(--o-color); }

/* Flash animation when score increases */
@keyframes scoreBump {
  0%   { transform: scale(1);    filter: brightness(1); }
  35%  { transform: scale(1.45); filter: brightness(1.8); }
  70%  { transform: scale(0.95); filter: brightness(1.2); }
  100% { transform: scale(1);    filter: brightness(1); }
}
.score-bump { animation: scoreBump 0.45s cubic-bezier(0.34,1.56,0.64,1); }

.score-divider {
  width: 100%;
  height: 1px;
  background: var(--border);
}
