:root {
  color-scheme: light dark;
  --bg: #fbf5e9;
  --surface: #fffdf8;
  --ink: #2e2419;
  --muted: #6f6151;
  --line: #e6dac5;
  --crust: #b9803f;
  --track: #efe5d2;
  --accent: #a32a4a;
  --on-accent: #ffffff;
  --gold: #e2ae3c;
  --on-gold: #2e2419;
  --serif: ui-serif, "Iowan Old Style", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1914;
    --surface: #2a221b;
    --ink: #f5ecdf;
    --muted: #b9a994;
    --line: #43372b;
    --crust: #d9a262;
    --track: #43372b;
    --accent: #f08ba6;
    --on-accent: #2a1017;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-padding-bottom: 96px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--sans);
  -webkit-text-size-adjust: 100%;
}

h1, h2 { font-family: var(--serif); line-height: 1.2; }
h1 { font-size: 2rem; margin: 0 0 16px; }
h2 { font-size: 1.25rem; margin: 28px 0 6px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.page {
  max-width: 620px;
  margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom));
}

/* Schaltflächen */
.primary, .secondary, .danger {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 11px 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
}
.primary { background: var(--accent); color: var(--on-accent); }
.primary:disabled { opacity: 0.6; }
.secondary { background: var(--surface); border-color: var(--line); color: var(--ink); }
.danger { background: transparent; border-color: var(--accent); color: var(--accent); }
.stack { display: grid; gap: 10px; }
.form-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }

/* Anmeldung */
.auth {
  max-width: 380px;
  margin: 0 auto;
  padding: calc(48px + env(safe-area-inset-top)) 20px 32px;
  text-align: center;
}
.auth h1 { margin: 12px 0 4px; }
.auth form { margin-top: 20px; text-align: left; }

/* Formular */
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; margin-bottom: 5px; font-weight: 600; }
.field small { font-weight: 400; font-size: 0.875rem; }
.field input, .field textarea {
  display: block;
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 16px;
}
.field input::placeholder { color: var(--muted); opacity: 0.75; }
.field textarea { resize: vertical; }
.error { color: var(--accent); font-weight: 600; }

.scale { display: flex; justify-content: space-between; margin: 22px 0 10px; font-size: 0.875rem; }
.rating { border: 0; margin: 0 0 16px; padding: 0; min-width: 0; }
.rating legend { padding: 0; margin-bottom: 6px; font-weight: 600; }
.rating-row { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 3px; }
.rating-row label { position: relative; display: block; }
.rating-row input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.rating-row span {
  display: grid;
  place-items: center;
  height: 44px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
}
.rating-row input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
}
.rating-row input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 1px; }

/* Ranking */
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 12px;
  background: var(--track);
  border-radius: 12px;
}
.tabs button {
  min-height: 40px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  font-weight: 600;
}
.tabs button[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 2px rgb(46 36 25 / 0.18); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chips button, .filter {
  min-height: 36px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 0.875rem;
}
.chips button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.filter { margin-bottom: 14px; border-color: var(--accent); color: var(--accent); font-weight: 600; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.card {
  display: block;
  width: 100%;
  padding: 14px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom: 3px solid var(--crust);
  border-radius: 14px;
}
.card-top { display: flex; align-items: center; gap: 12px; }
.rank {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--track);
  font: 700 1.0625rem var(--serif);
}
.rank-1 { background: var(--gold); color: var(--on-gold); }
.card-title { flex: 1; min-width: 0; display: block; overflow-wrap: anywhere; }
.card-title strong { display: block; font-size: 1.0625rem; line-height: 1.3; }
.card-title .muted { display: block; font-size: 0.875rem; }
.score { flex: none; display: block; text-align: right; }
.score b { display: block; font: 700 1.5rem/1.1 var(--serif); font-variant-numeric: tabular-nums; }
.score small { display: block; font-size: 0.75rem; }

.bars { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; margin-top: 12px; }
.bar { display: block; color: var(--muted); }
.bar.active { color: var(--ink); font-weight: 700; }
.bar-caption { display: flex; justify-content: space-between; font-size: 0.8125rem; font-variant-numeric: tabular-nums; }
.track { display: block; height: 6px; margin-top: 3px; background: var(--track); border-radius: 3px; overflow: hidden; }
.fill { display: block; height: 100%; background: var(--crust); border-radius: 3px; }
.bar.active .fill { background: var(--accent); }
.note { display: block; margin-top: 10px; font-size: 0.875rem; overflow-wrap: anywhere; white-space: pre-line; }

.empty { text-align: center; padding: 28px 12px; }
.empty h2 { margin-top: 12px; }
.empty .primary { max-width: 280px; margin: 16px auto 0; }

/* Navigation */
.nav {
  position: fixed;
  inset: auto 0 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 6px max(8px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.nav button {
  min-height: 48px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}
.nav button[aria-current="page"] { color: var(--accent); background: var(--track); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(80px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  background: var(--ink);
  color: var(--bg);
  border-radius: 10px;
  font-weight: 600;
  overflow-wrap: anywhere;
  pointer-events: none;
}

@media (min-width: 520px) {
  .bars { grid-template-columns: repeat(4, 1fr); }
}
