/* ----------------------------------------------------------------------- */
/*  4both — video calls                                                     */
/*  Dark throughout: a call is watched, not read, and bright chrome around   */
/*  someone's face is a distraction.                                        */
/* ----------------------------------------------------------------------- */

:root {
  --bg: #0b0d11;
  --panel: #14171e;
  --surface: rgba(255, 255, 255, 0.07);
  --surface-hi: rgba(255, 255, 255, 0.13);
  --border: rgba(255, 255, 255, 0.1);
  --text: #eceef3;
  --muted: #8f96a5;
  --accent: #6366f1;
  --accent-hi: #7c7ff5;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;

  /* Concentric: an inner radius plus its padding equals the outer radius.
     26 = 10 + 16, so the preview's corners sit parallel to the card's. */
  --r-card: 26px;
  --r-pad: 16px;
  --r-inner: 10px;
  --r-tile: 14px;
  --r-menu: 14px;

  /* One easing for everything that moves, one scale for every press. */
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --t-instant: 120ms;   /* colour and opacity on things pressed constantly */
  --t-swap: 200ms;      /* icon cross-fades */
  --t-enter: 280ms;     /* something arriving */
  --t-exit: 180ms;      /* exits are softer than enters */

  --bar-h: 76px;
  --gap: 10px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

button { font: inherit; cursor: pointer; border: 0; color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent-hi);
  outline-offset: 2px;
}
[hidden] { display: none !important; }

/* --------------------------------- icons -------------------------------- */

/* `<use>` clones a symbol into a shadow tree that page selectors cannot reach.
   Only inherited properties cross that boundary, and fill and stroke are
   inherited — so the icon style has to live on the <svg> itself. */
.ico {
  width: 22px; height: 22px;
  display: block;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.round.sm .ico { width: 17px; height: 17px; }
.ghost .ico { width: 18px; height: 18px; }

/* Two icons live in the same button and cross-fade, so the swap has an enter
   and an exit without any JavaScript timing. */
.toggle { position: relative; }
.toggle .ico {
  position: absolute;
  top: 50%; left: 50%;
  margin: -11px 0 0 -11px;
  transition: opacity var(--t-swap) var(--ease),
              scale var(--t-swap) var(--ease),
              filter var(--t-swap) var(--ease);
}
.round.sm.toggle .ico { margin: -8.5px 0 0 -8.5px; }
.toggle .ico-off, .toggle[aria-pressed="false"] .ico-on {
  opacity: 0;
  scale: 0.25;
  filter: blur(4px);
}
.toggle[aria-pressed="false"] .ico-off {
  opacity: 1;
  scale: 1;
  filter: blur(0);
}

/* -------------------------------- lobby --------------------------------- */

.lobby {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: max(16px, var(--safe-t)) 16px calc(16px + var(--safe-b));
}

.lobby-card {
  width: 100%;
  max-width: 400px;
  padding: var(--r-pad);
  background: var(--panel);
  border-radius: var(--r-card);
  /* Depth from layered shadow; the hairline is structure, not elevation. */
  box-shadow:
    0 0 0 1px var(--border),
    0 1px 2px rgba(0, 0, 0, 0.3),
    0 12px 32px -8px rgba(0, 0, 0, 0.5);
}

/* An entrance happens once, so the sequence can afford to say something:
   identity, then you on camera, then what to fill in. */
.stagger-1, .stagger-2, .stagger-3 { animation: rise var(--t-enter) var(--ease) backwards; }
.stagger-2 { animation-delay: 80ms; }
.stagger-3 { animation-delay: 160ms; }
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.lobby-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.logo {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  font-weight: 700; font-size: 14px; color: #fff;
}
.lobby-head h1 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.sub { margin: 0; font-size: 12px; color: var(--muted); }

.preview-wrap {
  position: relative;
  aspect-ratio: 4 / 3;
  margin-bottom: 14px;
  background: #05070a;
  border-radius: var(--r-inner);
  overflow: hidden;
  /* A hairline keeps the frame from bleeding into the card on dark content. */
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}
#preview {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity var(--t-swap) var(--ease);
}
#preview.is-off { opacity: 0; }
.mirrored { transform: scaleX(-1); }

.preview-off {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px;
  color: var(--muted); font-size: 13px;
  animation: fade var(--t-swap) var(--ease);
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.preview-controls {
  position: absolute; left: 0; right: 0; bottom: 10px;
  display: flex; justify-content: center; gap: 8px;
}

.field { margin-bottom: 12px; }
.field label { display: block; margin-bottom: 5px; font-size: 12px; color: var(--muted); }
.row { display: flex; gap: 8px; }

/* Every text-like field, not just type="text" — a password input styled by
   type alone silently keeps the browser's default width. */
input[type="text"], input[type="password"], select {
  width: 100%;
  padding: 10px 12px;
  background: #0f1218;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-inner);
  font: inherit;
  /* 16px stops iOS Safari zooming the page when a field takes focus. */
  font-size: 16px;
  transition: border-color var(--t-instant) var(--ease), background var(--t-instant) var(--ease);
}
input[type="text"]:hover, input[type="password"]:hover, select:hover { border-color: var(--surface-hi); }
#room { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.05em; }

.devices { margin-bottom: 12px; }
.devices summary {
  font-size: 12px; color: var(--muted); cursor: pointer;
  padding: 4px 0;
  transition: color var(--t-instant) var(--ease);
}
.devices summary:hover { color: var(--text); }
.devices[open] summary { margin-bottom: 8px; }

/* -------------------------------- buttons ------------------------------- */

.primary {
  width: 100%;
  padding: 13px;
  border-radius: var(--r-inner);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  transition: background var(--t-instant) var(--ease),
              scale var(--t-instant) var(--ease),
              opacity var(--t-instant) var(--ease);
}
.primary:hover:not(:disabled) { background: var(--accent-hi); }
.primary:active:not(:disabled) { scale: 0.96; }
.primary:disabled { opacity: 0.45; cursor: not-allowed; }

.ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 14px;
  border-radius: var(--r-inner);
  background: var(--surface);
  flex: none;
  white-space: nowrap;
  transition: background var(--t-instant) var(--ease), scale var(--t-instant) var(--ease);
}
.ghost:hover { background: var(--surface-hi); }
.ghost:active { scale: 0.96; }
.ghost.icon-only { padding: 10px; }

/* The copy button swaps its icon for a tick, so the confirmation is not only
   a word that has to be read. */
.with-icon { position: relative; }
.with-icon .ico {
  transition: opacity var(--t-swap) var(--ease), scale var(--t-swap) var(--ease), filter var(--t-swap) var(--ease);
}
.with-icon .ico-off { position: absolute; left: 14px; opacity: 0; scale: 0.25; filter: blur(4px); }
.with-icon.done .ico-on { opacity: 0; scale: 0.25; filter: blur(4px); }
.with-icon.done .ico-off { opacity: 1; scale: 1; filter: blur(0); }

.link {
  background: none;
  color: var(--accent-hi);
  padding: 0;
  font-size: 12px;
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color var(--t-instant) var(--ease);
}
.link:hover { color: #a5a7ff; }

.round {
  display: grid; place-items: center;
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--surface);
  transition: background var(--t-instant) var(--ease),
              color var(--t-instant) var(--ease),
              scale var(--t-instant) var(--ease);
}
.round:hover { background: var(--surface-hi); }
.round:active { scale: 0.96; }
.round.sm { width: 34px; height: 34px; background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(8px); }
.round.sm:hover { background: rgba(0, 0, 0, 0.75); }

/* A muted microphone or a covered camera is a state worth warning about, so it
   is red-tinted *and* carries a different icon — colour is never the only
   signal. Not sharing a screen is simply the resting state, and dressing it up
   as an alert makes the control look broken. */
.mutable[aria-pressed="false"] { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }
.mutable[aria-pressed="false"]:hover { background: rgba(239, 68, 68, 0.3); }
#shareBtn[aria-pressed="true"] { background: var(--accent); color: #fff; }
#shareBtn[aria-pressed="true"]:hover { background: var(--accent-hi); }
.round.danger { background: var(--red); color: #fff; }
.round.danger:hover { background: #dc2626; }
.round:disabled { opacity: 0.35; cursor: not-allowed; }
.round:disabled:hover { background: var(--surface); }

.share-row { display: flex; gap: 8px; margin-top: 14px; }
.share-row input { font-size: 13px; color: var(--muted); }
.share-row.compact { margin-top: 12px; }

.hint { margin: 10px 0 0; font-size: 12px; color: var(--muted); text-align: center; }
.hint.pending { color: var(--amber); animation: fade var(--t-enter) var(--ease); }

.notice {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: var(--r-inner);
  font-size: 13px;
  animation: rise var(--t-enter) var(--ease);
}
.notice.error { background: rgba(239, 68, 68, 0.12); color: #fca5a5; }

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

.call {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  animation: fade var(--t-enter) var(--ease);
}

.stage { position: relative; min-height: 0; background: #000; }

/* The picture-in-picture strip. Bottom-right on a desktop, where it covers no
   faces; top-right on a phone, clear of the thumb and the control bar. */
.tiles {
  position: absolute;
  right: 12px;
  bottom: calc(var(--bar-h) + 12px);
  display: flex;
  justify-content: flex-end;
  align-items: flex-end;
  gap: var(--gap);
  max-width: calc(100% - 24px);
  pointer-events: none;
}
.tiles > * { pointer-events: auto; }

.slot { position: relative; overflow: hidden; background: #05070a; }
.stage > .slot { width: 100%; height: 100%; animation: fade var(--t-enter) var(--ease); }

.tiles > .slot {
  width: clamp(104px, 18vw, 200px);
  /* Each tile takes the shape of what is inside it. A fixed 4:3 box would crop
     a phone's upright frame down to a strip. */
  aspect-ratio: var(--slot-ratio, 4 / 3);
  max-height: 38vh;
  border-radius: var(--r-tile);
  cursor: pointer;
  box-shadow:
    0 0 0 1px var(--border),
    0 8px 24px -6px rgba(0, 0, 0, 0.6);
  animation: tile-in var(--t-enter) var(--ease);
  transition: translate var(--t-instant) var(--ease),
              box-shadow var(--t-instant) var(--ease);
}
.tiles > .slot:hover {
  translate: 0 -2px;
  box-shadow:
    0 0 0 1px var(--surface-hi),
    0 12px 28px -6px rgba(0, 0, 0, 0.7);
}
.tiles > .slot:active { translate: 0 0; }
@keyframes tile-in {
  from { opacity: 0; scale: 0.9; translate: 0 6px; }
  to { opacity: 1; scale: 1; translate: 0 0; }
}
/* Exits are quieter than entrances: a small drop, no scale. */
.slot.leaving { animation: tile-out var(--t-exit) var(--ease) forwards; pointer-events: none; }
@keyframes tile-out {
  to { opacity: 0; translate: 0 4px; }
}

.slot video { width: 100%; height: 100%; display: block; background: #05070a; }
/* A face fills its small tile; a shared screen and the stage are never cropped. */
.tiles > .slot[data-role="camera"] video { object-fit: cover; }
.tiles > .slot[data-role="screen"] video { object-fit: contain; }
.stage > .slot video { object-fit: contain; }
.slot[data-mirrored="true"] video { transform: scaleX(-1); }

.slot-label {
  position: absolute;
  left: 8px; bottom: 8px;
  max-width: calc(100% - 16px);
  padding: 3px 8px;
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  font-size: 11px;
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stage > .slot .slot-label { font-size: 13px; left: 14px; bottom: 14px; padding: 4px 10px; }

/* Only a hint that a tile does something, and only where there is a pointer. */
.slot-expand {
  position: absolute;
  top: 8px; right: 8px;
  display: grid; place-items: center;
  width: 26px; height: 26px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity var(--t-instant) var(--ease);
}
.slot-expand .ico { width: 14px; height: 14px; }
.tiles > .slot:hover .slot-expand { opacity: 1; }
.stage > .slot .slot-expand { display: none; }

.slot-placeholder {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px;
  background: #0f1218;
  color: var(--muted);
  animation: fade var(--t-swap) var(--ease);
}
.avatar {
  display: grid; place-items: center;
  width: 30%; max-width: 88px; min-width: 42px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  color: #fff;
  font-size: clamp(16px, 5vw, 34px);
  font-weight: 600;
  text-transform: uppercase;
}
.tiles .slot-placeholder .avatar { width: 40%; }
.tiles .slot-placeholder span:not(.avatar) { display: none; }
.preview-off .avatar { width: 64px; font-size: 26px; }

/* Sits below the middle: the stage centre belongs to whoever is on it, and a
   panel dropped on top of their face reads as a mistake. */
.waiting {
  position: absolute;
  left: 50%;
  bottom: calc(var(--bar-h) + 28px);
  translate: -50% 0;
  width: min(400px, calc(100% - 32px));
  padding: 18px;
  border-radius: var(--r-card);
  background: rgba(12, 14, 19, 0.85);
  backdrop-filter: blur(16px);
  box-shadow: 0 0 0 1px var(--border), 0 16px 40px -8px rgba(0, 0, 0, 0.6);
  text-align: center;
  animation: rise var(--t-enter) var(--ease);
}
.waiting p { margin: 0; color: var(--muted); font-size: 14px; }

.unmute {
  position: absolute;
  left: 50%; top: calc(14px + var(--safe-t));
  translate: -50% 0;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  box-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.6);
  animation: rise var(--t-enter) var(--ease);
  transition: background var(--t-instant) var(--ease), scale var(--t-instant) var(--ease);
}
.unmute:hover { background: var(--accent-hi); }
.unmute:active { scale: 0.96; }

/* ------------------------------ control bar ----------------------------- */

.bar {
  position: relative;
  min-height: var(--bar-h);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 12px 14px calc(12px + var(--safe-b));
  background: var(--panel);
  box-shadow: 0 -1px 0 var(--border);
}

.bar-status {
  display: flex; align-items: center; gap: 6px;
  min-width: 0;
  font-size: 12px; color: var(--muted);
}
.bar-status span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); flex: none;
  transition: background var(--t-swap) var(--ease);
}
.dot.connected { background: var(--green); }
.dot.connecting, .dot.new { background: var(--amber); animation: pulse 1.2s ease-in-out infinite; }
.dot.failed, .dot.disconnected { background: var(--red); }
@keyframes pulse { 50% { opacity: 0.25; } }
.route { opacity: 0.85; }

.bar-controls { display: flex; gap: 10px; justify-content: center; }

.share-group { position: relative; display: flex; align-items: center; }
.chevron {
  display: grid; place-items: center;
  width: 20px; height: 48px;
  background: none;
  color: var(--muted);
  transition: color var(--t-instant) var(--ease);
}
.chevron .ico { width: 14px; height: 14px; transition: rotate var(--t-swap) var(--ease); }
.chevron:hover { color: var(--text); }
.chevron[aria-expanded="true"] .ico { rotate: 180deg; }

.menu {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  translate: -50% 0;
  width: 236px;
  padding: 6px;
  background: #1b1f28;
  border-radius: var(--r-menu);
  box-shadow: 0 0 0 1px var(--border), 0 16px 40px -8px rgba(0, 0, 0, 0.7);
  z-index: 10;
  animation: menu-in 160ms var(--ease);
}
@keyframes menu-in {
  from { opacity: 0; translate: -50% 6px; scale: 0.98; }
  to { opacity: 1; translate: -50% 0; scale: 1; }
}
.menu-title { margin: 6px 8px 8px; font-size: 11px; color: var(--muted); }
.menu-item {
  display: block;
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  background: none;
  text-align: left;
  transition: background var(--t-instant) var(--ease);
}
.menu-item:hover { background: var(--surface); }
.menu-item strong { display: block; font-size: 13px; font-weight: 500; }
.menu-item span { font-size: 11px; color: var(--muted); }
.menu-item[aria-current="true"] strong::after { content: ' ✓'; color: var(--accent-hi); }

.bar-share {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  min-width: 0;
  font-size: 12px; color: var(--muted);
  animation: fade var(--t-swap) var(--ease);
}
.bar-share span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* -------------------------------- phones -------------------------------- */

@media (max-width: 680px) {
  :root { --bar-h: 88px; }

  .tiles {
    top: calc(12px + var(--safe-t));
    bottom: auto;
    right: 10px;
    flex-direction: column;
    align-items: flex-end;
  }
  .tiles > .slot { width: clamp(88px, 26vw, 128px); max-height: 30vh; }

  .bar {
    grid-template-columns: 1fr;
    grid-template-areas: "status" "controls";
    justify-items: center;
    gap: 10px;
    padding-top: 10px;
  }
  .bar-status { grid-area: status; }
  .bar-controls { grid-area: controls; gap: 12px; }
  .bar-share { display: none; }
  .round { width: 54px; height: 54px; }
  .round .ico { width: 24px; height: 24px; }
  .toggle .ico { margin: -12px 0 0 -12px; }
  .chevron { height: 54px; }
}

@media (hover: none) {
  .tiles > .slot:hover { translate: 0 0; }
  .slot-expand { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
