/* Snake Theory — shared tokens & chrome */
:root {
  --snake-primary: #2563eb;
  --snake-primary-dark: #1d4ed8;
  --snake-text: #1f2937;
  --snake-muted: #4b5563;
}

.snake-skip-link {
  position: absolute;
  left: -9999px;
  z-index: 200;
  padding: 0.5rem 1rem;
  background: var(--snake-primary);
  color: #fff;
  border-radius: 10px;
  text-decoration: none;
}

.snake-skip-link:focus {
  left: 1rem;
  top: 5rem;
}

.snake-chapter-badge {
  display: inline-block;
  margin-bottom: 0.5rem;
  padding: 0.25rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--snake-primary);
  background: rgba(37, 99, 235, 0.1);
  border-radius: 999px;
}

.snake-lab-hero .snake-chapter-badge {
  color: #93c5fd;
  background: rgba(147, 197, 253, 0.15);
}

.snake-hub button:focus-visible,
.snake-hub a:focus-visible,
.audio-toggle:focus-visible {
  outline: 3px solid var(--snake-primary);
  outline-offset: 2px;
}

.duel-leaderboard .empty {
  justify-content: center;
  font-style: italic;
  color: #6b7280;
  border-bottom: none;
}

@media (prefers-reduced-motion: reduce) {
  .snake-hub-tab,
  .snake-cta-finhub {
    transition: none;
  }
}

/* Snake Theory hub — shared tab navigation */
.snake-hub {
  position: sticky;
  top: 72px;
  z-index: 50;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #e5e7eb;
  padding: 0.75rem 1rem;
}

.snake-hub-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.snake-hub-tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.snake-hub-tab {
  padding: 0.5rem 1.25rem;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  color: #4b5563;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.snake-hub-tab:hover {
  color: #2563eb;
  background: rgba(37, 99, 235, 0.08);
}

.snake-hub-tab.active {
  background: #2563eb;
  color: #fff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.35);
}

.snake-hub-tab-finhub {
  border: 1px solid #93c5fd;
  background: rgba(37, 99, 235, 0.06);
}

.snake-hub-tab-finhub:hover {
  background: rgba(37, 99, 235, 0.12);
}

.snake-hub-tab-finhub.active {
  background: #059669;
  border-color: #059669;
  box-shadow: 0 2px 8px rgba(5, 150, 105, 0.35);
}

.snake-hub-finhub {
  font-size: 0.85rem;
  color: #6b7280;
}

.snake-hub-finhub a {
  color: #2563eb;
  font-weight: 600;
  text-decoration: none;
}

.snake-hub-finhub a:hover {
  text-decoration: underline;
}

.snake-shake {
  animation: snake-shake 0.35s ease;
}

@keyframes snake-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

.duel-panel {
  width: 100%;
  max-width: 520px;
  margin: 0 0 1rem;
  padding: 1rem;
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
  border: 1px solid #93c5fd;
  border-radius: 12px;
  text-align: center;
}

.duel-panel h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  color: #1e40af;
}

.duel-scores {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin: 0.75rem 0;
  font-weight: 600;
}

.duel-scores .you { color: #2563eb; }
.duel-scores .ai { color: #7c3aed; }

.duel-result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 0.75rem;
}

.duel-result-actions .finhub-cta {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  font-size: 0.85rem;
}

.duel-leaderboard {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  text-align: left;
  font-size: 0.8rem;
  color: #374151;
}

.duel-leaderboard li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid rgba(147, 197, 253, 0.5);
}

.duel-leaderboard .win { color: #059669; font-weight: 600; }
.duel-leaderboard .loss { color: #dc2626; }
.duel-leaderboard .tie { color: #6b7280; }

.ai-decision-log {
  width: 100%;
  max-width: 520px;
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  font-size: 0.8rem;
}

.ai-decision-log h4 {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: #475569;
}

.ai-decision-log ol {
  margin: 0;
  padding-left: 1.25rem;
  color: #334155;
  max-height: 120px;
  overflow-y: auto;
}

.ai-decision-log li {
  padding: 0.15rem 0;
}

.ai-decision-log .model-tag {
  color: #64748b;
  font-size: 0.75rem;
}

.session-mode {
  margin-bottom: 1rem;
  text-align: center;
}

.session-mode label {
  margin-right: 0.5rem;
  font-weight: 600;
  color: #374151;
}

.session-mode select {
  padding: 0.35rem 0.75rem;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
}

.model-stats-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.5rem;
  margin-top: 0.75rem;
  font-size: 0.8rem;
}

.model-stat-card {
  padding: 0.5rem;
  background: #fff;
  border: 1px solid #dbeafe;
  border-radius: 8px;
  text-align: center;
}

.model-stat-card strong {
  display: block;
  font-size: 1rem;
  color: #1d4ed8;
}

.ai-decision-log .empty {
  list-style: none;
  padding-left: 0;
  color: #94a3b8;
  font-style: italic;
}

.model-badge {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  color: #1d4ed8;
  font-weight: 500;
}

.mobile-hint {
  display: none;
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  color: var(--snake-muted, #4b5563);
  line-height: 1.45;
  max-width: 520px;
  margin-left: auto;
  margin-right: auto;
}

/* Touch / keyboardless D-pad */
.mobile-controls {
  display: none;
  grid-template-columns: repeat(3, minmax(52px, 1fr));
  gap: 10px;
  margin-top: 1rem;
  width: 100%;
  max-width: 260px;
  touch-action: manipulation;
}

.mobile-controls .mobile-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  min-width: 52px;
  padding: 0;
  border: none;
  border-radius: 12px;
  background: var(--snake-primary, #2563eb);
  color: #fff;
  font-size: 1.35rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}

.mobile-controls .mobile-btn:active {
  transform: scale(0.96);
  background: var(--snake-primary-dark, #1d4ed8);
}

.mobile-controls #up { grid-column: 2; grid-row: 1; }
.mobile-controls #left { grid-column: 1; grid-row: 2; }
.mobile-controls #right { grid-column: 3; grid-row: 2; }
.mobile-controls #down { grid-column: 2; grid-row: 3; }

#game-board-wrap.snake-swipe-zone {
  touch-action: none;
  cursor: grab;
}

html.snake-touch-device #game-board-wrap.snake-swipe-zone {
  outline: 2px dashed rgba(37, 99, 235, 0.2);
  outline-offset: 4px;
}

html.snake-touch-device #game-board-wrap.snake-swipe-zone::after {
  content: 'Swipe to steer';
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  font-weight: 600;
  color: rgba(37, 99, 235, 0.55);
  pointer-events: none;
  letter-spacing: 0.02em;
}

@media (pointer: coarse), (max-width: 900px) {
  .mobile-controls {
    display: grid;
  }

  .desktop-hint {
    display: none !important;
  }

  .mobile-hint {
    display: block;
  }
}

html.snake-touch-device .mobile-controls {
  display: grid;
}

html.snake-touch-device .desktop-hint {
  display: none !important;
}

html.snake-touch-device .mobile-hint {
  display: block;
}

@media (prefers-reduced-motion: reduce) {
  .mobile-controls .mobile-btn:active {
    transform: none;
  }
}

.audio-toggle {
  margin-left: auto;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: #fff;
  cursor: pointer;
  font-size: 0.8rem;
}

.snake-cta-finhub {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
  padding: 0.75rem 1.25rem;
  background: linear-gradient(135deg, #1e40af 0%, #2563eb 100%);
  color: #fff;
  border-radius: 10px;
  text-decoration: none;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.snake-cta-finhub:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.35);
}

.snake-proof-card {
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
  border: 1px solid #bfdbfe;
  border-radius: 12px;
  padding: 1.5rem;
  text-align: left;
}

.snake-proof-card h3 {
  margin: 0 0 0.75rem;
  color: #1e40af;
  font-size: 1.1rem;
}

.snake-proof-card p {
  margin: 0;
  color: #374151;
  line-height: 1.6;
  font-size: 0.95rem;
}

.cta-image-placeholder {
  height: 400px;
  border-radius: 10px;
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 50%, #60a5fa 100%);
  display: flex;
  align-items: flex-end;
  padding: 2rem;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.15);
}

.cta-image-placeholder .image-content {
  position: static;
  padding: 0;
}

/* In-game overlays & toasts */
body.snake-overlay-open {
  overflow: hidden;
}

.snake-game-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  box-sizing: border-box;
}

.snake-overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(6px);
}

.snake-overlay-card {
  position: relative;
  z-index: 1;
  width: min(100%, 400px);
  padding: 1.75rem 1.5rem 1.5rem;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.22);
  text-align: center;
  animation: snake-overlay-in 0.25s ease;
  box-sizing: border-box;
}

@keyframes snake-overlay-in {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.snake-overlay-emoji {
  margin: 0 0 0.75rem;
  font-size: 2.5rem;
  line-height: 1;
}

.snake-overlay-title {
  margin: 0 0 0.65rem;
  padding: 0;
  font-size: 1.35rem;
  font-weight: 700;
  color: #111827;
  line-height: 1.3;
}

.snake-overlay-body {
  margin: 0 0 1.35rem;
  color: #4b5563;
  line-height: 1.6;
  font-size: 0.95rem;
}

.snake-overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  align-items: stretch;
  width: 100%;
}

.snake-game-overlay .snake-overlay-primary,
.snake-game-overlay .snake-overlay-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 44px;
  padding: 0.7rem 1.25rem;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.95rem;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
  box-sizing: border-box;
  margin: 0;
  line-height: 1.2;
}

.snake-game-overlay .snake-overlay-primary {
  background: var(--snake-primary, #2563eb);
  color: #fff;
  border: none;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.35);
}

.snake-game-overlay .snake-overlay-primary:hover {
  background: var(--snake-primary-dark, #1d4ed8);
}

.snake-game-overlay .snake-overlay-secondary {
  background: #fff;
  color: var(--snake-primary, #2563eb);
  border: 2px solid var(--snake-primary, #2563eb);
}

.snake-game-overlay .snake-overlay-primary:focus-visible,
.snake-game-overlay .snake-overlay-secondary:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 2px;
}

.snake-game-overlay--win .snake-overlay-card {
  border-top: 4px solid #059669;
}

.snake-game-overlay--lose .snake-overlay-card {
  border-top: 4px solid #f59e0b;
}

.snake-game-overlay--tutorial .snake-overlay-card {
  border-top: 4px solid var(--snake-primary, #2563eb);
}

#game-board-wrap {
  overflow: visible;
}

.snake-toast {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  padding: 0.5rem 1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 30;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}

.snake-toast--visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.snake-toast--info {
  background: #dbeafe;
  color: #1e40af;
}

.snake-toast--success {
  background: #d1fae5;
  color: #065f46;
}

.snake-toast--speed {
  background: #fef3c7;
  color: #92400e;
}

@media (prefers-reduced-motion: reduce) {
  .snake-overlay-card { animation: none; }
  .snake-toast { transition: none; }
}
