/* Napper — dunkel, warm, einhändig bedienbar.
   Die App wird nachts benutzt, mit einem Kind auf dem Arm. Deshalb:
   kein Weiß, keine kalten Blautöne in großen Flächen, große Tippziele
   im unteren Bildschirmdrittel, und ein Nachtlicht-Modus, der alles auf
   Bernstein herunterdimmt. */

:root {
  --bg:        #0f0d18;
  --bg-soft:   #161327;
  --card:      #1c1830;
  --card-hi:   #241f3c;
  --line:      #2f2949;
  --text:      #f2eeff;
  --muted:     #948eb4;
  --glow:      #221b3d;
  --accent:    #f0a868;
  --accent-dk: #c9823f;
  --violet:    #8b7ae8;
  --night:     #5468d8;
  --nap:       #8b7ae8;
  --feed:      #5cc3a0;
  --diaper:    #d99a5c;
  --danger:    #e2686d;

  --radius: 18px;
  --radius-lg: 26px;
  --pad: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, Roboto,
          'Helvetica Neue', Arial, sans-serif;
}

/* Nachtlicht: Bildschirm wird zur Funzel. Alles Bernstein, nichts leuchtet
   stärker als nötig — blaues Licht um drei Uhr nachts weckt beide. */
body[data-night='1'] {
  --bg: #0a0806;
  --bg-soft: #100c08;
  --card: #17110b;
  --card-hi: #1e160d;
  --line: #2a1f13;
  --glow: #1b1108;
  --text: #f0c896;
  --muted: #9c7648;
  --accent: #e09550;
  --violet: #c08a52;
  --night: #b07a44;
  --nap: #c08a52;
  --feed: #b08850;
  --diaper: #a87c48;
  filter: brightness(0.72);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(1000px 520px at 50% -8%, var(--glow) 0%, transparent 62%),
    var(--bg);
}

button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.02em; }
p { margin: 0; }
.muted { color: var(--muted); font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.5; }
.error { color: var(--danger); font-size: 14px; text-align: center; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ Buttons --- */
.btn {
  border: 0;
  border-radius: 14px;
  padding: 15px 18px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
}
.btn:active { transform: scale(0.975); }
.btn-primary { background: var(--accent); color: #241403; }
.btn-ghost { background: var(--card-hi); color: var(--text); }
.btn-quiet { background: transparent; color: var(--muted); }
.btn-stop { background: var(--card-hi); color: var(--accent); padding: 11px 18px; }

.icon-btn {
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--muted);
  width: 42px; height: 42px;
  border-radius: 50%;
  font-size: 19px;
  cursor: pointer;
}
body[data-night='1'] .icon-btn { color: var(--accent); border-color: var(--accent-dk); }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .btn { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span:first-child { font-size: 13px; color: var(--muted); }
.field input, .field select {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px 14px;
  outline: none;
  width: 100%;
}
.field input:focus, .field select:focus { border-color: var(--violet); }

/* -------------------------------------------------------- Einrichtung --- */
.setup {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(var(--safe-t) + 28px) 22px calc(var(--safe-b) + 28px);
}
.setup-inner { width: 100%; max-width: 380px; }
.brand { text-align: center; margin-bottom: 34px; }
.brand h1 { font-size: 34px; margin-top: 14px; }
.brand-sub { color: var(--muted); margin-top: 6px; font-size: 15px; }
.brand-moon {
  width: 76px; height: 76px;
  margin: 0 auto;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 32%, #ffd9a8, #f0a868 46%, #b9713a 100%);
  box-shadow: 0 0 46px rgba(240, 168, 104, 0.34), inset -10px -8px 22px rgba(90, 42, 8, 0.5);
  position: relative;
}
.brand-moon::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 74% 26%, var(--bg) 30%, transparent 31%);
}

/* --------------------------------------------------------------- App ---- */
.screen {
  padding: calc(var(--safe-t) + 14px) var(--pad) calc(96px + var(--safe-b));
  max-width: 620px;
  margin: 0 auto;
  animation: fade 0.22s ease;
}
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}
.topbar h2 { font-size: 22px; }

/* ------------------------------------------------------- Status-Ring ---- */
.status-card { position: relative; width: min(74vw, 268px); margin: 6px auto 4px; aspect-ratio: 1; }
.ring { position: absolute; inset: 0; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 10; stroke-linecap: round; }
.ring-track { stroke: var(--card); }
.ring-fill {
  stroke: var(--accent);
  stroke-dasharray: 553;
  stroke-dashoffset: 553;
  transition: stroke-dashoffset 0.6s ease, stroke 0.4s ease;
  filter: drop-shadow(0 0 8px rgba(240, 168, 104, 0.35));
}
.status-card.is-asleep .ring-fill { stroke: var(--night); filter: drop-shadow(0 0 8px rgba(84, 104, 216, 0.4)); }
.status-card.is-overdue .ring-fill { stroke: var(--danger); }

.status-inner {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 3px;
}
.status-label { font-size: 14px; color: var(--muted); }
.status-time {
  font-size: 46px;
  font-weight: 300;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  line-height: 1.05;
}
.status-sub { font-size: 13px; color: var(--muted); }

.prediction {
  text-align: center;
  font-size: 15px;
  color: var(--muted);
  margin: 10px 0 20px;
  line-height: 1.5;
  min-height: 44px;
}
.prediction b { color: var(--text); font-weight: 600; }
.prediction .warn { color: var(--accent); }

/* --------------------------------------------------------- Hauptknopf --- */
.big-btn {
  display: block;
  width: 100%;
  border: 0;
  border-radius: var(--radius-lg);
  padding: 24px;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: #241403;
  background: linear-gradient(165deg, #ffc188, var(--accent) 55%, #d98c47);
  box-shadow: 0 12px 28px rgba(240, 168, 104, 0.2);
  cursor: pointer;
  transition: transform 0.14s ease;
}
.big-btn:active { transform: scale(0.98); }
.big-btn.is-awake {
  color: #eef1ff;
  background: linear-gradient(165deg, #6f83e6, var(--night) 55%, #3c4bad);
  box-shadow: 0 12px 28px rgba(84, 104, 216, 0.22);
}

.quick-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0 26px; }
.quick {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 6px;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.quick span { font-size: 21px; color: var(--feed); }
.quick[data-quick='diaper'] span { color: var(--diaper); }
.quick.is-running { border-color: var(--feed); color: var(--text); }

/* ------------------------------------------------------------ Heute ----- */
.today-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.today-head h3 { font-size: 17px; }
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.tl-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--card);
  border-radius: 14px;
  cursor: pointer;
}
.tl-item:active { background: var(--card-hi); }
.tl-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--nap); }
.tl-dot.night { background: var(--night); }
.tl-dot.breast, .tl-dot.bottle, .tl-dot.solid, .tl-dot.pump { background: var(--feed); }
.tl-dot.diaper { background: var(--diaper); }
.tl-main { flex: 1; min-width: 0; }
.tl-title { font-size: 15px; }
.tl-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.tl-dur { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tl-live { color: var(--accent); }
.tl-empty { color: var(--muted); font-size: 14px; padding: 22px 4px; text-align: center; }

/* ---------------------------------------------------------- Verlauf ----- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 17px;
  margin-bottom: 14px;
}
.card h3 { font-size: 16px; margin-bottom: 12px; }

.stat-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 10px; text-align: center; }
.tile-val { font-size: 21px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile-lbl { font-size: 11.5px; color: var(--muted); margin-top: 4px; line-height: 1.3; }

.chart { display: flex; align-items: flex-end; gap: 5px; height: 148px; margin: 8px 0 12px; }
.bar-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; height: 100%; position: relative; }
.bar { border-radius: 4px 4px 0 0; min-height: 2px; }
.bar.night { background: var(--night); }
.bar.nap { background: var(--nap); border-radius: 4px; }
.bar-lbl { font-size: 9.5px; color: var(--muted); text-align: center; margin-top: 5px; }
.target-line { position: absolute; left: -2px; right: -2px; border-top: 1px dashed var(--accent-dk); opacity: 0.55; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; }
.sw-night { background: var(--night); }
.sw-nap { background: var(--nap); }
.sw-target { background: var(--accent-dk); }

.code-box {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-align: center;
  padding: 16px;
  background: var(--bg-soft);
  border: 1px dashed var(--line);
  border-radius: 14px;
  margin: 12px 0;
  font-variant-numeric: tabular-nums;
}

.switch { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; cursor: pointer; }
.switch input { width: 44px; height: 26px; accent-color: var(--accent); }

.tip { padding: 11px 0; border-bottom: 1px solid var(--line); font-size: 14px; line-height: 1.55; color: var(--muted); }
.tip:last-child { border-bottom: 0; }
.tip b { color: var(--text); font-weight: 600; }

/* --------------------------------------------------------- Tab-Leiste --- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: rgba(15, 13, 24, 0.9);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
  z-index: 20;
}
body[data-night='1'] .tabbar { background: rgba(10, 8, 6, 0.94); }
.tab {
  background: none;
  border: 0;
  color: var(--muted);
  padding: 11px 4px 9px;
  font-size: 10.5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.tab span { font-size: 18px; }
.tab.is-active { color: var(--accent); }

/* -------------------------------------------------------------- Sheet --- */
.sheet-wrap { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.6); animation: fade 0.2s ease; }
.sheet {
  position: relative;
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
  background: var(--bg-soft);
  border-radius: 24px 24px 0 0;
  border-top: 1px solid var(--line);
  padding: 10px var(--pad) calc(var(--pad) + var(--safe-b));
  max-height: 88dvh;
  overflow-y: auto;
  animation: rise 0.26s cubic-bezier(0.2, 0.9, 0.3, 1);
}
@keyframes rise { from { transform: translateY(100%); } }
.sheet-handle { width: 38px; height: 4px; background: var(--line); border-radius: 2px; margin: 4px auto 16px; }
.sheet h3 { font-size: 18px; margin-bottom: 16px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + var(--safe-b));
  transform: translateX(-50%);
  background: var(--card-hi);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 60;
  animation: fade 0.2s ease;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.offline-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--danger);
  margin-right: 6px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
