:root {
  --bg: #0b0f17;
  --bg-2: #111827;
  --glass: rgba(17, 24, 39, 0.62);
  --glass-strong: rgba(17, 24, 39, 0.86);
  --line: rgba(148, 163, 184, 0.16);
  --line-strong: rgba(148, 163, 184, 0.3);
  --text: #e6edf7;
  --muted: #8b98ad;
  --accent: #4de1ff;
  --accent-2: #8b5cf6;
  --good: #34d399;
  --fair: #fbbf24;
  --poor: #f87171;
  --live: #ff3b5c;
  --radius: 16px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg .fill { fill: currentColor; stroke: none; }
[hidden] { display: none !important; }

#app { position: fixed; inset: 0; display: grid; grid-template-rows: auto 1fr; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px; padding: 14px 18px calc(14px);
  padding-top: max(14px, env(safe-area-inset-top));
  background: linear-gradient(to bottom, rgba(5, 8, 14, 0.85), rgba(5, 8, 14, 0));
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 16px; letter-spacing: 0.2px; margin-right: 6px; white-space: nowrap; }
.brand b { background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo { width: 28px; height: 28px; stroke: none; }
.logo.big { width: 56px; height: 56px; }
.spacer { flex: 1; }

.pill {
  display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 12px; border-radius: 999px;
  background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  font-size: 13px; color: var(--text); white-space: nowrap;
}
.pill svg { width: 16px; height: 16px; color: var(--muted); }
.pill.room span:first-child { color: var(--muted); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 0 currentColor; }
#app[data-state="connected"] .status .dot { background: var(--good); animation: pulse-dot 2s infinite; color: var(--good); }
#app[data-state="connecting"] .status .dot, #app[data-state="signaling"] .status .dot, #app[data-state="waiting"] .status .dot { background: var(--accent); animation: blink 1.2s infinite; }
#app[data-state="reconnecting"] .status .dot { background: var(--fair); animation: blink 0.6s infinite; }
#app[data-state="closed"] .status .dot { background: var(--poor); }
#app[data-state="connected"] .status { border-color: rgba(52, 211, 153, 0.35); }
.quality .bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 12px; }
.quality .bars i { width: 3px; border-radius: 1px; background: var(--line-strong); }
.quality .bars i:nth-child(1) { height: 5px; } .quality .bars i:nth-child(2) { height: 8px; } .quality .bars i:nth-child(3) { height: 12px; }
.quality[data-q="good"] .bars i { background: var(--good); }
.quality[data-q="fair"] .bars i:nth-child(-n+2) { background: var(--fair); }
.quality[data-q="poor"] .bars i:nth-child(1) { background: var(--poor); }

@keyframes pulse-dot { 0% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.6); } 70% { box-shadow: 0 0 0 8px rgba(52, 211, 153, 0); } 100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); } }
@keyframes blink { 50% { opacity: 0.35; } }

.icon-btn {
  position: relative; display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 12px; border: 1px solid transparent;
  background: transparent; color: var(--text); cursor: pointer; transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.icon-btn:hover { background: rgba(148, 163, 184, 0.12); border-color: var(--line); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn.active { background: rgba(77, 225, 255, 0.14); border-color: rgba(77, 225, 255, 0.4); color: var(--accent); }
.icon-btn.accent { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #061018; }
.badge { position: absolute; top: 2px; right: 2px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--live); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; }

/* ---------------------------------------------------------------- stage */
#stage { position: relative; grid-row: 1 / -1; overflow: hidden; background: radial-gradient(1200px 700px at 50% 45%, #141c2e 0%, var(--bg) 70%); }
.backdrop { position: absolute; inset: -20%; background:
  radial-gradient(40% 35% at 25% 30%, rgba(77, 225, 255, 0.10), transparent 70%),
  radial-gradient(35% 30% at 75% 70%, rgba(139, 92, 246, 0.12), transparent 70%);
  filter: blur(20px); animation: drift 18s ease-in-out infinite alternate; pointer-events: none; }
@keyframes drift { to { transform: translate3d(4%, -3%, 0) scale(1.05); } }
#video, #pano, #fx { position: absolute; inset: 0; width: 100%; height: 100%; }
#video { object-fit: contain; opacity: 0; transition: opacity 0.6s ease; background: transparent; }
#app.has-video #video { opacity: 1; }
#pano { cursor: grab; }
#pano:active { cursor: grabbing; }
#fx { pointer-events: none; }
#stage.controllable #video { cursor: grab; }
#stage.controllable.dragging #video { cursor: grabbing; }
#stage.annotating #video, #stage.annotating #pano { cursor: crosshair; }

#placeholder { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; text-align: center; gap: 6px; pointer-events: none; transition: opacity 0.5s; }
#app.has-video #placeholder { opacity: 0; }
#placeholder h2 { margin: 26px 0 0; font-weight: 600; font-size: 22px; }
#placeholder p { margin: 0; color: var(--muted); max-width: 420px; }
.rings { position: relative; width: 140px; height: 140px; display: grid; place-items: center; }
.rings span { position: absolute; inset: 0; border-radius: 50%; border: 1.5px solid rgba(77, 225, 255, 0.45); animation: ripple 3s cubic-bezier(0.2, 0.6, 0.3, 1) infinite; }
.rings span:nth-child(2) { animation-delay: 1s; border-color: rgba(139, 92, 246, 0.45); }
.rings span:nth-child(3) { animation-delay: 2s; }
@keyframes ripple { from { transform: scale(0.35); opacity: 1; } to { transform: scale(1.35); opacity: 0; } }

#banner {
  position: absolute; top: 74px; left: 50%; transform: translateX(-50%); z-index: 15; padding: 10px 16px; border-radius: 12px;
  background: rgba(251, 191, 36, 0.14); border: 1px solid rgba(251, 191, 36, 0.4); color: #fde68a; backdrop-filter: blur(10px); box-shadow: var(--shadow);
  animation: drop 0.35s ease;
}
#banner.error { background: rgba(248, 113, 113, 0.14); border-color: rgba(248, 113, 113, 0.45); color: #fecaca; }
@keyframes drop { from { transform: translate(-50%, -10px); opacity: 0; } }

#mode-chip, #speaker, #rec-chip {
  position: absolute; z-index: 12; display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px;
  background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(12px); font-size: 12.5px;
}
#mode-chip { left: 50%; bottom: 104px; transform: translateX(-50%); color: var(--muted); }
#speaker { left: 18px; bottom: 104px; }
#rec-chip { right: 18px; top: 70px; color: #fecdd3; border-color: rgba(255, 59, 92, 0.4); }
.rec-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--live); animation: blink 1s infinite; }
.eq { display: inline-flex; gap: 2px; align-items: flex-end; height: 12px; }
.eq i { width: 3px; background: var(--good); border-radius: 2px; animation: eq 0.8s ease-in-out infinite; }
.eq i:nth-child(2) { animation-delay: 0.15s; } .eq i:nth-child(3) { animation-delay: 0.3s; }
@keyframes eq { 0%, 100% { height: 3px; } 50% { height: 12px; } }

#filmstrip { position: absolute; right: 18px; bottom: 104px; display: flex; gap: 10px; z-index: 11; }
.thumb { width: 168px; aspect-ratio: 16/9; border-radius: 12px; overflow: hidden; border: 1px solid var(--line-strong); background: #000; cursor: pointer; position: relative; box-shadow: var(--shadow); transition: transform 0.15s, border-color 0.15s; }
.thumb:hover { transform: translateY(-2px); border-color: var(--accent); }
.thumb.on { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(77, 225, 255, 0.35), var(--shadow); }
.thumb video { width: 100%; height: 100%; object-fit: cover; }
.thumb span { position: absolute; left: 8px; bottom: 6px; font-size: 11.5px; text-shadow: 0 1px 3px #000; }

#toasts { position: absolute; left: 50%; top: 76px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 30; justify-items: center; pointer-events: none; }
.toast { padding: 9px 14px; border-radius: 12px; background: var(--glass-strong); border: 1px solid var(--line); box-shadow: var(--shadow); backdrop-filter: blur(12px); animation: toast-in 0.25s ease; max-width: 80vw; }
.toast.out { animation: toast-out 0.3s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px) scale(0.98); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-6px); } }

/* ---------------------------------------------------------------- dock */
#dock {
  position: absolute; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20;
  display: flex; align-items: center; gap: 6px; padding: 8px; border-radius: 22px;
  background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(18px) saturate(140%); -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow: var(--shadow); transition: opacity 0.35s ease, transform 0.35s ease; max-width: calc(100vw - 24px); overflow-x: auto; scrollbar-width: none;
}
#app.idle-ui .topbar { opacity: 0; transform: translateY(-8px); }
#app.idle-ui #dock { opacity: 0; transform: translate(-50%, 8px); }
#app.idle-ui #stage { cursor: none; }
.group { display: flex; align-items: center; gap: 4px; }
.sep { width: 1px; height: 28px; background: var(--line); margin: 0 4px; }
.dock-btn {
  position: relative; display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 14px; border: 1px solid transparent;
  background: rgba(148, 163, 184, 0.08); cursor: pointer; transition: background 0.15s, transform 0.1s, color 0.15s, border-color 0.15s;
}
.dock-btn:hover { background: rgba(148, 163, 184, 0.16); }
.dock-btn:active { transform: scale(0.94); }
.dock-btn.active { background: rgba(77, 225, 255, 0.16); border-color: rgba(77, 225, 255, 0.45); color: var(--accent); }
.dock-btn .ico.off, .dock-btn.off .ico.on { display: none; }
.dock-btn.off .ico.off { display: block; }
.dock-btn.off { background: rgba(248, 113, 113, 0.14); color: #fca5a5; }
.dock-btn.mic .ring { position: absolute; inset: 0; width: 44px; height: 44px; transform: rotate(-90deg); pointer-events: none; }
.dock-btn.mic .ring circle { fill: none; stroke: var(--good); stroke-width: 2.5; stroke-dasharray: 125.6; stroke-dashoffset: 125.6; transition: stroke-dashoffset 0.08s linear; opacity: 0.9; }
.dock-btn.ptt { width: auto; padding: 0 12px; font-size: 12px; font-weight: 700; letter-spacing: 0.6px; color: var(--muted); }
.dock-btn.ptt.active { color: #061018; background: linear-gradient(135deg, var(--good), #10b981); }
.dock-btn.recording { color: var(--live); background: rgba(255, 59, 92, 0.14); border-color: rgba(255, 59, 92, 0.45); }
.vol { display: flex; align-items: center; gap: 2px; }
.vol input { width: 84px; accent-color: var(--accent); }
.select { display: inline-flex; align-items: center; gap: 6px; height: 44px; padding: 0 10px; border-radius: 14px; background: rgba(148, 163, 184, 0.08); cursor: pointer; }
.select svg { color: var(--muted); width: 18px; height: 18px; }
.select select { background: transparent; border: 0; outline: 0; cursor: pointer; max-width: 160px; }
.select select option { background: var(--bg-2); }
.swatches { display: flex; gap: 4px; padding: 0 4px; }
.swatches button { width: 16px; height: 16px; border-radius: 50%; border: 2px solid transparent; background: var(--c); cursor: pointer; padding: 0; opacity: 0.55; transition: opacity 0.15s, transform 0.15s; }
.swatches button.on { opacity: 1; border-color: #fff; transform: scale(1.15); }

/* ---------------------------------------------------------------- panels */
.panel {
  position: absolute; top: 66px; right: 14px; bottom: 96px; width: min(360px, calc(100vw - 28px)); z-index: 25; display: flex; flex-direction: column;
  background: var(--glass-strong); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); transform: translateX(calc(100% + 30px)); transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.panel.open { transform: none; }
.panel header { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 8px 16px; border-bottom: 1px solid var(--line); }
.panel h3 { margin: 0; font-size: 15px; font-weight: 600; }
.panel-actions { padding: 12px 16px; margin-top: auto; display: flex; gap: 8px; }
.chat-log { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; }
.chat-log .empty { color: var(--muted); text-align: center; margin: auto; }
.msg { max-width: 85%; padding: 8px 12px; border-radius: 14px 14px 14px 4px; background: rgba(148, 163, 184, 0.12); animation: toast-in 0.2s ease; word-wrap: break-word; }
.msg.me { align-self: flex-end; border-radius: 14px 14px 4px 14px; background: linear-gradient(135deg, rgba(77, 225, 255, 0.22), rgba(139, 92, 246, 0.22)); }
.msg .from { display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.msg.system { align-self: center; background: none; color: var(--muted); font-size: 12px; padding: 2px; }
.chat-form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; height: 36px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.25); outline: none; }
.chat-form input:focus { border-color: rgba(77, 225, 255, 0.5); }
.spark { padding: 10px 16px 0; }
.spark-head { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.spark-head b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.spark canvas { width: 100%; height: 46px; display: block; margin-top: 4px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; padding: 14px 16px; margin: 0; font-size: 12.5px; overflow-y: auto; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 12px; }
.field { display: grid; gap: 6px; padding: 8px 16px; }
.field label { font-size: 12px; color: var(--muted); }
.field input, .field select { height: 38px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.25); outline: none; width: 100%; }
.field input:focus, .field select:focus { border-color: rgba(77, 225, 255, 0.55); box-shadow: 0 0 0 3px rgba(77, 225, 255, 0.12); }
.field label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 13px; cursor: pointer; }
.field label.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.mono { font-family: var(--mono); font-size: 12px; color: var(--muted); word-break: break-all; }
hr { border: 0; border-top: 1px solid var(--line); margin: 8px 16px; }
.btn { height: 40px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line); background: rgba(148, 163, 184, 0.1); cursor: pointer; font-weight: 600; transition: transform 0.1s, filter 0.15s; }
.btn:active { transform: scale(0.98); }
.btn.primary { border: 0; color: #061018; background: linear-gradient(135deg, var(--accent), var(--accent-2)); width: 100%; height: 44px; margin-top: 8px; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost:hover { background: rgba(148, 163, 184, 0.18); }

/* ---------------------------------------------------------------- modals */
.modal { position: absolute; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(3, 6, 12, 0.6); backdrop-filter: blur(6px); animation: fade 0.25s ease; padding: 16px; }
@keyframes fade { from { opacity: 0; } }
.card { width: min(460px, 100%); padding: 22px 8px 18px; border-radius: 22px; background: var(--glass-strong); border: 1px solid var(--line-strong); box-shadow: var(--shadow); animation: rise 0.35s cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes rise { from { transform: translateY(12px) scale(0.98); opacity: 0; } }
.card-head { display: flex; gap: 14px; align-items: center; padding: 0 16px 10px; }
.card-head .logo { width: 44px; height: 44px; }
.card h1 { margin: 0; font-size: 20px; }
.card-head p { margin: 2px 0 0; color: var(--muted); }
.card .row { display: grid; grid-template-columns: 1fr 1fr; }
.card .btn.primary { margin: 12px 16px 0; width: calc(100% - 32px); }
.muted { color: var(--muted); }
.warn { margin: 6px 16px; padding: 10px 12px; border-radius: 12px; background: rgba(251, 191, 36, 0.12); border: 1px solid rgba(251, 191, 36, 0.35); color: #fde68a; font-size: 12.5px; }
.help { width: min(520px, 100%); padding-bottom: 22px; }
.help .card-head { justify-content: space-between; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; padding: 4px 20px; align-items: center; }
kbd { justify-self: start; min-width: 28px; padding: 3px 8px; border-radius: 8px; border: 1px solid var(--line-strong); border-bottom-width: 2px; background: rgba(148, 163, 184, 0.1); font-family: var(--mono); font-size: 12px; text-align: center; }

#audio-unlock { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 35; display: inline-flex; align-items: center; gap: 10px; padding: 14px 22px; border-radius: 999px; border: 0; cursor: pointer; font-weight: 600; color: #061018; background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 0 0 0 rgba(77, 225, 255, 0.5), var(--shadow); animation: unlock 2s infinite; }
@keyframes unlock { 70% { box-shadow: 0 0 0 16px rgba(77, 225, 255, 0), var(--shadow); } }

@media (max-width: 760px) {
  .brand span, #peers-pill, #room-pill, #quality-text { display: none; }
  .brand { margin-right: 0; }
  .topbar { gap: 6px; padding: 10px; padding-top: max(10px, env(safe-area-inset-top)); }
  .pill { height: 28px; padding: 0 10px; }
  .icon-btn { width: 32px; height: 32px; border-radius: 10px; }
  #dock { flex-wrap: wrap; justify-content: center; width: calc(100vw - 20px); max-width: 420px; gap: 6px; padding: 8px; overflow: visible; border-radius: 20px; }
  #dock .sep { display: none; }
  #dock .group { flex-wrap: wrap; justify-content: center; }
  .dock-btn { width: 42px; height: 42px; }
  .dock-btn.mic .ring { width: 42px; height: 42px; }
  .vol input { width: 64px; }
  .select { height: 42px; padding: 0 8px; }
  .select select { max-width: 104px; }
  .swatches { display: none; }
  .card .row { grid-template-columns: 1fr; }
  #filmstrip { bottom: 170px; }
  #filmstrip .thumb { width: 110px; }
  #mode-chip, #speaker { bottom: 170px; }
  .panel { top: 56px; bottom: 170px; right: 10px; width: calc(100vw - 20px); }
}
@media (max-width: 760px) and (orientation: portrait) {
  /* Portrait phones: put the picture under the top bar instead of floating in the middle. */
  #video { object-position: 50% 22%; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

.msg.file a { color: var(--accent); text-decoration: none; font-weight: 600; word-break: break-all; }
.msg.file img { display: block; max-width: 100%; border-radius: 10px; margin-top: 6px; }
.msg .bar { height: 4px; border-radius: 2px; background: rgba(148,163,184,.2); margin-top: 6px; overflow: hidden; }
.msg .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
#panel-chat.drop { outline: 2px dashed var(--accent); outline-offset: -8px; }

#clock { position: absolute; left: 18px; top: 70px; z-index: 12; padding: 6px 12px; border-radius: 10px; background: rgba(0,0,0,.65); font: 600 28px/1.2 var(--mono); color: #d8f4ff; letter-spacing: .5px; font-variant-numeric: tabular-nums; }
