@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;800&display=swap');

:root {
  --bg-dark: #0f0f1a;
  --bg-card: rgba(20, 20, 40, 0.85);
  --accent-primary: #6366f1;
  --accent-secondary: #8b5cf6;
  --accent-glow: rgba(99, 102, 241, 0.4);
  --player-x: #f43f5e;
  --player-o: #22d3ee;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --success: #10b981;
  --border: rgba(255, 255, 255, 0.1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow-x: hidden;
}

body {
  font-family: 'Poppins', sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  min-height: -webkit-fill-available;
  min-height: 100vh;
}

.game-wrapper {
  position: relative;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  overflow: hidden;
}

/* Animated Background Orbs */
.bg-animation {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.5;
  animation: float 8s ease-in-out infinite;
}

.orb-1 {
  width: 300px;
  height: 300px;
  background: var(--accent-primary);
  top: -100px;
  left: -100px;
  animation-delay: 0s;
}

.orb-2 {
  width: 250px;
  height: 250px;
  background: var(--player-x);
  bottom: -50px;
  right: -50px;
  animation-delay: 2s;
}

.orb-3 {
  width: 200px;
  height: 200px;
  background: var(--player-o);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation-delay: 4s;
}

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -30px) scale(1.1); }
  66% { transform: translate(-20px, 20px) scale(0.95); }
}

/* Main Container */
.ttt-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 350px;
  background: var(--bg-card);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 20px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

/* Header */
.ttt-header {
  text-align: center;
  margin-bottom: 20px;
}

.ttt-header h1 {
  font-size: 1.8rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.ttt-header .icon {
  font-size: 1.5rem;
}

.tagline {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

/* Mode Selector */
.mode-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid transparent;
  border-radius: 12px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: inherit;
}

.mode-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.mode-btn.active {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(139, 92, 246, 0.2));
  border-color: var(--accent-primary);
  color: var(--text);
}

.mode-icon {
  font-size: 1.5rem;
}

.mode-text {
  font-size: 0.85rem;
  font-weight: 600;
}

/* Lobby Panel */
.lobby-panel.hidden { display: none; }
.lobby-panel {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 16px;
}

.lobby-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.action-btn {
  padding: 12px 20px;
  border: none;
  border-radius: 10px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.create-btn {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  color: white;
  width: 100%;
  justify-content: center;
}

.create-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px var(--accent-glow);
}

.or-divider {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.join-row {
  display: flex;
  gap: 8px;
  width: 100%;
}

.join-row input {
  flex: 1;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  text-transform: uppercase;
  text-align: center;
  letter-spacing: 2px;
}

.join-row input:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.join-btn {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  border: 2px solid var(--border);
}

.join-btn:hover {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
}

.lobby-msg {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Status Bar */
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 12px;
  margin-bottom: 16px;
}

.status-text {
  font-weight: 600;
}

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

.room-info {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Game Board */
.ttt-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
  touch-action: manipulation;
}

.cell {
  aspect-ratio: 1;
  border: none;
  border-radius: 16px;
  background: linear-gradient(145deg, rgba(255,255,255,0.1), rgba(255,255,255,0.02));
  font-size: clamp(2rem, 12vw, 3.5rem);
  font-weight: 800;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}

.cell::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent, rgba(255,255,255,0.1));
  opacity: 0;
  transition: opacity 0.3s;
}

.cell:hover::before {
  opacity: 1;
}

.cell:hover {
  transform: scale(1.03);
}

.cell:active {
  transform: scale(0.97);
}

.cell.x {
  color: var(--player-x);
  text-shadow: 0 0 30px var(--player-x);
}

.cell.o {
  color: var(--player-o);
  text-shadow: 0 0 30px var(--player-o);
}

.cell.win {
  animation: winPulse 0.5s ease infinite alternate;
}

@keyframes winPulse {
  from { box-shadow: 0 0 20px var(--success); }
  to { box-shadow: 0 0 40px var(--success); }
}

.cell[disabled] {
  cursor: default;
}

/* Scoreboard */
.scoreboard {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.score-item {
  text-align: center;
  padding: 12px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 12px;
}

.score-item:first-child {
  border-left: 3px solid var(--player-x);
}

.score-item:last-child {
  border-left: 3px solid var(--player-o);
}

.score-item.draws {
  border-left: 3px solid var(--text-muted);
}

.score-label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.score-value {
  font-size: 1.5rem;
  font-weight: 800;
}

/* Actions */
.ttt-actions {
  display: flex;
  justify-content: center;
}

.reset-btn {
  padding: 14px 32px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border: none;
  border-radius: 12px;
  color: white;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  -webkit-tap-highlight-color: transparent;
}

.reset-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 30px var(--accent-glow);
}

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

/* Mobile Responsive */
@media (max-width: 480px) {
  .game-wrapper { padding: 12px; }
  .ttt-container { padding: 16px; border-radius: 20px; }
  .ttt-header h1 { font-size: 1.5rem; }
  .cell { border-radius: 12px; }
  .scoreboard { gap: 6px; }
  .score-item { padding: 10px 8px; }
  .score-value { font-size: 1.3rem; }
}

@media (max-width: 360px) {
  .ttt-container { padding: 12px; }
  .mode-selector { gap: 6px; }
  .mode-btn { padding: 10px; }
  .ttt-board { gap: 6px; }
  .reset-btn { padding: 12px 24px; font-size: 0.9rem; }
}

/* Landscape Mobile */
@media (max-height: 600px) and (orientation: landscape) {
  .game-wrapper { 
    align-items: flex-start; 
    padding: 10px;
  }
  .ttt-container { 
    max-width: 600px; 
    padding: 12px;
  }
  .ttt-header { margin-bottom: 10px; }
  .ttt-header h1 { font-size: 1.3rem; }
  .tagline { display: none; }
  .mode-selector { margin-bottom: 10px; }
  .status-bar { padding: 8px 12px; margin-bottom: 10px; }
  .ttt-board { gap: 6px; margin-bottom: 10px; }
  .scoreboard { margin-bottom: 10px; }
  .cell { font-size: 2rem; }
}
