:root {
  --bg: #0b0d12;
  --panel: #151922;
  --panel-2: #1c212d;
  --line: #2a3140;
  --text: #eef1f6;
  --muted: #8d97a8;
  --red: #e0453a;
  --correct: #1f9d55;
  --partial: #d4a017;
  --wrong: #b3312a;
  --accent: #ef4444;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  background-image: radial-gradient(1200px 500px at 50% -200px, #2a1414 0%, transparent 70%);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.label { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 1040px; margin: 0 auto; padding: 16px;
}
.logo { margin: 0; font-size: 30px; font-weight: 900; letter-spacing: -.02em; color: var(--accent); }
.logo span { color: var(--text); }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font-weight: 700; cursor: pointer;
}

main { max-width: 1040px; margin: 0 auto; padding: 0 16px 48px; }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px;
}

.btn {
  font: inherit; font-weight: 600; padding: 12px 20px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
}
.btn:hover { border-color: #465169; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #dc2626; }
.btn:disabled { opacity: .5; cursor: default; }
.linkish { background: none; border: 0; color: var(--muted); font: inherit; font-size: 13px; text-decoration: underline; cursor: pointer; padding: 0; }
.linkish:hover { color: var(--text); }

/* modes */
.modes { display: flex; gap: 8px; justify-content: center; margin-bottom: 16px; }
.mode {
  font: inherit; font-weight: 600; padding: 8px 18px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
}
.mode[aria-pressed="true"] { color: var(--text); border-color: var(--accent); background: #2a1616; }

/* intro + search */
.intro { text-align: center; padding: 28px 20px 20px; max-width: 640px; margin: 0 auto; }
.intro h2 { margin: 8px 0 4px; font-size: 24px; }
.intro p { margin: 0 0 18px; }
.road { height: 28px; position: relative; overflow: hidden; border-bottom: 2px dashed #39414f; max-width: 320px; margin: 0 auto; }
.road span { position: absolute; bottom: 0; font-size: 22px; animation: drive 4s linear infinite; transform: scaleX(-1); }
@keyframes drive { from { left: -30px; } to { left: 100%; } }
@media (prefers-reduced-motion: reduce) { .road span { animation: none; left: 45%; } }

.search-wrap { position: relative; display: flex; gap: 8px; }
#search {
  flex: 1; min-width: 0; font: inherit; font-size: 18px; padding: 12px 16px; border-radius: 10px;
  border: 2px solid var(--line); background: #0e1118; color: var(--text); outline: none;
}
#search:focus { border-color: var(--accent); }
#search:disabled { opacity: .6; }
/* year range for Unlimited: two range inputs stacked on one track */
.years { padding: 14px 18px; max-width: 640px; margin: 0 auto 12px; box-sizing: border-box; }
.years-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.years-top b { color: var(--text, #fff); margin-left: 6px; }
.years p { margin: 6px 0 0; }
.dual { position: relative; height: 28px; margin-top: 6px; }
.dual::before {
  content: ''; position: absolute; left: 0; right: 0; top: 12px; height: 4px; border-radius: 2px;
  background: linear-gradient(to right, var(--line) var(--lo, 0%), var(--accent, #f59e0b) var(--lo, 0%),
    var(--accent, #f59e0b) var(--hi, 100%), var(--line) var(--hi, 100%));
}
.dual input { position: absolute; left: 0; width: 100%; top: 0; height: 28px; margin: 0; background: none;
  pointer-events: none; -webkit-appearance: none; appearance: none; }
.dual input::-webkit-slider-runnable-track { background: none; height: 28px; }
.dual input::-moz-range-track { background: none; }
.dual input::-webkit-slider-thumb { -webkit-appearance: none; pointer-events: auto; width: 20px; height: 20px;
  margin-top: 4px; border-radius: 50%; background: #fff; border: 3px solid var(--accent, #f59e0b); cursor: pointer; }
.dual input::-moz-range-thumb { pointer-events: auto; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent, #f59e0b); cursor: pointer; }
.years.locked .dual { opacity: .45; }
.years.locked .dual input::-webkit-slider-thumb { cursor: not-allowed; }
.years.locked .dual input::-moz-range-thumb { cursor: not-allowed; }
.dual input:focus-visible::-webkit-slider-thumb { outline: 2px solid #fff; outline-offset: 2px; }

#suggestions {
  position: absolute; z-index: 10; left: 0; right: 0; top: calc(100% + 6px); text-align: left;
  list-style: none; margin: 0; padding: 6px; max-height: 320px; overflow-y: auto;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 16px 40px rgba(0,0,0,.5);
}
#suggestions li {
  padding: 9px 12px; border-radius: 7px; cursor: pointer; display: flex; justify-content: space-between; gap: 12px;
}
#suggestions li .cat { color: var(--muted); font-size: 12px; white-space: nowrap; }
#suggestions li.active, #suggestions li:hover { background: #2a3142; }
#suggestions li.empty { color: var(--muted); cursor: default; }
.under-search { display: flex; justify-content: space-between; align-items: center; min-height: 22px; margin-top: 8px; }
.error { color: #fca5a5; margin: 8px 0 0; }

/* board */
.board-wrap { overflow-x: auto; margin-top: 20px; padding-bottom: 8px; -webkit-overflow-scrolling: touch; }
.board { display: flex; flex-direction: column; gap: 6px; min-width: 940px; }
.row { display: grid; grid-template-columns: 1.6fr repeat(10, 1fr); gap: 6px; }
.row.head div {
  font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
  text-align: center; padding: 0 2px 4px; border-bottom: 2px solid var(--line);
}
.row.head div:first-child { text-align: left; }
.tile {
  min-height: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 6px 4px; border-radius: 8px; font-weight: 700; font-size: 14px; line-height: 1.2;
  border: 1px solid rgba(0,0,0,.25); position: relative; color: #fff;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.18);
}
.tile.name { background: var(--panel-2); color: var(--text); align-items: flex-start; text-align: left; padding: 8px 10px; }
.tile.name small { color: var(--muted); font-weight: 500; font-size: 11px; }
.tile.correct { background: var(--correct); }
.tile.partial { background: var(--partial); color: #1a1405; }
.tile.wrong { background: var(--wrong); }
.tile .arrow { font-size: 18px; line-height: 1; margin-top: 2px; opacity: .9; }
.tile .unit { font-size: 10px; font-weight: 600; opacity: .8; }
.row.new .tile { animation: flip .5s both; }
@keyframes flip {
  from { transform: rotateX(90deg); opacity: 0; }
  to { transform: rotateX(0); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { .row.new .tile { animation: none; } }
.board:not(.has-rows) .row.head { display: none; }
@media (max-width: 760px) {
  .board { min-width: 940px; }
  .row { grid-template-columns: 110px repeat(10, 1fr); }
  .tile { font-size: 12px; min-height: 58px; padding: 6px 2px; }
  /* keep the car name in view while scrolling sideways */
  .tile.name, .row.head div:first-child { position: sticky; left: 0; z-index: 2; }
  .tile.name { box-shadow: 6px 0 8px -4px rgba(0,0,0,.6); font-size: 12px; }
  .row.head div:first-child { background: var(--bg); }
}

/* win */
.win { text-align: center; margin: 20px auto 0; max-width: 640px; border-color: var(--correct); }
.win.lost { border-color: var(--wrong); }
.win-name { font-size: 26px; font-weight: 800; }
.win-specs { color: #c6cedb; font-size: 14px; margin: 4px 0 8px; }
.win-grid { font-size: 18px; line-height: 1.25; letter-spacing: 1px; margin: 12px 0 16px; white-space: pre; overflow-x: auto; }
.win .result-buttons { justify-content: center; }
.result-buttons { display: flex; gap: 10px; flex-wrap: wrap; }
@keyframes pop { 0% { transform: scale(.96); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.win:not(.hidden) { animation: pop .35s ease-out; }

/* legend */
.legend-panel { margin-top: 20px; text-align: center; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; justify-content: center; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 3px; }
.sw.correct { background: var(--correct); }
.sw.partial { background: var(--partial); }
.sw.wrong { background: var(--wrong); }

/* dialogs */
dialog {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
  color: var(--text); padding: 28px; max-width: 540px; width: calc(100% - 32px);
}
dialog::backdrop { background: rgba(2,5,10,.75); }
.help h2 { margin-top: 0; }
.help ol { padding-left: 20px; }
.help li { margin-bottom: 8px; }
.help ul { padding-left: 18px; margin: 6px 0; font-size: 14px; color: #c6cedb; }
.help ul li { margin-bottom: 2px; }
kbd { background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; font-size: 13px; }
