:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #f0ede7;
  --text: #1b1d22;
  --muted: #646a75;
  --border: #dcd8d0;
  --accent: #0b3fa8;
  --accent-text: #ffffff;
  --eu: #003399;
  --good: #1f8a4c;
  --mid: #c98a00;
  --bad: #c0392b;
  --map-bg: #dfe8ef;
  --land: #fbfaf7;
  --land-line: #9aa3ad;
  --land-hint: #ffe9a8;
  --city-dot: #59606b;
  --city-text: #4a505a;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.08);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111317;
    --surface: #1a1d23;
    --surface-2: #23272f;
    --text: #eceef2;
    --muted: #9aa1ad;
    --border: #2f343d;
    --accent: #5b8cff;
    --accent-text: #0b0d12;
    --map-bg: #0f1a24;
    --land: #262b33;
    --land-line: #4c5562;
    --land-hint: #5a4a17;
    --city-dot: #8f98a6;
    --city-text: #aab2bf;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button { font: inherit; color: inherit; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
.brand { font-size: 20px; margin: 0; display: flex; align-items: center; gap: 2px; white-space: nowrap; letter-spacing: .01em; }
.brand-d {
  display: inline-grid; place-items: center;
  width: 1.3em; height: 1.5em; border-radius: 5px;
  background: var(--eu); color: #fff; font-size: 1em; font-weight: 800;
}
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 999px; margin-left: auto; }
.tab {
  border: 0; background: transparent; padding: 6px 14px; border-radius: 999px;
  cursor: pointer; color: var(--muted); font-weight: 600; font-size: 14px;
}
.tab[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.tab.locked::after { content: " 🔒"; font-size: 11px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 700;
}

/* Layout */
.layout { flex: 1; display: grid; grid-template-columns: 380px 1fr; min-height: 0; }
.panel {
  padding: 20px; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 16px;
}
.panel > * { flex-shrink: 0; }
.map-wrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--map-bg); cursor: crosshair; }
.leaflet-container { font: inherit; background: var(--map-bg); }

.panel-head { display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; font-weight: 600; }
.score-label { color: var(--text); font-variant-numeric: tabular-nums; }

/* License plate */
.plate {
  display: flex; align-items: stretch;
  background: #fff; color: #111;
  border: 3px solid #111; border-radius: 10px;
  height: 84px; overflow: hidden;
  box-shadow: inset 0 0 0 2px #fff, var(--shadow);
  user-select: none;
}
.plate-eu {
  width: 42px; flex: none;
  background: var(--eu); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  padding: 6px 0 6px; gap: 2px;
  font: 700 20px/1 Arial, sans-serif;
}
.plate-stars { width: 26px; height: 26px; margin-bottom: auto; margin-top: 4px; }
.plate-text {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 10px;
  font-family: "DIN 1451", "DIN Alternate", Bahnschrift, "Arial Narrow", "Roboto Condensed", sans-serif;
  font-stretch: condensed; font-weight: 700; font-size: 50px; letter-spacing: .02em;
  padding: 0 10px; white-space: nowrap; overflow: hidden;
}
.plate-seals { display: flex; flex-direction: column; gap: 4px; }
.seal { display: block; width: 18px; height: 18px; border-radius: 50%; }
.seal-hu { background: conic-gradient(#e8a33d 0 25%, #f3c66b 0 50%, #e8a33d 0 75%, #f3c66b 0); border: 1px solid #b07a20; }
.seal-state { background: radial-gradient(circle at 50% 40%, #fff 0 30%, #d8d8d8 31% 60%, #a9a9a9 61%); border: 1px solid #888; }
.plate.pop { animation: pop .35s ease; }
@keyframes pop { 0% { transform: scale(.94); opacity: .3; } 100% { transform: scale(1); opacity: 1; } }

.prompt { margin: 0; color: var(--muted); }
.prompt.hint { color: var(--text); }
.prompt b { color: var(--text); }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  border: 1px solid transparent; border-radius: 10px; padding: 11px 16px;
  font-weight: 650; cursor: pointer; transition: transform .05s ease, opacity .15s;
}
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-text); flex: 1; }
.btn-ghost { background: var(--surface-2); border-color: var(--border); }
.btn-ghost small { color: var(--muted); font-weight: 500; }
.btn-link { background: none; color: var(--muted); text-decoration: underline; padding: 8px; }

/* Ergebnis-Popup */
.sheet {
  position: fixed; z-index: 1000;
  left: calc(380px + (100% - 380px) / 2); bottom: 24px;
  transform: translateX(-50%);
  width: min(420px, calc(100% - 32px));
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 18px;
  box-shadow: 0 12px 40px rgba(0,0,0,.28);
  padding: 16px 18px 18px;
  display: flex; flex-direction: column; gap: 6px;
}
.sheet.show { animation: sheet-in .28s cubic-bezier(.2,.9,.3,1.2); }
@keyframes sheet-in { from { transform: translate(-50%, 30px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
.sheet-title { font-size: 13px; font-weight: 600; color: var(--muted); }
.sheet-row { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.result-points { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.result-points small { font-size: 16px; color: var(--muted); font-weight: 600; }
.result-dist { font-weight: 700; }
.result-origin { color: var(--muted); font-size: 14px; }
.result-origin b { color: var(--text); }
.result-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.tag { font-size: 12px; font-weight: 650; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.tag-leicht { color: var(--good); }
.tag-mittel { color: var(--mid); }
.tag-schwer, .tag-profi { color: var(--bad); }
.result-note { margin: 0 0 6px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); font-weight: 600; font-size: 14px; }
.c-good { color: var(--good); } .c-mid { color: var(--mid); } .c-bad { color: var(--bad); }

/* Schwierigkeit */
.endless-box { display: flex; flex-direction: column; gap: 10px; }
.levels { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.level { border: 0; background: transparent; padding: 8px 4px; border-radius: 9px; font-weight: 650; font-size: 14px; color: var(--muted); cursor: pointer; }
.level[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.14); }
.level-desc { margin: 0; font-size: 13px; color: var(--muted); }

.endless-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center;
}
.endless-stats > div, .stats-row > div {
  background: var(--surface-2); border-radius: 10px; padding: 10px 4px;
  display: flex; flex-direction: column;
}
.endless-stats b, .stats-row b { font-size: 20px; font-variant-numeric: tabular-nums; }
.endless-stats span, .stats-row span { font-size: 12px; color: var(--muted); }

/* Impressum / Datenschutz */
.legal-links { margin-top: auto; padding-top: 8px; font-size: 13px; color: var(--muted); }
.legal-links a, .fine a { color: var(--muted); }
body.answered .legal-links { display: none; }

/* Map markers */
.target-label {
  background: var(--eu); color: #fff; border: 0; border-radius: 6px;
  font-weight: 700; padding: 3px 8px; box-shadow: var(--shadow);
}
.target-label::before { border-top-color: var(--eu) !important; }
.city { pointer-events: none; }
.city i {
  position: absolute; left: -3px; top: -3px; width: 6px; height: 6px; border-radius: 50%;
  background: var(--city-dot); box-shadow: 0 0 0 1.5px var(--land);
}
.city span {
  position: absolute; left: 6px; top: -8px; white-space: nowrap;
  font-size: 11px; font-weight: 600; line-height: 16px; color: var(--city-text);
  text-shadow: 0 0 2px var(--land), 0 0 2px var(--land), 0 0 3px var(--land);
}
.state-label {
  background: transparent; border: 0; box-shadow: none; color: var(--muted);
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
}

/* Modals */
.modal {
  border: 0; border-radius: 18px; padding: 0; max-width: 440px; width: calc(100% - 32px);
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.modal::backdrop { background: rgba(10,12,16,.5); }
.modal-inner { padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.modal h2 { margin: 0; font-size: 22px; }
.modal ul { padding-left: 20px; margin: 0; }
.modal li { margin: 4px 0; }
.fine { font-size: 13px; color: var(--muted); margin: 0; }
.sum-total { margin: 0; font-size: 18px; }
.sum-total b { font-size: 30px; }
.sum-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.sum-list li {
  display: grid; grid-template-columns: 64px 1fr auto; gap: 10px; align-items: center;
  background: var(--surface-2); border-radius: 10px; padding: 8px 10px; font-size: 14px;
}
.mini-plate {
  border: 2px solid #111; border-left: 8px solid var(--eu); border-radius: 5px; background: #fff; color: #111;
  font: 700 16px/1.3 "DIN 1451", Bahnschrift, "Arial Narrow", sans-serif; text-align: center; padding: 1px 4px;
}
.sum-list .pts { font-weight: 700; font-variant-numeric: tabular-nums; }
.sum-list .sub { color: var(--muted); font-size: 12px; }
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; }
.countdown { margin: 0; text-align: center; color: var(--muted); }
.countdown b { color: var(--text); font-variant-numeric: tabular-nums; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.modal-actions .btn-primary { flex-basis: 100%; }
.modal-actions .btn-ghost { flex: 1; }
.modal-actions .btn-link { margin: 0 auto; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-weight: 600; z-index: 2000; box-shadow: var(--shadow);
}

/* Rundenfortschritt im freien Modus */
.progress-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; color: var(--muted); }
.progress-head b { color: var(--text); font-variant-numeric: tabular-nums; }
.progress { position: relative; height: 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--mid); border-radius: 999px; transition: width .4s ease; }
.progress-bar.ok { background: var(--good); }
.progress-goal { position: absolute; top: -2px; bottom: -2px; left: 50%; width: 2px; background: var(--text); opacity: .5; }
.dots { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.dot {
  display: grid; place-items: center; height: 34px; border-radius: 9px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--muted); font-size: 14px; font-weight: 650;
}
.dot.now { border-color: var(--accent); color: var(--text); }
.dot.done { font-size: 16px; }
.run-meta { margin: 0; font-size: 13px; color: var(--muted); }
.result-note.ok { color: var(--good); }
.result-note.fail { color: var(--bad); }
.round-row { grid-template-columns: 80px 1fr auto !important; }
.record { font-size: 14px; font-weight: 700; color: var(--mid); margin-left: 6px; }

/* Auswahl der Schwierigkeit in der Zusammenfassung */
.pick-level { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.pick-level h3 { margin: 0; font-size: 17px; }
.pick-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.pick {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 10px 12px; border-radius: 12px; cursor: pointer; text-align: left;
  background: var(--surface-2); border: 1px solid var(--border);
}
.pick b { font-size: 16px; }
.pick span { font-size: 12px; color: var(--muted); }
.pick:hover, .pick.current { border-color: var(--accent); }
.pick[data-level="leicht"] b { color: var(--good); }
.pick[data-level="mittel"] b { color: var(--mid); }
.pick[data-level="schwer"] b, .pick[data-level="profi"] b { color: var(--bad); }
.modal { max-height: calc(100dvh - 24px); }

/* Mobile */
@media (max-width: 760px) {
  .topbar { padding: 8px 12px; gap: 8px; flex-wrap: wrap; }
  .brand { font-size: 18px; }
  .tabs { order: 3; width: 100%; margin: 0; }
  .tab { flex: 1; }
  .tab.locked::after { content: " 🔒"; font-size: 11px; }
.icon-btn { margin-left: auto; }
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .panel { border-right: 0; border-bottom: 1px solid var(--border); padding: 12px 16px; gap: 10px; max-height: 52vh; }
  .plate { height: 64px; }
  .plate-text { font-size: 38px; gap: 8px; }
  .plate-eu { width: 34px; font-size: 16px; }
  .plate-stars { width: 20px; height: 20px; }
  .seal { width: 14px; height: 14px; }
  .prompt { font-size: 14px; }
  .btn { padding: 10px 12px; font-size: 15px; }
  .sheet { left: 50%; bottom: max(12px, env(safe-area-inset-bottom)); padding: 14px 16px 16px; }
  .result-points { font-size: 28px; }
  .level { font-size: 13px; padding: 7px 2px; }
  .dot { height: 28px; }
  .endless-box { gap: 8px; }
  .endless-stats > div { padding: 6px 4px; }
  .endless-stats b { font-size: 15px; }
  .endless-box .btn-link { padding: 0; font-size: 14px; }
  /* Während der Auflösung: nur Kennzeichen zeigen, Karte bekommt den Platz */
  body.answered .prompt, body.answered .actions, body.answered .endless-box { display: none; }
  .sheet { gap: 4px; }
  .sheet .result-origin { font-size: 13px; }
  .result-tags { margin-bottom: 4px; }
  .endless-stats b { font-size: 16px; }
  .stats-row b { font-size: 16px; }
  .stats-row > div { padding: 6px 2px; }
  .stats-row span { font-size: 11px; }
  .modal-inner { padding: 18px 16px; gap: 10px; }
  .sum-total b { font-size: 26px; }
  .sum-list { gap: 4px; }
  .sum-list li { padding: 5px 8px; grid-template-columns: 54px 1fr auto; line-height: 1.25; }
  .mini-plate { font-size: 14px; }
  .pick { padding: 8px 10px; }
}
@media (max-width: 380px) {
  .plate-text { font-size: 32px; }
  .actions .btn { font-size: 14px; }
}
