:root {
  --bg: #0a0c14;
  --surface: #131726;
  --surface-2: #1b2033;
  --line: #262c42;
  --text: #e9ebf3;
  --muted: #8d93ab;
  --faint: #5d637c;
  --accent: #f5c26b;
  --accent-ink: #231806;
  --blue: #8fa3ff;
  --danger: #ff7a7a;
  --fav: #ffd166;
  --radius: 16px;
  --tabbar-h: 58px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body { min-height: 100vh; min-height: 100dvh; overflow-x: hidden; }

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 18px) 16px calc(var(--tabbar-h) + var(--safe-bottom) + 28px);
}

h1 { font-size: 30px; line-height: 1.15; margin: 6px 0 4px; letter-spacing: -0.02em; }
h2 { font-size: 18px; margin: 28px 0 10px; letter-spacing: -0.01em; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* ---------- Tabbar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(14, 17, 28, 0.92);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; color: var(--faint);
}
.tabbar a.active { color: var(--accent); }
.tabbar a.active svg { fill: currentColor; fill-opacity: .18; }

/* ---------- Karten & Buttons ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.card + .card { margin-top: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--line); font-weight: 600; font-size: 15px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn[aria-pressed="true"] { border-color: var(--fav); color: var(--fav); }
.btn svg { width: 18px; height: 18px; }

.icon-btn {
  width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 12px; color: var(--muted);
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 20px; height: 20px; }

.back { display: inline-flex; align-items: center; gap: 2px; color: var(--accent); font-size: 16px; margin-left: -6px; min-height: 40px; }

/* ---------- Start ---------- */
.hero { text-align: center; padding: 18px 0 8px; }
.hero .moon { color: var(--accent); }
.hero .moon svg { width: 34px; height: 34px; fill: currentColor; fill-opacity: .2; }
.start-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  width: 210px; height: 210px; margin: 26px auto 22px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffd88f, var(--accent) 55%, #d99a3a);
  color: var(--accent-ink); font-size: 22px; font-weight: 700; letter-spacing: -0.01em;
  box-shadow: 0 0 0 10px rgba(245, 194, 107, .08), 0 0 0 22px rgba(245, 194, 107, .04), 0 20px 50px rgba(245, 194, 107, .18);
  transition: transform .15s;
}
.start-btn:active { transform: scale(.96); }
.start-btn svg { width: 34px; height: 34px; fill: currentColor; stroke-width: 1.5; }

.segmented { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.segmented button { flex: 1; min-height: 38px; border-radius: 9px; font-size: 15px; color: var(--muted); font-weight: 600; }
.segmented button.on { background: var(--surface-2); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.field-label { display: flex; justify-content: space-between; align-items: baseline; margin: 0 2px 8px; font-size: 14px; color: var(--muted); }

.tips { list-style: none; margin: 0; padding: 0; }
.tips li { display: flex; gap: 12px; padding: 9px 0; font-size: 15px; }
.tips li + li { border-top: 1px solid var(--line); }
.tips .ico { width: 24px; text-align: center; flex: none; }

.notice { border-color: rgba(245, 194, 107, .35); background: rgba(245, 194, 107, .07); font-size: 14px; }
.notice.warn { border-color: rgba(255, 122, 122, .35); background: rgba(255, 122, 122, .07); }

.last-night { display: flex; align-items: center; gap: 12px; }
.last-night .grow { flex: 1; min-width: 0; }
.chev { color: var(--faint); }

/* ---------- Nacht-Detail ---------- */
.meta { color: var(--muted); font-size: 15px; }
.timeline { margin: 18px 0 8px; }
.tl-track {
  position: relative; height: 64px; border-radius: 12px; background: var(--surface);
  border: 1px solid var(--line); overflow: hidden;
}
.tl-mark {
  position: absolute; bottom: 0; width: 6px; margin-left: -3px; border-radius: 3px 3px 0 0;
  background: var(--blue); opacity: .85;
}
.tl-mark::after { content: ""; position: absolute; inset: -6px -8px 0; } /* größere Tippfläche */
.tl-mark.fav { background: var(--fav); }
.tl-mark.playing { background: var(--accent); opacity: 1; }
.tl-ticks { position: relative; height: 18px; margin-top: 4px; font-size: 11px; color: var(--faint); }
.tl-ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }

.toolbar { display: flex; gap: 8px; margin: 14px 0 12px; flex-wrap: wrap; }
.toolbar .btn { flex: 1; min-width: 140px; }

.ev-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.ev {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 8px 12px 12px;
  transition: border-color .2s, opacity .25s, transform .25s;
}
.ev.playing { border-color: rgba(245, 194, 107, .6); }
.ev.removing { opacity: 0; transform: scale(.97); }
.ev-play {
  width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--accent);
}
.ev-play svg { fill: currentColor; width: 18px; height: 18px; }
.ev.playing .ev-play { background: var(--accent); color: var(--accent-ink); }
.ev-main { min-width: 0; cursor: pointer; }
.ev-top { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.ev-time { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 17px; }
.ev-dur { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.ev-night { color: var(--faint); font-size: 13px; width: 100%; }
.ev-wave { position: relative; height: 26px; margin: 6px 0 4px; }
.ev-wave svg { width: 100%; height: 26px; stroke: none; fill: var(--blue); opacity: .75; display: block; }
.ev.fav .ev-wave svg { fill: var(--fav); }
.ev-progress {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0; pointer-events: none;
  background: rgba(245, 194, 107, .25); border-right: 2px solid var(--accent); border-radius: 3px;
  display: none;
}
.ev.playing .ev-progress, .ev.paused .ev-progress { display: block; }
.ev-level { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.bars { display: inline-flex; gap: 2px; align-items: flex-end; height: 12px; }
.bars i { width: 4px; border-radius: 1px; background: var(--line); }
.bars i:nth-child(1) { height: 4px; } .bars i:nth-child(2) { height: 7px; } .bars i:nth-child(3) { height: 10px; } .bars i:nth-child(4) { height: 12px; }
.bars.l1 i:nth-child(-n+1), .bars.l2 i:nth-child(-n+2), .bars.l3 i:nth-child(-n+3), .bars.l4 i:nth-child(-n+4) { background: var(--accent); }
.ev-actions { display: flex; flex-direction: column; }
.ev.fav .star { color: var(--fav); }
.ev.fav .star svg { fill: currentColor; }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty .big { font-size: 44px; margin-bottom: 8px; }

/* ---------- Übersicht ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.tile .v { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.tile .k { font-size: 13px; color: var(--muted); }

.chart { display: flex; align-items: flex-end; gap: 4px; height: 130px; padding-top: 18px; }
.chart .col { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; }
.chart .bar { width: 100%; max-width: 26px; background: var(--blue); border-radius: 4px 4px 1px 1px; min-height: 2px; }
.chart .bar.zero { background: var(--line); }
.chart .val { font-size: 11px; color: var(--muted); margin-bottom: 3px; font-variant-numeric: tabular-nums; }
.chart.hours { gap: 2px; }
.chart.hours .bar { background: var(--accent); max-width: none; }
.chart.hours .bar.zero { background: var(--line); }
.axis { display: flex; gap: 4px; margin-top: 6px; font-size: 11px; color: var(--faint); }
.axis span { flex: 1; min-width: 0; text-align: center; white-space: nowrap; overflow: visible; }
.axis.hours { gap: 2px; }

.night-list { display: flex; flex-direction: column; gap: 10px; }
.night-item { display: block; }
.night-item .row { display: flex; align-items: center; gap: 10px; }
.night-item .grow { flex: 1; min-width: 0; }
.night-item .title { font-weight: 600; }
.badge {
  min-width: 34px; height: 28px; padding: 0 9px; border-radius: 14px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2); font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums;
}
.badge.has { background: rgba(143, 163, 255, .16); color: var(--blue); }
.mini-tl { position: relative; height: 8px; margin-top: 10px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.mini-tl i { position: absolute; top: 0; bottom: 0; width: 3px; margin-left: -1.5px; background: var(--blue); }
.mini-tl i.fav { background: var(--fav); }

/* ---------- Einstellungen ---------- */
.setting { display: flex; align-items: center; gap: 12px; }
.setting .grow { flex: 1; }
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--line); transition: background .2s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 25px; height: 25px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked + span { background: #34c759; border-color: transparent; }
.switch input:checked + span::after { transform: translateX(20px); }
.storage-bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin: 10px 0 6px; }
.storage-bar div { height: 100%; background: var(--blue); }
ol.steps { padding-left: 20px; margin: 6px 0 0; }
ol.steps li { margin-bottom: 6px; }

/* ---------- Nachtmodus ---------- */
#night {
  position: fixed; inset: 0; z-index: 100; background: #000; color: #4a4f62;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  touch-action: none; overscroll-behavior: none; user-select: none; -webkit-user-select: none;
  padding: var(--safe-top) 16px var(--safe-bottom);
}
#night[hidden] { display: none; }
.n-wrap { text-align: center; transition: transform 2s ease; }
.n-clock { font-size: min(24vw, 140px); font-weight: 200; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; line-height: 1; color: #3d4152; }
.n-status { margin-top: 14px; font-size: 15px; color: #33374a; min-height: 21px; }
.n-status .rec { color: #7a2f2f; }
.n-controls {
  position: absolute; left: 0; right: 0; bottom: calc(var(--safe-bottom) + 28px);
  display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 0 24px;
  opacity: .28; transition: opacity .6s;
}
#night.awake .n-controls { opacity: 1; }
#night.awake .n-clock { color: #6b7088; }
#night.awake .n-status { color: #6b7088; }
.n-meter { position: relative; width: 100%; max-width: 280px; height: 6px; border-radius: 3px; background: #15171f; overflow: hidden; }
.n-level { height: 100%; width: 0; background: #3b4a7a; transition: width .3s; }
.n-thresh { position: absolute; top: 0; bottom: 0; width: 2px; background: #7a6a3b; left: 100%; }
.n-count { font-size: 14px; color: #5a5f74; }
.n-hint { font-size: 13px; color: #6b5a3b; text-align: center; max-width: 320px; }
.n-hint:empty { display: none; }
.n-stop {
  position: relative; overflow: hidden; width: 100%; max-width: 300px; height: 52px; border-radius: 26px;
  border: 1px solid #262936; color: #8a8fa5; font-size: 15px; font-weight: 600; touch-action: none;
}
.n-stop-fill { position: absolute; inset: 0; background: #3a2a14; transform: scaleX(0); transform-origin: left; }
.n-stop.holding .n-stop-fill { transform: scaleX(1); transition: transform 1.5s linear; }
.n-stop-label { position: relative; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px); transform: translateX(-50%);
  z-index: 200; max-width: calc(100% - 32px); padding: 11px 16px; border-radius: 12px;
  background: #2a3048; color: var(--text); font-size: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.5);
}
