/* =========================================================================
   AG app shell — mobile first. Nothing here assumes a mouse or a wide screen.

   Layout is a three-row grid: header / scrolling pane / tab bar. Only the
   middle row scrolls, so the tab bar stays put when the iOS keyboard opens
   and the header never slides away mid-scroll.

   Visual language: frosted-glass chrome over a slowly drifting ambient
   background, one gradient accent, stroke icons from the sprite in
   index.html. Logical properties (inline-start/end) throughout so an RTL
   pass is a `dir` flip, not a rewrite.
   ========================================================================= */

.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;   /* dvh, not vh: vh is wrong while iOS Safari's bars animate */
  max-width: var(--container);
  margin: 0 auto;
}

/* ===================== Glass chrome ===================== */

.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(1.5);
  backdrop-filter: blur(var(--blur)) saturate(1.5);
}

/* ===================== Header ===================== */

.hdr {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s2) var(--s4);
  padding-top: calc(var(--s2) + env(safe-area-inset-top));
  border-bottom: 1px solid var(--glass-border);
}

.hdr__mark {
  display: grid;
  place-items: center;
  width: 36px; height: 36px;
  border-radius: 12px;
  background: var(--accent-grad);
  color: var(--on-accent);
  box-shadow: var(--accent-glow);
  flex: none;
}

.hdr__mark .ic { width: 22px; height: 22px; stroke-width: 2; }

.hdr__title {
  flex: 1;
  min-width: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.hdr__sub {
  display: inline-flex;
  align-items: center;
  margin-top: 2px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--muted);
}

/* ===================== Panes ===================== */

.pane {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: var(--s4);
  padding-bottom: var(--s6);
  animation: fade-in var(--t) var(--ease);
}

.pane[hidden] { display: none; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

.stack { display: flex; flex-direction: column; gap: var(--s4); }

/* ===================== Cards ===================== */

.card {
  position: relative;
  background: var(--elevated);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  padding: var(--s4);
  box-shadow: var(--elev);
}

.card__label {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: var(--s3);
}

.card__label .ic {
  width: 16px; height: 16px;
  stroke-width: 2;
  color: var(--accent-ink);
}

.muted { color: var(--muted); font-size: 14px; }

/* ===================== Controls =====================
   44px min touch target throughout — below that, thumbs miss. Press feedback
   is a scale, never a layout change. */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: 46px;
  padding: 0 var(--s4);
  border: 1px solid var(--hairline);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: transform var(--t-fast) var(--ease),
              background-color var(--t-fast) var(--ease),
              border-color var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease),
              opacity var(--t-fast) var(--ease);
}

.btn .ic { width: 20px; height: 20px; }

.btn:active { transform: scale(0.96); }

/* A button that cannot do anything must not look like it can — the call
   buttons are disabled until the partner's device exists. */
.btn:disabled {
  opacity: 0.42;
  cursor: default;
  transform: none;
  box-shadow: none;
}

.btn--accent {
  background: var(--accent-grad);
  color: var(--on-accent);
  border-color: transparent;
  font-weight: 650;
  box-shadow: var(--accent-glow);
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.btn--icon {
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 50%;
  line-height: 1;
}

.btn--block { width: 100%; }

.btn--quiet-danger {
  background: transparent;
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
}

/* Toggle buttons carry two icons; the class the JS already toggles decides
   which one shows. No JS string swapping, no emoji. */
.ic--on { display: none; }
.btn--muted-on .ic--off,
.btn--video-on .ic--off { display: none; }
.btn--muted-on .ic--on,
.btn--video-on .ic--on { display: inline-block; }

/* Theme toggle: show the icon for the theme you would switch TO. */
.ic--sun { display: none; }
:root[data-theme="dark"] .ic--sun { display: inline-block; }
:root[data-theme="dark"] .ic--moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ic--sun { display: inline-block; }
  :root:not([data-theme="light"]) .ic--moon { display: none; }
}

/* Busy state (photo upload): the icon fades and a ring spins in its place. */
.is-busy { color: transparent !important; pointer-events: none; }
.is-busy::after {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  width: 18px; height: 18px;
  margin: -9px 0 0 -9px;
  border-radius: 50%;
  border: 2px solid var(--muted);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===================== Tab bar ===================== */

.tabbar {
  position: relative;
  z-index: 5;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  border-top: 1px solid var(--glass-border);
  padding: var(--s1) var(--s3);
  padding-bottom: calc(var(--s1) + env(safe-area-inset-bottom));
}

.tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: var(--tabbar-h);
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  font-weight: 550;
  letter-spacing: 0.01em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color var(--t-fast) var(--ease);
}

.tab__icon {
  display: grid;
  place-items: center;
  width: 52px; height: 30px;
  border-radius: var(--r-pill);
  transition: background-color var(--t) var(--ease), transform var(--t) var(--ease);
}

.tab__icon .ic { width: 22px; height: 22px; }

.tab:active .tab__icon { transform: scale(0.92); }

.tab[aria-selected="true"] { color: var(--accent-ink); }
.tab[aria-selected="true"] .tab__icon {
  background: var(--accent-soft);
}
.tab[aria-selected="true"] .ic { stroke-width: 2.1; }

/* ===================== Status dot ===================== */

.dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted);
  margin-inline-end: var(--s2);
  vertical-align: baseline;
  flex: none;
  transition: background-color var(--t) var(--ease);
}

.dot--ok   { background: var(--ok);     box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.dot--warn { background: var(--warn);   box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 22%, transparent); }
.dot--bad  { background: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 22%, transparent); }

/* ===================== Empty state ===================== */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s3);
  height: 100%;
  min-height: 260px;
  text-align: center;
  color: var(--muted);
  padding: var(--s6) var(--s5);
}

.empty h2 { color: var(--text); }
.empty p { max-width: 28ch; }

.empty__icon {
  display: grid;
  place-items: center;
  width: 84px; height: 84px;
  border-radius: 28px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 25%, transparent);
}

.empty__icon .ic { width: 40px; height: 40px; stroke-width: 1.5; }

/* ===================== Notes / banners ===================== */

.banner {
  display: flex;
  gap: var(--s3);
  align-items: start;
  border: 1px solid var(--hairline);
  border-radius: var(--r);
  padding: var(--s3) var(--s4);
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
  background: color-mix(in srgb, var(--elevated) 60%, transparent);
}

.banner--warn {
  margin: var(--s3) var(--s4) 0;
  color: var(--text);
  background: color-mix(in srgb, var(--warn) 16%, var(--elevated));
  border-color: color-mix(in srgb, var(--warn) 40%, transparent);
  flex-shrink: 0;
}
.banner--warn #key-banner-text { flex: 1; }

code {
  font-family: var(--ff-mono);
  font-size: 0.9em;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-sm);
  padding: 1px 5px;
}

/* ===================== Login gate ===================== */

.gate {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: var(--s5) var(--s4);
  padding-top: calc(var(--s5) + env(safe-area-inset-top));
  padding-bottom: calc(var(--s5) + env(safe-area-inset-bottom));
}

.gate__card {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  width: 100%;
  max-width: 400px;
  padding: var(--s6) var(--s5);
  text-align: center;
  border-radius: var(--r-xl);
  border: 1px solid var(--glass-border);
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(1.4);
  backdrop-filter: blur(var(--blur)) saturate(1.4);
  box-shadow: var(--elev-lift);
  animation: gate-in var(--t-slow) var(--ease);
}

@keyframes gate-in {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to   { opacity: 1; transform: none; }
}

.gate__mark {
  display: flex;
  justify-content: center;
  margin-bottom: var(--s2);
  color: var(--accent-ink);
}

/* The two rings draw themselves in on first paint. Pure stroke animation;
   the mark is the brand, so it earns the one decorative motion here. */
.gate__mark svg circle {
  stroke-dasharray: 836;
  stroke-dashoffset: 836;
  animation: draw 1.1s var(--ease) forwards;
}
.gate__mark svg circle:nth-child(2) { animation-delay: 160ms; }

@keyframes draw { to { stroke-dashoffset: 0; } }

.gate__card h1 {
  font-size: 32px;
  letter-spacing: -0.03em;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.gate__card .gate__tag { margin-bottom: var(--s3); }

.gate__card .btn--block { margin-top: var(--s2); }

/* ===================== Fields ===================== */

.field { display: block; text-align: start; }

.field__label {
  display: block;
  font-size: 13px;
  font-weight: 550;
  color: var(--muted);
  margin-bottom: var(--s1);
}

.input {
  width: 100%;
  min-height: 48px;
  padding: 0 var(--s4);
  /* --control, not --hairline: a hairline border on an input fails 3:1. */
  border: 1px solid var(--control);
  border-radius: var(--r-input);
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  color: var(--text);
  /* 16px minimum, or iOS zooms the whole page when the field is focused. */
  font: inherit;
  font-size: 16px;
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease),
              background-color var(--t-fast) var(--ease);
}

.input::placeholder { color: var(--muted); opacity: 0.8; }

.input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--elevated);
  box-shadow: var(--elev-glow);
}

.field__error {
  color: var(--danger);
  font-size: 14px;
  text-align: start;
}

/* ===================== Chat ===================== */

.pane--chat {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  animation: none;
}

.thread {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: var(--s1);
  padding: var(--s4);
  padding-bottom: var(--s5);
}

.bubble {
  position: relative;
  max-width: 78%;
  /* A long press has to mean "open the actions", not "start selecting text".
     Scoped to touch so a desktop mouse can still select and copy normally. */
  -webkit-touch-callout: none;
  padding: 9px 14px 7px;
  border-radius: var(--r-lg);
  line-height: 1.42;
  overflow-wrap: anywhere;
  animation: rise var(--t) var(--ease);
  transform-origin: bottom;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

@media (pointer: coarse) {
  .bubble { -webkit-user-select: none; user-select: none; }
}

/* The bubble held down for the action sheet, so it is obvious which one. */
.bubble--held { filter: brightness(1.12); transform: scale(0.985); }

/* Consecutive bubbles from the same side sit closer together. */
.bubble--them + .bubble--them,
.bubble--me + .bubble--me { margin-top: -1px; }

.bubble--them {
  align-self: start;
  background: var(--bubble-them);
  border: 1px solid var(--bubble-them-border);
  border-end-start-radius: var(--r-sm);
  box-shadow: var(--elev);
}

.bubble--me {
  align-self: end;
  background: var(--accent-grad);
  color: var(--on-accent);
  border-end-end-radius: var(--r-sm);
  box-shadow: var(--accent-glow);
}

/* A soft top highlight gives the gradient bubble a little volume. */
.bubble--me::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, rgb(255 255 255 / 0.18), transparent 45%);
  pointer-events: none;
}

.bubble--bad {
  align-self: start;
  background: transparent;
  border: 1px dashed color-mix(in srgb, var(--danger) 55%, transparent);
  color: var(--danger);
  font-size: 14px;
}

.bubble__ticks {
  margin-inline-start: 4px;
  font-size: 11px;
  letter-spacing: -0.12em;
  opacity: 0.7;
}

/* The timestamp gets its own line below the message, smaller and dimmer, so
   it never reads as part of what was written. `text-align: end` is logical,
   so it stays on the trailing edge in Arabic too. */
.bubble__time {
  display: block;
  margin-top: 5px;
  font-size: 11px;
  line-height: 1;
  text-align: end;
  opacity: 0.62;
  font-variant-numeric: tabular-nums;
  unicode-bidi: isolate;
}

/* ===================== Typing indicator ===================== */

/* Rides on the call/state poll that already runs every 3s, so it costs the
   receiving phone no extra requests. */
.typing {
  align-self: start;
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  padding: 10px 14px;
  border-radius: var(--r-lg);
  border-end-start-radius: var(--r-sm);
  background: var(--bubble-them);
  border: 1px solid var(--bubble-them-border);
  box-shadow: var(--elev);
  color: var(--muted);
  font-size: 12px;
  animation: rise var(--t) var(--ease);
}

/* .typing sets display, so [hidden] alone would not hide it. */
.typing[hidden] { display: none; }

.typing__dots { display: inline-flex; gap: 3px; }

.typing__dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: typing-bounce 1.3s var(--ease) infinite;
}

.typing__dots i:nth-child(2) { animation-delay: 0.16s; }
.typing__dots i:nth-child(3) { animation-delay: 0.32s; }

@keyframes typing-bounce {
  0%, 62%, 100% { opacity: 0.32; transform: none; }
  31%           { opacity: 1;    transform: translateY(-3px); }
}

@media (prefers-reduced-motion: reduce) {
  .typing__dots i { animation: none; opacity: 0.55; }
}

.bubble__temp {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
  font-size: 11px;
  opacity: 0.8;
}

.bubble--gone {
  background: transparent !important;
  border: 1px dashed var(--hairline);
  color: var(--muted);
  font-style: italic;
  font-size: 13px;
  box-shadow: none !important;
}
.bubble--once-wait { cursor: pointer; }
.bubble__tap {
  display: block;
  width: 100%;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 550;
  text-align: start;
  cursor: pointer;
  padding: 4px 0;
}

/* ---- Composer ---- */

.composer-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  padding: 6px var(--s4);
  font-size: 12px;
  font-weight: 550;
  text-align: center;
  color: var(--on-accent);
  background: var(--accent-grad);
}

.composer {
  position: relative;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2) var(--s3);
  padding-bottom: calc(var(--s2) + env(safe-area-inset-bottom) / 2);
  border-top: 1px solid var(--glass-border);
}

.composer__input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  border-radius: var(--r-pill);
  border-color: var(--hairline);
  background: var(--surface);
}

.composer__aux {
  flex: none;
  color: var(--muted);
  background: transparent;
  border-color: transparent;
  font-size: 15px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.composer__aux .ic { width: 22px; height: 22px; }

.composer__send {
  flex: none;
  width: 44px;
}

.composer__send .ic { width: 22px; height: 22px; stroke-width: 2.25; }

/* Lit up whenever messages are set to disappear, so the mode can never be
   on without it being obvious. */
.composer__aux--on {
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
  font-size: 13px;
}

.composer-bar--voice {
  justify-content: space-between;
  background: var(--accent-grad);
}

.voice {
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-width: 180px;
  padding: 4px 2px;
}

.voice__play {
  flex: none;
  width: 40px;
  height: 40px;
  min-height: 40px;
  background: color-mix(in srgb, currentColor 14%, transparent);
  border-color: transparent;
}

.voice__meta { flex: 1; min-width: 0; }

.voice__bar {
  height: 4px;
  border-radius: 2px;
  background: color-mix(in srgb, currentColor 22%, transparent);
  overflow: hidden;
  margin-bottom: 4px;
}

.voice__fill {
  height: 100%;
  width: 0;
  background: currentColor;
}

.voice__dur {
  font-size: 11px;
  opacity: 0.8;
  font-variant-numeric: tabular-nums;
}

/* ===================== Photos & disappearing ===================== */

.bubble--photo { padding: 4px; overflow: hidden; }
.bubble--photo .bubble__time {
  position: absolute;
  bottom: 8px;
  inset-inline-end: 10px;
  margin: 0;
  padding: 2px 7px;
  border-radius: var(--r-pill);
  background: rgb(0 0 0 / 0.45);
  color: #fff;
  opacity: 1;
}

.bubble__img {
  display: block;
  max-width: 100%;
  width: 240px;
  border-radius: calc(var(--r-lg) - 4px);
  background: var(--surface);
  cursor: pointer;
}

.bubble__pending {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 240px;
  height: 170px;
  border-radius: calc(var(--r-lg) - 4px);
  background:
    linear-gradient(110deg, transparent 30%, rgb(255 255 255 / 0.08) 50%, transparent 70%),
    var(--surface);
  background-size: 200% 100%, auto;
  animation: shimmer 1.6s linear infinite;
  color: var(--muted);
  font-size: 13px;
}

@keyframes shimmer { to { background-position: -200% 0, 0 0; } }

/* Full-screen photo viewer */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--scrim);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  padding: var(--s4);
  animation: fade-in var(--t-fast) var(--ease);
}

.lightbox[hidden] { display: none; }

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--r);
  box-shadow: var(--elev-lift);
}

.lightbox__close {
  position: absolute;
  top: calc(var(--s4) + env(safe-area-inset-top));
  inset-inline-end: var(--s4);
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  min-height: 44px;
  border-radius: 50%;
  background: rgb(255 255 255 / 0.14);
  border: 1px solid rgb(255 255 255 / 0.18);
  color: #fff;
  cursor: pointer;
}

/* ===================== Action sheet ===================== */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

/* .sheet sets display, so [hidden] alone would not hide it. */
.sheet[hidden] { display: none; }

.sheet__scrim {
  position: absolute;
  inset: 0;
  background: var(--scrim);
  animation: fade-in var(--t-fast) var(--ease);
}

.sheet__panel {
  position: relative;
  width: min(420px, 100%);
  margin: var(--s3);
  margin-bottom: calc(var(--s3) + env(safe-area-inset-bottom));
  padding: var(--s2);
  border-radius: var(--r-xl);
  background: var(--elevated);
  border: 1px solid var(--hairline);
  box-shadow: var(--elev-lift);
  animation: sheet-up var(--t) var(--ease);
}

@keyframes sheet-up {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: none; }
}

.sheet__item {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  min-height: 48px;
  padding: 0 var(--s3);
  border: 0;
  border-radius: var(--r);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 550;
  text-align: start;
  cursor: pointer;
}

.sheet__item[hidden] { display: none; }
.sheet__item:hover { background: color-mix(in srgb, currentColor 9%, transparent); }
.sheet__item--danger { color: var(--danger); }

.sheet__item--cancel {
  justify-content: center;
  margin-top: 2px;
  color: var(--muted);
  font-weight: 500;
}

/* ===================== Segmented control ===================== */

.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: var(--r-pill);
  background: var(--surface);
  border: 1px solid var(--hairline);
}

.seg__btn {
  min-height: 40px;
  border: 0;
  border-radius: var(--r-pill);
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease);
}

.seg__btn[aria-pressed="true"] {
  background: var(--elevated);
  color: var(--text);
  box-shadow: var(--elev);
}

/* Day separators, WhatsApp style: a centred pill, not a full-width rule. */
.daysep { align-self: center; margin: var(--s3) 0 var(--s2); }

.daysep span {
  display: inline-block;
  padding: 3px var(--s3);
  border-radius: var(--r-pill);
  background: var(--glass);
  border: 1px solid var(--glass-border);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: var(--muted);
  font-size: 12px;
  font-weight: 550;
}

/* ===================== Safety code ===================== */

.safety {
  font-family: var(--ff-mono);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-align: center;
  padding: var(--s4);
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--hairline);
  overflow-wrap: anywhere;
  color: var(--accent-ink);
  direction: ltr;
  unicode-bidi: isolate;
}

/* ===================== Avatars ===================== */

.avatar {
  position: relative;
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  margin: 0 auto var(--s3);
  border-radius: 50%;
  background: var(--accent-grad);
  color: var(--on-accent);
  box-shadow: var(--accent-glow), inset 0 0 0 1px rgb(255 255 255 / 0.25);
  flex: none;
}

.avatar .ic { width: 44px; height: 44px; stroke-width: 1.6; }

/* ===================== Call card ===================== */

.call-card { text-align: center; padding-top: var(--s5); }
.call-card h2 { margin-bottom: var(--s1); font-size: 22px; }
.call-card .stack { margin-top: var(--s5); gap: var(--s3); }

/* ===================== Call screen ===================== */

.callscreen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: var(--s5) var(--s4);
  padding-bottom: calc(var(--s6) + env(safe-area-inset-bottom));
  animation: fade-in var(--t) var(--ease);
}

.callscreen[hidden] { display: none; }

/* Its own ambient field, centred on the avatar. */
.callscreen::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(60vmax 60vmax at 50% 30%, var(--aurora-1), transparent 60%),
    radial-gradient(50vmax 50vmax at 80% 100%, var(--aurora-2), transparent 60%);
  pointer-events: none;
  z-index: 0;
}

.callscreen__inner {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s2);
  text-align: center;
  width: 100%;
  max-width: 400px;
}

.callscreen__avatar {
  width: 132px;
  height: 132px;
  margin-bottom: var(--s4);
}
.callscreen__avatar .ic { width: 60px; height: 60px; }

.callscreen__name { font-size: 28px; letter-spacing: -0.025em; }
.callscreen__state { color: var(--muted); font-size: 16px; }

.callscreen__quality {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px 4px 10px;
  border-radius: var(--r-pill);
  border: 1px solid var(--glass-border);
  background: var(--glass);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  font-size: 13px;
  font-weight: 550;
  color: var(--muted);
}

.callscreen__notice {
  font-size: 13px;
  color: var(--warn);
  margin-top: var(--s2);
  max-width: 34ch;
}

/* ---- Controls: round glass buttons with a caption underneath ---- */

/* Five controls (mute, speaker, camera, flip, end) must sit in ONE row on a
   390px phone: 5 × 64 + 4 × 8 = 352 inside 358 of usable width. The row is
   allowed to be wider than the text column above it. */
.callscreen__actions {
  display: flex;
  flex-wrap: nowrap;
  gap: var(--s2);
  justify-content: center;
  width: 100%;
  max-width: 460px;
  margin-top: var(--s7);
}

.callscreen__actions[hidden] { display: none; }

/* The JS hides individual buttons (speaker where unsupported, flip while the
   camera is off); the caption must go with them. */
.ctl:has(> .btn[hidden]) { display: none; }

.ctl {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 64px;
  font-size: 11px;
  font-weight: 550;
  color: var(--muted);
  flex: none;
}

.btn--round {
  width: 60px;
  height: 60px;
  min-height: 60px;
  padding: 0;
  border-radius: 50%;
  flex: none;
  background: var(--glass-strong);
  border-color: var(--glass-border);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: var(--elev);
}

.btn--round .ic { width: 26px; height: 26px; }

/* A ringing screen has exactly two decisions: make them big and far apart. */
.callscreen__actions--incoming { gap: var(--s8); }
.callscreen__actions--incoming .ctl { width: 80px; }
.callscreen__actions--incoming .btn--round { width: 76px; height: 76px; min-height: 76px; }
.callscreen__actions--incoming .btn--round .ic { width: 32px; height: 32px; }

.btn--danger {
  background: var(--danger);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 12px 30px -10px color-mix(in srgb, var(--danger) 70%, transparent);
}

.btn--ok {
  background: var(--ok);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 12px 30px -10px color-mix(in srgb, var(--ok) 70%, transparent);
}

/* Hang-up: the handset turned down. */
.ic--hangup { transform: rotate(135deg); }

.btn--muted-on {
  background: var(--warn);
  color: #17130a;
  border-color: transparent;
}

.btn--video-on {
  background: var(--accent-grad) !important;
  color: var(--on-accent) !important;
  border-color: transparent !important;
  box-shadow: var(--accent-glow) !important;
}

/* ---- Ringing: expanding rings behind the avatar ---- */

.callscreen--ringing .callscreen__avatar::before,
.callscreen--ringing .callscreen__avatar::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--accent) 60%, transparent);
  animation: ring 2.2s var(--ease) infinite;
  pointer-events: none;
}
.callscreen--ringing .callscreen__avatar::after { animation-delay: 0.9s; }

@keyframes ring {
  from { transform: scale(1); opacity: 0.9; }
  to   { transform: scale(1.75); opacity: 0; }
}

.callscreen--ringing .callscreen__avatar {
  animation: breathe 2.2s var(--ease) infinite;
}

@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.04); }
}

.callscreen--ringing .btn--ok { animation: nudge 1.6s var(--ease) infinite; }

@keyframes nudge {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-4px); }
}

/* ===================== Video ===================== */

.callscreen__remote {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* cover, not contain: a portrait phone filling a portrait screen. The
     alternative is two black bars on every call. */
  object-fit: cover;
  background: #000;
  z-index: 0;
}

.callscreen__local {
  position: absolute;
  top: calc(var(--s4) + env(safe-area-inset-top));
  inset-inline-end: var(--s4);
  width: 104px;
  height: 140px;
  object-fit: cover;
  border-radius: var(--r);
  border: 1px solid rgb(255 255 255 / 0.3);
  background: #000;
  box-shadow: var(--elev-lift);
  z-index: 2;
  /* Mirrored, because an unmirrored view of yourself reads as wrong. */
  transform: scaleX(-1);
}

/* With video up, the controls float over it and need their own contrast. */
.callscreen--video::before { display: none; }

.callscreen--video .callscreen__inner {
  position: absolute;
  inset-inline: 0;
  bottom: calc(var(--s6) + env(safe-area-inset-bottom));
  z-index: 3;
  gap: var(--s1);
  color: #fff;
  text-shadow: 0 1px 8px rgb(0 0 0 / 0.7);
}

.callscreen--video .callscreen__avatar { display: none; }
.callscreen--video .callscreen__state,
.callscreen--video .callscreen__quality,
.callscreen--video .ctl { color: rgb(255 255 255 / 0.88); }
.callscreen--video .callscreen__quality {
  background: rgb(0 0 0 / 0.35);
  border-color: rgb(255 255 255 / 0.2);
}

.callscreen--video .callscreen__actions .btn:not(.btn--danger):not(.btn--ok):not(.btn--video-on):not(.btn--muted-on) {
  background: rgb(255 255 255 / 0.16);
  border-color: rgb(255 255 255 / 0.28);
  color: #fff;
}

.callscreen--video .callscreen__notice { color: #ffd479; }

/* Narrow phones: 5 × 56 + 4 × 4 = 296 inside 328 on a 360px screen. */
@media (max-width: 370px) {
  .callscreen__actions { gap: var(--s1); }
  .ctl { width: 56px; }
  .btn--round { width: 52px; height: 52px; min-height: 52px; }
  .btn--round .ic { width: 22px; height: 22px; }
  .callscreen__actions--incoming { gap: var(--s7); }
}

/* ===================== Diagnostics list ===================== */

.diag { display: flex; flex-direction: column; gap: 0; }
.diag p {
  display: flex;
  align-items: center;
  padding: var(--s2) 0;
  border-bottom: 1px solid var(--hairline);
}
.diag p:last-child { border-bottom: 0; }

/* ===================== Wide screens =====================
   A phone app on a tablet or desktop: keep the phone proportions, float the
   shell as a device-like panel instead of stretching it edge to edge. */

@media (min-width: 760px) {
  .app {
    height: min(100dvh, 960px);
    margin: max(0px, calc((100dvh - 960px) / 2)) auto;
    max-width: 520px;
    border-radius: var(--r-xl);
    overflow: hidden;
    border: 1px solid var(--glass-border);
    box-shadow: var(--elev-lift);
    background: color-mix(in srgb, var(--bg) 85%, transparent);
  }

  .hdr { padding-top: var(--s3); }

  .callscreen {
    max-width: 520px;
    height: min(100dvh, 960px);
    margin: auto;
    border-radius: var(--r-xl);
    overflow: hidden;
    inset: 0;
  }
}
