:root {
  --bg: #0e1014;
  --surface: #171a21;
  --surface-2: #1f232c;
  --border: #2a2f3a;
  --text: #eef0f4;
  --muted: #9aa3b2;
  --alc: #f5a524;
  --alc-soft: rgba(245, 165, 36, 0.18);
  --thc: #b197fc;
  --thc-soft: rgba(177, 151, 252, 0.2);
  --red: #ff5d5d;
  --orange: #ff9f43;
  --yellow: #ffd43b;
  --green: #3ecf8e;
  --radius: 18px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f5f8;
    --surface: #ffffff;
    --surface-2: #eef0f4;
    --border: #dde1e8;
    --text: #12151b;
    --muted: #5d6676;
    --alc: #d88a00;
    --alc-soft: rgba(216, 138, 0, 0.16);
    --thc: #7c5ce0;
    --thc-soft: rgba(124, 92, 224, 0.16);
    --red: #e03131;
    --orange: #e8590c;
    --yellow: #c99a00;
    --green: #0f9d63;
    --shadow: 0 8px 30px rgba(20, 30, 50, 0.12);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(96px + var(--safe-b));
}

button, input { font: inherit; color: inherit; }
input { color: var(--text); }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 20px; letter-spacing: -0.02em; }
.brand img { border-radius: 8px; }
.profile-btn {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 12px; font-size: 14px; color: var(--muted);
}

main { max-width: 560px; margin: 0 auto; padding: 4px 16px 16px; display: grid; gap: 14px; }
main > * { min-width: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card h2 { margin: 0 0 10px; font-size: 15px; font-weight: 650; color: var(--muted); letter-spacing: 0.01em; }

/* Status */
.status { position: relative; overflow: hidden; padding: 18px 16px 16px; }
.status::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--status-color, var(--green));
}
.status[data-status="red"] { --status-color: var(--red); }
.status[data-status="orange"] { --status-color: var(--orange); }
.status[data-status="yellow"] { --status-color: var(--yellow); }
.status[data-status="green"] { --status-color: var(--green); }
.pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 12px; border-radius: 999px; font-weight: 700; font-size: 14px;
  background: color-mix(in srgb, var(--status-color) 18%, transparent); color: var(--status-color);
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status .when { color: var(--muted); font-size: 14px; margin: 10px 0 2px; }
.values { display: grid; grid-template-columns: 1fr; gap: 6px; margin: 6px 0 12px; }
.values.two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.value .big { font-size: 46px; font-weight: 780; letter-spacing: -0.03em; line-height: 1.05; font-variant-numeric: tabular-nums; }
.values.two .value .big { font-size: 34px; }
.value .unit { font-size: 0.45em; font-weight: 650; color: var(--muted); margin-left: 4px; letter-spacing: 0; }
.value .label { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em; }
.value.alc .label { color: var(--alc); }
.value.thc .label { color: var(--thc); }
.value .range { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.value .rising { font-size: 14px; font-weight: 700; color: var(--orange); margin: 2px 0; font-variant-numeric: tabular-nums; }
.ready-main { display: grid; gap: 2px; border-top: 1px solid var(--border); padding: 12px 0; }
.ready-main > span { font-size: 14px; color: var(--muted); font-weight: 600; }
.ready-main b { font-size: 26px; font-weight: 780; letter-spacing: -0.02em; color: var(--status-color); font-variant-numeric: tabular-nums; }
.ready-main b small { display: block; font-size: 14px; font-weight: 500; letter-spacing: 0; color: var(--muted); }
.ready { display: grid; gap: 8px; border-top: 1px solid var(--border); padding-top: 12px; }
.ready-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 14px; }
.ready-row span:first-child { color: var(--muted); min-width: 0; }
.ready-row b { font-variant-numeric: tabular-nums; white-space: nowrap; flex: none; }
.status .note { margin: 12px 0 0; font-size: 13px; color: var(--muted); }
.status .note.warn { color: var(--orange); }
.share-btn {
  position: absolute; top: 14px; right: 14px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  width: 36px; height: 36px; display: grid; place-items: center; color: var(--muted);
}
.empty { color: var(--muted); margin: 10px 0 0; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.col { flex-direction: column; }
.chip {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px;
  padding: 8px 14px; font-size: 14px; font-weight: 550; line-height: 1.2; text-align: left;
}
.chips.col .chip { border-radius: 12px; padding: 10px 14px; }
.chip[aria-checked="true"], .chip.on {
  background: color-mix(in srgb, var(--text) 92%, transparent); color: var(--bg); border-color: transparent;
}
.chips.method .chip[aria-checked="true"] { background: var(--thc); color: #120c22; }

.drive-custom { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; font-size: 14px; color: var(--muted); }
input[type="datetime-local"], input[type="number"], input[type="text"] {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; min-height: 44px; width: 100%; font-size: 16px;
}
.drive-custom input { width: auto; flex: 0 1 220px; }
input:focus-visible, button:focus-visible { outline: 2px solid var(--alc); outline-offset: 2px; }

/* Konsequenzen */
.consequence .headline { display: flex; align-items: center; gap: 10px; font-size: 19px; font-weight: 720; margin: 0 0 4px; }
.consequence .sub { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.c-item { border-radius: 14px; background: var(--surface-2); padding: 12px 14px; margin-top: 10px; border-left: 4px solid var(--border); }
.c-item[data-level="crime"] { border-left-color: var(--red); }
.c-item[data-level="owi"] { border-left-color: var(--orange); }
.c-item[data-level="risk"] { border-left-color: var(--yellow); }
.c-item h3 { margin: 0; font-size: 15px; }
.c-item .law { font-size: 12px; color: var(--muted); }
.facts { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.fact { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px; font-size: 14px; }
.fact b { font-variant-numeric: tabular-nums; }
.c-item p, .c-item li { font-size: 14px; color: var(--muted); margin: 6px 0 0; }
.c-item ul { margin: 6px 0 0; padding-left: 18px; }
.worst { margin-top: 12px; font-size: 14px; color: var(--muted); }
.worst b { color: var(--text); }
.all-good { display: flex; align-items: center; gap: 12px; }
.all-good .big-emoji { font-size: 34px; }

/* Charts */
#charts { display: grid; gap: 14px; }
#charts:empty { display: none; }
.chart-card .legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.chart-card svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-card .peak { font-size: 13px; color: var(--muted); margin: -4px 0 6px; }
svg .grid line { stroke: var(--border); stroke-width: 1; }
svg .grid line.v { stroke-dasharray: 2 4; }
svg text { fill: var(--muted); font-size: 10px; font-family: inherit; }
svg .band { opacity: 0.25; }
svg .mean { fill: none; stroke-width: 2.5; stroke-linejoin: round; }
.alc-chart svg .band { fill: var(--alc); }
.alc-chart svg .mean { stroke: var(--alc); }
.thc-chart svg .band { fill: var(--thc); }
.thc-chart svg .mean { stroke: var(--thc); }
.alc-chart .legend .l-mean { background: var(--alc); }
.alc-chart .legend .l-band { background: var(--alc-soft); height: 10px; }
.thc-chart .legend .l-mean { background: var(--thc); }
.thc-chart .legend .l-band { background: var(--thc-soft); height: 10px; }
svg .limit { stroke: var(--orange); stroke-dasharray: 5 4; stroke-width: 1.2; }
svg .limit.red { stroke: var(--red); }
svg .limit.yellow { stroke: var(--yellow); }
svg .limit-label { fill: var(--orange); font-weight: 650; }
svg .limit-label.red { fill: var(--red); }
svg .limit-label.yellow { fill: var(--yellow); }
svg .now { stroke: var(--text); stroke-width: 1.5; }
svg .now-label { fill: var(--text); font-weight: 700; }
svg .drive { stroke: var(--green); stroke-width: 1.5; stroke-dasharray: 3 3; }
svg .drive-label { fill: var(--green); font-weight: 700; }
svg .marker { fill: var(--text); }

/* Verlauf */
.log-head { display: flex; justify-content: space-between; align-items: center; }
.log-head h2 { margin: 0; }
.log ul { list-style: none; margin: 10px 0 0; padding: 0; }
.log li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.log li:first-child { border-top: 0; }
.log .ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 20px; background: var(--alc-soft); flex: none; }
.log li.thc .ico { background: var(--thc-soft); }
.log .what { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 0; }
.log .what b { display: block; font-size: 15px; }
.log .what small { display: block; color: var(--muted); font-size: 13px; }
.log .time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; }
.log .del { background: none; border: 0; color: var(--muted); width: 36px; height: 36px; border-radius: 10px; font-size: 16px; }
.pill-btn {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 7px 14px; font-size: 14px; font-weight: 650; color: var(--text);
}
.reset-wide { width: 100%; margin-top: 12px; font-weight: 650; color: var(--text); }
.text-btn { background: none; border: 0; color: var(--muted); font-size: 14px; padding: 6px 0; text-decoration: underline; text-underline-offset: 3px; }

/* Info */
.info summary { font-weight: 650; cursor: pointer; list-style: none; display: flex; justify-content: space-between; }
.info summary::after { content: "＋"; color: var(--muted); }
.info details[open] summary::after { content: "−"; }
.prose { font-size: 14px; color: var(--muted); }
.prose h3 { color: var(--text); font-size: 15px; margin: 16px 0 4px; }
.prose p { margin: 6px 0; }
.prose ul { padding-left: 18px; margin: 6px 0; }
.prose a { color: var(--text); }
.disclaimer { font-size: 13px; color: var(--muted); text-align: center; margin: 4px 8px 0; }

/* Add-Leiste */
.addbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  padding: 12px 16px calc(12px + var(--safe-b));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  max-width: 560px; margin: 0 auto;
}
.add {
  border: 0; border-radius: 16px; min-height: 56px; font-size: 17px; font-weight: 720;
  box-shadow: var(--shadow); display: flex; align-items: center; justify-content: center; gap: 8px;
}
.add-drink { background: var(--alc); color: #1d1300; }
.add-thc { background: var(--thc); color: #140d27; }

/* Sheets */
dialog.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  margin: auto auto 0; padding: 0; border: 0;
  border-radius: 22px 22px 0 0; background: var(--surface); color: var(--text);
  box-shadow: var(--shadow);
}
dialog.sheet.small { margin: auto; border-radius: 22px; max-width: 360px; }
dialog.sheet[open] { animation: up 0.22s ease-out; }
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
@keyframes up { from { transform: translateY(40px); } to { transform: none; } }
@media (prefers-reduced-motion: reduce) { dialog.sheet[open] { animation: none; } }
.sheet form { padding: 0 16px calc(16px + var(--safe-b)); display: grid; gap: 14px; }
.sheet.small form { padding: 20px; }
.sheet-head { position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; align-items: center; padding: 16px 0 8px; background: var(--surface); }
.sheet-head h2 { margin: 0; font-size: 19px; }
.close { background: var(--surface-2); border: 0; border-radius: 50%; width: 34px; height: 34px; color: var(--muted); }
.preset-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.preset {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 14px;
  padding: 10px 6px; display: grid; justify-items: center; gap: 2px; text-align: center; min-height: 82px;
}
.preset .e { font-size: 24px; }
.preset b { font-size: 13px; line-height: 1.2; }
.preset small { font-size: 11px; color: var(--muted); }
.preset[aria-checked="true"] { border-color: var(--alc); background: var(--alc-soft); }
.field { display: grid; gap: 8px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 650; color: var(--muted); }
.field-row { display: grid; gap: 10px; }
.field-row.three { grid-template-columns: 1fr 1fr 1fr; }
.inline { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.inline input { width: 110px; flex: none; }
.time-input { margin-top: 2px; }
.stepper { display: grid; grid-template-columns: 40px 1fr 40px; align-items: center; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; min-height: 44px; }
.stepper button { background: none; border: 0; font-size: 20px; height: 44px; }
.stepper output { text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.switch { display: flex; gap: 12px; align-items: flex-start; font-size: 15px; }
.switch input { width: 22px; height: 22px; margin: 0; flex: none; accent-color: var(--alc); }
.switch.accept { background: var(--surface-2); border-radius: 12px; padding: 12px; }
.hint { color: var(--muted); font-size: 14px; margin: 0; }
.hint.small { font-size: 13px; margin-top: -6px; }
.primary {
  border: 0; border-radius: 14px; min-height: 52px; font-weight: 750; font-size: 17px;
  background: var(--alc); color: #1d1300;
}
.primary.thc { background: var(--thc); color: #140d27; }
.sheet form > .primary[type="submit"] { position: sticky; bottom: calc(12px + var(--safe-b)); box-shadow: 0 -6px 24px var(--surface), var(--shadow); z-index: 1; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip-row .chips { display: contents; }
.chip-row .inline input { width: 84px; }
.primary:disabled { opacity: 0.45; }
.ghost { background: none; border: 1px solid var(--border); border-radius: 14px; min-height: 46px; color: var(--muted); }
.danger { color: var(--red); }
.primary.danger { background: var(--red); color: #fff; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

@media (max-width: 360px) {
  .preset-grid { grid-template-columns: repeat(2, 1fr); }
  .values.two { grid-template-columns: 1fr; }
  .field-row.three { grid-template-columns: 1fr 1fr; }
}

.ok { color: var(--green); }
.ready-row small { color: var(--muted); font-weight: 500; font-size: 13px; }
.card h2 small { font-weight: 500; }
.toast {
  position: fixed; left: 50%; bottom: calc(92px + var(--safe-b)); transform: translateX(-50%); z-index: 20;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
  white-space: nowrap; max-width: calc(100% - 32px); overflow: hidden; text-overflow: ellipsis;
}
[hidden] { display: none !important; }
