/* ===== TicTacToe Game Styles ===== */

:root {
  --x-color: #3b82f6;
  --o-color: #f59300;
  --board-bg: #0d1117;
  --cell-bg: #161b22;
  --cell-hover: #1c2433;
  --grid-line: #30363d;
  --win-glow: #fbbf24;
}

#ttt-root {
  min-height: 100vh;
  background: var(--board-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 32px 16px 80px;
  position: relative;
  overflow: hidden;
  font-family: 'Neue Montreal', 'Funnel Sans', sans-serif;
}

/* Ambient glow background */
#ttt-root::before {
  content: '';
  position: fixed;
  top: -30%;
  left: 50%;
  transform: translateX(-50%);
  width: 600px;
  height: 400px;
  background: radial-gradient(ellipse, rgba(59,130,246,0.08) 0%, transparent 70%);
  pointer-events: none;
}

/* ===== Board ===== */

.ttt-board-wrap {
  position: relative;
}

.ttt-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 6px;
  width: 330px;
  height: 330px;
  background: var(--grid-line);
  border-radius: 18px;
  padding: 6px;
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.04),
    0 24px 48px rgba(0,0,0,0.6);
}

.ttt-cell {
  background: var(--cell-bg);
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  /* keep every cell locked to its 1fr grid track regardless of content */
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  transition: background 0.12s ease, transform 0.1s ease;
  cursor: crosshair;
}

.ttt-cell.drop-target {
  background: var(--cell-hover);
  transform: scale(1.04);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.12);
}

.ttt-cell.winning {
  animation: win-pulse 0.9s ease-in-out infinite alternate;
}

@keyframes win-pulse {
  from { background: rgba(251, 191, 36, 0.08); box-shadow: inset 0 0 0 2px rgba(251,191,36,0.4); }
  to   { background: rgba(251, 191, 36, 0.18); box-shadow: inset 0 0 0 2px rgba(251,191,36,0.8), 0 0 20px rgba(251,191,36,0.25); }
}

/* ===== Pieces ===== */

.piece-in-cell {
  width: 75%;
  height: 75%;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: piece-pop 0.32s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.piece-in-cell svg {
  width: 100%;
  height: 100%;
}

@keyframes piece-pop {
  0%   { transform: scale(0.2) rotate(20deg); opacity: 0; }
  100% { transform: scale(1) rotate(0deg);    opacity: 1; }
}

/* Used when the local player drops a piece — starts from ghost scale so there's no flash */
.piece-in-cell.dropped {
  animation: piece-land 0.18s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes piece-land {
  0%   { transform: scale(1.18) rotate(-6deg); opacity: 1; }
  100% { transform: scale(1)    rotate(0deg);  opacity: 1; }
}

/* ===== Piece Tray ===== */

.ttt-tray {
  background: #10161f;
  border: 1.5px solid #21262d;
  border-radius: 20px;
  padding: 18px 28px;
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.04);
}

.tray-label {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.25em;
  color: #3d4554;
  background: #10161f;
  padding: 0 10px;
  white-space: nowrap;
}

.tray-divider {
  width: 1px;
  height: 44px;
  background: #21262d;
  margin: 0 6px;
  flex-shrink: 0;
}

.tray-piece {
  width: 58px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: rgba(255,255,255,0.03);
  border: 1.5px solid rgba(255,255,255,0.06);
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease, opacity 0.2s ease;
  cursor: grab;
  user-select: none;
  -webkit-user-drag: none;
  position: relative;
}

.tray-piece svg {
  pointer-events: none;
  width: 34px;
  height: 34px;
  transition: transform 0.15s ease;
}

.tray-piece.can-drag {
  cursor: grab;
}

.tray-piece.can-drag:hover {
  background: rgba(255,255,255,0.07);
  transform: translateY(-5px) scale(1.08);
  box-shadow: 0 10px 28px rgba(0,0,0,0.4);
}

.tray-piece.can-drag:hover svg {
  transform: scale(1.05);
}

.tray-piece.inactive {
  opacity: 0.25;
  cursor: default;
  pointer-events: none;
}

.tray-piece.dragging-source {
  opacity: 0.15;
  transform: scale(0.9);
}

/* Your-symbol glow hint */
.tray-piece.can-drag.x-piece {
  box-shadow: 0 0 0 1px rgba(59,130,246,0.2);
}
.tray-piece.can-drag.o-piece {
  box-shadow: 0 0 0 1px rgba(245,147,0,0.2);
}

/* ===== Floating drag ghost ===== */

#drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  transform: translate(-50%, -50%) rotate(-6deg) scale(1.18);
  filter: drop-shadow(0 14px 28px rgba(0,0,0,0.55));
  display: none;
  align-items: center;
  justify-content: center;
  will-change: left, top;
}

#drag-ghost.active {
  display: flex;
}

#drag-ghost svg {
  width: 72px;
  height: 72px;
}

/* ===== Live cursors (Reverb presence/whisper) ===== */

/* Fixed full-viewport overlay that holds the dynamically-created cursors. */
#ttt-cursors {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9998;
}

.remote-cursor {
  position: fixed;
  pointer-events: none;
  z-index: 9998;
  display: none;
  /* position smoothing handled by requestAnimationFrame in JS (no CSS transition) */
  will-change: left, top;
}

.remote-cursor.visible {
  display: block;
}

.remote-cursor .cursor-svg {
  display: block;
  width: 28px;
  height: auto;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.4));
}

.remote-cursor .cursor-name {
  position: absolute;
  top: 28px;
  left: 16px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
  color: #fff;
  padding: 2px 8px;
  border-radius: 6px;
  opacity: 0.9;
}

.remote-cursor .cursor-drag-piece {
  position: absolute;
  top: -36px;
  left: -36px;
  display: none;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  transform: rotate(-6deg) scale(1.18);
  filter: drop-shadow(0 14px 28px rgba(0,0,0,0.55));
}

.remote-cursor.dragging .cursor-drag-piece {
  display: flex;
}

.remote-cursor.dragging .hand-wrap {
  display: none;
}

.remote-cursor.dragging .cursor-name {
  top: 28px;
  left: 16px;
}

/* ===== Status bar ===== */

.ttt-status-bar {
  text-align: center;
  padding: 10px 28px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.03em;
  border: 1.5px solid #21262d;
  background: #10161f;
  transition: color 0.3s;
  min-width: 260px;
}

/* ===== Player chips ===== */

.player-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px 7px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  border: 2px solid transparent;
  background: rgba(255,255,255,0.04);
  transition: border-color 0.3s, background 0.3s, box-shadow 0.3s;
}

.player-chip.active-turn {
  background: rgba(255,255,255,0.07);
  box-shadow: 0 0 0 2px currentColor, 0 0 16px rgba(255,255,255,0.06);
}

.player-chip .chip-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ===== Room code ===== */

.room-code {
  font-family: monospace;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.28em;
  color: #f59300;
  background: rgba(245,147,0,0.08);
  border: 1.5px solid rgba(245,147,0,0.25);
  border-radius: 8px;
  padding: 5px 16px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  display: inline-block;
}

.room-code:hover {
  background: rgba(245,147,0,0.14);
  border-color: rgba(245,147,0,0.4);
}

/* ===== Win overlay ===== */

.win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(6px);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}

.win-overlay.show {
  display: flex;
  animation: overlay-in 0.35s ease;
}

@keyframes overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.win-card {
  background: #161b22;
  border: 1.5px solid rgba(255,255,255,0.08);
  border-radius: 28px;
  padding: 52px 64px;
  text-align: center;
  box-shadow: 0 32px 80px rgba(0,0,0,0.7);
  animation: card-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: 420px;
  width: 100%;
}

@keyframes card-in {
  from { transform: scale(0.85) translateY(20px); opacity: 0; }
  to   { transform: scale(1) translateY(0);        opacity: 1; }
}

.win-emoji {
  font-size: 56px;
  line-height: 1;
  margin-bottom: 16px;
  display: block;
}

.win-title {
  font-size: 36px;
  font-weight: 800;
  color: #fff;
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}

.win-sub {
  font-size: 14px;
  color: #6e7681;
  margin-bottom: 36px;
}

.btn-play-again {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #f59300;
  color: #000;
  font-weight: 800;
  font-size: 15px;
  padding: 13px 32px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  letter-spacing: 0.02em;
}

.btn-play-again:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(245,147,0,0.4);
}

.btn-play-again:active {
  transform: translateY(0);
}

/* ===== Toast ===== */

#ttt-toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #21262d;
  color: #e6edf3;
  padding: 11px 22px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 10000;
  pointer-events: none;
  white-space: nowrap;
}

#ttt-toast.show {
  transform: translateX(-50%) translateY(0);
}

/* ===== Confetti ===== */

@keyframes confetti-float {
  0%   { transform: translateY(0) rotate(0deg) scale(1);   opacity: 1; }
  100% { transform: translateY(-105vh) rotate(540deg) scale(0.6); opacity: 0; }
}

.confetti-bit {
  position: fixed;
  bottom: -10px;
  border-radius: 2px;
  animation: confetti-float linear forwards;
  pointer-events: none;
  z-index: 2000;
}

/* ===== Waiting dots ===== */

.waiting-dots span {
  display: inline-block;
  animation: dot-bounce 1.2s ease-in-out infinite;
  opacity: 0.6;
}
.waiting-dots span:nth-child(2) { animation-delay: 0.2s; }
.waiting-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40%            { transform: translateY(-5px); }
}

/* ===== Lobby ===== */

.lobby-card {
  background: #10161f;
  border: 1.5px solid #21262d;
  border-radius: 24px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}

.lobby-input {
  width: 100%;
  background: #0d1117;
  border: 1.5px solid #30363d;
  border-radius: 10px;
  color: #e6edf3;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.25em;
  text-align: center;
  padding: 12px;
  text-transform: uppercase;
  transition: border-color 0.2s;
  font-family: monospace;
  outline: none;
}

.lobby-input:focus {
  border-color: #f59300;
}

.lobby-input::placeholder {
  letter-spacing: 0.15em;
  color: #3d4554;
  font-size: 14px;
  font-weight: 500;
  text-transform: none;
}

.lobby-btn-primary {
  width: 100%;
  background: #f59300;
  color: #000;
  font-weight: 800;
  font-size: 15px;
  padding: 13px;
  border-radius: 11px;
  border: none;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  letter-spacing: 0.02em;
}

.lobby-btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(245,147,0,0.35);
}

.lobby-btn-secondary {
  width: 100%;
  background: transparent;
  color: #e6edf3;
  font-weight: 700;
  font-size: 14px;
  padding: 12px;
  border-radius: 11px;
  border: 1.5px solid #30363d;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.lobby-btn-secondary:hover {
  border-color: #6e7681;
  background: rgba(255,255,255,0.04);
}

/* ===== Responsive ===== */

@media (max-width: 400px) {
  .ttt-board { width: 290px; height: 290px; }
  .tray-piece { width: 50px; height: 50px; }
  .win-card { padding: 36px 28px; }
}
