/* Design System - Inspired by Race Engine Styling */

:root {
  /* Color Palette - Dark Theme */
  --bg-primary: #0b1020;
  --bg-secondary: #1a1a2e;
  --bg-tertiary: #16213e;
  --bg-panel: rgba(255, 255, 255, 0.08);
  --bg-card: rgba(255, 255, 255, 0.05);
  --bg-hover: rgba(255, 255, 255, 0.1);
  
  /* Text Colors */
  --text-primary: #f2f5ff;
  --text-secondary: #ccc;
  --text-muted: #999;
  --text-accent: #ffd54a;
  
  /* Accent Colors */
  --accent-gold: #ffd54a;
  --accent-silver: #c0c0c0;
  --accent-bronze: #cd7f32;
  --accent-success: #49e47a;
  --accent-warning: #ffb84a;
  --accent-error: #ff6b6b;
  
  /* Gradients */
  --gradient-primary: linear-gradient(135deg, #ffb84a, #ff8a3d);
  --gradient-success: linear-gradient(135deg, #4be48a, #20d07a);
  --gradient-error: linear-gradient(135deg, #ff8787, #ff6b6b);
  --gradient-card: linear-gradient(135deg, #1a1a2e, #16213e);
  --gradient-panel: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
  
  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 20px rgba(255, 215, 0, 0.3);
  
  /* Border Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  
  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
}

/* Base Styles */
body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Inter, "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji";
  line-height: 1.6;
  min-height: 100vh;
}

/* Override Tailwind's default light theme */
.bg-gray-50 {
  background: var(--bg-primary) !important;
}

.bg-white {
  background: var(--bg-secondary) !important;
}

.text-gray-900 {
  color: var(--text-primary) !important;
}

.text-gray-700 {
  color: var(--text-secondary) !important;
}

.text-gray-600 {
  color: var(--text-muted) !important;
}

/* Navigation */
.nav-dark {
  background: var(--bg-panel);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: var(--shadow-sm);
}

.nav-dark .nav-link {
  color: var(--text-secondary);
  transition: all 0.3s ease;
}

.nav-dark .nav-link:hover {
  color: var(--text-primary);
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
}

/* Cards */
.card-dark {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-md);
  transition: all 0.3s ease;
}

.card-dark:hover {
  background: var(--bg-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.card-gradient {
  background: var(--gradient-card);
  border: 2px solid var(--accent-gold);
  border-radius: var(--radius-xl);
  padding: var(--space-md);
  box-shadow: var(--shadow-lg);
}

/* Buttons */
.btn-dark {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-primary);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 600;
  transition: all 0.3s ease;
  text-decoration: none;
  display: inline-block;
}

/* Mobile betting form - scoped styles for connected input/button */
.mobile-betting-form .form-input-dark.rounded-l-none {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

.mobile-betting-form .form-input-dark.rounded-r-none {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: none; /* Remove right border to connect with button */
}

.mobile-betting-form .form-input-dark.rounded-l-md {
  border-top-left-radius: var(--radius-md);
  border-bottom-left-radius: var(--radius-md);
}

.mobile-betting-form .form-input-dark.rounded-r-md {
  border-top-right-radius: var(--radius-md);
  border-bottom-right-radius: var(--radius-md);
}

.mobile-betting-form .btn-dark.rounded-l-none {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  border-left: none; /* Remove left border to connect with input */
}

.mobile-betting-form .btn-dark.rounded-r-none {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.mobile-betting-form .btn-dark.rounded-l-md {
  border-top-left-radius: var(--radius-md);
  border-bottom-left-radius: var(--radius-md);
}

.mobile-betting-form .btn-dark.rounded-r-md {
  border-top-right-radius: var(--radius-md);
  border-bottom-right-radius: var(--radius-md);
}

/* Ensure borders match between input and button */
.mobile-betting-form .form-input-dark,
.mobile-betting-form .btn-dark {
  border-color: rgba(255, 255, 255, 0.18);
  border-width: 1px;
}

/* Only apply hover styles on devices that support hover (not touch devices) */
@media (hover: hover) and (pointer: fine) {
  .btn-dark:hover {
    background: rgba(255, 255, 255, 0.18);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
  }
  
  .btn-primary:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
  }
}

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

/* Prevent persistent :active and :hover states on mobile devices, especially iOS Safari */
.btn-dark,
.btn-dark.btn-primary {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* On touch devices, disable hover effects completely */
@media (hover: none) and (pointer: coarse) {
  .btn-dark:hover,
  .btn-dark.btn-primary:hover {
    background: rgba(255, 255, 255, 0.12) !important;
    transform: none !important;
    box-shadow: none !important;
  }
  
  .btn-primary:hover {
    background: var(--gradient-primary) !important;
    transform: none !important;
    box-shadow: var(--shadow-sm) !important;
  }
  
  .btn-dark:active,
  .btn-dark.btn-primary:active {
    transition: all 0.1s ease;
  }
}

/* Force normal state class to break persistent hover on iOS */
.btn-dark.force-normal-state,
.btn-dark.btn-primary.force-normal-state {
  background: rgba(255, 255, 255, 0.12) !important;
  transform: none !important;
  box-shadow: none !important;
}

.btn-primary.force-normal-state {
  background: var(--gradient-primary) !important;
  transform: none !important;
  box-shadow: var(--shadow-sm) !important;
}

.btn-primary {
  background: var(--gradient-primary);
  color: #1b1203;
  border-color: rgba(0, 0, 0, 0.2);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.btn-success {
  background: var(--gradient-success);
  color: #02170b;
  border-color: rgba(0, 0, 0, 0.2);
}

.btn-error {
  background: var(--gradient-error);
  color: #160202;
  border-color: rgba(0, 0, 0, 0.2);
}

.btn-warning {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #1b1203;
  border-color: rgba(0, 0, 0, 0.2);
}

/* Panels */
.panel-dark {
  background: var(--bg-panel);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  box-shadow: var(--shadow-md);
}

/* Status Indicators */
.status-badge {
  padding: var(--space-xs) var(--space-sm);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.status-waiting {
  background: rgba(255, 184, 74, 0.2);
  color: var(--accent-warning);
  border: 1px solid rgba(255, 184, 74, 0.3);
}

.status-active {
  background: rgba(73, 228, 122, 0.2);
  color: var(--accent-success);
  border: 1px solid rgba(73, 228, 122, 0.3);
}

.status-finished {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Horse Cards */
.horse-card {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-md);
  padding: var(--space-xs);
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.horse-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--gradient-primary);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.horse-card:hover {
  background: var(--bg-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.horse-card:hover::before {
  opacity: 1;
}

.horse-card.winner {
  border-color: var(--accent-gold);
  box-shadow: var(--shadow-glow);
}

.horse-card.winner::before {
  background: var(--accent-gold);
  opacity: 1;
}

/* Race Display */
.race-container {
  /* Remove green background - canvas will draw its own background texture */
  background: transparent;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255, 255, 255, 0.12);
  overflow: hidden;
  position: relative;
}

.race-track {
  /* Remove background color - canvas will draw its own background texture */
  background: transparent;
  width: 100%;
  height: 100%;
  display: block;
}

/* Results Display */
.results-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  backdrop-filter: blur(4px);
}

.results-card {
  background: var(--gradient-card);
  border: 2px solid var(--accent-gold);
  border-radius: var(--radius-xl);
  padding: var(--space-2xl);
  max-width: 800px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  text-align: center;
  color: var(--text-primary);
}

.results-title {
  font-size: 36px;
  margin: 0 0 var(--space-xl) 0;
  color: var(--accent-gold);
  text-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
  font-weight: bold;
}

/* Top Three Display */
.top-three-container {
  display: flex;
  justify-content: space-around;
  align-items: center;
  margin-bottom: var(--space-xl);
  padding: var(--space-lg);
  background: rgba(255, 215, 0, 0.1);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255, 215, 0, 0.3);
}

.horse-podium {
  text-align: center;
  padding: var(--space-md);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  min-width: 150px;
  transition: all 0.3s ease;
}

.horse-podium:hover {
  transform: scale(1.05);
  background: var(--bg-hover);
}

.podium-position {
  font-size: 24px;
  margin-bottom: var(--space-sm);
}

.podium-name {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: var(--space-xs);
}

.podium-time {
  font-size: 16px;
  font-weight: bold;
  color: var(--text-primary);
}

/* Form Elements */
.form-input-dark {
  background: rgba(0, 0, 0, 0.35);
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  font-family: inherit;
  transition: all 0.3s ease;
  min-width: 0; /* Allow flex to shrink below default min-width */
  width: 100%; /* Ensure it respects flex container */
}

/* Allow Tailwind rounded classes to override form-input-dark border-radius */
.form-input-dark.rounded-l-none {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

.form-input-dark.rounded-r-none {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.form-input-dark.rounded-l-md {
  border-top-left-radius: var(--radius-md);
  border-bottom-left-radius: var(--radius-md);
}

.form-input-dark.rounded-r-md {
  border-top-right-radius: var(--radius-md);
  border-bottom-right-radius: var(--radius-md);
}

.form-input-dark:focus {
  outline: none;
  border-color: var(--accent-gold);
  box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.1);
}

.form-label-dark {
  font-size: 12px;
  opacity: 0.8;
  color: var(--text-secondary);
  margin-bottom: var(--space-xs);
  display: block;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
  from { transform: translateX(-100%); }
  to { transform: translateX(0); }
}

@keyframes glow {
  0%, 100% { box-shadow: 0 0 20px rgba(255, 215, 0, 0.3); }
  50% { box-shadow: 0 0 30px rgba(255, 215, 0, 0.6); }
}

.animate-fade-in {
  animation: fadeIn 0.6s ease-out;
}

.animate-slide-in {
  animation: slideIn 0.4s ease-out;
}

.animate-glow {
  animation: glow 2s ease-in-out infinite;
}

/* Responsive Design */
@media (max-width: 768px) {
  .top-three-container {
    flex-direction: column;
    gap: var(--space-md);
  }
  
  .horse-podium {
    min-width: auto;
    width: 100%;
  }
  
  .results-card {
    padding: var(--space-lg);
    margin: var(--space-md);
  }
  
  /* Mobile form inputs - ensure flex works properly */
  .form-input-dark {
    min-width: 0;
    flex-shrink: 1;
  }
  
  /* Ensure flex containers don't overflow */
  .flex {
    min-width: 0;
  }
  
  /* Reduce button horizontal padding on mobile to give more room for inputs */
  .btn-dark {
    padding-left: var(--space-sm);
    padding-right: var(--space-sm);
  }
  
  .results-title {
    font-size: 28px;
  }
}

/* QR Code Styles */
.qr-code-container {
  background: white;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  box-shadow: var(--shadow-md);
  transition: all 0.3s ease;
}

.qr-code-container:hover {
  transform: scale(1.02);
  box-shadow: var(--shadow-lg);
}

.game-code-display {
  background: var(--gradient-primary);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  text-align: center;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}

.game-code-display::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.1) 50%, transparent 70%);
  transform: translateX(-100%);
  transition: transform 0.6s ease;
}

.game-code-display:hover::before {
  transform: translateX(100%);
}

.join-url-container {
  background: var(--bg-tertiary);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  position: relative;
}

.join-url-container::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--gradient-primary);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

/* Utility Classes */
.text-glow {
  text-shadow: 0 0 10px currentColor;
}

.border-glow {
  box-shadow: 0 0 20px rgba(255, 215, 0, 0.3);
}

.backdrop-blur {
  backdrop-filter: blur(6px);
}

.glass-effect {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}
