: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,
textarea {
  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 .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,
.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.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;
}

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

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

.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;
}

.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;
}

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

.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); }

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

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

.group-header h2 {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

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

.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,
label span {
  color: var(--muted);
  font-size: 12px;
}

.field,
.color-field,
.slider-field {
  display: grid;
  gap: 7px;
}

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

.field textarea {
  resize: vertical;
  line-height: 1.25;
}

.color-field {
  grid-template-columns: 1fr 54px;
  align-items: center;
}

.color-field input {
  width: 54px;
  height: 34px;
  padding: 2px;
  border-radius: 8px;
}

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

.slider-field span,
.slider-field input {
  grid-column: 1;
}

.slider-field output {
  grid-row: 1 / span 2;
  grid-column: 2;
  color: var(--soft);
  font-size: 12px;
  text-align: right;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.segmented,
.preset-grid {
  display: grid;
  gap: 6px;
}

.segmented {
  grid-template-columns: repeat(2, 1fr);
}

.preset-grid {
  grid-template-columns: repeat(2, 1fr);
}

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

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

.section-switches {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.section-switch {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  padding: 7px 44px 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #121615;
  color: var(--soft);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.section-switch::after {
  content: "";
  position: absolute;
  right: 10px;
  width: 28px;
  height: 16px;
  border-radius: 999px;
  background: #303635;
}

.section-switch::before {
  content: "";
  position: absolute;
  right: 24px;
  z-index: 1;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #a1aaa4;
  transition: right 140ms ease, background 140ms ease;
}

.section-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.section-switch.is-active {
  border-color: rgba(64, 215, 181, 0.72);
  color: var(--text);
  background: #161c1b;
}

.section-switch.is-active::after {
  background: #15362f;
}

.section-switch.is-active::before {
  right: 12px;
  background: var(--accent);
}

.timeline-summary {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.drop-zone {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 11px;
  align-items: center;
  min-height: 92px;
  padding: 14px;
  border: 1px dashed #596360;
  border-radius: 8px;
  background: #121615;
  cursor: pointer;
}

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

.drop-zone input {
  display: none;
}

.drop-symbol {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--accent);
}

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

.drop-zone strong,
.drop-zone small {
  grid-column: 2;
}

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

.drop-zone small {
  align-self: start;
  color: var(--muted);
  font-size: 12px;
}

.audio-zone,
.video-zone {
  border-style: solid;
}

.stage-area {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) 52px;
  place-items: center;
  min-width: 0;
  min-height: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0)),
    #0b0d0d;
}

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

#stageCanvas {
  min-width: 0;
  min-height: 0;
  display: block;
  background: #101211;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.3);
  cursor: grab;
  touch-action: none;
}

#stageCanvas:active {
  cursor: grabbing;
}

.stage-hud {
  position: absolute;
  top: 14px;
  left: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: calc(100% - 28px);
}

.stage-hud span {
  min-height: 28px;
  padding: 6px 9px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(8, 10, 10, 0.74);
  color: #dbe3df;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(8px);
}

.timeline {
  display: grid;
  grid-template-columns: auto 48px minmax(120px, 1fr) 48px;
  grid-template-rows: auto 18px;
  align-items: center;
  gap: 10px;
  padding: 8px 16px 12px;
  border-top: 1px solid var(--line);
  background: #101313;
}

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

#scrubSlider {
  width: 100%;
}

.wrapflow-timeline-bars {
  position: relative;
  grid-column: 3;
  grid-row: 2;
  height: 18px;
  min-width: 0;
}

.wrapflow-timeline-segment {
  position: absolute;
  top: 4px;
  height: 10px;
  min-width: 4px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  color: rgba(247, 255, 249, 0.88);
  font-size: 8px;
  font-weight: 850;
  line-height: 8px;
  text-align: center;
  white-space: nowrap;
}

.wrapflow-timeline-segment.is-intro {
  background: rgba(64, 215, 181, 0.42);
}

.wrapflow-timeline-segment.is-video {
  background: rgba(255, 255, 255, 0.12);
}

.wrapflow-timeline-segment.is-ending {
  background: rgba(255, 188, 95, 0.44);
}

.wrapflow-timeline-segment.is-transition {
  background: rgba(121, 215, 255, 0.26);
}

.wrapflow-duration-marker {
  position: absolute;
  top: 1px;
  width: 12px;
  height: 16px;
  padding: 0;
  border: 1px solid rgba(247, 255, 249, 0.78);
  border-radius: 4px;
  background: var(--panel);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.34);
  cursor: ew-resize;
  transform: translateX(-50%);
}

.wrapflow-duration-marker::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 3px;
  width: 2px;
  height: 8px;
  background: var(--accent);
  transform: translateX(-50%);
}

@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;
    min-width: 0;
  }

  .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);
  }
}

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

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

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

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

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

  .wrapflow-timeline-bars {
    grid-column: 1 / -1;
  }
}
