* {
  box-sizing: border-box;
  margin: 0px;
  padding: 0px;
}

:root {
  --background-color: #000;
  --custom-red-color: #ff453a;
  --cyan-color: rgba(0, 255, 255, 0.36);
  --transparent-bg: rgba(0, 0, 0, 0);

  --font-color: white;
  --message-font-size: 15px;
  
  --cyan-caret-color: cyan;

  --corner-radius: 8px;
  --cyan-border:2px solid cyan;

  --layout-margin: 12px;

  --chat-width-desktop: 30%;
  --log-width-desktop: 30%;

  --corner-button-inflate:110%;
  --corner-button-size:30px;
}

/* THE WHITE-BAND BACKSTOP. html had NO background and body sets `background: transparent`,
   so the page canvas was UA-default WHITE — and any mismatch between the laid-out height and
   the real visible viewport (iOS toolbar settle, overscroll, first frames before the aurora
   paints, in-call views) showed as a white bar at the top or bottom. Painting html with the
   theme colour makes any such band invisible: it can only ever be app-coloured. Keep in sync
   with the theme-color meta (#000 dark / #dff0f7 light, see theme_strip.js). */
html { background-color: #000; }
html[data-theme="light"] { background-color: #dff0f7; }

body {
  /* #6 dead-space fix: use the DYNAMIC viewport so the app fills the screen as the browser
     toolbar collapses/expands, instead of leaving a dead band below the content (which happens
     with svh once the toolbar retracts). svh stays as the fallback for browsers without dvh.
     Safe here because the body is overflow:hidden — there is no scroll to animate the toolbar,
     so dvh does not jitter during use. LAW 1: never 100vh. */
  height: 100svh;                /* fallback for browsers without dvh */
  height: 100dvh;                /* better fallback where supported */
  height: var(--app-h, 100dvh);  /* JS-measured real viewport (visualViewport) — wins, no dead band */
  width: 100%;      /* 100vw includes the scrollbar and causes horizontal overflow (LAW 3). */
  overflow: hidden;

  background: transparent;
  padding: 0;
  position: relative;
}

/* Dashboard stage — CSS grid: fluid main area + content-sized strip. */
.main-container {
  height: 100%;
  width: 100%;
  position: relative;

  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: clamp(4px, 0.6dvh, 8px);
  padding: clamp(4px, 0.6dvh, 8px);
  padding-top:    max(clamp(4px, 0.6dvh, 8px), env(safe-area-inset-top,    0px));
  /* Maximum-low strip: NO decorative floor at the bottom — only the hardware safe-area inset
     (home indicator). In a browser tab (inset 0) the strip sits flush against the bottom edge. */
  padding-bottom: env(safe-area-inset-bottom, 0px);

  overflow: hidden;
}

/* ── Corner buttons — small liquid-glass adaptive chips ────────────
   Stacked top-right, vertically flowing via flexbox so inserting or
   hiding one (e.g. screen-view-toggle) doesn't require position math.
   --cb-size scales per breakpoint below. */
:root {
  --cb-size: 34px;
  --cb-gap: 6px;
}

.corner-button {
  position: fixed;
  top: calc(var(--layout-margin) + env(safe-area-inset-top, 0px));
  right: calc(var(--layout-margin) + env(safe-area-inset-right, 0px));
  /* Stacking via translate keeps the fixed right-edge anchor while flowing
     each button down by the sum of (size + gap) per sibling above it. */
  width:  var(--cb-size);
  height: var(--cb-size);
  padding: 0;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 999px;
  background: rgba(255,255,255,0.10);
  backdrop-filter: blur(12px) saturate(160%);
  -webkit-backdrop-filter: blur(12px) saturate(160%);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.06),
    0 4px 14px rgba(0,0,0,0.28);
  color: rgba(255,255,255,0.92);
  cursor: pointer;
  z-index: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, transform 0.18s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.corner-button .cb-svg {
  width: calc(var(--cb-size) * 0.55);
  height: calc(var(--cb-size) * 0.55);
  pointer-events: none;
  /* Subtle glyph shadow boosts contrast against any video color behind. */
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
}

.corner-button:hover {
  background: rgba(255,255,255,0.18);
  color: #ffffff;
  transform: scale(1.06);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.10),
    0 6px 20px rgba(0,0,0,0.34);
}

.corner-button:active {
  transform: scale(0.94);
}

/* Vertical stack via top offsets — button 2 offset by 1×(size+gap), etc.
   Using top offsets instead of flex lets each button stay position:fixed. */
.corner-button.toggle-fit        { top: calc(var(--layout-margin) + env(safe-area-inset-top, 0px)); }
.corner-button.bg-button         { top: calc(var(--layout-margin) + env(safe-area-inset-top, 0px) + 1 * (var(--cb-size) + var(--cb-gap))); }
.corner-button.hide-button       { top: calc(var(--layout-margin) + env(safe-area-inset-top, 0px) + 2 * (var(--cb-size) + var(--cb-gap))); }
.corner-button.screen-view-toggle{ top: calc(var(--layout-margin) + env(safe-area-inset-top, 0px) + 3 * (var(--cb-size) + var(--cb-gap))); }

/* ── Background Editor Styles ────────────────────────────────── */
.bg-editor-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.bg-editor-modal {
  background: rgba(14,16,22,0.98);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 16px;
  padding: 24px;
  width: 90vw;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.6);
}

.bg-editor-header h3 { color: #fff; font-size: 18px; margin-bottom: 4px; }
.bg-editor-header p { color: rgba(255,255,255,0.5); font-size: 12px; }

.bg-editor-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  cursor: grab;
  border: 1px solid rgba(255,255,255,0.2);
  /* Suppress native touch gestures (scroll, pinch-zoom) so our pan+pinch
     handlers own the interaction. */
  touch-action: none;
  user-select: none;
}
.bg-editor-viewport:active { cursor: grabbing; }

#bg-editor-img {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  user-select: none;
  /* The inner <img> must not receive pointer events: otherwise the browser's
     native image-drag consumes mouseup and the drag state stays stuck,
     which is exactly what froze the editor on desktop. */
  pointer-events: none;
  -webkit-user-drag: none;
}

.bg-viewport-guide {
  position: absolute;
  inset: 0;
  border: 1px dashed rgba(255,255,255,0.3);
  pointer-events: none;
}

.bg-editor-controls { display: flex; flex-direction: column; gap: 16px; }

.bg-control-row { display: flex; align-items: center; gap: 12px; }
.bg-zoom-label { color: #fff; font-size: 12px; min-width: 40px; }
#bg-zoom-slider { flex: 1; accent-color: cyan; }

.bg-target-row { display: flex; gap: 16px; justify-content: center; }
.bg-checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}

.bg-action-row { display: flex; gap: 12px; margin-top: 8px; }
.bg-btn-primary, .bg-btn-secondary {
  flex: 1;
  padding: 12px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.bg-btn-primary { background: cyan; border: none; color: #000; }
.bg-btn-primary:hover { background: #00cccc; transform: translateY(-1px); }
.bg-btn-secondary { background: transparent; border: 1px solid rgba(255,255,255,0.2); color: #fff; }
.bg-btn-secondary:hover { background: rgba(255,255,255,0.05); }

/* Apply backgrounds via CSS variables */
body {
  background-image: var(--bg-img, none);
  background-position: var(--bg-pos, center);
  background-size: var(--bg-size, cover);
}

@media (orientation: portrait) {
  body {
    background-image: var(--bg-img-portrait, var(--bg-img, none));
  }
}
@media (orientation: landscape) {
  body {
    background-image: var(--bg-img-landscape, var(--bg-img, none));
  }
}

/* Responsive sizing — smaller on mobile than the old 44px enlargement.
   Research and touch-target guidance met via 8px outside padding hit-area. */
@media (max-width: 599px) {
  :root { --cb-size: 30px; --cb-gap: 5px; }
  .corner-button::before {
    /* Invisible 44×44 hit area so the 30px visual still meets WCAG 2.5.5 */
    content: '';
    position: absolute;
    inset: -7px;
  }
}
@media (min-width: 600px) and (max-width: 1199px) {
  :root { --cb-size: 34px; --cb-gap: 6px; }
}
@media (min-width: 1200px) {
  :root { --cb-size: 38px; --cb-gap: 8px; }
}

/* Accessibility / perf fallback — solid chip on reduced-transparency and
   when backdrop-filter is unsupported. */
@media (prefers-reduced-transparency: reduce) {
  .corner-button {
    background: rgba(20,20,22,0.72);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}
@supports not (backdrop-filter: blur(1px)) {
  .corner-button { background: rgba(20,20,22,0.72); }
}

/* ── Screen Share Three-State Display ───────────────────────────── */

/* State 2: Background — behind everything, fills viewport */
#screen-share-video.ss-background {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: -1 !important;
  object-fit: cover;
  border-radius: 0 !important;
  margin: 0 !important;
}

/* State 3: Full screen — above everything */
#screen-share-video.ss-fullscreen {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: 9000 !important;
  object-fit: contain;
  background: black;
  border-radius: 0 !important;
  margin: 0 !important;
}

/* In full screen state, keep the toggle button above the video */
.screen-view-toggle.ss-fullscreen-active {
  z-index: 9001 !important;
}

/* Mobile: larger touch target for the screen view toggle */
@media (max-width: 600px) {
  .corner-button.screen-view-toggle {
    width: 40px;
    height: 40px;
  }
}

/* Ensure screen share states fill viewport on all orientations + safe areas */
#screen-share-video.ss-background,
#screen-share-video.ss-fullscreen {
  width: 100vw !important;
  height: 100vh !important;
  /* dvh for mobile browsers that hide URL bar */
  height: 100dvh !important;
}

/* Main video stage — fills grid row 1 completely. No % height calc,
   no manual margins. object-fit: cover preserves aspect across any ratio. */
.main-video {
  grid-row: 1;
  inline-size: 100%;
  block-size: 100%;
  min-block-size: 0;
  object-fit: cover;
  object-position: 50% 50%;
  border-radius: var(--corner-radius);
  position: relative;
  z-index: 1;
  background-color: #000;
}

.main-video-fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;      /* 100vw includes the scrollbar and causes horizontal overflow (LAW 3). */
  height: 100dvh;  /* LAW 1: 100vh is wrong on every mobile browser — it ignores collapsing toolbars, so content gets cut off. */
  height: 100dvh;
  background-color: var(--transparent-bg);
  object-fit: cover;
  z-index: 50;
}

/* Thumbnail strip — grid row 2, height clamped to a responsive band.
   container-type enables inline-size queries in style_participants.css. */
.video-list {
  grid-row: 2;
  inline-size: 100%;
  block-size: clamp(84px, 16svh, 150px);
  background-color: var(--transparent-bg);
  border-radius: var(--corner-radius);
  display: flex;
  flex-direction: row;
  align-items: stretch;
  /* Fixed gap (no cqi unit) — adding/removing tiles must not recompute the
     spacing of the rest of the strip. */
  gap: 8px;
  padding: 0;

  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
}

@media (orientation: landscape) and (max-height: 480px) {
  /* Landscape phones: strip shrinks further so the stage keeps useful area. */
  .video-list { block-size: clamp(64px, 22svh, 110px); }
}

.video-stream {
  object-fit: cover;
  flex-shrink: 0;
  position: relative;
  border-radius: var(--corner-radius);
  background-color: black;
}

/* Hide scrollbar*/
.video-list {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.video-list::-webkit-scrollbar {
  display: none;
}

.video-stream:hover{
  border:var(--cyan-border);
}

.log-container {
  position: absolute;
  display: none;
  background-color: rgb(0, 107, 107);
}
/* ── High-Res Background Layer Logic ───────────────────────── */
.app-background-layer {
  position: fixed;
  inset: 0;
  z-index: -2;
  background-color: #000;
  background-image: var(--bg-img, none);
  background-position: var(--bg-pos, center);
  background-size: var(--bg-size, cover);
  background-repeat: no-repeat;
  transition: opacity 0.5s ease;
}

@media (orientation: portrait) {
  .app-background-layer {
    background-image: var(--bg-img-portrait, var(--bg-img, none));
    background-size: var(--bg-size-portrait, var(--bg-size, cover));
    background-position: var(--bg-pos-portrait, var(--bg-pos, center));
  }
}

@media (orientation: landscape) {
  .app-background-layer {
    background-image: var(--bg-img-landscape, var(--bg-img, none));
    background-size: var(--bg-size-landscape, var(--bg-size, cover));
    background-position: var(--bg-pos-landscape, var(--bg-pos, center));
  }
}
