/* Famchat - WhatsApp-style layout, orange theme, sized for phones and kids' tablets */
:root {
  --brand: #f97316; --brand-dark: #ea580c; --on-brand: #ffffff;
  --page: #ffffff; --ink: #111b21; --soft: #667781; --line: #e9edef;
  --wall: #f3ece3; --theirs: #ffffff; --theirs-ink: #111b21;
  --mine: #ffe0c2; --mine-ink: #111b21; --tick: #8696a0; --tick-read: #ea580c;
  --chip: #fff3e6; --chip-ink: #54656f; --badge: #f97316; --danger: #dc2626; --ok: #16a34a;
  --shadow: 0 1px 0.5px rgba(11, 20, 26, .13);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #111b21; --ink: #e9edef; --soft: #8696a0; --line: #222d34;
    --wall: #0b141a; --theirs: #202c33; --theirs-ink: #e9edef;
    --mine: #7c2d12; --mine-ink: #fff7ed; --tick: #8696a0; --tick-read: #fdba74;
    --chip: #182229; --chip-ink: #8696a0; --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  background: var(--page); color: var(--ink);
  font: 17px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", sans-serif;
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
  overscroll-behavior: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
[hidden] { display: none !important; }
#app { height: 100%; display: flex; flex-direction: column; max-width: 900px; margin: 0 auto; background: var(--page); }

.splash { margin: auto; text-align: center; font-weight: 700; font-size: 22px; color: var(--brand); }
.splash-emoji { font-size: 84px; }

/* ---------- top bar */
.bar {
  display: flex; align-items: center; gap: 12px; flex: none;
  min-height: calc(env(safe-area-inset-top, 0px) + 64px);
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px 8px 8px;
  background: var(--brand); color: var(--on-brand);
}
.bar h1 { font-size: 21px; font-weight: 700; margin: 0; flex: 1; min-width: 0; line-height: 1.2; }
.bar h1, .bar .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .sub { font-size: 14px; opacity: .92; font-weight: 400; display: block; min-height: 1.1em; }
.bar > .av { margin-left: 4px; }
.iconbtn { width: 48px; height: 48px; border-radius: 50%; font-size: 26px; display: grid; place-items: center; flex: none; color: inherit; }
.iconbtn:active { background: rgba(255, 255, 255, .22); }
.back { font-size: 30px; width: 44px; margin-right: -6px; }

/* ---------- avatars */
.av {
  width: 54px; height: 54px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-size: 31px; line-height: 1; background: var(--chip); overflow: hidden;
}
.av.sm { width: 44px; height: 44px; font-size: 25px; }
.av.xs { width: 22px; height: 22px; font-size: 13px; }
.bar .av { box-shadow: 0 0 0 2px rgba(255, 255, 255, .85); }

/* ---------- chat list */
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.list { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 16px); }
.row {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  padding: 10px 16px; min-height: 80px; background: var(--page);
}
.row:active { background: var(--line); }
.row .mid { flex: 1; min-width: 0; align-self: stretch; display: flex; flex-direction: column; justify-content: center;
  border-bottom: 1px solid var(--line); padding: 6px 0; }
.row:last-child .mid { border-bottom: 0; }
.row .top { display: flex; align-items: baseline; gap: 8px; }
.row .name { font-weight: 600; font-size: 18.5px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .time { font-size: 13px; color: var(--soft); flex: none; }
.row .time.new { color: var(--brand-dark); font-weight: 600; }
.row .bottom { display: flex; align-items: center; gap: 8px; margin-top: 3px; }
.row .prev { color: var(--soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 16px; flex: 1; min-width: 0; }
.badge {
  min-width: 24px; height: 24px; padding: 0 7px; border-radius: 12px; background: var(--badge);
  color: #fff; font-weight: 700; font-size: 13.5px; display: grid; place-items: center; flex: none;
}
.section { padding: 18px 16px 6px; color: var(--soft); font-size: 14px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.note {
  display: flex; gap: 12px; align-items: center; margin: 10px 12px; padding: 14px 16px;
  border-radius: 14px; background: var(--chip); font-size: 16px;
}
.note .grow { flex: 1; }
.btn {
  padding: 10px 20px; border-radius: 999px; background: var(--brand); color: var(--on-brand);
  font-weight: 700; min-height: 46px; font-size: 16.5px;
}
.btn.ghost { background: var(--chip); color: var(--ink); }
.btn.danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: .5; }

/* ---------- a chat */
.chat { background: var(--wall); }
.msgs { padding: 8px 10px 10px; display: flex; flex-direction: column; }
.day {
  align-self: center; margin: 12px 0 8px; padding: 5px 12px; border-radius: 8px;
  background: var(--theirs); color: var(--chip-ink); font-size: 13.5px; box-shadow: var(--shadow);
}
.msg { display: flex; flex-direction: column; max-width: 82%; align-self: flex-start; margin-top: 2px; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.first { margin-top: 10px; }
.who { font-size: 14px; font-weight: 700; margin: 0 0 3px 4px; display: flex; gap: 6px; align-items: center; }
.bubble {
  position: relative; padding: 7px 10px 8px 11px; border-radius: 10px;
  background: var(--theirs); color: var(--theirs-ink); box-shadow: var(--shadow);
  white-space: pre-wrap; overflow-wrap: anywhere; text-align: left; font-size: 17.5px; line-height: 1.35;
  min-width: 72px; cursor: pointer; user-select: text; -webkit-user-select: text;
}
.msg.mine .bubble { background: var(--mine); color: var(--mine-ink); }
.msg.first .bubble { border-top-left-radius: 0; }
.msg.first.mine .bubble { border-top-left-radius: 10px; border-top-right-radius: 0; }
/* the little tails, like WhatsApp */
.msg.first .bubble::before {
  content: ""; position: absolute; top: 0; left: -8px; width: 8px; height: 13px;
  background: var(--theirs); clip-path: polygon(0 0, 100% 0, 100% 100%);
}
.msg.first.mine .bubble::before { left: auto; right: -8px; background: var(--mine); clip-path: polygon(0 0, 100% 0, 0 100%); }
.stamp {
  float: right; position: relative; top: 7px; margin: 0 0 0 12px; font-size: 12px; line-height: 1;
  color: var(--soft); white-space: nowrap; user-select: none; -webkit-user-select: none;
}
.msg.mine .stamp { color: var(--tick); }
.tick { margin-left: 3px; letter-spacing: -3px; font-size: 13px; }
.tick.read { color: var(--tick-read); font-weight: 700; }
.bubble.big { background: none !important; box-shadow: none; font-size: 64px; line-height: 1.1; padding: 0 2px; min-width: 0; }
.bubble.big::before { display: none; }
.bubble.big .stamp { float: none; display: block; text-align: right; top: 0; margin: 2px 0 0; font-size: 12px;
  background: var(--theirs); padding: 3px 8px; border-radius: 10px; width: max-content; margin-left: auto; }
.msg.pending .bubble { opacity: .7; }
.msg.failed .bubble { outline: 2px solid var(--danger); }
.meta { font-size: 13px; color: var(--danger); margin: 3px 6px 0; }
.rx { display: flex; gap: 3px; flex-wrap: wrap; margin-top: -4px; padding: 0 6px; position: relative; z-index: 1; }
.rx span { background: var(--theirs); border: 1px solid var(--line); border-radius: 999px; padding: 1px 7px; font-size: 16px; box-shadow: var(--shadow); }
.seen { font-size: 13px; color: var(--soft); margin: 3px 4px 0; display: flex; gap: 3px; align-items: center; }
.picker-bar {
  display: flex; gap: 2px; padding: 6px; border-radius: 999px; background: var(--theirs);
  box-shadow: 0 4px 18px rgba(0, 0, 0, .22); margin: 6px 0 2px; z-index: 2;
}
.picker-bar button { font-size: 30px; width: 48px; height: 48px; border-radius: 50%; }
.picker-bar button.on { background: var(--chip); }
.typing { font-size: 14.5px; color: var(--soft); padding: 0 16px 2px; min-height: 22px; font-style: italic; background: var(--wall); }
.more { align-self: center; margin: 8px; }
.empty { align-self: center; margin: 16px; padding: 8px 14px; border-radius: 8px; background: var(--chip); color: var(--chip-ink); font-size: 15px; text-align: center; }

/* ---------- typing box */
.composer {
  display: flex; align-items: flex-end; gap: 6px; flex: none;
  padding: 6px 8px calc(env(safe-area-inset-bottom, 0px) + 8px); background: var(--wall);
}
.pill {
  flex: 1; min-width: 0; display: flex; align-items: flex-end; background: var(--theirs);
  border-radius: 26px; box-shadow: var(--shadow); min-height: 52px; padding: 2px 6px 2px 2px;
}
.pill textarea {
  flex: 1; min-width: 0; resize: none; border: 0; background: transparent; outline: none;
  padding: 13px 6px 13px 2px; max-height: 150px; min-height: 48px; line-height: 1.3; font-size: 18px;
}
.pill textarea::placeholder { color: var(--soft); }
.send {
  width: 52px; height: 52px; border-radius: 50%; background: var(--brand); color: #fff; font-size: 24px;
  display: grid; place-items: center; flex: none; box-shadow: var(--shadow);
}
.send:active { background: var(--brand-dark); }
.send:disabled { opacity: .45; }
.emojibtn { width: 48px; height: 48px; border-radius: 50%; font-size: 27px; display: grid; place-items: center; flex: none; opacity: .85; }
.emojibtn.on { background: var(--chip); opacity: 1; }
.readonly { margin: 8px; }

/* ---------- emoji keyboard */
.emojis { background: var(--page); border-top: 1px solid var(--line); flex: none; }
.etabs { display: flex; overflow-x: auto; border-bottom: 1px solid var(--line); }
.etabs button { font-size: 26px; padding: 8px 14px; flex: none; border-bottom: 3px solid transparent; }
.etabs button.on { border-bottom-color: var(--brand); }
.egrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); height: 260px; overflow-y: auto; padding: 6px; }
.egrid button { font-size: 34px; height: 54px; border-radius: 12px; }
.egrid button:active { background: var(--chip); }

/* ---------- setup, Family page */
.pagepad { padding: 4px 12px calc(env(safe-area-inset-bottom, 0px) + 16px); }
.card { background: var(--page); border: 1px solid var(--line); border-radius: 16px; padding: 18px; margin: 12px 0; }
.card h2 { margin: 0 0 12px; font-size: 20px; }
.setup { margin: auto; width: min(440px, 100%); padding: 28px 18px; text-align: center; }
.setup .big { font-size: 76px; }
.setup h1 { margin: 6px 0 4px; font-size: 30px; }
.setup p { font-size: 17px; color: var(--soft); }
.field { display: block; text-align: left; margin: 14px 0; }
.field span { display: block; font-size: 15px; color: var(--soft); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 14px 16px; border-radius: 14px; border: 2px solid var(--line); background: var(--page);
  outline: none; min-height: 54px; font-size: 18px;
}
.field input:focus { border-color: var(--brand); }
.code-input { font-size: 28px !important; letter-spacing: 3px; text-align: center; text-transform: uppercase; font-family: ui-monospace, Menlo, Consolas, monospace !important; }
.err { color: var(--danger); min-height: 1.4em; font-size: 16px; }
.choices { display: flex; flex-wrap: wrap; gap: 6px; }
.choices button { width: 50px; height: 50px; border-radius: 50%; font-size: 28px; display: grid; place-items: center; border: 3px solid transparent; }
.choices button.on { border-color: var(--brand); }
.swatch { width: 42px !important; height: 42px !important; }
.swatch.on { border-color: var(--ink) !important; }
.person { display: flex; align-items: center; gap: 14px; font-size: 18px; }
.person .mid { flex: 1; min-width: 0; }
.tag { display: inline-block; font-size: 13px; padding: 2px 9px; border-radius: 999px; background: var(--chip); margin-left: 6px; font-weight: 600; vertical-align: middle; }
.tag.paused { background: var(--danger); color: #fff; }
.devices { margin: 12px 0 0; padding: 0; list-style: none; font-size: 15px; color: var(--soft); }
.devices li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.devices li span { flex: 1; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.codebox { margin-top: 14px; padding: 16px; border-radius: 14px; background: var(--chip); text-align: center; }
.codebox .code { font: 700 32px/1.2 ui-monospace, Menlo, Consolas, monospace; letter-spacing: 3px; user-select: all; }
.small { font-size: 14.5px; color: var(--soft); }
.paused-screen { margin: auto; text-align: center; padding: 24px; font-size: 18px; }
.paused-screen .big { font-size: 80px; }
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 96px); transform: translateX(-50%);
  background: #111b21; color: #fff; padding: 12px 18px; border-radius: 999px; font-size: 16px; z-index: 50;
  max-width: calc(100% - 32px); text-align: center;
}
.offline { background: #54656f; color: #fff; text-align: center; font-size: 14px; padding: 4px; flex: none; }

/* tablets: a little roomier */
@media (min-width: 700px) {
  body { font-size: 18px; }
  .bubble { font-size: 18.5px; }
  .msg { max-width: 70%; }
  .msgs { padding: 10px 24px 12px; }
}
