:root, :root[data-theme="dark"] {
  --bg: #131210;
  --bg-elev: #1b1a17;
  --card: #22201d;
  --card-hover: #292622;
  --surface-soft: #2a2824;
  --border: #322f29;
  --border-strong: #454038;
  --text: #eeeae1;
  --text-strong: #fbf9f4;
  --muted: #a19b8f;
  --faint: #6f6a60;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.16);
  --accent-fg: #ffffff;
  --pin: #e0a800;
  --pin-soft: rgba(224, 168, 0, 0.16);
  --good: #10b981;
  --good-soft: rgba(16, 185, 129, 0.15);
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.15);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.15);
  --btn-primary: #f3efe6;
  --btn-primary-fg: #141310;
  --band: #282622;
  --band-alt: #211f1c;
  --band-cur: #3c3831;
  --input-bg: #171613;
  --shadow: 0 12px 32px -14px rgba(0, 0, 0, 0.55);
}

:root[data-theme="light"] {
  --bg: #eceae4;
  --bg-elev: #fbfaf7;
  --card: #ffffff;
  --card-hover: #f7f5f0;
  --surface-soft: #f2f0ea;
  --border: #e3e0d7;
  --border-strong: #cfc9bc;
  --text: #27251f;
  --text-strong: #151411;
  --muted: #767268;
  --faint: #a49f94;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.12);
  --accent-fg: #ffffff;
  --pin: #c99500;
  --pin-soft: rgba(201, 149, 0, 0.15);
  --good: #059669;
  --good-soft: rgba(5, 150, 105, 0.13);
  --warn: #d97706;
  --warn-soft: rgba(217, 119, 6, 0.13);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.13);
  --btn-primary: #171613;
  --btn-primary-fg: #fbfaf7;
  --band: #dedbd3;
  --band-alt: #e7e4dc;
  --band-cur: #cbc6bb;
  --input-bg: #fdfcfa;
  --shadow: 0 10px 26px -12px rgba(20, 19, 16, 0.16);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13.5px/1.55 "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* Header & Navigation */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 20px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 52%, #e0a800 100%);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: -0.03em;
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.35);
}
.brand-name {
  font-weight: 700;
  font-size: 14.5px;
  color: var(--text-strong);
  letter-spacing: -0.02em;
  line-height: 1.15;
}
.brand-sub {
  font-size: 11px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.domain-pill {
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 10.5px;
}

.tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.14s ease;
}
.tab-btn:hover { color: var(--text-strong); background: var(--surface-soft); }
.tab-btn.active {
  color: var(--text-strong);
  background: var(--card);
  border-color: var(--border-strong);
  box-shadow: 0 2px 8px -4px rgba(0, 0, 0, 0.35);
}
.tab-badge {
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  background: var(--surface-soft);
  color: var(--muted);
}
.tab-btn.active .tab-badge { background: var(--accent-soft); color: var(--accent); }

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
}
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 3px var(--good-soft);
}
.icon-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.14s;
}
.icon-btn:hover { border-color: var(--border-strong); }

/* Main Container */
.workspace {
  max-width: 1460px;
  margin: 0 auto;
  padding: 20px;
}
.view-panel { display: none; }
.view-panel.active { display: block; animation: fadeIn 0.18s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* Cards & Grids */
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.9fr); gap: 18px; align-items: start; }
.grid-equal { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-wrap { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.space-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.card-compact { padding: 14px; }
.card-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.hero-heading {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-strong);
  line-height: 1.2;
}
.subcopy { color: var(--muted); font-size: 13.5px; margin-top: 4px; }

/* Inputs & Controls */
label.field-label {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}
.input, .textarea, .select {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text-strong);
  outline: none;
  transition: border-color 0.14s, background 0.14s;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--accent); background: var(--card); }
.textarea { resize: vertical; min-height: 92px; line-height: 1.5; }

.segmented {
  display: inline-flex;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 3px;
  gap: 3px;
}
.seg-btn {
  padding: 6px 11px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.13s;
}
.seg-btn:hover { color: var(--text-strong); }
.seg-btn.active {
  background: var(--card);
  color: var(--text-strong);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

/* Style Selector Cards */
.style-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.style-card {
  position: relative;
  border-radius: 11px;
  border: 1.5px solid var(--border);
  background: var(--input-bg);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  transition: all 0.16s ease;
}
.style-card:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.style-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.style-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
  background: #0d0d10;
}
.style-body { padding: 10px 12px; }
.style-name { font-weight: 700; color: var(--text-strong); font-size: 13px; display: flex; align-items: center; justify-content: space-between; }
.style-desc { font-size: 11.5px; color: var(--muted); margin-top: 3px; line-height: 1.4; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  background: var(--surface-soft);
  color: var(--muted);
}
.pill-accent { background: var(--accent-soft); color: var(--accent); }
.pill-good { background: var(--good-soft); color: var(--good); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-danger { background: var(--danger-soft); color: var(--danger); }
.pill-pin { background: var(--pin-soft); color: var(--pin); }

/* Toggle Switch */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--input-bg);
}
.toggle-meta strong { display: block; font-size: 12.5px; color: var(--text-strong); }
.toggle-meta span { font-size: 11px; color: var(--muted); }
.switch {
  position: relative;
  width: 38px;
  height: 22px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  inset: 0;
  background: var(--border-strong);
  border-radius: 999px;
  cursor: pointer;
  transition: 0.16s;
}
.slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #fff;
  transition: 0.16s;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(16px); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: var(--surface-soft);
  color: var(--text-strong);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.14s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--card-hover); border-color: var(--muted); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--btn-primary);
  color: var(--btn-primary-fg);
  border-color: var(--btn-primary);
}
.btn-primary:hover { filter: brightness(0.94); background: var(--btn-primary); }
.btn-accent {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-accent:hover { filter: brightness(1.08); background: var(--accent); }
.btn-sm { padding: 5px 10px; font-size: 11.5px; border-radius: 7px; }
.btn-lg { padding: 12px 20px; font-size: 14px; font-weight: 700; }

/* Presets */
.chip-btn {
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-size: 11.5px;
  cursor: pointer;
  transition: all 0.13s;
}
.chip-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Pipeline Stepper */
.pipeline-steps {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}
.step-box {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  position: relative;
}
.step-box.running { border-color: var(--accent); background: var(--accent-soft); }
.step-box.done { border-color: var(--good); }
.step-box.warn { border-color: var(--warn); }
.step-num { font-size: 10.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.step-title { font-size: 13px; font-weight: 700; color: var(--text-strong); margin: 3px 0; }
.step-detail { font-size: 11px; color: var(--muted); }

/* QA Checklist */
.qa-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.qa-item {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 10px 11px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--input-bg);
}
.qa-item.pass { border-left: 3px solid var(--good); }
.qa-item.fail { border-left: 3px solid var(--danger); }
.qa-icon { font-size: 13px; line-height: 1.2; flex-shrink: 0; margin-top: 1px; }
.qa-name { font-size: 12px; font-weight: 700; color: var(--text-strong); }
.qa-detail { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* Frame Contact Sheet (Second-Agent Visual Reviewer) */
.contact-sheet {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}
.contact-frame {
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow: hidden;
  background: #0d0d10;
  position: relative;
}
.contact-frame.flagged { border-color: var(--danger); box-shadow: 0 0 0 2px var(--danger-soft); }
.contact-frame img { width: 100%; display: block; aspect-ratio: 16/9; object-fit: cover; }
.contact-meta {
  padding: 5px 7px;
  font-size: 10.5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card);
  color: var(--muted);
}

/* Browser Review Workspace (petergyang/video-explainer review_page.py parity) */
.review-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 365px;
  gap: 16px;
  align-items: start;
}
.player-frame {
  position: relative;
  width: 100%;
  background: #09090b;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  margin: 0 auto;
}
.player-frame.aspect-16-9 { aspect-ratio: 16 / 9; max-height: 62vh; }
.player-frame.aspect-9-16 { aspect-ratio: 9 / 16; max-height: 64vh; max-width: 370px; }
.player-frame.aspect-1-1 { aspect-ratio: 1 / 1; max-height: 62vh; max-width: 560px; }
.player-frame canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: pointer;
}
.player-overlay-cta {
  position: absolute;
  right: 18px;
  top: 18px;
  z-index: 6;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  gap: 6px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}
.player-overlay-cta.visible { display: inline-flex; }
.spatial-pin {
  position: absolute;
  width: 22px;
  height: 22px;
  margin-left: -11px;
  margin-top: -11px;
  border-radius: 50%;
  background: var(--pin);
  color: #141310;
  font-size: 10px;
  font-weight: 800;
  display: grid;
  place-items: center;
  border: 2px solid #fff;
  pointer-events: none;
  z-index: 5;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.timeline-bar {
  position: relative;
  height: 32px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--band);
  cursor: pointer;
  user-select: none;
  border: 1px solid var(--border);
}
.scene-band {
  position: absolute;
  top: 0;
  bottom: 0;
  background: var(--band);
  border-right: 1px solid var(--bg);
  font: 10.5px ui-monospace, monospace;
  color: var(--muted);
  padding: 8px 0 0 6px;
  overflow: hidden;
  white-space: nowrap;
}
.scene-band:nth-child(even) { background: var(--band-alt); }
.scene-band.cur { background: var(--band-cur); color: var(--text-strong); font-weight: 700; }
.playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2.5px;
  margin-left: -1px;
  background: var(--text-strong);
  z-index: 4;
  pointer-events: none;
}
.timeline-pin {
  position: absolute;
  top: 3px;
  width: 9px;
  height: 9px;
  margin-left: -4.5px;
  border-radius: 50%;
  background: var(--pin);
  border: 1.5px solid #141310;
  z-index: 5;
  cursor: pointer;
}
.timeline-pin:hover { transform: scale(1.35); }

.review-rail {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  max-height: 78vh;
  overflow: hidden;
}
.review-rail-body { padding: 14px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 10px; }
.review-rail-foot { padding: 12px 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.comment-card {
  padding: 10px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--card);
  cursor: pointer;
}
.comment-card.active-near { border-color: var(--pin); }
.comment-thumb {
  width: 72px;
  aspect-ratio: 16/9;
  border-radius: 5px;
  object-fit: cover;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

/* Video Library Grid */
.video-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.14s, border-color 0.14s;
}
.video-card:hover { transform: translateY(-2px); border-color: var(--border-strong); }
.video-card-preview {
  position: relative;
  aspect-ratio: 16/9;
  background: #0b0b0e;
  cursor: pointer;
  overflow: hidden;
}
.video-card-preview canvas { width: 100%; height: 100%; display: block; }
.video-card-play {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.28);
  opacity: 0;
  transition: opacity 0.15s;
}
.video-card-preview:hover .video-card-play { opacity: 1; }
.play-circle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: #111;
  display: grid;
  place-items: center;
  font-size: 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.video-card-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }

/* Code Blocks */
.code-block {
  position: relative;
  background: #0d0e11;
  color: #e2e8f0;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 12px 14px;
  font: 12px/1.55 "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Avatars & Templates */
.avatar-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 10px; }
.avatar-card {
  padding: 11px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--input-bg);
  cursor: pointer;
  text-align: center;
  transition: all 0.14s;
}
.avatar-card.selected { border-color: var(--accent); background: var(--accent-soft); }
.avatar-circle {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  margin: 0 auto 7px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 18px;
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.25);
  overflow: hidden;
}
.avatar-circle img { width: 100%; height: 100%; object-fit: cover; }

/* Table */
.scene-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.scene-table th, .scene-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.scene-table th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }

/* Embed Preview Box */
.embed-preview-shell {
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  background: #09090b;
}
.embed-preview-shell iframe {
  width: 100%;
  height: 410px;
  border: 0;
  display: block;
}

/* Toast */
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 100;
  padding: 11px 16px;
  border-radius: 10px;
  background: var(--text-strong);
  color: var(--bg);
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: all 0.2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* Responsive */
@media (max-width: 1080px) {
  .grid-2, .review-shell, .grid-equal { grid-template-columns: 1fr; }
  .pipeline-steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .qa-list { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .style-cards, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; padding: 10px 14px; }
  .status-pill { display: none; }
}
