html, body { background: #0b0c10; user-select: none; -webkit-tap-highlight-color: transparent; }
.screen { position: fixed; inset: 0; }
.center {
  display: flex; align-items: center; justify-content: center; overflow-y: auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: radial-gradient(circle at 30% 0%, rgba(124, 92, 255, 0.18), transparent 55%), #0b0c10;
}
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.spacer { flex: 1; }
button { touch-action: manipulation; }

/* ------------------------------------------------------------ cards */
.card {
  width: 100%; max-width: 420px; padding: 28px 24px 22px; border-radius: 22px;
  background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px; text-align: center;
}
.card.wide { max-width: 860px; text-align: left; }
.logo { width: 56px; height: 56px; margin: 0 auto; }
.card h1 { margin: 0; font-size: 24px; font-weight: 700; }
.card p { margin: 0; line-height: 1.5; }
.field { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.field span { color: #cdd0db; font-size: 13px; }
.field input { height: 46px; font-size: 16px; user-select: text; }
.btn.big { height: 48px; font-size: 16px; font-weight: 600; }
.btn.danger { background: var(--rec); border-color: var(--rec); color: #fff; }

.pre-grid { display: grid; grid-template-columns: 1.25fr 1fr; gap: 24px; align-items: center; }
.legal { margin: 4px 0 0; font-size: 12px; line-height: 1.5; color: var(--dim); }
.legal a { color: var(--muted); }
.preview { position: relative; aspect-ratio: 4 / 3; border-radius: 18px; overflow: hidden; background: #000; }
.preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.preview-off { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: var(--muted); background: #121318; }
.preview-off svg { width: 34px; height: 34px; }
.preview-ctl { position: absolute; left: 0; right: 0; bottom: 14px; display: flex; justify-content: center; gap: 12px; }
.pre-info { display: flex; flex-direction: column; gap: 14px; }
.kind { align-self: flex-start; padding: 4px 10px; border-radius: 8px; background: var(--accent-soft); color: var(--accent-2); font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.kind.live { background: rgba(255, 59, 48, 0.15); color: #ff8a80; }

/* round buttons */
.rbtn, .cbtn {
  position: relative; width: 52px; height: 52px; border-radius: 50%; border: 0; cursor: pointer; color: #fff;
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  background: rgba(48, 51, 64, 0.92); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: background 0.15s, transform 0.08s;
}
.rbtn:hover, .cbtn:hover { background: rgba(68, 72, 90, 0.95); }
.rbtn:active, .cbtn:active { transform: scale(0.94); }
.rbtn svg, .cbtn svg { width: 22px; height: 22px; }
.rbtn.off, .cbtn.off { background: #f2f3f7; color: #16171d; }
.cbtn.on { background: var(--accent); }
.cbtn.danger { background: var(--rec); width: 64px; border-radius: 26px; }
.cbtn .emoji { font-size: 21px; line-height: 1; }
.cbtn[hidden] { display: none; }
.badge { position: absolute; top: -3px; right: -3px; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px; background: var(--rec); font-size: 11px; line-height: 19px; font-weight: 700; }

/* ------------------------------------------------------------ room */
#room { display: flex; flex-direction: column; background: #0b0c10; }
.topbar {
  flex: none; display: flex; align-items: center; gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
}
.topbar b { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.timer { color: var(--muted); font: 600 13px "Cascadia Mono", Consolas, monospace; }
.badge-live { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: 6px; background: var(--rec); color: #fff; font: 800 11px/1 "Segoe UI", system-ui, sans-serif; letter-spacing: 0.06em; flex: none; }
.badge-live i { width: 6px; height: 6px; border-radius: 50%; background: #fff; animation: blink 1.4s infinite; }
@keyframes blink { 50% { opacity: 0.3; } }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 17px; border: 0; background: rgba(255, 255, 255, 0.08); color: #e6e8f0; cursor: pointer; font-size: 13px; font-weight: 600; flex: none; }
.chip:hover { background: rgba(255, 255, 255, 0.14); }
.chip svg { width: 16px; height: 16px; }

.stage-wrap { position: relative; flex: 1; min-height: 0; display: flex; gap: 10px; padding: 0 12px 8px; }
.grid { flex: 1; display: flex; flex-wrap: wrap; gap: 10px; align-content: center; justify-content: center; }
.grid .tile { flex: none; width: var(--tw, 320px); height: var(--th, 180px); }
.stage { flex: 1; min-width: 0; display: flex; }
.stage .tile { flex: 1; }
.strip { flex: none; display: flex; flex-direction: column; gap: 10px; width: 220px; overflow-y: auto; scrollbar-width: none; }
.strip::-webkit-scrollbar { display: none; }
.strip .tile { flex: none; aspect-ratio: 16 / 10; }
.strip .tile.portrait { width: 130px; align-self: center; }
#room.mode-grid .stage, #room.mode-grid .strip { display: none; }
#room:not(.mode-grid) .grid { display: none; }
#room.focus .strip, #room.focus .pip { display: none; }
.strip:empty { display: none; }

.tile {
  position: relative; min-width: 0; min-height: 0; border-radius: 16px; overflow: hidden; background: #16171e; cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  transition: box-shadow 0.2s;
}
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.tile.screen video, .stage .tile video, .tile.fit video { object-fit: contain; }
/* zoom inside a video (pinch / wheel); the wrapper is scaled, the video keeps its mirroring */
.vwrap { position: absolute; inset: 0; transform-origin: 0 0; will-change: transform; }
.stage .tile, .grid .tile { touch-action: none; }
.tile.zoomed { cursor: grab; }
.tile.zoomed:active { cursor: grabbing; }
.zchip {
  position: absolute; left: 50%; top: 10px; transform: translateX(-50%); z-index: 3; padding: 5px 12px; border: 0; border-radius: 999px;
  background: rgba(0, 0, 0, 0.65); color: #fff; font: 600 12.5px "Segoe UI", sans-serif; cursor: pointer; backdrop-filter: blur(6px);
}
.zchip[hidden] { display: none; }
.tile.mirror video { transform: scaleX(-1); }
.tile.speaking { box-shadow: inset 0 0 0 3px var(--ok); }
.tile .avatar {
  position: absolute; left: 50%; top: 50%; width: 30%; max-width: 110px; aspect-ratio: 1; transform: translate(-50%, -50%);
  border-radius: 50%; display: grid; place-items: center; font: 700 clamp(18px, 4vw, 40px) "Segoe UI", sans-serif; color: #fff;
  background: linear-gradient(135deg, var(--c1, #7c5cff), var(--c2, #ff4d8a));
}
.tile.has-video .avatar { display: none; }
.tile .name {
  position: absolute; left: 8px; bottom: 8px; max-width: calc(100% - 16px); display: flex; align-items: center; gap: 5px;
  padding: 3px 8px; border-radius: 8px; background: rgba(0, 0, 0, 0.55); color: #fff; font-size: 12.5px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; backdrop-filter: blur(4px);
}
.tile .name svg { width: 13px; height: 13px; flex: none; }
.tile .name .muted-ic { color: #ff8a80; }
.tile .hand { position: absolute; top: 8px; left: 8px; font-size: 22px; animation: wave 1s ease-in-out infinite; }
@keyframes wave { 50% { transform: rotate(18deg); } }
.tile .tbtn {
  position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; border-radius: 10px; border: 0; cursor: pointer;
  background: rgba(0, 0, 0, 0.5); color: #fff; display: grid; place-items: center; opacity: 0; transition: opacity 0.15s;
}
.tile .tbtn svg { width: 16px; height: 16px; }
.tile:hover .tbtn, .stage .tile .tbtn { opacity: 1; }
.tile.pinned::after { content: ""; position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 0 0 2px var(--accent-2); pointer-events: none; }

/* 1:1 call: the other person fills the screen, you in a corner */
.pip {
  position: absolute; right: 22px; bottom: 18px; width: 220px; aspect-ratio: 16 / 10; z-index: 4; border-radius: 16px; overflow: hidden;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.55), 0 0 0 2px rgba(255, 255, 255, 0.85); cursor: grab; touch-action: none;
}
.pip:empty { display: none; }
.pip.portrait { width: 150px; }
.pip .tile { position: absolute; inset: 0; border-radius: 0; }
.pip .tile .name { display: none; }

/* TikTok-style floating comments */
.floaters {
  position: absolute; left: 22px; bottom: 16px; z-index: 5; width: min(360px, 70%); display: flex; flex-direction: column; gap: 6px;
  pointer-events: none;
}
.floater {
  align-self: flex-start; max-width: 100%; padding: 7px 11px; border-radius: 14px; color: #fff; font-size: 14px; line-height: 1.35;
  background: rgba(10, 10, 16, 0.5); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); word-wrap: break-word;
  animation: floatIn 0.35s cubic-bezier(.2,.8,.2,1) both;
}
.floater b { color: #c9b8ff; margin-right: 6px; font-weight: 700; }
.floater.host b { color: #ff9f97; }
.floater.sys { background: rgba(124, 92, 255, 0.45); }
.floater.out { animation: floatOut 0.8s ease forwards; }
@keyframes floatIn { from { opacity: 0; transform: translateY(14px) scale(0.96); } }
@keyframes floatOut { to { opacity: 0; transform: translateY(-14px); } }
#room.no-floaters .floaters { display: none; }

.reactions { position: absolute; right: 30px; bottom: 10px; width: 80px; height: 60%; pointer-events: none; z-index: 5; }
.reaction { position: absolute; bottom: 0; font-size: 30px; animation: rise 2.6s cubic-bezier(.3,.7,.4,1) forwards; }
@keyframes rise {
  0% { transform: translate(0, 0) scale(0.6); opacity: 0; }
  12% { opacity: 1; transform: translate(0, -20px) scale(1.1); }
  100% { transform: translate(var(--dx, 0), -360px) scale(0.9); opacity: 0; }
}

.empty-note { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--muted); text-align: center; padding: 20px; pointer-events: none; }
.empty-note b { color: var(--text); font-size: 18px; }
.empty-note .chip { pointer-events: auto; }

.controls {
  flex: none; display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap;
  padding: 8px max(12px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

/* side panels */
.panel {
  position: absolute; top: 60px; right: 12px; bottom: 86px; width: 340px; z-index: 6; display: flex; flex-direction: column;
  background: rgba(20, 21, 28, 0.97); border: 1px solid var(--line-2); border-radius: 18px; box-shadow: var(--shadow);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 10px 16px; border-bottom: 1px solid var(--line); }
.panel-head .chk { margin-left: auto; margin-right: 6px; font-size: 12.5px; color: var(--muted); }
.icon-btn { width: 34px; height: 34px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: var(--panel-3); color: #fff; }
.messages { flex: 1; overflow-y: auto; padding: 10px 14px; display: flex; flex-direction: column; gap: 8px; user-select: text; }
.msg b { display: block; font-size: 12.5px; color: var(--accent-2); }
.msg.host b { color: #ff8a80; }
.msg.me b { color: var(--ok); }
.msg span { font-size: 14px; line-height: 1.4; white-space: pre-wrap; word-wrap: break-word; }
.msg.sys span { color: var(--muted); font-size: 12.5px; font-style: italic; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; height: 44px; font-size: 16px; user-select: text; }
.chat-form .btn { width: 48px; height: 44px; padding: 0; }
.people { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.person { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: var(--panel-2); }
.person .av { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; background: linear-gradient(135deg, var(--c1), var(--c2)); flex: none; }
.person b { flex: 1; min-width: 0; font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person em { font-style: normal; color: var(--muted); font-size: 11.5px; }
.person .ic { display: flex; gap: 4px; color: var(--muted); }
.person .ic svg { width: 15px; height: 15px; }
.person .ic .on { color: var(--ok); }
.person .icon-btn { width: 30px; height: 30px; }
.person .icon-btn svg { width: 15px; height: 15px; }
.host-tools { display: flex; flex-direction: column; gap: 10px; padding: 12px; border-top: 1px solid var(--line); }
.chk { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: #cdd0db; cursor: pointer; }
.chk input { accent-color: var(--accent); width: 16px; height: 16px; }

.overlay { position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.6); padding: 16px; }
.ov-card { max-width: 420px; padding: 24px; border-radius: 18px; background: var(--panel); border: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.ov-card b { font-size: 17px; }
.ov-card span { color: var(--muted); font-size: 14px; line-height: 1.5; }
.spinner { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--panel-3); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------ phones */
@media (max-width: 760px) {
  .pre-grid { grid-template-columns: 1fr; }
  .card.wide { padding: 18px; }
  .topbar .chip span { display: none; }
  .topbar .chip { width: 38px; padding: 0; justify-content: center; }
  .stage-wrap { flex-direction: column; padding: 0 6px 4px; gap: 6px; }
  .strip { flex-direction: row; width: auto; height: 92px; overflow-x: auto; overflow-y: hidden; }
  .strip .tile { height: 100%; aspect-ratio: 4 / 3; }
  .strip .tile.portrait { width: auto; align-self: auto; }
  .grid { gap: 6px; }
  .tile { border-radius: 12px; }
  .pip { width: 150px; aspect-ratio: 3 / 4; right: 12px; bottom: 12px; border-radius: 12px; }
  .pip.portrait { width: 100px; }
  .floaters { left: 12px; bottom: 10px; width: 78%; }
  #room:not(.mode-grid) .strip:not(:empty) ~ .floaters { bottom: 108px; }
  .floater { font-size: 13px; padding: 6px 10px; }
  .reactions { right: 10px; }
  .controls { gap: 7px; padding-top: 6px; flex-wrap: nowrap; }
  .cbtn { width: 46px; height: 46px; flex: none; }
  .cbtn svg { width: 21px; height: 21px; }
  .cbtn.danger { width: 56px; }
  #overlayBtn { display: none; } /* the toggle lives in the chat header on phones */
  .panel { left: 0; right: 0; top: auto; bottom: 0; width: auto; height: 62%; border-radius: 18px 18px 0 0; animation: sheet 0.22s ease-out; }
  @keyframes sheet { from { transform: translateY(40%); opacity: 0; } }
  .chat-form { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
}
@media (max-width: 380px) {
  .cbtn { width: 42px; height: 42px; }
  .cbtn.danger { width: 50px; }
  .controls { gap: 5px; }
}
