:root {
  color-scheme: light;
  --page:           #f4f8f7;
  --surface-1:      #ffffff;
  --surface-2:      #eaf2f1;
  --text-primary:   #0b1615;
  --text-secondary: #4b5f5c;
  --text-muted:     #7c8f8c;
  --border:         rgba(11, 22, 21, 0.10);
  --grid:           #dde8e6;

  --tanne:          #0f766e;
  --tanne-strong:   #0b5a54;
  --petrol:         #155e75;
  --petrol-strong:  #0f4a5c;
  --accent:         var(--tanne);
  --accent-2:       var(--petrol);
  --on-accent:      #ffffff;

  --good:           #15803d;
  --warn:           #b45309;
  --critical:       #b91c1c;
  --star-off:       #cfd9d7;
  --star-on:        #0f766e;

  --shadow: 0 1px 2px rgba(11,22,21,0.06), 0 4px 16px rgba(11,22,21,0.06);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:           #0a1211;
    --surface-1:      #10201e;
    --surface-2:      #142a27;
    --text-primary:   #eef5f4;
    --text-secondary: #a9bfbb;
    --text-muted:     #7c918d;
    --border:         rgba(238, 245, 244, 0.10);
    --grid:           #1b3330;

    --tanne:          #2dd4bf;
    --tanne-strong:   #5eead4;
    --petrol:         #38bdf8;
    --petrol-strong:  #7dd3fc;
    --accent:         var(--tanne);
    --accent-2:       var(--petrol);
    --on-accent:      #06211f;

    --good:           #4ade80;
    --warn:           #fbbf24;
    --critical:       #f87171;
    --star-off:       #2a4340;
    --star-on:        #2dd4bf;

    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 4px 16px rgba(0,0,0,0.35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:           #0a1211;
  --surface-1:      #10201e;
  --surface-2:      #142a27;
  --text-primary:   #eef5f4;
  --text-secondary: #a9bfbb;
  --text-muted:     #7c918d;
  --border:         rgba(238, 245, 244, 0.10);
  --grid:           #1b3330;

  --tanne:          #2dd4bf;
  --tanne-strong:   #5eead4;
  --petrol:         #38bdf8;
  --petrol-strong:  #7dd3fc;
  --accent:         var(--tanne);
  --accent-2:       var(--petrol);
  --on-accent:      #06211f;

  --good:           #4ade80;
  --warn:           #fbbf24;
  --critical:       #f87171;
  --star-off:       #2a4340;
  --star-on:        #2dd4bf;

  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 4px 16px rgba(0,0,0,0.35);
}

*[hidden] { display: none !important; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: -apple-system, "SF Pro Text", system-ui, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: linear-gradient(135deg, var(--tanne-strong), var(--petrol-strong));
  color: #ffffff;
}
.topbar .back {
  background: rgba(255,255,255,0.16);
  border: none;
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.topbar .titles { min-width: 0; }
.topbar h1 { font-size: 1.05rem; margin: 0; line-height: 1.2; }
.topbar .sub { font-size: 0.78rem; opacity: 0.85; margin: 1px 0 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Bottom nav ---------- */
nav.bottomnav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: flex;
  max-width: 560px;
  margin: 0 auto;
  background: var(--surface-1);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.bottomnav button {
  flex: 1;
  background: none;
  border: none;
  padding: 10px 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--text-muted);
  font-size: 0.72rem;
}
nav.bottomnav button .ic { font-size: 1.25rem; line-height: 1; }
nav.bottomnav button.active { color: var(--accent); font-weight: 600; }

main { flex: 1; padding: 14px 14px 24px; }

/* ---------- Cards / lists ---------- */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.car-list { display: flex; flex-direction: column; gap: 10px; }
.car-item {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}
.car-item .row1 { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.car-item h3 { margin: 0; font-size: 1rem; }
.car-item .chev { color: var(--text-muted); }
.progress-line { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 0.76rem; color: var(--text-secondary); }
.progress-line .bar { flex: 1; height: 6px; border-radius: 999px; background: var(--grid); overflow: hidden; }
.progress-line .bar > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.progress-line.petrol .bar > span { background: var(--accent-2); }

/* ---------- Section / category accordion ---------- */
.category {
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface-1);
}
.category > summary {
  list-style: none;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
}
.category > summary::-webkit-details-marker { display: none; }
.category > summary .count { font-weight: 400; font-size: 0.76rem; color: var(--text-muted); }
.category .items { padding: 0 14px 6px; }

/* ---------- Criterion / star row ---------- */
.criterion {
  padding: 10px 0;
  border-top: 1px solid var(--grid);
}
.criterion:first-child { border-top: none; }
.criterion .label { font-size: 0.88rem; margin-bottom: 6px; }
.stars { display: flex; gap: 6px; }
.stars button {
  background: none;
  border: none;
  padding: 4px;
  font-size: 1.55rem;
  line-height: 1;
  color: var(--star-off);
  min-width: 40px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stars button.on { color: var(--star-on); }
.criterion .note-toggle {
  margin-top: 4px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.74rem;
  padding: 4px 0;
}
.criterion textarea {
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--grid);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text-primary);
  padding: 8px 10px;
  font-size: 0.85rem;
  resize: vertical;
  min-height: 44px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 0.92rem;
  font-weight: 600;
}
.btn.primary { background: linear-gradient(135deg, var(--tanne), var(--petrol)); color: var(--on-accent); width: 100%; }
.btn.ghost { background: var(--surface-2); color: var(--text-primary); }
.btn.small { padding: 8px 12px; font-size: 0.82rem; border-radius: 10px; }
.btn:disabled { opacity: 0.5; }

/* ---------- Rater picker ---------- */
.rater-pick { display: flex; gap: 8px; margin-bottom: 14px; }
.rater-pick button {
  flex: 1;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  font-weight: 600;
}
.rater-pick button.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface-1));
  color: var(--accent);
}

.rater-badge {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 0.86rem;
}
.rater-badge strong { color: var(--accent); }
.link-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.76rem;
  text-decoration: underline;
  padding: 4px;
  flex-shrink: 0;
}

.mode-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.mode-tabs button {
  flex: 1;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-secondary);
}
.mode-tabs button.active { background: var(--accent); color: var(--on-accent); border-color: transparent; }

.hint { font-size: 0.8rem; color: var(--text-secondary); margin: 0 0 14px; line-height: 1.4; }
.empty { color: var(--text-muted); font-size: 0.86rem; text-align: center; padding: 30px 10px; }

/* ---------- Auswertung / Vergleichstabelle ---------- */
.table-scroll { overflow-x: auto; border-radius: 12px; border: 1px solid var(--border); }
table.cmp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  background: var(--surface-1);
}
table.cmp-table th, table.cmp-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}
table.cmp-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  position: sticky;
  top: 0;
  background: var(--surface-1);
}
table.cmp-table td.num, table.cmp-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.cmp-table tr.cat-row td {
  background: var(--surface-2);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
table.cmp-table tr.diff-low td { background: color-mix(in srgb, var(--warn) 20%, transparent); }
table.cmp-table tr.diff-high td { background: color-mix(in srgb, var(--critical) 22%, transparent); }

/* ---------- Export screen ---------- */
.export-car { padding: 12px 14px; margin-bottom: 10px; }
.export-car h3 { margin: 0 0 8px; font-size: 0.96rem; }
.export-row { display: flex; gap: 8px; margin-bottom: 6px; }
.export-row .btn { flex: 1; }
.export-note { font-size: 0.72rem; color: var(--text-muted); margin: 6px 0 0; }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text-primary);
  color: var(--page);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.82rem;
  box-shadow: var(--shadow);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.toast.show { opacity: 1; }

/* ---------- PIN gate ---------- */
.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: linear-gradient(160deg, var(--tanne-strong), var(--petrol-strong));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.gate .box {
  background: var(--surface-1);
  border-radius: 18px;
  padding: 24px 20px;
  width: 100%;
  max-width: 340px;
  box-shadow: var(--shadow);
  text-align: center;
}
.gate h2 { margin: 0 0 6px; font-size: 1.1rem; }
.gate p { margin: 0 0 16px; font-size: 0.85rem; color: var(--text-secondary); }
.gate-input-wrap { position: relative; margin-bottom: 10px; }
.gate input {
  width: 100%;
  padding: 12px 44px 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--grid);
  background: var(--surface-2);
  color: var(--text-primary);
  font-size: 1rem;
  text-align: center;
  letter-spacing: 0.1em;
}
.gate .eye-btn {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 1.1rem;
  padding: 8px;
  color: var(--text-muted);
  line-height: 1;
}
.gate .error { color: var(--critical); font-size: 0.8rem; min-height: 1.2em; margin-bottom: 6px; }

.header-progress { display: flex; align-items: center; gap: 8px; margin: 4px 0 16px; font-size: 0.82rem; color: var(--text-secondary); }
