:root {
  color-scheme: dark;
  --bg: #10151b;
  --surface: #18212b;
  --line: #2c3a49;
  --text: #f2f6fa;
  --muted: #a9b6c3;
  --blue: #2f74f0;
  --green: #1f9d55;
  --red: #c6303f;
  --amber: #f0b44c;
  font: 18px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
main { max-width: 760px; margin: 0 auto; padding: calc(20px + env(safe-area-inset-top, 0px)) 16px calc(28px + env(safe-area-inset-bottom, 0px)); }
[hidden] { display: none !important; }

/* Text: plain, never boxed, so it can't be mistaken for a button. */
h1 { font-size: clamp(1.7rem, 6vw, 2.4rem); line-height: 1.15; margin: 0 0 6px; }
p { margin: 0; }
#intro { color: var(--muted); margin-bottom: 4px; }
#intro:empty { display: none; }
#status { color: var(--muted); font-size: .95rem; min-height: 1.45em; }
.top { margin-bottom: 18px; }

.icon { width: 1.25em; height: 1.25em; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon.big { width: 2.2em; height: 2.2em; }

/* Buttons: solid, full width, with an icon. Only real buttons look like this. */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; min-height: 60px; padding: 14px 20px; margin: 0;
  border: 0; border-radius: 16px; font: inherit; font-weight: 700; color: #fff;
  cursor: pointer; box-shadow: 0 2px 0 #0006; -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .switch:focus-visible { outline: 3px solid #b6d3ff; outline-offset: 3px; }
.btn-primary { background: var(--blue); }
.btn-danger { background: var(--red); }
.btn-answer { background: var(--green); }
.btn-outline { background: transparent; color: var(--text); border: 2px solid var(--line); box-shadow: none; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- Family caller page ---------- */
.stage { position: relative; aspect-ratio: 16 / 10; background: #05080b; border-radius: 18px; overflow: hidden; display: grid; place-items: center; }
.stage-empty { color: #6f7e8d; text-align: center; padding: 0 24px; font-size: .95rem; }
.stage.has-tiles .stage-empty { display: none; }
.call-tiles { position: absolute; inset: 0; display: grid; gap: 4px; }

/* A person's video. Used on the family page and the TV. */
.tile { position: relative; min-width: 0; min-height: 0; background: #0b1016; border-radius: 10px; overflow: hidden; }
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.tile-name { position: absolute; left: 8px; bottom: 8px; padding: 3px 10px; border-radius: 8px; background: #000a; color: #fff; font-size: .82rem; font-weight: 600; }
.tile-off { display: none; position: absolute; inset: 0; place-items: center; color: #8696a7; font-size: .9rem; }
/* Mom with her camera off: keep the video element playing her audio, just hide the picture. */
.tile.camera-off video { visibility: hidden; }
.tile.camera-off .tile-off { display: grid; }
.caller-controls { display: grid; gap: 10px; margin-top: 16px; }
/* Only one of Call / Hang up shows at a time. */
#hangup { display: none; }
body.in-call #hangup { display: flex; }
body.in-call #startCall, body.in-call .hint { display: none; }
.hint { font-size: .88rem; color: var(--muted); text-align: center; margin: -2px 0 6px; }
/* In a call the page fits the screen exactly, so phones have nothing to scroll:
   the header stays put and the video area takes the rest. */
body.caller.in-call { overflow: hidden; }
body.caller.in-call main { display: flex; flex-direction: column; height: 100vh; height: 100dvh; padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
body.caller.in-call .top { margin-bottom: 12px; }
body.caller.in-call #caller { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
body.caller.in-call .stage { flex: 1 1 auto; min-height: 0; aspect-ratio: auto; }
body.caller.in-call .caller-controls { margin-top: 12px; }
body.caller.in-call .calling-as { display: none; }

/* Caller self-view: small, draggable, tucked into the corner of the stage. */
.self-preview { position: absolute; z-index: 20; top: 8px; right: 8px; width: min(34vw, 200px); border-radius: 12px; overflow: hidden; background: var(--bg); box-shadow: 0 4px 18px #000a; }
.preview-bar { display: flex; align-items: center; justify-content: space-between; min-height: 32px; padding: 0 4px 0 10px; background: #000a; font-size: .8rem; font-weight: 600; cursor: move; touch-action: none; user-select: none; }
.preview-minimize { min-height: 28px; min-width: 32px; margin: 0; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--text); font: inherit; font-size: 1.2rem; line-height: 1; cursor: pointer; }
.self-preview video { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
#preview, #momPreview { transform: scaleX(-1); }

/* ---------- Mom's page ---------- */
body.mom main { max-width: 520px; }
body.mom h1 { text-align: center; font-size: clamp(1.9rem, 8vw, 2.5rem); }
body.mom #status { text-align: center; font-size: 1.05rem; }
body.mom #intro { text-align: center; font-size: 1.1rem; }

.mom-preview { position: relative; aspect-ratio: 3 / 4; height: 30vh; min-height: 150px; margin: 0 auto; background: #05080b; border-radius: 22px; overflow: hidden; display: grid; place-items: center; }
.mom-preview video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.mom-preview-off { display: grid; justify-items: center; gap: 8px; color: #6f7e8d; font-size: 1rem; }
#momPreview:not([hidden]) + .mom-preview-off { display: none; }

/* On/off switches: obviously tappable, state spelled out in words and color. */
.mom-toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.switch {
  display: grid; justify-items: center; gap: 2px; padding: 14px 8px; margin: 0;
  border: 2px solid var(--line); border-radius: 18px; background: var(--surface);
  color: var(--text); font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.switch .icon { width: 1.7em; height: 1.7em; margin-bottom: 4px; }
.switch-label { font-weight: 700; }
.switch-state { font-size: .9rem; color: var(--muted); }
.switch[aria-pressed="true"] { border-color: var(--green); background: #143524; }
.switch[aria-pressed="true"] .switch-state { color: #7ee2a6; font-weight: 700; }

.mom-actions { margin-top: 18px; }
.mom-alerts { margin-top: 18px; display: grid; gap: 10px; }
.mom-alerts .hint { font-size: 1rem; margin: 0; }
body[data-mom-state="incall"] .mom-alerts { display: none; }
.btn-answer, .btn-huge { min-height: 84px; font-size: 1.5rem; border-radius: 22px; }
.btn-answer .icon, .btn-huge .icon { width: 1.4em; height: 1.4em; }
.btn-answer { animation: ring 1.6s ease-in-out infinite; }
@keyframes ring { 0%, 100% { box-shadow: 0 0 0 0 #1f9d5588; } 50% { box-shadow: 0 0 0 12px #1f9d5500; } }
@media (prefers-reduced-motion: reduce) { .btn-answer { animation: none; } }

/* ---------- Fire TV receiver (unchanged behavior) ---------- */
.small { font-size: .9rem; color: var(--muted); }
body.theater { background: #000; overflow: hidden; }
body.theater main { max-width: none; padding: 0; }
body.theater .top, body.theater .small, body.theater #caller, body.theater #mom, body.theater #enableAudio { display: none !important; }
body.theater #receiver { display: block; }
.tv-tiles { display: grid; gap: 6px; width: 100%; height: 68vh; }
body.theater .tv-tiles { position: fixed; inset: 0; width: 100vw; height: 100vh; padding: 6px; background: #000; transition: all .3s ease; }
body.theater .tv-tiles .tile-name { font-size: 1.3rem; left: 16px; bottom: 16px; padding: 6px 16px; }
.toast { position: fixed; z-index: 30; top: 32px; left: 50%; transform: translateX(-50%); padding: 14px 28px; border-radius: 999px; background: #000c; color: #fff; font-size: 1.6rem; font-weight: 700; }
#enterFullscreen { position: fixed; z-index: 5; inset: 0; width: 100vw; height: 100vh; margin: 0; border: 0; border-radius: 0; background: #111923; color: #fff; font: inherit; font-size: 1.6rem; font-weight: 700; display: grid; place-content: center; text-align: center; }
#enterFullscreen span { display: block; margin-top: 10px; font-size: .85em; font-weight: 400; color: #c6d1dc; }

/* ---------- Sign-in ---------- */
.form { display: grid; gap: 8px; }
.form label { font-weight: 700; margin-top: 8px; }
.form input { width: 100%; min-height: 54px; padding: 12px 14px; border: 2px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); font: inherit; }
.form input:focus { outline: none; border-color: var(--blue); }
.form .btn { margin-top: 14px; }
.calling-as { margin-top: 18px; color: var(--muted); font-size: .92rem; }
.link { padding: 0; margin: 0; border: 0; background: none; color: #8db6ff; font: inherit; text-decoration: underline; cursor: pointer; }
