:root {
  --bg: #000;
  --fg: #e8e8e8;
  --panel: rgba(0, 0, 0, 0.72);
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
  overscroll-behavior: none;
  /* Forwarded touches (native touch) must not pan or zoom this page. */
  touch-action: none;
  font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
}

#stage {
  position: fixed;
  inset: 0;
  height: 100dvh;
  outline: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#screen {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
}

#status {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--panel);
  pointer-events: none;
}

#status:empty, #status[hidden] { display: none; }

/* ---------- Stage 10: loader (SPEC-10 "Default loader"). A custom.css restyles it through these
   variables; a custom loader.html replaces the markup. Hidden at ready with `hidden`: display: none
   removes the spinner's animation, which would otherwise delay wheel input (docs/design.md, "Client
   rule"). `!important` so no restyle can keep a hidden loader on screen. ---------- */
:root {
  --loader-bg: #fff;           /* the default looks like a blank page loading in a browser */
  --loader-fg: #5f6368;
  --loader-accent: #1a73e8;
  --loader-track: rgba(0, 0, 0, 0.08);
  --loader-logo: none;          /* e.g. url(/custom/<name>/logo.svg): absolute, the index inlines loader.html */
  --loader-logo-size: 0px;      /* the logo slot's size; 0 = no logo */
  --loader-spinner-size: 24px;
  --loader-font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}

#loader {
  position: fixed;
  inset: 0;
  z-index: 5; /* under the chips (7) */
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--loader-bg);
  color: var(--loader-fg);
  font: var(--loader-font);
  /* Clicks go through to #stage (the tap to start the video, a replaced tab taking its session back). */
  pointer-events: none;
}
#loader[hidden] { display: none !important; }

.loader-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: calc(100vw - 32px);
  text-align: center;
}

.loader-logo {
  width: var(--loader-logo-size);
  height: var(--loader-logo-size);
  background: var(--loader-logo) center / contain no-repeat;
}

.loader-spinner {
  box-sizing: border-box;
  width: var(--loader-spinner-size);
  height: var(--loader-spinner-size);
  border: 2.5px solid var(--loader-track);
  border-top-color: var(--loader-accent);
  border-radius: 50%;
  animation: cuddle-spin 0.9s linear infinite;
}
@keyframes cuddle-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .loader-spinner { animation-duration: 2.4s; } }

/* A final or waiting message (link invalid, session ended, open in another tab): no spinner. A custom
   loader marks its own spinner with data-cuddle-spinner to get the same. */
#loader.loader-static [data-cuddle-spinner] { display: none !important; }

/* The default loader is only the spinner: no text while it spins (connecting, starting, every server busy
   retry). Its status line shows only in a static message (tap to start the video, another tab, invalid link).
   A custom loader.html's own status line is not affected. */
.loader-status { overflow-wrap: anywhere; }
#loader:not(.loader-static) .loader-status { display: none; }
#loader.loader-static .loader-status:empty { display: none; }

/* The browser refused to start the video without a gesture (iOS Low Power Mode, Safari Auto-Play "Never"):
   a neutral checkbox card asks for the press instead of a video prompt (app.js tapCard). The press anywhere
   counts. No spinner and no status line beside it. */
.loader-check {
  display: none;
  align-items: center;
  gap: 12px;
  box-sizing: border-box;
  width: 280px;
  max-width: calc(100vw - 32px);
  padding: 14px 16px;
  border: 1px solid #d3d3d3;
  border-radius: 4px;
  background: #f9f9f9;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.08);
  color: #222;
  font: 14px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  text-align: left;
}
.loader-check-box {
  flex: none;
  box-sizing: border-box;
  width: 26px;
  height: 26px;
  border: 2px solid #c1c1c1;
  border-radius: 2px;
  background: #fff;
}
#loader.loader-tap .loader-check { display: flex; }
#loader.loader-tap .loader-spinner,
#loader.loader-tap .loader-status { display: none; }
#loader.loader-tap-checking .loader-check-box {
  border-color: rgba(0, 0, 0, 0.08);
  border-top-color: var(--loader-accent);
  border-radius: 50%;
  animation: cuddle-spin 0.9s linear infinite;
}

#stats {
  position: fixed;
  right: 8px;
  top: 8px;
  margin: 0;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--panel);
  pointer-events: none;
  white-space: pre;
}

/* Shown only while the stream is below the requested resolution (pixel budget). */
#degraded {
  position: fixed;
  left: 8px;
  bottom: calc(8px + env(safe-area-inset-bottom));
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--panel);
  font-size: 11px;
  opacity: 0.65;
  pointer-events: none;
}

#degraded[hidden] { display: none; }

#kbd-btn {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 24px;
  background: var(--panel);
  color: var(--fg);
  font-size: 22px;
}

/* Focusable for the mobile keyboard, but invisible. 16px avoids iOS zoom-on-focus. */
#kbd {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  border: 0;
  padding: 0;
  font-size: 16px;
  resize: none;
}

/* ---------- Toasts (client/toast.js). #chips is outside #stage and floats over it. ---------- */
/* Chips and toasts. The container ignores the pointer; chips with a button take it back. */
#chips {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100vw - 24px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  z-index: 7;
  pointer-events: none;
}
#chips:empty { display: none; }
.chip {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  padding: 6px 12px;
  border-radius: 16px;
  background: rgba(32, 32, 36, 0.95);
  color: var(--fg);
  font: 13px/1.3 system-ui, -apple-system, sans-serif;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
  pointer-events: auto;
  overflow-wrap: anywhere;
}
.chip button {
  flex: none;
  padding: 4px 10px;
  border: 0;
  border-radius: 12px;
  background: #3b82f6;
  color: #fff;
  font: inherit;
  font-weight: 600;
}

#copy-btn {
  position: fixed;
  right: calc(76px + env(safe-area-inset-right));
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 24px;
  background: var(--panel);
  color: var(--fg);
  font-size: 22px;
}
#copy-btn[hidden] { display: none; }

/* ---------- Connection loss after ready (netloss.js, created by app.js) ---------- */
/* The frozen last frame: the video's own box and fit, so the same letterboxing at any size. Above the video,
   under everything else; the stage keeps the pointer (input is ignored while the connection is down). */
#freeze {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
}
#freeze[hidden] { display: none; }

/* A small browser-like indicator: a thin indeterminate bar along the top edge and a chip under it.
   display: none when connected, so neither animation runs after ready (docs/design.md, "Client rule"). */
#netloss {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 6; /* over the stage, under the chips (7); the big loader (5) is hidden while this shows */
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
}
#netloss[hidden] { display: none !important; }
.netloss-bar {
  position: relative;
  align-self: stretch;
  height: 3px;
  margin-top: env(safe-area-inset-top);
  overflow: hidden;
  background: var(--loader-track);
}
.netloss-bar::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 40%;
  background: var(--loader-accent);
  animation: cuddle-netbar 1.4s ease-in-out infinite;
}
@keyframes cuddle-netbar { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
.netloss-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 6px 12px;
  border-radius: 16px;
  background: rgba(32, 32, 36, 0.92);
  color: var(--fg);
  font: 13px/1.3 system-ui, -apple-system, sans-serif;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}
.netloss-spin {
  box-sizing: border-box;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--fg);
  border-radius: 50%;
  animation: cuddle-spin 0.9s linear infinite;
}
@media (prefers-reduced-motion: reduce) {
  .netloss-bar::before { animation-duration: 3s; }
  .netloss-spin { animation-duration: 2.4s; }
}
