/* Glue between the design's CSS and our Django integration.
   Kept separate from the vendored design CSS so the design files
   stay byte-identical to what the designer shipped. */

/* Page color lives on <html> so we can keep body and .ss-app transparent,
   which lets the fixed-position legacy <video> at z-index: -1 actually
   show through. If body/ss-app set their own opaque background, they
   stack above the negative-z-index video and we just see the page color. */
html { background: var(--bg); color: var(--fg); }
.ss-body { margin: 0; background: transparent; color: var(--fg); font-family: var(--font); overflow: hidden; }

#legacy-video-mount {
  z-index: -1;
  pointer-events: none;
}
#legacy-video-mount #video-stream-overlay {
  pointer-events: auto;
}

/* Override the design's .ss-app + .ss-stage opaque backgrounds so the
   video underneath shows through. */
.ss-app { background: transparent !important; }
.ss-stage { background: transparent !important; }
.ss-stage .rt-frame { background: transparent; }

/* Placeholder shown in the spectator layer when no live broadcast
   is active. */
.yt-frame .yt-fallback-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--fg-2);
  text-align: center;
  padding: 24px;
}
.yt-frame .yt-fallback-placeholder h2 { font-size: 18px; font-weight: 600; margin: 0 0 8px; }
.yt-frame .yt-fallback-placeholder p { font-size: 13px; color: var(--dim); margin: 0; }

/* Placeholder for the chat panel when no broadcast is active. */
.ss-chat-empty {
  padding: 24px;
  color: var(--dim);
  font-size: 12px;
  text-align: center;
}

/* Toast notifications stack. Positioned below the design's topbar
   (the topbar itself + its inset run to roughly 80px from the page top,
   plus a 16px breathing gap). */
.ss-toaster {
  position: fixed;
  top: 96px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  /* align-items:center lets each toast shrink to its message width
     instead of stretching to the column. Pair with width:auto on the
     toast itself (below) so short messages render as snug pills and
     longer ones grow up to the column max-width before wrapping. */
  align-items: center;
  gap: 8px;
  pointer-events: none;
  /* No min-width: the toast sizes to its content. Cap at 90vw so a
     comically long notification can't span the full viewport on a
     narrow window. */
  max-width: min(560px, 90vw);
}
.ss-toaster .skipped-toast {
  pointer-events: auto;
  white-space: normal;
  word-break: normal;
  /* The design's .skipped-toast was a single modal-style centered
     popup (position:absolute, top:50%, translate(-50%,-50%)). Inside
     our flex-column stack that centering escapes flow and pins the
     toast to the stack's collapsed 0-height anchor, which renders
     it half-above the .ss-toaster's top:96px line - so the visible
     pill ends up overlapping the topbar. Override back to normal
     flow so each toast sits inside the flex stack the way a stack
     of notifications should. */
  position: relative;
  left: auto;
  top: auto;
  transform: none;
  /* Variable width: shrink to the message so short copy reads as a
     pill instead of a half-empty banner. The column's max-width caps
     the upper bound; long copy wraps cleanly inside that limit. */
  width: auto;
  max-width: 100%;
}
.ss-toaster .skipped-toast .st-title { white-space: normal; overflow: visible; text-overflow: clip; }

/* YouTube embeds maintain 16:9 internally - when the iframe isn't
   that aspect, YouTube's player adds its own letterbox/pillarbox.
   Fix is to size the iframe to "cover" the viewport (one dimension
   fills, the other overflows and gets clipped by the .yt-frame
   wrapper) so the 16:9 video crops to fill instead.
   Math: 177.78vh = 16/9 * vh; 56.25vw = 9/16 * vw. The max() pair
   guarantees both viewport dimensions are at least covered. */
.ss-stage .yt-frame {
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.ss-stage .yt-iframe {
  position: absolute;
  top: 50%;
  left: 50%;
  width: max(100%, 177.78vh);
  height: max(100%, 56.25vw);
  transform: translate(-50%, -50%);
  border: 0;
  /* No mouse interaction with the iframe: the spectator has the
     topbar unmute control + the queue panel actions, they don't
     need YouTube's player chrome. Suppressing pointer events also
     prevents accidental clicks from popping the YouTube controls
     overlay back into view. */
  pointer-events: none;
}

/* Global E-STOP banner. Driver commands are gated server-side
   when robot_status is "Stopped"; this banner is the user-facing
   signal. Mods get an inline Resume button. */
.ss-estop-banner {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 120;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: linear-gradient(180deg, rgba(229, 74, 74, 0.95), rgba(180, 50, 50, 0.95));
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 16px 40px -10px rgba(0, 0, 0, 0.6), 0 0 0 4px rgba(229, 74, 74, 0.15);
}
.ss-estop-banner .ss-estop-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #fff;
  animation: apPulse 1.4s ease-in-out infinite;
}
/* Mod HUD foot button flips from red E-STOP to green Resume while
   the robot is in the Stopped state. Same control, opposite action.
   Mirrors the .mh-foot .go palette from mod-hud.css. */
.mh-foot .stop.is-resume {
  background: linear-gradient(180deg, rgba(126, 210, 122, 0.28), rgba(126, 210, 122, 0.18));
  color: #9be19a;
  border-color: rgba(126, 210, 122, 0.5);
}
.mh-foot .stop.is-resume:hover {
  background: rgba(126, 210, 122, 0.36);
  color: #fff;
}

/* Tighter button styling for the geofence toolbar so four
   full-label buttons ("Draw allow" / "Draw exclude" / "Clear all" /
   "Save") fit on one row within the 360px Mod HUD width. */
.mh-geo-toolbar .mh-quickbtn {
  height: 32px;
  padding: 0 8px;
  font-size: 12px;
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
}

/* Expanded Mod HUD: fills the whole viewport area below the
   topbar (~80px) so map-heavy panes can use the full screen
   while keeping the draw toolbar visible. Replaces Google Maps'
   fullscreen control (which escape-hatched the map out of the
   panel and stranded the toolbar). */
.mh-hud.is-expanded {
  /* These !importants override the inline style React writes for
     pos.x / pos.y during drag mode. Position is set explicitly via
     CSS in expanded mode. */
  left: 16px !important;
  right: 16px !important;
  top: 96px !important;
  bottom: 16px !important;
  width: auto !important;
  max-height: none !important;
}
/* Expanded body: stop being a scroll container so the geo section
   can flex to fill the height. Other panes scroll within the
   section as needed. */
.mh-hud.is-expanded .mh-body {
  max-height: none;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.mh-hud.is-expanded .mh-body > .mh-section { flex: 1; min-height: 0; }
.mh-hud.is-expanded .mh-geo-toolbar { flex: none; }
.mh-hud.is-expanded .mh-geo-mapwrap { flex: 1; min-height: 0; }
.mh-hud.is-expanded #geofence-map { min-height: 0; }

/* Map-corner expand toggle: lives at the upper-right of the
   geofence map, where Google's native fullscreen button used to
   sit. Replaces it 1:1 (same affordance, different behavior:
   widens the HUD instead of escape-hatching to viewport). */
.mh-geo-expand {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.95);
  color: rgba(0, 0, 0, 0.75);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 2px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  transition: background 120ms ease;
}
.mh-geo-expand:hover { background: #fff; color: #000; }

/* Click-to-peek queue popover that drops below the topbar's
   "N in queue" pill. Anchored to .watchers-wrap (which is set
   to position: relative inline). Glassy dark panel matching the
   queue-panel / mod-hud chrome. */
.watchers-wrap .pill-btn { cursor: pointer; }
.watchers-wrap .pill-btn.is-open { background: rgba(255,255,255,0.06); }
.queue-popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  min-width: 260px;
  max-width: 340px;
  padding: 12px 14px;
  background: rgba(15, 13, 12, 0.94);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid var(--border-2, rgba(255,255,255,0.12));
  border-radius: 12px;
  box-shadow: 0 16px 40px -12px rgba(0,0,0,0.6);
  color: var(--fg);
  font-size: 13px;
  /* Slot anchor: small triangle pointing back at the pill. */
}
.queue-popover::before {
  content: "";
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 10px; height: 10px;
  background: rgba(15, 13, 12, 0.94);
  border-left: 1px solid var(--border-2, rgba(255,255,255,0.12));
  border-top: 1px solid var(--border-2, rgba(255,255,255,0.12));
}
.queue-popover .qpop-head { font-size: 12px; color: var(--dim); margin-bottom: 8px; }
.queue-popover .qpop-empty { color: var(--dim); padding: 4px 0; }
.queue-popover .qpop-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 320px; overflow-y: auto; }
.queue-popover .qpop-row { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 6px; }
.queue-popover .qpop-row.is-me { background: rgba(117, 88, 255, 0.16); }
.queue-popover .qpop-pos { font-family: var(--mono); font-size: 11px; color: var(--dim); width: 22px; text-align: right; flex: none; }
.queue-popover .qpop-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-popover .qpop-eta { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.04em; flex: none; }
.queue-popover .qpop-row.is-me .qpop-eta { color: #b6a8ff; font-weight: 600; }

/* Stream unmute/mute toggle, top-right of the stage. Pulses for
   attention while muted (autoplay-with-sound is browser-blocked, so
   the user has to click); collapses to a quiet circular icon-only
   button once audio is on. Ported verbatim from the design's
   audio-prompt component in stream-swap.css. */
.ss-stage .audio-prompt {
  position: absolute;
  top: 18px;
  right: 24px;
  z-index: 6;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 14px;
  background: rgba(10,9,8,0.82);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 999px;
  color: var(--fg);
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(0,0,0,0.4);
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease, box-shadow 140ms ease;
}
.ss-stage .audio-prompt.is-muted { animation: apPulse 2.8s ease-in-out 0.6s infinite; }
.ss-stage .audio-prompt:hover {
  border-color: rgba(255,255,255,0.32);
  background: rgba(20,16,14,0.94);
}
.ss-stage .audio-prompt:active { transform: none; }
.ss-stage .audio-prompt .ap-icon {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 50%;
  flex: none;
  transition: background 160ms ease, color 160ms ease;
}
.ss-stage .audio-prompt.is-muted .ap-icon {
  background: rgba(255,142,117,0.16);
  color: #ff8e75;
}
.ss-stage .audio-prompt.is-on {
  /* Match muted padding so the icon's right + top edge land in the
     exact same px - no jump on toggle. */
  padding: 6px;
  border-radius: 50%;
}
.ss-stage .audio-prompt.is-on .ap-icon {
  background: transparent;
  color: var(--ok);
  border: 0;
}
.ss-stage .audio-prompt .ap-label { white-space: nowrap; }
@keyframes apPulse {
  0%, 100% { box-shadow: 0 8px 20px rgba(0,0,0,0.4), 0 0 0 0   rgba(255,142,117,0); }
  50%      { box-shadow: 0 8px 20px rgba(0,0,0,0.4), 0 0 0 7px rgba(255,142,117,0.14); }
}

/* The design's .queue-panel sat over a static mockup so a 0.72-alpha
   panel background looked fine. Over the live video it washes out:
   the secondary copy ("Viewers take turns at the wheel...") becomes
   hard to read because the high-contrast video shows through. Push
   to near-opaque while keeping the backdrop blur so the chrome
   still feels glassy rather than slab-flat. */
.queue-panel { background: rgba(10, 9, 8, 0.92) !important; }

/* Top-bar sign-in button, shown only when the user isn't signed in.
   Matches the design's pill-button visual language so it sits
   comfortably alongside the unmute / mod-launcher buttons. */
.topbar-signin {
  background: var(--fg);
  color: var(--bg);
  border: none;
  border-radius: 999px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
  cursor: pointer;
  white-space: nowrap;
}
.topbar-signin:hover { opacity: 0.9; }
.topbar-signin:focus-visible { outline: 2px solid var(--ok); outline-offset: 2px; }

/* Dev/staging fake-chat fallback. YouTube's live_chat iframe refuses
   embed_domain values that don't match the loading origin, so on
   localhost the panel renders blank. We swap in a small static feed
   so the rest of the chat chrome looks real during local iteration. */
.ss-chat-fake { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.ss-chat-fake-banner {
  padding: 8px 12px;
  font-size: 11px;
  color: var(--dim);
  background: rgba(255, 200, 0, 0.06);
  border-bottom: 1px solid rgba(255, 200, 0, 0.15);
  text-align: center;
  flex: none;
}
.ss-chat-fake-list { overflow-y: auto; padding: 12px 8px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.ss-chat-fake-row { font-size: 13px; line-height: 1.4; word-break: break-word; }
.ss-chat-fake-author { font-weight: 600; margin-right: 6px; }
.ss-chat-fake-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(117, 88, 255, 0.18);
  color: #b6a8ff;
  margin-right: 6px;
  vertical-align: middle;
}
.ss-chat-fake-text { color: var(--fg); }

/* Hold-to-confirm button (used by End turn). Progress bar fills
   from left as the user holds. Releasing early cancels.
   Driven by a --p custom property (0..1) the React component writes
   via inline style; CSS scales the bar on the compositor with
   transform: scaleX, which keeps the animation smooth even while
   the rest of the page is laying out. The previous width-based
   animation forced one layout per RAF frame and stuttered under
   load. */
.is-hold { position: relative; overflow: hidden; }
.is-hold .hold-progress {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 138, 122, 0.35);
  pointer-events: none;
  transform: scaleX(var(--p, 0));
  transform-origin: left center;
  transition: transform 80ms linear;
  z-index: 0;
  will-change: transform;
}
.is-hold .hold-label { position: relative; z-index: 1; }
.is-hold.is-holding { background: rgba(255, 138, 122, 0.12); }

/* While the websocket is disconnected the on-screen
   queue / position / countdown numbers are frozen at whatever the
   last broadcast said. They're useful (you didn't suddenly become
   undriving), but the lack of any visual signal that they're stale
   means a brief blip mid-turn looks like the timer paused. Grey
   out queue-derived chrome when we're not connected; the topbar
   pill, modals, and toaster keep their full color so the user
   sees the connection-state indicators clearly. */
.ss-app.is-stale .queue-panel,
.ss-app.is-stale .ss-control-panel .cp-time,
.ss-app.is-stale .ss-control-panel .dpad-grid,
.ss-app.is-stale .qp-list {
  opacity: 0.55;
  filter: saturate(0.6);
  transition: opacity 200ms ease, filter 200ms ease;
}
