/* Babyphone — soft, rounded, made for night use.
   Parent side: calm warm-indigo night palette, large type, big rounded targets.
   Baby side: a full-screen sky that changes with the wake-up clock. */

:root {
    --bg:      #1d1b33;
    --card:    #29274a;
    --card-2:  #353260;
    --line:    rgb(255 255 255 / .08);
    --text:    #f7f3ff;
    --text-2:  #cdc6ea;
    --text-3:  #a29cc8;
    --on-accent: #2b1810;

    --peach:   #ffb48c;  /* primary action */
    --mint:    #8fe3c6;  /* all quiet, connected */
    --sun:     #ffd56f;  /* sound, attention */
    --lilac:   #b8a6ff;  /* live, engaged */
    --rose:    #ff8193;  /* alarm, stop */

    --r-s: 14px; --r-m: 20px; --r-l: 28px;
    --tap: 48px;
    --font: ui-rounded, "SF Pro Rounded", "Nunito", "Quicksand", "Varela Round", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --shadow: 0 10px 30px rgb(0 0 0 / .25);
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
    background: var(--bg);
    color: var(--text);
    font: 400 1rem/1.45 var(--font);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
[hidden] { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.1rem; font-weight: 700; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon { width: 20px; height: 20px; flex: none; }
:focus-visible { outline: 3px solid var(--lilac); outline-offset: 3px; }

/* ---------- Buttons ---------- */
button { font: inherit; color: inherit; cursor: pointer; }
.btn {
    min-height: var(--tap); padding: 0 20px;
    border: 0; border-radius: 999px;
    background: var(--card-2); color: var(--text);
    font-weight: 600;
    transition: transform .12s, background .2s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--peach); color: var(--on-accent); }
.btn-big { min-height: 60px; font-size: 1.1rem; width: 100%; }
.btn-quiet { background: transparent; color: var(--text-2); }
.btn-danger { background: rgb(255 129 147 / .16); color: var(--rose); width: 100%; margin-top: 8px; }
.icon-btn {
    width: var(--tap); height: var(--tap); border: 0; border-radius: 50%;
    background: transparent; display: grid; place-items: center; color: var(--text-2);
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:active { background: var(--card); }
.row { display: flex; gap: 10px; align-items: center; }
.row.center { justify-content: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.hint { color: var(--text-3); font-size: .9rem; margin: 8px 0; }
.lead { color: var(--text-2); font-size: 1.05rem; margin: 10px 0 24px; }
.error { color: var(--rose); }

input[type=url], input[type=time], input#join-name {
    font: inherit; font-size: 1rem; color: var(--text);
    background: var(--card-2); border: 2px solid transparent; border-radius: var(--r-s);
    min-height: var(--tap); padding: 0 14px; width: 100%;
}
input:focus { border-color: var(--lilac); outline: none; }
input[type=time]::-webkit-calendar-picker-indicator { filter: invert(1); opacity: .7; }

/* Toggle switches */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 52px; color: var(--text-2); }
input[role=switch] {
    appearance: none; -webkit-appearance: none; flex: none;
    width: 52px; height: 32px; border-radius: 999px; margin: 0;
    background: var(--card-2); position: relative; cursor: pointer; transition: background .2s;
}
input[role=switch]::after {
    content: ""; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px;
    border-radius: 50%; background: var(--text-2); transition: transform .2s, background .2s;
}
input[role=switch]:checked { background: var(--mint); }
input[role=switch]:checked::after { transform: translateX(20px); background: #1b3a30; }

input[type=range] { width: 100%; accent-color: var(--peach); height: 32px; }
.range-labels { display: flex; justify-content: space-between; color: var(--text-3); font-size: .85rem; }

/* ---------- Setup screens ---------- */
.screen { min-height: 100%; }
.setup {
    display: grid; place-items: center; padding: 24px 20px calc(24px + var(--safe-b));
    background: radial-gradient(120% 80% at 50% 0%, #3a3270 0%, var(--bg) 60%);
}
.setup-card { width: min(440px, 100%); text-align: center; }
.logo { width: 96px; height: 96px; margin: 0 auto 18px; }
.logo svg { width: 100%; height: 100%; stroke: none; }
.logo-sky { fill: #2e2a5c; }
.logo-moon { fill: var(--sun); }
.logo-star { fill: #fff; }
.manual { margin-top: 14px; color: var(--text-3); text-align: left; }
.manual summary { cursor: pointer; text-align: center; min-height: var(--tap); line-height: var(--tap); }
.manual form { margin-top: 8px; }

.role-grid { display: grid; gap: 14px; margin: 24px 0 12px; }
.role {
    display: grid; grid-template-columns: 64px 1fr; grid-template-rows: auto auto; column-gap: 16px;
    align-items: center; text-align: left;
    padding: 18px; border: 2px solid transparent; border-radius: var(--r-l);
    background: var(--card); box-shadow: var(--shadow);
}
.role:active { border-color: var(--peach); }
.role-art { grid-row: span 2; width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; }
.role-art svg { width: 32px; height: 32px; }
.role-art-baby { background: #2f2c66; color: var(--sun); }
.role-art-parent { background: #3d2f4c; color: var(--peach); }
.role strong { font-size: 1.15rem; }
.role span:not(.role-art) { color: var(--text-3); font-size: .9rem; }

/* ---------- Sheets & overlays ---------- */
dialog.sheet {
    width: min(520px, 100%); max-height: 88vh; margin: auto auto 0; padding: 20px 20px calc(20px + var(--safe-b));
    border: 0; border-radius: var(--r-l) var(--r-l) 0 0;
    background: var(--card); color: var(--text); box-shadow: var(--shadow);
}
@media (min-width: 600px) { dialog.sheet { margin: auto; border-radius: var(--r-l); } }
dialog.sheet::backdrop { background: rgb(10 8 25 / .6); backdrop-filter: blur(4px); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.qr { background: #fff; border-radius: var(--r-m); padding: 14px; width: min(300px, 100%); margin: 12px auto; }
.qr svg { display: block; width: 100%; height: auto; stroke: none; }
#pair-sheet .btn { width: 100%; }
.facts { list-style: none; padding: 0; margin: 8px 0 14px; display: grid; gap: 6px; color: var(--text-2); }
.facts li { display: flex; gap: 10px; align-items: center; }
.facts .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-3); }
.facts .ok .dot { background: var(--mint); }
.facts .warn .dot { background: var(--sun); }
.preview { width: 100%; border-radius: var(--r-m); background: #000; margin-bottom: 12px; max-height: 220px; object-fit: cover; }

.toast {
    position: fixed; left: 50%; bottom: calc(20px + var(--safe-b)); transform: translateX(-50%);
    max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 999px;
    background: #f7f3ff; color: #241f3f; font-weight: 600; box-shadow: var(--shadow); z-index: 60;
}

.alarm {
    position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px;
    background: rgb(40 10 30 / .82); backdrop-filter: blur(6px);
}
.alarm-card { width: min(420px, 100%); text-align: center; background: var(--card); border-radius: var(--r-l); padding: 28px 22px; box-shadow: var(--shadow); }
.alarm-icon { width: 88px; height: 88px; margin: 0 auto 14px; border-radius: 50%; display: grid; place-items: center; background: rgb(255 129 147 / .18); color: var(--rose); animation: pulse 1s ease-in-out infinite; }
.alarm[data-kind=nap] .alarm-icon { background: rgb(255 213 111 / .18); color: var(--sun); }
.alarm[data-kind=call] .alarm-icon { background: rgb(255 180 140 / .2); color: var(--peach); }
.alarm-icon svg { width: 44px; height: 44px; }
.alarm-card p { color: var(--text-2); }
.alarm-card .btn { min-width: 130px; }
@keyframes pulse { 50% { transform: scale(1.08); } }

/* ---------- Parent station ---------- */
.parent {
    width: min(560px, 100%); margin: 0 auto;
    padding: calc(8px + var(--safe-t)) 16px calc(28px + var(--safe-b));
}
.p-head { display: flex; align-items: center; gap: 8px; min-height: 56px; }
.chip, .link-chip {
    display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px;
    border-radius: 999px; background: var(--card); color: var(--text-2); font-size: .88rem; font-weight: 600;
    white-space: nowrap;
}
.chip.e2ee { color: var(--mint); padding: 0 10px; }
.chip.low { color: var(--rose); }
.link-chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-3); }
.link-chip[data-state=ok] .dot { background: var(--mint); }
.link-chip[data-state=connecting] .dot { background: var(--sun); animation: blink 1.2s steps(2) infinite; }
.link-chip[data-state=lost] { color: var(--rose); }
.link-chip[data-state=lost] .dot { background: var(--rose); }
@keyframes blink { 50% { opacity: .2; } }

.hero {
    --lvl: 0; --tone: var(--text-3);
    text-align: center; padding: 20px 16px 16px; margin: 6px 0 14px;
    border-radius: var(--r-l); background: var(--card);
}
.hero[data-state=quiet] { --tone: var(--mint); }
.hero[data-state=sound] { --tone: var(--sun); }
.hero[data-state=live]  { --tone: var(--lilac); }
.hero[data-state=lost]  { --tone: var(--rose); }
.orb { position: relative; width: 160px; height: 160px; margin: 6px auto 16px; display: grid; place-items: center; }
.orb-ring {
    position: absolute; inset: 0; border-radius: 50%;
    background: radial-gradient(circle, color-mix(in srgb, var(--tone) 45%, transparent) 0%, transparent 70%);
    transform: scale(calc(.75 + var(--lvl) * .5)); transition: transform .25s ease-out;
}
.hero[data-state=quiet] .orb-ring { animation: breathe 5s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(.88); opacity: .7; } }
.orb-core {
    position: relative; width: 104px; height: 104px; border-radius: 50%; display: grid; place-items: center;
    background: color-mix(in srgb, var(--tone) 22%, var(--card-2)); color: var(--tone);
    transition: background .4s, color .4s;
}
.orb-core svg { width: 54px; height: 54px; }
.hero-title { font-size: 1.7rem; }
.hero-sub { color: var(--text-3); margin: 6px 0 12px; min-height: 1.45em; }
.video-wrap { position: relative; margin: -8px -4px 14px; border-radius: var(--r-m); overflow: hidden; background: #000; aspect-ratio: 4 / 3; }
.video-wrap video { width: 100%; height: 100%; object-fit: cover; display: block; }
.self-pip { position: absolute; right: 10px; bottom: 10px; width: 28% !important; height: auto !important; aspect-ratio: 3/4; border-radius: var(--r-s); border: 2px solid rgb(255 255 255 / .6); }
.hero:has(.video-wrap:not([hidden])) .orb { display: none; }

.timeline { margin-top: 6px; }
.tl-track { position: relative; height: 22px; border-radius: 999px; background: var(--card-2); overflow: hidden; }
.tl-track i { position: absolute; top: 0; bottom: 0; min-width: 4px; background: var(--sun); border-radius: 3px; opacity: .85; }
.tl-labels { display: flex; justify-content: space-between; color: var(--text-3); font-size: .78rem; margin-top: 4px; }

.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.act {
    display: grid; justify-items: center; gap: 6px; padding: 14px 4px 12px;
    border: 0; border-radius: var(--r-m); background: var(--card); color: var(--text-2);
    font-size: .85rem; font-weight: 600; transition: background .2s, color .2s, transform .12s;
}
.act svg { width: 28px; height: 28px; }
.act:active { transform: scale(.96); }
.act[aria-pressed=true] { background: var(--lilac); color: #221a45; }
#act-talk[aria-pressed=true], #act-call[aria-pressed=true] { background: var(--peach); color: var(--on-accent); }
.act:disabled { opacity: .4; }

.card { border-radius: var(--r-l); background: var(--card); padding: 18px; margin-bottom: 14px; }
.card-head { display: flex; align-items: center; gap: 10px; color: var(--peach); margin-bottom: 4px; }
.card-head h2 { color: var(--text); }
.sub-head { color: var(--text-2); font-weight: 600; margin: 14px 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
    min-height: 44px; padding: 0 16px; border: 0; border-radius: 999px;
    background: var(--card-2); color: var(--text); font-weight: 600;
}
.pill:active, .pill[aria-pressed=true] { background: var(--peach); color: var(--on-accent); }
.pill-quiet { background: transparent; color: var(--text-2); box-shadow: inset 0 0 0 2px var(--card-2); }
.countdown { font-size: 3rem; font-weight: 700; margin: 6px 0 0; font-variant-numeric: tabular-nums; color: var(--sun); }
.time-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 6px 0; }
.time-row label { display: grid; gap: 4px; color: var(--text-3); font-size: .88rem; }
.keep-open { text-align: center; padding: 0 12px; }

.dim { position: fixed; inset: 0; z-index: 40; background: #000; display: grid; place-content: center; justify-items: center; gap: 16px; }
.dim-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--mint); opacity: .45; transition: transform .2s, background .3s; }
.dim-text { color: #4c4766; font-size: .95rem; margin: 0; }

/* ---------- Baby station: the sky ---------- */
.baby { position: fixed; inset: 0; overflow: hidden; user-select: none; -webkit-user-select: none; }
.sky { position: absolute; inset: 0; transition: background 4s ease; }
.sky-art { position: absolute; inset: 0; width: 100%; height: 100%; stroke: none; }
.sky-art * { transition: opacity 4s ease, transform 4s ease, fill 4s ease; }
.stars circle { fill: #fff8d6; }
.moon-glow { fill: #fff2b8; opacity: .08; }
.moon-body { fill: #ffe9a3; }
.moon .face, .sun .face { fill: none; stroke: #8a6a3a; stroke-width: 5; stroke-linecap: round; }
.moon .cheek { fill: #ffb9a6; opacity: .6; }
.moon .crater { fill: #f3d98a; }
.sun-body { fill: #ffd25e; }
.sun .rays path { stroke: #ffd25e; stroke-width: 12; stroke-linecap: round; fill: none; }
.sun .eye { fill: #8a5a2a; }
.sun .cheek { fill: #ff9f8a; opacity: .7; }
.clouds path { fill: #fff; opacity: 0; }
.hill-back { fill: #1d1d4a; }
.hill-front { fill: #26265c; }
.sun { transform: translateY(520px); opacity: 0; transform-box: fill-box; transform-origin: center; }
.sun .rays { transform-origin: 200px 330px; }

/* Night: moon and stars, soft glow */
.sky[data-phase=night] { background: linear-gradient(#0c0d2a, #1b1b4d 55%, #2c2462); }
.sky[data-phase=night] .stars { animation: twinkle 6s ease-in-out infinite; }
@keyframes twinkle { 50% { opacity: .55; } }
/* Very dark variant when the soft night light is off */
.sky[data-light=dark][data-phase=night] { background: #040410; }
.sky[data-light=dark][data-phase=night] .moon { opacity: .28; }
.sky[data-light=dark][data-phase=night] .stars { opacity: .25; animation: none; }
.sky[data-light=dark][data-phase=night] .hill { fill: #08081a; }

/* Dawn: almost time — the sun peeks over the hill */
.sky[data-phase=dawn] { background: linear-gradient(#2c2a6e, #a2588a 55%, #ffad84); }
.sky[data-phase=dawn] .moon { opacity: .0; transform: translateY(-200px); }
.sky[data-phase=dawn] .stars { opacity: .25; }
.sky[data-phase=dawn] .sun { transform: translateY(260px); opacity: 1; }
.sky[data-phase=dawn] .hill-back { fill: #5b3b6e; }
.sky[data-phase=dawn] .hill-front { fill: #6e4677; }

/* Wake: OK to get up */
.sky[data-phase=wake] { background: linear-gradient(#7fcaff, #bfe6ff 55%, #fff0b8); }
.sky[data-phase=wake] .moon, .sky[data-phase=day] .moon { opacity: 0; transform: translateY(-300px); }
.sky[data-phase=wake] .stars, .sky[data-phase=day] .stars { opacity: 0; }
.sky[data-phase=wake] .sun { transform: none; opacity: 1; }
.sky[data-phase=wake] .sun .rays { animation: spin 40s linear infinite; }
@keyframes spin { to { transform: rotate(1turn); } }
.sky[data-phase=wake] .clouds path, .sky[data-phase=day] .clouds path { opacity: .9; }
.sky[data-phase=wake] .hill-back, .sky[data-phase=day] .hill-back { fill: #7bc98b; }
.sky[data-phase=wake] .hill-front, .sky[data-phase=day] .hill-front { fill: #5db574; }

/* Day: awake time, calm */
.sky[data-phase=day] { background: linear-gradient(#9bd6ff, #d8f0ff); }
.sky[data-phase=day] .sun { transform: translate(110px, -180px) scale(.55); opacity: 1; }

.sky-greeting {
    position: absolute; left: 0; right: 0; top: calc(9% + var(--safe-t)); margin: 0; text-align: center;
    font-size: clamp(1.8rem, 8vw, 3rem); font-weight: 800; color: #5a3a10; text-shadow: 0 2px 0 rgb(255 255 255 / .6);
}

.kid-call {
    position: absolute; left: 50%; bottom: calc(7% + var(--safe-b)); transform: translateX(-50%);
    width: 112px; height: 112px; border-radius: 50%; border: 0;
    background: #ff9db0; color: #fff; box-shadow: 0 8px 0 #e07890, 0 14px 30px rgb(0 0 0 / .25);
    display: grid; place-items: center; transition: transform .15s, opacity 2s, box-shadow .15s;
}
.kid-call svg { width: 60px; height: 60px; fill: #fff; stroke: #fff; }
.kid-call:active { transform: translateX(-50%) translateY(6px); box-shadow: 0 2px 0 #e07890; }
.sky[data-phase=night] ~ .kid-call { opacity: .5; filter: saturate(.6); }
.baby-call:not([hidden]) ~ .kid-call { display: none; }
.kid-call.ringing { animation: ring 1.2s ease-in-out infinite; opacity: 1 !important; }
@keyframes ring { 0%,100% { transform: translateX(-50%) rotate(0); } 20% { transform: translateX(-50%) rotate(-10deg) scale(1.05); } 40% { transform: translateX(-50%) rotate(10deg) scale(1.05); } 60% { transform: translateX(-50%) rotate(0); } }

.talk-waves { position: absolute; left: 50%; top: 41%; width: 0; height: 0; pointer-events: none; }
.talk-waves span {
    position: absolute; left: -130px; top: -130px; width: 260px; height: 260px; border-radius: 50%;
    border: 6px solid rgb(255 200 220 / .7); animation: wave 2.4s ease-out infinite; opacity: 0;
}
.talk-waves span:nth-child(2) { animation-delay: .8s; }
.talk-waves span:nth-child(3) { animation-delay: 1.6s; }
@keyframes wave { 0% { transform: scale(.6); opacity: .9; } 100% { transform: scale(1.6); opacity: 0; } }

.baby-call { position: absolute; inset: calc(12px + var(--safe-t)) 12px calc(150px + var(--safe-b)); border-radius: 36px; overflow: hidden; background: #000; box-shadow: 0 0 0 8px rgb(255 255 255 / .5); }
.baby-call video { width: 100%; height: 100%; object-fit: cover; }

.hold-lock {
    position: absolute; top: calc(12px + var(--safe-t)); right: 12px; width: 52px; height: 52px; border: 0;
    border-radius: 50%; background: rgb(255 255 255 / .08); color: rgb(255 255 255 / .45); display: grid; place-items: center;
}
.hold-lock .icon { width: 22px; height: 22px; grid-area: 1/1; }
.hold-ring { grid-area: 1/1; width: 52px; height: 52px; transform: rotate(-90deg); }
.hold-ring circle { stroke: #fff; stroke-width: 3; stroke-dasharray: 132; stroke-dashoffset: 132; opacity: .9; }
.hold-lock.holding .hold-ring circle { transition: stroke-dashoffset 2s linear; stroke-dashoffset: 0; }
.baby-offline {
    position: absolute; top: calc(18px + var(--safe-t)); left: 14px; display: flex; gap: 8px; align-items: center;
    color: rgb(255 255 255 / .6); font-size: .9rem; background: rgb(0 0 0 / .3); padding: 6px 12px; border-radius: 999px;
}
.baby-offline .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--rose); }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition-duration: .01ms !important; }
}

/* ---------- Devices and pairing ---------- */
.hint.warn { color: var(--sun); }
.field { display: grid; gap: 8px; text-align: left; color: var(--text-2); margin: 16px 0; }
.pair-code {
    font-size: 2.6rem; font-weight: 800; letter-spacing: .35em; text-align: center; margin: 14px 0;
    font-variant-numeric: tabular-nums; color: var(--peach);
}
.pair-done { text-align: center; }
#pair-ask .row .btn { flex: 1; }
.device-list { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 6px; }
.device {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px;
    background: var(--card-2); border-radius: var(--r-s);
}
.device .icon { width: 22px; height: 22px; color: var(--text-3); flex: none; }
.device.online .icon { color: var(--mint); }
.device-text { display: grid; flex: 1; min-width: 0; }
.device-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-state { color: var(--text-3); font-size: .85rem; }
.btn-small { min-height: 40px; padding: 0 14px; font-size: .9rem; }
.btn-danger-quiet { color: var(--rose); background: transparent; }

/* ---------- Night picture ---------- */
.video-wrap .night-view { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.video-wrap .night-view[hidden] { display: none; }
/* On the baby station: the screen itself as a dim red lamp, below the child's heart button. */
.red-light { position: fixed; inset: 0; background: #7a1206; z-index: 1; pointer-events: none; }
.red-light[hidden] { display: none; }
.baby .kid-call, .baby .hold-lock, .baby .baby-call, .baby .baby-offline, .baby .talk-waves { z-index: 2; }
