:root {
  --bg: #f7f1ec; --card: #fffaf6; --ink: #2b2430; --muted: #7d7183; --line: #eadfd6;
  --accent: #c8695a; --accent-ink: #fff; --soft: #f1e5dc;
  --wave: #4f86a8; --sleep: #6c7fd1; --feed: #d9779b; --kick: #d99a33; --ec: #3a9e83; --miss: #b86b4b;
  --danger: #b83a2e; --ok: #3a9e63; --warn: #d99a33;
  --r: 18px; --shadow: 0 1px 2px rgba(60,30,20,.06), 0 4px 14px rgba(60,30,20,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17151c; --card: #221f29; --ink: #efe9f2; --muted: #a49cab; --line: #34303d;
    --accent: #e48a78; --accent-ink: #1b1418; --soft: #2c2833;
    --wave: #6fa9cc; --sleep: #8b9bf0; --feed: #ef93b4; --kick: #f0b860; --ec: #5cc4a6; --miss: #d48a66;
    --danger: #ff7b6b; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17151c; --card: #221f29; --ink: #efe9f2; --muted: #a49cab; --line: #34303d;
  --accent: #e48a78; --accent-ink: #1b1418; --soft: #2c2833;
  --wave: #6fa9cc; --sleep: #8b9bf0; --feed: #ef93b4; --kick: #f0b860; --ec: #5cc4a6; --miss: #d48a66;
  --danger: #ff7b6b; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
  overscroll-behavior-y: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
h1, h2 { margin: 0; }
h2 { font-size: 1rem; font-weight: 650; }
.muted { color: var(--muted); font-size: .88rem; }
.em { font-size: 1.4em; line-height: 1; }

/* Kopfzeile */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 6px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { flex: 1; min-width: 0; }
.brand h1 { font-size: 1.25rem; letter-spacing: .02em; }
.sub { color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 1.25rem; }
.icon-btn:active { background: var(--soft); }
.dot { width: 11px; height: 11px; border-radius: 50%; background: var(--muted); display: block; }
.dot.ok { background: var(--ok); } .dot.syncing { background: var(--warn); } .dot.offline { background: var(--danger); }

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

/* Untere Navigation */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabs button { display: grid; justify-items: center; gap: 2px; padding: 6px 0; border-radius: 12px; font-size: .72rem; color: var(--muted); }
.tabs button .em { font-size: 1.3rem; filter: grayscale(.7); opacity: .7; }
.tabs button.on { color: var(--ink); font-weight: 600; }
.tabs button.on .em { filter: none; opacity: 1; }

/* Karten & Kacheln */
.card { background: var(--card); border-radius: var(--r); padding: 14px; box-shadow: var(--shadow); border: 1px solid var(--line); display: grid; gap: 10px; }
.card-h { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.link { color: var(--accent); font-size: .88rem; font-weight: 600; }
.hint { background: var(--soft); border-radius: 14px; padding: 10px 12px; font-size: .88rem; color: var(--muted); cursor: pointer; }

.big {
  width: 100%; min-height: 96px; border-radius: 22px; display: grid; justify-items: center; align-content: center; gap: 3px;
  background: var(--accent); color: var(--accent-ink); font-size: 1.2rem; font-weight: 650; box-shadow: var(--shadow);
  transition: transform .08s;
}
.big:active, .tile:active, .qk:active, .chip:active { transform: scale(.97); }
.big small { font-size: .82rem; font-weight: 500; opacity: .85; }
.big.wave { background: var(--wave); color: #fff; }
.big.sleep { background: var(--sleep); color: #fff; }
.big.stop { background: var(--ink); color: var(--bg); min-height: 64px; }

.grid2, .grid3, .grid4 { display: grid; gap: 8px; }
.grid2 { grid-template-columns: repeat(2, 1fr); }
.grid3 { grid-template-columns: repeat(3, 1fr); }
.grid4 { grid-template-columns: repeat(4, 1fr); }
.tile, .qk {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px 6px;
  display: grid; justify-items: center; gap: 4px; font-size: .85rem; font-weight: 550; box-shadow: var(--shadow); min-height: 72px; align-content: center;
}
.qk.miss { border-color: color-mix(in srgb, var(--miss) 45%, var(--line)); }
.qk.hit { border-color: color-mix(in srgb, var(--ec) 45%, var(--line)); }
.side { position: relative; background: var(--feed); color: #fff; border: 0; font-size: 1.05rem; min-height: 84px; }
.side .badge { position: absolute; top: 6px; right: 8px; font-size: .66rem; background: rgba(255,255,255,.28); padding: 2px 7px; border-radius: 99px; }
.side.other { opacity: .72; }
.sub-h { font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

.timer-card { border-radius: 22px; padding: 16px; display: grid; gap: 10px; color: #fff; box-shadow: var(--shadow); }
.timer-card.contraction { background: var(--wave); }
.timer-card.feed { background: var(--feed); }
.timer-card.sleep { background: var(--sleep); }
.timer-card .lbl { font-weight: 600; opacity: .9; }
.clock { font-size: 3rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .02em; line-height: 1; }
.timer-card .btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.timer-card .btns button, .timer-card > button { background: rgba(255,255,255,.22); color: #fff; border-radius: 14px; min-height: 52px; font-weight: 650; }
.timer-card .btns button.solid, .timer-card > button.solid { background: #fff; color: #222; }
.since { font-size: .9rem; color: var(--muted); text-align: center; }
.since b { font-variant-numeric: tabular-nums; color: var(--ink); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--soft); border-radius: 14px; padding: 10px; display: grid; gap: 2px; }
.stat b { font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: .75rem; color: var(--muted); }

/* Balken */
.bars { display: grid; gap: 5px; }
.bar-row { display: grid; grid-template-columns: 74px 1fr 56px; gap: 8px; align-items: center; font-size: .82rem; }
.bar-row .track { height: 12px; background: var(--soft); border-radius: 99px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--accent); border-radius: 99px; }
.bar-row .val { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
button.bar-row { width: 100%; text-align: left; padding: 3px 0; border-radius: 8px; }
button.bar-row:active { background: var(--soft); }
.bar-row.zero .val { color: var(--warn); font-weight: 650; }
.bar-row.zero span:first-child { color: var(--warn); }
.warn {
  background: color-mix(in srgb, var(--warn) 16%, var(--card)); border: 1px solid color-mix(in srgb, var(--warn) 45%, var(--line));
  border-radius: 14px; padding: 10px 12px; font-size: .88rem;
}
.hours { display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px; align-items: end; height: 90px; }
.hours i { background: var(--kick); border-radius: 3px 3px 0 0; min-height: 2px; display: block; }
.hours-axis { display: grid; grid-template-columns: repeat(4, 1fr); font-size: .7rem; color: var(--muted); }

/* Listen */
.rows { display: grid; }
.row { display: grid; grid-template-columns: 34px 1fr auto; gap: 8px; align-items: start; text-align: left; padding: 9px 2px; border-top: 1px solid var(--line); }
.rows .row:first-child { border-top: 0; }
.row .rt { min-width: 0; font-size: .92rem; }
.row .note { display: block; color: var(--muted); font-size: .82rem; font-style: italic; overflow-wrap: anywhere; }
.row .rm { display: grid; justify-items: end; font-size: .82rem; font-variant-numeric: tabular-nums; }
.who { font-size: .7rem; color: var(--muted); }
.day-h { font-size: .8rem; font-weight: 650; color: var(--muted); padding: 10px 2px 2px; text-transform: uppercase; letter-spacing: .05em; }
.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; font-variant-numeric: tabular-nums; }
.tbl th { text-align: left; color: var(--muted); font-weight: 550; font-size: .75rem; padding: 4px 4px; }
.tbl td { padding: 7px 4px; border-top: 1px solid var(--line); }
.tbl tr[data-act] { cursor: pointer; }
.lvl { display: inline-block; min-width: 26px; text-align: center; border-radius: 8px; padding: 1px 4px; background: var(--soft); }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 7px 12px; font-size: .88rem; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip .sw { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.scale { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.scale button { aspect-ratio: 1; border-radius: 10px; background: var(--soft); font-weight: 650; font-variant-numeric: tabular-nums; min-height: 32px; }
.scale button.on { background: var(--accent); color: var(--accent-ink); }

/* Rhythmus */
.strips { display: grid; gap: 4px; }
.strip { display: grid; grid-template-columns: 64px 1fr; gap: 8px; align-items: center; font-size: .78rem; }
.lane {
  position: relative; height: 26px; border-radius: 6px; background: var(--soft); overflow: hidden;
  background-image: linear-gradient(to right, var(--line) 1px, transparent 1px); background-size: 25% 100%;
}
.lane.solo { height: 34px; }
.lane.solo .pt.kick { top: 6px; height: 22px; width: 3px; margin-left: -1.5px; }
.seg { position: absolute; top: 3px; bottom: 3px; border-radius: 3px; display: block; }
.seg.sleep { background: var(--sleep); }
.seg.feed { background: var(--feed); top: 7px; bottom: 7px; }
.seg.contraction { background: var(--wave); }
.pt { position: absolute; width: 4px; margin-left: -2px; border-radius: 2px; display: block; }
.pt.kick { background: var(--kick); top: 2px; height: 8px; }
.pt.ec { background: var(--ec); bottom: 2px; height: 8px; }
.pt.miss { background: var(--miss); bottom: 2px; height: 8px; }
.axis { display: grid; grid-template-columns: 64px 1fr; gap: 8px; font-size: .7rem; color: var(--muted); }
.axis div { display: flex; justify-content: space-between; }

/* Sheet */
#sheet { position: fixed; inset: 0; z-index: 20; }
.sheet-bg { position: absolute; inset: 0; background: rgba(10,6,12,.45); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; overflow: auto; margin: 0 auto; max-width: 560px;
  background: var(--card); border-radius: 22px 22px 0 0; padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  display: grid; gap: 14px; animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: .4; } }
.sheet-h { display: flex; align-items: center; gap: 10px; }
.sheet-h h2 { flex: 1; font-size: 1.1rem; }
.x { width: 36px; height: 36px; border-radius: 50%; background: var(--soft); }
.field { display: grid; gap: 6px; }
.fl { font-size: .8rem; font-weight: 600; color: var(--muted); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
input:not([type=file]), textarea {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 10px 12px; min-height: 44px;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.actions { display: flex; gap: 8px; }
.primary, .danger, .ghost, .btn {
  flex: 1; min-height: 50px; border-radius: 14px; font-weight: 650; display: grid; place-items: center; cursor: pointer;
}
.primary { background: var(--accent); color: var(--accent-ink); }
.danger { background: none; color: var(--danger); border: 1px solid var(--line); flex: 0 0 auto; padding: 0 16px; }
.ghost, .btn { background: var(--soft); }
.err { color: var(--danger); font-size: .88rem; min-height: 1em; margin: 0; }

/* Toast */
#toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(92px + env(safe-area-inset-bottom)); z-index: 30; margin: 0 auto; max-width: 528px;
  background: var(--ink); color: var(--bg); border-radius: 14px; padding: 10px 10px 10px 14px; display: flex; align-items: center; gap: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
#toast[hidden] { display: none; }
#toast span { flex: 1; }
#toast button { color: var(--accent); font-weight: 700; padding: 6px 8px; }

.login { margin-top: 10vh; }
.login form { display: grid; gap: 12px; }
.disclaimer { font-size: .78rem; color: var(--muted); text-align: center; padding: 0 8px; }
[hidden] { display: none !important; }
