/* ============================================================================
   styles/main.css — Responsive Layout, Two-Joystick Controls & Telemetry HUD
   ============================================================================ */

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #0b1120;
  color: #f8fafc;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

#app-root {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#viewport-container {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

/* ============================================================================
   SUBTLE ATTENTION-GRABBING PULSE ANIMATIONS (Part 6 / 7.3)
   Respects prefers-reduced-motion automatically
   ============================================================================ */

@keyframes subtle-cta-pulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 10px 26px rgba(249, 115, 22, 0.28), 0 0 0 0 rgba(251, 146, 60, 0.25);
  }
  50% {
    transform: scale(1.022);
    box-shadow: 0 14px 34px rgba(249, 115, 22, 0.45), 0 0 18px 2px rgba(251, 146, 60, 0.32);
  }
}

@keyframes subtle-reward-pulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 6px 18px rgba(16, 185, 129, 0.22);
  }
  50% {
    transform: scale(1.02);
    box-shadow: 0 10px 26px rgba(16, 185, 129, 0.42), 0 0 14px 1px rgba(52, 211, 153, 0.28);
  }
}

.pulse-cta {
  animation: subtle-cta-pulse 3.0s ease-in-out infinite;
}

.pulse-reward {
  animation: subtle-reward-pulse 3.2s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .pulse-cta,
  .pulse-reward,
  .tutorial-highlight {
    animation: none !important;
    transform: none !important;
  }
}

/* Top Telemetry & Action Bar */
.hud-top-bar {
  position: absolute;
  top: 10px;
  left: 14px;
  right: 14px;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}

.hud-card {
  pointer-events: auto;
  background: rgba(15, 23, 42, 0.86);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(148, 163, 184, 0.26);
  border-radius: 14px;
  padding: 8px 14px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.42);
}

/* Progress & Telemetry Strip */
.race-telemetry-card {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1 1 400px;
  max-width: 640px;
}

.metric-block {
  display: flex;
  flex-direction: column;
  min-width: 78px;
}

.metric-label {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #94a3b8;
}

.metric-value {
  font-size: 19px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: #ffffff;
}

.metric-sub {
  font-size: 11px;
  font-weight: 700;
  color: #38bdf8;
}

/* 100m Track Mini-Map Progress Bar */
.track-progress-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 140px;
}

.track-progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 700;
  color: #cbd5e1;
}

.track-progress-bar {
  position: relative;
  height: 10px;
  background: rgba(51, 65, 85, 0.88);
  border-radius: 999px;
  overflow: visible;
  border: 1px solid rgba(148, 163, 184, 0.32);
}

#hud-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #f97316, #fb7185, #facc15);
  border-radius: 999px;
  transition: width 0.06s linear;
}

.progress-marker {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 0 6px rgba(0,0,0,0.65);
}

.progress-marker.player {
  background: #f97316;
  z-index: 2;
}

.progress-marker.rival {
  background: #0284c7;
  z-index: 1;
}

/* Action Toolbar Buttons */
.hud-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  pointer-events: auto;
}

.hud-btn {
  background: rgba(30, 41, 59, 0.92);
  color: #f1f5f9;
  border: 1.5px solid rgba(148, 163, 184, 0.32);
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
  white-space: nowrap;
}

.hud-btn:hover {
  background: rgba(51, 65, 85, 0.96);
  border-color: #38bdf8;
}

.hud-btn.primary {
  background: linear-gradient(135deg, #f97316 0%, #e11d48 100%);
  border-color: #fb923c;
  color: #ffffff;
  font-weight: 800;
}

.hud-btn.primary:hover {
  background: linear-gradient(135deg, #ea580c 0%, #be123c 100%);
  border-color: #fde047;
}

.hud-btn.active-toggle {
  background: rgba(14, 165, 233, 0.26);
  border-color: #38bdf8;
  color: #38bdf8;
}

/* Bottom-Center Status & Balance Telemetry Pill (Compact so character stays prominent) */
.hud-status-banner {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 440px);
  pointer-events: none;
}

.balance-radar {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(34,197,94,0.18) 0%, rgba(15,23,42,0.92) 70%);
  border: 1.5px solid rgba(148, 163, 184, 0.42);
  flex-shrink: 0;
}

.balance-radar::before,
.balance-radar::after {
  content: '';
  position: absolute;
  background: rgba(148, 163, 184, 0.25);
}

.balance-radar::before {
  top: 50%;
  left: 4px;
  right: 4px;
  height: 1px;
}

.balance-radar::after {
  left: 50%;
  top: 4px;
  bottom: 4px;
  width: 1px;
}

#hud-balance-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22c55e;
  border: 1.5px solid #ffffff;
  transform: translate(-50%, -50%);
}

.state-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.state-standing, .state-walking, .state-running {
  background: rgba(34, 197, 94, 0.2);
  color: #4ade80;
  border: 1px solid rgba(34, 197, 94, 0.45);
}

.state-stumbling, .state-falling {
  background: rgba(245, 158, 11, 0.22);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.5);
}

.state-fallen, .state-recovering {
  background: rgba(239, 68, 68, 0.25);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.5);
}

.state-finished {
  background: rgba(56, 189, 248, 0.25);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.5);
}

.foot-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(51, 65, 85, 0.65);
  color: #94a3b8;
  border: 1px solid rgba(148, 163, 184, 0.2);
}

.foot-badge.grounded {
  background: rgba(34, 197, 94, 0.22);
  color: #4ade80;
  border-color: rgba(34, 197, 94, 0.5);
}

/* ============================================================================
   TWO ERGONOMIC MULTITOUCH JOYSTICKS (LOWER-LEFT & LOWER-RIGHT)
   ============================================================================ */

.joystick-column {
  position: absolute;
  bottom: 16px;
  width: 204px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  pointer-events: none;
}

.joystick-column.left {
  left: 16px;
}

.joystick-column.right {
  right: 16px;
}

.joystick-card {
  pointer-events: auto;
  background: rgba(15, 23, 42, 0.84);
  backdrop-filter: blur(10px);
  border: 2px solid rgba(148, 163, 184, 0.34);
  border-radius: 20px;
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.48);
  touch-action: none;
}

.joystick-card.active {
  border-color: #38bdf8;
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.35), 0 12px 32px rgba(0, 0, 0, 0.55);
}

.joystick-card.latched {
  border-color: #f59e0b;
}

.joystick-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.joystick-title {
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #ffffff;
}

.joystick-keys {
  font-size: 10px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(51, 65, 85, 0.9);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.35);
}

.joystick-ring {
  position: relative;
  width: 142px;
  height: 142px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(30, 41, 59, 0.94) 0%, rgba(15, 23, 42, 0.98) 100%);
  border: 2px solid rgba(148, 163, 184, 0.42);
  touch-action: none;
  cursor: grab;
}

.joystick-ring:active {
  cursor: grabbing;
}

.joystick-ring::before,
.joystick-ring::after {
  content: '';
  position: absolute;
  background: rgba(148, 163, 184, 0.22);
  pointer-events: none;
}

.joystick-ring::before {
  top: 50%;
  left: 10%;
  right: 10%;
  height: 1px;
}

.joystick-ring::after {
  left: 50%;
  top: 10%;
  bottom: 10%;
  width: 1px;
}

.joy-axis-label {
  position: absolute;
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  color: rgba(203, 213, 225, 0.78);
  pointer-events: none;
}

.joy-axis-label.top { top: 6px; left: 50%; transform: translateX(-50%); }
.joy-axis-label.bottom { bottom: 6px; left: 50%; transform: translateX(-50%); }
.joy-axis-label.left { left: 6px; top: 50%; transform: translateY(-50%); }
.joy-axis-label.right { right: 6px; top: 50%; transform: translateY(-50%); }

.joystick-center-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #64748b;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.joystick-vector-line {
  position: absolute;
  top: 50%;
  left: 50%;
  height: 3.5px;
  width: 0%;
  background: linear-gradient(90deg, #38bdf8, #f97316);
  transform-origin: 0% 50%;
  border-radius: 999px;
  pointer-events: none;
}

.joystick-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 32%, #f8fafc, #38bdf8 60%, #0284c7 100%);
  border: 2.5px solid #ffffff;
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.6);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.joystick-card.leg-stick .joystick-knob {
  background: radial-gradient(circle at 32% 32%, #fffbeb, #fb923c 55%, #e11d48 100%);
}

.joystick-footer {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  font-size: 10px;
  font-weight: 700;
  color: #cbd5e1;
  font-variant-numeric: tabular-nums;
}

/* Countdown Overlay */
#countdown-overlay {
  position: absolute;
  top: 36%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  text-align: center;
  pointer-events: none;
}

#countdown-text {
  font-size: 86px;
  font-weight: 900;
  color: #facc15;
  text-shadow: 0 6px 28px rgba(0, 0, 0, 0.85);
  line-height: 1;
}

#countdown-sub {
  margin-top: 6px;
  font-size: 14px;
  font-weight: 700;
  color: #f8fafc;
  background: rgba(15, 23, 42, 0.88);
  padding: 6px 16px;
  border-radius: 999px;
  border: 1px solid rgba(250, 204, 21, 0.45);
}

/* Modals & Drawers */
.modal-backdrop {
  position: absolute;
  inset: 0;
  z-index: 30;
  background: rgba(2, 6, 23, 0.74);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-panel {
  background: #0f172a;
  border: 1.5px solid rgba(148, 163, 184, 0.36);
  border-radius: 20px;
  max-width: 680px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  padding: 22px 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.72);
}

.drawer-panel {
  position: absolute;
  top: 98px;
  right: 16px;
  z-index: 25;
  width: 310px;
  max-width: 92vw;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
}

.slider-row {
  margin-bottom: 10px;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: #cbd5e1;
  margin-bottom: 3px;
}

.slider-row input[type="range"] {
  width: 100%;
  accent-color: #38bdf8;
}

/* Automated Test Suite Styling */
.test-summary-pass {
  background: rgba(34, 197, 94, 0.18);
  border: 1px solid rgba(34, 197, 94, 0.45);
  color: #4ade80;
  padding: 10px 12px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 12px;
}

.test-summary-warn {
  background: rgba(245, 158, 11, 0.18);
  border: 1px solid rgba(245, 158, 11, 0.45);
  color: #fbbf24;
  padding: 10px 12px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 12px;
}

.test-row {
  padding: 8px 10px;
  border-radius: 8px;
  margin-bottom: 6px;
  background: rgba(30, 41, 59, 0.7);
  border-left: 4px solid #22c55e;
}

.test-row.fail {
  border-left-color: #ef4444;
}

.test-row-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.test-badge {
  font-size: 10px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(34, 197, 94, 0.25);
  color: #4ade80;
}

.test-row.fail .test-badge {
  background: rgba(239, 68, 68, 0.25);
  color: #f87171;
}

.test-category {
  color: #38bdf8;
  font-weight: 700;
}

.test-detail {
  font-size: 11px;
  color: #94a3b8;
  margin-top: 3px;
  font-family: monospace;
}

.hidden {
  display: none !important;
}

/* Responsive adaptation for narrower Canvas panels & mobile screens */
@media (max-width: 768px) {
  .joystick-column {
    width: 156px;
    bottom: 68px;
  }
  .joystick-ring {
    width: 114px;
    height: 114px;
  }
  .joystick-knob {
    width: 34px;
    height: 34px;
  }
  .hud-status-banner {
    max-width: 96vw;
    bottom: 6px;
  }
}
