:root {
  color-scheme: dark;
  --bg0: #0b0d10;
  --bg1: #14181f;
  --bg2: #10141a;
  --line: #2a3140;
  --text: #e8edf5;
  --muted: #8b95a8;
  --accent: #3d9a7a;
  --accent-strong: #4db894;
  --danger: #c45c5c;
  --focus: #6eb8ff;
  --radius: 14px;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, #1a2433 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #16221c 0%, transparent 50%),
    var(--bg0);
  color: var(--text);
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

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

.exit-btn {
  flex-shrink: 0;
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}

.exit-btn:hover:not(:disabled) {
  color: var(--text);
  border-color: color-mix(in srgb, var(--line) 70%, var(--text));
}

.brand {
  margin: 0;
  font-size: 1.75rem;
  letter-spacing: -0.03em;
  font-weight: 650;
}

.status {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

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

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

.panel {
  background: color-mix(in srgb, var(--bg1) 88%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem;
}

.label {
  display: block;
  margin-bottom: 0.45rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.label.inline {
  margin: 0;
}

.code-input {
  width: 100%;
  padding: 0.9rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #0e1218;
  color: var(--text);
  font-size: 1.35rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin-bottom: 0.85rem;
}

.code-input:focus {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #1b222d;
  color: var(--text);
  border-radius: 999px;
  padding: 0.75rem 1.2rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

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

.btn:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--focus) 40%, var(--line));
}

.btn.primary {
  width: 100%;
  background: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 70%, #000);
  color: #04140f;
}

.btn.danger {
  background: color-mix(in srgb, var(--danger) 22%, #1b222d);
  border-color: color-mix(in srgb, var(--danger) 55%, var(--line));
}

.btn.danger[data-recording="true"] {
  background: var(--danger);
  color: #fff;
  border-color: color-mix(in srgb, var(--danger) 80%, #000);
}

.btn.compact-btn {
  padding: 0.5rem 0.9rem;
  font-size: 0.85rem;
}

.error {
  margin: 0.75rem 0 0;
  color: var(--danger);
  font-size: 0.9rem;
}

/* ---------- Viewer workspace (desktop-first two-column dashboard) ---------- */

.viewer-panel {
  display: block;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 400px) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: stretch;
}

.workspace-column {
  background: color-mix(in srgb, var(--bg1) 88%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.workspace-column[hidden] {
  display: none;
}

.column-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-strong);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent-strong) 60%, transparent);
  animation: live-pulse 2s ease-out infinite;
}

@keyframes live-pulse {
  0% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent-strong) 55%, transparent);
  }
  70% {
    box-shadow: 0 0 0 6px transparent;
  }
  100% {
    box-shadow: 0 0 0 0 transparent;
  }
}

.column-title {
  margin: 0.15rem 0 0;
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.stream-stats {
  display: flex;
  gap: 0.6rem;
  font-size: 0.75rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  background: #0e1218;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  white-space: nowrap;
}

.icon-btn {
  appearance: none;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #1b222d;
  color: var(--text);
  font-size: 1.2rem;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
}

.icon-btn:hover {
  border-color: color-mix(in srgb, var(--danger) 55%, var(--line));
  color: var(--danger);
}

.text-btn {
  appearance: none;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.2rem 0;
}

.text-btn:hover {
  color: var(--focus);
}

/* Live column */

.live-content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.live-primary {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.video-shell {
  position: relative;
  aspect-ratio: 9 / 16;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  touch-action: none;
  cursor: grab;
  contain: layout paint;
  width: 100%;
  margin: 0 auto;
}

.live-video-shell {
  max-height: 56vh;
}

.playback-shell {
  max-height: 74vh;
}

.video-shell.is-dragging {
  cursor: grabbing;
}

.video-shell.is-zoomed {
  cursor: grab;
}

/* Filters live OUTSIDE the scaled layer — avoids black-frame compositor bugs. */
.video-fx {
  width: 100%;
  height: 100%;
  transform: translateZ(0);
}

.video-stage {
  position: relative;
  width: 100%;
  height: 100%;
  transform-origin: center center;
  backface-visibility: hidden;
}

.video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  position: absolute;
  inset: 0;
  /* Keep decoder frames on their own layer without parenting under a filtered ancestor. */
  transform: translateZ(0);
}

.svg-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.controls {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
}

.record-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}

.record-icon {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
  flex-shrink: 0;
}

.record-btn[data-recording="true"] .record-icon {
  border-radius: 3px;
  background: #fff;
  animation: record-blink 1.2s ease-in-out infinite;
}

@keyframes record-blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

.record-timer {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  color: #ff8e8e;
  min-width: 4.5rem;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

/* Settings / enhance panel */

.enhance-panel {
  display: grid;
  gap: 0.6rem;
  padding: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg2);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.15rem;
}

.settings-title {
  margin: 0.1rem 0 0;
  font-size: 0.95rem;
  font-weight: 650;
}

.enhance-row {
  display: grid;
  grid-template-columns: minmax(7rem, 9rem) 1fr;
  gap: 0.55rem;
  align-items: center;
}

.enhance-row .label {
  font-variant-numeric: tabular-nums;
}

.range {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.enhance-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.1rem;
}

/* Review column */

.rec-badge {
  position: absolute;
  top: 0.65rem;
  left: 0.65rem;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: rgba(10, 12, 16, 0.72);
  border: 1px solid color-mix(in srgb, var(--danger) 55%, var(--line));
  color: #ffb3b3;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  backdrop-filter: blur(3px);
}

.rec-badge-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  animation: record-blink 1.2s ease-in-out infinite;
}

#review-panel.is-live-recording .playback-shell {
  border-color: color-mix(in srgb, var(--danger) 55%, var(--line));
}

.review-content {
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex: 1;
  gap: 0.9rem;
  min-width: 0;
}

.playback-controls {
  display: grid;
  gap: 0.75rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg2);
}

.review-time {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.55rem;
  align-items: center;
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
  color: var(--muted);
}

.seek-bar {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.review-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.review-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}

#restart-playback-btn {
  min-width: 5.5rem;
}

.control-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #1b222d;
  color: var(--text);
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.control-btn:hover {
  border-color: color-mix(in srgb, var(--focus) 40%, var(--line));
}

.play-btn {
  appearance: none;
  border: 1px solid color-mix(in srgb, var(--accent) 70%, #000);
  background: var(--accent);
  color: #04140f;
  border-radius: 10px;
  padding: 0.55rem 1.4rem;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  min-width: 5rem;
}

.play-btn:hover {
  background: var(--accent-strong);
}

.speed-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.playback-zoom-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.playback-zoom-val {
  min-width: 2.5rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  color: var(--muted);
}

.playback-orient-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.playback-orient-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.orient-btn.is-active,
.orient-btn[aria-pressed='true'] {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
  background: color-mix(in srgb, var(--accent) 18%, #1b222d);
  color: var(--text);
}

.speed-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.speed-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #1b222d;
  color: var(--text);
  border-radius: 999px;
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.speed-btn.is-active {
  background: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 70%, #000);
  color: #04140f;
}

.review-keys {
  font-size: 0.75rem;
}

/* Empty review placeholder */

.review-empty {
  align-items: center;
  justify-content: center;
  text-align: center;
  border-style: dashed;
  gap: 0.9rem;
  min-height: 260px;
}

.review-empty .eyebrow {
  display: inline-flex;
  justify-content: center;
}

.empty-visual {
  width: 3.2rem;
  height: 3.2rem;
  border-radius: 50%;
  background: #1b222d;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 1.1rem;
}

.empty-copy {
  margin: 0.4rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---------- Layout breakpoints ---------- */

@media (min-width: 980px) {
  .app {
    max-width: 1400px;
    padding: 2rem 2.5rem 3rem;
  }

  .brand {
    font-size: 2rem;
  }

  .workspace {
    grid-template-columns: 380px minmax(0, 1fr);
    gap: 1.5rem;
  }

  .live-video-shell {
    max-height: 62vh;
  }

  .playback-shell {
    max-height: 78vh;
  }
}

@media (max-width: 979px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .live-video-shell,
  .playback-shell {
    max-height: 62vh;
  }

  .review-empty {
    min-height: 180px;
  }
}
