:root {
  color-scheme: dark;
  --bg: #101211;
  --panel: #171a1a;
  --line: #303635;
  --line-strong: #515b58;
  --text: #f3f6f2;
  --muted: #a1aaa4;
  --soft: #d5ddd7;
  --accent: #40d7b5;
  --accent-2: #ffbc5f;
  --danger: #ff6f61;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button,
select,
input[type="text"],
input[type="number"],
textarea {
  border: 1px solid var(--line);
  background: #121615;
  color: var(--text);
}

button {
  cursor: pointer;
}

button:disabled,
a.is-disabled {
  cursor: not-allowed;
  opacity: 0.48;
  pointer-events: none;
}

.app-shell {
  display: grid;
  grid-template-rows: 72px minmax(0, 1fr);
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  min-width: 960px;
}

body.is-embedded .topbar {
  display: none;
}

body.is-embedded .timeline {
  display: none;
}

body.is-embedded .standalone-export-group {
  display: none;
}

body.is-embedded .app-shell {
  grid-template-rows: minmax(0, 1fr);
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 18px 14px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(16, 18, 17, 0.96);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid #63706d;
  border-radius: 8px;
  background: #151b1a;
  color: var(--accent);
  font-size: 13px;
  font-weight: 850;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
  letter-spacing: 0;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.suite-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101414;
}

.icon-button,
.primary-button,
.secondary-link,
.download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-decoration: none;
}

.icon-button {
  width: 40px;
  padding: 0;
}

.icon-button svg {
  width: 19px;
  height: 19px;
  fill: currentColor;
}

.primary-button {
  padding: 0 18px;
  border-color: rgba(64, 215, 181, 0.55);
  background: #15362f;
  color: #eafff8;
  font-weight: 800;
}

.primary-button.is-recording {
  border-color: rgba(255, 111, 97, 0.7);
  background: #3a1b1a;
  color: #ffe4df;
}

.file-picker-input {
  position: fixed;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.secondary-link,
.download-link {
  padding: 0 14px;
  background: #121615;
  color: var(--soft);
  font-weight: 700;
}

.suite-tabs .secondary-link {
  min-height: 30px;
  padding: 0 10px;
  border-color: transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.suite-tabs .secondary-link.is-active {
  border-color: rgba(64, 215, 181, 0.48);
  background: #16302d;
  color: #dcfff7;
}

.download-link:not(.is-disabled) {
  border-color: rgba(255, 188, 95, 0.58);
  color: #ffe1ad;
}

button:hover,
.secondary-link:hover,
.download-link:hover {
  border-color: var(--line-strong);
  background: #1d2220;
}

.workspace {
  display: grid;
  grid-template-columns: 304px minmax(420px, 1fr) 304px;
  min-height: 0;
}

.panel {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  background: var(--panel);
}

.panel-left {
  border-right: 1px solid var(--line);
}

.panel-right {
  border-left: 1px solid var(--line);
}

.batch-picker {
  display: grid;
  grid-template-columns: 1fr;
  gap: 5px;
  width: 100%;
  margin-top: 10px;
  padding: 12px;
  border: 1px dashed #596360;
  border-radius: 8px;
  background: #121615;
  color: var(--soft);
  cursor: pointer;
  text-align: left;
}

.batch-picker span {
  font-size: 13px;
  font-weight: 800;
}

.batch-picker small {
  color: var(--muted);
  font-size: 12px;
}

.control-group {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.group-header h2 {
  margin: 0;
  color: var(--soft);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.control-group.is-collapsible .group-header {
  cursor: pointer;
  margin-bottom: 0;
}

.control-group.is-collapsible:not(.is-collapsed) .group-header {
  margin-bottom: 14px;
}

.control-group.is-collapsed > :not(.group-header) {
  display: none !important;
}

.accordion-toggle {
  width: 28px;
  min-height: 28px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #121615;
  color: var(--soft);
  font-size: 17px;
  font-weight: 850;
  line-height: 1;
}

.group-header span {
  color: var(--muted);
  font-size: 12px;
}

.drop-zone {
  display: grid;
  grid-template-columns: 40px 1fr;
  grid-template-rows: auto auto;
  gap: 4px 12px;
  align-items: center;
  min-height: 92px;
  padding: 14px;
  border: 1px dashed #5a6764;
  border-radius: 8px;
  background: #121615;
  cursor: pointer;
}

.drop-zone.compact {
  min-height: 76px;
}

.drop-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.drop-symbol {
  display: grid;
  grid-row: 1 / span 2;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--accent);
  background: #19201f;
}

.drop-symbol svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.drop-zone strong {
  font-size: 14px;
}

.drop-zone small {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field,
.slider-field,
.color-field {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.field span,
.slider-field span,
.color-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 38px;
  border-radius: 8px;
  padding: 0 10px;
}

.field textarea {
  min-height: 96px;
  padding: 10px;
  resize: vertical;
  line-height: 1.35;
}

.field.two-up {
  display: inline-grid;
  width: calc(50% - 5px);
  margin-right: 6px;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.secondary-button,
.full-button {
  min-height: 38px;
  border-radius: 8px;
  color: var(--soft);
  font-weight: 750;
}

.full-button {
  width: 100%;
  margin-top: 8px;
}

.layer-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.layer-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 8px;
  width: 100%;
  min-height: 48px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111514;
  color: var(--soft);
  text-align: left;
}

.layer-item.is-active {
  border-color: rgba(64, 215, 181, 0.68);
  background: #15362f;
}

.layer-item strong {
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-item span {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.slider-field {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.slider-field input {
  grid-column: 1 / span 2;
  width: 100%;
  accent-color: var(--accent);
}

.slider-field output {
  color: var(--soft);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.color-field input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #121615;
}

.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.preset-grid button {
  min-height: 38px;
  border-radius: 8px;
  color: var(--soft);
  font-size: 12px;
  font-weight: 750;
}

.preset-grid button.is-active {
  border-color: rgba(64, 215, 181, 0.68);
  background: #15362f;
  color: #eafff8;
}

.secondary-button.is-active {
  border-color: rgba(64, 215, 181, 0.68);
  background: #15362f;
  color: #eafff8;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 12px;
  color: var(--soft);
  font-size: 12px;
  font-weight: 750;
}

.switch-row input {
  accent-color: var(--accent);
}

.compact-switch {
  min-height: 38px;
  margin-top: 0;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #121615;
}

.stage-area {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) 76px;
  min-width: 0;
  min-height: 0;
  background: #0b0d0c;
}

body.is-embedded .stage-area {
  grid-template-rows: minmax(0, 1fr);
}

#stageCanvas {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: block;
  object-fit: contain;
  object-position: center;
  cursor: crosshair;
  touch-action: none;
}

.stage-hud {
  position: absolute;
  top: 14px;
  left: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  pointer-events: none;
}

.stage-hud span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 999px;
  background: rgba(10, 12, 11, 0.72);
  color: var(--soft);
  font-size: 12px;
  font-weight: 750;
}

.timeline {
  position: relative;
  display: grid;
  grid-template-columns: 72px 46px minmax(0, 1fr) 46px;
  align-items: start;
  gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: #101311;
}

.timeline-stack {
  display: grid;
  grid-template-rows: 24px 26px;
  gap: 5px;
  min-width: 0;
}

.timeline-markers {
  position: relative;
  height: 26px;
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 7px;
  background: rgba(4, 6, 6, 0.34);
  overflow: hidden;
}

.timeline-marker {
  position: absolute;
  top: 4px;
  height: 18px;
  min-width: 18px;
  padding: 0 7px;
  border: 1px solid rgba(64, 215, 181, 0.44);
  border-radius: 6px;
  background: rgba(64, 215, 181, 0.42);
  color: #eafff8;
  font-size: 10px;
  font-weight: 850;
  line-height: 16px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.timeline-marker::before,
.timeline-marker::after {
  content: "";
  position: absolute;
  top: 3px;
  width: 2px;
  height: 12px;
  border-radius: 999px;
  background: rgba(234, 255, 248, 0.76);
  opacity: 0;
}

.timeline-marker::before {
  left: 4px;
}

.timeline-marker::after {
  right: 4px;
}

.timeline-marker:hover::before,
.timeline-marker:hover::after,
.timeline-marker.is-active::before,
.timeline-marker.is-active::after {
  opacity: 1;
}

.timeline-marker.is-active {
  border-color: rgba(255, 188, 95, 0.82);
  background: var(--accent-2);
  color: #17110b;
}

.timeline-marker.is-stack-moving {
  box-shadow: 0 0 0 2px rgba(255, 188, 95, 0.28), 0 6px 0 rgba(255, 188, 95, 0.18);
}

.timeline-marker.is-stack-moving::after {
  content: attr(data-stack-count);
  top: -9px;
  right: -7px;
  display: grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border-radius: 999px;
  background: #101311;
  color: var(--accent-2);
  font-size: 10px;
  line-height: 17px;
  opacity: 1;
}

.is-draggable-number {
  cursor: ns-resize;
}

.timeline-button {
  min-height: 32px;
  border-radius: 8px;
  color: var(--soft);
}

.timeline span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.timeline input {
  width: 100%;
  accent-color: var(--accent);
}

.batch-status {
  min-height: 34px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.progress {
  height: 4px;
  margin-top: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #0d100f;
}

.progress span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

#sourceVideo {
  display: none;
}

@media (max-width: 1050px) {
  body {
    overflow: auto;
    overflow-x: hidden;
    min-height: 100dvh;
  }

  .app-shell {
    min-width: 0;
    min-height: 100dvh;
    height: auto;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .topbar {
    position: sticky;
    top: max(env(safe-area-inset-top, 0px), 0px);
    z-index: 6;
    flex-wrap: wrap;
    width: 100%;
    max-width: 100vw;
    min-width: 0;
    gap: 10px;
    padding: 12px;
  }

  .brand {
    flex: 1 1 180px;
  }

  .brand p {
    max-width: 68vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .top-actions {
    flex: 1 1 100%;
    min-width: 0;
    max-width: 100%;
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .top-actions::-webkit-scrollbar {
    display: none;
  }

  .suite-tabs {
    flex: 0 0 auto;
  }

  .workspace {
    grid-template-columns: 1fr;
    width: 100%;
    max-width: 100vw;
    min-width: 0;
  }

  .panel {
    width: 100%;
    max-width: 100vw;
    min-height: 0;
    min-width: 0;
    overflow: visible;
    border-right: 0;
    border-left: 0;
  }

  .stage-area {
    width: 100%;
    max-width: 100vw;
    height: min(58vh, 500px);
    min-height: 320px;
    min-width: 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
  }

  .field.two-up {
    display: grid;
    width: 100%;
    margin-right: 0;
  }
}

@media (max-width: 560px) {
  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .brand h1 {
    font-size: 16px;
  }

  .button-row {
    grid-template-columns: 1fr;
  }

  .stage-area {
    height: 50vh;
    min-height: 300px;
  }

  .timeline {
    grid-template-columns: 58px 40px minmax(0, 1fr) 40px;
    gap: 8px;
    padding: 8px 10px;
  }
}
