/* Watershed Web - Flagship CRDT Territory Game */

:root {
  /* Core palette - dark, atmospheric, with neon accents */
  --bg-deep: #0a0a0f;
  --bg-dark: #12121a;
  --bg-surface: #1a1a25;
  --bg-elevated: #252535;

  /* Player colors - vibrant neons */
  --player-1: #e94560;  /* Crimson */
  --player-2: #00d4ff;  /* Cyan */
  --player-3: #4ade80;  /* Lime */
  --player-4: #fbbf24;  /* Amber */

  /* UI accents */
  --accent: #e94560;
  --accent-glow: rgba(233, 69, 96, 0.4);
  --success: #00ff88;
  --warning: #ffaa00;
  --danger: #ff4444;
  --contested: #a855f7;  /* Purple for contested cells */
  --contested-glow: rgba(168, 85, 247, 0.5);

  /* Text */
  --text-primary: #ffffff;
  --text-secondary: #a0a0b0;
  --text-dim: #606070;

  /* Effects */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --glow-strong: 0 0 20px;
  --glow-soft: 0 0 10px;

  /* Grid */
  --cell-size: clamp(28px, 6vmin, 52px);
  --cell-gap: 3px;
  --grid-padding: 16px;
  --token-scale: 0.75;

  /* Typography */
  --font-display: 'Orbitron', 'Rajdhani', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Animation */
  --speed-fast: 150ms;
  --speed-normal: 300ms;
  --speed-slow: 500ms;
  --ease-out: cubic-bezier(0.215, 0.61, 0.355, 1);
  --ease-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* ============================================================================
   Reset & Base
   ============================================================================ */

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

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

body {
  font-family: var(--font-body);
  background: radial-gradient(ellipse at top, var(--bg-surface), var(--bg-deep));
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Grid background pattern */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 60px 60px;
  pointer-events: none;
  z-index: 0;
}

/* ============================================================================
   App Container
   ============================================================================ */

#app {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ============================================================================
   Typography
   ============================================================================ */

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

h1 { font-size: clamp(1.5rem, 4vw, 2.5rem); }
h2 { font-size: clamp(1.2rem, 3vw, 1.8rem); }
h3 { font-size: clamp(1rem, 2vw, 1.3rem); }

/* ============================================================================
   Buttons
   ============================================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 28px;
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--speed-fast) var(--ease-out);
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.1), transparent);
  opacity: 0;
  transition: opacity var(--speed-fast);
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #ff6b7a);
  color: white;
  box-shadow: 0 4px 15px var(--accent-glow);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 25px var(--accent-glow);
}

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

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-secondary:hover {
  background: var(--bg-surface);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-danger {
  background: linear-gradient(135deg, var(--danger), #ff6666);
  color: white;
}

.btn-icon {
  padding: 10px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 8px;
  background: var(--bg-elevated);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--speed-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: var(--bg-surface);
  color: var(--text-primary);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* ============================================================================
   Input Fields
   ============================================================================ */

.input {
  width: 100%;
  padding: 14px 18px;
  font-size: 1rem;
  font-family: var(--font-body);
  color: var(--text-primary);
  background: var(--bg-dark);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  transition: all var(--speed-fast);
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.input::placeholder {
  color: var(--text-dim);
}

/* ============================================================================
   Modals
   ============================================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all var(--speed-normal);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: linear-gradient(180deg, var(--bg-surface), var(--bg-dark));
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 40px;
  max-width: 500px;
  width: 90%;
  text-align: center;
  transform: scale(0.9) translateY(20px);
  transition: transform var(--speed-normal) var(--ease-bounce);
  box-shadow: var(--shadow-lg);
}

.modal-overlay.active .modal {
  transform: scale(1) translateY(0);
}

.modal h2 {
  margin-bottom: 16px;
  background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.modal p {
  color: var(--text-secondary);
  margin-bottom: 24px;
  line-height: 1.7;
}

.modal-content {
  text-align: left;
  margin: 24px 0;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 32px;
  flex-wrap: wrap;
}

/* Rules modal specific */
.rules-content {
  max-width: 650px;
  text-align: left;
  max-height: 70vh;
  overflow-y: auto;
  padding-right: 8px;
}

.rules-content ul {
  margin: 16px 0;
  padding-left: 24px;
  color: var(--text-secondary);
}

.rules-content li {
  margin: 8px 0;
  line-height: 1.6;
}

.rules-content .highlight {
  color: var(--warning);
  font-weight: 600;
}

.rules-content .crdt-highlight {
  background: rgba(168, 85, 247, 0.15);
  border-left: 3px solid var(--contested);
  padding: 12px 16px;
  margin: 16px 0;
  border-radius: 0 8px 8px 0;
}

/* Generic hidden utility */
.hidden {
  display: none !important;
}

/* ============================================================================
   Start Screen
   ============================================================================ */

.start-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  z-index: 100;
}

.start-screen.hidden {
  display: none;
}

.game-logo {
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 8vw, 5rem);
  font-weight: 900;
  background: linear-gradient(135deg, var(--player-1), var(--player-2), var(--player-3), var(--player-4));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
  text-shadow: 0 0 60px rgba(233, 69, 96, 0.3);
  animation: logo-glow 3s ease-in-out infinite;
}

@keyframes logo-glow {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.2); }
}

.game-tagline {
  font-size: clamp(0.9rem, 2vw, 1.1rem);
  color: var(--text-secondary);
  margin-bottom: 48px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.start-form {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.server-input-group {
  display: flex;
  gap: 8px;
}

.server-input-group .input {
  flex: 1;
}

.start-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}

.start-footer {
  margin-top: 32px;
  display: flex;
  gap: 16px;
}

/* ============================================================================
   Game Screen
   ============================================================================ */

.game-screen {
  display: none;
  height: 100%;
  flex-direction: column;
  padding: 16px;
  gap: 16px;
}

.game-screen.active {
  display: flex;
}

/* Top bar */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: var(--bg-surface);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.game-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.game-title h1 {
  font-size: 1.3rem;
  margin: 0;
}

.timer-display {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-dark);
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  transition: all var(--speed-fast);
}

.timer-display.warning {
  color: var(--warning);
  animation: timer-pulse 1s ease-in-out infinite;
}

.timer-display.critical {
  color: var(--danger);
  animation: timer-pulse 0.5s ease-in-out infinite;
}

@keyframes timer-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.02); }
}

.header-actions {
  display: flex;
  gap: 8px;
}

/* Sync status */
.sync-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-dark);
  border-radius: 20px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.sync-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: all var(--speed-fast);
}

.sync-indicator.connected {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.sync-indicator.syncing {
  background: var(--warning);
  animation: sync-pulse 1s ease-in-out infinite;
}

.sync-indicator.offline {
  background: var(--danger);
}

@keyframes sync-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.peer-count {
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

/* ============================================================================
   Energy Display
   ============================================================================ */

.energy-display {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-dark);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  min-width: 160px;
  transition: all var(--speed-fast);
}

.energy-icon {
  color: var(--warning);
  flex-shrink: 0;
}

.energy-bar-track {
  flex: 1;
  height: 10px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 5px;
  overflow: hidden;
  position: relative;
}

.energy-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--success), #88ffcc);
  border-radius: 5px;
  transition: width var(--speed-fast) var(--ease-out), background var(--speed-fast);
  box-shadow: 0 0 8px var(--success);
}

.energy-text {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
  min-width: 38px;
  text-align: right;
}

/* Color shifts as energy depletes */
.energy-display.energy-full .energy-bar-fill {
  background: linear-gradient(90deg, var(--success), #88ffcc);
  box-shadow: 0 0 8px var(--success);
}

.energy-display.energy-mid .energy-bar-fill {
  background: linear-gradient(90deg, var(--warning), #ffcc66);
  box-shadow: 0 0 8px var(--warning);
}

.energy-display.energy-mid .energy-icon {
  color: var(--warning);
}

.energy-display.energy-low .energy-bar-fill {
  background: linear-gradient(90deg, var(--danger), #ff7777);
  box-shadow: 0 0 8px var(--danger);
}

.energy-display.energy-low .energy-icon {
  color: var(--danger);
}

.energy-display.energy-depleted {
  border-color: var(--danger);
  box-shadow: 0 0 12px rgba(255, 68, 68, 0.3);
  animation: energy-depleted-pulse 1.5s ease-in-out infinite;
}

.energy-display.energy-depleted .energy-bar-fill {
  background: var(--danger);
  box-shadow: 0 0 6px var(--danger);
  width: 8% !important;
}

@keyframes energy-depleted-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Shake feedback when placement rejected */
.energy-display.shake {
  animation: energy-shake 0.4s var(--ease-bounce);
  border-color: var(--danger) !important;
}

@keyframes energy-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* ============================================================================
   Energy Preset Selector (Lobby)
   ============================================================================ */

.energy-preset-section {
  margin: 0 0 22px;
  text-align: left;
}

.energy-preset-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin: 0 0 10px;
  text-align: center;
}

.energy-preset-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.btn-preset {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 8px;
  background: var(--bg-dark);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--speed-fast) var(--ease-out);
  font-family: var(--font-body);
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.85rem;
  font-weight: 600;
}

.btn-preset:hover {
  background: var(--bg-surface);
  border-color: rgba(255, 255, 255, 0.18);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.btn-preset .preset-name {
  font-family: var(--font-display);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.btn-preset .preset-desc {
  font-size: 0.65rem;
  color: var(--text-dim);
  font-weight: 400;
  line-height: 1.3;
}

.btn-preset.active {
  background: linear-gradient(135deg, rgba(233, 69, 96, 0.18), rgba(0, 212, 255, 0.12));
  border-color: var(--accent);
  color: var(--text-primary);
  box-shadow: 0 0 14px var(--accent-glow);
}

.btn-preset.active .preset-desc {
  color: var(--text-secondary);
}

.energy-preset-hint {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-align: center;
  margin: 8px 0 0;
  font-style: italic;
}

/* ============================================================================
   Game Length Selector (Lobby)
   ============================================================================ */

.duration-section {
  margin: 0 0 22px;
  text-align: left;
}

.duration-section-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin: 0 0 10px;
  text-align: center;
}

.duration-toggle-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.btn-duration-toggle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 8px;
  background: var(--bg-dark);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--speed-fast) var(--ease-out);
  font-family: var(--font-body);
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.85rem;
  font-weight: 600;
}

.btn-duration-toggle:hover {
  background: var(--bg-surface);
  border-color: rgba(255, 255, 255, 0.18);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.btn-duration-toggle .preset-name {
  font-family: var(--font-display);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.btn-duration-toggle .preset-desc {
  font-size: 0.65rem;
  color: var(--text-dim);
  font-weight: 400;
  line-height: 1.3;
}

.btn-duration-toggle.active {
  background: linear-gradient(135deg, rgba(0, 212, 255, 0.18), rgba(74, 222, 128, 0.12));
  border-color: var(--player-2);
  color: var(--text-primary);
  box-shadow: 0 0 14px rgba(0, 212, 255, 0.35);
}

.btn-duration-toggle.active .preset-desc {
  color: var(--text-secondary);
}

/* ============================================================================
   Bot Opponent Selector (Lobby)
   ============================================================================ */

.bot-section {
  margin: 0 0 22px;
  text-align: left;
}

.bot-section-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin: 0 0 10px;
  text-align: center;
}

.bot-toggle-group {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.btn-bot-toggle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 6px;
  background: var(--bg-dark);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--speed-fast) var(--ease-out);
  font-family: var(--font-body);
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.85rem;
  font-weight: 600;
}

.btn-bot-toggle:hover {
  background: var(--bg-surface);
  border-color: rgba(255, 255, 255, 0.18);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.btn-bot-toggle .preset-name {
  font-family: var(--font-display);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.btn-bot-toggle .preset-desc {
  font-size: 0.6rem;
  color: var(--text-dim);
  font-weight: 400;
  line-height: 1.3;
}

.btn-bot-toggle.active {
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.18), rgba(233, 69, 96, 0.12));
  border-color: var(--player-4);
  color: var(--text-primary);
  box-shadow: 0 0 14px rgba(251, 191, 36, 0.35);
}

.btn-bot-toggle.active .preset-desc {
  color: var(--text-secondary);
}

.bot-section-hint {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-align: center;
  margin: 8px 0 0;
  font-style: italic;
}

/* Bot player badge in score panel / lobby */
.lobby-player.bot-player .player-label::after {
  content: ' 🤖';
  font-size: 0.8em;
}

/* Main game area */
.game-main {
  flex: 1;
  display: flex;
  gap: 24px;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

/* Score panel */
.score-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 200px;
}

/* Mobile score panel — hidden on desktop, shown on mobile */
.mobile-score {
  display: none;
}

.player-score {
  background: var(--bg-surface);
  border-radius: 12px;
  padding: 16px;
  border: 2px solid transparent;
  transition: all var(--speed-fast);
  position: relative;
  overflow: hidden;
}

.player-score::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--player-color);
}

.player-score.current-player {
  border-color: var(--player-color);
  box-shadow: 0 0 20px rgba(var(--player-color-rgb), 0.2);
}

.player-score-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.player-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.95rem;
}

.player-color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--player-color);
  box-shadow: 0 0 8px var(--player-color);
}

.player-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat {
  text-align: center;
  padding: 8px;
  background: var(--bg-dark);
  border-radius: 6px;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin-top: 2px;
}

/* Highlight the Score stat in the player card */
.stat-score .stat-value {
  color: var(--warning);
  text-shadow: 0 0 8px rgba(255, 170, 0, 0.4);
}

.stat-score .stat-label {
  color: var(--warning);
  opacity: 0.8;
}

.territory-bar {
  height: 6px;
  background: var(--bg-dark);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 12px;
}

.territory-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--player-color), rgba(255,255,255,0.3));
  border-radius: 3px;
  transition: width var(--speed-normal) var(--ease-out);
}

/* Game board */
.board-container {
  position: relative;
  padding: var(--grid-padding);
  background: var(--bg-surface);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow: var(--shadow-md);
}

.game-board {
  display: grid;
  grid-template-columns: repeat(10, var(--cell-size));
  grid-template-rows: repeat(10, var(--cell-size));
  gap: var(--cell-gap);
  position: relative;
}

/* Grid cells */
.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  background: var(--bg-dark);
  border-radius: 6px;
  position: relative;
  cursor: pointer;
  transition: all var(--speed-fast);
  overflow: hidden;
}

.cell::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(255,255,255,0.03), transparent 70%);
  opacity: 0;
  transition: opacity var(--speed-fast);
}

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

.cell.highlighted {
  box-shadow: inset 0 0 0 2px var(--success);
  animation: cell-pulse 1.5s ease-in-out infinite;
}

.cell.targetable {
  cursor: pointer;
  box-shadow: inset 0 0 0 2px var(--warning);
}

.cell.merge-target {
  box-shadow: inset 0 0 0 2px var(--player-2);
  animation: merge-pulse 1s ease-in-out infinite;
}

@keyframes cell-pulse {
  0%, 100% { box-shadow: inset 0 0 0 2px var(--success); }
  50% { box-shadow: inset 0 0 0 3px var(--success), 0 0 15px var(--success); }
}

@keyframes merge-pulse {
  0%, 100% { box-shadow: inset 0 0 0 2px var(--player-2); }
  50% { box-shadow: inset 0 0 0 3px var(--player-2), 0 0 15px var(--player-2); }
}

/* Contested cell */
.cell.contested {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.2), rgba(100, 50, 180, 0.3));
  animation: contested-glow 2s ease-in-out infinite;
}

.cell.contested::after {
  content: '⚔';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell-size) * 0.5);
  color: var(--contested);
  opacity: 0.6;
  text-shadow: 0 0 10px var(--contested);
}

@keyframes contested-glow {
  0%, 100% {
    box-shadow: 0 0 10px var(--contested-glow);
  }
  50% {
    box-shadow: 0 0 25px var(--contested-glow), inset 0 0 20px rgba(168, 85, 247, 0.2);
  }
}

/* Tokens */
.token {
  position: absolute;
  inset: calc(var(--cell-size) * 0.1);
  width: calc(var(--cell-size) * var(--token-scale));
  height: calc(var(--cell-size) * var(--token-scale));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: calc(var(--cell-size) * 0.35);
  font-weight: 700;
  color: white;
  cursor: pointer;
  transition: all var(--speed-fast) var(--ease-bounce);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  user-select: none;
}

/* Entrance animation — plays once when a new token element is created
   (incremental rendering: only genuinely new tokens get this, not the
   whole board on every state update). */
.token.token-entering {
  animation: token-enter 320ms var(--ease-bounce);
}

@keyframes token-enter {
  0% {
    transform: scale(0) rotate(-180deg);
    opacity: 0;
  }
  70% {
    transform: scale(1.1) rotate(10deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

/* Ping ring — a circular ripple in the placing player's color, spawned
   alongside a newly-placed token. More visually prominent for remote
   placements so the player notices sync activity. */
.token-ping-ring {
  position: absolute;
  inset: calc(var(--cell-size) * 0.1);
  width: calc(var(--cell-size) * var(--token-scale));
  height: calc(var(--cell-size) * var(--token-scale));
  border-radius: 50%;
  border: 2px solid var(--ping-color, currentColor);
  pointer-events: none;
  animation: token-ping 650ms ease-out forwards;
  z-index: 5;
}

@keyframes token-ping {
  from {
    transform: scale(1);
    opacity: 0.8;
  }
  to {
    transform: scale(2.5);
    opacity: 0;
  }
}

/* Exit animation — consumed tokens (merged/split) fade + shrink before
   being removed from the DOM. */
.token.token-exiting {
  animation: token-exit 180ms ease-in forwards;
  pointer-events: none;
}

@keyframes token-exit {
  from {
    transform: scale(1);
    opacity: 1;
  }
  to {
    transform: scale(0);
    opacity: 0;
  }
}

/* Pulse animation — plays when a token's strength changes (e.g. merged
   from strength-1 → strength-2). */
.token.token-pulsing {
  animation: token-pulse 220ms ease-in-out;
}

@keyframes token-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.token:hover {
  transform: scale(1.15);
  z-index: 10;
}

.token.selected {
  transform: scale(1.2);
  box-shadow: 0 0 20px currentColor, 0 0 40px currentColor;
  z-index: 20;
  animation: token-selected 1s ease-in-out infinite;
}

@keyframes token-selected {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.3); }
}

.token.strength-1 { background: currentColor; }
.token.strength-2 {
  background: linear-gradient(135deg, currentColor, rgba(255,255,255,0.3));
  box-shadow: 0 0 15px currentColor;
}
.token.strength-3 {
  background: linear-gradient(135deg, currentColor, #ffffff, currentColor);
  box-shadow: 0 0 20px currentColor, inset 0 0 10px rgba(255,255,255,0.5);
  animation: token-legendary 2s ease-in-out infinite;
}

/* Entrance/pulse/exit animations must override the legendary loop when
   present (higher specificity wins over .token.strength-3). */
.token.strength-3.token-entering { animation: token-enter 320ms var(--ease-bounce); }
.token.strength-3.token-pulsing { animation: token-pulse 220ms ease-in-out; }
.token.strength-3.token-exiting { animation: token-exit 180ms ease-in forwards; }

/* Fortified token (strength-3) — cannot be contested */
.token.fortified {
  position: relative;
}

.token.fortified::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 2px solid currentColor;
  opacity: 0.7;
  animation: fortified-ring 2s ease-in-out infinite;
  pointer-events: none;
}

.token.fortified .fortified-shield {
  position: absolute;
  top: -6px;
  right: -6px;
  font-size: calc(var(--cell-size) * 0.3);
  line-height: 1;
  background: var(--bg-deep);
  border-radius: 50%;
  width: calc(var(--cell-size) * 0.4);
  height: calc(var(--cell-size) * 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 8px currentColor;
  pointer-events: none;
}

@keyframes fortified-ring {
  0%, 100% {
    transform: scale(1);
    opacity: 0.7;
  }
  50% {
    transform: scale(1.08);
    opacity: 0.4;
  }
}

@keyframes token-legendary {
  0%, 100% { transform: scale(1) rotate(0deg); }
  25% { transform: scale(1.05) rotate(-2deg); }
  75% { transform: scale(1.05) rotate(2deg); }
}

/* Multiple tokens in cell */
.cell .token-container {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.cell.contested .token-container {
  flex-direction: row;
}

.cell .token.multi {
  width: calc(var(--cell-size) * 0.5);
  height: calc(var(--cell-size) * 0.5);
  font-size: calc(var(--cell-size) * 0.25);
}

/* Provenance tooltip */
.provenance-tooltip {
  position: fixed;
  background: var(--bg-surface);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 16px;
  max-width: 280px;
  z-index: 1000;
  pointer-events: none;
  opacity: 0;
  transform: translateY(10px);
  transition: all var(--speed-fast);
  box-shadow: var(--shadow-lg);
}

.provenance-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.provenance-tooltip h4 {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.provenance-tree {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.provenance-node {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-dark);
  border-radius: 6px;
  font-size: 0.8rem;
}

.provenance-node .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--player-color);
}

.provenance-node .type {
  font-size: 0.65rem;
  text-transform: uppercase;
  padding: 2px 6px;
  background: var(--bg-elevated);
  border-radius: 3px;
  color: var(--text-dim);
}

.provenance-node .coords {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-left: auto;
}

/* Action instructions */
.action-instructions {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-surface);
  padding: 12px 24px;
  border-radius: 30px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-md);
  z-index: 50;
}

.action-instructions .key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 8px;
  background: var(--bg-elevated);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-primary);
}

/* ============================================================================
   Game Over Screen
   ============================================================================ */

.game-over-screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  z-index: 200;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(10px);
}

.game-over-screen.active {
  display: flex;
  animation: fade-in var(--speed-normal);
}

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

.winner-display {
  text-align: center;
  margin-bottom: 40px;
}

.winner-display h2 {
  font-size: clamp(2rem, 6vw, 4rem);
  margin-bottom: 16px;
  background: linear-gradient(135deg, var(--success), #88ffcc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.winner-display.tie h2 {
  background: linear-gradient(135deg, var(--text-secondary), var(--text-primary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.final-scores {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  width: 100%;
  max-width: 800px;
  margin-bottom: 40px;
}

.final-score-card {
  background: var(--bg-surface);
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  border: 2px solid transparent;
  transition: all var(--speed-fast);
}

.final-score-card.winner {
  border-color: var(--success);
  box-shadow: 0 0 30px rgba(0, 255, 136, 0.2);
  transform: scale(1.05);
}

.final-score-card .player-color-dot {
  width: 20px;
  height: 20px;
  margin: 0 auto 12px;
}

.final-score-card .player-name {
  font-size: 1.1rem;
  margin-bottom: 16px;
}

.final-score-card .score-value {
  font-family: var(--font-mono);
  font-size: 3rem;
  font-weight: 700;
  color: var(--text-primary);
}

.final-score-card .score-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.final-score-card .score-sub {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 4px;
  font-family: var(--font-mono);
}

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

.room-lobby {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at top, rgba(40, 20, 35, 0.65), rgba(0, 0, 0, 0.95));
  backdrop-filter: blur(14px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 600;
  padding: 24px;
  overflow-y: auto;
  animation: lobby-backdrop-in var(--speed-normal) var(--ease-out);
}

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

.lobby-content {
  position: relative;
  background:
    linear-gradient(180deg, var(--bg-surface), var(--bg-dark));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  padding: 40px 36px 28px;
  max-width: 460px;
  width: 100%;
  text-align: center;
  box-shadow:
    var(--shadow-lg),
    0 0 60px rgba(233, 69, 96, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  animation: lobby-card-in var(--speed-normal) var(--ease-bounce);
}

/* Subtle neon top edge */
.lobby-content::before {
  content: '';
  position: absolute;
  top: 0;
  left: 24px;
  right: 24px;
  height: 1px;
  background: linear-gradient(90deg,
    transparent,
    var(--player-1) 20%,
    var(--player-2) 50%,
    var(--player-3) 80%,
    transparent);
  opacity: 0.7;
}

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

/* Header / logo */
.lobby-header {
  margin-bottom: 28px;
}

.lobby-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  border-radius: 16px;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 1.8rem;
  color: #fff;
  background: linear-gradient(135deg, var(--player-1), var(--player-2));
  box-shadow:
    0 8px 24px rgba(233, 69, 96, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  animation: logo-glow 3s ease-in-out infinite;
}

.lobby-content h2 {
  margin-bottom: 4px;
  font-size: clamp(1.3rem, 3.5vw, 1.7rem);
  background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.lobby-subtitle {
  font-size: 0.7rem;
  color: var(--text-dim);
  letter-spacing: 0.25em;
  text-transform: uppercase;
  margin: 0;
}

/* ----------------------------------------------------------------------------
   Lobby states — entrance animation when shown
   ---------------------------------------------------------------------------- */

.lobby-state {
  margin-bottom: 20px;
}

/* Animate a state in whenever it becomes visible (hidden removed by JS) */
.lobby-state:not(.hidden) {
  animation: lobby-state-in var(--speed-normal) var(--ease-out);
}

@keyframes lobby-state-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.lobby-intro,
.lobby-content p {
  color: var(--text-secondary);
  margin-bottom: 18px;
  line-height: 1.6;
  font-size: 0.95rem;
}

.lobby-intro {
  margin-bottom: 22px;
}

/* ----------------------------------------------------------------------------
   Connecting state
   ---------------------------------------------------------------------------- */

.lobby-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 12px 0 20px;
  height: 32px;
}

.lobby-spinner span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--player-2);
  box-shadow: 0 0 10px var(--player-2);
  animation: spinner-bounce 1.2s var(--ease-bounce) infinite;
}

.lobby-spinner span:nth-child(2) {
  background: var(--player-1);
  box-shadow: 0 0 10px var(--player-1);
  animation-delay: 0.15s;
}

.lobby-spinner span:nth-child(3) {
  background: var(--player-3);
  box-shadow: 0 0 10px var(--player-3);
  animation-delay: 0.3s;
}

@keyframes spinner-bounce {
  0%, 80%, 100% { transform: scale(0.5); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

.lobby-connecting-text {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin: 0;
}

.lobby-ellipsis {
  display: inline-block;
  width: 1.5em;
  text-align: left;
  animation: ellipsis 1.4s steps(4, end) infinite;
}

@keyframes ellipsis {
  0%   { content: ''; }
  25%  { content: '.'; }
  50%  { content: '..'; }
  75%  { content: '...'; }
  100% { content: ''; }
}

/* ----------------------------------------------------------------------------
   Room select
   ---------------------------------------------------------------------------- */

.lobby-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 0 0 18px;
}

.btn-lobby-cta {
  width: 100%;
  padding: 16px 24px;
  font-size: 0.95rem;
}

.lobby-divider {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 20px 0;
  color: var(--text-dim);
  font-size: 0.7rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
}

.lobby-divider::before,
.lobby-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.12), transparent);
}

.lobby-join {
  text-align: left;
}

.lobby-join label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 8px;
}

.room-code-input-group {
  display: flex;
  gap: 8px;
}

.room-code-input-group .input {
  flex: 1;
}

.room-code-field {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  text-align: center;
  padding: 14px 16px;
}

/* ----------------------------------------------------------------------------
   Room code display
   ---------------------------------------------------------------------------- */

.room-code-display {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 8px 0 22px;
}

.room-code-large {
  font-family: var(--font-mono);
  font-size: clamp(1.8rem, 6vw, 2.6rem);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.18em;
  background:
    linear-gradient(180deg, var(--bg-dark), #0d0d16);
  padding: 18px 28px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow:
    inset 0 2px 8px rgba(0, 0, 0, 0.4),
    0 0 24px rgba(0, 212, 255, 0.08);
  text-shadow: 0 0 12px rgba(0, 212, 255, 0.3);
  animation: room-code-reveal var(--speed-slow) var(--ease-out);
}

@keyframes room-code-reveal {
  from {
    opacity: 0;
    transform: scale(0.85);
    letter-spacing: 0.4em;
  }
  to {
    opacity: 1;
    transform: scale(1);
    letter-spacing: 0.18em;
  }
}

/* Copy icon buttons (code + link) */
.btn-copy-code,
.btn-copy-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 10px;
  border-radius: 10px;
  background: var(--bg-elevated);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--speed-fast) var(--ease-out);
}

.btn-copy-code:hover,
.btn-copy-link:hover {
  background: var(--bg-surface);
  color: var(--player-2);
  border-color: rgba(0, 212, 255, 0.4);
  box-shadow: 0 0 14px rgba(0, 212, 255, 0.2);
  transform: translateY(-1px);
}

.btn-copy-code:active,
.btn-copy-link:active {
  transform: translateY(0);
}

/* Copied feedback: swap icon + tint */
.btn-copy-code.copied,
.btn-copy-link.copied {
  background: rgba(74, 222, 128, 0.12);
  border-color: var(--player-3);
  color: var(--player-3);
  box-shadow: 0 0 14px rgba(74, 222, 128, 0.3);
}

.btn-copy-code .icon-check,
.btn-copy-link .icon-check {
  display: none;
}

.btn-copy-code.copied .icon-copy,
.btn-copy-link.copied .icon-copy {
  display: none;
}

.btn-copy-code.copied .icon-check,
.btn-copy-link.copied .icon-check {
  display: inline-flex;
}

.room-link-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  margin: 0 0 8px;
}

.room-link-group {
  display: flex;
  align-items: stretch;
  gap: 8px;
  background: var(--bg-dark);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 6px;
  transition: border-color var(--speed-fast);
}

.room-link-group:focus-within {
  border-color: rgba(0, 212, 255, 0.4);
  box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.12);
}

.room-link {
  flex: 1;
  display: flex;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--player-2);
  word-break: break-all;
  padding: 8px 10px;
  text-decoration: none;
  border-radius: 6px;
  transition: color var(--speed-fast);
  min-width: 0;
}

.room-link:hover {
  color: var(--text-primary);
  text-decoration: underline;
}

.btn-small {
  padding: 8px 16px;
  font-size: 0.8rem;
}

/* ----------------------------------------------------------------------------
   Waiting / player list
   ---------------------------------------------------------------------------- */

.lobby-status {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin: 0 0 16px;
  letter-spacing: 0.04em;
}

.lobby-players {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 0 22px;
}

.lobby-player {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-dark);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 0.92rem;
  transition: all var(--speed-fast) var(--ease-out);
  animation: lobby-player-in var(--speed-normal) var(--ease-bounce);
}

@keyframes lobby-player-in {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}

.lobby-player:hover {
  border-color: rgba(255, 255, 255, 0.12);
  background: var(--bg-surface);
}

.lobby-player .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--player-color, var(--success));
  box-shadow: 0 0 10px var(--player-color, var(--success));
  flex-shrink: 0;
}

.lobby-player .player-label {
  flex: 1;
  text-align: left;
  color: var(--text-primary);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lobby-player .you-tag {
  font-size: 0.7rem;
  color: var(--text-dim);
  font-weight: 400;
}

.lobby-player .host-badge {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 700;
  color: var(--warning);
  padding: 3px 8px;
  background: rgba(255, 170, 0, 0.12);
  border: 1px solid rgba(255, 170, 0, 0.25);
  border-radius: 4px;
  flex-shrink: 0;
}

/* Empty / waiting slot */
.lobby-player.empty-slot {
  background: transparent;
  border: 1px dashed rgba(255, 255, 255, 0.08);
}

.lobby-player.empty-slot .dot {
  background: transparent;
  border: 1.5px solid var(--text-dim);
  box-shadow: none;
  animation: slot-pulse 2s ease-in-out infinite;
}

.lobby-player.empty-slot .player-label {
  color: var(--text-dim);
  font-style: italic;
  font-weight: 400;
  animation: slot-pulse-text 2s ease-in-out infinite;
}

@keyframes slot-pulse {
  0%, 100% { border-color: var(--text-dim); }
  50% { border-color: var(--player-2); }
}

@keyframes slot-pulse-text {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 0.9; }
}

/* Start game button needs full width in waiting state */
#lobby-waiting .btn-lobby-cta {
  width: 100%;
}

/* ----------------------------------------------------------------------------
   Error state
   ---------------------------------------------------------------------------- */

.lobby-error-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: rgba(255, 68, 68, 0.1);
  border: 1px solid rgba(255, 68, 68, 0.3);
  color: var(--danger);
  animation: error-pulse 2s ease-in-out infinite;
}

@keyframes error-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 68, 68, 0.2); }
  50% { box-shadow: 0 0 0 10px rgba(255, 68, 68, 0); }
}

.error-text {
  color: var(--danger);
  font-weight: 600;
  margin-bottom: 20px;
  line-height: 1.5;
}

/* ----------------------------------------------------------------------------
   Footer / cancel
   ---------------------------------------------------------------------------- */

.lobby-footer {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
  padding: 10px 20px;
  font-size: 0.8rem;
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  border-color: rgba(255, 255, 255, 0.08);
}

.lobby-content .btn-secondary {
  margin-top: 8px;
}

/* Defeat styling */
.winner-display.defeat h2 {
  background: none;
  -webkit-background-clip: initial;
  -webkit-text-fill-color: #e94560;
  background-clip: initial;
  color: #e94560;
}

/* Offline demo banner */
.offline-banner {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: linear-gradient(135deg, var(--bg-elevated), var(--bg-surface));
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-lg);
  z-index: 150;
  transform: translateY(100px);
  opacity: 0;
  transition: all var(--speed-normal);
}

.offline-banner.visible {
  transform: translateY(0);
  opacity: 1;
}

.offline-banner.offline-mode {
  border-color: var(--warning);
  background: linear-gradient(135deg, rgba(255, 170, 0, 0.1), rgba(255, 170, 0, 0.05));
}

.offline-banner h4 {
  font-size: 0.85rem;
  margin-bottom: 4px;
}

.offline-banner p {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

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

@media (max-width: 1024px) {
  .game-main {
    flex-direction: column;
  }

  .score-panel {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    min-width: auto;
  }

  .player-score {
    flex: 1;
    min-width: 150px;
    max-width: 200px;
  }
}

@media (max-width: 768px) {
  .game-header {
    flex-wrap: wrap;
    gap: 12px;
  }

  .timer-display {
    order: 3;
    width: 100%;
    justify-content: center;
  }

  .energy-display {
    order: 4;
    width: 100%;
    justify-content: center;
  }

  .score-panel {
    display: none; /* Hide detailed scores on mobile */
  }

  .mobile-score {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 8px 0;
  }

  .mobile-score .player-score {
    flex: 0 0 120px;
    padding: 12px;
  }

  .board-container {
    padding: 8px;
  }

  :root {
    --cell-size: clamp(24px, 8vmin, 40px);
    --cell-gap: 2px;
  }

  .action-instructions {
    bottom: 16px;
    padding: 10px 16px;
    font-size: 0.8rem;
    max-width: calc(100% - 32px);
    flex-wrap: wrap;
    justify-content: center;
  }
}

@media (max-width: 480px) {
  .start-form {
    padding: 0 16px;
  }

  .modal {
    padding: 24px;
    width: 95%;
  }

  .game-header {
    padding: 10px 12px;
  }

  .game-title h1 {
    font-size: 1rem;
  }

  .timer-display {
    font-size: 1.2rem;
    padding: 6px 12px;
  }

  /* Lobby mobile tweaks */
  .room-lobby {
    padding: 12px;
    align-items: flex-start;
  }

  .lobby-content {
    padding: 28px 20px 22px;
    border-radius: 16px;
  }

  .lobby-content::before {
    left: 16px;
    right: 16px;
  }

  .room-code-large {
    padding: 14px 18px;
    letter-spacing: 0.14em;
  }

  .room-code-field {
    font-size: 1rem;
    letter-spacing: 0.14em;
    padding: 12px 10px;
  }
}

/* ============================================================================
   Accessibility
   ============================================================================ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:focus-visible,
.cell:focus-visible,
.token:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px var(--accent-glow);
}
