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

:root {
  --bg:          #0d0c14;
  --surface:     #16141f;
  --surface2:    #1e1b2e;
  --border:      #2a2740;
  --x:           #e94560;
  --o:           #4ecca3;
  --muted:       #8b83a8;
  --text:        #fffffe;
  --radius:      18px;
  --tr:          .18s cubic-bezier(.4,0,.2,1);
}

body {
  min-height: 100svh;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 60% 50% at 15% 15%, rgba(233,69,96,.12) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 85% 85%, rgba(78,204,163,.10) 0%, transparent 60%);
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

/* ── Screens ────────────────────────────────────────────── */
.screen { display: none; width: 100%; max-width: 460px; }
.screen.active { display: flex; flex-direction: column; align-items: center; }

/* ── Lobby ──────────────────────────────────────────────── */
.lobby-card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.logo {
  font-size: 3rem;
  font-weight: 900;
  letter-spacing: -2px;
  line-height: 1;
  margin-bottom: 4px;
}
.x-col { color: var(--x); }
.o-col { color: var(--o); }
.sep   { color: var(--muted); font-size: 2rem; margin: 0 4px; }

.lobby-card h1 {
  font-size: 1.8rem;
  font-weight: 900;
  letter-spacing: -1px;
}
.subtitle {
  color: var(--muted);
  font-size: .9rem;
  text-align: center;
  max-width: 280px;
  margin-bottom: 8px;
}

.lobby-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 8px;
}

.divider {
  text-align: center;
  color: var(--muted);
  font-size: .85rem;
  position: relative;
}
.divider::before, .divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 42%;
  height: 1px;
  background: var(--border);
}
.divider::before { left: 0; }
.divider::after  { right: 0; }

.join-row {
  display: flex;
  gap: 8px;
}
.join-row input {
  flex: 1;
}

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 22px;
  border: none;
  border-radius: 12px;
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform var(--tr), filter var(--tr), box-shadow var(--tr);
  font-family: inherit;
}
.btn svg { width: 18px; height: 18px; fill: none; }
.btn:hover  { transform: translateY(-2px); filter: brightness(1.1); }
.btn:active { transform: scale(.97);       filter: brightness(.95); }

.btn-primary {
  background: linear-gradient(135deg, var(--x), #b52040);
  color: #fff;
  box-shadow: 0 4px 20px rgba(233,69,96,.35);
  width: 100%;
}
.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  width: 100%;
}

/* ── Inputs ─────────────────────────────────────────────── */
input[type="text"] {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1rem;
  padding: 13px 16px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--tr);
}
input[type="text"]:focus {
  border-color: var(--x);
}
input::placeholder { color: var(--muted); }

#join-code {
  text-transform: uppercase;
  letter-spacing: 4px;
  font-weight: 700;
  font-size: 1.05rem;
}

/* ── Error ──────────────────────────────────────────────── */
.error-msg {
  color: var(--x);
  font-size: .85rem;
  text-align: center;
}
.hidden { display: none !important; }

/* ── Modal ──────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-inner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.modal-inner h2 { font-size: 1.2rem; font-weight: 700; }

/* ── Waiting ────────────────────────────────────────────── */
.waiting-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 32px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}
.waiting-card h2 { font-size: 1.3rem; font-weight: 700; }
.waiting-card p  { color: var(--muted); font-size: .9rem; }

.spinner {
  width: 52px;
  height: 52px;
  border: 4px solid var(--border);
  border-top-color: var(--x);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.room-code-display {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 20px;
}
#display-room-code {
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: 8px;
  color: var(--o);
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: 8px;
  transition: color var(--tr), background var(--tr);
}
.icon-btn svg { width: 20px; height: 20px; fill: none; }
.icon-btn:hover { color: var(--text); background: var(--surface2); }

.hint { font-size: .78rem !important; }
.link { color: var(--o); word-break: break-all; }

/* ── Game screen ────────────────────────────────────────── */
#screen-game {
  gap: 16px;
}

.game-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.room-badge {
  font-size: .8rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 14px;
}
.room-badge strong { color: var(--text); }

/* ── Scoreboard ─────────────────────────────────────────── */
.scoreboard {
  display: flex;
  gap: 10px;
  width: 100%;
}
.score-card {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: border-color var(--tr), box-shadow var(--tr);
}
.score-card.active-x { border-color: var(--x); box-shadow: 0 0 20px rgba(233,69,96,.2); }
.score-card.active-o { border-color: var(--o); box-shadow: 0 0 20px rgba(78,204,163,.2); }

.score-symbol { font-size: 1.5rem; font-weight: 900; line-height: 1; }
.score-name   { font-size: .65rem; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); text-align: center; max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-num    { font-size: 1.7rem; font-weight: 800; }

/* ── Status ─────────────────────────────────────────────── */
.status-bar {
  font-size: 1rem;
  min-height: 28px;
  text-align: center;
  color: var(--muted);
}

/* ── Board ──────────────────────────────────────────────── */
.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
  aspect-ratio: 1;
}

.cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  font-weight: 900;
  color: transparent;
  transition: background var(--tr), border-color var(--tr), transform var(--tr), color var(--tr);
  position: relative;
}
.cell:not([disabled]):not(.taken):hover {
  background: var(--surface2);
  border-color: #4a4460;
  transform: scale(1.04);
}
.cell:not([disabled]):active { transform: scale(.96); }

.cell.x-cell { color: var(--x); border-color: rgba(233,69,96,.35); }
.cell.o-cell { color: var(--o); border-color: rgba(78,204,163,.35); }

.cell.winning {
  background: linear-gradient(135deg, rgba(233,69,96,.15), rgba(78,204,163,.15));
  border-color: rgba(255,255,255,.2);
  animation: glow 1.2s ease-in-out infinite alternate;
}
@keyframes glow {
  from { box-shadow: 0 0 0   rgba(233,69,96,.3); }
  to   { box-shadow: 0 0 22px rgba(233,69,96,.6); }
}

.cell .mark {
  animation: pop .22s cubic-bezier(.34,1.56,.64,1);
}
@keyframes pop {
  from { transform: scale(0) rotate(-15deg); opacity: 0; }
  to   { transform: scale(1) rotate(0deg);   opacity: 1; }
}

.cell:disabled { cursor: default; }
.cell.taken    { cursor: not-allowed; }

/* ── Game Actions ───────────────────────────────────────── */
.game-actions { width: 100%; display: flex; justify-content: center; }
.game-actions .btn-primary { max-width: 220px; }

/* ── Connection indicator ───────────────────────────────── */
.conn-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .75rem;
  color: var(--muted);
}
.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22C55E;
  animation: pulse-dot 2s ease-in-out infinite;
}
.conn-dot.offline { background: var(--x); animation: none; }
@keyframes pulse-dot {
  0%,100% { opacity: 1; }
  50%      { opacity: .4; }
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 380px) {
  .lobby-card, .waiting-card { padding: 28px 20px; }
  .cell { font-size: 2.2rem; border-radius: 10px; }
  #display-room-code { font-size: 1.5rem; letter-spacing: 5px; }
}
