/* Snake Theory Play page — game-first layout */
:root {
  --snake-text: #1f2937;
  --snake-muted: #4b5563;
  --snake-border: #e5e7eb;
  --snake-radius: 10px;
  --snake-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* Game section — hero placement */
.game-section {
  padding: 1.5rem 1rem max(3rem, env(safe-area-inset-bottom, 0px));
  background: #fff;
  width: 100%;
}

.game-container-wrapper {
  max-width: 1200px;
  margin: 0 auto;
  text-align: center;
}

.game-title {
  font-size: 1.75rem;
  color: var(--snake-text);
  margin-bottom: 1.25rem;
}

.game-container {
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  padding: 1.5rem;
  margin: 0 auto;
  max-width: 600px;
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 1px solid #e0e0e0;
  position: relative;
}

#game-board-wrap {
  margin-bottom: 1rem;
  padding: 10px;
  border: 2px solid rgba(37, 99, 235, 0.3);
  border-radius: 10px;
  background-color: rgba(249, 250, 251, 0.8);
  box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.1), 0 5px 15px rgba(0, 0, 0, 0.1);
  position: relative;
  overflow: visible;
}

#snake-canvas {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}

.best-score {
  font-size: 0.95rem;
  color: var(--snake-muted);
  margin: -0.5rem 0 1rem;
  font-weight: 500;
}

#score {
  font-size: 1.2rem;
  margin-bottom: 0.75rem;
  color: var(--snake-text);
  font-weight: 600;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.1) 0%, rgba(37, 99, 235, 0.2) 100%);
  padding: 0.5rem 1.5rem;
  border-radius: 20px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

.pilot-status {
  margin: 0.75rem 0;
  padding: 12px 15px;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.05) 0%, rgba(37, 99, 235, 0.1) 100%);
  border-radius: 12px;
  border: 1px solid rgba(37, 99, 235, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

#pilot-label {
  font-size: 0.85rem;
  color: var(--snake-text);
  margin: 0;
  font-weight: 600;
  max-width: 220px;
  line-height: 1.3;
}

.traffic-light {
  display: flex;
  align-items: center;
  background: linear-gradient(to bottom, #333 0%, #222 100%);
  padding: 5px 10px;
  border-radius: 15px;
}

.traffic-light .light {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background-color: #555;
  margin: 0 5px;
  border: 1px solid #444;
  transition: all 0.3s ease;
}

.traffic-light .light.red {
  background-color: #ff3b30;
  box-shadow: 0 0 10px #ff3b30;
}

.traffic-light .light.yellow {
  background-color: #ffcc00;
  box-shadow: 0 0 10px #ffcc00;
}

.traffic-light .light.green {
  background-color: #34c759;
  box-shadow: 0 0 10px #34c759;
}

.game-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 0.75rem;
  gap: 0.25rem;
}

.game-controls button,
.pilot-status #autopilot {
  font-weight: 600;
  font-size: 0.9rem;
  padding: 10px 16px;
  margin: 5px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: all 0.25s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.game-controls button:focus-visible,
.pilot-status #autopilot:focus-visible,
.mobile-btn:focus-visible,
.wheel-button:focus-visible {
  outline: 3px solid var(--snake-primary);
  outline-offset: 2px;
}

#autopilot {
  background: linear-gradient(135deg, #e0f2fe 0%, #bfdbfe 100%);
  color: var(--snake-primary);
  border: 1px solid #93c5fd;
}

#start-pause {
  background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%);
  color: #16a34a;
  border: 1px solid #86efac;
  min-width: 120px;
}

#start-pause.start-pulse {
  animation: start-pulse 1.2s ease-in-out 3;
}

@keyframes start-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(22, 163, 74, 0); }
}

#reset {
  background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
  color: #dc2626;
  border: 1px solid #fca5a5;
  min-width: 100px;
}

.controller-toggle-btn {
  background: linear-gradient(135deg, #fef3c7 0%, #fcd34d 100%);
  color: #92400e;
}

.desktop-hint {
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--snake-muted);
}

.snake-origin-line {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--snake-muted);
}

/* Floating controller — desktop optional */
.game-controller {
  display: none;
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(calc(100% + 50px));
  opacity: 0;
  pointer-events: none;
  flex-direction: column;
  align-items: center;
  width: 200px;
  padding: 25px 15px 15px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 12px;
  border: 3px solid #f59e0b;
  z-index: 100;
  transition: all 0.3s ease;
}

.game-controller.active {
  display: flex;
  transform: translateX(-50%);
  opacity: 1;
  pointer-events: auto;
}

.keyboard-control {
  position: relative;
  width: 150px;
  height: 150px;
}

.wheel-button {
  position: absolute;
  width: 50px;
  height: 50px;
  background: linear-gradient(135deg, var(--snake-primary) 0%, var(--snake-primary-dark) 100%);
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.25rem;
}

.keyboard-control #up { top: 0; left: 50%; transform: translateX(-50%); }
.keyboard-control #down { bottom: 0; left: 50%; transform: translateX(-50%); }
.keyboard-control #left { left: 0; top: 50%; transform: translateY(-50%); }
.keyboard-control #right { right: 0; top: 50%; transform: translateY(-50%); }

.game-notification {
  position: absolute;
  top: -50px;
  left: 50%;
  transform: translateX(-50%);
  background-color: rgba(37, 99, 235, 0.9);
  color: #fff;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  z-index: 100;
}

.game-notification.fade-out { opacity: 0; transition: opacity 0.5s ease; }

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: #fff;
  border-radius: 12px;
  padding: 30px;
  max-width: 400px;
  width: 90%;
  text-align: center;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}

.modal-content h3 { color: var(--snake-primary); margin-bottom: 15px; }
.modal-content p { color: var(--snake-muted); line-height: 1.6; margin-bottom: 1.5rem; }

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: center;
}

.modal-content button,
.modal-finhub {
  padding: 10px 25px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.modal-content button {
  background: var(--snake-primary);
  color: #fff;
  border: none;
}

.modal-finhub {
  color: var(--snake-primary);
  text-decoration: none;
  border: 2px solid var(--snake-primary);
}

/* Collapsible theory */
.theory-accordion {
  padding: 2rem 1rem 4rem;
  background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 40%, #eff6ff 100%);
  width: 100%;
}

.theory-accordion details {
  max-width: 1200px;
  margin: 0 auto;
  background: #fff;
  border-radius: var(--snake-radius);
  box-shadow: var(--snake-shadow);
  overflow: hidden;
}

.theory-accordion summary {
  padding: 1.25rem 1.5rem;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--snake-text);
  cursor: pointer;
  list-style: none;
}

.theory-accordion summary::-webkit-details-marker { display: none; }

.theory-accordion summary::after {
  content: '+';
  float: right;
  font-size: 1.25rem;
  color: var(--snake-primary);
}

.theory-accordion details[open] summary::after { content: '−'; }

.theory-accordion-inner {
  padding: 0 1.5rem 2rem;
  border-top: 1px solid var(--snake-border);
}

.snake-theory-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  align-items: center;
  margin-bottom: 2rem;
}

.snake-theory-content h2 {
  font-size: 1.5rem;
  color: var(--snake-text);
  margin-bottom: 1rem;
}

.snake-theory-content p {
  color: var(--snake-muted);
  line-height: 1.7;
}

.theory-highlight {
  background: rgba(37, 99, 235, 0.1);
  border-left: 4px solid var(--snake-primary);
  padding: 1rem;
  border-radius: 0 var(--snake-radius) var(--snake-radius) 0;
  margin: 1rem 0;
}

.snake-illustration {
  position: relative;
  height: 220px;
  background: rgba(255, 255, 255, 0.8);
  border-radius: var(--snake-radius);
  box-shadow: var(--snake-shadow);
}

.snake-path {
  position: absolute;
  inset: 10%;
  border: 4px dashed var(--snake-primary);
  border-radius: 20px;
}

.snake-dot {
  position: absolute;
  width: 20px;
  height: 20px;
  background: var(--snake-primary);
  border-radius: 50%;
  animation: moveAlong 10s linear infinite;
}

.snake-food {
  position: absolute;
  width: 16px;
  height: 16px;
  background: #ff3f3f;
  border-radius: 50%;
  top: 30%;
  right: 30%;
}

@keyframes moveAlong {
  0% { top: 50%; left: 10%; }
  25% { top: 20%; left: 50%; }
  50% { top: 50%; left: 90%; }
  75% { top: 80%; left: 50%; }
  100% { top: 50%; left: 10%; }
}

.infographic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.infographic-item {
  padding: 1.5rem;
  background: rgba(37, 99, 235, 0.05);
  border-radius: var(--snake-radius);
  text-align: center;
}

.infographic-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 1rem;
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--snake-primary);
}

.infographic-flow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 1.5rem;
  background: rgba(37, 99, 235, 0.03);
  border-radius: var(--snake-radius);
}

.flow-step {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  min-width: 180px;
}

.flow-number {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--snake-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  flex-shrink: 0;
}

.flow-arrow { color: var(--snake-primary); font-weight: bold; }

/* CTA */
.cta-section {
  padding: 4rem 1rem;
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
}

.cta-container {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 2rem;
  align-items: center;
}

.cta-content h2 {
  font-size: 1.75rem;
  color: var(--snake-text);
  margin-bottom: 1rem;
}

.cta-benefit {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.benefit-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(37, 99, 235, 0.1);
  color: var(--snake-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.cta-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.cta-primary,
.cta-secondary {
  padding: 0.75rem 1.25rem;
  border-radius: var(--snake-radius);
  font-weight: 600;
  text-decoration: none;
}

.cta-primary {
  background: var(--snake-primary);
  color: #fff;
}

.cta-secondary {
  background: #fff;
  color: var(--snake-primary);
  border: 2px solid var(--snake-primary);
}

@media (max-width: 1024px) {
  .snake-theory-container,
  .cta-container {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .controller-toggle-btn { display: none; }
  .game-controller { display: none !important; }
  .infographic-flow { flex-direction: column; align-items: flex-start; }
  .flow-arrow { transform: rotate(90deg); }
}

@media (prefers-reduced-motion: reduce) {
  .snake-dot,
  #start-pause.start-pulse,
  .snake-shake {
    animation: none !important;
  }
}
