:root {
  --bg: #0d0d0f;
  --bg2: #16161a;
  --bg3: #1e1e24;
  --border: #2a2a35;
  --accent: #e63946;
  --accent2: #ff6b35;
  --text: #f0f0f5;
  --text2: #9090a8;
  --green: #2ecc71;
  --blue: #3498db;
  --yellow: #f1c40f;
  --purple: #9b59b6;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,.5);
}

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

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }

/* ── Layout ── */
#app { display: flex; flex-direction: column; min-height: 100vh; }

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}

.logo {
  font-size: 1.3rem; font-weight: 800; letter-spacing: -.5px;
  color: var(--text);
}

.logo span {
  font-weight: 800;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}

nav { display: flex; gap: 8px; }

nav button {
  background: none; border: 1px solid var(--border);
  color: var(--text2); padding: 6px 14px; border-radius: 6px;
  cursor: pointer; font-size: .85rem; transition: all .2s;
}
nav button:hover, nav button.active {
  border-color: var(--accent); color: var(--text);
  background: rgba(230,57,70,.1);
}

.auth-btn {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: #fff !important;
}

main { flex: 1; padding: 24px; max-width: 1200px; margin: 0 auto; width: 100%; }

/* ── Cards ── */
.card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow);
}

/* ── Headings ── */
h2 { font-size: 1.4rem; font-weight: 700; margin-bottom: 16px; }
h3 { font-size: 1.1rem; font-weight: 600; margin-bottom: 12px; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 20px; border-radius: 8px; border: none;
  font-size: .9rem; font-weight: 600; cursor: pointer;
  transition: all .2s; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #c1121f; }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); }
.btn-ghost { background: none; color: var(--text2); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--text2); }
.btn-sm { padding: 6px 12px; font-size: .8rem; }
.btn-danger { background: rgba(230,57,70,.15); color: var(--accent); border: 1px solid rgba(230,57,70,.3); }
.btn-danger:hover { background: var(--accent); color: #fff; }

/* ── Form ── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: .85rem; color: var(--text2); margin-bottom: 6px; }

input[type=text], input[type=email], input[type=password], input[type=number], select {
  width: 100%; padding: 10px 12px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: .9rem;
  outline: none; transition: border-color .2s;
}
input:focus, select:focus { border-color: var(--accent); }
select option { background: var(--bg3); }

/* ── Compare page ── */
.page-compare { display: grid; grid-template-columns: 340px 1fr; gap: 20px; align-items: start; }

@media (max-width: 900px) {
  .page-compare { grid-template-columns: 1fr; }
}

/* ── Vehicle Selector ── */
.vehicle-slots { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }

.vehicle-slot {
  display: flex; align-items: center; gap: 10px;
  padding: 12px; border-radius: 8px;
  background: var(--bg3); border: 1px solid var(--border);
  position: relative;
}
.slot-color {
  width: 10px; flex-shrink: 0; height: 44px;
  border-radius: 4px;
}
.slot-info { flex: 1; min-width: 0; }
.slot-name { font-weight: 600; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot-sub { font-size: .78rem; color: var(--text2); }
.slot-empty { color: var(--text2); font-size: .85rem; }
.slot-remove {
  background: none; border: none; color: var(--text2);
  cursor: pointer; font-size: 1.1rem; padding: 4px;
}
.slot-remove:hover { color: var(--accent); }

/* ── Search dropdown ── */
.search-wrap { position: relative; }
.search-results {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 50;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; margin-top: 4px;
  max-height: 280px; overflow-y: auto;
  box-shadow: var(--shadow);
}
.search-result-item {
  padding: 10px 14px; cursor: pointer;
  display: flex; flex-direction: column; gap: 2px;
  border-bottom: 1px solid var(--border);
  transition: background .15s;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--bg2); }
.sri-name { font-weight: 600; font-size: .9rem; }
.sri-sub { font-size: .78rem; color: var(--text2); }

.sri-thumb {
  width: 72px; height: 44px; flex-shrink: 0;
  border-radius: 6px; background: var(--bg2) center/cover no-repeat;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; border: 1px solid var(--border);
}

.result-thumb {
  width: 80px; height: 48px; flex-shrink: 0;
  border-radius: 6px; background: var(--bg3) center/cover no-repeat;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; border: 1px solid var(--border);
}

/* ── Disciplines ── */
.discipline-list { display: flex; flex-direction: column; gap: 8px; }

.discipline-btn {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: 8px;
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); cursor: pointer; text-align: left;
  transition: all .2s;
}
.discipline-btn:hover { border-color: var(--accent); }
.discipline-btn.active {
  border-color: var(--accent); background: rgba(230,57,70,.1);
}
.discipline-icon { font-size: 1.4rem; }
.discipline-label { font-weight: 600; font-size: .9rem; }
.discipline-sub { font-size: .78rem; color: var(--text2); margin-top: 1px; }

/* ── Custom discipline ── */
.custom-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }

/* ── Race section ── */
.race-section { display: flex; flex-direction: column; gap: 16px; }

.race-canvas-wrap {
  border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--border);
  background: #1a2a1a;
}
#raceCanvas { display: block; width: 100%; }

/* ── Results table ── */
.results-table {
  width: 100%; border-collapse: collapse; font-size: .88rem;
}
.results-table th {
  text-align: left; padding: 10px 12px;
  font-size: .78rem; color: var(--text2);
  border-bottom: 1px solid var(--border);
  font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
}
.results-table td {
  padding: 10px 12px; border-bottom: 1px solid var(--border);
}
.results-table tr:last-child td { border-bottom: none; }
.results-table tr:hover td { background: rgba(255,255,255,.03); }

.cell-rank { font-weight: 700; }
.rank-1 { color: #ffd700; }
.rank-2 { color: #c0c0c0; }
.rank-3 { color: #cd7f32; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 100px;
  font-size: .72rem; font-weight: 600;
}
.badge-petrol    { background: rgba(241,196,15,.15);  color: #f1c40f; }
.badge-diesel    { background: rgba(52,152,219,.15);  color: #3498db; }
.badge-electric  { background: rgba(46,204,113,.15);  color: #2ecc71; }
.badge-hybrid    { background: rgba(155,89,182,.15);  color: #9b59b6; }
.badge-plugin_hybrid { background: rgba(155,89,182,.15); color: #9b59b6; }

/* ── Fuel price banner ── */
.fuel-banner {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 18px; border-radius: 8px;
  background: var(--bg3); border: 1px solid var(--border);
  flex-wrap: wrap;
}
.fuel-banner label { font-size: .85rem; color: var(--text2); }
.fuel-banner input { width: 90px; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.7); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px;
  width: 100%; max-width: 400px;
  box-shadow: var(--shadow);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-close { background: none; border: none; color: var(--text2); font-size: 1.4rem; cursor: pointer; }
.modal-close:hover { color: var(--text); }

/* ── Toast ── */
.toast-wrap { position: fixed; bottom: 24px; right: 24px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 18px; border-radius: 8px;
  background: var(--bg3); border: 1px solid var(--border);
  font-size: .88rem; box-shadow: var(--shadow);
  animation: slide-in .2s ease;
}
.toast-success { border-color: var(--green); color: var(--green); }
.toast-error   { border-color: var(--accent); color: var(--accent); }

@keyframes slide-in {
  from { transform: translateX(40px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* ── Saved comparisons ── */
.saved-list { display: flex; flex-direction: column; gap: 12px; }
.saved-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-radius: 8px;
  background: var(--bg3); border: 1px solid var(--border);
  gap: 12px;
}
.saved-item-info { flex: 1; }
.saved-item-name { font-weight: 600; }
.saved-item-meta { font-size: .78rem; color: var(--text2); margin-top: 2px; }
.saved-item-actions { display: flex; gap: 8px; }

/* ── Loading spinner ── */
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { text-align: center; padding: 48px 20px; color: var(--text2); }
.empty-state .icon { font-size: 3rem; margin-bottom: 12px; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text2); }
