:root {
  --bg: #000;
  --bar: rgba(22, 22, 24, .86);
  --card: #1C1C1E;
  --raised: #2C2C2E;
  --line: rgba(255, 255, 255, .09);
  --text: #F5F5F7;
  --sub: #8E8E93;
  --accent: #0A84FF;
  --green: #30D158;
  --red: #FF453A;
  --mine: #0A84FF;
  --theirs: #26262A;
  --tabs-h: 58px;
  --safe-b: env(safe-area-inset-bottom);
  --safe-t: env(safe-area-inset-top);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); overscroll-behavior: none; }
body {
  color: var(--text);
  font: 17px/1.35 -apple-system, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none; user-select: none;
}
input, textarea, .bubble, .ussdtext { -webkit-user-select: text; user-select: text; }
button, input, select, textarea { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; cursor: pointer; }
button:disabled { opacity: .4; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg .dots circle { fill: currentColor; stroke: none; }
.sub { color: var(--sub); font-size: 15px; }
.center { text-align: center; }

/*
 * A Home Screen app's page starts out told it is shorter than the screen: on an iPhone Air,
 * innerHeight, 100%, 100dvh and position: fixed all stop at 844 of 912 pt, and nothing is drawn
 * below that, leaving a bar under the tabs. Only a page as tall as the screen gets drawn to the
 * bottom (and iOS then puts its numbers right, at the first touch). So the app is a box in the
 * page's own flow, 100lvh (the whole screen) tall, that scrolls inside itself.
 */
#app { position: relative; height: 100lvh; display: flex; flex-direction: column; background: var(--bg); overflow: hidden; }
.overlay { position: fixed; top: 0; left: 0; right: 0; height: 100lvh; }
/* With the keyboard up, the box follows what is left of the screen (set from app.js). */
body.typing #app { height: var(--vvh, 100lvh); }

header#top {
  flex: none; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
  padding: calc(var(--safe-t) + 6px) 18px 8px;
}
header#top h1 { font-size: 32px; font-weight: 700; letter-spacing: -.02em; margin: 0; }
.chip {
  display: flex; align-items: center; gap: 7px; height: 30px; padding: 0 12px; margin-bottom: 4px;
  border-radius: 15px; background: var(--card); font-size: 13px; color: var(--sub); max-width: 55%;
}
.chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--sub); flex: none; }
.chip.live { color: var(--text); }
.chip.live .dot { background: var(--green); }
.chip.bad .dot { background: var(--red); }

main#scroller {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 0 16px 120px;
}
.view { display: none; }
.view.on { display: block; }

/* ---- tabs ---- */
nav#tabs {
  flex: none; display: flex; justify-content: space-around;
  height: calc(var(--tabs-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--bar); border-top: .5px solid var(--line);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
}
nav#tabs button {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--sub); font-size: 11px; font-weight: 500; position: relative;
}
nav#tabs button svg { width: 26px; height: 26px; }
nav#tabs button.on { color: var(--accent); }
.badge {
  position: absolute; top: 5px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--red); color: #fff; font-size: 12px; line-height: 18px; font-weight: 600; display: none;
}
.badge.on { display: block; }
body.in-thread nav#tabs { display: none; }

.fab {
  position: absolute; right: 18px; bottom: calc(var(--tabs-h) + var(--safe-b) + 18px);
  width: 58px; height: 58px; border-radius: 29px; display: none; align-items: center; justify-content: center;
  background: var(--accent); color: #fff; box-shadow: 0 6px 20px rgba(10, 132, 255, .35);
}
.fab svg { width: 26px; height: 26px; stroke-width: 2.4; }
.fab.on { display: flex; }

/* ---- lists ---- */
.list { display: flex; flex-direction: column; }
.item {
  display: flex; gap: 12px; align-items: center; width: 100%; text-align: left;
  padding: 10px 0; min-height: 72px; position: relative;
}
.item + .item::before { content: ''; position: absolute; top: 0; left: 60px; right: 0; border-top: .5px solid var(--line); }
.item .main { flex: 1; min-width: 0; }
.item .line1 { display: flex; align-items: baseline; gap: 8px; }
.item .name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .when { color: var(--sub); font-size: 14px; flex: none; }
.item .last {
  color: var(--sub); font-size: 15px; line-height: 1.3; margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; unicode-bidi: plaintext;
}
.item.unread .last { color: var(--text); }
.item.unread .main::after { content: ''; position: absolute; left: -10px; top: 50%; width: 8px; height: 8px; margin-top: -4px; border-radius: 50%; background: var(--accent); }
.item .kind { display: flex; align-items: center; gap: 4px; color: var(--sub); font-size: 14px; margin-top: 2px; }
.item .kind svg { width: 14px; height: 14px; }
.item.missed .name { color: var(--red); }

.avatar {
  width: 48px; height: 48px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 18px; color: #fff; background: #48484A; letter-spacing: .02em;
}
.avatar svg { width: 24px; height: 24px; }
.avatar.small { width: 34px; height: 34px; font-size: 14px; }
.avatar.small svg { width: 18px; height: 18px; }
.avatar.huge { width: 96px; height: 96px; font-size: 38px; margin: 0 auto 14px; }
.avatar.huge svg { width: 44px; height: 44px; }

.empty { display: none; text-align: center; color: var(--sub); margin-top: 18vh; }
.empty.on { display: block; }
.empty svg { width: 52px; height: 52px; stroke-width: 1.5; opacity: .6; }
.empty p { margin: 10px 0 0; font-size: 15px; }

/* ---- one thread ---- */
body.in-thread header#top { display: none; }
.threadbar {
  position: sticky; top: 0; z-index: 3; display: flex; align-items: center; gap: 10px;
  margin: 0 -16px; padding: calc(var(--safe-t) + 4px) 8px 8px;
  background: var(--bar); border-bottom: .5px solid var(--line);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
}
.threadbar .who { flex: 1; min-width: 0; }
.threadbar .who div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#t-name { font-weight: 600; font-size: 16px; }
#t-number { font-size: 13px; }
.icon-btn { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; border-radius: 22px; color: var(--text); }
.icon-btn.accent { color: var(--accent); }
.icon-btn.big svg { width: 28px; height: 28px; }
.newto { display: none; align-items: center; gap: 8px; padding: 10px 0; border-bottom: .5px solid var(--line); color: var(--sub); }
.newto.on { display: flex; }
.newto input { flex: 1; border: 0; background: none; outline: none; font-size: 17px; color: var(--text); }

#bubbles { display: flex; flex-direction: column; gap: 2px; padding: 10px 0 8px; }
.bubble {
  max-width: 78%; padding: 8px 13px; border-radius: 19px; background: var(--theirs); align-self: flex-start;
  white-space: pre-wrap; word-wrap: break-word; unicode-bidi: plaintext; font-size: 17px; line-height: 1.3;
}
.bubble.mine { background: var(--mine); color: #fff; align-self: flex-end; }
.bubble.gap { margin-top: 8px; }
.bubble.failed { background: #5a1f1c; }
.meta { font-size: 12px; color: var(--sub); margin: 2px 6px 6px; }
.meta.mine { align-self: flex-end; }
.meta.bad { color: var(--red); }
.day { align-self: center; color: var(--sub); font-size: 12px; font-weight: 500; margin: 14px 0 6px; }

#composer {
  flex: none; display: none; align-items: flex-end; gap: 8px;
  padding: 8px 12px calc(8px + var(--safe-b));
  background: var(--bar); border-top: .5px solid var(--line);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
}
body.typing #composer { padding-bottom: 8px; }
body.in-thread #composer { display: flex; }
#composer textarea {
  flex: 1; resize: none; max-height: 140px; min-height: 38px; padding: 8px 14px; border-radius: 19px;
  border: .5px solid #3A3A3C; background: #0E0E10; outline: none; font-size: 17px; line-height: 1.3; unicode-bidi: plaintext;
}
.send { width: 38px; height: 38px; border-radius: 19px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; }
.send svg { width: 20px; height: 20px; stroke-width: 2.6; }

/* ---- settings ---- */
.group { margin: 14px 0 22px; }
.group-title { font-size: 13px; color: var(--sub); text-transform: uppercase; letter-spacing: .03em; margin: 0 16px 7px; }
.group-foot { font-size: 13px; color: var(--sub); margin: 7px 16px 0; }
.card { background: var(--card); border-radius: 14px; padding: 14px 16px; }
.card.rows { padding: 0 0 0 16px; }
.card.gap { margin-top: 14px; }
.card p { margin: 0 0 12px; }
.row-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 50px; padding-right: 16px; border-bottom: .5px solid var(--line); }
.row-label { flex: none; }
.row-value { color: var(--sub); text-align: right; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-btn { display: block; width: 100%; text-align: left; min-height: 50px; color: var(--accent); border-bottom: .5px solid var(--line); }
.row-btn.danger { color: var(--red); }
.card.rows > :last-child { border-bottom: 0; }
.seg { display: flex; background: #2C2C2E; border-radius: 9px; padding: 2px; gap: 2px; width: 190px; }
.seg button { flex: 1; height: 32px; border-radius: 7px; color: var(--text); font-size: 14px; font-weight: 500; }
.seg button.on { background: #636366; }
.btn { min-height: 50px; padding: 0 18px; border-radius: 12px; background: var(--raised); font-weight: 600; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.wide { width: 100%; }
.field { width: 100%; padding: 13px 14px; border-radius: 12px; border: .5px solid #3A3A3C; background: #0E0E10; outline: none; margin: 4px 0 8px; }
video { width: 100%; border-radius: 12px; display: none; margin-top: 12px; }
details summary { color: var(--accent); font-size: 15px; margin: 14px 0 6px; list-style: none; }
details summary::-webkit-details-marker { display: none; }

/* ---- sheets: the keypad, a code's answer ---- */
.scrim { position: fixed; top: 0; left: 0; right: 0; height: 100lvh; background: rgba(0, 0, 0, .5); display: none; z-index: 14; }
.scrim.on { display: block; }
.sheet {
  position: fixed; left: 0; right: 0; top: 100lvh; transform: translateY(-100%); z-index: 15; display: none; flex-direction: column; gap: 12px;
  background: #1C1C1E; border-radius: 24px 24px 0 0; padding: 8px 20px calc(20px + var(--safe-b));
  max-height: 88lvh; overflow: auto;
}
.sheet.on { display: flex; }
.grab { width: 38px; height: 5px; border-radius: 3px; background: #48484A; align-self: center; margin-bottom: 4px; }
.dial {
  border: 0; background: none; outline: none; text-align: center; font-size: 34px; font-weight: 500; letter-spacing: .02em;
  height: 52px; caret-color: var(--accent);
}
.dial::placeholder { font-size: 20px; color: #48484A; font-weight: 400; }
.padkeys { display: grid; grid-template-columns: repeat(3, 76px); justify-content: center; gap: 14px 26px; }
.padkeys button {
  width: 76px; height: 76px; border-radius: 38px; background: #333336;
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1;
}
.padkeys button b { font-size: 32px; font-weight: 400; }
.padkeys button small { font-size: 10px; letter-spacing: .14em; color: #AEAEB2; margin-top: 3px; height: 11px; }
.padkeys button:active { background: #5A5A5E; }
.padrow { display: grid; grid-template-columns: 76px 76px 76px; justify-content: center; gap: 26px; align-items: center; margin-top: 4px; }
.simpick { height: 40px; border-radius: 20px; border: 0; background: #2C2C2E; color: var(--sub); font-size: 13px; text-align: center; padding: 0 6px; }
.callbtn { width: 76px; height: 76px; border-radius: 38px; background: var(--green); color: #fff; display: flex; align-items: center; justify-content: center; }
.callbtn.code { background: var(--accent); }
.callbtn svg { width: 32px; height: 32px; fill: #fff; stroke: none; }
.ussdtext { white-space: pre-wrap; font-size: 18px; line-height: 1.4; unicode-bidi: plaintext; }
.u-form { display: none; gap: 8px; align-items: center; position: sticky; bottom: 0; background: #1C1C1E; padding-top: 6px; }
.u-opts { display: flex; flex-direction: column; gap: 6px; }
.u-opts:empty { display: none; }
.u-opts button {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: start; padding: 9px 12px;
  border-radius: 16px; background: #2C2C2E; font-size: 17px; line-height: 1.3; unicode-bidi: plaintext;
}
.u-opts button:active { background: #3A3A3C; }
.u-opts b {
  flex: none; width: 30px; height: 30px; border-radius: 15px; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 600;
}
/* With the keyboard up the sheet stands on it, not on the screen's foot behind it, and its words
   scroll while the box to type in stays in sight. */
body.typing #ussd { top: var(--vvh); max-height: calc(var(--vvh) - 12px); padding-bottom: 0; }
body.typing .u-form { padding-bottom: 10px; }
body.typing #u-close { display: none; }
.u-form.on { display: flex; }
.u-form .field { margin: 0; }

/* ---- calls on screen ---- */
.overlay {
  z-index: 20; display: none; flex-direction: column; justify-content: space-between;
  background: linear-gradient(180deg, #1d2633 0%, #0b0d12 60%, #000 100%);
  padding: calc(var(--safe-t) + 56px) 24px calc(var(--safe-b) + 40px);
}
.overlay.on { display: flex; }
.callwho { text-align: center; }
.big-name { font-size: 32px; font-weight: 600; margin: 0 0 4px; word-break: break-word; unicode-bidi: plaintext; }
.state { margin-top: 10px; color: #c7c7cc; font-size: 17px; font-variant-numeric: tabular-nums; }
.callbuttons { display: flex; justify-content: space-around; }
.callbuttons.grid { display: grid; grid-template-columns: repeat(3, 1fr); row-gap: 26px; justify-items: center; }
.callbuttons.grid .cb.end { grid-column: 2; }
#speaker svg path:first-child { fill: currentColor; }
#speaker:not(.on) .wave { opacity: .45; }
.route-note { margin-top: 6px; color: #8e8e93; font-size: 13px; min-height: 16px; }
.cb { display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 14px; color: #c7c7cc; }
.round { width: 76px; height: 76px; border-radius: 38px; display: flex; align-items: center; justify-content: center; color: #fff; }
.round svg { width: 32px; height: 32px; }
.round.red { background: var(--red); }
.round.green { background: var(--green); }
.round.red svg, .round.green svg { fill: #fff; stroke: none; }
.round.glass { background: rgba(255, 255, 255, .16); }
.round.glass.on { background: #fff; color: #000; }
.incall-keys { display: none; }
.incall-keys.on { display: grid; }
.incall-keys button { background: rgba(255, 255, 255, .16); }
body.in-thread main#scroller { padding-bottom: 8px; }

body.typing nav#tabs, body.typing .fab { display: none !important; }
.dialwho { min-height: 20px; margin-top: -8px; }
.padfoot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 2px; }
.padfoot .simpick { width: auto; padding: 0 12px; }
.sheet.tall { height: 88lvh; }
.sheethead { display: flex; align-items: center; justify-content: space-between; }
.sheethead b { font-size: 20px; }
.textbtn { color: var(--accent); font-size: 17px; font-weight: 600; min-height: 44px; padding: 0 4px; }
#c-list { flex: 1; overflow-y: auto; min-height: 0; margin: 0 -4px; }
#c-list .item { min-height: 60px; padding: 6px 4px; }
#c-list .avatar { width: 40px; height: 40px; font-size: 15px; }
#contacts .empty { margin-top: 30px; }
.filebtn { display: flex; align-items: center; justify-content: center; position: relative; }
.filebtn input { position: absolute; inset: 0; opacity: 0; }
.small { font-size: 13px; line-height: 1.4; margin: 0; }
.newto .icon-btn { margin-right: -10px; }

/* ---- a code on its way: rings going out, as a signal does, over where the answer will be ---- */
.u-wait { display: none; flex-direction: column; gap: 14px; }
.u-wait.on { display: flex; }
.u-row { display: flex; align-items: center; gap: 14px; }
#u-stage { font-size: 17px; }
#u-secs { font-variant-numeric: tabular-nums; }
.pulse { position: relative; width: 44px; height: 44px; flex: none; }
.pulse b { position: absolute; left: 50%; top: 50%; width: 10px; height: 10px; margin: -5px; border-radius: 50%; background: var(--accent); }
.pulse i {
  position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--accent);
  opacity: 0; transform: scale(.25); animation: ring 1.6s linear infinite;
}
.pulse i:nth-child(2) { animation-delay: .53s; }
.pulse i:nth-child(3) { animation-delay: 1.06s; }
@keyframes ring { 0% { opacity: .6; transform: scale(.25); } 100% { opacity: 0; transform: scale(1); } }
.shimmer { display: flex; flex-direction: column; gap: 8px; }
.shimmer span {
  height: 12px; border-radius: 6px; width: 100%;
  background: linear-gradient(90deg, #2c2c2e 0%, #48484a 50%, #2c2c2e 100%) 0 0 / 200% 100%;
  animation: shine 1.3s ease-in-out infinite;
}
.shimmer span.short { width: 60%; }
@keyframes shine { 0% { background-position: 150% 0; } 100% { background-position: -50% 0; } }
@media (prefers-reduced-motion: reduce) { .pulse i, .shimmer span { animation: none; } .pulse i { opacity: .3; transform: none; } }
