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

:root {
  --bg:       #0f0f13;
  --surface:  #17171f;
  --surface2: #1e1e28;
  --border:   #2e2e40;
  --text:     #eeeef5;
  --muted:    #555568;

  --p1:       #ff4e4e;
  --p1-glow:  rgba(255, 78, 78, 0.5);
  --p1-dim:   rgba(255, 78, 78, 0.15);
  --p2:       #ffe033;
  --p2-glow:  rgba(255, 224, 51, 0.5);
  --p2-dim:   rgba(255, 224, 51, 0.15);
  --empty:    #12121a;
  --board-bg: #1a1a2e;
  --board-border: #252540;

  --cols: 7;
  --rows: 6;
  --cell: 72px;
  --gap:  6px;
  --radius: calc(var(--cell) / 2);
}

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

/* ── App / Screens ───────────────────────────────────────────────────── */
.app { 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; }
.hidden { display: none !important; }

/* ── LOBBY ───────────────────────────────────────────────────────────── */
.lobby-card {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 48px 56px;
  display: flex; flex-direction: column; align-items: center; gap: 32px;
  min-width: 420px;
  box-shadow: 0 0 80px rgba(255,78,78,0.06), 0 0 120px rgba(255,224,51,0.04), 0 30px 80px rgba(0,0,0,0.6);
  animation: popUp 0.4s cubic-bezier(0.16,1,0.3,1);
}
@keyframes popUp { from { transform: scale(0.92) translateY(20px); opacity: 0; } to { transform: scale(1) translateY(0); opacity: 1; } }

.title-block { text-align: center; }

.game-title {
  font-family: 'Syne', sans-serif;
  font-size: 3.8rem; font-weight: 800;
  letter-spacing: 0.05em; line-height: 1;
  color: var(--text);
}
.four {
  color: var(--p1);
  text-shadow: 0 0 20px var(--p1-glow), 0 0 50px rgba(255,78,78,0.3);
  font-size: 1.2em;
}
.game-sub { font-size: 0.55rem; letter-spacing: 0.3em; color: var(--muted); margin-top: 8px; text-transform: uppercase; }

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

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

/* Slots */
.lobby-slots { display: flex; align-items: center; gap: 20px; width: 100%; }
.p-slot {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 20px 16px; border: 1px solid var(--border); background: var(--surface2);
  transition: border-color 0.3s;
}
.p-slot.connected { border-color: var(--muted); }
.p-slot.me-1 { border-color: var(--p1); box-shadow: 0 0 20px var(--p1-dim); }
.p-slot.me-2 { border-color: var(--p2); box-shadow: 0 0 20px var(--p2-dim); }

.slot-disc { width: 40px; height: 40px; border-radius: 50%; opacity: 0.3; transition: opacity 0.3s; }
.p-slot.connected .slot-disc, .p-slot.me-1 .slot-disc, .p-slot.me-2 .slot-disc { opacity: 1; }
.disc-1 { background: var(--p1); box-shadow: 0 0 15px var(--p1-glow); }
.disc-2 { background: var(--p2); box-shadow: 0 0 15px var(--p2-glow); }

.p-slot span { font-size: 0.5rem; letter-spacing: 0.1em; color: var(--muted); text-transform: uppercase; }
.p-slot.me-1 span { color: var(--p1); }
.p-slot.me-2 span { color: var(--p2); }

.slot-vs { font-family: 'Syne', sans-serif; font-size: 1.4rem; font-weight: 800; color: var(--border); }

/* Buttons */
.lobby-actions { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.btn {
  font-family: 'JetBrains Mono', monospace; font-size: 0.65rem; letter-spacing: 0.15em;
  padding: 13px 20px; border: 1px solid; cursor: pointer; text-transform: uppercase;
  transition: all 0.15s; background: transparent; width: 100%;
}
.btn-primary  { background: var(--p1); border-color: var(--p1); color: #fff; font-weight: 700; }
.btn-primary:hover  { background: #ff6b6b; box-shadow: 0 0 20px var(--p1-glow); }
.btn-secondary { border-color: var(--p2); color: var(--p2); }
.btn-secondary:hover { background: var(--p2-dim); box-shadow: 0 0 15px var(--p2-glow); }
.btn-ghost { border-color: var(--border); color: var(--muted); }
.btn-ghost:hover { border-color: var(--text); color: var(--text); }

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

.game-header { display: flex; align-items: center; gap: 16px; }
.title-sm { font-family: 'Syne', sans-serif; font-size: 2rem; font-weight: 800; letter-spacing: 0.05em; }
.badge { font-size: 0.48rem; letter-spacing: 0.2em; padding: 4px 10px; border: 1px solid var(--muted); color: var(--muted); text-transform: uppercase; }

/* Players row */
.players-row { display: flex; align-items: center; gap: 24px; width: 100%; justify-content: center; }
.player-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 18px; border: 1px solid var(--border);
  background: var(--surface2);
  transition: border-color 0.3s, box-shadow 0.3s;
  min-width: 160px;
}
.player-card.active {
  border-color: var(--p1);
  box-shadow: 0 0 20px var(--p1-dim);
}
#card-2.active {
  border-color: var(--p2);
  box-shadow: 0 0 20px var(--p2-dim);
}

.disc { width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0; }
.p-label { font-size: 0.55rem; letter-spacing: 0.1em; color: var(--muted); flex: 1; text-transform: uppercase; }
.player-card.active .p-label { color: var(--text); }

.turn-arrow { font-size: 0.7rem; opacity: 0; transition: opacity 0.2s; }
#card-1 .turn-arrow { color: var(--p1); }
#card-2 .turn-arrow { color: var(--p2); }
.player-card.active .turn-arrow { opacity: 1; animation: bounce 0.6s ease infinite alternate; }
@keyframes bounce { from { transform: translateY(0); } to { transform: translateY(4px); } }

.status-text { font-size: 0.55rem; letter-spacing: 0.12em; color: var(--muted); text-align: center; min-width: 120px; }

/* Column hover hints */
.col-hints { width: calc(var(--cols) * (var(--cell) + var(--gap)) - var(--gap)); }
.col-hint-row { display: flex; gap: var(--gap); }
.col-hint {
  width: var(--cell); height: 20px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; opacity: 0; transition: opacity 0.15s;
  font-size: 0.6rem; color: var(--muted);
}
.col-hint:hover { opacity: 1 !important; }
.col-hints.my-turn .col-hint { opacity: 0.3; }
.col-hints.my-turn .col-hint:hover { opacity: 1; }

/* Board */
.board-wrap { position: relative; }
.board {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-template-rows: repeat(var(--rows), var(--cell));
  gap: var(--gap);
  background: var(--board-bg);
  border: 3px solid var(--board-border);
  border-radius: 12px;
  padding: var(--gap);
  box-shadow: 0 8px 40px rgba(0,0,0,0.6), inset 0 2px 0 rgba(255,255,255,0.04);
}

/* Cells */
.cell {
  width: var(--cell); height: var(--cell);
  border-radius: var(--radius);
  background: var(--empty);
  box-shadow: inset 0 3px 8px rgba(0,0,0,0.5);
  cursor: pointer;
  transition: background 0.1s;
  position: relative;
  overflow: hidden;
}
.cell::after {
  content: '';
  position: absolute; inset: 0; border-radius: var(--radius);
  background: rgba(255,255,255,0.04);
  opacity: 0; transition: opacity 0.15s;
}
.cell.hoverable:hover::after { opacity: 1; }
.cell.hoverable:hover { background: rgba(255,255,255,0.04); }

.cell.p1 {
  background: var(--p1);
  box-shadow: 0 0 12px var(--p1-glow), inset 0 3px 0 rgba(255,255,255,0.25), inset 0 -3px 0 rgba(0,0,0,0.2);
  animation: dropIn 0.25s cubic-bezier(0.34,1.4,0.64,1);
}
.cell.p2 {
  background: var(--p2);
  box-shadow: 0 0 12px var(--p2-glow), inset 0 3px 0 rgba(255,255,255,0.3), inset 0 -3px 0 rgba(0,0,0,0.15);
  animation: dropIn 0.25s cubic-bezier(0.34,1.4,0.64,1);
}

@keyframes dropIn {
  from { transform: scaleY(0.3) translateY(-20px); opacity: 0.5; }
  to   { transform: scaleY(1)   translateY(0);     opacity: 1; }
}

/* Winning cells */
.cell.win {
  animation: winPulse 0.6s ease infinite alternate;
  z-index: 2;
}
.cell.p1.win { box-shadow: 0 0 25px var(--p1-glow), 0 0 50px var(--p1-glow); }
.cell.p2.win { box-shadow: 0 0 25px var(--p2-glow), 0 0 50px var(--p2-glow); }
@keyframes winPulse {
  from { transform: scale(1); }
  to   { transform: scale(1.08); }
}

/* Result */
.result-banner {
  font-family: 'Syne', sans-serif; font-weight: 800;
  font-size: 2.2rem; letter-spacing: 0.1em; text-align: center;
  padding: 14px 36px; border: 2px solid;
  animation: popUp 0.3s cubic-bezier(0.16,1,0.3,1);
}
.result-banner.win-1  { color: var(--p1); border-color: var(--p1); box-shadow: 0 0 30px var(--p1-dim); }
.result-banner.win-2  { color: var(--p2); border-color: var(--p2); box-shadow: 0 0 30px var(--p2-dim); }
.result-banner.draw   { color: var(--muted); border-color: var(--border); }
.result-banner.my-win { background: rgba(255,255,255,0.03); }

/* Actions */
.game-actions { display: flex; gap: 12px; }
.game-actions .btn { width: auto; min-width: 140px; }

/* Spectator */
.spec-note { font-size: 0.55rem; letter-spacing: 0.15em; color: var(--muted); padding: 8px 18px; border: 1px dashed var(--border); }

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  :root { --cell: 46px; --gap: 4px; }
  .lobby-card { padding: 32px 24px; min-width: 0; width: 94vw; }
  .game-title { font-size: 2.8rem; }
  .players-row { gap: 12px; }
  .player-card { min-width: 120px; padding: 8px 12px; }
  .score-panel { right: 8px; padding: 12px 10px; gap: 8px; }
  .score-value { font-size: 2rem; }
}
@media (max-width: 400px) {
  :root { --cell: 38px; --gap: 3px; }
}

/* ── 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: 14px;
  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.42rem;
  letter-spacing: 0.35em;
  color: var(--muted);
  text-transform: uppercase;
}

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

/* Small disc indicator in score panel */
.score-disc {
  width: 22px; height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
}
.score-disc.disc-1 { background: var(--p1); box-shadow: 0 0 10px var(--p1-glow); }
.score-disc.disc-2 { background: var(--p2); box-shadow: 0 0 10px var(--p2-glow); }

.score-value {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 2.6rem;
  line-height: 1;
  letter-spacing: 0.02em;
}
.s-val-1 { color: var(--p1); }
.s-val-2 { color: var(--p2); }

/* Flash animation when score increases */
@keyframes scoreBump {
  0%   { transform: scale(1);    filter: brightness(1); }
  35%  { transform: scale(1.5);  filter: brightness(2); }
  70%  { transform: scale(0.93); filter: brightness(1.3); }
  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);
}
