/* ==========================================================================
   ScreenTalk — dark, calm, tablet-first UI
   ========================================================================== */

:root {
  --bg: #070b16;
  --bg-soft: #0a1120;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-2: rgba(255, 255, 255, 0.075);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #eef2ff;
  --muted: #98a5bf;
  --muted-2: #6b7893;
  --brand: #7c8cff;
  --brand-2: #38e1c6;
  --grad: linear-gradient(135deg, #7c8cff 0%, #38e1c6 100%);
  --green: #34d399;
  --red: #fb5a76;
  --amber: #fbbf24;
  --radius: 20px;
  --radius-sm: 13px;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "PingFang TC",
    "PingFang HK", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background-color: var(--bg);
  background-image:
    radial-gradient(1100px 700px at 8% -10%, rgba(84, 62, 255, 0.18), transparent 60%),
    radial-gradient(900px 620px at 110% 10%, rgba(20, 184, 166, 0.12), transparent 55%),
    radial-gradient(900px 700px at 50% 120%, rgba(99, 54, 190, 0.14), transparent 60%);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

body.in-room { overflow: hidden; }

h1, h2, h3, p { margin: 0; }
button { font-family: inherit; }
a { color: inherit; text-decoration: none; }

[hidden] { display: none !important; }

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

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: inline-block;
  vertical-align: middle;
}

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.grad-text {
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ------------------------------- home ---------------------------------- */

.view-home {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding: clamp(14px, 2.4vw, 28px) clamp(16px, 4vw, 56px) clamp(14px, 2vw, 22px);
  overflow: hidden;
}

.orbs { position: absolute; inset: 0; pointer-events: none; z-index: 0; }

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.55;
  animation: orbFloat 18s ease-in-out infinite alternate;
}
.orb-a { width: clamp(320px, 36vw, 560px); height: clamp(320px, 36vw, 560px); background: #4b3bff; top: -18%; left: -10%; }
.orb-b { width: clamp(280px, 30vw, 460px); height: clamp(280px, 30vw, 460px); background: #0e7a74; bottom: -20%; right: -8%; opacity: 0.38; animation-delay: -6s; }
.orb-c { width: 320px; height: 320px; background: #5b2d8f; top: 42%; left: 54%; opacity: 0.22; animation-delay: -12s; }

@keyframes orbFloat {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(3%, 5%, 0) scale(1.08); }
}

.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand { display: inline-flex; align-items: center; gap: 10px; }
.brand-mark { width: 34px; height: 34px; display: block; filter: drop-shadow(0 6px 18px rgba(90, 110, 255, 0.45)); }
.brand-mark svg { width: 100%; height: 100%; display: block; }
.brand-mark-sm { width: 30px; height: 30px; }
.brand-name { font-weight: 700; letter-spacing: -0.02em; font-size: 18px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--muted);
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.035);
  backdrop-filter: blur(10px);
}
.pill-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.15); }

.home-main {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 1240px;
  margin: auto;
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(360px, 0.92fr);
  align-items: center;
  gap: clamp(28px, 5vw, 80px);
  padding: clamp(28px, 5vh, 64px) 0;
}

.eyebrow {
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.22em;
  color: var(--brand-2);
  margin-bottom: 18px;
  text-transform: uppercase;
}

.hero h1 {
  font-size: clamp(40px, 5.6vw, 74px);
  line-height: 1.06;
  letter-spacing: -0.035em;
  font-weight: 800;
  margin-bottom: 20px;
}

.hero-sub {
  color: var(--muted);
  font-size: clamp(15px, 1.25vw, 17px);
  max-width: 34em;
  margin-bottom: 24px;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; padding: 0; margin: 0 0 22px; }
.chips li {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 13px;
  border-radius: 999px;
  font-size: 13px;
  color: #c8d2ea;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.chips .icon { width: 15px; height: 15px; color: var(--brand-2); }

.trust { display: flex; align-items: flex-start; gap: 8px; font-size: 12.5px; color: var(--muted-2); max-width: 36em; }
.trust .icon { width: 15px; height: 15px; color: var(--green); margin-top: 2px; }

/* join card */

.join-card {
  position: relative;
  width: 100%;
  max-width: 480px;
  justify-self: end;
  padding: clamp(22px, 2.6vw, 32px);
  border-radius: 26px;
  border: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.025)),
    rgba(9, 14, 27, 0.6);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(22px) saturate(140%);
}

.card-title { font-size: 21px; letter-spacing: -0.02em; margin-bottom: 18px; font-weight: 700; }

.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 7px; font-weight: 500; }

.input {
  width: 100%;
  height: 52px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(4, 8, 17, 0.62);
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.16s, box-shadow 0.16s, background 0.16s;
}
.input::placeholder { color: #5d6a84; }
.input:focus {
  border-color: rgba(124, 140, 255, 0.7);
  box-shadow: 0 0 0 4px rgba(124, 140, 255, 0.16);
  background: rgba(4, 8, 17, 0.85);
}
.input-code { letter-spacing: 0.24em; text-transform: uppercase; font-size: 17px; }

.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  height: 48px;
  padding: 0 20px;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 650;
  color: var(--text);
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease, opacity 0.16s;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.985); }
.btn .icon { width: 19px; height: 19px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-lg { width: 100%; height: 56px; font-size: 17px; }

.btn-primary {
  background: var(--grad);
  color: #06101f;
  box-shadow: 0 12px 32px rgba(88, 118, 255, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.btn-primary:hover { box-shadow: 0 16px 40px rgba(88, 118, 255, 0.45); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0) scale(0.99); }

.btn-secondary {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-secondary:hover { background: rgba(255, 255, 255, 0.12); }

.divider { display: flex; align-items: center; gap: 12px; margin: 20px 0 16px; color: var(--muted-2); font-size: 12px; }
.divider::before, .divider::after { content: ""; height: 1px; flex: 1; background: var(--border); }

.join-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
.join-row .btn { height: 52px; padding: 0 24px; }
.card-note { margin-top: 12px; font-size: 12px; color: var(--muted-2); }

.invite-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(124, 140, 255, 0.12);
  border: 1px solid rgba(124, 140, 255, 0.32);
  animation: fadeUp 0.35s ease both;
}
.invite-banner strong { display: block; font-size: 14px; }
.invite-banner .mono { font-size: 12.5px; color: var(--brand-2); letter-spacing: 0.16em; }
.invite-banner-icon {
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center;
  background: rgba(124, 140, 255, 0.18); color: var(--brand); flex: 0 0 auto;
}

.home-foot {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  color: var(--muted-2);
  font-size: 12px;
  padding-top: 12px;
}
.dot-sep { width: 3px; height: 3px; border-radius: 50%; background: var(--muted-2); opacity: 0.7; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ------------------------------- room ---------------------------------- */

.view-room {
  position: relative;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: radial-gradient(900px 520px at 50% -10%, rgba(72, 62, 200, 0.18), transparent 70%);
}

.room-top {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) clamp(12px, 2.2vw, 22px) 8px;
}

.room-top-left, .room-top-right { display: flex; align-items: center; gap: 10px; min-width: 0; }

.brand-mark-sm { filter: none; }

.room-code-wrap { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.room-label { font-size: 10px; letter-spacing: 0.18em; color: var(--muted-2); text-transform: uppercase; }
.room-code { font-size: 16px; letter-spacing: 0.18em; font-weight: 600; color: var(--text); }

.icon-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  width: 38px;
  height: 38px;
  border-radius: 11px;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.16s, color 0.16s, transform 0.16s;
  touch-action: manipulation;
  flex: 0 0 auto;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.11); color: var(--text); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn .icon { width: 17px; height: 17px; }

.conn-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.14); }
.conn-pill[data-state="connected"] .conn-dot { background: var(--green); box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.16); }
.conn-pill[data-state="disconnected"] .conn-dot { background: var(--red); box-shadow: 0 0 0 4px rgba(251, 90, 118, 0.16); }
.conn-pill[data-state="connecting"] .conn-dot { animation: pulseDot 1.2s ease-in-out infinite; }

@keyframes pulseDot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.latency { font-size: 11.5px; color: var(--muted-2); width: 46px; text-align: right; }

.peer-count {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  font-size: 12.5px;
  color: var(--muted);
}
.peer-count .icon { width: 15px; height: 15px; }

/* stage */

.stage {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 4px;
  min-height: 0;
  padding: 0 clamp(8px, 1.6vw, 20px) 4px;
}

.stage-main {
  min-height: 0;
  overflow: auto;
  scrollbar-width: thin;
  display: grid;
  gap: clamp(8px, 1.1vw, 14px);
  padding: 6px;
}
.stage-main.grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
  align-content: center;
  align-items: center;
}
.stage-main.stage-full {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.tile {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 100%;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: #0b1120;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
  animation: tileIn 0.3s ease both;
}

@keyframes tileIn {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}

.tile video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #04070d;
  opacity: 0;
  transition: opacity 0.22s ease;
}
.tile.has-video video { opacity: 1; }
.tile.is-screen video { object-fit: contain; }
.tile.is-self:not(.is-screen) video { transform: scaleX(-1); }

.tile-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 38%, rgba(124, 140, 255, 0.18), transparent 62%),
    linear-gradient(160deg, #0d1426, #0a0f1d);
  transition: opacity 0.3s ease;
}
.tile.has-video .tile-fallback { opacity: 0; }

.tile-avatar {
  width: clamp(54px, 7vw, 82px);
  height: clamp(54px, 7vw, 82px);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: clamp(22px, 2.6vw, 30px);
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, rgba(124, 140, 255, 0.42), rgba(56, 225, 198, 0.3));
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  text-transform: uppercase;
}

.tile-top {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 46px;
  display: flex;
  gap: 6px;
  pointer-events: none;
  z-index: 2;
}

.badge {
  display: none;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(5, 9, 18, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
  color: var(--text);
}
.badge .icon { width: 12px; height: 12px; }
.tile.is-muted .badge-mic { display: inline-flex; color: var(--red); }
.tile.is-sharing .badge-screen { display: inline-flex; color: var(--brand-2); }

.tile-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 20px 12px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(transparent, rgba(3, 6, 14, 0.85));
  z-index: 2;
}
.tile-name {
  font-size: 13px;
  font-weight: 600;
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.65);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile-name .you { font-size: 10px; font-weight: 500; color: #b9c4dc; margin-left: 5px; opacity: 0.8; }

.tile-sound { display: inline-flex; gap: 2.5px; align-items: flex-end; height: 13px; margin-left: auto; opacity: 0; transition: opacity 0.2s; }
.tile-sound i { width: 3px; border-radius: 2px; background: var(--green); height: 5px; animation: soundBar 0.9s ease-in-out infinite; }
.tile-sound i:nth-child(2) { animation-delay: 0.12s; }
.tile-sound i:nth-child(3) { animation-delay: 0.24s; }
.tile-sound i:nth-child(4) { animation-delay: 0.36s; }
.tile-sound i:nth-child(5) { animation-delay: 0.48s; }
@keyframes soundBar {
  0%, 100% { height: 4px; }
  50% { height: 12px; }
}
.tile.is-speaking .tile-sound { opacity: 1; }
.tile.is-speaking {
  box-shadow: 0 0 0 2px rgba(52, 211, 153, 0.72), 0 0 30px rgba(52, 211, 153, 0.22);
  border-color: transparent;
}

.tile-expand {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 3;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: rgba(5, 9, 18, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text);
  cursor: pointer;
  opacity: 0.85;
  transition: opacity 0.16s, background 0.16s;
  touch-action: manipulation;
}
.tile-expand .icon { width: 15px; height: 15px; }
.tile-expand:hover { background: rgba(20, 28, 48, 0.9); opacity: 1; }

@media (hover: hover) {
  .tile-expand { opacity: 0; }
  .tile:hover .tile-expand, .tile-expand:focus-visible { opacity: 1; }
}

.stage-main.stage-full .tile {
  width: 100%;
  height: 100%;
  max-height: 100%;
  aspect-ratio: auto;
  border-radius: 14px;
  background: #04070d;
}

.strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 8px 4px 10px;
  scrollbar-width: thin;
  flex: 0 0 auto;
}
.strip .tile {
  width: clamp(118px, 15vw, 176px);
  flex: 0 0 auto;
  aspect-ratio: 16 / 10;
  border-radius: 12px;
}
.strip .tile .tile-avatar { width: 34px; height: 34px; font-size: 15px; }
.strip .tile .tile-bar { padding: 14px 8px 6px; }
.strip .tile .tile-name { font-size: 11px; }
.strip .tile .badge { font-size: 9.5px; padding: 3px 6px; }
.strip .tile .tile-expand { width: 26px; height: 26px; border-radius: 8px; }
.strip .tile .tile-expand .icon { width: 12px; height: 12px; }

.stage.focus-mode .stage-main .tile:not(.focused),
.stage.focus-mode .strip { display: none; }

.stage.focus-mode .stage-main {
  display: block;
  overflow: hidden;
  padding: 0;
}
.stage.focus-mode .tile.focused {
  position: fixed;
  inset: 0;
  z-index: 90;
  width: 100%;
  height: 100%;
  max-height: none;
  aspect-ratio: auto;
  border-radius: 0;
  border: 0;
  background: #000;
}
.stage.focus-mode .tile.focused .tile-expand { position: fixed; top: calc(12px + env(safe-area-inset-top)); right: 12px; z-index: 95; width: 42px; height: 42px; border-radius: 12px; background: rgba(10, 15, 28, 0.8); }

/* empty state */

.empty-state {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: 14px clamp(12px, 3vw, 28px);
}
.stage.alone .stage-main { visibility: hidden; }

.empty-card {
  width: min(540px, 100%);
  max-height: 100%;
  overflow: auto;
  text-align: center;
  padding: clamp(20px, 3vw, 34px);
  border-radius: 24px;
  border: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02)),
    rgba(8, 13, 26, 0.72);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px) saturate(140%);
  animation: fadeUp 0.35s ease both;
}

.radar { position: relative; width: 96px; height: 96px; margin: 0 auto 16px; display: grid; place-items: center; }
.radar-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(124, 140, 255, 0.45);
  animation: radarPulse 2.6s ease-out infinite;
}
.radar-ring:nth-child(2) { animation-delay: 1.3s; }
@keyframes radarPulse {
  0% { transform: scale(0.55); opacity: 0.9; }
  100% { transform: scale(1.15); opacity: 0; }
}
.radar-core {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, rgba(124, 140, 255, 0.35), rgba(56, 225, 198, 0.28));
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #fff;
}
.radar-core .icon { width: 24px; height: 24px; }

.empty-card h2 { font-size: clamp(20px, 2.4vw, 24px); letter-spacing: -0.02em; margin-bottom: 8px; }
.empty-sub { color: var(--muted); font-size: 14px; margin-bottom: 18px; }

.invite-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(3, 7, 15, 0.62);
  margin-bottom: 16px;
}
.invite-box code {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: var(--brand-2);
  text-align: left;
}

.empty-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.empty-actions .btn { height: 46px; font-size: 14.5px; }

.mic-test { display: flex; align-items: center; justify-content: center; gap: 9px; margin-top: 18px; font-size: 12.5px; color: var(--muted); }
.mic-test-bars { display: inline-flex; align-items: flex-end; gap: 3px; height: 16px; }
.mic-test-bars i { width: 3px; border-radius: 2px; background: var(--green); height: 4px; opacity: 0.5; }
.mic-test-bars.live i { animation: soundBar 0.85s ease-in-out infinite; opacity: 1; }
.mic-test-bars.live i:nth-child(2) { animation-delay: 0.1s; }
.mic-test-bars.live i:nth-child(3) { animation-delay: 0.2s; }
.mic-test-bars.live i:nth-child(4) { animation-delay: 0.3s; }
.mic-test-bars.live i:nth-child(5) { animation-delay: 0.4s; }
.mic-test.muted { color: var(--red); }
.mic-test.muted .mic-test-bars i { background: var(--red); animation: none; opacity: 0.4; }

.empty-hint { margin-top: 10px; font-size: 12px; color: var(--muted-2); }

/* controls */

.controls {
  position: relative;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px clamp(10px, 2vw, 22px) calc(12px + env(safe-area-inset-bottom));
}

.ctrl-group {
  display: flex;
  align-items: center;
  gap: clamp(2px, 1vw, 8px);
  padding: 7px;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: rgba(12, 18, 34, 0.72);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px) saturate(140%);
}

.ctrl {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 4px 6px;
  width: clamp(62px, 8vw, 78px);
  border-radius: 16px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.14s ease;
}
.ctrl:active { transform: scale(0.94); }
.ctrl:disabled { opacity: 0.38; cursor: not-allowed; }

.ctrl-icon {
  width: clamp(46px, 5.6vw, 52px);
  height: clamp(46px, 5.6vw, 52px);
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: background 0.16s, box-shadow 0.16s, border-color 0.16s;
}
.ctrl-icon .icon { width: 21px; height: 21px; }
.ctrl:hover .ctrl-icon { background: rgba(255, 255, 255, 0.15); }
.ctrl-label { font-size: 10.5px; color: var(--muted); white-space: nowrap; font-weight: 500; }

.ctrl-mic[aria-pressed="false"] .ctrl-icon,
.ctrl-cam[aria-pressed="true"] .ctrl-icon {
  background: rgba(255, 255, 255, 0.14);
}
.ctrl-mic[aria-pressed="false"] .ctrl-icon {
  background: var(--red);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 8px 24px rgba(251, 90, 118, 0.35);
}
.ctrl-share[aria-pressed="true"] .ctrl-icon {
  background: var(--grad);
  color: #06101f;
  border-color: transparent;
  box-shadow: 0 8px 26px rgba(88, 180, 255, 0.32);
}
.ctrl-leave .ctrl-icon {
  background: var(--red);
  border-color: transparent;
  color: #fff;
  width: clamp(50px, 6vw, 56px);
  height: clamp(50px, 6vw, 56px);
  box-shadow: 0 10px 28px rgba(251, 90, 118, 0.35);
  border-radius: 50%;
}
.ctrl-leave { width: clamp(58px, 7vw, 70px); }

/* banner + toast */

.banner {
  position: fixed;
  z-index: 60;
  top: calc(64px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 24px));
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px 11px 15px;
  border-radius: 14px;
  background: rgba(251, 191, 36, 0.13);
  border: 1px solid rgba(251, 191, 36, 0.35);
  color: #fde68a;
  font-size: 13px;
  backdrop-filter: blur(16px);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.35);
  animation: fadeUp 0.25s ease both;
}
.banner-action {
  margin-left: auto;
  flex: 0 0 auto;
  appearance: none;
  border: 1px solid rgba(251, 191, 36, 0.45);
  background: rgba(251, 191, 36, 0.15);
  color: #fde68a;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
}
.banner-close { width: 30px; height: 30px; background: transparent; border-color: transparent; color: #fde68a; }
.banner-close .icon { width: 14px; height: 14px; }

.toast {
  position: fixed;
  z-index: 70;
  left: 50%;
  bottom: calc(112px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  max-width: min(520px, calc(100vw - 32px));
  padding: 11px 18px;
  border-radius: 12px;
  background: rgba(16, 23, 42, 0.92);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13.5px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  backdrop-filter: blur(16px);
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.45);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* overlay */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 7, 14, 0.72);
  backdrop-filter: blur(10px);
  animation: fadeUp 0.2s ease both;
}
.overlay-card {
  width: min(420px, 100%);
  padding: 26px;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: rgba(10, 16, 30, 0.96);
  box-shadow: var(--shadow);
}
.overlay-card h3 { font-size: 19px; margin-bottom: 8px; }
.overlay-card p { font-size: 14px; color: var(--muted); margin-bottom: 20px; }
.overlay-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.overlay-actions .btn { flex: 1; min-width: 130px; }

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

@media (max-width: 899px) {
  .home-main { grid-template-columns: 1fr; gap: 26px; padding: 22px 0 18px; }
  .hero h1 { font-size: clamp(38px, 8.4vw, 56px); }
  .join-card { justify-self: stretch; max-width: 560px; margin: 0 auto; }
  .hero-sub { font-size: 15px; }
  .topbar .pill { display: none; }
  .home-foot { justify-content: center; }
  .hero { text-align: center; }
  .hero .chips, .hero .trust { justify-content: center; }
  .eyebrow { margin-bottom: 12px; }
}

@media (max-width: 560px) {
  .room-code { font-size: 14px; letter-spacing: 0.12em; }
  .latency { display: none; }
  .room-top { padding-top: calc(8px + env(safe-area-inset-top)); }
  .conn-pill { padding: 6px 9px; font-size: 11px; }
  .peer-count { padding: 6px 9px; }
  .stage { padding: 0 6px 2px; }
  .stage-main { gap: 8px; padding: 4px; }
  .stage-main.grid { grid-template-columns: 1fr; }
  .controls { gap: 8px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .ctrl-group { padding: 6px; gap: 0; }
  .ctrl { width: 60px; }
  .ctrl-label { font-size: 9.5px; }
  .empty-card { padding: 22px 16px; }
  .empty-actions .btn { width: 100%; }
  .toast { bottom: calc(104px + env(safe-area-inset-bottom)); }
}

@media (min-width: 900px) and (max-height: 760px) {
  .home-main { padding: 14px 0; }
  .hero h1 { font-size: clamp(38px, 4.6vw, 58px); }
  .hero-sub, .chips { margin-bottom: 16px; }
}

/* touch: bigger hit areas, no hover-only affordance */
@media (pointer: coarse) {
  .tile-expand { width: 40px; height: 40px; opacity: 0.9; }
  .icon-btn { width: 42px; height: 42px; }
  .btn { min-height: 48px; }
}

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

/* ------------------------- extra runtime states ------------------------- */

.stage.focus-mode .tile.focused video { object-fit: contain; background: #000; }

.tile.needs-tap::after {
  content: "點一下開啟聲音";
  position: absolute;
  z-index: 4;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 9px 14px;
  border-radius: 999px;
  background: rgba(5, 9, 18, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  backdrop-filter: blur(10px);
  pointer-events: none;
}

/* avoid iOS double-tap zoom / accidental text selection in call UI */
.view-room { touch-action: manipulation; }
.view-room .tile { -webkit-user-select: none; user-select: none; }

/* iOS: keep the video from forcing its own fullscreen controls */
.view-room video::-webkit-media-controls { display: none !important; }


/* invite-first landing: the join action becomes the primary CTA */
.join-card.invite-mode .join-row { grid-template-columns: minmax(0, 1fr); }
.join-card.invite-mode .join-row .btn { width: 100%; }

.text-link {
  appearance: none;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 12.5px;
  font-family: inherit;
  margin-top: 14px;
  padding: 6px 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  touch-action: manipulation;
}
.text-link:hover { color: var(--text); }

/* Safari (iPad) needs the prefixed backdrop-filter */
.join-card, .ctrl-group, .empty-card, .banner, .toast, .overlay, .invite-box {
  -webkit-backdrop-filter: blur(20px) saturate(140%);
}
.topbar .pill, .chips li, .badge {
  -webkit-backdrop-filter: blur(10px);
}
