:root {
  --bg: #0e1116;
  --panel: #161b22;
  --line: #2a313c;
  --text: #e6e9ef;
  --dim: #8a93a3;
  --accent: #4f8cff;
  --danger: #e5484d;
}

* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
.hidden { display: none !important; }

/* ---- join ---- */
.join { height: 100%; display: grid; place-items: center; padding: 16px; }
.join-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px 24px;
  display: grid;
  gap: 18px;
}
.join-card h1 { font-size: 26px; letter-spacing: -0.5px; }
.tag { color: var(--dim); font-size: 13px; margin-bottom: 6px; }
.join-card input[type="text"], .join-card input:not([type]) {
  background: #0b0e13; color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 11px 12px; font-size: 15px;
}
.lowbw { color: var(--dim); font-size: 13px; display: flex; gap: 8px; align-items: center; }
.join-card button {
  background: var(--accent); color: #fff; border: 0;
  padding: 12px; border-radius: 8px; font-size: 15px; font-weight: 600;
  cursor: pointer;
}
.err { color: var(--danger); font-size: 13px; min-height: 1em; }

/* ---- meeting ---- */
/* Everything floats over the stage — the content gets the full viewport. */
.meet { height: 100%; display: flex; flex-direction: column; position: relative; }
.main { flex: 1 1 0; min-height: 0; display: flex; position: relative; }
.stage { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; }

/* connection status chip (top right) — visible only while it has text */
.net {
  position: absolute; top: 10px; right: 10px; z-index: 15;
  pointer-events: none;
  padding: 4px 10px; border-radius: 999px;
  background: rgba(0, 0, 0, .4);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums;
}
.net:empty { display: none; }

/* indicator bar: REC + duration + participant count + screens-only marker */
.hud {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  z-index: 15; pointer-events: none;
  display: flex; align-items: center; gap: 8px;
  padding: 4px 12px; border-radius: 999px;
  background: rgba(0, 0, 0, .4);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  font-size: 12.5px; font-variant-numeric: tabular-nums;
}
.hud-sep { color: var(--dim); }
.hud-peers { display: flex; align-items: center; gap: 5px; }
.hud-peers svg { width: 13px; height: 13px; color: var(--dim); }
.hud-rec {
  display: flex; align-items: center; gap: 5px;
  color: var(--danger); font-weight: 700; letter-spacing: .04em;
}
.hud-rec::after { content: '·'; color: var(--dim); font-weight: 400; margin-left: 3px; }
.rec-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger);
  animation: rec-pulse 1.4s ease-in-out infinite;
}
@keyframes rec-pulse { 50% { opacity: .25; } }
.hud-chip {
  background: rgba(79, 140, 255, .22); color: var(--accent);
  padding: 1px 8px; border-radius: 999px;
  font-size: 11px; white-space: nowrap;
}

/* ---- participants panel — overlays the stage (stage keeps full width) ---- */
.participants {
  display: none;
  position: absolute; top: 0; right: 0; bottom: 0; z-index: 20;
  width: min(80vw, 300px);
  flex-direction: column;
  background: var(--panel); border-left: 1px solid var(--line);
  box-shadow: -12px 0 32px rgba(0,0,0,.45);
}
.participants.open { display: flex; }
.participants header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.participants h2 { font-size: 14px; }
.p-count { color: var(--dim); font-weight: 400; }
.p-close {
  background: none; border: 0; color: var(--dim);
  font-size: 14px; cursor: pointer; padding: 4px;
}
.p-list {
  list-style: none; margin: 0; padding: 8px;
  overflow-y: auto; display: grid; gap: 2px; align-content: start;
}
.p-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 8px; font-size: 14px;
}
.p-list li:hover { background: rgba(255,255,255,.05); }
.p-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-badge {
  font-size: 11px; color: #ffd166;
  border: 1px solid rgba(255,209,102,.35); border-radius: 6px; padding: 1px 6px;
}
.p-actions { display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.p-list li:hover .p-actions { opacity: 1; }
.p-actions button {
  width: 28px; height: 28px; border-radius: 7px;
  border: 1px solid var(--line); background: rgba(0,0,0,.35); color: var(--text);
  font-size: 13px; cursor: pointer;
}
.p-actions button:hover { border-color: var(--accent); }


/* screen shares row */
.screens {
  display: flex; gap: 8px; padding: 8px;
  overflow-x: auto;
  flex: 2 1 0;
  min-height: 0;
}
.screen-tile {
  position: relative;
  flex: 1 0 min(70vw, 640px);
  background: #000; border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden;
  display: grid;
}
/* pan/zoom layer: video + annotation canvas transform together */
.view-layer {
  grid-area: 1/1; position: relative;
  transform-origin: 0 0; will-change: transform;
}
.view-layer video {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: contain;
}
.screen-tile.zoomed .view-layer { touch-action: none; cursor: grab; }
.screen-tile.zoomed .view-layer:active { cursor: grabbing; }

/* per-tile toolbar: draw / undo / clear / focus */
.tile-tools {
  position: absolute; top: 8px; right: 8px; z-index: 4;
  display: flex; gap: 6px;
  opacity: 0; transition: opacity .15s;
}
.screen-tile:hover .tile-tools,
.tile-tools:has(.active) { opacity: 1; }
.tile-tools button {
  width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.55); color: var(--text);
  font-size: 16px; cursor: pointer;
}
.tile-tools button.active { background: var(--accent); border-color: var(--accent); }

/* annotation overlay — sits exactly over the video box */
.ann-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  z-index: 3; pointer-events: none;
}
.ann-canvas.drawing { pointer-events: auto; cursor: crosshair; touch-action: none; }

/* zoom controls, bottom-right: − 100% ＋ (click the % to reset) */
.zoom-tools {
  position: absolute; bottom: 8px; right: 8px; z-index: 4;
  display: flex; border: 1px solid var(--line); border-radius: 8px;
  overflow: hidden;
  opacity: 0; transition: opacity .15s;
}
.screen-tile:hover .zoom-tools,
.screen-tile.zoomed .zoom-tools { opacity: 1; }
.zoom-tools button {
  width: 30px; height: 28px; border: 0;
  background: rgba(0,0,0,.55); color: var(--text);
  font-size: 14px; cursor: pointer;
}
.zoom-tools .zoom-label {
  width: auto; padding: 0 7px;
  font-size: 11px; font-variant-numeric: tabular-nums;
}
.screens.focus-mode { flex: 1 1 auto; }
.screen-tile.focused { flex: 1 1 100%; }

/* screens-only mode: all shared screens as a tile grid, cameras hidden */
.screens.screens-only {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
  grid-auto-rows: 1fr;
  overflow-y: auto; overflow-x: hidden;
}
.screens.screens-only .screen-tile { min-height: 200px; }

/* manage-tiles: fixed column count for shared screens (grid instead of the
   default side-by-side row). Focus mode wins — the focused share keeps the
   whole area regardless of the column setting. */
.screens.fixed-cols:not(.focus-mode) {
  display: grid;
  grid-auto-rows: 1fr;
  overflow-y: auto; overflow-x: hidden;
}
.screens.fixed-cols:not(.focus-mode) .screen-tile { min-height: 200px; }
@media (hover: none) {
  .tile-tools, .zoom-tools { opacity: 1; } /* no hover on touch — always visible */
}

/* camera grid */
.grid {
  flex: 1 1 0; min-height: 0;
  display: grid; gap: 8px; padding: 8px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  grid-auto-rows: 1fr;
}
.tile {
  position: relative; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  min-height: 110px;
}
.tile video { width: 100%; height: 100%; object-fit: cover; }
.tile .name {
  position: absolute; left: 8px; bottom: 8px;
  background: rgba(0,0,0,.55); padding: 2px 8px; border-radius: 6px;
  font-size: 12px;
}
.tile.muted::after {
  content: "🔇"; position: absolute; top: 8px; right: 8px; font-size: 14px;
}

/* last-N: peers without live video show as an avatar tile */
.tile.placeholder {
  display: flex; align-items: center; justify-content: center;
}
.tile.placeholder .avatar {
  width: 56px; height: 56px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 600; color: #0b0e13;
}

/* ---- settings popover: actions + view + grid options ---- */
.settings-menu {
  position: absolute; bottom: calc(96px + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  z-index: 30;
  min-width: 300px;
  display: flex; flex-direction: column; gap: 10px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 16px 18px;
  box-shadow: 0 12px 32px rgba(0,0,0,.45);
}
.sm-title { font-size: 16px; color: var(--dim); margin-bottom: 8px; }
.sm-title span { color: var(--text); font-weight: 600; }

/* one row of icon buttons: share / people / record / screens-only */
.sm-actions { display: flex; gap: 8px; }
.sm-action {
  position: relative;
  flex: 1 1 0;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px 4px 8px; border-radius: 10px;
  border: 1px solid var(--line); background: #0b0e13; color: var(--text);
  font-size: 11px; cursor: pointer;
}
.sm-action:hover { border-color: var(--dim); }
.sm-action svg { width: 18px; height: 18px; }
.sm-action.active { background: rgba(79,140,255,.18); border-color: var(--accent); color: var(--accent); }
.sm-action.rec-on { background: rgba(229,72,77,.15); border-color: var(--danger); color: var(--danger); }
.sm-action .count {
  position: absolute; top: -6px; right: -6px;
  min-width: 17px; padding: 0 5px; border-radius: 9px; text-align: center;
  background: var(--accent); color: #fff;
  font-size: 10px; line-height: 16px;
}
.sm-action .count:empty { display: none; }
.sm-sep { border: 0; border-top: 1px solid var(--line); margin: 0; }

/* screens-only toggle switch */
.sm-switch {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-size: 12px; color: var(--dim);
}
.switch {
  position: relative; flex: 0 0 auto;
  width: 36px; height: 20px; border-radius: 999px;
  border: 1px solid var(--line); background: #0b0e13;
  padding: 0; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.switch .knob {
  position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--dim);
  transition: transform .15s, background .15s;
}
.switch.active { background: var(--accent); border-color: var(--accent); }
.switch.active .knob { transform: translateX(16px); background: #fff; }
.tm-row { display: flex; align-items: center; gap: 10px; }
.tm-label { font-size: 12px; color: var(--dim); white-space: nowrap; width: 96px; }
.tm-opts { display: flex; gap: 4px; }
.tm-opts button {
  min-width: 30px; height: 30px; padding: 0 8px; border-radius: 7px;
  border: 1px solid var(--line); background: #0b0e13; color: var(--text);
  font-size: 12px; cursor: pointer;
}
.tm-opts button.active { background: var(--accent); border-color: var(--accent); }

/* ---- floating main toolbar (single-tone icons) ---- */
.toolbar {
  position: absolute; bottom: calc(12px + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  z-index: 30;
  display: flex; gap: 6px; align-items: center;
  padding: 8px 10px; border-radius: 999px;
  background: rgba(0, 0, 0, .4);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,.08);
}
.toolbar button {
  width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: transparent; color: var(--text);
  display: grid; place-items: center; cursor: pointer;
}
.toolbar button:hover { background: rgba(255,255,255,.12); }
.toolbar button svg { width: 20px; height: 20px; }
.toolbar button .ic-off { display: none; }
.toolbar button.off .ic-on { display: none; }
.toolbar button.off .ic-off { display: block; }
.toolbar button.off { color: var(--danger); background: rgba(229,72,77,.15); }
.toolbar button.active { color: var(--accent); background: rgba(79,140,255,.15); }
.toolbar .leave { color: #fff; background: var(--danger); }
.toolbar .leave:hover { background: #d63a3f; }

/* minimized toolbar: one small restore button */
.toolbar-mini {
  position: absolute; bottom: calc(12px + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  z-index: 30;
  width: 40px; height: 26px; border-radius: 999px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(0, 0, 0, .35); color: var(--dim);
  display: grid; place-items: center; cursor: pointer;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.toolbar-mini svg { width: 16px; height: 16px; }
.toolbar-mini:hover { color: var(--text); background: rgba(0,0,0,.55); }

@media (max-width: 640px) {
  .screens { flex-direction: column; overflow-x: hidden; overflow-y: auto; }
  .screen-tile { flex: 0 0 auto; aspect-ratio: 16/9; }
  .settings-menu { max-width: 92vw; }
  .p-actions { opacity: 1; } /* no hover on touch */
}
