:root {
  --bg: #f3f6ec;
  --bg-accent: #f7f2e8;
  --panel: rgba(253, 255, 250, 0.86);
  --panel-strong: #ffffff;
  --text: #1b2d27;
  --muted: #54635e;
  --accent: #0f766e;
  --accent-hover: #0b5e58;
  --danger: #b42318;
  --ring: rgba(27, 45, 39, 0.16);
  --shadow: rgba(15, 30, 24, 0.12);
  --shadow-lg: rgba(15, 30, 24, 0.22);
  --video-shell: rgba(255, 255, 255, 0.5);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
}

:root[data-theme="dark"] {
  --bg: #08151d;
  --bg-accent: #112326;
  --panel: rgba(11, 29, 37, 0.82);
  --panel-strong: #13313f;
  --text: #e6f2ef;
  --muted: #99b4ac;
  --accent: #2dd4bf;
  --accent-hover: #54e6d2;
  --danger: #ff6b5b;
  --ring: rgba(130, 181, 171, 0.26);
  --shadow: rgba(0, 0, 0, 0.32);
  --shadow-lg: rgba(0, 0, 0, 0.52);
  --video-shell: rgba(19, 49, 63, 0.55);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

body {
  background:
    radial-gradient(circle at 12% 8%, color-mix(in oklab, var(--accent) 20%, transparent) 0%, transparent 36%),
    radial-gradient(circle at 88% 12%, color-mix(in oklab, var(--bg-accent) 90%, white 10%) 0%, transparent 42%),
    linear-gradient(140deg, var(--bg) 0%, var(--bg-accent) 100%);
}

.container {
  position: relative;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0 24px 24px;
}

.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--ring);
  border-top: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  padding: 14px 18px;
  margin: 0 -24px 16px;
  box-shadow: 0 12px 28px var(--shadow);
  backdrop-filter: blur(14px);
  animation: topbar-enter 360ms ease-out;
}

.topbar h1 {
  font-size: 23px;
  font-weight: 700;
  letter-spacing: 0.01em;
  margin: 0;
  color: var(--text);
}

.room-info {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-self: start;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-self: end;
}

#roomLabel {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

#roomId {
  background: color-mix(in oklab, var(--panel-strong) 86%, var(--accent) 14%);
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  border: 1px solid var(--ring);
}

button {
  background: color-mix(in oklab, var(--panel-strong) 86%, var(--accent) 14%);
  color: var(--text);
  border: 1px solid var(--ring);
  padding: 10px 15px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease, color 0.16s ease;
  box-shadow: 0 3px 10px var(--shadow);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

button:hover {
  border-color: var(--accent);
  background: color-mix(in oklab, var(--panel-strong) 82%, var(--accent) 18%);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

#copyLinkBtn,
#themeToggle {
  background: var(--panel-strong);
}

button.danger {
  border-color: color-mix(in oklab, var(--danger) 66%, var(--ring) 34%);
  color: var(--danger);
  background: color-mix(in oklab, var(--panel-strong) 92%, var(--danger) 8%);
}

button.danger:hover {
  border-color: var(--danger);
  background: color-mix(in oklab, var(--panel-strong) 82%, var(--danger) 18%);
}

.controls {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 10px;
  margin: 0;
  justify-content: center;
  align-items: center;
  animation: controls-enter 320ms ease-out 90ms both;
}

.stage {
  position: relative;
  width: 100%;
  min-height: calc(100vh - 172px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  background: transparent;
  border: none;
  border-radius: 0;
  overflow: visible;
  box-shadow: none;
}

video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: linear-gradient(180deg, #152a35 0%, #081018 100%);
}

.remote {
  max-width: 100%;
  max-height: calc(100vh - 252px);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--radius-lg);
  margin-top: 14px;
  box-shadow: 0 8px 20px var(--shadow);
  opacity: 1;
  visibility: visible;
  transition: opacity 260ms ease, visibility 260ms ease;
}

.remote.remote-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.stage .controls {
  position: fixed;
  bottom: 24px;
  left: 50%;
  top: auto;
  transform: translateX(-50%);
  margin: 0;
  padding: 10px;
  border-radius: var(--radius-md);
  background: color-mix(in oklab, var(--panel) 92%, transparent);
  border: 1px solid var(--ring);
  backdrop-filter: blur(10px);
  z-index: 30;
}

.waiting-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 2;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 260ms ease, visibility 260ms ease;
}

.waiting-overlay.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.waiting-overlay-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-width: 360px;
  text-align: center;
  padding: 20px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--ring);
  background: color-mix(in oklab, var(--panel) 82%, transparent);
  box-shadow: 0 8px 24px var(--shadow);
  backdrop-filter: blur(10px);
}

.waiting-overlay-card .material-symbols-rounded {
  font-size: 28px;
  color: var(--accent);
}

.waiting-overlay-card h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.waiting-overlay-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

/* Reconnection overlay */
.reconnect-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 260ms ease, visibility 260ms ease;
  background: rgba(0, 0, 0, 0.35);
}

.reconnect-overlay.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.reconnect-overlay-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-width: 320px;
  text-align: center;
  padding: 24px 20px;
  border-radius: var(--radius-md);
  border: 1px solid var(--ring);
  background: var(--panel);
  box-shadow: 0 12px 32px var(--shadow-lg);
  backdrop-filter: blur(14px);
}

.reconnect-overlay-card .material-symbols-rounded {
  font-size: 32px;
  color: var(--accent);
  animation: reconnect-spin 1.2s linear infinite;
}

.reconnect-overlay-card h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.reconnect-overlay-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

@keyframes reconnect-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Device picker popover */
.device-picker {
  position: fixed;
  left: 50%;
  bottom: 90px;
  top: auto;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--ring);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  min-width: 240px;
  max-width: 320px;
  box-shadow: 0 12px 28px var(--shadow-lg);
  backdrop-filter: blur(14px);
  z-index: 31;
  display: none;
  flex-direction: column;
  gap: 12px;
  animation: device-picker-in 160ms ease-out;
}

.device-picker.active {
  display: flex;
}

.device-picker-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.device-picker-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.device-picker-label .material-symbols-rounded {
  font-size: 16px;
}

.device-picker-select {
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--ring);
  background: var(--panel-strong);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  appearance: auto;
}

.device-picker-select:focus {
  outline: none;
  border-color: var(--accent);
}


@keyframes device-picker-in {
  from { opacity: 0; transform: translateX(-50%) translateY(6px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

body.fullscreen-mode .device-picker {
  background: rgba(0, 0, 0, 0.75);
  border-color: rgba(255, 255, 255, 0.2);
}

body.fullscreen-mode .device-picker-select {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
  color: #fff;
}

body.fullscreen-mode .device-picker-label {
  color: rgba(255, 255, 255, 0.6);
}

.controls button.is-active {
  border-color: var(--accent);
  background: color-mix(in oklab, var(--panel-strong) 74%, var(--accent) 26%);
  color: var(--text);
}

.material-symbols-rounded {
  font-variation-settings: "FILL" 0, "wght" 500, "GRAD" 0, "opsz" 24;
  font-size: 20px;
  line-height: 1;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#muteBtn.is-active {
  border-color: color-mix(in oklab, var(--danger) 60%, var(--ring) 40%);
  background: color-mix(in oklab, var(--panel-strong) 86%, var(--danger) 14%);
  color: var(--danger);
}

.help {
  color: var(--muted);
  font-size: 14px;
}

/* Hide old grid if it still exists */
.videos, .videoWrap { display: none; }

.pip {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 280px;
  min-width: 120px;
  max-width: 50vw;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--ring);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: linear-gradient(180deg, #152a35 0%, #081018 100%);
  box-shadow: 0 18px 35px var(--shadow-lg);
  z-index: 999;
  transition: box-shadow 0.2s ease, transform 0.2s ease;
  animation: pip-enter 340ms ease-out 120ms both;
}

.local-video-off {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 12, 18, 0.68);
  color: rgba(233, 242, 249, 0.92);
  opacity: 0;
  visibility: hidden;
  transition: opacity 220ms ease, visibility 220ms ease;
  pointer-events: none;
}

.local-video-off .material-symbols-rounded {
  font-size: 42px;
}

.pip.local-video-off-active .local-video-off {
  opacity: 1;
  visibility: visible;
}

.pip:hover {
  box-shadow: 0 24px 44px var(--shadow-lg);
  transform: translateY(-1px);
}

.pip-resize-handle {
  position: absolute;
  top: 0;
  left: 0;
  width: 20px;
  height: 20px;
  cursor: nwse-resize;
  background: linear-gradient(135deg, rgba(255,255,255,0.35) 0%, transparent 55%);
  border-top-left-radius: 14px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.pip:hover .pip-resize-handle {
  opacity: 1;
}

.pip-resize-handle::before {
  content: '';
  position: absolute;
  top: 4px;
  left: 4px;
  width: 8px;
  height: 8px;
  border-top: 2px solid rgba(255,255,255,0.75);
  border-left: 2px solid rgba(255,255,255,0.75);
}

.pip.resizing {
  transition: none;
}

/* Fullscreen mode (document fullscreen) */
body.fullscreen-mode .container {
  max-width: none;
  padding: 0;
}

body.fullscreen-mode .topbar {
  display: none;
}

body.fullscreen-mode .stage {
  position: fixed;
  inset: 0;
  background: #000;
  justify-content: center;
  padding: 0;
  z-index: 1;
}

body.fullscreen-mode .remote {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  object-fit: cover;
  border-radius: 0;
  box-shadow: none;
}

.stage:fullscreen .remote,
.stage.is-fullscreen .remote {
  max-width: 100vw;
  max-height: calc(100vh - 80px);
  border-radius: 0;
  box-shadow: none;
}

body.fullscreen-mode .controls {
  position: fixed;
  bottom: 24px;
  left: 50%;
  top: auto;
  right: auto;
  margin: 0;
  padding: 10px;
  background: rgba(0, 0, 0, 0.6);
  opacity: 0;
  transform: translateX(-50%) translateY(16px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 30;
}

body.fullscreen-mode .controls.controls-visible,
body.fullscreen-mode .controls:focus-within,
.stage:fullscreen .controls.controls-visible,
.stage.is-fullscreen .controls.controls-visible,
.stage:fullscreen .controls:focus-within,
.stage.is-fullscreen .controls:focus-within {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

body.fullscreen-mode .controls button,
.stage:fullscreen .controls button,
.stage.is-fullscreen .controls button {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
  color: #fff;
  backdrop-filter: blur(8px);
}

body.fullscreen-mode .controls button:hover,
.stage:fullscreen .controls button:hover,
.stage.is-fullscreen .controls button:hover {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.5);
}

body.fullscreen-mode .controls button.danger,
.stage:fullscreen .controls button.danger,
.stage.is-fullscreen .controls button.danger {
  background: rgba(239, 68, 68, 0.3);
  border-color: rgba(239, 68, 68, 0.5);
  color: #fca5a5;
}

body.fullscreen-mode .controls button.danger:hover,
.stage:fullscreen .controls button.danger:hover,
.stage.is-fullscreen .controls button.danger:hover {
  background: rgba(239, 68, 68, 0.5);
}

body.fullscreen-mode .pip {
  position: fixed;
  right: 24px;
  bottom: 100px;
  left: auto;
  top: auto;
  z-index: 40;
  width: 240px;
  display: block;
}

body.fullscreen-mode .toy-panel {
  position: fixed;
  left: 24px;
  bottom: 100px;
  right: auto;
  top: auto;
  z-index: 50;
  max-height: calc(100vh - 180px);
}

body.fullscreen-mode .toy-panel.minimized {
  bottom: 24px;
}

.local {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.pipLabel {
  position: absolute;
  left: 10px;
  bottom: 8px;
  font-size: 12px;
  color: #fff;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(8px);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-weight: 500;
}

/* Hide old grid if it still exists */
.videos, .videoWrap { display: none; }

/* Responsive: shrink PiP a bit on small screens */
@media (max-width: 640px) {
  .container { padding: 0 24px 24px; }
  .stage {
    height: calc(100vh - 240px);
  }
  .pip {
    width: 160px;
    max-width: 40vw;
    right: 12px;
    bottom: 12px;
    border-radius: 12px;
  }
  .topbar {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px 14px;
  }
  .topbar h1 { justify-self: center; }
  .room-info { justify-self: center; }
  .topbar-actions { justify-self: center; }
  .controls {
    gap: 8px;
    max-height: calc(100vh - 140px);
    overflow-y: auto;
  }
  button {
    padding: 10px 14px;
    font-size: 13px;
  }
  .device-picker {
    left: 50%;
    top: auto;
    bottom: 80px;
    transform: translateX(-50%);
    min-width: 200px;
  }
}

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

@keyframes controls-enter {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes pip-enter {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .topbar,
  .controls,
  .pip {
    animation: none;
  }
}

/* Recording indicator */
.recording-indicator {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.95) 0%, rgba(220, 38, 38, 0.95) 100%);
  color: white;
  padding: 12px 24px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 600;
  z-index: 1000;
  display: none;
  align-items: center;
  gap: 12px;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.35), 0 8px 24px rgba(239, 68, 68, 0.2);
  backdrop-filter: blur(8px);
}

.recording-indicator.active {
  display: flex;
}

.recording-dot {
  width: 12px;
  height: 12px;
  background: white;
  border-radius: 50%;
  animation: pulse 1.5s ease-in-out infinite;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
}

.toast-container {
  position: fixed;
  top: 76px;
  right: 24px;
  z-index: 1200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  min-width: 220px;
  max-width: 320px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--ring);
  background: color-mix(in oklab, var(--panel) 92%, transparent);
  color: var(--text);
  box-shadow: 0 8px 18px var(--shadow);
  backdrop-filter: blur(10px);
  transform: translateY(-4px);
  opacity: 0;
  animation: toast-in 180ms ease-out forwards;
}

.toast.toast-join {
  border-color: color-mix(in oklab, var(--accent) 58%, var(--ring) 42%);
}

.toast.toast-leave {
  border-color: color-mix(in oklab, var(--danger) 45%, var(--ring) 55%);
}

.toast.toast-out {
  animation: toast-out 180ms ease-in forwards;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.9); }
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-4px); }
}

/* Stats detail panel */
.stats-panel {
  position: fixed;
  top: 116px;
  left: 24px;
  z-index: 24;
  display: none;
  flex-direction: column;
  gap: 6px;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--ring);
  border-radius: var(--radius-md);
  backdrop-filter: blur(14px);
  box-shadow: 0 8px 24px var(--shadow);
  font-size: 12px;
  min-width: 200px;
  animation: stats-in 150ms ease-out;
}

.stats-panel.active {
  display: flex;
}

.stats-row {
  display: grid;
  grid-template-columns: 52px 1fr 1fr;
  gap: 6px;
  align-items: center;
}

.stats-row.stats-row-full {
  grid-template-columns: 52px 1fr;
}

.stats-dir {
  font-weight: 700;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stats-row span:not(.stats-dir) {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

@keyframes stats-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

body.fullscreen-mode .stats-panel {
  top: 52px;
  left: auto;
  right: 16px;
  background: rgba(0,0,0,0.7);
  border-color: rgba(255,255,255,0.2);
}

@media (max-width: 640px) {
  .stats-panel {
    top: auto;
    bottom: 116px;
    left: 12px;
  }
}

/* Connection quality indicator */
.quality-indicator {
  position: fixed;
  top: 80px;
  left: 24px;
  display: none;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--ring);
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 12px var(--shadow);
  z-index: 25;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  transition: opacity 220ms ease;
}

.quality-indicator.active {
  display: inline-flex;
}

.quality-indicator .material-symbols-rounded {
  font-size: 18px;
}

.quality-divider,
.quality-codec,
.quality-divider-res,
.quality-res {
  display: none;
}

.quality-indicator.has-codec .quality-divider,
.quality-indicator.has-codec .quality-codec {
  display: inline;
}

.quality-indicator.has-res .quality-divider-res,
.quality-indicator.has-res .quality-res {
  display: inline;
}

.quality-codec {
  letter-spacing: 0.02em;
}

.quality-indicator.quality-good { color: #16a34a; }
.quality-indicator.quality-good .material-symbols-rounded { color: #16a34a; }

.quality-indicator.quality-fair { color: #ca8a04; }
.quality-indicator.quality-fair .material-symbols-rounded { color: #ca8a04; }

.quality-indicator.quality-poor { color: var(--danger); }
.quality-indicator.quality-poor .material-symbols-rounded { color: var(--danger); }

body.fullscreen-mode .quality-indicator {
  top: 16px;
  left: auto;
  right: 16px;
  background: rgba(0, 0, 0, 0.6);
  border-color: rgba(255, 255, 255, 0.2);
}

body.fullscreen-mode .quality-indicator.quality-good { color: #4ade80; }
body.fullscreen-mode .quality-indicator.quality-good .material-symbols-rounded { color: #4ade80; }
body.fullscreen-mode .quality-indicator.quality-fair { color: #facc15; }
body.fullscreen-mode .quality-indicator.quality-fair .material-symbols-rounded { color: #facc15; }
body.fullscreen-mode .quality-indicator.quality-poor { color: #fca5a5; }
body.fullscreen-mode .quality-indicator.quality-poor .material-symbols-rounded { color: #fca5a5; }

@media (max-width: 640px) {
  .quality-indicator {
    top: auto;
    bottom: 80px;
    left: 12px;
    font-size: 11px;
    padding: 4px 8px;
  }
}

/* Toy Panel (hidden by default) */
.toy-panel {
  display: none;
  position: fixed;
  left: 24px;
  bottom: 24px;
  width: 380px;
  max-width: calc(100vw - 48px);
  max-height: calc(100vh - 100px);
  background: linear-gradient(135deg, #fff0f7 0%, #ffe3f1 100%);
  border: 1px solid rgba(255, 64, 129, 0.25);
  border-radius: 18px;
  box-shadow: 0 18px 50px rgba(255, 47, 122, 0.25);
  z-index: 1000;
  overflow: hidden;
  font-family: "Space Grotesk", system-ui, sans-serif;
}

.toy-panel.active {
  display: block;
}

.toy-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.5);
  border-bottom: 1px solid rgba(255, 64, 129, 0.15);
  font-weight: 600;
  color: #2b1120;
}

.toy-header-buttons {
  display: flex;
  gap: 8px;
  align-items: center;
}

.toy-minimize,
.toy-close {
  background: transparent;
  border: none;
  font-size: 24px;
  color: #7d4f68;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  box-shadow: none;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}

.toy-minimize:hover,
.toy-close:hover {
  color: #ff2f7a;
  background: rgba(255, 47, 122, 0.1);
}

/* Minimized state */
.toy-panel.minimized {
  width: auto;
  min-width: 160px;
}

.toy-panel.minimized .toy-panel-content {
  display: none;
}

.toy-panel.minimized .toy-minimize {
  transform: rotate(180deg);
}

.toy-panel-content {
  padding: 16px;
  overflow-y: auto;
  max-height: calc(100vh - 200px);
}

.toy-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 10px 0;
  flex-wrap: wrap;
}

.toy-label {
  display: flex;
  gap: 6px;
  align-items: center;
  color: #7d4f68;
  font-size: 13px;
}

.toy-panel .toy-easing {
  display: none;
}

.toy-panel .toy-room-name {
  display: none;
}

.toy-label input,
.toy-label select {
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(255, 64, 129, 0.25);
  color: #2b1120;
  padding: 6px 8px;
  border-radius: 8px;
  outline: none;
  width: 70px;
  font-size: 13px;
}

.toy-label input:focus,
.toy-label select:focus {
  border-color: #ff2f7a;
}

.toy-label input[type="text"] {
  width: auto;
  min-width: 80px;
}

.toy-panel input[type="range"] {
  flex: 1;
  min-width: 120px;
  accent-color: #ff2f7a;
}

.toy-pill {
  background: rgba(255, 255, 255, 0.65);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 64, 129, 0.25);
  color: #2b1120;
  font-size: 12px;
}

.toy-pill code {
  background: transparent;
  padding: 0;
  border: none;
}

.toy-panel code {
  background: rgba(255, 255, 255, 0.6);
  padding: 3px 6px;
  border-radius: 6px;
  border: 1px solid rgba(255, 64, 129, 0.25);
  font-size: 12px;
}

.toy-btn-ghost {
  padding: 6px 12px;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid rgba(255, 64, 129, 0.25);
  background: transparent;
  color: #2b1120;
  font-weight: 500;
  font-size: 13px;
  box-shadow: none;
}

.toy-btn-ghost:hover {
  border-color: #ff2f7a;
  background: rgba(255, 47, 122, 0.1);
}

.toy-section {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 64, 129, 0.15);
}

.toy-status-ok {
  color: #18c29c;
}

/* Make title clickable for secret */
.topbar h1 {
  cursor: default;
  user-select: none;
}

@media (max-width: 640px) {
  .toy-panel {
    left: 12px;
    bottom: 12px;
    width: calc(100vw - 24px);
  }
}


/* Screen share PiP — shown at bottom-left for the person receiving the screen share */
.pip-screen {
  left: 24px;
  right: auto;
  bottom: 24px;
  width: 380px;
  max-width: 90vw;
}

/* Screen share receiver overlay — shown at bottom-left for the person receiving the screen share */
.screen-share-recv-overlay {
  position: fixed;
  left: 24px;
  bottom: 260px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--ring);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  box-shadow: 0 8px 24px var(--shadow-lg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 998;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  animation: pip-enter 300ms ease-out both;
}

.screen-share-recv-overlay .material-symbols-rounded {
  font-size: 18px;
  color: var(--accent);
  flex-shrink: 0;
}

.screen-share-recv-overlay .screen-share-recv-vol-icon {
  color: var(--muted);
  margin-left: 6px;
}

.screen-share-recv-label {
  color: var(--muted);
  white-space: nowrap;
}

.screen-share-recv-overlay input[type="range"] {
  width: 80px;
  accent-color: var(--accent);
  cursor: pointer;
}

.screen-share-recv-overlay #screenShareRecvLabel {
  min-width: 36px;
  text-align: right;
  color: var(--muted);
}

/* Screen audio volume control — shown inside controls bar while screen sharing */
.screen-audio-ctrl {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--ring);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  height: 44px;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  white-space: nowrap;
}

.screen-audio-ctrl .material-symbols-rounded {
  font-size: 18px;
  color: var(--muted);
  flex-shrink: 0;
}

.screen-audio-ctrl input[type="range"] {
  width: 72px;
  accent-color: var(--accent);
  cursor: pointer;
}

.screen-audio-ctrl span:last-child {
  min-width: 34px;
  text-align: right;
  color: var(--muted);
}


/* ---- Doomscroll together (phone feed as a "doom" peer) ---- */
.doom-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 14px;
  position: relative;
}

.doom-stage video {
  width: auto;
  height: calc(100vh - 252px);
  max-height: calc(100vh - 252px);
  max-width: 100%;
  aspect-ratio: 9 / 16;
  object-fit: contain;
  background: #000;
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 20px var(--shadow);
}

.doom-badge {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: color-mix(in oklab, var(--panel) 85%, transparent);
  border: 1px solid var(--ring);
  backdrop-filter: blur(10px);
  font-size: 12px;
  pointer-events: none;
  opacity: 0.9;
}

.doom-badge .material-symbols-rounded { font-size: 16px; }

/* While a phone feed is on stage, the remote camera becomes a floating PiP (top-right) */
body.doom-active .remote {
  position: fixed;
  top: 84px;
  right: 24px;
  width: 280px;
  min-width: 120px;
  max-width: 50vw;
  height: auto;
  max-height: none;
  aspect-ratio: 16 / 9;
  margin: 0;
  object-fit: cover;
  border: 1px solid var(--ring);
  border-radius: var(--radius-md);
  box-shadow: 0 18px 35px var(--shadow-lg);
  z-index: 998;
  cursor: move;
}

body.doom-active .waiting-overlay { display: none; }

body.fullscreen-mode .doom-stage,
.stage:fullscreen .doom-stage,
.stage.is-fullscreen .doom-stage {
  margin-top: 0;
}

body.fullscreen-mode .doom-stage video,
.stage:fullscreen .doom-stage video,
.stage.is-fullscreen .doom-stage video {
  height: 100vh;
  max-height: 100vh;
  border-radius: 0;
  box-shadow: none;
}

body.fullscreen-mode.doom-active .remote {
  top: 24px;
  right: 24px;
  width: 240px;
  height: auto;
  z-index: 40;
}

/* "Add my phone" dialog */
.doom-phone-dialog {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(360px, 92vw);
  padding: 22px 22px 18px;
  background: var(--panel);
  border: 1px solid var(--ring);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 60px var(--shadow-lg);
  backdrop-filter: blur(14px);
  z-index: 1200;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.doom-phone-dialog h2 {
  margin: 0;
  font-size: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.doom-phone-dialog p { margin: 0; font-size: 14px; opacity: 0.85; }
.doom-phone-dialog .doom-phone-hint { font-size: 12px; opacity: 0.6; }

.doom-phone-dialog img {
  width: 220px;
  height: 220px;
  border-radius: var(--radius-md);
  background: #fff;
  padding: 8px;
}

.doom-phone-link {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--accent, #4aa3ff);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
}

.doom-phone-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 4px;
  border-radius: 999px;
}

.doom-phone-close:hover { background: color-mix(in oklab, var(--ring) 40%, transparent); }
