/* Family Call
   Operate mode: the video is the content, the interface gets out of its way.
   Dark by use-scene — these calls happen at home in the evening.
   System font stack on purpose: Google Fonts is unreliable from Iran, and a
   webfont that half-loads is worse than none. */

:root {
  --bg:        #0a0c10;
  --surface:   #12161d;
  --raised:    #1a202a;
  --raised-2:  #232b38;
  --line:      #262e3b;
  --line-soft: #1d242f;

  --fg:        #e8edf5;
  --fg-2:      #a9b6c9;
  --fg-3:      #7f8ea3;

  --accent:    #4fd1b5;
  --accent-dk: #0e3d36;
  --good:      #3dd68c;
  --warn:      #f5b544;
  --bad:       #ff5f5f;
  --bad-dk:    #3d1618;

  --r-sm: 8px;
  --r:    12px;
  --r-lg: 18px;
  --r-pill: 999px;

  --shadow: 0 8px 24px -8px rgb(0 0 0 / .7), 0 2px 6px -2px rgb(0 0 0 / .5);
  --ease: cubic-bezier(.22, 1, .36, 1);

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

/* [hidden] loses to any class selector on source order alone, which silently
   leaves every "hidden" screen stacked on the page. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Tahoma, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* Browser surfaces belong to the design too. */
::selection { background: var(--accent); color: #05201b; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
* { scrollbar-width: thin; scrollbar-color: var(--raised-2) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--raised-2); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8;
      stroke-linecap: round; stroke-linejoin: round; flex: none; display: block; }
.ic--lg { width: 28px; height: 28px; }

/* ══════════════════════════════════  Join  ═════════════════════════════ */

.join {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: calc(28px + var(--safe-t)) 20px calc(28px + var(--safe-b));
  /* A single soft light source behind the card, not a decorative gradient. */
  background:
    radial-gradient(60rem 40rem at 50% -10%, #101a22 0%, transparent 70%),
    var(--bg);
}

.card {
  width: min(392px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 30px 28px 26px;
  display: grid;
  gap: 16px;
  box-shadow: var(--shadow);
}

.card__mark {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  border-radius: 14px;
  background: var(--accent-dk);
  color: var(--accent);
  margin-bottom: 2px;
}

.card h1 { margin: 0; font-size: 25px; line-height: 1.15; letter-spacing: -.025em; font-weight: 620; }
.card .sub { margin: -10px 0 6px; color: var(--fg-3); font-size: 14px; }

.field { display: grid; gap: 7px; font-size: 13px; color: var(--fg-2); font-weight: 500; }

input[type="text"], input[type="password"], select {
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 0 12px;
  height: 46px;
  color: var(--fg);
  width: 100%;
  appearance: none;
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
input::placeholder { color: var(--fg-3); }
input:hover, select:hover { border-color: var(--raised-2); }
input:focus, select:focus { border-color: var(--accent); outline: none; background: var(--surface); }

select {
  background-image: linear-gradient(45deg, transparent 50%, var(--fg-3) 50%),
                    linear-gradient(135deg, var(--fg-3) 50%, transparent 50%);
  background-position: calc(100% - 17px) 21px, calc(100% - 12px) 21px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

/* Custom checkbox so the control matches the icon set. */
.toggles { display: flex; gap: 18px; }
.toggles--wrap { flex-wrap: wrap; gap: 10px 18px; }

.toggle {
  display: inline-flex; align-items: center; gap: 9px;
  font-size: 13.5px; color: var(--fg-2); cursor: pointer;
  min-height: 34px; user-select: none;
}
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle__box {
  width: 21px; height: 21px; flex: none;
  border: 1.5px solid var(--line); border-radius: 6px;
  background: var(--raised);
  display: grid; place-items: center;
  color: transparent;
  transition: background .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease);
}
.toggle__box .ic { width: 13px; height: 13px; stroke-width: 2.6; }
.toggle input:checked + .toggle__box { background: var(--accent); border-color: var(--accent); color: #05201b; }
.toggle input:focus-visible + .toggle__box { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle:hover .toggle__box { border-color: var(--fg-3); }

.btn {
  border: 0; border-radius: var(--r-sm);
  height: 48px; padding: 0 18px;
  font-weight: 600; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: filter .15s var(--ease), transform .08s var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--accent); color: #05201b; }
.btn--primary:hover { filter: brightness(1.08); }
.btn--primary:disabled { opacity: .5; cursor: progress; transform: none; }
.btn--quiet {
  background: var(--raised); color: var(--fg-2);
  border: 1px solid var(--line); height: 42px; font-size: 14px; font-weight: 500;
}
.btn--quiet:hover { background: var(--raised-2); color: var(--fg); }

.msg { margin: 0; font-size: 13px; min-height: 18px; color: var(--bad); }

/* ══════════════════════════════════  Call  ═════════════════════════════ */

.call {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;   /* minmax(0,·) or the stage
                                                     refuses to shrink and
                                                     pushes controls offscreen */
  padding-top: var(--safe-t);
}

/* ─────────────────────────────────  Topbar  ──────────────────────────── */

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface);
  min-height: 52px;
}

.topbar__id { display: flex; align-items: center; gap: 9px; font-size: 14px; min-width: 0; }
.topbar__id strong { font-weight: 600; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar__people { display: inline-flex; align-items: center; gap: 5px; color: var(--fg-3); font-size: 13px;
                  font-variant-numeric: tabular-nums; }
.topbar__people .ic { width: 16px; height: 16px; }
.topbar__actions { margin-left: auto; display: flex; gap: 4px; }

.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--fg-3); flex: none;
  transition: background .3s var(--ease), box-shadow .3s var(--ease);
}
.dot.ok   { background: var(--good); box-shadow: 0 0 0 3px rgb(61 214 140 / .16); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px rgb(245 181 68 / .16); }
.dot.bad  { background: var(--bad);  box-shadow: 0 0 0 3px rgb(255 95 95 / .16); }

.gstats {
  margin-left: auto;
  display: flex; gap: 14px;
  font: 500 11.5px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--fg-3);
  white-space: nowrap; overflow-x: auto; scrollbar-width: none;
  font-variant-numeric: tabular-nums;
}
.gstats::-webkit-scrollbar { display: none; }
.gstats b { color: var(--fg-2); font-weight: 600; }
.gstats + .topbar__actions { margin-left: 12px; }

.iconbtn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  background: transparent; border: 0; border-radius: var(--r-sm);
  color: var(--fg-3);
  transition: background .15s var(--ease), color .15s var(--ease);
}
.iconbtn:hover { background: var(--raised); color: var(--fg); }
.iconbtn[aria-pressed="true"] { background: var(--accent-dk); color: var(--accent); }

/* ──────────────────────────────────  Stage  ──────────────────────────── */

.stage { display: grid; min-height: 0; overflow: hidden; }
.stage[data-layout="grid"]      { grid-template-rows: 1fr; }
.stage[data-layout="spotlight"] { grid-template-rows: minmax(0,1fr) auto; }

.grid {
  display: grid;
  gap: 10px;
  padding: 10px;
  min-height: 0;
  overflow: auto;
  align-content: center;
  justify-content: center;
  grid-auto-rows: 1fr;
  grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr));
}

/* Spotlight: one tile owns the stage, the rest become a filmstrip. */
.stage[data-layout="spotlight"] .grid { padding: 10px 10px 0; }
.strip {
  display: flex; gap: 8px;
  padding: 8px 10px calc(8px);
  overflow-x: auto; overflow-y: hidden;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}
.strip::-webkit-scrollbar { display: none; }
.strip .tile { flex: 0 0 clamp(116px, 19vw, 196px); scroll-snap-align: start; }

/* ──────────────────────────────────  Tile  ───────────────────────────── */

.tile {
  position: relative;
  background: #000;
  border-radius: var(--r);
  overflow: hidden;
  aspect-ratio: 16 / 9;
  min-height: 0;
  isolation: isolate;
  transition: box-shadow .2s var(--ease);
}
.tile::after {                       /* single elevation source: an inset hairline */
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / .07);
  pointer-events: none; z-index: 3;
}
.tile.is-speaking::after { box-shadow: inset 0 0 0 2px var(--accent); }

.tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }
.tile.is-self video { transform: scaleX(-1); }
.tile.is-self.is-sharing video { transform: none; }
.tile.is-novideo video { visibility: hidden; }

.tile__avatar {
  position: absolute; inset: 0; display: none; place-items: center;
  background: linear-gradient(160deg, var(--raised) 0%, var(--surface) 100%);
}
.tile.is-novideo .tile__avatar { display: grid; }
.tile__initial {
  width: clamp(44px, 22%, 84px); aspect-ratio: 1;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--raised-2);
  color: var(--fg-2);
  font-size: clamp(18px, 9cqw, 32px); font-weight: 600;
  letter-spacing: .01em;
}

.tile__name {
  position: absolute; left: 9px; bottom: 9px; z-index: 4;
  background: rgb(6 8 11 / .66);
  backdrop-filter: blur(10px);
  padding: 4px 9px; border-radius: var(--r-sm);
  font-size: 12.5px; font-weight: 500;
  display: flex; align-items: center; gap: 6px;
  max-width: calc(100% - 18px);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tile__name .ic { width: 14px; height: 14px; color: var(--bad); }
.strip .tile__name { font-size: 11px; padding: 3px 7px; left: 6px; bottom: 6px; }

/* Per-tile metrics — off unless the user asks for them. */
.tile__hud {
  position: absolute; right: 9px; top: 9px; z-index: 4;
  background: rgb(6 8 11 / .7);
  backdrop-filter: blur(10px);
  padding: 6px 9px; border-radius: var(--r-sm);
  font: 500 10.5px/1.55 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--fg-3); text-align: right; white-space: pre;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.tile__hud b { color: var(--fg-2); font-weight: 600; }
.tile__hud .g { color: var(--good); }
.tile__hud .w { color: var(--warn); }
.tile__hud .e { color: var(--bad); }
body:not(.show-stats) .tile__hud { display: none; }
.strip .tile__hud { display: none !important; }

/* Tile actions: on hover for pointers, always on for touch. */
.tile__acts {
  position: absolute; top: 8px; left: 8px; z-index: 5;
  display: flex; gap: 5px;
  opacity: 0; transform: translateY(-4px);
  transition: opacity .18s var(--ease), transform .18s var(--ease);
}
.tile:hover .tile__acts,
.tile:focus-within .tile__acts { opacity: 1; transform: none; }
@media (hover: none) { .tile__acts { opacity: 1; transform: none; } }
.strip .tile__acts { display: none; }

.tileact {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: 0; border-radius: var(--r-sm);
  background: rgb(6 8 11 / .72);
  backdrop-filter: blur(10px);
  color: var(--fg-2);
  transition: background .15s var(--ease), color .15s var(--ease);
}
.tileact:hover { background: rgb(6 8 11 / .9); color: var(--fg); }
.tileact.is-on { background: var(--accent); color: #05201b; }
.tileact .ic { width: 16px; height: 16px; }

/* Volume popover, anchored to its tile. */
.volpop {
  position: absolute; z-index: 6;
  top: 46px; left: 8px;
  width: 176px; padding: 11px 12px 12px;
  background: rgb(12 15 20 / .95);
  backdrop-filter: blur(16px);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  display: grid; gap: 8px;
}
.volpop__row { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--fg-3); }
.volpop__row b { color: var(--fg); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ────────────────────────────────  Controls  ─────────────────────────── */

.controls {
  display: flex; justify-content: center; align-items: center;
  gap: 8px;
  padding: 12px 12px calc(12px + var(--safe-b));
  border-top: 1px solid var(--line-soft);
  background: var(--surface);
}

.pill {
  display: inline-flex; align-items: center; gap: 8px;
  height: 46px; padding: 0 17px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: var(--raised);
  color: var(--fg-2);
  font-size: 14px; font-weight: 500;
  transition: background .15s var(--ease), color .15s var(--ease),
              border-color .15s var(--ease), transform .08s var(--ease);
}
.pill:hover { background: var(--raised-2); color: var(--fg); }
.pill:active { transform: translateY(1px); }
.pill.is-off {
  background: var(--bad-dk); border-color: #5c2226; color: #ff9b9b;
}
.pill.is-on { background: var(--accent-dk); border-color: #17564c; color: var(--accent); }
.pill--leave { background: var(--bad); border-color: var(--bad); color: #2a0708; font-weight: 600; }
.pill--leave:hover { background: #ff7373; color: #2a0708; }

/* ─────────────────────────────────  Panel  ───────────────────────────── */

.scrim {
  position: fixed; inset: 0; z-index: 25;
  background: rgb(4 6 9 / .55);
  backdrop-filter: blur(2px);
  animation: fade .18s var(--ease);
}
@keyframes fade { from { opacity: 0 } }

.panel {
  position: fixed; z-index: 30;
  top: 0; right: 0; bottom: 0;
  width: min(408px, 100%);
  background: var(--surface);
  border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding-top: var(--safe-t);
  animation: slide .26s var(--ease);
  box-shadow: -16px 0 40px -20px rgb(0 0 0 / .8);
}
@keyframes slide { from { transform: translateX(24px); opacity: 0 } }

.panel__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 12px 14px 20px;
  border-bottom: 1px solid var(--line-soft);
}
.panel__head h2 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -.01em; }

.panel__tabs { display: flex; gap: 2px; padding: 10px 14px 0; border-bottom: 1px solid var(--line-soft); }
.tab {
  border: 0; background: transparent; color: var(--fg-3);
  padding: 9px 13px 11px; font-size: 13.5px; font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color .15s var(--ease), border-color .15s var(--ease);
}
.tab:hover { color: var(--fg-2); }
.tab.is-on { color: var(--accent); border-bottom-color: var(--accent); }

.panel__body { overflow-y: auto; padding: 18px 20px calc(28px + var(--safe-b)); -webkit-overflow-scrolling: touch; }
.tabpane { display: none; }
.tabpane.is-on { display: grid; gap: 26px; }

.group { display: grid; gap: 12px; }
.group__title {
  margin: 0; font-size: 11.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .07em; color: var(--fg-3);
}
.hint { margin: -3px 0 0; font-size: 12.5px; line-height: 1.55; color: var(--fg-3); }

.slider { display: grid; gap: 2px; }
.slider__row { display: flex; justify-content: space-between; align-items: baseline;
               font-size: 13px; color: var(--fg-2); font-weight: 500; }
.slider__row output { font: 600 12px/1 ui-monospace, Menlo, Consolas, monospace; color: var(--fg);
                      font-variant-numeric: tabular-nums; }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 36px; background: transparent; margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 5px; border-radius: 99px; background: var(--raised-2);
}
input[type="range"]::-moz-range-track { height: 5px; border-radius: 99px; background: var(--raised-2); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 17px; height: 17px; margin-top: -6px;
  border-radius: 50%; background: var(--accent);
  border: 3px solid var(--surface);
  box-shadow: 0 1px 4px rgb(0 0 0 / .5);
  transition: transform .12s var(--ease);
}
input[type="range"]::-moz-range-thumb {
  width: 17px; height: 17px; border-radius: 50%; background: var(--accent);
  border: 3px solid var(--surface); box-shadow: 0 1px 4px rgb(0 0 0 / .5);
}
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.15); }

/* Per-peer volume rows. */
.peervols { display: grid; gap: 14px; }
.peervols .empty { margin: 0; font-size: 13px; color: var(--fg-3); font-style: normal; }
.peervol { display: grid; gap: 1px; }
.peervol__row { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; }
.peervol__name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.peervol__val { font: 600 12px/1 ui-monospace, Menlo, Consolas, monospace; color: var(--fg-3);
                font-variant-numeric: tabular-nums; }

.diag {
  margin: 0; padding: 12px;
  background: var(--bg); border: 1px solid var(--line-soft); border-radius: var(--r-sm);
  font: 500 11px/1.6 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--fg-3); white-space: pre-wrap; word-break: break-word;
  max-height: 320px; overflow: auto;
}

/* ─────────────────────────────────  Toast  ───────────────────────────── */

.toast {
  position: fixed; left: 50%; z-index: 40;
  bottom: calc(88px + var(--safe-b));
  transform: translate(-50%, 10px);
  background: var(--raised-2);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: 10px 18px;
  font-size: 13.5px; font-weight: 500;
  opacity: 0; pointer-events: none;
  transition: opacity .22s var(--ease), transform .22s var(--ease);
  max-width: calc(100vw - 32px); text-align: center;
  box-shadow: var(--shadow);
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ══════════════════════════════════  Small screens  ════════════════════ */

@media (max-width: 560px) {
  .controls { gap: 6px; padding: 10px 8px calc(10px + var(--safe-b)); }
  .pill { padding: 0; width: 52px; height: 52px; justify-content: center; border-radius: 50%; }
  .pill__label { display: none; }              /* icon-only: five fit a phone */
  .pill .ic { width: 22px; height: 22px; }
  .pill--leave { width: 62px; }

  .panel {
    top: auto; left: 0; right: 0; bottom: 0;
    width: 100%; height: min(86vh, 660px);
    border-left: 0; border-top: 1px solid var(--line);
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    animation: sheet .28s var(--ease);
  }
  @keyframes sheet { from { transform: translateY(28px); opacity: 0 } }
  .panel__head { padding-left: 18px; }
  .panel__body { padding: 16px 18px calc(24px + var(--safe-b)); }

  .topbar { padding: 8px 10px; gap: 8px; min-height: 48px; }
  .gstats { gap: 10px; font-size: 10.5px; }
  .grid { gap: 8px; padding: 8px; }
  .toast { bottom: calc(94px + var(--safe-b)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Spotlight must actually spend the screen on one person. A 16:9 tile on a
   tall phone is capped at width×9/16 and wastes everything below it, so the
   pinned tile drops the ratio and fills the stage instead. */
.stage[data-layout="spotlight"] .grid { align-content: stretch; grid-auto-rows: minmax(0, 1fr); }
.stage[data-layout="spotlight"] .grid .tile { aspect-ratio: auto; height: 100%; min-height: 0; }
.stage[data-layout="spotlight"] .grid .tile video { object-fit: contain; }

@media (pointer: coarse) {
  input[type="range"] { height: 44px; }
}
