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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #0f172a;
  color: #f1f5f9;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* ── Screens ── */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}
.screen.active {
  opacity: 1;
  pointer-events: all;
}

/* ── Setup Screen ── */
.title {
  font-size: 3rem;
  font-weight: 900;
  letter-spacing: 0.05em;
  margin-bottom: 2.5rem;
  background: linear-gradient(135deg, #6366f1, #a78bfa, #38bdf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.players-container {
  display: flex;
  align-items: center;
  gap: 2rem;
  margin-bottom: 2.5rem;
}

.player-card {
  background: #1e293b;
  border: 2px solid #334155;
  border-radius: 16px;
  padding: 1.8rem 2rem;
  width: 260px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: border-color 0.3s;
}
.player-card.ready { border-color: #4ade80; }

.player-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #94a3b8;
}

.name-input {
  background: #0f172a;
  border: 1.5px solid #334155;
  border-radius: 8px;
  color: #f1f5f9;
  font-size: 1rem;
  padding: 0.6rem 0.9rem;
  outline: none;
  transition: border-color 0.2s;
  width: 100%;
}
.name-input:focus { border-color: #6366f1; }

.color-label {
  font-size: 0.8rem;
  color: #64748b;
  margin-top: 0.25rem;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, opacity 0.2s;
}
.swatch:hover { transform: scale(1.15); }
.swatch.selected { border-color: #fff; transform: scale(1.2); }
.swatch.taken { opacity: 0.25; cursor: not-allowed; }

.color-warning {
  font-size: 0.75rem;
  color: #f87171;
  min-height: 1rem;
}

/* ── Mode Toggle ── */
.mode-toggle {
  display: flex;
  gap: 0;
  background: #0f172a;
  border: 1.5px solid #334155;
  border-radius: 50px;
  padding: 4px;
  margin-bottom: 2rem;
}
.mode-btn {
  padding: 0.55rem 1.6rem;
  font-size: 0.9rem;
  font-weight: 700;
  background: transparent;
  color: #64748b;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.mode-btn.active {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  box-shadow: 0 2px 10px rgba(99,102,241,0.4);
}

/* ── Saphire AI Card ── */
.saphire-profile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0;
}
.saphire-profile.hidden { display: none; }

.saphire-gem {
  font-size: 2.8rem;
  color: #0F52BA;
  filter: drop-shadow(0 0 12px #0F52BA99);
  animation: gem-pulse 2s ease-in-out infinite alternate;
}
@keyframes gem-pulse {
  from { filter: drop-shadow(0 0 8px #0F52BA88); }
  to   { filter: drop-shadow(0 0 20px #0F52BAcc); }
}

.saphire-name-display {
  font-size: 1.4rem;
  font-weight: 900;
  color: #0F52BA;
  letter-spacing: 0.04em;
  text-shadow: 0 0 16px #0F52BA66;
}

.saphire-role {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #475569;
}

.saphire-color-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #0f172a;
  border: 1.5px solid #334155;
  border-radius: 50px;
  padding: 0.35rem 0.9rem;
  font-size: 0.8rem;
  color: #94a3b8;
  margin-top: 0.25rem;
}
.saphire-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #0F52BA;
  box-shadow: 0 0 6px #0F52BA;
  display: inline-block;
  flex-shrink: 0;
}

/* Locked AI card style */
.player-card.ai-locked {
  border-color: #0F52BA55;
  box-shadow: 0 0 20px #0F52BA22;
}

/* ── Thinking Indicator ── */
.thinking-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  font-weight: 600;
  color: #0F52BA;
  margin-bottom: 0.75rem;
  opacity: 1;
  transition: opacity 0.2s;
}
.thinking-indicator.hidden { display: none; }

.thinking-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #0F52BA;
  animation: thinking-bounce 1.1s ease-in-out infinite;
}
.thinking-dot:nth-child(2) { animation-delay: 0.18s; }
.thinking-dot:nth-child(3) { animation-delay: 0.36s; }
@keyframes thinking-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40%            { transform: translateY(-6px); opacity: 1; }
}

.vs-badge {
  font-size: 1.4rem;
  font-weight: 900;
  color: #475569;
  letter-spacing: 0.05em;
}

.start-btn {
  padding: 0.9rem 3.5rem;
  font-size: 1.1rem;
  font-weight: 700;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s, box-shadow 0.2s;
  box-shadow: 0 4px 24px rgba(99,102,241,0.4);
}
.start-btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 8px 30px rgba(99,102,241,0.5); }
.start-btn:active:not(:disabled) { transform: translateY(0); }
.start-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ── Game Screen ── */
.game-header {
  margin-bottom: 1.25rem;
}

.turn-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #1e293b;
  border-radius: 50px;
  padding: 0.6rem 1.4rem;
  font-size: 1rem;
  font-weight: 600;
  box-shadow: 0 2px 12px rgba(0,0,0,0.3);
  border: 2px solid transparent;
  transition: border-color 0.3s;
}
.turn-indicator.pop {
  animation: indicator-pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes indicator-pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.turn-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-block;
  transition: background 0.3s;
  box-shadow: 0 0 8px currentColor;
}

/* ── Turn Banner ── */
.turn-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(15, 23, 42, 0.92);
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 60px;
  padding: 0.9rem 2.2rem;
  font-size: 1.5rem;
  font-weight: 800;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}
.turn-banner.hidden { display: none; }
.turn-banner.show {
  animation: banner-pop 0.85s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
@keyframes banner-pop {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  30%  { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
  60%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  80%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
}

.turn-banner-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

/* ── Board ── */
.board-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.ghost-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  padding: 0 8px;
  margin-bottom: 4px;
  height: 52px;
}

.ghost-cell {
  width: 64px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.ghost-piece {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  opacity: 0.35;
  transition: opacity 0.15s;
  pointer-events: none;
}

.board {
  background: #1a4a8a;
  border-radius: 14px;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: 6px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5), inset 0 2px 8px rgba(255,255,255,0.05);
}

.cell {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #0f172a;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: background 0.15s;
}
.cell:hover { background: #162032; }

/* The piece inside a cell */
.piece {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  transform: translateY(-420px);
  transition: transform 0.45s cubic-bezier(0.55, 0, 1, 0.45);
}
.piece.landed { transform: translateY(0); }

/* Winning cell glow — applied to the cell itself so it isn't clipped */
.cell.winner-cell {
  transform: scale(1.12);
  z-index: 2;
  animation: pulse-win 0.75s ease-in-out infinite alternate;
}
.cell.winner-cell .piece {
  filter: brightness(1.25);
}
@keyframes pulse-win {
  from { box-shadow: 0 0 0 3px #fff, 0 0 14px 6px rgba(255,255,255,0.5); }
  to   { box-shadow: 0 0 0 6px #fff, 0 0 32px 12px rgba(255,255,255,0.85); }
}

/* Dim all non-winning pieces when the board has a winner */
.board.has-winner .cell:not(.winner-cell) {
  opacity: 0.3;
}

/* Canvas line connecting the winning 4 cells */
.win-line-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
}

/* ── Result Overlay ── */
.result-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  transition: opacity 0.4s;
}
.result-overlay.hidden { opacity: 0; pointer-events: none; }

.result-box {
  background: #1e293b;
  border: 2px solid #334155;
  border-radius: 20px;
  padding: 2.5rem 3.5rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  animation: pop-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes pop-in {
  from { transform: scale(0.6); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

.result-text {
  font-size: 2.2rem;
  font-weight: 900;
  line-height: 1.2;
}

.play-again-btn {
  padding: 0.8rem 2.5rem;
  font-size: 1rem;
  font-weight: 700;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s;
  box-shadow: 0 4px 18px rgba(99,102,241,0.4);
}
.play-again-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(99,102,241,0.5); }
.play-again-btn:active { transform: translateY(0); }

/* ── Confetti Canvas ── */
#confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 100;
}
