:root {
  --bg: #ffffff;
  --text: #000000;
  --muted: #6b6b6b;
  --line: rgba(0, 0, 0, 0.08);
  --glass: rgba(255, 255, 255, 0.84);
  --field: rgba(0, 0, 0, 0.05);
  --accent: #000000;
  --accent-text: #ffffff;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --text: #ffffff;
    --muted: #8f8f8f;
    --line: rgba(255, 255, 255, 0.1);
    --glass: rgba(0, 0, 0, 0.66);
    --field: rgba(255, 255, 255, 0.08);
    --accent: #ffffff;
    --accent-text: #000000;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; overflow: hidden; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

button, input { font: inherit; color: inherit; }
a { color: inherit; font-weight: 600; }

.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { flex: none; width: 14px; height: 14px; }

/* Pale panels over the picture. */
.bar, .credit, .next, .composer, .toast, .job {
  background: var(--glass);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
}

/* ---- The stage: full bleed ---- */

.stage { position: fixed; inset: 0; background: var(--bg); }

.shot {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: var(--bg);
  opacity: 0;
  transition: opacity 0.35s ease;
}
.shot.live { opacity: 1; }

.empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0 24px;
  color: var(--muted);
  text-align: center;
}
.empty p { margin: 0; }
.empty .big { color: var(--text); font-size: 20px; font-weight: 650; }

/* ---- The bar ---- */

.bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  font-size: 13px;
}
.logo {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  margin-left: -6px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: color 0.25s ease, transform 0.12s ease;
}
.logo svg { width: auto; height: 22px; }
.logo:active { transform: scale(0.88); }
.logo:focus-visible { outline: 2px solid var(--text); outline-offset: 1px; }
.name { font-weight: 650; letter-spacing: -0.01em; white-space: nowrap; }
.watching { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.watching:not(:empty)::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 7px;
  border-radius: 50%;
  background: #e5484d;
  vertical-align: 1px;
  animation: pulse 1.6s ease-in-out infinite;
}
.grow { flex: 1; }
.you { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.remaining { color: var(--muted); font-variant-numeric: tabular-nums; transition: color 0.4s ease; }
.remaining.ticking { color: var(--text); }

/* How many clips are waiting, on the Up next chip and its sections. */
.count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 11px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.chip[aria-expanded="true"] { border-color: var(--text); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.chip[aria-pressed="false"] { color: var(--muted); }

.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}
.link:hover { color: var(--text); }

.handle { font-weight: 600; white-space: nowrap; }
.handle::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--handle);
}

/* ---- Now playing ---- */

.credits {
  position: fixed;
  left: 16px;
  bottom: 92px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  max-width: min(560px, calc(100% - 32px));
}
.credit {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  margin: 0;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
}
.credit .prompt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-style: italic; }
.credit .by { flex: none; color: var(--muted); white-space: nowrap; }
.credit .by .handle { color: var(--text); }

/* ---- Up next ---- */

.next {
  position: fixed;
  top: 52px;
  right: 16px;
  z-index: 5;
  width: 300px;
  max-height: calc(100% - 200px);
  overflow-y: auto;
  padding: 6px;
  border-radius: 14px;
}
.next section + section { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line); }
.next h2 {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 4px 8px 2px;
  font-size: 12px;
  font-weight: 650;
}
.next ol { margin: 0; padding: 0; list-style: none; }
.next li.none { color: var(--muted); }
.next li {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 8px;
  border-radius: 9px;
  font-size: 13px;
}
.next li + li { border-top: 1px solid var(--line); }
.next .text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.next .prompt {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-style: italic;
}
.next .by { color: var(--muted); }
.next li.making { animation: pulse 1.6s ease-in-out infinite; }
.next li.making .text { display: block; color: var(--muted); }

/* ---- Composer ---- */

.composer {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 10;
  width: min(760px, calc(100% - 32px));
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.kinds {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2px;
  padding: 2px;
  border-radius: 10px;
  background: var(--field);
}
.kinds button {
  height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.kinds button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
.composer input {
  height: 40px;
  min-width: 0;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  outline: none;
  background: var(--field);
  font-size: 15px;
}
.composer input:focus-visible { outline: 2px solid var(--text); outline-offset: -2px; }
.composer input::placeholder { color: var(--muted); }
.primary {
  height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.primary:disabled { opacity: 0.5; cursor: default; }
.status { grid-column: 1 / -1; margin: 0 4px 2px; font-size: 13px; }
.status:empty { display: none; }
.status a { margin-left: 2px; }

.toast {
  position: fixed;
  top: 52px;
  left: 50%;
  z-index: 20;
  max-width: calc(100% - 32px);
  transform: translateX(-50%);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow);
}

/* ---- Clips being made: one card each, bottom right ---- */

.jobs {
  position: fixed;
  right: 16px;
  bottom: 92px;
  z-index: 6;
  width: 300px;
  max-height: 50%;
  overflow-y: auto;
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.job {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 9px 8px 9px 12px;
  border-radius: 12px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: rise 0.25s ease;
}
.job > .icon { margin-top: 3px; color: var(--muted); }
.job .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.job .prompt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-style: italic; }
.job .state { color: var(--muted); }
.job.making .state::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 6px;
  border: 1.5px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -1px;
  animation: spin 0.8s linear infinite;
}
.job.done .state { color: var(--text); font-weight: 600; }
.job.failed .state { color: var(--text); }
.job .dismiss {
  flex: none;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.job .dismiss:hover { color: var(--text); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* ---- Phones: the stream is the whole screen ---- */

@media (max-width: 899px) {
  .next { left: 16px; right: 16px; width: auto; max-height: 45%; }
}

@media (max-width: 640px) {
  /* Mark, name, Up next, what's left and sound have to share 390 pixels. */
  .bar { height: 44px; gap: 6px; padding: 0 12px 0 6px; font-size: 12px; }
  .logo { margin-left: 0; }
  .name { font-size: 12px; }
  #next-toggle { padding: 0 5px 0 9px; }
  #sound { width: 28px; padding: 0; justify-content: center; }
  .next, .toast { top: 54px; }
  .watching, .you .handle, #disconnect, .long, #sound .label { display: none; }
  .composer { grid-template-columns: minmax(0, 1fr) auto; }
  .kinds { grid-column: 1 / -1; }
  .credits { bottom: 148px; }
  /* On a phone the cards sit where the credits are, so the credits step aside. */
  .jobs { left: 12px; right: 12px; bottom: 148px; width: auto; max-height: 40%; }
  body:has(.jobs li) .credits { visibility: hidden; }
  .toast { border-radius: 14px; text-align: center; }
  .credit { font-size: 12px; }
}
