:root {
  --deep: #10122a; --night: #171a36; --raise: #1d2145; --line: #2c3160;
  --ink: #f1ebdd; --soft: #a9aecf; --cry: #ff9d8a; --move: #8fb4ff;
  --asleep: #4d5bd1; --awake: #b7a6ea; --out: #3b4170; --dusk: #4a3a6e; --dawn: #6b5a86; --ok: #6fd39a;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --tabbar: calc(58px + env(safe-area-inset-bottom));
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { background: var(--deep); -webkit-text-size-adjust: 100%; }
body { margin: 0; color: var(--ink); background: var(--deep); font: 16px/1.5 var(--sans);
       -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--move); outline-offset: 2px; }
.soft { color: var(--soft); }
.msg { min-height: 1.5em; color: var(--soft); font-size: 14px; }
.msg.bad { color: var(--cry); }
h2 { font: 600 15px/1.2 var(--sans); color: var(--soft); margin: 34px 2px 10px; }
h2.first { margin-top: 8px; }

/* ---------- buttons */
.primary { background: var(--ink); color: var(--deep); border: 0; border-radius: 999px; padding: 14px 26px;
           font-weight: 600; font-size: 17px; }
.primary.small { padding: 10px 16px; font-size: 15px; }
.primary:disabled { opacity: .5; }
.ghost { background: none; border: 1px solid var(--line); border-radius: 999px; padding: 10px 18px; }
.round { width: 40px; height: 40px; border-radius: 999px; border: 1px solid var(--line); background: none;
         display: grid; place-items: center; padding: 0; font-size: 20px; line-height: 1; }
.round svg { width: 22px; height: 22px; fill: currentColor; }
.round:disabled { opacity: .3; cursor: default; }
.pill { border-radius: 999px; border: 1px solid rgba(255,255,255,.25); background: rgba(16,18,42,.55);
        padding: 0 14px; height: 40px; font-size: 14px; font-weight: 600; }

/* ---------- sign-in gate */
.gate { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center;
        justify-content: center; text-align: center; padding: 32px 24px calc(32px + env(safe-area-inset-bottom));
        background: radial-gradient(120% 70% at 50% 0%, #2a2558 0%, var(--deep) 62%); }
.gate h1 { font: 400 40px/1.1 var(--serif); margin: 22px 0 10px; }
.gate p { max-width: 30em; margin: 0 0 22px; }
.moon { width: 76px; height: 76px; border-radius: 50%; box-shadow: inset -16px -6px 0 0 var(--ink);
        transform: rotate(-20deg); }
.a2hs { text-align: left; max-width: 26em; margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
.a2hs ol { padding-left: 1.3em; margin: 6px 0 0; }
.a2hs li { margin: 4px 0; }

/* ---------- layout */
main { padding: calc(env(safe-area-inset-top) + 12px) 16px calc(var(--tabbar) + 24px); max-width: 720px;
       margin: 0 auto; }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; height: var(--tabbar); display: flex;
        background: rgba(16,18,42,.92); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
        border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
          color: var(--soft); text-decoration: none; font-size: 11px; font-weight: 600; }
.tabs a svg { width: 25px; height: 25px; }
.tabs a.on { color: var(--ink); }

/* ---------- live */
.stage { position: relative; margin: 0 -16px; background: #000; aspect-ratio: 16 / 9; overflow: hidden; }
@media (min-width: 560px) { .stage { margin: 0; border-radius: 16px; } }
.stage video, .stage img { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.stage img { position: absolute; inset: 0; }
.stage-top { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; gap: 8px; }
.stage-bottom { position: absolute; bottom: 10px; left: 10px; right: 10px; display: flex; gap: 8px;
                justify-content: flex-end; }
.stage-bottom .round { background: rgba(16,18,42,.55); border-color: rgba(255,255,255,.25); }
.stage-bottom #sound { margin-right: auto; }
.stage-msg { position: absolute; inset: auto 16px 56px; margin: 0; text-align: center; font-size: 14px;
             background: rgba(16,18,42,.75); border-radius: 10px; padding: 8px 12px; }
.chip { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px 6px 10px; border-radius: 999px;
        background: rgba(16,18,42,.6); font-size: 14px; font-weight: 600; backdrop-filter: blur(6px);
        -webkit-backdrop-filter: blur(6px); }
.chip::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--soft); }
.chip.quiet::before { background: var(--ok); }
.chip.crying { background: var(--cry); color: #3a1410; }
.chip.crying::before { background: #3a1410; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .chip.crying::before { animation: none; } }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 1px; margin: 16px 0 0;
         background: var(--line); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.fact { background: var(--night); padding: 12px 14px; display: flex; flex-direction: column; }
.fact-label { color: var(--soft); font-size: 13px; }
.fact-value { font: 400 21px/1.25 var(--serif); }
.controls { margin-top: 16px; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.control { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px;
           background: var(--night); border-top: 1px solid var(--line); }
.control:first-child { border-top: 0; }
.switch { width: 52px; height: 32px; border-radius: 999px; border: 0; background: var(--line); position: relative; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%;
                 background: var(--ink); transition: transform .15s; }
.switch[aria-checked="true"] { background: var(--asleep); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }
.switch:disabled { opacity: .4; }
.tonight { display: flex; flex-direction: column; gap: 2px; margin-top: 16px; padding: 14px; border-radius: 14px;
           background: var(--night); border: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.tonight span:last-child { font: 400 19px/1.3 var(--serif); }

/* ---------- sleep */
.sleep-head { display: grid; grid-template-columns: 40px 1fr 40px; align-items: center; gap: 8px; }
.sleep-head p { margin: 0; text-align: center; font-size: 14px; }
.story { font: 400 clamp(25px, 6.6vw, 36px)/1.22 var(--serif); margin: 20px 2px 22px; min-height: 2.44em; }
#strip { width: 100%; height: 132px; display: block; border-radius: 14px; }
.hours { position: relative; height: 18px; margin-top: 6px; color: var(--soft); font-size: 12px; }
.hours span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.hours span:first-child { transform: none; }
.hours span:last-child { transform: translateX(-100%); }
.key { display: flex; gap: 14px; color: var(--soft); font-size: 13px; margin: 10px 2px 0; flex-wrap: wrap; }
.key i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.k-asleep { background: var(--asleep); } .k-awake { background: var(--awake); }
.k-cry { background: var(--cry); } .k-out { background: var(--out); }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin-top: 22px; background: var(--line);
           border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.metric { background: var(--night); padding: 12px; }
.metric b { display: block; font: 400 22px/1.2 var(--serif); }
.metric span { color: var(--soft); font-size: 12.5px; }
table.list { width: 100%; border-collapse: collapse; }
table.list td { padding: 11px 2px; border-top: 1px solid var(--line); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 1px solid var(--line); }
td.t { font: 400 19px/1.2 var(--serif); white-space: nowrap; width: 5.6em; }
td.d { color: var(--soft); font-size: 14px; }
td.r { text-align: right; white-space: nowrap; }
td.none { color: var(--soft); }
.thumb { width: 72px; height: 41px; object-fit: cover; border-radius: 6px; display: block; background: #000; }
.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; margin-left: 6px;
       background: var(--raise); color: var(--soft); }
.tag.cry { background: rgba(255,157,138,.18); color: var(--cry); }
.trend { display: grid; grid-template-columns: repeat(14, 1fr); gap: 4px; height: 118px; }
.bar { background: none; border: 0; padding: 0; display: flex; flex-direction: column; justify-content: flex-end;
       border-radius: 6px; }
.bar b { display: block; background: var(--asleep); border-radius: 4px 4px 0 0; opacity: .55; }
.bar.on b { opacity: 1; }
.bar.nodata b { background: var(--line); opacity: 1; }
.bar span { color: var(--soft); font-size: 11px; text-align: center; margin-top: 5px; }
.bar.on span { color: var(--ink); font-weight: 600; }
.how { margin-top: 30px; color: var(--soft); font-size: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.how summary { cursor: pointer; color: var(--ink); }

/* ---------- family */
.card { background: var(--night); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.card p { margin: 0 0 12px; }
.prefs { display: flex; flex-direction: column; gap: 2px; margin: 4px 0 14px; }
.pref { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; }
.pref small { display: block; color: var(--soft); }
.row { display: flex; gap: 8px; }
.invite { margin-top: 14px; }
.invite label { display: block; margin-bottom: 8px; }
.invite input:not([type]) { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
                            background: var(--deep); color: var(--ink); font: inherit; }
.check { display: flex !important; align-items: center; gap: 8px; margin-top: 12px; color: var(--soft); font-size: 14px; }
.actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.ghost.small { padding: 8px 14px; font-size: 15px; }
tr.new td { background: rgba(77, 91, 209, .22); transition: background 2s; }
.linkbox { word-break: break-all; font-size: 13px; color: var(--ink); background: var(--deep); padding: 8px 10px;
           border-radius: 8px; margin: 8px 0; }
.health { font-size: 13px; margin-top: 28px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--ok); }
.dot.off { background: var(--cry); }

/* ---------- listen mode */
.listen-btn { display: flex; align-items: center; gap: 12px; width: 100%; margin-top: 16px; padding: 12px 14px;
              text-align: left; background: var(--night); border: 1px solid var(--line); border-radius: 14px; }
.listen-btn svg { width: 28px; height: 28px; flex: none; }
.listen-btn b { display: block; font-weight: 600; }
.listen-btn small { color: var(--soft); font-size: 13px; }
.listen-btn.on { border-color: var(--asleep); background: rgba(77, 91, 209, .18); }
.listen-bar { position: fixed; left: 12px; right: 12px; bottom: calc(var(--tabbar) + 10px); z-index: 6;
              display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 14px; border-radius: 14px;
              background: var(--asleep); color: #fff; box-shadow: 0 6px 24px rgba(0, 0, 0, .35); }
.listen-bar span:nth-child(2) { flex: 1; font-size: 15px; font-weight: 600; }
.listen-bar .ghost { border-color: rgba(255, 255, 255, .5); color: #fff; }
.listen-bar.trouble { background: #7a4b5c; }
.eq { display: flex; align-items: flex-end; gap: 2px; height: 16px; }
.eq i { width: 3px; background: #fff; border-radius: 1px; animation: eq 1s ease-in-out infinite; }
.eq i:nth-child(2) { animation-delay: .2s; } .eq i:nth-child(3) { animation-delay: .4s; }
@keyframes eq { 0%, 100% { height: 4px; } 50% { height: 16px; } }
@media (prefers-reduced-motion: reduce) { .eq i { animation: none; height: 10px; } }
body.listening main { padding-bottom: calc(var(--tabbar) + 90px); }

/* ---------- unanswered-crying light */
.field { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; }
.field select { background: var(--deep); color: var(--ink); border: 1px solid var(--line); border-radius: 10px;
                padding: 8px 10px; font: inherit; max-width: 60%; }
.field select:disabled { opacity: .5; }
.explain { color: var(--soft); font-size: 14px; margin: 10px 0 0 !important; }
