:root {
  --bg: #0a0a0b;
  --surface: #121216;
  --fg: #e8e8ee;
  --dim: #6b6b78;
  --dimmer: #26262e;
  --line: #1c1c22;
  --accent: #8b5cf6;
  --accent-bright: #a78bfa;
  --accent-deep: #6d28d9;
  --accent-glow: #c4b5fd;
  --accent-soft: rgba(139, 92, 246, 0.12);
  --warn: #ef4444;
  --mono: ui-monospace, "SF Mono", "IBM Plex Mono", Menlo, Consolas, monospace;
  --pad: 18px;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overscroll-behavior-y: none;
}

::selection { background: var(--accent); color: var(--bg); }
a { color: inherit; text-decoration: none; }
.dim { color: var(--dim); }
.small { font-size: 12px; }

/* ---------- Header ---------- */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px var(--pad);
  margin-top: calc(-1 * env(safe-area-inset-top));
  padding-top: calc(14px + env(safe-area-inset-top));
  background: linear-gradient(to bottom, var(--bg) 70%, rgba(10, 10, 11, 0));
}
.brand { font-weight: 600; font-size: 17px; letter-spacing: 0.01em; }
.cursor { color: var(--accent); animation: blink 1.1s steps(2) infinite; margin-left: 1px; }
@keyframes blink { 50% { opacity: 0; } }
.back { font-size: 26px; line-height: 1; color: var(--dim); padding: 0 6px 2px 0; }
.back:active { color: var(--accent); }

.sync {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-size: 12px;
  color: var(--dim);
  background: none;
  border: 0;
  padding: 6px 0 6px 8px;
}
.sync i { width: 7px; height: 7px; border-radius: 1px; background: var(--dimmer); }
.sync.ok i { background: var(--accent); }
.sync.syncing i { background: var(--accent-bright); animation: blink 0.8s steps(2) infinite; }
.sync.offline i { background: var(--dim); }
.sync.auth, .sync.error { color: var(--warn); }
.sync.auth i, .sync.error i { background: var(--warn); }

.view { padding: 4px var(--pad) 48px; max-width: 560px; margin: 0 auto; }
section { margin-bottom: 28px; }
.section-title { color: var(--dim); font-size: 12px; text-transform: lowercase; letter-spacing: 0.04em; margin: 0 0 10px; }
.row { display: flex; gap: 8px; align-items: center; }
.empty, .hint { color: var(--dim); font-size: 13px; }
.hint:empty { display: none; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  font: inherit;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--dimmer);
  border-radius: var(--radius);
  padding: 12px 16px;
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0a0a0b; font-weight: 600; }
.btn.primary:active { background: var(--accent-deep); }
.btn.big { width: 100%; min-height: 76px; font-size: 18px; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 13px; }
.btn.ghost { background: none; border-color: transparent; color: var(--dim); }
.btn.danger { color: var(--warn); border-color: rgba(239, 68, 68, 0.3); background: none; }
.btn.icon { min-height: 44px; width: 44px; padding: 0; font-size: 20px; color: var(--dim); background: none; }
.hero-action { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.hero-action .ghost { align-self: center; }

/* ---------- Hub ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 14px;
  min-height: 108px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.tile:first-child { grid-column: 1 / -1; min-height: 120px; }
.tile:active { border-color: var(--accent); }
.tile-name { font-weight: 600; font-size: 17px; }
.tile-sub { color: var(--dim); font-size: 12px; }
.tile.hot { border-color: var(--accent); background: linear-gradient(135deg, var(--accent-soft), var(--surface)); }
.tile.hot .tile-sub { color: var(--accent-glow); }
.tile.soon { opacity: 0.35; }

/* ---------- Laufende Attacke ---------- */
.ongoing {
  border: 1px solid var(--accent);
  background: linear-gradient(135deg, var(--accent-soft), var(--surface));
  border-radius: var(--radius);
  padding: 18px;
}
.ongoing-label { color: var(--accent-glow); font-size: 12px; display: flex; align-items: center; gap: 8px; }
.pulse { width: 8px; height: 8px; background: var(--accent); border-radius: 1px; animation: blink 1.1s steps(2) infinite; }
.ongoing-time { font-size: 34px; font-weight: 600; margin: 6px 0 2px; }
.ongoing-sub { color: var(--dim); font-size: 13px; margin-bottom: 14px; }
.ongoing .row > * { flex: 1; }

/* ---------- Statistik ---------- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.stat { background: var(--bg); padding: 12px 14px; }
.stat-value { font-size: 24px; font-weight: 600; }
.stat-label { color: var(--dim); font-size: 11px; }
.stat.warn .stat-value { color: var(--warn); }
.note { font-size: 12px; margin: 10px 0 0; }
.note.warn { color: #fca5a5; }

/* ---------- Heatmap (Game-of-Life-Zellen) ---------- */
.heat-grid { display: grid; grid-template-columns: repeat(13, 1fr); grid-template-rows: repeat(7, 1fr); gap: 3px; }
.heat-grid i, .heat-legend i { display: block; aspect-ratio: 1; background: var(--surface); border-radius: 2px; }
.heat-grid i.f { background: transparent; }
.l1 { background: rgba(139, 92, 246, 0.3) !important; }
.l2 { background: rgba(139, 92, 246, 0.55) !important; }
.l3 { background: var(--accent) !important; }
.l4 { background: var(--accent-glow) !important; box-shadow: 0 0 8px rgba(196, 181, 253, 0.5); }
.heat-legend { display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin-top: 8px; font-size: 11px; color: var(--dim); }
.heat-legend i { width: 10px; }
.heat-legend span { margin: 0 4px; }

/* ---------- Verlauf ---------- */
.entries { list-style: none; margin: 0 0 22px; padding: 0; border-top: 1px solid var(--line); }
.entry { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.entry:active { background: var(--accent-soft); }
.entry-when { font-size: 14px; }
.entry-bar { grid-row: span 2; align-self: center; display: flex; align-items: center; gap: 8px; font-size: 12px; }
.entry-meta { font-size: 12px; color: var(--fg); }
.ibar { display: inline-grid; grid-template-columns: repeat(10, 5px); gap: 2px; }
.ibar i { height: 12px; background: var(--dimmer); border-radius: 1px; }
.ibar i.on { background: var(--accent); }
.ival { width: 18px; text-align: right; color: var(--dim); }

/* ---------- Formular ---------- */
.edit section { margin-bottom: 26px; }
.intensity { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.intensity button {
  font: inherit;
  font-size: 18px;
  font-weight: 600;
  height: 54px;
  border-radius: 8px;
  border: 1px solid var(--dimmer);
  background: var(--surface);
  color: var(--fg);
}
.intensity button.sel { background: var(--accent); border-color: var(--accent); color: var(--bg); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip {
  font: inherit;
  font-size: 13px;
  padding: 8px 12px;
  min-height: 38px;
  border-radius: 999px;
  border: 1px solid var(--dimmer);
  background: none;
  color: var(--fg);
}
.chip.sel { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-glow); }
.chip.add { color: var(--dim); border-style: dashed; }

label { display: block; color: var(--dim); font-size: 12px; margin-bottom: 12px; }
input, textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  font: inherit;
  font-size: 16px; /* verhindert Zoom auf iOS */
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--dimmer);
  border-radius: 8px;
  padding: 10px 12px;
  min-height: 46px;
}
.row input { margin-top: 0; }
input:focus, textarea:focus { outline: none; border-color: var(--accent); }
input[type="datetime-local"] { -webkit-appearance: none; appearance: none; }
textarea { resize: vertical; }
.times .row input { flex: 1; min-width: 0; }

.meds { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.med { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.med input { flex: 1; min-width: 0; }
.med input.dose { flex: 0 0 92px; }

.edit-footer { display: flex; justify-content: space-between; align-items: center; }
.saved { font-size: 12px; }

/* ---------- Helfer ---------- */
.grow { flex: 1; }
.btn.full { width: 100%; }
.row.wrap { flex-wrap: wrap; }

.toggle {
  font: inherit;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 14px 8px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--dimmer);
  background: none;
  color: var(--fg);
  margin-bottom: 12px;
}
.toggle i { width: 18px; height: 18px; border-radius: 4px; border: 1.5px solid var(--dim); display: grid; place-items: center; }
.toggle.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-glow); }
.toggle.on i { background: var(--accent); border-color: var(--accent); }
.toggle.on i::after { content: "✓"; color: var(--bg); font-size: 12px; font-style: normal; font-weight: 700; }

/* ---------- Heute-Karte ---------- */
.today-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: -6px; }
.card-head .section-title { margin: 0; }
.more { color: var(--dim); font-size: 12px; padding: 4px 0 4px 12px; }
.water-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; color: var(--dim); }
.water-val b { color: var(--fg); font-size: 20px; font-weight: 600; }
.water-bar { height: 8px; background: var(--dimmer); border-radius: 2px; margin: 8px 0 10px; overflow: hidden; }
.water-bar i { display: block; height: 100%; background: var(--accent); transition: width 0.2s; }
.water-bar.done i { background: var(--accent-glow); box-shadow: 0 0 8px rgba(196, 181, 253, 0.6); }
.supps { display: flex; flex-wrap: wrap; gap: 8px; }
.supps .toggle { margin: 0; flex: 1; min-width: 140px; }
.sleep { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--dim); }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper .btn { width: 44px; padding: 0; }
.sleep-val { min-width: 52px; text-align: center; color: var(--dim); }
.sleep-val b { color: var(--fg); font-size: 18px; }
.view > .today-card { margin-bottom: 16px; }

.daynav { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.daynav .btn { width: 44px; padding: 0; }

/* ---------- Laufende Attacke: Medikamente ---------- */
.ongoing { display: flex; flex-direction: column; gap: 10px; }
.ongoing-sub { margin-bottom: 4px; }
.ongoing-meds { color: var(--accent-glow); font-size: 13px; }
.ongoing .row > * { flex: 1; }
.details-link { color: var(--dim); font-size: 12px; align-self: flex-end; padding: 4px 0; }

/* ---------- Muster ---------- */
.ins-row { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.ins-row > span:first-child { color: var(--dim); }
.ins-row b { font-weight: 600; }

/* ---------- Mahlzeiten, Bewegung, Garmin ---------- */
.meals .label, .move-head { font-size: 13px; color: var(--dim); }
.meal-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 8px; }
.toggle.meal { margin: 0; padding: 8px 4px; font-size: 13px; gap: 2px; justify-content: center; flex-direction: column; min-height: 52px; }
.toggle.meal i { display: none; }
.toggle.meal .dim { font-size: 11px; }
.move-head { display: flex; justify-content: space-between; margin-bottom: 8px; }
.move-head b { color: var(--fg); }
.move-head b.goal { color: var(--accent-glow); }
.move .toggle { margin: 0; min-height: 38px; }
.chip.static { display: inline-flex; align-items: center; cursor: default; }
.sleep-val .src { margin-left: 8px; font-size: 10px; color: var(--accent-bright); border: 1px solid var(--accent-deep); border-radius: 3px; padding: 1px 4px; vertical-align: middle; }
.section-title.sub { margin-top: 18px; }

/* ---------- Eigene Schlafbewertung ---------- */
.sleep-block { display: flex; flex-direction: column; gap: 10px; }
.srate-row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--dim); }
.srate { display: grid; grid-template-columns: repeat(5, 40px); gap: 5px; }
.srate button { font: inherit; font-size: 15px; font-weight: 600; height: 40px; border-radius: 8px; border: 1px solid var(--dimmer); background: none; color: var(--fg); }
.srate button.sel { background: var(--accent); border-color: var(--accent); color: var(--bg); }
