:root {
  --bg-primary: #06090f;
  --bg-secondary: #0d1117;
  --bg-card: #151b28;
  --bg-card-hover: #1a2233;
  --border: #1e2a3a;
  --border-accent: #3b82f6;
  --text-primary: #e8ecf4;
  --text-secondary: #8b95a8;
  --text-muted: #5a6478;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-glow: rgba(59, 130, 246, 0.15);
  --accent-glow-strong: rgba(59, 130, 246, 0.25);
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --purple: #a78bfa;
  --font-body: 'Space Grotesk', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

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

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(59, 130, 246, 0.08), transparent),
    radial-gradient(ellipse 60% 40% at 80% 60%, rgba(139, 92, 246, 0.04), transparent);
}

.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
.header {
  padding: 28px 0 20px;
  margin-bottom: 32px;
  position: relative;
}

.header::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: -20px;
  right: -20px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border) 20%, var(--accent) 50%, var(--border) 80%, transparent);
  opacity: 0.6;
}

.header-content {
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 28px;
  filter: drop-shadow(0 0 8px rgba(59, 130, 246, 0.3));
}

.logo h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #60a5fa, var(--accent), var(--purple));
  background-size: 200% 200%;
  animation: gradientShift 8s ease infinite;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

@keyframes gradientShift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.logo-link {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.tagline {
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 400;
}

.nav {
  margin-left: auto;
}

.nav-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: 6px;
  transition: color 0.2s, background 0.2s;
}

.nav-link:hover {
  color: var(--text-primary);
  background: var(--bg-card);
}

.nav-link-active {
  color: var(--accent);
  background: var(--accent-glow);
}

/* Controls */
.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 24px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  margin-bottom: 32px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(255, 255, 255, 0.02) inset;
}

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

.control-group label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
}

select {
  appearance: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14px;
  padding: 10px 36px 10px 12px;
  width: 100%;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' fill='none' stroke='%238b95a8' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

select:hover {
  border-color: var(--text-muted);
  background: var(--bg-card-hover);
}

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

select:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.date-input {
  appearance: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14px;
  padding: 10px 12px;
  width: 100%;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
  color-scheme: dark;
}

.date-input:hover {
  border-color: var(--text-muted);
  background: var(--bg-card-hover);
}

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

.analyze-btn {
  grid-column: 1 / -1;
  padding: 14px 24px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: white;
  border: none;
  border-radius: 10px;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s, opacity 0.2s;
  box-shadow: 0 2px 12px rgba(59, 130, 246, 0.25);
  letter-spacing: 0.2px;
}

.analyze-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(59, 130, 246, 0.35);
}

.analyze-btn:active:not(:disabled) {
  transform: translateY(0) scale(0.99);
}

.analyze-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Runners Section */
.runners-section {
  margin-bottom: 32px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.runners-section h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.runners-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.15);
}

.runners-table thead {
  background: linear-gradient(180deg, var(--bg-card), var(--bg-card-hover));
}

.runners-table th {
  padding: 10px 12px;
  text-align: left;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.runners-table td {
  padding: 8px 12px;
  color: var(--text-secondary);
  border-bottom: 1px solid rgba(30, 42, 58, 0.6);
  transition: background 0.15s;
}

.runners-table tbody tr:last-child td {
  border-bottom: none;
}

.runners-table tbody tr:hover {
  background: var(--bg-card-hover);
}

.col-num {
  font-weight: 700;
  color: var(--accent);
  width: 32px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 13px;
}

.col-name {
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

.odds-win {
  color: var(--green);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
}

.odds-place {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
}

.tag {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 6px;
  vertical-align: middle;
  display: inline-block;
}

.tag-fav {
  background: rgba(251, 191, 36, 0.12);
  color: var(--amber);
  border: 1px solid rgba(251, 191, 36, 0.25);
  box-shadow: 0 0 8px rgba(251, 191, 36, 0.08);
}

.tag-mover {
  background: rgba(59, 130, 246, 0.12);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.25);
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.08);
}

.result-pos {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}

.result-pos-1 {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: #fbbf24;
  text-shadow: 0 0 12px rgba(251, 191, 36, 0.3);
}

.result-pos-2 {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: #94a3b8;
}

.result-pos-3 {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: #cd7f32;
}

/* Analysis Section */
.analysis-section {
  margin-bottom: 32px;
  animation: fadeIn 0.4s ease;
}

.analysis-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.analysis-header h2 {
  font-size: 16px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.cache-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(52, 211, 153, 0.1);
  color: var(--green);
  border: 1px solid rgba(52, 211, 153, 0.2);
}

.analysis-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  line-height: 1.8;
  font-size: 14px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
  position: relative;
}

.analysis-content::before {
  content: "";
  position: absolute;
  top: 0;
  left: 24px;
  right: 24px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-glow-strong), transparent);
}

.analysis-content h1,
.analysis-content h2,
.analysis-content h3 {
  color: var(--text-primary);
  margin-top: 28px;
  margin-bottom: 10px;
}

.analysis-content h1 { font-size: 20px; }
.analysis-content h2 {
  font-size: 17px;
  color: var(--accent);
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(59, 130, 246, 0.15);
}
.analysis-content h3 { font-size: 15px; color: var(--purple); }

.analysis-content h1:first-child,
.analysis-content h2:first-child,
.analysis-content h3:first-child {
  margin-top: 0;
}

.analysis-content p {
  margin-bottom: 12px;
  color: var(--text-secondary);
}

.analysis-content strong {
  color: var(--text-primary);
  font-weight: 600;
}

.analysis-content ul, .analysis-content ol {
  margin-bottom: 12px;
  padding-left: 20px;
}

.analysis-content li {
  margin-bottom: 6px;
  color: var(--text-secondary);
}

.analysis-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}

.analysis-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 16px 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.analysis-table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
}

.analysis-table td {
  padding: 9px 14px;
  color: var(--text-secondary);
  border-bottom: 1px solid rgba(30, 42, 58, 0.6);
}

.analysis-table tbody tr:last-child td {
  border-bottom: none;
}

.analysis-table tbody tr:hover {
  background: var(--bg-card-hover);
}

/* Error Section */
.error-section {
  margin-bottom: 32px;
  animation: fadeIn 0.3s ease;
}

.error-content {
  background: rgba(248, 113, 113, 0.06);
  border: 1px solid rgba(248, 113, 113, 0.2);
  border-radius: 12px;
  padding: 16px 20px;
  color: var(--red);
  font-size: 14px;
}

/* Footer */
.footer {
  padding: 24px 0;
  text-align: center;
  position: relative;
}

.footer::before {
  content: "";
  position: absolute;
  top: 0;
  left: -20px;
  right: -20px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}

.footer p {
  font-size: 12px;
  color: var(--text-muted);
}

/* Runners scroll wrapper for mobile */
.runners-grid {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* About Page */
.about-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px;
  line-height: 1.8;
  font-size: 15px;
  margin-bottom: 32px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
}

.about-content h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  margin-top: 36px;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(59, 130, 246, 0.15);
}

.about-content h2:first-child {
  margin-top: 0;
}

.about-content p {
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.about-content a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(59, 130, 246, 0.3);
  transition: border-color 0.2s;
}

.about-content a:hover {
  border-bottom-color: var(--accent);
}

.about-steps {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin: 20px 0;
}

.about-step {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  padding: 16px;
  border-radius: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  transition: border-color 0.2s, background 0.2s;
}

.about-step:hover {
  border-color: rgba(59, 130, 246, 0.2);
  background: var(--bg-card-hover);
}

.step-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: white;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 700;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.2);
}

.about-step h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.about-step p {
  font-size: 14px;
  margin-bottom: 0;
}

.about-list {
  list-style: none;
  padding: 0;
  margin: 16px 0;
}

.about-list li {
  color: var(--text-secondary);
  padding: 8px 0 8px 24px;
  position: relative;
  font-size: 14px;
}

.about-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 16px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.3);
}

.about-list li strong {
  color: var(--text-primary);
}

/* Responsive */
@media (max-width: 640px) {
  .app {
    padding: 0 12px;
  }

  .controls {
    grid-template-columns: 1fr;
    padding: 16px;
    gap: 12px;
  }

  .header {
    padding: 20px 0 16px;
    margin-bottom: 20px;
  }

  .header-content {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
  }

  .tagline {
    width: 100%;
    order: 3;
  }

  .nav {
    margin-left: auto;
  }

  .about-content {
    padding: 20px;
    font-size: 14px;
  }

  .about-step {
    padding: 12px;
  }

  select {
    font-size: 16px;
  }

  .runners-table {
    font-size: 12px;
  }

  .runners-table th,
  .runners-table td {
    padding: 6px 8px;
    white-space: nowrap;
  }

  .col-trainer,
  .col-weight {
    display: none;
  }

  .col-name {
    white-space: normal;
    min-width: 100px;
  }

  .analysis-content {
    padding: 16px;
    font-size: 13px;
  }

  .runners-section,
  .analysis-section,
  .error-section {
    margin-bottom: 20px;
  }
}
