:root {
  --bg-desk: #0D0F12;
  --bg-panel: #15181E;
  --bg-well: #090B0E;
  --ink-primary: #F2F0EA;
  --ink-muted: #9AA1AE;
  --signal-amber: #F59E0B;
  --signal-vermilion: #D93829;
  --signal-mint: #34D399;
  --border-hairline: #272C36;
  --border-strong: #39404E;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-desk);
  color: var(--ink-primary);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

button, input, textarea {
  font: inherit;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 2px solid var(--signal-amber);
  outline-offset: 2px;
}

/* Top Broadcast Bar */
.topbar {
  min-height: 62px;
  padding: 10px 18px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

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

.brand-mark {
  display: block;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.02em;
  color: var(--ink-primary);
}

.brand-sub {
  font-size: 11px;
  color: var(--ink-muted);
}

.reel-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: thin;
  padding: 2px 0;
  min-width: 0;
}

.reel-tab {
  appearance: none;
  background: var(--bg-well);
  color: var(--ink-muted);
  border: 1px solid var(--border-hairline);
  border-radius: 7px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.reel-tab:hover {
  color: var(--ink-primary);
  border-color: var(--border-strong);
}

.reel-tab.is-active {
  background: var(--ink-primary);
  color: var(--bg-desk);
  border-color: var(--ink-primary);
}

.topbar-actions {
  flex-shrink: 0;
}

.btn-buy {
  appearance: none;
  background: var(--signal-vermilion);
  color: #FFFFFF;
  border: 1px solid #F05A4C;
  border-radius: 7px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.btn-buy:hover {
  background: #C42E20;
}

/* Main Studio Workspace */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  height: calc(100vh - 62px);
  min-height: 580px;
}

.stage-column {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg-well);
  border-right: 1px solid var(--border-hairline);
}

.stage-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-hairline);
}

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

.tally-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ink-muted);
  flex-shrink: 0;
}

.tally-dot.is-playing {
  background: var(--signal-amber);
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.7);
}

.active-reel-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.015em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.spec-badge {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-muted);
  background: var(--bg-well);
  border: 1px solid var(--border-hairline);
  border-radius: 5px;
  padding: 3px 8px;
  white-space: nowrap;
}

.aspect-group {
  display: inline-flex;
  background: var(--bg-well);
  border: 1px solid var(--border-hairline);
  border-radius: 7px;
  padding: 2px;
  flex-shrink: 0;
}

.aspect-btn {
  appearance: none;
  background: transparent;
  color: var(--ink-muted);
  border: 0;
  border-radius: 5px;
  padding: 5px 12px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.aspect-btn.is-active {
  background: var(--signal-amber);
  color: #0D0F12;
}

.stage-well {
  flex: 1;
  min-height: 0;
  padding: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, #141821 0%, #07090C 100%);
  overflow: hidden;
}

.stage-frame {
  position: relative;
  width: min(100%, calc((100vh - 280px) * 16 / 9));
  aspect-ratio: 16 / 9;
  background: #000000;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 22px 54px rgba(0, 0, 0, 0.55);
}

.stage-frame.is-9x16 {
  width: auto;
  height: min(100%, calc(100vh - 260px));
  max-width: 100%;
  aspect-ratio: 9 / 16;
}

.stage-frame iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

/* Transport & Timeline Scrubber */
.transport-dock {
  background: var(--bg-panel);
  border-top: 1px solid var(--border-hairline);
  padding: 12px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.transport-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.transport-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ctrl-btn {
  appearance: none;
  background: var(--bg-well);
  color: var(--ink-primary);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.ctrl-btn:hover {
  border-color: var(--ink-muted);
}

.ctrl-btn.primary {
  background: var(--signal-amber);
  color: #0D0F12;
  border-color: var(--signal-amber);
  font-weight: 700;
}

.ctrl-btn.primary:hover {
  background: #FBBF24;
}

.timecode-readout {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-primary);
  background: var(--bg-well);
  border: 1px solid var(--border-hairline);
  border-radius: 6px;
  padding: 6px 11px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tc-sep { color: var(--ink-muted); }
.tc-fps { color: var(--signal-amber); margin-left: 6px; font-weight: 700; }

.scrubber-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#timelineSlider {
  width: 100%;
  accent-color: var(--signal-amber);
  cursor: pointer;
  margin: 0;
}

.shot-ticks {
  display: flex;
  justify-content: space-between;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 11px;
  color: var(--ink-muted);
}

/* Inspector Sidebar */
.inspector-column {
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
}

.inspector-section {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-hairline);
}

.editor-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-bottom: 0;
  min-height: 280px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.editor-section .section-head {
  margin-bottom: 0;
}

.section-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-primary);
}

.section-hint {
  font-size: 12px;
  color: var(--ink-muted);
}

.json-status {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 11px;
  color: var(--signal-mint);
}

.json-status.is-error {
  color: #FCA5A5;
}

.shot-pills {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.shot-pill {
  appearance: none;
  background: var(--bg-well);
  color: var(--ink-primary);
  border: 1px solid var(--border-hairline);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.shot-pill:hover {
  border-color: var(--border-strong);
}

.shot-pill.is-active {
  border-color: var(--signal-amber);
  background: rgba(245, 158, 11, 0.12);
}

.shot-pill-time {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 11px;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

.json-editor {
  flex: 1;
  width: 100%;
  min-height: 210px;
  resize: vertical;
  background: var(--bg-well);
  color: #E2E8F0;
  border: 1px solid var(--border-hairline);
  border-radius: 7px;
  padding: 12px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
}

.editor-actions {
  display: flex;
  gap: 8px;
}

.editor-actions .ctrl-btn {
  flex: 1;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 10, 0.78);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 100;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-dialog {
  width: min(760px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: 0 28px 72px rgba(0, 0, 0, 0.7);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-hairline);
}

.modal-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.modal-subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--ink-muted);
}

.modal-close {
  appearance: none;
  background: var(--bg-well);
  color: var(--ink-primary);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}

.modal-body {
  padding: 20px 22px;
}

.modal-grid {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: 16px;
}

.modal-card {
  background: var(--bg-well);
  border: 1px solid var(--border-hairline);
  border-radius: 8px;
  padding: 16px;
}

.modal-card h3 {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--signal-amber);
}

.bundle-list {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.55;
  color: #D7DCE5;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cli-block {
  background: #05070A;
  border: 1px solid var(--border-hairline);
  border-radius: 6px;
  padding: 12px;
  overflow-x: auto;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 12px;
  color: var(--signal-mint);
  margin: 0 0 12px;
}

.modal-note {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-muted);
}

.modal-footer {
  padding: 16px 22px;
  border-top: 1px solid var(--border-hairline);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.price-tag {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-primary);
}

.modal-footer-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.modal-link {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

/* Responsive Mobile Layout (e.g. 390x844) */
@media (max-width: 1023px) {
  .topbar {
    flex-wrap: wrap;
    padding: 10px 14px;
    gap: 10px;
  }

  .brand {
    flex: 1 1 auto;
  }

  .topbar-actions {
    width: 100%;
    order: 2;
  }

  .btn-buy {
    width: 100%;
    text-align: center;
  }

  .reel-tabs {
    width: 100%;
    order: 3;
  }

  .workspace {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
  }

  .stage-column {
    border-right: 0;
    border-bottom: 1px solid var(--border-hairline);
  }

  .stage-toolbar {
    padding: 10px 14px;
  }

  .stage-well {
    padding: 12px;
    min-height: 220px;
  }

  .stage-frame {
    width: 100%;
    height: auto;
    max-height: 55vh;
  }

  .stage-frame.is-9x16 {
    height: 54vh;
    width: auto;
    max-width: 100%;
  }

  .transport-dock {
    padding: 12px 14px;
  }

  .inspector-column {
    overflow: visible;
  }

  .modal-grid {
    grid-template-columns: 1fr;
  }
}
