:root {
  --bg: #E6EAEE;          /* winter slush */
  --surface: #F7F9FA;
  --ink: #18212B;
  --ink-soft: #4A5663;
  --line: #C9D1D9;
  --amber: #F2A900;       /* LT road-sign amber: cautions */
  --amber-ink: #6B4A00;
  --amber-bg: #FFF1C9;
  --pine: #2F7D57;        /* pluses */
  --pine-bg: #DDF0E5;
  --brake: #C6362C;       /* bans */
  --brake-bg: #FBE1DE;
  --focus: #1F6FEB;
  --radius-card: 14px;
  --radius-chip: 999px;
  --shadow: 0 1px 0 rgba(24, 33, 43, .06), 0 6px 18px -10px rgba(24, 33, 43, .25);
  --tabbar-h: 60px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121820; --surface: #1A222C; --ink: #E7ECF1; --ink-soft: #A3B0BD; --line: #2C3742;
    --amber-ink: #FFD36B; --amber-bg: #3A2E0E; --pine: #5CC38E; --pine-bg: #14301F;
    --brake: #FF7D72; --brake-bg: #3B1714; --focus: #6EA8FF;
    --shadow: 0 1px 0 rgba(0,0,0,.4), 0 8px 20px -12px rgba(0,0,0,.8);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121820; --surface: #1A222C; --ink: #E7ECF1; --ink-soft: #A3B0BD; --line: #2C3742;
  --amber-ink: #FFD36B; --amber-bg: #3A2E0E; --pine: #5CC38E; --pine-bg: #14301F;
  --brake: #FF7D72; --brake-bg: #3B1714; --focus: #6EA8FF;
  --shadow: 0 1px 0 rgba(0,0,0,.4), 0 8px 20px -12px rgba(0,0,0,.8);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 16px/1.45 "Barlow", system-ui, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
a { color: inherit; }
img { display: block; max-width: 100%; }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.num { font-family: "Barlow Condensed", "Barlow", sans-serif; font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-soft); }
.linkish { background: none; border: 0; padding: 6px 0; color: var(--ink-soft); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

/* ---------- top bar / tabs ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 12px 16px;
  background: var(--bg); position: sticky; top: 0; z-index: 5;
  border-bottom: 1px solid var(--line);
}
.brand { font: 700 22px/1 "Barlow Condensed", sans-serif; text-decoration: none; letter-spacing: .01em; }
.topbar .linkish { margin-left: auto; font-size: 14px; }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabs a { display: grid; place-items: center; text-decoration: none; font-weight: 600; color: var(--ink-soft); }
.tabs a[aria-current="page"] { color: var(--ink); box-shadow: inset 0 3px 0 var(--amber); }

@media (min-width: 760px) {
  body { padding-bottom: 0; }
  .tabs { position: static; display: flex; gap: 4px; height: auto; background: none; border: 0; padding: 0; }
  .tabs a { padding: 8px 12px; border-radius: 8px; }
  .tabs a[aria-current="page"] { box-shadow: inset 0 -3px 0 var(--amber); border-radius: 0; }
}

main { padding: 16px; max-width: 1180px; margin: 0 auto; outline: none; }
.foot { padding: 8px 16px 24px; max-width: 1180px; margin: 0 auto; font-size: 13px; color: var(--ink-soft); }

/* ---------- browse controls ---------- */
.controls { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; }
.controls.sliders { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 20px; align-items: start; }  /* second row: sliders and other range filters; the first row holds the menus */
.controls select, .btn {
  height: 40px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer;
}
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); font-weight: 600; }
.summary { margin: 4px 0 16px; color: var(--ink-soft); font-size: 15px; }
.summary strong { color: var(--ink); }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink-soft); }

.menu-wrap { position: relative; }
.sort-slot { margin-left: auto; }  /* sorting isn't a filter: it sits apart, on the right */
.sort-slot .menu { left: auto; right: 0; }
.menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 10; min-width: 220px; max-width: calc(100vw - 32px);
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 6px;
  box-shadow: 0 12px 32px -12px rgba(0,0,0,.35); display: grid;
}
.menu[hidden] { display: none; }
.menu button { text-align: left; background: none; border: 0; padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: 15px; }
.menu button:hover, .menu button:focus-visible { background: var(--bg); }
.menu button[aria-checked="true"] { font-weight: 600; box-shadow: inset 3px 0 0 var(--amber); }

/* One rule for every km / price scale (card gauges, details page, filter sliders): bigger numbers on the right, and red. */
:root { --low-to-high: linear-gradient(90deg, var(--pine) 0%, var(--amber) 55%, var(--brake) 100%); }

/* ---------- car cards ---------- */
.grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1000px) { .grid { grid-template-columns: repeat(3, 1fr); } }

.card {
  background: var(--surface); border-radius: var(--radius-card); box-shadow: var(--shadow);
  overflow: hidden; text-decoration: none; display: flex; flex-direction: column;
  transition: opacity .2s;
}
.card-wrap { position: relative; display: flex; }
.card-wrap > .card { flex: 1; }
.card-wrap.up > .card { box-shadow: 0 0 0 2px var(--pine), var(--shadow); }
.card-wrap > .votes { position: absolute; top: 8px; right: 8px; z-index: 2; }
.votes { display: inline-flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.votes .mine { display: inline-flex; gap: 4px; }
.votes .others { display: inline-flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
.other-vote { font-size: 12px; font-weight: 600; padding: 2px 6px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--ink); white-space: nowrap; }
.other-vote.up { border-color: var(--pine); }
.other-vote.down { border-color: var(--brake); }
.vote {
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); cursor: pointer;
  background: var(--surface); color: var(--ink-soft); font-size: 16px; line-height: 1;
}
.vote:hover { color: var(--ink); border-color: var(--ink-soft); }
.vote[data-vote="1"].on { background: var(--pine); border-color: var(--pine); color: #fff; }
.vote[data-vote="-1"].on { background: var(--brake); border-color: var(--brake); color: #fff; }
.vote:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.checks-menu label { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; font-size: 15px; cursor: pointer; white-space: nowrap; }
.checks-menu label:hover { background: var(--bg); }
.checks-menu label.child { padding-left: 34px; }
.flag-mark { flex: none; font-size: 17px; line-height: 1; font-family: "Apple Symbols", "Segoe UI Symbol", sans-serif; }  /* ⚑ as text, so CSS colours it */
.flag-mark.red { color: #ef4444; }
.flag-mark.yellow { color: #facc15; }
.card.dim { opacity: .45; }
.card.dim:hover, .card.dim:focus-within { opacity: .85; }
.card .photo { aspect-ratio: 16 / 10; background: var(--line); object-fit: cover; width: 100%; display: block; }
.card .card-carousel { border-radius: 0; aspect-ratio: 16 / 10; }
.card .card-carousel img { object-fit: cover; cursor: pointer; }
.card .card-carousel .nav { width: 36px; height: 36px; font-size: 24px; }
.card .body { padding: 12px 14px 14px; display: grid; gap: 10px; color: inherit; text-decoration: none; }
.card .seen { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }
.card .head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card h3 { margin: 0; font-size: 18px; font-weight: 600; line-height: 1.2; }
.card .sub { font-size: 14px; color: var(--ink-soft); }
.card .sub span, .card .seen span { white-space: nowrap; }  /* lines break between items, never inside "Petrol hybrid" */
.price { font: 700 26px/1 "Barlow Condensed", sans-serif; white-space: nowrap; }
.mismatch { font-size: 13px; color: var(--ink-soft); }

.km { font: 600 20px/1.1 "Barlow Condensed", sans-serif; font-variant-numeric: tabular-nums; }
.km.big { font-size: 28px; }

/* percentile gauge */
.gauge { display: grid; gap: 4px; font-size: 14px; }
.gauge .bar { position: relative; height: 8px; border-radius: 4px; background: var(--low-to-high); opacity: .85; }
.gauge .bar.na { background: var(--line); }
.gauge .pin { position: absolute; top: -4px; width: 4px; height: 16px; border-radius: 2px; background: var(--ink); transform: translateX(-2px); box-shadow: 0 0 0 2px var(--surface); }
.gauge .txt strong { font-weight: 600; }
.tone.green { color: var(--pine); }
.tone.yellow { color: var(--amber-ink); }
.tone.red { color: var(--brake); }

/* facts */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 13px; line-height: 1.2; padding: 4px 9px; border-radius: var(--radius-chip); font-weight: 500; }
.chip.caution { background: var(--amber-bg); color: var(--amber-ink); }
.chip.plus { background: var(--pine-bg); color: var(--pine); }
.chip.banned { background: var(--brake-bg); color: var(--brake); }
.chip.more { background: transparent; color: var(--ink-soft); padding-left: 2px; }

/* ---------- car page ---------- */
.back { display: inline-block; margin-bottom: 12px; color: var(--ink-soft); }
.car-hero { display: grid; gap: 16px; }
@media (min-width: 900px) { .car-hero { grid-template-columns: 1.2fr 1fr; align-items: start; } }
.carousel { position: relative; border-radius: var(--radius-card); overflow: hidden; background: var(--line); aspect-ratio: 4 / 3; min-width: 0; }
.carousel .track { display: flex; height: 100%; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; overscroll-behavior-x: contain; }
.carousel .track::-webkit-scrollbar { display: none; }
.carousel .track:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.carousel img { flex: 0 0 100%; width: 100%; height: 100%; object-fit: contain; scroll-snap-align: start; background: #000; }
.carousel .nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: rgba(0, 0, 0, .55); color: #fff; font-size: 28px; line-height: 1; cursor: pointer; display: grid; place-items: center;
}
.carousel .nav:hover { background: rgba(0, 0, 0, .75); }
.carousel .nav:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.carousel .prev { left: 10px; }
.carousel .next { right: 10px; }
.carousel .count { position: absolute; right: 10px; bottom: 10px; padding: 3px 9px; border-radius: 999px; background: rgba(0, 0, 0, .6); color: #fff; font-size: 13px; font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) { .carousel .track { scroll-behavior: auto; } }
.car-hero h1 { margin: 0 0 4px; font-size: 30px; line-height: 1.1; font-weight: 700; }
.car-hero .price { font-size: 40px; }
.facts-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; background: var(--line); border-radius: 12px; overflow: hidden; margin: 16px 0; }
@media (min-width: 640px) { .facts-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.facts-grid div { background: var(--surface); padding: 10px 12px; }
.facts-grid dt { font-size: 13px; color: var(--ink-soft); }
.facts-grid dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
section.block { background: var(--surface); border-radius: var(--radius-card); padding: 16px; margin: 14px 0; box-shadow: var(--shadow); }
section.block h2 { margin: 0 0 10px; font-size: 20px; }
.fact-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.fact-list li { padding-left: 14px; border-left: 4px solid; }
.fact-list.caution li { border-color: var(--amber); }
.fact-list.plus li { border-color: var(--pine); }
.fact-list.red li { border-color: var(--brake); }
.three { display: grid; gap: 14px; }
@media (min-width: 900px) { .three { grid-template-columns: repeat(3, 1fr); } .three section.block { margin: 0; } }
.gearbox.red { box-shadow: inset 4px 0 0 var(--brake), var(--shadow); }
.gearbox.yellow { box-shadow: inset 4px 0 0 var(--amber), var(--shadow); }
.gearbox.green { box-shadow: inset 4px 0 0 var(--pine), var(--shadow); }
.gearbox p { max-width: 75ch; }
.fact-list small { display: block; color: var(--ink-soft); }
.two { display: grid; gap: 14px; }
@media (min-width: 760px) { .two { grid-template-columns: 1fr 1fr; } .two section.block { margin: 0; } }
.desc { white-space: pre-line; max-width: 70ch; margin: 0; }
.features h3 { font-size: 15px; margin: 12px 0 6px; color: var(--ink-soft); font-weight: 600; }
.features .chip { background: var(--bg); color: var(--ink); }
.features .chip.win { background: var(--pine-bg); color: var(--pine); font-weight: 600; }
table.plain { border-collapse: collapse; width: 100%; font-size: 15px; }
table.plain td, table.plain th { text-align: left; padding: 6px 8px 6px 0; border-bottom: 1px solid var(--line); }
table.plain th { font-weight: 600; color: var(--ink-soft); font-size: 13px; }
table.plain td.r, table.plain th.r { text-align: right; white-space: nowrap; padding-left: 8px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.actions a { text-decoration: none; display: inline-flex; align-items: center; }

/* ---------- sheet ---------- */
.sheet { border: 0; padding: 0; width: min(560px, 100%); max-height: 88vh; border-radius: 18px; background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.sheet::backdrop { background: rgba(10, 14, 20, .5); }
@media (max-width: 640px) { .sheet { margin: auto 0 0; width: 100%; max-width: 100%; border-radius: 18px 18px 0 0; } }
.sheet-inner { padding: 18px 16px 24px; }
.sheet h2 { margin: 0 0 12px; font-size: 22px; }
.field { display: grid; gap: 6px; margin: 14px 0; }
.field > span { font-weight: 600; font-size: 15px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: inline-block; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); font-size: 14px; }
.seg input:checked + span { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.range { display: flex; gap: 8px; align-items: center; }
.range input { width: 100%; min-width: 0; height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.sheet-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.how dl { margin: 0; display: grid; gap: 10px; }
.how dt { font-weight: 600; }
.how dd { margin: 0; color: var(--ink-soft); }

.empty { padding: 40px 16px; text-align: center; color: var(--ink-soft); }
.notice { padding: 12px 14px; border-radius: 12px; background: var(--amber-bg); color: var(--amber-ink); margin-bottom: 14px; font-size: 15px; }

/* market + advice (Task 8) */
.chart { background: var(--surface); border-radius: var(--radius-card); box-shadow: var(--shadow); padding: 12px; margin: 14px 0; overflow: hidden; }
.chart h2 { margin: 2px 4px 8px; font-size: 18px; }
.chart svg { max-width: 100%; height: auto; }
.advice-grid { display: grid; gap: 14px; }
@media (min-width: 900px) { .advice-grid { grid-template-columns: 1fr 1fr; } }
.advice-card h2 { font-size: 19px; margin: 0; }
.advice-card .src { font-size: 14px; color: var(--ink-soft); margin: 2px 0 10px; }
.advice-card tr.few td { color: var(--ink-soft); }
.advice-card .tablewrap { overflow-x: auto; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.mot p { max-width: 75ch; }
.mot h3 { margin: 14px 0 4px; font-size: 16px; }
.checks { margin: 6px 0 10px; padding-left: 20px; max-width: 75ch; }
.checks li { margin: 4px 0; }
.mot-flags { display: grid; gap: 10px; grid-template-columns: 1fr; margin: 4px 0 10px; }
@media (min-width: 760px) { .mot-flags { grid-template-columns: repeat(3, 1fr); } }
.mot-col { border-left: 4px solid var(--line, #ccc); padding: 2px 0 2px 10px; }
.mot-col.red { border-color: var(--brake); } .mot-col.yellow { border-color: var(--amber); } .mot-col.green { border-color: var(--pine); }
.mot-col h3 { margin: 0 0 4px; font-size: 15px; }
.mot-col ul { margin: 0; padding-left: 16px; } .mot-col li { margin: 3px 0; }
.mot-col p { margin: 0; }
.mot details { margin: 6px 0; } .mot summary { cursor: pointer; font-weight: 600; }
.sent-by { display: inline-block; margin-top: 4px; font-size: 13px; font-weight: 600; color: var(--ink, #222); background: var(--chip, #eef0f3); border-radius: 999px; padding: 1px 8px; }
.sent p { max-width: 75ch; font-style: italic; }

/* ---------- back to top ---------- */
.to-top {
  position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); z-index: 20;
  height: 48px; padding: 0 18px; border-radius: 999px; border: 0; cursor: pointer;
  background: var(--ink); color: var(--bg); font: 600 16px/1 "Barlow", sans-serif; box-shadow: 0 8px 24px -8px rgba(0,0,0,.45);
}
.to-top[hidden] { display: none; }
.to-top:hover { opacity: .9; }
.to-top:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

/* ---------- removed ads, favourites ---------- */
.card.gone .photo, .card.gone .card-carousel img { filter: grayscale(.85); }
.gone-badge { display: inline-block; margin-top: 4px; padding: 2px 8px; border-radius: 6px; font-size: 13px; font-weight: 600; background: var(--ink); color: var(--bg); }
.view-title { margin: 0 0 4px; font-size: 26px; }
#city-menu { max-height: 60vh; overflow-y: auto; }  /* ~70 cities */
/* dual range: two inputs stacked on one track; only the thumbs take clicks */
.pct-slider .dual { position: relative; display: inline-block; width: 120px; height: 24px; }
.pct-slider .dual::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 4px; margin-top: -2px; border-radius: 2px;
  /* the card gauge's red→green, faded outside the selected range */
  --fade: color-mix(in srgb, var(--surface) 75%, transparent);
  background: linear-gradient(to right, var(--fade) var(--lo), transparent var(--lo) var(--hi), var(--fade) var(--hi)),
              var(--low-to-high); height: 8px; margin-top: -4px; border-radius: 4px; }
.pct-slider .dual input { position: absolute; inset: 0; width: 100%; margin: 0; background: none; pointer-events: none; -webkit-appearance: none; appearance: none; }
.pct-slider .dual input::-webkit-slider-runnable-track { background: transparent; height: 4px; }
.pct-slider .dual input::-moz-range-track { background: transparent; }
.pct-slider .dual input::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; border-radius: 50%; background: var(--ink); border: 2px solid var(--surface); }
.pct-slider .dual input::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--ink); border: 2px solid var(--surface); }
.pct-slider .dual input::-webkit-slider-thumb { pointer-events: auto; }
.pct-slider .dual input::-moz-range-thumb { pointer-events: auto; }

/* absolute € range: neutral track, no red→green meaning */
.pct-slider .dual.plain::before { background: linear-gradient(to right, var(--fade) var(--lo), transparent var(--lo) var(--hi), var(--fade) var(--hi)), var(--ink-soft); }
/* price sliders stacked, columns aligned (label, value, track, hidden count) */
.slider-stack { display: grid; grid-template-columns: auto auto minmax(80px, 1fr) auto; column-gap: 6px; row-gap: 2px; align-items: center; }
.slider-stack .pct-slider { display: contents; }
#eur-out { min-width: 12ch; }
.slider-stack .dual { width: 100%; }  /* tracks stretch so the three columns share the row equally */
/* narrow screens: one column of sliders, all sharing the same four columns so the tracks line up */
@media (max-width: 900px) {
  .controls.sliders { grid-template-columns: auto auto minmax(80px, 1fr) auto; column-gap: 6px; row-gap: 4px; align-items: center; }
  .controls.sliders .slider-stack { display: contents; }
}  /* widest label: €0.0k–€8.0k+ */
#km-out, #price-out { min-width: 7ch; }  /* widest: 100–100 */
.pct-slider output { min-width: 2ch; font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; }

/* Scraper tab */
.ok-ink { color: var(--pine); font-weight: 600; }
.warn-ink { color: var(--amber-ink); font-weight: 600; }
.table-wrap { overflow-x: auto; }
table.runs { width: 100%; border-collapse: collapse; font-size: 14px; }
table.runs th, table.runs td { text-align: left; padding: 6px 10px 6px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.runs th { color: var(--ink-soft); font-weight: 600; }
pre.log { margin: 0; max-height: 420px; overflow: auto; font-size: 12px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
