/* Family Calls - one stylesheet, mobile first.
 *
 * Dark only. The app is used on phones in the evening and in a dark video call the
 * surrounding chrome should not be the brightest thing on screen.
 */

:root {
  --bg: #0d1017;
  --surface: #161b25;
  --surface-2: #1e2534;
  --line: #2a3345;
  --text: #eef2f8;
  --muted: #98a3b6;
  --accent: #4f8cff;
  --accent-2: #6e5af0;
  --green: #35d07f;
  --red: #ff4d5e;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  /* Stops iOS zooming the whole page when a kid double-taps a video tile. */
  touch-action: manipulation;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }

/* ---------- login ---------- */

.login {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
  gap: 26px;
}
.login h1 { margin: 0; font-size: 26px; letter-spacing: -0.02em; }
.login .sub { margin: -14px 0 0; color: var(--muted); font-size: 15px; }

.people {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  width: 100%;
  max-width: 420px;
}
.person {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 22px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.person:active { transform: scale(0.97); }
.person.selected { border-color: var(--accent); background: var(--surface-2); }
.person .name { font-size: 17px; font-weight: 600; }

.avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 22px;
  color: #0d1017;
  flex: none;
}
.avatar.sm { width: 40px; height: 40px; font-size: 16px; }
.avatar.lg { width: 96px; height: 96px; font-size: 38px; }

/* PIN keypad: big targets, because a 9-year-old taps this on a phone. */
.pinpad { width: 100%; max-width: 320px; display: none; flex-direction: column; gap: 18px; }
.pinpad.on { display: flex; }
.pin-dots { display: flex; justify-content: center; gap: 14px; height: 18px; }
.pin-dots i {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--line);
}
.pin-dots i.filled { background: var(--accent); border-color: var(--accent); }
.keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.keys button {
  height: 64px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 24px;
  font-weight: 600;
}
.keys button:active { background: var(--surface-2); }
.keys button.wide { font-size: 15px; font-weight: 500; color: var(--muted); }

.error { color: var(--red); min-height: 20px; font-size: 14px; text-align: center; }
.linkish { color: var(--muted); font-size: 14px; text-decoration: underline; }

/* ---------- app shell ---------- */

.app { display: flex; flex-direction: column; height: 100dvh; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.topbar h2 { margin: 0; font-size: 19px; font-weight: 650; letter-spacing: -0.01em; }
.topbar .spacer { flex: 1; }
.iconbtn {
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--line);
  font-size: 17px;
}
.iconbtn:active { background: var(--surface-2); }

.views { flex: 1; overflow: hidden; position: relative; }
.view { position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; display: none; }
.view.on { display: block; }

.tabbar {
  display: flex;
  border-top: 1px solid var(--line);
  background: var(--bg);
  padding-bottom: var(--safe-bottom);
}
.tabbar button {
  flex: 1;
  padding: 10px 0 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--muted);
  font-size: 11px;
  position: relative;
}
.tabbar button .glyph { font-size: 20px; line-height: 1; }
.tabbar button.on { color: var(--accent); }

.badge {
  position: absolute;
  top: 4px;
  left: 50%;
  margin-left: 6px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

/* ---------- calls view ---------- */

.pad { padding: 16px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 4px 0 12px; }

.callall {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 17px;
  font-weight: 650;
  margin-bottom: 22px;
}
.callall:active { filter: brightness(0.92); }
.callall .glyph { font-size: 26px; }
.callall small { display: block; font-weight: 400; opacity: 0.85; font-size: 13px; }

.contact {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 12px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  margin-bottom: 10px;
  text-align: left;
}
.contact .who { flex: 1; min-width: 0; }
.contact .who b { display: block; font-size: 16px; font-weight: 600; }
.contact .who span { font-size: 13px; color: var(--muted); }
.contact .act { display: flex; gap: 8px; }
.contact .act button {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; font-size: 18px;
  background: var(--surface-2); border: 1px solid var(--line);
}
.contact .act button.video { background: var(--accent); border-color: var(--accent); color: #fff; }
.contact .act button:active { transform: scale(0.94); }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; margin-right: 6px; }
.dot.on { background: var(--green); box-shadow: 0 0 0 3px rgba(53, 208, 127, 0.18); }

.avwrap { position: relative; flex: none; }
.avwrap .status {
  position: absolute; right: -1px; bottom: -1px;
  width: 14px; height: 14px; border-radius: 50%;
  border: 2.5px solid var(--bg); background: var(--muted);
}
.avwrap .status.on { background: var(--green); }

/* ---------- chats ---------- */

.thread-row {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.thread-row:active { background: var(--surface); }
.thread-row .meta { flex: 1; min-width: 0; }
.thread-row .meta b { display: block; font-size: 16px; font-weight: 600; margin-bottom: 2px; }
.thread-row .meta span {
  display: block; font-size: 14px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thread-row .right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.thread-row .time { font-size: 12px; color: var(--muted); }
.thread-row .count {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 700;
  display: grid; place-items: center;
}

/* conversation */
.convo { position: absolute; inset: 0; display: none; flex-direction: column; background: var(--bg); z-index: 5; }
.convo.on { display: flex; }
/* The tab bar would otherwise sit under the composer, stacking two bars and two
   lots of safe-area padding at the bottom of a phone. Back is in the header. */
body.convo-open .tabbar { display: none; }
.msgs { flex: 1; overflow-y: auto; padding: 14px 14px 6px; display: flex; flex-direction: column; gap: 3px; }

.bubble {
  max-width: 78%;
  padding: 9px 13px;
  border-radius: 18px;
  font-size: 15.5px;
  line-height: 1.38;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  background: var(--surface-2);
  align-self: flex-start;
  border-bottom-left-radius: 5px;
}
.bubble.mine {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-left-radius: 18px;
  border-bottom-right-radius: 5px;
}
.bubble .from { display: block; font-size: 12px; font-weight: 700; margin-bottom: 2px; }
.bubble .at { font-size: 11px; opacity: 0.65; margin-left: 8px; float: right; margin-top: 4px; }
.bubble.call {
  align-self: center;
  background: transparent;
  border: 1px dashed var(--line);
  color: var(--muted);
  font-size: 13px;
  max-width: 90%;
  text-align: center;
}
.stack-gap { margin-top: 9px; }
.typing { padding: 2px 16px 6px; font-size: 12.5px; color: var(--muted); height: 20px; }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  padding: 9px 12px calc(9px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg);
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  padding: 10px 14px;
  border-radius: 20px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  /* 16px exactly: anything smaller and iOS Safari zooms the page on focus. */
  font-size: 16px;
  line-height: 1.35;
  outline: none;
}
.composer textarea:focus { border-color: var(--accent); }
.composer .send {
  width: 42px; height: 42px; flex: none; border-radius: 50%;
  background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 18px;
}
.composer .send:disabled { opacity: 0.4; }

/* ---------- incoming call ---------- */

.ring {
  position: fixed; inset: 0; z-index: 50;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  gap: 20px;
  background: linear-gradient(170deg, #182338, #0d1017 65%);
  padding: calc(40px + var(--safe-top)) 24px calc(40px + var(--safe-bottom));
}
.ring.on { display: flex; }
.ring .who { font-size: 27px; font-weight: 650; }
.ring .what { color: var(--muted); font-size: 15px; margin-top: -12px; }
.ring .avatar.lg { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(79, 140, 255, 0.45); }
  50% { box-shadow: 0 0 0 22px rgba(79, 140, 255, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .ring .avatar.lg { animation: none; }
}
.ring .actions { display: flex; gap: 26px; margin-top: 18px; }
.ring .actions .col { display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.big-round {
  width: 68px; height: 68px; border-radius: 50%;
  display: grid; place-items: center; font-size: 27px; color: #fff;
}
.big-round.accept { background: var(--green); }
.big-round.decline { background: var(--red); }
.big-round:active { transform: scale(0.93); }

/* ---------- in call ---------- */

.incall { position: fixed; inset: 0; z-index: 40; display: none; flex-direction: column; background: #05070b; }
.incall.on { display: flex; }

.grid {
  flex: 1;
  display: grid;
  gap: 6px;
  padding: 6px;
  padding-top: calc(6px + var(--safe-top));
  grid-template-columns: 1fr;
  min-height: 0;
}
.grid.n2 { grid-template-rows: 1fr 1fr; }
.grid.n3, .grid.n4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
@media (orientation: landscape) and (min-width: 700px) {
  .grid.n2 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
}

.tile {
  position: relative;
  background: var(--surface);
  border-radius: 14px;
  overflow: hidden;
  min-height: 0;
  display: grid;
  place-items: center;
}
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #05070b; }
/* Your own preview is mirrored: an unmirrored self-view feels wrong to everyone. */
.tile.self video { transform: scaleX(-1); }
.tile.self.rear video { transform: none; }
.tile .label {
  position: absolute; left: 8px; bottom: 8px;
  padding: 3px 9px; border-radius: 10px;
  background: rgba(5, 7, 11, 0.62);
  font-size: 12.5px; font-weight: 600;
  display: flex; align-items: center; gap: 5px;
  backdrop-filter: blur(6px);
}
.tile .placeholder { position: absolute; inset: 0; display: grid; place-items: center; background: var(--surface); }
.tile .placeholder.hidden { display: none; }
.tile .conn {
  position: absolute; right: 8px; top: 8px;
  font-size: 11px; color: var(--muted);
  background: rgba(5, 7, 11, 0.62); padding: 2px 8px; border-radius: 9px;
}

.controls {
  display: flex;
  justify-content: center;
  gap: 14px;
  padding: 14px 12px calc(16px + var(--safe-bottom));
  background: rgba(5, 7, 11, 0.9);
}
.controls button {
  width: 56px; height: 56px; border-radius: 50%;
  display: grid; place-items: center; font-size: 21px;
  background: var(--surface-2); border: 1px solid var(--line);
}
.controls button.off { background: #fff; color: #05070b; }
.controls button.hangup { background: var(--red); border-color: var(--red); color: #fff; }
.controls button:active { transform: scale(0.93); }
.controls button:disabled { opacity: 0.35; }

.calltop {
  position: absolute; top: calc(10px + var(--safe-top)); left: 0; right: 0;
  text-align: center; font-size: 13px; color: var(--muted); pointer-events: none; z-index: 2;
}

/* ---------- misc ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 10px 16px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.on { opacity: 1; }

.banner {
  margin: 0 16px 14px;
  padding: 13px 15px;
  border-radius: 13px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 14px;
  color: var(--muted);
  display: none;
  line-height: 1.45;
}
.banner.on { display: block; }
.banner b { color: var(--text); }
.banner button {
  margin-top: 10px;
  padding: 9px 15px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
}
.banner .dismiss { background: transparent; color: var(--muted); text-decoration: underline; padding: 9px 6px; }

/* A call happening right now is the one banner that should pull the eye. */
.banner.ongoing { border-color: var(--green); background: rgba(53, 208, 127, 0.09); color: var(--text); }
.banner.ongoing button { background: var(--green); }
.banner.ongoing .dismiss { background: transparent; }

.offline {
  display: none;
  background: #6b3a00;
  color: #ffd9a0;
  text-align: center;
  font-size: 13px;
  padding: 6px;
}
.offline.on { display: block; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 14px; line-height: 1.5; }

/* Build and notification diagnostics, shown in the app on purpose. */
.status {
  margin-top: 26px;
  padding: 13px 14px;
  border-radius: 13px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--muted);
}
.status .rows { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; }
.status .rows span:nth-child(odd) { opacity: 0.75; }
.status .rows span:nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; }
.status .ok { color: var(--green); }
.status .bad { color: var(--red); font-weight: 600; }
.status button {
  margin-top: 11px;
  width: 100%;
  padding: 9px;
  border-radius: 9px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
}
.status button:active { background: var(--line); }

/* Same string, on the call screen, so a phone can be identified mid-call. */
.callver {
  position: absolute;
  top: calc(10px + var(--safe-top));
  right: 12px;
  font-size: 10.5px;
  color: var(--muted);
  opacity: 0.65;
  z-index: 3;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
