/* The user-facing site: lobby, call, blocked screen. Tokens come from styles.css. */

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* dvh tracks the mobile browser chrome; vh is the fallback. */
  height: 100vh;
  height: 100dvh;
}

main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  min-height: 0;
}

/* ------------------------------------------------------------------ brand */

/* Flex only here: the admin header's brand is bare text plus a span, and as flex
   items its words would be pushed apart with gaps between them. */
a.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

/* The one tagline that is always in view. Wide screens only: on anything narrower
   the header's space belongs to the status pill. */
.brand-tagline {
  padding-left: 14px;
  border-left: 1px solid var(--line);
  font-size: 13px;
  color: var(--text-faint);
  white-space: nowrap;
}
@media (max-width: 1080px) {
  .brand-tagline {
    display: none;
  }
}

.logo {
  width: 28px;
  height: 28px;
  flex: none;
}
.logo-bg {
  fill: var(--accent);
}
.logo-a {
  fill: #fff;
  opacity: 0.95;
}
.logo-b {
  fill: #0b1c47;
  opacity: 0.55;
}

.topbar-icon {
  width: 38px;
  height: 38px;
  padding: 0;
  color: var(--text-dim);
}

/* --------------------------------------------------------- media controls */

.ctl {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  position: relative;
  background: var(--surface-2);
  color: var(--text);
}
.ctl:hover:not(:disabled) {
  background: var(--surface-3);
}

/* Off reads as a state you are in, not an action: solid red, like every call app. */
.ctl[aria-pressed="true"] {
  background: var(--danger-solid);
  border-color: var(--danger-solid);
  color: #fff;
}
.ctl[aria-pressed="true"]:hover:not(:disabled) {
  background: var(--danger-solid-hover);
}

.media-tag {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 550;
  color: #fff;
  background: rgba(7, 11, 20, 0.62);
  backdrop-filter: blur(6px);
}
/* ------------------------------------------------------------------- gate */

#gate {
  overflow-y: auto;
}

.gate-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 32px 18px;
}

.gate-card {
  width: min(480px, 100%);
  padding: 30px 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.gate-logo {
  width: 44px;
  height: 44px;
}

.gate-card h1 {
  font-size: 26px;
  line-height: 1.2;
  letter-spacing: -0.03em;
}
.gate-card .lede {
  margin-top: -10px;
}

.gate-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 14px;
}
.gate-steps > li {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 12px;
  align-items: start;
}
.step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-text);
  background: var(--accent-soft);
  border: 1px solid #2b4a8f;
}
.step-body {
  display: grid;
  gap: 8px;
  padding-top: 3px;
  font-size: 14.5px;
}

.gate-card .start {
  height: 52px;
  font-size: 15.5px;
  border-radius: 999px;
}
.gate-hint {
  margin-top: -10px;
  text-align: center;
}

/* Phones: less frame, so "Allow camera and microphone" stays on one line at 375px. */
@media (max-width: 480px) {
  .gate-wrap {
    padding: 14px 12px 24px;
    place-items: start center;
  }
  .gate-card {
    padding: 22px 18px 18px;
    gap: 16px;
  }
  .gate-card h1 {
    font-size: 23px;
  }
}

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

#lobby {
  display: grid;
  place-items: center;
  padding: 32px 22px;
  overflow-y: auto;
}

.lobby {
  width: min(1060px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 36px;
  align-items: start;
}

.lobby-preview {
  overflow: hidden;
}

.preview-pane {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #000;
}

.preview-pane video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  /* Mirror your own preview, as every video app does. */
  transform: scaleX(-1);
}

.preview-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  padding: 24px;
  color: var(--text-faint);
  font-size: 14px;
  text-align: center;
  background: radial-gradient(ellipse at center, #121b2d 0%, #070b14 75%);
}

.checks {
  list-style: none;
  margin: 0;
  padding: 6px 0;
}
.checks li {
  display: grid;
  grid-template-columns: 22px auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  font-size: 13.5px;
}
.checks li + li {
  border-top: 1px solid var(--line-soft);
}
.check-name {
  font-weight: 550;
}
.check-detail {
  color: var(--text-dim);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* The mark is drawn in CSS so the state attribute alone drives it. */
.check-mark {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 2px solid var(--line);
}
.checks li[data-state="pending"] .check-mark {
  border-color: var(--line);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
.checks li[data-state="ok"] .check-mark {
  border: none;
  background: var(--ok-bg);
}
.checks li[data-state="ok"] .check-mark::after {
  content: "";
  width: 9px;
  height: 5px;
  border-left: 2px solid var(--ok);
  border-bottom: 2px solid var(--ok);
  transform: translateY(-1px) rotate(-45deg);
}
.checks li[data-state="warn"] .check-mark,
.checks li[data-state="error"] .check-mark {
  border: none;
  background: var(--warn-bg);
}
.checks li[data-state="error"] .check-mark {
  background: var(--danger-bg);
}
.checks li[data-state="warn"] .check-mark::after,
.checks li[data-state="error"] .check-mark::after {
  content: "!";
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  color: var(--warn);
}
.checks li[data-state="error"] .check-mark::after {
  color: var(--danger);
}

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

.lobby-setup {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-top: 4px;
}

.lobby-setup h1 {
  font-size: 30px;
  line-height: 1.15;
  letter-spacing: -0.03em;
}

.lede {
  margin-top: 8px;
  color: var(--text-dim);
  font-size: 15px;
}

.level-row {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 14px;
  padding: 10px 16px 14px;
  border-top: 1px solid var(--line-soft);
}
.level-row .meter {
  margin-top: 0;
}

.hint {
  font-size: 12.5px;
  color: var(--text-faint);
  margin-top: 6px;
}

/*
 * Segmented level meter. The fill is a plain width; the gaps are painted over it by a
 * repeating gradient in the surface colour, so there is one element to update per
 * animation frame rather than twenty.
 */
.meter {
  position: relative;
  height: 8px;
  margin-top: 10px;
  border-radius: 4px;
  background: var(--surface-3);
  overflow: hidden;
}
.meter > i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--ok) 0 70%, var(--warn) 90%);
  transition: width 0.08s linear;
}
.meter::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    90deg,
    transparent 0 9px,
    var(--bg) 9px 11px
  );
}

.consent {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13.5px;
  color: var(--text-dim);
  cursor: pointer;
}
.consent:has(input:checked) {
  border-color: #2b4a8f;
  background: var(--accent-soft);
  color: var(--text);
}
.consent input {
  width: 18px;
  height: 18px;
  margin: 1px 0 0;
  flex: none;
  accent-color: var(--accent);
  cursor: pointer;
}

.lobby-actions {
  display: flex;
  gap: 10px;
}
.lobby-actions .start {
  flex: 1;
  height: 50px;
  font-size: 15.5px;
  border-radius: 999px;
}
.settings-btn {
  height: 50px;
  border-radius: 999px;
  padding: 0 20px;
}
.retry-btn {
  align-self: flex-start;
  margin-top: -6px;
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 13px;
}

.guidelines {
  border-top: 1px solid var(--line-soft);
  padding-top: 16px;
}
.guidelines h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}
.guidelines ul {
  margin: 10px 0 0;
  padding-left: 18px;
  display: grid;
  gap: 5px;
  font-size: 13px;
  color: var(--text-faint);
}
.guidelines strong {
  color: var(--text-dim);
  font-weight: 600;
}

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

#call {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 14px;
  padding: 14px;
  min-height: 0;
}

/* Full screen covers the whole call, chat included; it needs its own ground. */
#call:fullscreen {
  background: var(--bg);
}

.stage {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  min-width: 0;
  background: var(--bg);
}

.stage-media {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
}

.remote-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--line-soft);
  background: #000;
}

#remote {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #000;
}

.local-wrap {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 3;
  width: clamp(140px, 22%, 250px);
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: #000;
  box-shadow: var(--shadow);
}
.local-wrap video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transform: scaleX(-1);
}
.local-wrap .off {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-faint);
  background: var(--surface);
}

/* The overlay is a centring grid. Exactly one child goes in it — two children make
   two grid rows and strand the explanation at the bottom, behind the self-view. */
.stage-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  padding: 72px 24px 24px;
  text-align: center;
  color: var(--text-dim);
  background: radial-gradient(ellipse at center, #111a2c 0%, #070b14 72%);
}

.overlay-block {
  max-width: 46ch;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.overlay-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}
.overlay-detail {
  font-size: 14px;
  color: var(--text-dim);
}
.overlay-meta {
  font: 12.5px var(--mono);
  color: var(--text-faint);
}
.overlay-block button {
  margin-top: 8px;
  border-radius: 999px;
  padding: 10px 22px;
}

.overlay-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  color: var(--text-dim);
  margin-bottom: 4px;
}
.overlay-icon[data-tone="error"] {
  background: var(--danger-bg);
  color: var(--danger);
}
.overlay-icon[data-tone="ok"] {
  background: var(--ok-bg);
  color: var(--ok);
}
.overlay-icon[data-tone="waiting"] {
  background: var(--warn-bg);
  color: var(--warn);
}

/* Searching: two rings expanding out of an avatar. */
.radar {
  position: relative;
  width: 96px;
  height: 96px;
  display: grid;
  place-items: center;
  margin-bottom: 6px;
}
.radar::before,
.radar::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  animation: ripple 2.4s cubic-bezier(0.2, 0.6, 0.35, 1) infinite;
}
.radar::after {
  animation-delay: 1.2s;
}
.radar .core {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent-text);
  border: 1px solid #2b4a8f;
}

@keyframes ripple {
  0% {
    transform: scale(0.55);
    opacity: 0.7;
  }
  100% {
    transform: scale(1.35);
    opacity: 0;
  }
}

.spinner {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid var(--surface-3);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
  margin-bottom: 6px;
}

.stage-bar {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 4;
  display: flex;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.stage-bar > * {
  pointer-events: auto;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 11px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(7, 11, 20, 0.66);
  backdrop-filter: blur(8px);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 550;
  white-space: nowrap;
}
.chip.mono {
  font-family: var(--mono);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
button.chip:hover:not(:disabled) {
  background: rgba(21, 29, 46, 0.9);
}

/* Signal bars. The level is carried by bar count AND the label, never colour alone. */
.bars {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 13px;
}
.bars i {
  width: 3px;
  border-radius: 1px;
  background: rgba(255, 255, 255, 0.22);
}
.bars i:nth-child(1) {
  height: 5px;
}
.bars i:nth-child(2) {
  height: 9px;
}
.bars i:nth-child(3) {
  height: 13px;
}
.quality[data-level="good"] .bars i {
  background: var(--ok);
}
.quality[data-level="fair"] .bars i:nth-child(-n + 2) {
  background: var(--warn);
}
.quality[data-level="poor"] .bars i:nth-child(1) {
  background: var(--danger);
}

.quality-pop {
  position: absolute;
  top: 50px;
  left: 12px;
  z-index: 6;
  width: min(280px, calc(100% - 24px));
  padding: 12px 14px;
  box-shadow: var(--shadow);
}
.quality-pop dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px 14px;
  font-size: 12.5px;
}
.quality-pop dt {
  color: var(--text-faint);
}
.quality-pop dd {
  margin: 0;
  text-align: right;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}
.quality-pop .hint {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--line-soft);
}

.unmute {
  position: absolute;
  left: 50%;
  top: 54px;
  transform: translateX(-50%);
  z-index: 5;
  border-radius: 999px;
  box-shadow: var(--shadow);
}

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

.controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.controls .group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.controls .group.end {
  justify-content: flex-end;
}

.pill-btn {
  height: 44px;
  border-radius: 999px;
  padding: 0 18px;
}
.next {
  min-width: 136px;
  font-size: 15px;
}

.ctl.report {
  color: var(--danger);
}
.ctl.report:hover:not(:disabled) {
  background: var(--danger-bg);
  border-color: var(--danger-line);
}

.chat-toggle,
.chat-close {
  display: none;
}

.badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  border: 2px solid var(--surface);
  box-sizing: content-box;
}

/* ------------------------------------------------------------- chat panel */

.side {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.side > header {
  color: var(--text);
}
.chat-sub {
  color: var(--text-faint);
  font-weight: 400;
}

#messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overscroll-behavior: contain;
}

#messages:empty::before {
  content: "Messages appear here once you are matched.";
  margin: auto;
  max-width: 24ch;
  text-align: center;
  font-size: 13px;
  color: var(--text-faint);
}

.msg {
  max-width: 85%;
  padding: 8px 13px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  animation: rise 0.16s ease-out;
}
.msg.you {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.msg.them {
  align-self: flex-start;
  background: var(--surface-3);
  border-bottom-left-radius: 5px;
}
.msg.system {
  align-self: center;
  max-width: 100%;
  margin: 6px 0;
  padding: 3px 12px;
  color: var(--text-faint);
  background: transparent;
  font-size: 12px;
  text-align: center;
  animation: none;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

.typing {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px 8px;
  font-size: 12.5px;
  color: var(--text-faint);
}
.typing-dots {
  display: inline-flex;
  gap: 3px;
}
.typing-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: bounce 1.2s ease-in-out infinite;
}
.typing-dots i:nth-child(2) {
  animation-delay: 0.15s;
}
.typing-dots i:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-3px);
    opacity: 1;
  }
}

#chat-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line-soft);
}
#chat-form input {
  border-radius: 999px;
  padding-left: 16px;
}
.send {
  width: 42px;
  height: 42px;
  flex: none;
  padding: 0;
  border-radius: 50%;
}

/* ---------------------------------------------------------------- blocked */

.blocked-wrap {
  display: grid;
  place-items: center;
  height: 100%;
  padding: 24px;
}
.blocked-card {
  max-width: 440px;
  padding: 32px 28px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.blocked-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--danger-bg);
  color: var(--danger);
  margin-bottom: 4px;
}
.blocked-card h2 {
  font-size: 20px;
}
.blocked-card button {
  margin-top: 8px;
}

/* ----------------------------------------------------------------- toasts */

.toasts {
  position: fixed;
  top: 68px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(420px, calc(100vw - 24px));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  box-shadow: var(--shadow);
  font-size: 13.5px;
  animation: rise 0.18s ease-out;
}
.toast[data-tone="ok"] .i {
  color: var(--ok);
}
.toast[data-tone="error"] {
  border-color: var(--danger-line);
}
.toast[data-tone="error"] .i {
  color: var(--danger);
}

/* ---------------------------------------------------------------- dialogs */

dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(440px, calc(100vw - 28px));
  box-shadow: var(--shadow);
}
dialog::backdrop {
  background: rgba(3, 6, 12, 0.7);
  backdrop-filter: blur(2px);
}
.modal-body {
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.modal-head {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.modal-head h3 {
  font-size: 17px;
  margin-bottom: 3px;
}
.modal-icon {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent-text);
}
.modal-icon.danger {
  background: var(--danger-bg);
  color: var(--danger);
}
.reasons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.reasons button {
  justify-content: flex-start;
  font-weight: 500;
  font-size: 13.5px;
  padding: 10px 12px;
}
.reasons button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
button.danger-solid {
  background: var(--danger-solid);
  border-color: var(--danger-solid);
  color: #fff;
}
button.danger-solid:hover:not(:disabled) {
  background: var(--danger-solid-hover);
}

.shortcuts {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px 16px;
  align-items: center;
  font-size: 14px;
}
.shortcuts dt {
  text-align: right;
}
.shortcuts dd {
  margin: 0;
  color: var(--text-dim);
}

/* ------------------------------------------------------------- responsive */

@media (max-width: 1080px) {
  #call {
    grid-template-columns: minmax(0, 1fr) 300px;
  }
}

@media (max-width: 880px) {
  .lobby {
    grid-template-columns: 1fr;
    gap: 22px;
  }
  .lobby-setup h1 {
    font-size: 25px;
  }
  #lobby {
    place-items: start center;
    padding: 18px 14px 28px;
  }
}

/* Keyboard shortcuts mean nothing without a keyboard. */
@media (hover: none) {
  .topbar-icon {
    display: none;
  }
}

/*
 * Phones and small tablets. The two videos split the screen — the stranger on top, you
 * underneath — which uses a tall display properly, and the chat becomes a sheet that
 * slides up over the call rather than stealing half of it permanently.
 */
@media (max-width: 900px) {
  .topbar {
    padding: 8px 14px;
    min-height: 50px;
    padding-top: calc(8px + env(safe-area-inset-top));
  }

  #call {
    grid-template-columns: 1fr;
    padding: 0;
    gap: 0;
  }

  .stage {
    gap: 0;
  }

  .stage-media {
    grid-template-rows: minmax(0, 3fr) minmax(0, 2fr);
    gap: 2px;
    background: var(--line-soft);
  }

  .remote-wrap {
    border-radius: 0;
    border: none;
  }

  #remote {
    object-fit: cover;
  }

  .local-wrap {
    position: relative;
    right: auto;
    bottom: auto;
    width: auto;
    aspect-ratio: auto;
    border: none;
    border-radius: 0;
    box-shadow: none;
  }

  .controls {
    border-radius: 0;
    border-width: 1px 0 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    grid-template-columns: auto 1fr auto;
  }
  .controls .primary-actions {
    justify-content: flex-end;
  }

  .chat-toggle {
    display: inline-flex;
  }

  /*
   * Small on purpose: the sheet sits over the stranger's video, and a chat that hides
   * the person you are talking to defeats the point. 40% of the screen shows four or
   * five messages and the input.
   *
   * `--keyboard-inset` lifts it above the on-screen keyboard where the browser does
   * not do that itself (iOS Safari); app.js measures it from the visual viewport.
   * Android Chrome resizes the page instead, via interactive-widget in index.html,
   * and there the inset stays 0 and dvh shrinks with the keyboard.
   */
  .side {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--keyboard-inset, 0px);
    z-index: 30;
    height: min(40dvh, 340px);
    min-height: 180px;
    border-radius: 18px 18px 0 0;
    border-width: 1px 0 0;
    box-shadow: 0 -18px 40px rgba(0, 0, 0, 0.5);
    padding-bottom: env(safe-area-inset-bottom);
    transform: translateY(105%);
    visibility: hidden;
    transition:
      transform 0.24s cubic-bezier(0.2, 0.7, 0.3, 1),
      visibility 0s linear 0.24s;
  }
  #call.chat-open .side {
    transform: none;
    visibility: visible;
    transition:
      transform 0.24s cubic-bezier(0.2, 0.7, 0.3, 1),
      visibility 0s;
  }
  .chat-close {
    display: inline-flex;
    width: 36px;
    height: 36px;
    padding: 0;
    margin: -6px -8px -6px 0;
  }

  /* Tighter inside a small sheet: every pixel of padding is a message not shown. */
  .side > header {
    padding: 8px 14px;
  }
  .chat-sub {
    display: none;
  }
  #messages {
    padding: 10px 12px;
    gap: 5px;
  }
  .msg {
    padding: 6px 11px;
    font-size: 13.5px;
  }
  .typing {
    padding: 0 12px 6px;
  }
  #chat-form {
    padding: 8px 10px;
  }
  .send {
    width: 38px;
    height: 38px;
  }
  /* 16px exactly: iOS Safari zooms the whole page into any input below that when it
     is focused, and stays zoomed after the keyboard closes. */
  #chat-form input {
    font-size: 16px;
    padding-top: 6px;
    padding-bottom: 6px;
  }
}

@media (max-width: 480px) {
  .controls {
    gap: 6px;
    padding-left: 8px;
    padding-right: 8px;
  }
  .controls .group {
    gap: 6px;
  }
  .ctl {
    width: 42px;
    height: 42px;
  }
  #stop .label {
    display: none;
  }
  #stop {
    width: 42px;
    padding: 0;
  }
  .next {
    min-width: 0;
    padding: 0 18px;
  }
  .next .i {
    display: none;
  }
  #fullscreen {
    display: none;
  }
  .brand-name {
    display: none;
  }
}

/* Landscape phones: side by side, not stacked — stacking two videos into 360px of
   height leaves both unreadable. */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 520px) {
  .stage-media {
    grid-template-rows: 1fr;
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  }
  .topbar {
    display: none;
  }
}
