/* Studio – frosted glass on a soft, dark, blurred-light backdrop.
   Pills and round buttons, white/grey only, no colour accent (red only for recording). */
:root {
  --text: #f3f3f6;
  --muted: rgba(235, 236, 245, 0.56);
  --faint: rgba(235, 236, 245, 0.34);
  --glass: rgba(255, 255, 255, 0.065);
  --glass-strong: rgba(255, 255, 255, 0.12);
  --glass-press: rgba(255, 255, 255, 0.18);
  --well: rgba(10, 11, 16, 0.32);
  --rim: rgba(255, 255, 255, 0.16);
  --rim-soft: rgba(255, 255, 255, 0.09);
  --rec: #ff5a52;
  --ok: #a9e3c4;
  --warn: #f1d48a;
  --pill: 999px;
  --card: 30px;
  --blur: blur(28px) saturate(150%);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.38), 0 2px 6px rgba(0, 0, 0, 0.22);
  --edge: inset 0 1px 0 rgba(255, 255, 255, 0.22), inset 0 -1px 0 rgba(0, 0, 0, 0.28);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; color: var(--text); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
html { background: #1c1d24; }
/* soft window light falling across the room */
body::before {
  content: ""; position: fixed; inset: -12%; z-index: -1; pointer-events: none;
  background:
    radial-gradient(55% 45% at 72% 4%, rgba(205, 208, 224, 0.42), transparent 62%),
    radial-gradient(40% 40% at 18% 70%, rgba(120, 126, 150, 0.22), transparent 70%),
    linear-gradient(102deg, transparent 0 14%, rgba(8, 9, 14, 0.42) 17% 24%, transparent 28% 50%, rgba(8, 9, 14, 0.38) 53% 60%, transparent 64%),
    linear-gradient(8deg, transparent 0 38%, rgba(8, 9, 14, 0.28) 42% 47%, transparent 52%),
    linear-gradient(180deg, #686a78 0%, #3a3b46 38%, #22232b 72%, #1a1b21 100%);
  filter: blur(34px);
}
[hidden] { display: none !important; }
h1 { font-size: 30px; margin: 0 0 18px; font-weight: 600; letter-spacing: -0.02em; }
h3 { font-size: 12px; color: var(--muted); margin: 0 0 10px; font-weight: 500; letter-spacing: 0.02em; }
a { color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
svg { display: block; }

.glass, .card, .lobby-form, .producer-panel, .script-panel, .popup, .inbox, .pill, .dock, .round {
  background: var(--glass);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  border: 1px solid var(--rim);
  box-shadow: var(--edge), var(--shadow);
}

/* buttons */
button { background: var(--glass); border: 1px solid var(--rim-soft); border-radius: var(--pill); padding: 10px 18px; cursor: pointer; box-shadow: var(--edge); transition: background 0.15s, border-color 0.15s, transform 0.1s; }
button:hover:not(:disabled) { background: var(--glass-strong); border-color: var(--rim); }
button:active:not(:disabled) { background: var(--glass-press); transform: scale(0.985); }
button:disabled { opacity: 0.4; cursor: default; }
button.primary { background: rgba(255, 255, 255, 0.86); color: #17181e; border-color: rgba(255, 255, 255, 0.9); font-weight: 600; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3), inset 0 1px 0 #fff; }
button.primary:hover:not(:disabled) { background: #fff; }
button.big { width: 100%; padding: 15px 20px; font-size: 16px; }
button.icon { padding: 4px 10px; font-size: 13px; }

/* form fields: recessed wells */
input, select, textarea { width: 100%; background: var(--well); border: 1px solid var(--rim-soft); border-radius: 18px; padding: 12px 16px; margin-top: 6px; box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.25); }
input, select { border-radius: var(--pill); }
select { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(-45deg, transparent 50%, var(--muted) 50%); background-position: calc(100% - 22px) 52%, calc(100% - 17px) 52%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 40px; }
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus { outline: none; border-color: rgba(255, 255, 255, 0.32); }
textarea { resize: vertical; }
label { display: block; margin: 0 0 14px; color: var(--muted); font-size: 13px; }
label input, label select { color: var(--text); font-size: 15px; }
label.check { display: flex; gap: 10px; align-items: center; color: var(--text); font-size: 14px; }
input[type="checkbox"] { appearance: none; -webkit-appearance: none; width: 20px; height: 20px; flex: none; margin: 0; padding: 0; border-radius: 7px; background: var(--well); border: 1px solid var(--rim); cursor: pointer; display: grid; place-items: center; }
input[type="checkbox"]:checked { background: rgba(255, 255, 255, 0.85); border-color: #fff; }
input[type="checkbox"]:checked::after { content: ""; width: 9px; height: 5px; border-left: 2px solid #17181e; border-bottom: 2px solid #17181e; transform: translateY(-1px) rotate(-45deg); }

.hint { color: var(--faint); font-size: 12px; font-weight: 400; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: #ffb1ab; }
.note { background: var(--glass); border: 1px solid var(--rim-soft); padding: 12px 16px; border-radius: 18px; margin-bottom: 16px; font-size: 14px; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.spacer { flex: 1; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.rec { color: var(--rec); }

.screen { min-height: 100vh; }
.center { display: flex; align-items: center; justify-content: center; padding: 24px; }
.card { border-radius: var(--card); padding: 36px; max-width: 500px; width: 100%; }

/* lobby */
.lobby { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(320px, 1fr); gap: 36px; max-width: 1180px; margin: 0 auto; padding: 64px 28px; align-items: center; min-height: 100vh; }
.lobby-preview { position: relative; background: #0c0d11; border: 1px solid var(--rim); border-radius: var(--card); aspect-ratio: 16 / 9; overflow: hidden; box-shadow: var(--edge), var(--shadow); }
.lobby-preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.preview-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.meter { position: absolute; left: 22px; right: 22px; bottom: 20px; height: 6px; border-radius: var(--pill); background: rgba(0, 0, 0, 0.35); border: 1px solid var(--rim-soft); overflow: hidden; -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
.meter div { height: 100%; width: 0; background: linear-gradient(90deg, rgba(255,255,255,0.55), #fff); box-shadow: 0 0 12px rgba(255, 255, 255, 0.6); transition: width 0.06s linear; }
.lobby-form { border-radius: var(--card); padding: 32px; }
.eyebrow { color: var(--muted); font-size: 13px; margin: 0 0 6px; }
.consent { color: var(--faint); font-size: 12.5px; margin: 16px 0; }
#btn-devices { margin-bottom: 18px; }
@media (max-width: 860px) { .lobby { grid-template-columns: 1fr; padding: 18px; gap: 18px; min-height: 0; } }

/* room */
#room { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 16px 18px 0; }
.topbar > div { border-radius: var(--pill); padding: 8px 16px; font-size: 14px; background: var(--glass); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur); border: 1px solid var(--rim-soft); box-shadow: var(--edge); }
.topbar > div:empty { display: none; }
.room-name { font-weight: 600; }
.rec-state { display: flex; align-items: center; gap: 9px; color: var(--muted); }
.rec-state .dot { width: 9px; height: 9px; border-radius: 50%; background: rgba(255, 255, 255, 0.3); }
.rec-state.on { color: var(--text); border-color: rgba(255, 90, 82, 0.45) !important; }
.rec-state.on .dot { background: var(--rec); box-shadow: 0 0 10px var(--rec), 0 0 22px rgba(255, 90, 82, 0.5); animation: pulse 1.6s infinite; }
#rec-timer { font-variant-numeric: tabular-nums; }
#rec-timer:empty { display: none; }
.upload-state { margin-left: auto; color: var(--muted); font-size: 13px !important; }
.upload-state.warn { color: var(--warn); }
@keyframes pulse { 50% { opacity: 0.4; } }

.room-body { flex: 1; display: flex; min-height: 0; gap: 16px; padding: 10px 18px 0; }
.stage { flex: 1; min-width: 0; position: relative; }
.stage-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
/* tile size is computed in JS (fitGrid): the column count that gives the largest 16:9 tiles wins */
.grid { position: absolute; inset: 0; display: flex; flex-wrap: wrap; gap: var(--gap, 14px); align-content: flex-start; justify-content: center; }
.tile.pip { position: absolute; right: 0; bottom: 0; width: var(--pip-w, 220px); border-radius: 18px; z-index: 2; box-shadow: var(--edge), 0 14px 40px rgba(0, 0, 0, 0.5); }
.tile.pip .tile-name { left: 9px; bottom: 9px; padding: 3px 10px; font-size: 12px; }
.tile.pip .tile-badges { transform: scale(0.85); transform-origin: top right; }
.tile { position: relative; flex: 0 0 auto; width: var(--tile-w, 100%); aspect-ratio: 16 / 9; background: #0b0c10; border: 1px solid var(--rim); border-radius: 26px; overflow: hidden; box-shadow: var(--edge), var(--shadow); }
.tile video { width: 100%; height: 100%; object-fit: cover; background: #0b0c10; }
.tile.self video { transform: scaleX(-1); }
.tile.cam-off video { opacity: 0; }
.tile.cam-off::after { content: attr(data-off); position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.tile-name, .badge { -webkit-backdrop-filter: blur(16px) saturate(140%); backdrop-filter: blur(16px) saturate(140%); background: rgba(20, 21, 28, 0.42); border: 1px solid var(--rim-soft); border-radius: var(--pill); }
.tile-name { position: absolute; left: 14px; bottom: 14px; padding: 5px 13px; font-size: 13px; }
.tile-badges { position: absolute; right: 14px; top: 14px; display: flex; gap: 6px; }
.badge { padding: 4px 11px; font-size: 12px; }
.badge.rec { color: #fff; }
.badge.rec::first-letter { color: var(--rec); text-shadow: 0 0 8px var(--rec); }

/* floating dock with round buttons + labels */
.controls { display: flex; gap: 14px; justify-content: center; align-items: center; padding: 16px 18px 20px; }
.dock { display: flex; gap: 4px; padding: 6px; border-radius: var(--pill); }
.dock-btn { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 96px; padding: 10px 16px 9px; border-radius: var(--pill); background: transparent; border-color: transparent; box-shadow: none; color: var(--text); }
.dock-btn:hover:not(:disabled) { background: var(--glass); border-color: var(--rim-soft); box-shadow: var(--edge); }
.dock-btn.active { background: var(--glass-strong); border-color: var(--rim-soft); box-shadow: var(--edge); }
.dock-btn .lbl { font-size: 12.5px; color: var(--muted); }
.dock-btn svg { width: 24px; height: 24px; }
.dock-btn .ic-off { display: none; }
.dock-btn.off .ic-on { display: none; }
.dock-btn.off .ic-off { display: block; color: #ffb1ab; }
.dock-btn.off .lbl { color: #ffb1ab; }
.dock-btn { position: relative; }
.dock-btn .count { position: absolute; top: 6px; right: 26px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #fff; color: #17181e; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.round { width: 62px; height: 62px; padding: 0; border-radius: 50%; display: grid; place-items: center; }
.round svg { width: 24px; height: 24px; }
.round.danger:hover { background: rgba(255, 90, 82, 0.18); border-color: rgba(255, 90, 82, 0.4); }

/* side panels */
.script-panel, .producer-panel { width: 370px; border-radius: var(--card); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.producer-panel { overflow-y: auto; }
body.panel-closed .producer-panel { display: none; }
.panel-head { display: flex; align-items: center; gap: 6px; padding: 16px 16px 14px 22px; border-bottom: 1px solid var(--rim-soft); }
.script-body { padding: 18px 24px 40px; overflow-y: auto; flex: 1; font-size: 18px; line-height: 1.55; }
.script-body h2, .script-body h3, .script-body h4, .script-body h5 { color: var(--text); font-size: 1.15em; font-weight: 600; margin: 1.1em 0 0.4em; letter-spacing: -0.01em; }
.script-body ul, .script-body ol { padding-left: 1.2em; }
.script-body li { margin: 0.3em 0; }
.script-body ul.checks { list-style: none; padding-left: 0; }
.script-body label { color: var(--text); font-size: inherit; display: flex; gap: 0.6em; align-items: center; margin: 0; }
.script-body label:has(input:checked) { color: var(--faint); text-decoration: line-through; }
.script-panel.collapsed { width: 64px; }
.script-panel.collapsed .script-body, .script-panel.collapsed #script-title, .script-panel.collapsed #script-smaller, .script-panel.collapsed #script-bigger { display: none; }
.panel-section { padding: 20px 22px; border-bottom: 1px solid var(--rim-soft); }
.panel-section:last-child { border-bottom: 0; }
.panel-section input, .panel-section textarea, .panel-section select { margin: 0 0 10px; }
.rec-btn { width: 100%; padding: 14px; font-weight: 600; font-size: 15px; display: flex; align-items: center; justify-content: center; gap: 10px; }
.rec-btn::before { content: ""; width: 11px; height: 11px; border-radius: 50%; background: var(--rec); box-shadow: 0 0 10px var(--rec); }
.rec-btn.on { background: rgba(255, 90, 82, 0.16); border-color: rgba(255, 90, 82, 0.5); }
.rec-btn.on::before { border-radius: 3px; }
.people { list-style: none; margin: 0; padding: 0; }
.people li { padding: 12px 14px; margin-bottom: 8px; border-radius: 20px; background: var(--well); border: 1px solid var(--rim-soft); }
.people li.muted { background: none; border: 0; padding: 0; }
.people .status { color: var(--muted); font-size: 12px; margin: 6px 0 0 30px; line-height: 1.6; }
.people label.check { margin: 0; }
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--rim-soft); padding: 1px 8px; border-radius: var(--pill); font-weight: 400; }
.msg-log { list-style: none; margin: 12px 0 0; padding: 0; max-height: 240px; overflow-y: auto; }
.msg-log li { padding: 9px 0; border-top: 1px solid var(--rim-soft); font-size: 13px; }
.msg-log .meta { color: var(--faint); font-size: 11.5px; margin-bottom: 2px; }
.file-btn { display: inline-flex; align-items: center; background: var(--glass); border: 1px solid var(--rim-soft); border-radius: var(--pill); padding: 8px 16px; color: var(--text); cursor: pointer; margin: 0 0 10px; font-size: 13px; box-shadow: var(--edge); }
.file-btn:hover { background: var(--glass-strong); }
.file-btn input { display: none; }

@media (max-width: 900px) {
  .room-body { flex-direction: column; }
  .script-panel, .producer-panel { width: auto; max-height: 45vh; }
  .script-panel.collapsed { width: auto; max-height: 64px; }
  .dock-btn { min-width: 72px; }
}

/* producer messages popping up for the guest */
.popups { position: fixed; top: 84px; left: 50%; transform: translateX(-50%); width: min(600px, calc(100vw - 24px)); display: flex; flex-direction: column; gap: 12px; z-index: 50; pointer-events: none; }
.popup { pointer-events: auto; border-radius: var(--card); padding: 20px 20px 20px 26px; background: rgba(255, 255, 255, 0.13); border-color: rgba(255, 255, 255, 0.3); box-shadow: var(--edge), 0 30px 80px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.05), 0 0 60px rgba(255, 255, 255, 0.1); animation: pop 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2); display: grid; grid-template-columns: 1fr auto; gap: 6px 18px; align-items: center; }
.popup-from { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.popup-text { font-size: 22px; line-height: 1.35; font-weight: 500; white-space: pre-wrap; letter-spacing: -0.01em; }
.popup button { min-width: 72px; }
.popup.out { opacity: 0; transform: translateY(-8px) scale(0.98); transition: all 0.18s; }
@keyframes pop { from { opacity: 0; transform: translateY(-12px) scale(0.96); } }

/* guest's message history */
.inbox { position: fixed; bottom: 112px; left: 50%; transform: translateX(-50%); width: min(460px, calc(100vw - 24px)); max-height: min(60vh, 520px); display: flex; flex-direction: column; border-radius: var(--card); z-index: 40; overflow: hidden; animation: pop 0.22s ease-out; }
.inbox[hidden] { display: none; }
.inbox-list { list-style: none; margin: 0; padding: 4px 22px 16px; overflow-y: auto; }
.inbox-list li { padding: 12px 0; border-top: 1px solid var(--rim-soft); }
.inbox-list li:first-child { border-top: 0; }
.inbox-list .meta { color: var(--faint); font-size: 11.5px; margin-bottom: 4px; }
.inbox-list .text { font-size: 16px; line-height: 1.4; white-space: pre-wrap; }
.toast { position: fixed; bottom: 110px; left: 50%; transform: translateX(-50%); background: rgba(60, 20, 20, 0.5); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur); border: 1px solid rgba(255, 120, 110, 0.4); padding: 12px 18px; border-radius: var(--pill); z-index: 60; max-width: 90vw; }

.progress { height: 8px; background: var(--well); border: 1px solid var(--rim-soft); border-radius: var(--pill); overflow: hidden; margin: 22px 0 10px; }
.progress div { height: 100%; width: 0; background: linear-gradient(90deg, rgba(255,255,255,0.55), #fff); box-shadow: 0 0 12px rgba(255,255,255,0.5); transition: width 0.3s; }

/* admin */
.admin { max-width: 1000px; margin: 0 auto; padding: 48px 22px 80px; }
.admin .card { max-width: none; margin-bottom: 18px; padding: 24px 26px; }
.admin table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
.admin td, .admin th { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--rim-soft); vertical-align: top; }
.admin th { color: var(--faint); font-weight: 500; font-size: 12px; }
.admin code, .cmd { display: inline-block; background: var(--well); border: 1px solid var(--rim-soft); padding: 4px 12px; border-radius: var(--pill); font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; margin-bottom: 6px; }
.linkrow { display: grid; grid-template-columns: 56px 1fr auto 84px; gap: 8px; align-items: center; margin: 6px 0; }
.linkrow .btn-link { text-align: center; text-decoration: none; color: inherit; padding: 8px 14px; font-size: 13px; border-radius: var(--pill); background: var(--glass); border: 1px solid var(--rim-soft); box-shadow: var(--edge); }
.linkrow .btn-link:hover { background: var(--glass-strong); border-color: var(--rim); }
.linkrow input { margin: 0; font-size: 12.5px; padding: 9px 14px; }
.linkrow button { white-space: nowrap; padding: 8px 14px; font-size: 13px; }
.inline { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.inline label { margin: 0; flex: 1; min-width: 170px; }

/* In the call no live blur: backdrop-filter over playing video costs GPU/CPU on every frame, which a
   weak laptop takes away from its own recording (measured: test source stuttered by up to 400 ms).
   The background is already a soft blurred gradient, so slightly denser glass looks the same. */
#room, #room * { -webkit-backdrop-filter: none !important; backdrop-filter: none !important; }
#room { --glass: rgba(255, 255, 255, 0.085); --glass-strong: rgba(255, 255, 255, 0.13); }
#room .tile-name, #room .badge { background: rgba(20, 21, 28, 0.62); }
#room .inbox, #room .producer-panel, #room .script-panel { background: rgba(58, 60, 70, 0.72); }
#room .popup { background: rgba(92, 94, 104, 0.82); }
.dock-btn .count[hidden] { display: none; }
.lang-select { width: auto; margin: 0 0 0 4px; padding: 5px 30px 5px 12px; font-size: 12.5px; background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%; }

/* producer off stage: small presence pill instead of a tile */
.topbar > .listeners { display: flex; gap: 8px; padding: 0; background: none; border: 0; box-shadow: none; -webkit-backdrop-filter: none; backdrop-filter: none; }
.listener { display: flex; align-items: center; gap: 8px; padding: 8px 16px 8px 12px; border-radius: var(--pill); font-size: 14px; color: var(--muted); background: var(--glass); border: 1px solid var(--rim-soft); box-shadow: var(--edge); }
.listener svg { width: 17px; height: 17px; }
.listener.mic { color: var(--text); }

/* confirmation before leaving during a recording */
.modal-wrap { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 20px; background: rgba(8, 9, 13, 0.55); animation: fade 0.15s ease-out; }
.modal-wrap[hidden] { display: none; }
.modal { width: min(460px, 100%); border-radius: var(--card); padding: 26px 26px 22px; background: rgba(70, 72, 82, 0.92); border: 1px solid var(--rim); box-shadow: var(--edge), 0 30px 80px rgba(0, 0, 0, 0.55); animation: pop 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2); }
.modal h2 { margin: 0 0 8px; font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.modal p { margin: 0 0 20px; color: var(--muted); line-height: 1.45; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; }
.modal-actions button { width: 100%; padding: 12px 18px; }
button.danger { color: #ffb1ab; border-color: rgba(255, 90, 82, 0.35); }
button.danger:hover:not(:disabled) { background: rgba(255, 90, 82, 0.18); border-color: rgba(255, 90, 82, 0.55); }
@keyframes fade { from { opacity: 0; } }
