/* ── AIRace Coach — Racing Telemetry Dark Theme ── */

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

:root {
  --bg: #0a0e17;
  --bg-elevated: #0f1420;
  --surface: #141a28;
  --surface-hover: #1a2236;
  --surface-glass: rgba(20, 26, 40, 0.75);
  --border: rgba(255,255,255,0.06);
  --border-active: rgba(0,229,160,0.3);
  --accent: #00e5a0;
  --accent-glow: rgba(0,229,160,0.15);
  --accent-dim: #00b37d;
  --red: #ff4757;
  --red-glow: rgba(255,71,87,0.12);
  --yellow: #ffa502;
  --yellow-glow: rgba(255,165,2,0.12);
  --text: #edf0f5;
  --text-secondary: #8892a4;
  --text-muted: #505a6e;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: 72px;
  --header-h: 56px;
  --font-display: 'Outfit', sans-serif;
  --font-body: 'DM Sans', sans-serif;
}

html { height: 100%; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── App Shell ── */
.app-shell { display: flex; flex-direction: column; min-height: 100dvh; }

.app-header {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 12px;
  padding: calc(var(--safe-top) + 10px) 20px 10px;
  background: rgba(10, 14, 23, 0.88);
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--border);
}

.back-btn {
  display: none; background: none; border: none; color: var(--accent);
  width: 36px; height: 36px; border-radius: 50%;
  cursor: pointer; transition: background 0.2s;
  align-items: center; justify-content: center;
}
.back-btn:active { background: var(--accent-glow); }
.back-btn.visible { display: flex; }

.header-brand { flex: 1; }
.header-logo {
  font-family: var(--font-display); font-size: 22px; font-weight: 800;
  letter-spacing: -0.5px; color: var(--text);
}
.header-logo span { color: var(--accent); }
.header-sub { font-size: 11px; color: var(--text-muted); letter-spacing: 1.5px; text-transform: uppercase; margin-top: -1px; }

.app-content {
  flex: 1; padding: 20px 16px calc(var(--nav-h) + var(--safe-bottom) + 16px);
  max-width: 480px; margin: 0 auto; width: 100%;
}

/* ── Bottom Nav ── */
.app-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  display: flex; height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(10, 14, 23, 0.92);
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid var(--border);
}

.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 4px; padding: 8px 0;
  background: none; border: none; color: var(--text-muted);
  font-family: var(--font-body); font-size: 10px; font-weight: 600;
  letter-spacing: 0.3px; cursor: pointer; transition: color 0.25s;
  position: relative;
}
.nav-btn svg { width: 22px; height: 22px; transition: transform 0.25s; }
.nav-btn.active { color: var(--accent); }
.nav-btn.active svg { transform: scale(1.1); }
.nav-btn.active::before {
  content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 24px; height: 2px; background: var(--accent); border-radius: 0 0 2px 2px;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 12px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.25s, transform 0.2s;
}
.card::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.02) 0%, transparent 50%);
  pointer-events: none;
}
.card-tap { cursor: pointer; }
.card-tap:active { transform: scale(0.98); }
.card-tap:hover { border-color: var(--border-active); }

.card-glow-green { border-color: rgba(0,229,160,0.2); box-shadow: 0 0 30px rgba(0,229,160,0.05); }
.card-glow-red { border-color: rgba(255,71,87,0.2); box-shadow: 0 0 30px rgba(255,71,87,0.05); }

/* ── Typography ── */
.section-label {
  font-family: var(--font-display); font-size: 11px; font-weight: 600;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: 2px;
  margin: 28px 0 12px; padding-left: 2px;
}

.hero-time {
  font-family: var(--font-display); font-size: 48px; font-weight: 900;
  letter-spacing: -2px; line-height: 1;
  background: linear-gradient(135deg, var(--accent) 0%, #00ffc8 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-value {
  font-family: var(--font-display); font-size: 20px; font-weight: 700;
  color: var(--text); line-height: 1.1;
}
.stat-label { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ── Badges ── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: var(--radius-xs);
  font-family: var(--font-display); font-size: 10px; font-weight: 700;
  letter-spacing: 0.5px; text-transform: uppercase;
}
.badge-ok { background: var(--accent-glow); color: var(--accent); }
.badge-medium { background: var(--yellow-glow); color: var(--yellow); }
.badge-high { background: var(--red-glow); color: var(--red); }
.badge-dt { background: rgba(255,255,255,0.06); color: var(--text-secondary); font-size: 11px; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; display: block; letter-spacing: 0.3px; }
.form-input {
  width: 100%; padding: 14px 16px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-family: var(--font-body); font-size: 15px;
  outline: none; transition: border-color 0.25s, box-shadow 0.25s;
  -webkit-appearance: none; appearance: none;
}
.form-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.form-input::placeholder { color: var(--text-muted); }
.form-row { display: flex; gap: 10px; }
.form-row .form-group { flex: 1; }

/* ── Drivetrain / Weather Radio ── */
.radio-group { display: flex; gap: 6px; }
.radio-btn {
  flex: 1; padding: 12px 8px; text-align: center;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-family: var(--font-display); font-size: 14px; font-weight: 700;
  color: var(--text-muted); cursor: pointer; transition: all 0.25s;
  letter-spacing: 0.5px;
}
.radio-btn.active {
  border-color: var(--accent); color: var(--accent);
  background: var(--accent-glow); box-shadow: 0 0 12px var(--accent-glow);
}

/* ── Buttons ── */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 16px; border: none; border-radius: var(--radius-sm);
  font-family: var(--font-display); font-size: 15px; font-weight: 700;
  cursor: pointer; transition: all 0.2s; letter-spacing: 0.3px;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: var(--bg); }
.btn-primary:disabled { opacity: 0.3; cursor: not-allowed; transform: none; }
.btn-ghost { background: transparent; color: var(--accent); border: 1px solid var(--border); }
.btn-ghost:hover { border-color: var(--border-active); }
.btn-danger { background: var(--red); color: white; }
.btn-sm { padding: 10px 16px; font-size: 13px; width: auto; }

/* ── Pilot Badge ── */
.pilot-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 16px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 100px; font-size: 13px; font-weight: 500; margin-bottom: 20px;
}
.pilot-chip-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px var(--accent); }

/* ── Upload Zone ── */
.upload-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 48px 24px; text-align: center; cursor: pointer;
  transition: all 0.3s; position: relative; overflow: hidden;
}
.upload-zone::before {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 50%, var(--accent-glow) 0%, transparent 70%);
  opacity: 0; transition: opacity 0.3s;
}
.upload-zone.dragover { border-color: var(--accent); }
.upload-zone.dragover::before { opacity: 1; }
.upload-zone svg { color: var(--text-muted); margin-bottom: 12px; }
.upload-zone p { color: var(--text-muted); font-size: 14px; position: relative; }
.upload-zone .file-name { color: var(--accent); font-weight: 600; margin-top: 10px; font-size: 15px; }

/* ── Spinner ── */
.spinner { display: inline-block; width: 20px; height: 20px; border: 2.5px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.analyzing-overlay {
  text-align: center; padding: 40px 20px;
}
.analyzing-ring {
  width: 64px; height: 64px; border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto 20px;
}
.analyzing-text { font-family: var(--font-display); font-size: 16px; font-weight: 600; color: var(--text); }
.analyzing-sub { font-size: 13px; color: var(--text-muted); margin-top: 6px; }

/* ── Map ── */
.map-wrap { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); margin-bottom: 16px; height: 260px; }
.map-wrap .leaflet-container { background: var(--bg) !important; }

/* ── Corner Cards ── */
.corner-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-bottom: 8px; overflow: hidden; transition: border-color 0.25s;
}
.corner-card-header {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; cursor: pointer;
}
.corner-card-header:active { background: var(--surface-hover); }
.corner-id { font-family: var(--font-display); font-size: 15px; font-weight: 800; color: var(--accent); min-width: 32px; }
.corner-id.sev-high { color: var(--red); }
.corner-id.sev-medium { color: var(--yellow); }
.corner-speeds { flex: 1; font-size: 12px; color: var(--text-secondary); line-height: 1.5; }
.corner-speeds strong { color: var(--text); font-family: var(--font-display); font-size: 13px; font-weight: 700; }
.corner-chevron { color: var(--text-muted); transition: transform 0.3s; font-size: 18px; }
.corner-card.expanded .corner-chevron { transform: rotate(180deg); }
.corner-detail { display: none; padding: 0 16px 16px; border-top: 1px solid var(--border); }
.corner-card.expanded .corner-detail { display: block; padding-top: 14px; }

.corner-metric-row { display: flex; gap: 8px; margin-bottom: 8px; }
.corner-metric {
  flex: 1; padding: 10px; background: var(--bg); border-radius: var(--radius-xs);
  text-align: center;
}
.corner-metric-val { font-family: var(--font-display); font-size: 16px; font-weight: 700; }
.corner-metric-label { font-size: 10px; color: var(--text-muted); margin-top: 2px; text-transform: uppercase; letter-spacing: 0.5px; }
.corner-metric-delta { font-size: 10px; font-weight: 600; margin-top: 2px; }
.delta-pos { color: var(--accent); }
.delta-neg { color: var(--red); }

.corner-tip {
  padding: 12px; background: var(--bg); border-radius: var(--radius-xs);
  font-size: 13px; color: var(--text-secondary); line-height: 1.6;
  border-left: 3px solid var(--accent); margin-top: 10px;
}
.corner-tip.tip-high { border-color: var(--red); }
.corner-tip.tip-medium { border-color: var(--yellow); }

/* ── AI Coach Section ── */
.ai-section { margin-top: 24px; }
.ai-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; background: var(--accent-glow); border: 1px solid rgba(0,229,160,0.2);
  border-radius: 100px; font-family: var(--font-display); font-size: 10px;
  font-weight: 700; color: var(--accent); letter-spacing: 1px; text-transform: uppercase;
  margin-bottom: 12px;
}
.ai-summary {
  font-size: 14px; line-height: 1.7; color: var(--text-secondary);
  padding: 16px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin-bottom: 12px;
}
.ai-tip {
  padding: 16px; border-radius: var(--radius-sm); margin-bottom: 10px;
  background: var(--surface); border: 1px solid var(--border);
}
.ai-tip-corner { font-family: var(--font-display); font-size: 13px; font-weight: 700; color: var(--accent); margin-bottom: 4px; }
.ai-tip-title { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.ai-tip-detail { font-size: 13px; line-height: 1.6; color: var(--text-secondary); margin-bottom: 8px; }
.ai-tip-technique { font-size: 12px; color: var(--accent-dim); font-style: italic; line-height: 1.5; padding: 10px; background: var(--accent-glow); border-radius: var(--radius-xs); }

.ai-strength {
  padding: 12px 14px; background: var(--accent-glow); border-radius: var(--radius-xs);
  font-size: 13px; color: var(--accent); line-height: 1.5; margin-bottom: 6px;
}

.ai-pattern {
  padding: 14px; background: var(--yellow-glow); border: 1px solid rgba(255,165,2,0.15);
  border-radius: var(--radius-sm); font-size: 13px; color: var(--yellow);
  line-height: 1.6; margin-bottom: 12px;
}

.ai-strategy {
  padding: 14px; background: var(--surface); border: 1px solid var(--border-active);
  border-radius: var(--radius-sm); font-size: 13px; color: var(--text); line-height: 1.6;
}

.ai-videos { margin-top: 12px; }
.ai-video-link {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 13px; color: var(--accent);
  text-decoration: none; margin-bottom: 6px; transition: border-color 0.2s;
}
.ai-video-link:hover { border-color: var(--border-active); }

/* ── Consistency Stats ── */
.stats-row { display: flex; gap: 8px; margin-bottom: 12px; }
.stat-card {
  flex: 1; padding: 14px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); text-align: center;
}

/* ── History ── */
.session-card {
  display: flex; align-items: center; gap: 14px; padding: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; margin-bottom: 8px; transition: all 0.2s;
}
.session-card:active { transform: scale(0.98); border-color: var(--border-active); }
.session-time { font-family: var(--font-display); font-size: 22px; font-weight: 800; color: var(--accent); min-width: 80px; }
.session-info { flex: 1; }
.session-pilot { font-size: 14px; font-weight: 600; }
.session-car { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.session-date { font-size: 11px; color: var(--text-muted); }

/* ── Empty State ── */
.empty { text-align: center; padding: 60px 20px; }
.empty svg { color: var(--text-muted); opacity: 0.3; margin-bottom: 16px; }
.empty h3 { font-family: var(--font-display); font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.empty p { font-size: 14px; color: var(--text-muted); line-height: 1.5; }

/* ── Warning ── */
.warning-box {
  padding: 12px 14px; background: var(--yellow-glow); border: 1px solid rgba(255,165,2,0.2);
  border-radius: var(--radius-sm); font-size: 13px; color: var(--yellow); margin-bottom: 12px; line-height: 1.5;
}

/* ── Car Search Dropdown ── */
.car-dropdown {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 50;
  max-height: 220px; overflow-y: auto; display: none;
  background: var(--surface); border: 1px solid var(--border);
  border-top: none; border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  box-shadow: 0 12px 40px rgba(0,0,0,0.4);
}
.car-dropdown.show { display: block; }
.car-option {
  padding: 12px 16px; cursor: pointer; transition: background 0.15s;
  border-bottom: 1px solid var(--border); font-size: 14px;
}
.car-option:hover { background: var(--surface-hover); }
.car-option:last-child { border-bottom: none; }
.car-option-name { font-weight: 600; }
.car-option-specs { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ── Animations ── */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeIn 0.35s ease-out both; }
.fade-in-1 { animation-delay: 0.05s; }
.fade-in-2 { animation-delay: 0.1s; }
.fade-in-3 { animation-delay: 0.15s; }
.fade-in-4 { animation-delay: 0.2s; }
.fade-in-5 { animation-delay: 0.25s; }

@keyframes pulseGlow { 0%,100% { box-shadow: 0 0 20px var(--accent-glow); } 50% { box-shadow: 0 0 40px rgba(0,229,160,0.25); } }
.pulse-glow { animation: pulseGlow 2s ease-in-out infinite; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
