:root {
  --bg: #0c1018;
  --bg-soft: #131826;
  --card: #1a2030;
  --line: #232a3c;
  --text: #e3e8f0;
  --muted: #8694ad;
  --accent: #6aa3c8;
  --accent-glow: rgba(106,163,200,0.25);
  --good: #5fa777;
  --warn: #d4a843;
  --bad: #d65d5d;
  --radius: 18px;
  --radius-sm: 12px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
}
body.bright {
  --bg: #f4efe9;
  --bg-soft: #ece5da;
  --card: #ffffff;
  --line: #d9d2c5;
  --text: #2d2533;
  --muted: #6a5e6f;
  --accent-glow: rgba(106,163,200,0.18);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.4;
  font-weight: 400;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.3s ease, color 0.3s ease;
}
button { font-family: inherit; font-size: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 16px; color: var(--text); }

#app { min-height: 100vh; display: flex; flex-direction: column; position: relative; z-index: 1; }

/* ============ Onboarding =============== */
.onboarding {
  min-height: 100vh;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding: 0 0 32px;
  position: relative;
}
.onb-hero {
  width: 100%;
  display: flex; justify-content: center; align-items: flex-end;
  padding-top: 320px;
  background: url('/night-bg.svg') center top / 100% auto no-repeat;
  background-position: top;
  min-height: 460px;
  pointer-events: none;
}
.onb-hero img {
  width: min(86vw, 360px);
  height: auto;
  display: block;
  margin-bottom: -20px;
  filter: drop-shadow(0 12px 24px rgba(0,0,0,0.35));
}
.onb-sky {
  display: flex; justify-content: center;
  margin-bottom: -8px;
  filter: drop-shadow(0 12px 28px rgba(0,0,0,0.5));
}
.onb-sky svg { width: min(78vw, 300px); height: auto; display: block; }
.onboarding-inner { max-width: 420px; text-align: center; padding: 0 24px; }
.onboarding h1 { font-size: 30px; margin: 16px 0 12px; font-weight: 600; letter-spacing: -0.02em; }
.onb-sub { color: var(--muted); margin: 0 0 24px; font-size: 16px; }

/* ============ Header =============== */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; padding-bottom: 76px; }
.app-header {
  display: flex; align-items: center; gap: 14px;
  padding: 18px 20px 12px;
  background: linear-gradient(180deg, rgba(12,16,24,0.85) 0%, rgba(12,16,24,0));
  position: sticky; top: 0; z-index: 5;
}
.child-pill {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border: 1px solid var(--line);
  padding: 8px 12px; border-radius: 999px; color: var(--text);
  transition: transform 0.15s ease;
}
.child-pill:active { transform: scale(0.96); }
.child-dot {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: var(--bg); font-weight: 700; font-size: 14px;
}
.child-name { font-weight: 600; }
.caret { color: var(--muted); font-size: 12px; }
.child-meta { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 14px; flex: 1; }
.badge { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: 12px; }
.badge.prem { color: var(--warn); border-color: rgba(212,168,67,0.3); }
.header-nav { display: flex; gap: 6px; }
.iconbtn {
  background: var(--card); border: 1px solid var(--line);
  width: 40px; height: 40px; border-radius: 12px;
  color: var(--text); font-size: 18px;
}
.iconbtn:active { transform: scale(0.94); }

/* ============ Main =============== */
.app-main { flex: 1; padding: 4px 20px 24px; max-width: 720px; margin: 0 auto; width: 100%; }
.tracker-label { font-size: 12px; letter-spacing: 0.16em; color: var(--muted); margin: 12px 0 8px; padding: 0 4px; }

/* ============ Big button =============== */
.big-btn-wrap { padding: 12px 0 16px; }
.big-btn {
  width: 100%;
  aspect-ratio: 1 / 1; max-height: 320px;
  border-radius: 50%;
  border: none;
  background: radial-gradient(circle at 30% 30%, var(--accent), color-mix(in srgb, var(--accent) 60%, #000 30%));
  color: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: 24px;
  box-shadow: 0 16px 36px var(--accent-glow), 0 0 0 1px rgba(255,255,255,0.06) inset;
  transition: transform 0.12s ease, box-shadow 0.2s ease;
  touch-action: manipulation;
}
.big-btn:active { transform: scale(0.97); box-shadow: 0 4px 14px var(--accent-glow); }
.big-btn-title { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.big-btn-since { font-size: 38px; font-weight: 700; letter-spacing: -0.02em; line-height: 1; font-variant-numeric: tabular-nums; }
.big-btn-state { font-size: 13px; opacity: 0.7; text-transform: lowercase; letter-spacing: 0.08em; }

/* ============ Cards =============== */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card-title { font-size: 13px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }
.gauge-card .gauge { margin: 0 -4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; line-height: 1.5; }
.rec-card { border-left: 4px solid var(--accent); padding-left: 14px; }
.rec-text { font-size: 16px; line-height: 1.4; margin: 4px 0 8px; }

/* ============ Quick actions =============== */
.quick-actions { display: flex; gap: 8px; padding: 8px; }
.qa {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: var(--bg-soft); border: 1px solid var(--line);
  color: var(--text); border-radius: var(--radius-sm); padding: 14px 8px;
}
.qa:active { transform: scale(0.96); }
.qa-emoji { font-size: 22px; }

/* ============ Tabs =============== */
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex;
  background: rgba(12,16,24,0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  padding: 6px 6px calc(env(safe-area-inset-bottom, 0px) + 6px);
  z-index: 10;
}
body.bright .tabs { background: rgba(244,239,233,0.94); }
.tab-btn {
  flex: 1; background: transparent; border: none; color: var(--muted);
  padding: 10px 6px; border-radius: var(--radius-sm); font-size: 12px;
}
.tab-btn.on { background: var(--card); color: var(--text); }

/* ============ Modal =============== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 100; animation: fade 0.18s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--bg-soft); width: 100%; max-width: 520px;
  border-radius: 24px 24px 0 0; padding: 24px 20px 28px;
  max-height: 92vh; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.modal.wide { max-width: 600px; }
.modal h2 { margin: 0 0 16px; font-size: 22px; }
.form-grid { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { color: var(--muted); font-size: 13px; letter-spacing: 0.04em; }
.field-raw > .seg { margin-top: 0; }
input[type="text"], input[type="date"], input[type="datetime-local"], select, textarea {
  background: var(--card); border: 1px solid var(--line);
  color: var(--text); border-radius: var(--radius-sm); padding: 12px 14px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
textarea { resize: vertical; font-size: 16px; }
.seg { display: flex; gap: 8px; }
.seg-btn { flex: 1; padding: 10px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); color: var(--text); }
.seg-btn.on { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; min-height: 44px; padding: 10px 4px; cursor: pointer; }
.check input { width: 22px; height: 22px; min-width: 44px; min-height: 44px; accent-color: var(--accent); margin: 0; padding: 10px; box-sizing: border-box; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

/* ============ Buttons =============== */
.btn { padding: 12px 18px; border-radius: var(--radius-sm); border: none; font-weight: 600; }
.btn-primary { background: var(--accent); color: var(--bg); }
.btn-ghost { background: var(--card); color: var(--text); border: 1px solid var(--line); }
.btn-danger { background: var(--bad); color: #fff; }
.btn:active { transform: scale(0.96); }

/* ============ Settings / log / analytics =============== */
.settings-list { display: flex; flex-direction: column; gap: 8px; }
.setting-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px; border-radius: var(--radius-sm); border: 1px solid var(--line);
}
.setting-label { flex: 1; }
.child-row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px; margin-bottom: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); color: var(--text);
}
.child-row.on { border-color: var(--accent); }
.child-row .child-name { flex: 1; }

.log-day { margin-bottom: 16px; }
.log-day-head { font-size: 12px; letter-spacing: 0.12em; color: var(--muted); text-transform: uppercase; padding: 4px 6px; }
.log-entry {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius-sm); margin-bottom: 6px;
}
.log-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }
.log-dot.night { background: #8a7ad9; }
.log-dot.day { background: var(--accent); }
.log-times { flex: 1; }
.log-start { font-weight: 600; }
.log-dur { color: var(--muted); font-size: 13px; }

.chart-block { margin-top: 8px; }
.bar-row { padding: 6px 0; }
.bar-label { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.bar-track { background: var(--bg-soft); border-radius: 8px; height: 14px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 70%, white 30%)); border-radius: 8px; }
.insight-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.insight {
  padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--bg-soft);
}
.insight .label { font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.insight .value { font-size: 18px; font-weight: 700; margin-top: 2px; }

/* ============ Toast =============== */
.toast {
  position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 10px 12px;
  display: flex; align-items: center; gap: 12px; z-index: 50;
  opacity: 0; transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-act { background: transparent; border: 1px solid var(--accent); color: var(--accent); border-radius: 999px; padding: 4px 10px; font-size: 13px; }

@media (min-width: 720px) {
  .big-btn { max-width: 360px; margin: 0 auto; }
  .app-main { padding: 24px 24px 24px; }
  .onb-hero { padding-top: 340px; min-height: 520px; }
}

/* ============ Night-sky background =============== */
body.bg-stars {
  background: url('/night-bg.svg') center top / 100% auto no-repeat fixed,
              radial-gradient(circle at 80% 6%, rgba(253,246,200,0.18), transparent 50%),
              var(--bg);
}
body.bg-stars::before {
  content: "";
  position: fixed; left: 0; right: 0; top: 38%; height: 90%;
  background: linear-gradient(180deg, rgba(7,10,20,0) 0%, rgba(7,10,20,0.55) 35%, rgba(7,10,20,0.92) 100%);
  pointer-events: none;
  z-index: 0;
}
.onboarding { background: transparent; }
