:root {
  color-scheme: dark;
  --bg: #0a0e17;
  --bg-elevated: #121a28;
  --bg-card: #151f30;
  --text: #eef3fb;
  --muted: #8fa3be;
  --accent: #5eead4;
  --accent-soft: rgba(94, 234, 212, 0.15);
  --line: rgba(255, 255, 255, 0.08);
  --danger: #f87171;
  --warn: #fbbf24;
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --sheet-dur: 320ms;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --hit: 48px;
  --ic: 24px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

body {
  margin: 0;
  min-height: 100dvh;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  font-optical-sizing: auto;
  font-family: "DM Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background:
    radial-gradient(100% 60% at 50% -10%, rgba(94, 234, 212, 0.08), transparent 50%),
    var(--bg);
  padding:
    calc(8px + var(--safe-top))
    max(16px, env(safe-area-inset-right))
    calc(64px + var(--safe-bottom))
    max(16px, env(safe-area-inset-left));
}

button,
a[href],
.cam-card,
.clip-row,
.activity-card,
.btn-close,
.btn-icon {
  touch-action: manipulation;
}

.cam-card,
.clip-row,
.activity-card,
.btn-close,
.live-ctl,
.ptz-btn,
#liveTalkBtn {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.ic {
  width: var(--ic);
  height: var(--ic);
  display: block;
  flex-shrink: 0;
}

.hidden,
[hidden] {
  display: none !important;
}

/* —— Header —— */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 4px;
  padding: 6px 0 10px;
  background: rgba(10, 14, 23, 0.78);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.header-brand {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.header-titles {
  min-width: 0;
}

.logo-orbit {
  width: 44px;
  height: 44px;
  perspective: 600px;
  flex-shrink: 0;
}

.logo-spin {
  width: 44px;
  height: 44px;
  animation: spin-y 4s linear infinite;
  filter: drop-shadow(0 0 12px var(--accent-soft));
}

@keyframes spin-y {
  to {
    transform: rotateY(360deg);
  }
}

.header-kicker {
  margin: 0;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.header-title {
  margin: 0;
  font-family: "Outfit", sans-serif;
  font-size: 1.35rem;
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.header-actions-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.status-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}

.status-pill[data-state="ok"] {
  color: var(--accent);
  border-color: var(--accent-soft);
  background: rgba(94, 234, 212, 0.06);
}

.status-pill[data-state="bad"] {
  color: var(--danger);
}

.status-pill[data-state="warn"] {
  color: var(--warn);
  border-color: rgba(251, 191, 36, 0.35);
  background: rgba(251, 191, 36, 0.08);
}

.btn-icon {
  width: var(--hit);
  height: var(--hit);
  min-width: var(--hit);
  min-height: var(--hit);
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 120ms var(--ease-out), color 120ms var(--ease-out), transform 100ms var(--ease-out);
}

.btn-icon:active {
  transform: scale(0.94);
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

@media (hover: hover) and (pointer: fine) {
  .btn-icon:hover {
    color: var(--accent);
    background: var(--accent-soft);
  }
}

.btn-text {
  min-height: 36px;
  padding: 6px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.btn-text:active {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.panel-lede {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
  max-width: 36rem;
}

.app-main {
  flex: 1;
  min-height: 0;
}

.app-panel {
  animation: panel-in 220ms var(--ease-out);
}

.app-panel[hidden] {
  display: none !important;
}

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

/* —— Tab bar —— */
.app-tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  gap: 2px;
  padding: 6px max(8px, env(safe-area-inset-right)) calc(6px + var(--safe-bottom))
    max(8px, env(safe-area-inset-left));
  background: rgba(10, 14, 23, 0.92);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.app-tab {
  flex: 1;
  min-height: 52px;
  padding: 4px 2px 2px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  transition: color 120ms var(--ease-out);
}

.tab-ic {
  width: 22px;
  height: 22px;
  opacity: 0.72;
  transition: opacity 120ms var(--ease-out), transform 100ms var(--ease-out);
}

.app-tab-label {
  display: block;
  line-height: 1.1;
}

.app-tab.is-active {
  color: var(--accent);
}

.app-tab.is-active .tab-ic {
  opacity: 1;
}

.app-tab:active {
  transform: scale(0.96);
}

.app-tab.is-active .tab-ic {
  transform: translateY(-1px);
}

.notif-lede {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
  max-width: 36rem;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--hit);
  padding: 10px 18px;
  border: 1px solid var(--accent-soft);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 100ms var(--ease-out), transform 100ms var(--ease-out);
}

.btn-primary:active {
  transform: scale(0.98);
  background: rgba(94, 234, 212, 0.22);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.notif-cam-list {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.notif-cam-list:empty {
  display: none;
}

.notif-cam-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--hit);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg-elevated);
  cursor: pointer;
}

.notif-cam-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.notif-cam-row label {
  flex: 1;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}

/* —— Camera grid —— */
.camera-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}

@media (min-width: 700px) {
  .camera-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }
}

@media (min-width: 1200px) {
  .camera-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.cam-card {
  display: grid;
  grid-template: 1fr / 1fr;
  padding: 0;
  border: none;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: left;
  color: inherit;
  transition: transform 100ms var(--ease-out), box-shadow 100ms var(--ease-out);
}

.cam-card.is-pressed,
.cam-card:active {
  transform: scale(0.97);
}

@media (hover: hover) and (pointer: fine) {
  .cam-card:hover {
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  }
}

.cam-card.has-frame {
  border: 1px solid var(--line);
}

.cam-card.cam-offline {
  border-color: rgba(255, 120, 100, 0.45);
}

.cam-media {
  grid-area: 1 / 1;
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  overflow: hidden;
}

.cam-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  color: transparent;
}

#panelActivity:has(#activityStrip:not(:empty)) #activityEmpty {
  display: none !important;
}

.cam-footer {
  grid-area: 1 / 1;
  align-self: end;
  z-index: 4;
  padding: 28px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.88) 0%, rgba(0, 0, 0, 0.45) 55%, transparent 100%);
  pointer-events: none;
}

.cam-footer strong {
  font-family: "Outfit", sans-serif;
  font-size: 15px;
  font-weight: 600;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

.cam-updated {
  font-size: 11px;
  color: rgba(238, 243, 251, 0.78);
}

.cam-time-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 3;
  padding: 3px 8px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  pointer-events: none;
}

.cam-time-badge[data-state="ok"] {
  color: var(--accent);
}

.cam-time-badge[data-state="offline"] {
  background: rgba(180, 50, 40, 0.88);
}

.cam-offline-banner {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 3;
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #fff;
  background: rgba(180, 50, 40, 0.92);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.cam-shimmer {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    110deg,
    transparent 30%,
    rgba(255, 255, 255, 0.06) 50%,
    transparent 70%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  pointer-events: none;
}

.cam-card.has-frame .cam-shimmer {
  opacity: 0;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* —— Activity —— */
.activity-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}

@media (min-width: 520px) {
  .activity-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 900px) {
  .activity-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.activity-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  padding: 0;
  background: var(--bg-card);
  color: inherit;
  cursor: pointer;
  text-align: left;
  transition: transform 100ms var(--ease-out), border-color 120ms var(--ease-out);
}

.activity-card:active {
  transform: scale(0.98);
}

.activity-card img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: #000;
}

.activity-card[data-status]::after {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  backdrop-filter: blur(8px);
}

.activity-card[data-status="ready"]::after {
  content: "Clip";
  color: var(--accent);
  background: rgba(10, 14, 23, 0.72);
  border: 1px solid var(--accent-soft);
}

.activity-card[data-status="recording"]::after {
  content: "Live";
  color: #fff;
  background: rgba(239, 68, 68, 0.85);
}

.activity-card[data-status="error"]::after {
  content: "Failed";
  color: #fff;
  background: rgba(248, 113, 113, 0.85);
}

.activity-cap {
  display: block;
  padding: 10px 12px 11px;
  font-size: 13px;
  line-height: 1.35;
  color: var(--text);
  font-weight: 500;
}

.live-kicker.is-live-now {
  color: #34d399;
  animation: live-pulse 1.4s ease-in-out infinite;
}

@keyframes live-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.55;
  }
}

/* —— Recordings —— */
.clip-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.clip-row {
  width: 100%;
  display: grid;
  grid-template-columns: 96px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 8px 10px 8px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-elevated);
  cursor: pointer;
  color: inherit;
  font: inherit;
  text-align: left;
  transition: background 0.15s, transform 0.12s;
}

.clip-row.is-pressed,
.clip-row:active {
  transform: scale(0.98);
  background: var(--bg-card);
}

.clip-thumb {
  width: 96px;
  height: 54px;
  border-radius: 10px;
  object-fit: cover;
  background: #000;
}

.clip-thumb-fallback {
  background: linear-gradient(135deg, #1a2538, #0d121c);
}

.clip-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.clip-cam {
  font-weight: 600;
  font-family: "Outfit", sans-serif;
  font-size: 15px;
}

.clip-when {
  font-size: 13px;
  color: var(--muted);
}

.clip-size {
  font-size: 12px;
  color: var(--muted);
  opacity: 0.85;
}

.clip-chev {
  font-size: 20px;
  color: var(--muted);
  padding-right: 2px;
  opacity: 0.6;
}

.empty-state {
  color: var(--muted);
  font-size: 14px;
  margin: 8px 0 0;
}

.recordings-timeline {
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-card);
  max-height: min(42vh, 320px);
  overflow: auto;
}

.timeline-head {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 8px;
}

.timeline-range {
  text-transform: none;
  letter-spacing: 0;
  font-size: 11px;
}

.timeline-lane {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.timeline-lane.is-focus .timeline-track {
  outline: 1px solid var(--accent-soft);
  border-radius: 6px;
}

.timeline-label {
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timeline-track {
  position: relative;
  height: 16px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  overflow: hidden;
}

.timeline-mark {
  position: absolute;
  top: 2px;
  bottom: 2px;
  min-width: 3px;
  border: none;
  border-radius: 4px;
  padding: 0;
  cursor: pointer;
  opacity: 0.92;
}

.timeline-mark.is-motion {
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.timeline-mark:active {
  opacity: 1;
  filter: brightness(1.15);
}

/* —— Dialogs —— */
.live-dialog,
.clip-dialog {
  border: none;
  padding: 0;
  margin: auto;
  max-width: none;
  max-height: none;
  width: 100%;
  height: 100%;
  background: transparent;
}

.live-dialog[open],
.clip-dialog[open] {
  display: flex;
}

.live-dialog::backdrop,
.clip-dialog::backdrop {
  background: rgba(4, 8, 14, 0.55);
  backdrop-filter: blur(12px) saturate(140%);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  opacity: 0;
  transition: opacity var(--sheet-dur) var(--ease-out);
}

.live-dialog[open]::backdrop,
.clip-dialog[open]::backdrop {
  opacity: 1;
}

.live-shell,
.clip-shell {
  width: min(960px, 100vw - 24px);
  margin: max(12px, var(--safe-top)) auto max(12px, var(--safe-bottom));
  background: rgba(18, 26, 40, 0.94);
  backdrop-filter: blur(24px) saturate(150%);
  -webkit-backdrop-filter: blur(24px) saturate(150%);
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform var(--sheet-dur) var(--ease-out), opacity var(--sheet-dur) var(--ease-out);
}

@media (max-width: 640px) {
  .live-dialog,
  .clip-dialog {
    align-items: flex-end;
    justify-content: center;
    padding: 0;
  }

  .live-shell,
  .clip-shell {
    width: 100%;
    max-width: 100%;
    margin: 0;
    border-radius: 20px 20px 0 0;
    transform: translateY(100%);
  }

  .live-dialog[open] .live-shell:not(.is-closing),
  .clip-dialog[open] .clip-shell:not(.is-closing) {
    transform: translateY(0);
  }

  .live-shell.is-closing,
  .clip-shell.is-closing {
    transform: translateY(100%);
  }

  .live-shell .live-top {
    border-radius: 20px 20px 0 0;
  }

  .live-shell .live-stage {
    border-radius: 0;
    margin: 0 -1px;
    width: calc(100% + 2px);
  }
}

.live-top,
.clip-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.live-top-main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  min-width: 0;
  flex: 1;
}

.live-top-titles {
  min-width: 0;
}

.live-kicker {
  margin: 0;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--accent);
  font-weight: 600;
}

.live-top h2,
.clip-top h2 {
  margin: 2px 0 0;
  font-family: "Outfit", sans-serif;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.live-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  white-space: nowrap;
}

.live-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--muted);
}

.live-status[data-state="connecting"] {
  color: var(--warn);
  border-color: rgba(251, 191, 36, 0.35);
}

.live-status[data-state="connecting"]::before {
  background: var(--warn);
  animation: status-pulse 1.2s ease-in-out infinite;
}

.live-status[data-state="reconnecting"] {
  color: var(--warn);
  border-color: rgba(251, 191, 36, 0.35);
}

.live-status[data-state="reconnecting"]::before {
  background: var(--warn);
  animation: status-pulse 1s ease-in-out infinite;
}

.live-status[data-state="live"] {
  color: var(--accent);
  border-color: var(--accent-soft);
  background: rgba(94, 234, 212, 0.08);
}

.live-status[data-state="live"]::before {
  background: #ef4444;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.35);
}

.live-status[data-state="offline"] {
  color: var(--muted);
}

.live-status[data-state="offline"]::before {
  background: rgba(143, 163, 190, 0.6);
}

@keyframes status-pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.45;
    transform: scale(0.85);
  }
}

.btn-close {
  width: var(--hit);
  height: var(--hit);
  min-width: var(--hit);
  min-height: var(--hit);
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 100ms var(--ease-out), background 100ms var(--ease-out);
  flex-shrink: 0;
}

.btn-close .ic {
  width: 22px;
  height: 22px;
}

.btn-close.is-pressed,
.btn-close:active {
  transform: scale(0.94);
  background: rgba(255, 255, 255, 0.08);
}

/* —— Live stage —— */
.live-stage {
  position: relative;
  aspect-ratio: 16 / 9;
  width: 100%;
  min-height: min(52vh, 480px);
  background: #000;
  overflow: hidden;
}

.live-stage.live-stage-active:has(.is-playing) {
  overflow: visible;
}

.live-stage-media {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  pointer-events: none;
}

.live-stage-media .live-video,
.live-stage-media fp-live-player {
  pointer-events: auto;
}

.live-poster {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  z-index: 4;
  pointer-events: none;
  transition: opacity 0.35s ease-out;
  background: #000;
}

.live-poster.live-poster-hidden {
  opacity: 0;
  z-index: 1;
}

.live-poster.live-poster-solo {
  opacity: 1;
  z-index: 5;
}

.live-stage-media fp-live-player,
.live-stage-media .live-rtc-layer,
.live-stage fp-live-player,
.live-stage .live-rtc-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  background: #000;
  opacity: 0;
  transition: opacity 0.25s ease-out;
}

.live-stage-media .live-video,
.live-stage .live-video {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  opacity: 0;
  transition: opacity 0.25s ease-out;
}

.live-stage-media fp-live-player.is-playing,
.live-stage-media .live-rtc-layer.is-playing,
.live-stage fp-live-player.is-playing,
.live-stage .live-rtc-layer.is-playing {
  opacity: 1;
  z-index: 3;
}

.live-stage-media .live-video.is-playing,
.live-stage-media fp-live-player.is-playing .live-video,
.live-stage .live-video.is-playing,
.live-video.is-playing {
  opacity: 1;
  z-index: 4;
}

/* —— Live nav —— */
.live-nav-btn {
  position: absolute;
  top: 50%;
  z-index: 40;
  transform: translateY(-50%);
  width: var(--hit);
  height: var(--hit);
  min-width: var(--hit);
  min-height: var(--hit);
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(10, 14, 23, 0.45);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
  opacity: 0;
  transition: background 120ms var(--ease-out), opacity 120ms var(--ease-out), transform 100ms var(--ease-out);
}

.live-nav-prev {
  left: max(8px, env(safe-area-inset-left));
}

.live-nav-next {
  right: max(8px, env(safe-area-inset-right));
}

@media (hover: hover) and (pointer: fine) {
  .live-nav-btn {
    opacity: 0.85;
  }

  .live-nav-btn:hover {
    opacity: 1;
    background: rgba(10, 14, 23, 0.72);
    border-color: var(--accent-soft);
  }
}

@media (hover: none) {
  .live-nav-btn {
    display: none;
  }
}

.live-nav-btn:active {
  transform: translateY(-50%) scale(0.94);
}

/* —— PTZ —— */
.live-ptz-overlay {
  position: absolute;
  right: max(10px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 35;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  pointer-events: auto;
  touch-action: none;
}

.live-ptz-overlay[hidden] {
  display: none !important;
}

.ptz-pad {
  display: flex;
  align-items: center;
  gap: 10px;
  touch-action: none;
}

.ptz-ring {
  position: relative;
  width: 156px;
  height: 156px;
  border-radius: 50%;
  background: rgba(10, 14, 23, 0.55);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}

.ptz-btn {
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  touch-action: none;
  transition: background 80ms ease, transform 80ms ease;
}

.ptz-btn.is-pressed,
.ptz-btn:active {
  transform: scale(0.92);
}

.ptz-wedge {
  position: absolute;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.ptz-wedge .ic {
  width: 20px;
  height: 20px;
  opacity: 0.9;
}

.ptz-up {
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
}

.ptz-down {
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
}

.ptz-left {
  left: 4px;
  top: 50%;
  transform: translateY(-50%);
}

.ptz-right {
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
}

.ptz-center {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 52px;
  height: 52px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ptz-stop-mark {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: var(--muted);
}

.ptz-wedge.is-pressed,
.ptz-wedge:active,
.ptz-center.is-pressed,
.ptz-center:active {
  background: var(--accent-soft);
}

.ptz-zoom-pills {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ptz-zoom-pill {
  min-width: 40px;
  min-height: 40px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(10, 14, 23, 0.55);
  backdrop-filter: blur(12px);
  font-size: 18px;
  font-weight: 600;
  line-height: 1;
}

.ptz-zoom-pill[hidden] {
  display: none !important;
}

.ptz-hint {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
  min-height: 1em;
  text-align: right;
  max-width: 200px;
}

.ptz-hint.warn {
  color: var(--danger);
}

/* —— Live controls —— */
.live-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: 4px 2px;
  padding: 8px 8px 10px;
  border-top: 1px solid var(--line);
  background: rgba(10, 14, 23, 0.35);
}

.live-ctl {
  min-width: 56px;
  min-height: var(--hit);
  padding: 6px 4px 4px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: color 120ms var(--ease-out), background 100ms var(--ease-out), transform 100ms var(--ease-out), box-shadow 120ms var(--ease-out);
}

.live-ctl .lbl {
  line-height: 1.1;
  max-width: 64px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.live-ctl:active,
.live-ctl.is-pressed {
  transform: scale(0.94);
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.live-ctl:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.live-ctl[aria-pressed="true"],
.live-ctl[data-state="on"] {
  color: var(--accent);
}

.live-ctl[aria-pressed="true"] .ic,
.live-ctl[data-state="on"] .ic {
  filter: drop-shadow(0 0 8px rgba(94, 234, 212, 0.35));
}

.live-ctl-primary {
  min-width: 64px;
  min-height: 56px;
  padding-top: 8px;
  color: var(--accent);
  background: rgba(94, 234, 212, 0.1);
  border: 1px solid var(--accent-soft);
  border-radius: 14px;
}

.live-ctl-primary.is-pressed,
.live-ctl-primary:active {
  box-shadow: 0 0 0 3px rgba(94, 234, 212, 0.25), 0 0 24px rgba(94, 234, 212, 0.2);
  background: rgba(94, 234, 212, 0.18);
  color: #fff;
}

.live-ctl-talk-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.live-talk-hint {
  margin: 0;
  font-size: 10px;
  color: var(--muted);
  text-align: center;
  max-width: 72px;
  line-height: 1.2;
}

.live-talk-hint:not([hidden]) {
  display: block;
}

.live-hint {
  margin: 0;
  padding: 8px 16px 12px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.live-hint:empty {
  display: none;
}

@media (max-width: 640px) {
  .live-hint {
    padding-bottom: calc(12px + var(--safe-bottom));
  }
}

/* —— Clip dialog —— */
.clip-video-wrap {
  background: #000;
}

.clip-video {
  width: 100%;
  display: block;
  max-height: min(68vh, 560px);
  aspect-ratio: 16 / 9;
  object-fit: contain;
  background: #000;
}

.clip-scrub {
  padding: 12px 16px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.clip-scrub input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  touch-action: manipulation;
  height: 28px;
}

.clip-transport {
  display: flex;
  justify-content: center;
  gap: 16px;
}

.clip-transport-btn {
  min-width: 72px;
}

/* —— Fullscreen / immersive —— */
html.live-fs-lock,
html.live-fs-lock body {
  overflow: hidden;
  overscroll-behavior: none;
}

.live-dialog.live-fs-active {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  align-items: stretch;
  justify-content: stretch;
}

.live-dialog.live-fs-active::backdrop {
  background: #000;
  opacity: 1;
}

.live-dialog.live-fs-active .live-shell {
  width: 100%;
  height: 100%;
  max-height: 100dvh;
  margin: 0;
  border-radius: 0;
  border: none;
  transform: none !important;
  display: flex;
  flex-direction: column;
  background: #000;
}

.live-dialog.live-fs-active .live-stage {
  flex: 1;
  aspect-ratio: auto;
  min-height: 0;
  width: 100%;
}

.live-dialog.live-immersive,
.live-dialog.live-landscape {
  align-items: stretch;
  justify-content: stretch;
  padding: 0;
}

.live-dialog.live-immersive .live-shell,
.live-dialog.live-landscape .live-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  margin: 0;
  border-radius: 0;
  border: none;
  background: #000;
}

.live-dialog.live-immersive .live-stage,
.live-dialog.live-landscape .live-stage {
  flex: 1;
  aspect-ratio: auto;
  min-height: 0;
}

.live-dialog.live-immersive .live-top,
.live-dialog.live-landscape .live-top,
.live-dialog.live-fs-active .live-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  padding-top: max(8px, var(--safe-top));
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  border: none;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.75), transparent);
}

.live-dialog.live-immersive .live-controls,
.live-dialog.live-landscape .live-controls,
.live-dialog.live-fs-active .live-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  margin: 0;
  border: none;
  flex-wrap: nowrap;
  justify-content: center;
  gap: 2px;
  padding: 32px 8px calc(10px + var(--safe-bottom));
  background: linear-gradient(to top, rgba(0, 0, 0, 0.82) 0%, rgba(0, 0, 0, 0.35) 55%, transparent 100%);
  opacity: 1;
  transition: opacity 0.35s var(--ease-out);
}

.live-dialog.live-immersive .live-shell:not(:focus-within):not(:hover) .live-controls,
.live-dialog.live-landscape .live-shell:not(:focus-within):not(:hover) .live-controls,
.live-dialog.live-fs-active .live-shell:not(:focus-within):not(:hover) .live-controls {
  opacity: 0.55;
}

.live-dialog.live-immersive .live-hint,
.live-dialog.live-landscape .live-hint,
.live-dialog.live-fs-active .live-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(68px + var(--safe-bottom));
  z-index: 25;
  padding: 6px 16px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.75);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}

.live-dialog.live-immersive .live-ptz-overlay,
.live-dialog.live-landscape .live-ptz-overlay,
.live-dialog.live-fs-active .live-ptz-overlay {
  bottom: calc(76px + var(--safe-bottom));
}

.live-shell:fullscreen {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  background: #000;
  border: none;
  border-radius: 0;
}

.live-shell:fullscreen .live-stage {
  flex: 1;
  aspect-ratio: auto;
  min-height: 0;
}

.live-shell:fullscreen .live-poster,
.live-shell:fullscreen .live-video,
.live-shell:fullscreen fp-live-player.is-playing {
  object-fit: contain;
}

@media (orientation: landscape) {
  .live-dialog.live-landscape .live-shell {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
}

/* —— Sign-in page —— */
body.sign-in-page {
  display: grid;
  place-items: center;
  padding: 24px max(16px, env(safe-area-inset-right)) calc(24px + var(--safe-bottom))
    max(16px, env(safe-area-inset-left));
  background:
    radial-gradient(80% 50% at 50% 0%, rgba(94, 234, 212, 0.1), transparent 55%),
    var(--bg);
}

.sign-in-card {
  width: min(22rem, 100%);
  text-align: center;
  padding: 28px 24px 32px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: rgba(18, 26, 40, 0.92);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
}

.sign-in-card h1 {
  margin: 0 0 8px;
  font-family: "Outfit", sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
}

.sign-in-card .sign-in-lede {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.sign-in-card .btn-primary {
  width: 100%;
  margin-top: 22px;
}

.sign-in-card .sign-in-err {
  color: var(--danger);
  margin-top: 14px;
  font-size: 13px;
  min-height: 1.2em;
}

@media (prefers-reduced-motion: reduce) {
  .logo-spin,
  .cam-shimmer,
  .live-status[data-state="connecting"]::before,
  .live-status[data-state="reconnecting"]::before,
  .live-kicker.is-live-now {
    animation: none;
  }

  .live-shell,
  .clip-shell,
  .live-dialog::backdrop,
  .clip-dialog::backdrop,
  .app-panel {
    transition: opacity 180ms ease !important;
    transform: none !important;
    animation: none;
  }

  .live-ctl,
  .cam-card,
  .activity-card {
    transition: none;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .app-header,
  .app-tabbar,
  .live-shell,
  .clip-shell,
  .live-dialog::backdrop,
  .clip-dialog::backdrop,
  .ptz-ring,
  .live-nav-btn {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: var(--bg-elevated);
  }

  .live-dialog::backdrop,
  .clip-dialog::backdrop {
    background: rgba(4, 8, 14, 0.92);
  }
}
