* {
  box-sizing: border-box
}

html,
body {
  height: 100%
}

:root {
  --bg: #fbfbfc;
  --line: #e5e6eb;
  --text: #171922;
  --muted: #7d8290;
  --purple: #6048f5;
  --teal: #0d9488
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "DM Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden
}

.header {
  width: 100%;
  height: 64px;
  flex-shrink: 0;
  margin: 0 auto 20px;
  padding: 0 22px;
  background: #fff;
  border: 1px solid #e8e8ed;
  border-top: none;
  border-radius: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 3px 18px rgba(30, 30, 60, .035)
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 22px
}

.brand img {
  width: 44px;
  height: 44px;
  color: var(--purple)
}

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

.button,
.settings {
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font: inherit;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 14px;
  cursor: pointer
}

.button img,
.settings img {
  width: 18px;
  height: 18px
}

.primary {
  background: var(--purple);
  border-color: var(--purple);
  color: #fff
}

.primary img {
  filter: brightness(0) invert(1)
}

.settings {
  width: 36px;
  padding: 0;
  justify-content: center
}

.page {
  max-width: 1540px;
  width: 100%;
  margin: auto;
  padding: 0 14px 14px;
  display: grid;
  grid-template-columns: 145px minmax(760px, 1180px) 145px;
  grid-template-rows: 1fr;
  gap: 20px;
  flex: 1;
  min-height: 0
}

.editor {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%
}

.ad {
  height: 600px;
  max-height: 100%;
  overflow: hidden;
  border: 1px dashed #d9dce5;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #8e94a3;
  font-size: 18px;
  line-height: 1.8
}

.ad small {
  font-size: 15px
}

.columns {
  display: grid;
  grid-template-columns: 180px minmax(450px, 1fr) 320px;
  grid-template-rows: 1fr;
  gap: 10px;
  align-items: stretch;
  flex: 1;
  min-height: 0
}

.center {
  min-height: 0;
  display: flex;
  flex-direction: column
}

.panel,
.preview-card {
  background: #fff;
  border: 1px solid #e6e7ec;
  border-radius: 14px;
  box-shadow: 0 3px 16px rgba(25, 25, 50, .025)
}

.panel {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  justify-content: flex-start;
  align-self: flex-start;
  overflow-y: auto;
  overflow-x: hidden;
  max-height: 100%
}

.panel>* {
  flex-shrink: 0
}

.preview-card {
  display: flex;
  flex-direction: column;
  flex: 0 1 auto;
  max-height: 100%;
  min-height: 0
}

.preview-card:has(.workspace--grid) {
  flex: 1 1 auto
}

.panel h2 {
  font-size: 18px;
  margin: 0
}

.tool {
  width: 100%;
  height: 88px;
  border: 1px solid #ececf1;
  border-radius: 11px;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  font: inherit;
  color: var(--text);
  cursor: pointer
}

.tool:hover {
  background: #faf9ff;
  border-color: #ddd9ff
}

.tool img {
  width: 28px;
  height: 28px
}

.tool span {
  font-size: 14px;
  text-align: center;
  line-height: 1.2
}

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  background: #111;
  overflow: hidden;
  border-radius: 12px 12px 0 0
}

.poster,
.stage video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain
}

.stage video {
  display: none
}

.empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  background: rgba(20, 20, 25, .12);
  color: #fff
}

.empty button {
  border: 0;
  border-radius: 9px;
  padding: 11px 17px;
  background: #fff;
  color: #222;
  font-weight: 650;
  cursor: pointer
}

.empty span {
  font-size: 14px
}

.controls {
  height: 72px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0
}

.player,
.ratio {
  height: 42px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  display: grid;
  place-items: center;
  cursor: pointer
}

.player {
  width: 42px
}

.player img {
  width: 21px;
  height: 21px
}

.player.active {
  background: #f2efff;
  color: var(--purple)
}

.controls span {
  font-size: 13px;
  color: #686d79;
  white-space: nowrap
}

.controls input {
  flex: 1;
  min-width: 70px;
  accent-color: var(--purple)
}

.seek-wrap {
  flex: 1;
  min-width: 70px;
  display: flex;
  flex-direction: column;
  gap: 2px
}

.seek-wrap #seek {
  flex: none;
  width: 100%
}

.seek-labels {
  display: flex;
  justify-content: space-between
}

.ratio {
  padding: 0 12px;
  font: inherit;
  color: #555b68;
  white-space: nowrap
}

.ratio span {
  margin-left: 7px
}

.pause {
  height: 15px;
  width: 12px;
  border-left: 4px solid currentColor;
  border-right: 4px solid currentColor
}

.privacy {
  height: 48px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  color: #8a8e99;
  font-size: 13px
}

.privacy img {
  width: 17px
}

@media(max-width:1250px) {
  .page {
    grid-template-columns: 1fr;
    max-width: 1000px
  }

  .ad {
    display: none
  }

  .columns {
    grid-template-columns: 180px minmax(450px, 1fr) 320px
  }
}

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

  .tool {
    height: 70px;
    padding: 0;
    justify-content: center;
    flex-direction: column;
    gap: 5px
  }
}

@media(max-width:620px) {
  .header {
    height: 62px;
    margin: 10px;
    border-radius: 11px;
    padding: 0 11px
  }

  .brand {
    font-size: 16px
  }

  .brand img {
    width: 23px
  }

  .button.light,
  .primary {
    font-size: 0;
    padding: 0;
    width: 42px;
    justify-content: center
  }

  .settings {
    width: 42px
  }

  .page {
    padding: 0 8px
  }

  .controls {
    height: 62px;
    padding: 0 9px;
    gap: 7px
  }

  .controls span {
    font-size: 11px
  }

  .ratio {
    display: none
  }
}

/* Colored tool icons */
.basic .tool:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 14px rgba(32, 34, 50, .055);
}

.tool {
  transition: border-color .16s ease, background .16s ease, box-shadow .16s ease, transform .16s ease
}

/* Chỉ focus khi click, không focus từ keyboard */
.tool:focus-visible {
  outline: none;
  box-shadow: none !important;
  background-color: #fff !important;
  border-color: #ececf1 !important
}

.tool:focus {
  outline: none;
  box-shadow: none !important;
  background-color: #fff !important;
  border-color: #ececf1 !important
}

/* Canvas preview layer: video stays underneath as data source, canvas is what the user actually sees */
.stage {
  flex-shrink: 0
}

.stage video {
  display: block;
  opacity: 0;
  pointer-events: none
}

.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none
}

.stage.has-video canvas {
  display: block
}

.stage.has-video .poster,
.stage.has-video .empty {
  display: none
}

/* Contain mode: dùng khi đang chỉnh crop (xem toàn khung hình) hoặc đã áp dụng crop (chỉ hiện đúng phần crop, không bị cover cắt thêm) */
.stage--contain canvas {
  object-fit: contain
}

/* Tool active state (button stays highlighted while its panel is open / applied) */
.tool--active {
  background: #f2efff;
  border-color: #ddd9ff;
  color: var(--purple)
}

.tool__label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
}

.tool__label small {
  font-size: 0;
  font-weight: 500;
  color: var(--purple);
  display: none
}

.tool--active .tool__label small:not(:empty) {
  display: block
}

/* Shared workspace: inline tool panels below the player controls, instead of modal dialogs */
.workspace {
  display: none;
  flex: 1;
  min-height: 0;
  overflow-y: auto
}

.workspace.workspace--active {
  display: flex;
  flex-direction: column;
  padding: 16px;
  border-top: 1px solid var(--line)
}

.tool-panel {
  display: none
}

.tool-panel.tool-panel--active {
  display: block
}

.tool-panel__header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px
}

.tool-panel__header strong {
  font-size: 15px
}

.tool-panel__actions {
  margin-left: auto
}

.tool-panel__actions {
  display: flex;
  gap: 8px
}

#panelAddText>textarea {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  font: inherit;
  resize: vertical;
  color: var(--text);
  margin-bottom: 14px
}

#panelAddText>.tool-panel__actions {
  margin-bottom: 6px;
  justify-content: flex-end
}

.btn-ghost,
.btn-primary {
  height: 36px;
  padding: 0 16px;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .16s ease, box-shadow .16s ease, border-color .16s ease
}

.btn-ghost {
  border: 1px solid var(--line);
  background: #fff;
  color: #686d79
}

.btn-ghost:hover {
  background: #faf9ff;
  border-color: #ddd9ff;
  color: var(--text)
}

.btn-primary {
  border: 1px solid var(--line);
  background: var(--exp-accent);
  color: #fff
}

.btn-primary:hover {
  background: var(--exp-accent-hover)
}

.tool-panel__close {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 20px;
  line-height: 1;
  color: #686d79;
  cursor: pointer;
  display: grid;
  place-items: center
}

.tool-panel__close:hover {
  background: #faf9ff;
  border-color: #ddd9ff;
  color: var(--purple)
}

.crop-hint {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 14px
}

/* Add Image: compact import control above the elements grid. */
.media-upload-btn {
  width: fit-content;
  max-width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  margin: 0 auto 16px;
  border-radius: 12px;
  border: 1px solid #dfe1e6;
  background: #fff;
  color: #292b3a;
  cursor: pointer;
  gap: 9px;
  padding: 5px 15px 5px 8px;
  white-space: nowrap;
  box-shadow: 0 2px 7px rgba(30, 32, 40, .06);
  transition: transform .16s ease, background .16s ease, border-color .16s ease,
    box-shadow .16s ease
}

.media-upload-btn__icon {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #eef0f3;
  box-shadow: none;
}

.media-upload-btn__icon img {
  width: 17px;
  height: 17px;
}

.media-upload-btn__label {
  line-height: 1;
}

.media-upload-btn:hover {
  background: #f7f8fa;
  border-color: #c9ccd3;
  box-shadow: 0 4px 10px rgba(30, 32, 40, .09);
  transform: translateY(-1px)
}

.media-upload-btn:focus-visible {
  outline: 3px solid rgba(80, 84, 94, .18);
  outline-offset: 2px
}

/* Crop selection rect drawn on top of the canvas while editing */
.crop-rect {
  position: absolute;
  border: 2px solid var(--purple);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .45);
  cursor: move;
  touch-action: none
}

.crop-rect__handle {
  position: absolute;
  width: 14px;
  height: 14px;
  background: #fff;
  border: 2px solid var(--purple);
  border-radius: 50%;
  touch-action: none
}

.crop-rect__handle[data-corner=tl] {
  left: -7px;
  top: -7px;
  cursor: nwse-resize
}

.crop-rect__handle[data-corner=tr] {
  right: -7px;
  top: -7px;
  cursor: nesw-resize
}

.crop-rect__handle[data-corner=bl] {
  left: -7px;
  bottom: -7px;
  cursor: nesw-resize
}

.crop-rect__handle[data-corner=br] {
  right: -7px;
  bottom: -7px;
  cursor: nwse-resize
}

/* Transform (Rotate & Flip) / Speed chip options */
.transform-group {
  margin-bottom: 14px
}

.transform-group:last-child {
  margin-bottom: 0
}

.transform-group__label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 0px
}

.transform-options {
  display: flex;
  gap: 8px;
  flex-wrap: wrap
}

.transform-chip {
  height: 36px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font: inherit;
  cursor: pointer;
  color: var(--text)
}

.transform-chip:hover {
  border-color: #ddd9ff;
  background: #faf9ff
}

.transform-chip:focus,
.transform-chip:focus-visible {
  outline: none
}

.transform-chip--selected {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff
}

.transform-chip.tool--active {
  background: #f2efff;
  border-color: #ddd9ff;
  color: var(--purple)
}

/* Shape picker (Draw panel): 3 nút mỗi hàng, độ rộng bằng nhau thay vì co theo độ dài chữ */
#drawShapeOptions {
  display: grid;
  grid-template-columns: repeat(3, 1fr)
}

#drawShapeOptions .transform-chip {
  width: 100%;
  padding: 0;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center
}

#drawShapeOptions .transform-chip img {
  width: 20px;
  height: 20px;
  filter: none
}

#drawShapeOptions .transform-chip--selected img {
  filter: brightness(0) invert(1)
}

.draw-transform-row {
  display: flex
}

/* Draw panel Actions row (Undo/Redo/Clear/Move-Resize-Rotate): 4 nút rộng bằng nhau, icon xếp trên nhãn để đủ chỗ
   hiện hết chữ trong panel hẹp (thử hàng ngang icon+chữ bị cắt chữ "Clear" ở panel width thực tế) */
#drawActionsRow {
  display: grid;
  grid-template-columns: repeat(4, 1fr)
}

#drawActionsRow .draw-action-btn {
  width: 100%;
  height: 52px;
  padding: 0 4px;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
  font-weight: 500
}

#drawActionsRow .draw-action-btn img {
  width: 16px;
  height: 16px
}

#drawActionsRow .draw-action-btn:disabled {
  opacity: .4;
  cursor: not-allowed;
  pointer-events: none
}

/* Line style chips (Draw panel Style section): tái dùng .transform-chip nhưng để chữ co theo
   nội dung thay vì rộng bằng nhau như #drawShapeOptions */
#drawLineDashOptions .transform-chip {
  padding: 0 14px;
  height: 32px
}

/* Elements category picker (Emoji/Stickers/GIF/Animation) reuses .text-fx-tabs (see index.html) —
   4 tabs (vs Add Text's 2) need tighter padding/font-size to fit the panel's width without
   overflowing; ellipsis as a safety net for whichever label still doesn't fully fit. */
#elementsCategoryOptions.text-fx-tabs {
  padding: 3px
}

#elementsCategoryOptions .text-fx-tab {
  padding: 8px 4px;
  font-size: 12px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis
}

/* Dual-handle trim range: two overlapping <input type=range>, only their thumbs are interactive */
.trim-range {
  position: relative;
  height: 34px;
  display: flex;
  align-items: center
}

.trim-range__track {
  position: absolute;
  left: 0;
  right: 0;
  height: 4px;
  border-radius: 2px;
  background: var(--line)
}

.trim-range__fill {
  position: absolute;
  height: 4px;
  border-radius: 2px;
  background: var(--purple)
}

.trim-range input[type=range] {
  position: absolute;
  left: 0;
  right: 0;
  width: 100%;
  margin: 0;
  height: 34px;
  background: transparent;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none
}

.trim-range input[type=range]::-webkit-slider-runnable-track {
  background: transparent
}

.trim-range input[type=range]::-moz-range-track {
  background: transparent
}

.trim-range input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  pointer-events: auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--purple);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
  cursor: pointer
}

.trim-range input[type=range]::-moz-range-thumb {
  pointer-events: auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--purple);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
  cursor: pointer
}

.trim-times {
  display: flex;
  justify-content: space-between;
  margin-top: 0px;
  font-size: 12px;
  color: var(--muted)
}

/* Clear separator between the Basic tool buttons and the Video Effects controls/time-range block */
.basic-divider {
  border: none;
  border-top: 1px solid var(--line);
  margin: 0px -20px 0px;
  padding: 0;
  width: calc(100% + 34px)
}

/* Show divider when any panel below it is active (handles both Video Effects and Add Text controls) */
.basic-divider:has(~ .tool-panel.tool-panel--active) {
  display: block
}

/* Show divider in Advanced section (always show since timeline-edits is always present) */
.advanced .basic-divider {
  display: block
}

/* Video Effects: grid chọn filter kèm ảnh mẫu (giống filters-grid của final-ffmpeg-sdk) */
.effects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  align-content: start;
  gap: 8px;
  margin-bottom: 4px;
  padding-right: 2px
}

#texteffectsGrid .effects-grid {
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  container-type: inline-size
}

#texteffectsGridEffects {
  display: none !important;
}

#texteffectsGridEffects.textfx-panel--active {
  display: flex !important;
  flex-wrap: wrap;
  grid-template-columns: unset;
  container-type: unset;
}

.effect-card {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  cursor: pointer;
  color: var(--text);
  text-align: center;
  min-width: 0
}

.effect-card__thumb {
  display: block;
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 8px;
  background: #eee;
  border: 2px solid transparent;
  box-sizing: border-box
}

.effect-card__canvas {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover
}

.effect-card:hover .effect-card__thumb {
  border-color: #ddd9ff
}

.effect-card--selected .effect-card__thumb {
  border-color: var(--purple);
  box-shadow: 0 0 0 2px rgba(96, 72, 245, .25)
}

.effect-card__label {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis
}

.effect-card__thumb--emoji {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  background: #f4f4f7
}

/* Add Sound panel: category tabs (nhiều tab hơn Emoji/Stickers/GIF nên cho scroll ngang thay vì
   chia đều/wrap như .text-fx-tabs) + grid card (label dưới, nút Play giữa, nút + góc trên-phải). */
.sound-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
  padding-bottom: 4px
}

.sound-tab {
  flex: 0 0 auto;
  padding: 8px;
  border: none;
  border-radius: 8px;
  background: #f5f5f7;
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  cursor: pointer
}

.sound-tab--active {
  color: #fff;
  background: linear-gradient(90deg, rgb(42, 123, 155) 0%, rgb(87, 199, 133) 100%);
  font-weight: 600
}

.sound-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
  padding-right: 2px
}

.sound-card {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  background: #f4f4f7;
  border: 1px solid var(--line);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 6px 4px;
  box-sizing: border-box
}

.sound-card--selected {
  border-color: var(--purple);
  box-shadow: 0 0 0 2px rgba(96, 72, 245, .25)
}

.sound-card__add {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: var(--purple);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0
}

.sound-card__add:hover {
  background: #4c37d1
}

.sound-card__play {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: #fff;
  color: var(--purple);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .2);
  padding: 0
}

.sound-card__play--playing {
  background: var(--purple);
  color: #fff
}

.sound-card__label {
  font-size: 11px;
  color: var(--text);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%
}

.effect-controls {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1.5px solid var(--purple);
  border-radius: 10px;
  max-height: 180px;
  overflow-y: auto
}

/* Audio Effects: preset đọc-only (không có tham số số học để chỉnh, khác Video Effects) */
.audio-effect-info {
  padding: 12px 14px;
  border: 1.5px solid var(--purple);
  border-radius: 10px
}

.audio-effect-info__name {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 4px
}

.audio-effect-info__desc {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 10px
}

.audio-effect-info__params {
  display: flex;
  flex-wrap: wrap;
  gap: 6px
}

.audio-effect-param-chip {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 10px;
  background: #f2efff;
  color: var(--purple);
  font-weight: 600
}

.control-group {
  margin-bottom: 10px
}

.control-group:last-child {
  margin-bottom: 0
}

.control-group label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px
}

.control-value {
  color: var(--teal);
  font-weight: 600
}

.control-group input[type=range] {
  width: 100%
}

.control-group textarea {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  font: inherit;
  resize: vertical;
  color: var(--text)
}

.draw-color-row {
  display: flex;
  align-items: center;
  justify-content: space-between
}

.draw-color-row label {
  margin-bottom: 0;
  display: flex;
  align-items: center;
  gap: 6px
}

.control-group input[type=color]:not(.color-swatch) {
  width: 36px;
  height: 28px;
  border: none;
  border-radius: 6px;
  padding: 0;
  cursor: pointer;
  background: none
}

.control-group input[type=color]:disabled {
  opacity: .4;
  cursor: not-allowed
}

/* Add Text panel: labeled sections + toggle-collapsible sub-controls (Background/Shadow/Border) */
.control-section {
  margin-bottom: 10px
}

.control-section:last-of-type {
  margin-bottom: 0
}

/* Background/Shadow/Border: boxed card look (matches new Add Text design reference) */
.control-section--card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #00000000
}

.control-section--card .control-group:last-child {
  margin-bottom: 0
}

/* Color swatch + editable hex code, used by Text/Background/Shadow/Border color rows */
.color-hex-group {
  display: flex;
  align-items: center;
  gap: 8px
}

.color-hex-input {
  width: 90px;
  box-sizing: border-box;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
  font-size: 12px;
  color: var(--text);
  text-transform: uppercase;
  background: #fff
}

.color-hex-input:disabled {
  opacity: .5;
  cursor: not-allowed;
  background: #f2f2f5
}

/* Editable numeric box paired with a range slider (Font Size, Corner Radius, Blur, Thickness, Opacity) */
.control-num-input {
  width: 52px;
  flex-shrink: 0;
  box-sizing: border-box;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 6px;
  font: inherit;
  font-size: 12px;
  color: var(--text);
  text-align: center
}

.control-num-input::-webkit-outer-spin-button,
.control-num-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0
}

.control-num-input:disabled {
  opacity: .5;
  cursor: not-allowed;
  background: #f2f2f5
}

.control-unit {
  font-size: 12px;
  color: var(--muted);
  flex-shrink: 0
}

.control-section__title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: .02em;
  margin-bottom: 4px;
  line-height: 1.2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-height: 32px
}

.control-section__title label {
  font-weight: 400;
  color: var(--muted)
}

.control-section__title > span:first-of-type {
  margin-left: -2px;
  margin-right: auto;
}

.control-toggle {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0
}

.control-group--inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px
}

.control-group--inline label {
  margin-bottom: 0
}

.control-group--inline select,
.control-group--slider-row select {
  padding: 6px 28px 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafafb url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237d8290' stroke-width='3'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 6px center;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  outline: none;
  transition: border-color .15s
}

.control-group--inline select:hover,
.control-group--slider-row select:hover {
  border-color: var(--purple)
}

.control-group--inline select:focus,
.control-group--slider-row select:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 2px rgba(96, 72, 245, .15)
}

.control-group--slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 32px
}

.control-group--slider-row label {
  margin-bottom: 0;
  flex-shrink: 0
}

.control-group--slider-row input[type=range] {
  width: auto;
  flex: 1;
  margin: 0
}

.control-group--slider-row .control-value {
  flex-shrink: 0
}

.control-group--slider-row .color-swatch {
  flex-shrink: 0
}

.control-group--slider-row select {
  flex-shrink: 0;
  width: auto
}

.control-section__title .color-swatch {
  flex-shrink: 0
}

.control-section__title input[type=range] {
  flex: 1;
  width: auto;
  min-width: 0;
  margin: 0 4px
}

.control-toggle input[type=checkbox] {
  width: 24px;
  height: 24px;
  margin: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  border: 1.5px solid var(--line);
  border-radius: 50%;
  background: #fff;
  position: relative;
  transition: border-color .15s, background .15s
}

.control-toggle input[type=checkbox]:checked {
  background: var(--teal);
  border-color: var(--teal)
}

.control-toggle input[type=checkbox]:checked::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
  transform: translate(-50%, -50%)
}

/* Slider dạng thanh mảnh (giống Time-Range): #seek dùng màu purple (slider liên quan thời gian),
   slider thông số (font size, radius, stroke width, alpha...) dùng màu teal để phân biệt. */
#seek,
.control-group input[type=range],
.control-section__title input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 20px;
  margin: 0;
  background: transparent;
  cursor: pointer
}

#seek {
  flex: 1
}

#currentTime,
#duration {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap
}

#seek::-webkit-slider-runnable-track,
.control-group input[type=range]::-webkit-slider-runnable-track,
.control-section__title input[type=range]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: var(--line)
}

#seek::-webkit-slider-runnable-track {
  background: linear-gradient(to right, var(--purple) 0%, var(--purple) var(--progress, 0%), var(--line) var(--progress, 0%), var(--line) 100%)
}

#seek::-moz-range-track,
.control-group input[type=range]::-moz-range-track,
.control-section__title input[type=range]::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--line)
}

#seek::-moz-range-progress {
  height: 4px;
  border-radius: 2px;
  background: var(--purple)
}

.control-group input[type=range]::-moz-range-progress,
.control-section__title input[type=range]::-moz-range-progress {
  height: 4px;
  border-radius: 2px;
  background: var(--teal)
}

#seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  margin-top: -9px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--purple);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
  cursor: pointer
}

#seek::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--purple);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
  cursor: pointer
}

.control-group input[type=range]::-webkit-slider-thumb,
.control-section__title input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  margin-top: -6px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--teal);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
  cursor: pointer
}

.control-group input[type=range]::-moz-range-thumb,
.control-section__title input[type=range]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--teal);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
  cursor: pointer
}

.switch {
  display: inline-block;
  position: relative;
  width: 38px;
  height: 22px;
  cursor: pointer;
  flex-shrink: 0
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0
}

.switch__track {
  position: absolute;
  inset: 0;
  background: #ddd;
  border-radius: 11px;
  transition: background .15s
}

.switch__track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: left .15s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .2)
}

.switch input:checked+.switch__track {
  background: var(--teal)
}

.switch input:checked+.switch__track::after {
  left: 18px
}

.color-row {
  display: flex;
  align-items: center;
  justify-content: space-between
}

.color-row label {
  margin-bottom: 0
}

.color-swatch {
  width: 32px;
  height: 32px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  padding: 0;
  cursor: pointer;
  background: none
}

.color-swatch:disabled {
  opacity: .4;
  cursor: not-allowed
}

#addTextColor,
#addTextBgColor,
#drawStrokeColor {
  -webkit-appearance: none;
  appearance: none;
  overflow: hidden;
}

#addTextColor::-webkit-color-swatch-wrapper,
#addTextBgColor::-webkit-color-swatch-wrapper,
#drawStrokeColor::-webkit-color-swatch-wrapper {
  padding: 0;
}

#addTextColor::-webkit-color-swatch,
#addTextBgColor::-webkit-color-swatch,
#drawStrokeColor::-webkit-color-swatch {
  border: 0;
  opacity: 0;
}

.is-disabled-group {
  opacity: .45;
  pointer-events: none;
  transition: opacity .15s
}

/* Add Text / Add Image / Draw: list of items already added to the overlay */
.overlay-item-list {
  margin-top: 14px;
  border-top: 1px dashed var(--line);
  padding-top: 10px
}

.overlay-item-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 6px;
  border-radius: 8px;
  cursor: pointer
}

.overlay-item-row:hover {
  background: #faf9ff
}

.overlay-item-row__label {
  flex: 1;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis
}

.overlay-item-row__remove {
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  padding: 2px 6px;
  line-height: 1
}

.overlay-item-row__remove:hover {
  color: #e5484d
}

/* Video Effects: list of effects already added */
.effect-item-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 6px;
  border-radius: 8px;
  cursor: pointer
}

.effect-item-row:hover {
  background: #faf9ff
}

.effect-item-row__label {
  flex: 1;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis
}

.effect-item-row__remove {
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  padding: 2px 6px;
  line-height: 1
}

.effect-item-row__remove:hover {
  color: #e5484d
}

/* Draw tool: transparent canvas layer overlaid on the stage for freehand strokes */
#drawLiveCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
  background: transparent;
  cursor: crosshair;
  touch-action: none;
  pointer-events: none
}

/* Add Text: interactive box for drag-to-move, drag-corner-to-scale, drag-handle-to-rotate */
.overlay-box {
  position: absolute;
  border: 1.5px dashed var(--purple);
  cursor: move;
  touch-action: none;
  box-sizing: border-box;
  min-width: 40px
}

.overlay-box[hidden] {
  display: none
}

.overlay-box__resize {
  position: absolute;
  right: -8px;
  bottom: -8px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--purple);
  border: 2px solid #fff;
  cursor: nwse-resize;
  touch-action: none
}

.overlay-box__rotate {
  position: absolute;
  top: -34px;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--purple);
  color: #fff;
  border: 2px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  line-height: 1;
  cursor: grab;
  touch-action: none
}

.overlay-box__rotate-line {
  position: absolute;
  top: -12px;
  left: 50%;
  width: 1.5px;
  height: 12px;
  background: var(--purple);
  transform: translateX(-50%);
  pointer-events: none
}

/* Add Text: live DOM+CSS preview shown inside #overlayBox for ALL text (with or without effect) —
   rasterized to PNG via snapdom only when the item is committed, see overlay-filter.js.
   The stage is sized to its OWN natural content box (fontSize is stored in video-pixel units), then
   scaled down with a CSS transform to fit the (smaller, screen-CSS-px) #overlayBox — this keeps the
   live preview pixel-identical to the rasterized PNG instead of stretching/squashing text to fill a
   differently-scaled container. */
.text-fx-live {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  transform-origin: 0 0
}

.text-fx-live[hidden] {
  display: none
}

.text-fx-stage {
  box-sizing: border-box;
  white-space: pre;
  text-align: left;
  font-family: sans-serif;
  font-size: var(--fx-font-size, 16px);
  position: relative;
  /* z-index:0 (not auto) forms a local stacking context so the ::before's z-index:-1 stays
     contained BEHIND this element's own text instead of escaping to paint behind unrelated
     ancestors (video/canvas/other overlay items). */
  z-index: 0
}

/* User's Background option paints on a ::before pseudo instead of the element itself, so it never
   conflicts with effects that paint text via background + background-clip:text (see applyStageStyling()).
   Living on .text-fx-stage's own pseudo (not a parent node) means it's automatically included whenever
   this element is captured/animated/exported — no separate parent node needed. */
.text-fx-stage::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--fx-bg, none);
  border-radius: var(--fx-bg-radius, 0px);
  z-index: -1;
  pointer-events: none
}

/* Wraps a static effect's own text paint (color/gradient/filter/stroke) separate from .text-fx-stage
   itself, so the user's Background option (set via ::before above) never conflicts with
   effects that paint text via background + background-clip:text (see applyStageStyling()). */
.text-fx-content {
  margin: 0;
  padding: 0
}

/* Add Text: tabs + grids for choosing a Static / Animated text effect (giống #effectsGrid của Video Effects) */
#texteffectsGrid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px
}

.text-fx-tabs {
  display: flex;
  gap: 0;
  margin: 0;
  margin-bottom: 10px;
  background: #f5f5f7;
  padding: 4px;
  border-radius: 0;
  grid-column: 1;
  align-items: center;
}

#textfxSpeedRow {
  grid-column: 2;
  margin: 0 !important
}

.textfx-panel {
  grid-column: 1/-1
}

.text-fx-tab {
  flex: 1 1 0;
  padding: 10px 16px;
  border: none;
  background: transparent;
  border-radius: 0;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  text-align: center;
  transition: all 0.2s ease;
}

.text-fx-tab--active {
  color: white;
  background: linear-gradient(90deg, rgb(42, 123, 155) 0%, rgb(87, 199, 133) 100%);
  border: none;
  font-weight: 600;
}

.text-fx-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 2px
}

.text-fx-item {
  padding: 8px 6px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #00000000;
  cursor: pointer;
  text-align: center;
  font-size: 24px;
  color: #1c1d22;
  white-space: nowrap;
  line-height: 1.3;
  min-height: 75px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all .2s ease
}

.text-fx-item__inner {
  max-width: 100%
}

#texteffectsGridEffects .text-fx-item {
  flex: 0 0 auto;
  min-width: auto;
  width: auto;
  white-space: normal;
  min-height: auto;
  padding: 8px 12px;
}

.text-fx-item--selected {
  background: linear-gradient(90deg, rgb(42, 123, 155) 0%, rgb(87, 199, 133) 50%, rgb(237, 221, 83) 100%);
  border-color: #ddd9ff;
  color: var(--purple);

}

.text-fx-item--none {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line)
}

.text-fx-item--none.text-fx-item--selected {
  background: linear-gradient(90deg, rgb(42, 123, 155) 0%, rgb(87, 199, 133) 50%, rgb(237, 221, 83) 100%);
  border-color: #ddd9ff;
  color: var(--purple);
}

/* In/Out/Attention tabs (4-tab #texteffectsGrid, see buildTextFxGrids() in overlay-filter.js) */
.textfx-speed {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 12px;
  color: var(--muted);
  font-weight: 700
}

.textfx-speed select {
  border: 0;
  background: transparent;
  font: inherit;
  font-weight: 800;
  color: var(--text);
  cursor: pointer;
  outline: none
}

.textfx-panel {
  display: none;
  grid-column: 1/-1
}

.textfx-panel.textfx-panel--active {
  display: grid
}

/* Add Text: nút "Animation" mở tab In/Out/Attention (xem setActiveTextFxTab() trong overlay-filter.js)
   nằm trên hàng riêng, canh phải, có border dưới để tách khỏi tab-bar Style/Effects bên dưới. */
.textfx-anim-toggle-row {
  display: flex;
  justify-content: flex-end;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--line)
}

.textfx-anim-btn {
  flex: 1 1 0;
  border: none;
  color: var(--muted);
  font-weight: 500;
  padding: 10px 16px;
  font-size: 14px;
  background: transparent;
  border-radius: 0;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.textfx-anim-btn:hover {
  background: rgba(87, 199, 133, 0.08);
  color: var(--text);
}

.textfx-anim-btn.text-fx-tab--active {
  color: white;
  background: linear-gradient(90deg, rgb(42, 123, 155) 0%, rgb(87, 199, 133) 100%);
  border: none;
  font-weight: 600;
}

/* Add Text: tab "Style" — Background/Shadow/Border xếp dọc 1 cột (mỗi nhóm có Opacity riêng thay cho
   checkbox bật/tắt cũ), xem buildTextFxGrids()/updateTextDraft() trong overlay-filter.js */
.textfx-style-params.textfx-panel--active {
  display: flex;
  flex-direction: column;
  gap: 10px
}

/* Nhóm chip chọn loại animation (In/Out/Attention) — hiện qua nút #textfxAnimBtn, xem setActiveTextFxTab() */
.textfx-anim-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px
}

#addTextAnimGroup {
  display: flex;
  gap: 8px;
  flex-shrink: 0
}

.textfx-anim-card {
  padding: 4px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #00000000;
  cursor: pointer;
  aspect-ratio: 1;
  display: grid;
  grid-template-rows: 1fr auto;
  align-items: center;
  justify-items: center;
  gap: 2px;
  overflow: hidden;
  transition: all .2s ease
}

.textfx-anim-card--selected {
  background: linear-gradient(90deg, rgb(42, 123, 155) 0%, rgb(87, 199, 133) 50%, rgb(237, 221, 83) 100%);
  border-color: #ddd9ff;
  color: var(--purple);

}

.textfx-anim-box {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #7c3aed;
  flex-shrink: 0;
  grid-row: 1
}

.textfx-anim-label {
  font-size: 9px;
  color: var(--muted);
  font-weight: 600;
  text-align: center;
  white-space: normal;
  word-break: break-word;
  line-height: 1;
  grid-row: 2
}


/* Timeline / Edits: list of all effect items */
.columns {
  display: grid;
  grid-template-columns: 180px minmax(450px, 1fr) 320px;
  grid-template-rows: 1fr;
  gap: 10px;
  align-items: stretch;
  flex: 1;
  min-height: 0
}

.timeline-edits {
  display: none;
  padding-top: 0px;
  border-top: 0px solid var(--line);
  margin-top: auto
}

.timeline-edits.timeline-edits--show {
  display: block
}

.timeline-edits__header {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px
}

.timeline-edits__header::before {
  content: "☰";
  font-size: 16px
}

.timeline-edits__list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 300px;
  overflow-y: auto
}

/* .timeline-edit-item__bar phải canh cùng toạ độ x trái/phải với #seek ở .controls phía trên —
   2 khu vực này nằm ở 2 container khác nhau (không có chung cha để dùng CSS Grid subgrid) nên
   không thể canh bằng CSS thuần. syncTimelineTrackInsets() (app.js) ĐO vị trí thật của #seek mỗi
   lần render/resize rồi ghi ra 2 CSS var --timeline-track-inset-start/-end trên #timelineEditsList
   — .timeline-edit-item dùng padding-left/right = 2 var đó để dành đúng khoảng trống cho bar, và
   __prefix/__suffix (chứa icon + start/end time) được đặt tuyệt đối đè lên vùng padding đó (không
   hardcode px nên luôn đúng dù nội dung/kích thước 2 bên đổi bất kỳ lúc nào). */
.timeline-edit-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 24px;
  padding: 0 var(--timeline-track-inset-end, 0px) 0 var(--timeline-track-inset-start, 32px);
  border-radius: 6px;
  cursor: pointer;
  position: relative
}

.timeline-edit-item:hover {
  background: #f2efff
}

.timeline-edit-item__prefix {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--timeline-track-inset-start, 32px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px
}

.timeline-edit-item__prefix .timeline-edit-item__time-val {
  margin-right: 8px
}

.timeline-edit-item__suffix {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: var(--timeline-track-inset-end, 0px);
  display: flex;
  align-items: center;
  justify-content: flex-end
}

.timeline-edit-item__icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--muted);
  transition: color .15s
}

.timeline-edit-item__icon img {
  width: 24px;
  height: 24px
}

.timeline-edit-item__icon svg {
  width: 24px;
  height: 24px
}

.timeline-edit-item__bar {
  flex: 1;
  height: 4px;
  background: var(--line);
  border-radius: 1px;
  position: relative
}

.timeline-edit-item__bar-fill {
  position: absolute;
  height: 4px;
  background: var(--muted);
  opacity: 0.85;
  top: 50%;
  transform: translateY(-50%);
  border-radius: 2px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  transition: background .15s
}

/* Item đang active/focus trong Timeline/Edits: cho phép click start/end time để mở dialog sửa
   (thay thế "Timeline 1" đã bỏ) — xem renderTimelineEdits() trong app.js. Luôn render start/end cho
   MỌI item (giữ chỗ bố cục) nhưng chỉ hiện khi item đang active — dùng visibility (không phải
   display) để không làm layout của .timeline-edit-item nhảy khi focus/blur. start nằm bên trái bar,
   end bên phải bar (2 span độc lập, không còn bọc chung 1 wrapper). */
.timeline-edit-item__time-val {
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 4px;
  flex-shrink: 0;
  font-size: 12px;
  color: var(--muted);
  visibility: hidden;
  transition: background .15s, color .15s
}

.timeline-edit-item--active .timeline-edit-item__time-val {
  visibility: visible
}

.timeline-edit-item__time-val:hover {
  background: #f2efff;
  color: var(--purple)
}

.timeline-edit-item--active .timeline-edit-item__icon {
  color: var(--item-color, var(--purple))
}

.timeline-edit-item--active .timeline-edit-item__bar-fill {
  background: var(--item-color, var(--purple));
}

/* Kéo 2 đầu (start/end) của item đang active trực tiếp trên bar — thay cho "Timeline 1" đã bỏ */
.timeline-edit-item__handle {
  position: absolute;
  top: 50%;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--purple);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
  transform: translate(-50%, -50%);
  cursor: ew-resize;
  touch-action: none;
  z-index: 2
}

@media(max-width:1250px) {
  .columns {
    grid-template-columns: 180px minmax(450px, 1fr) 320px;
    grid-template-rows: 1fr
  }
}

/* Hide right panel entirely (and reclaim its width for center) when no tool panel is open and no timeline items exist */
.panel.advanced:not(:has(.tool-panel--active, .timeline-edits--show)) {
  display: none
}

.columns:has(.panel.advanced:not(:has(.tool-panel--active, .timeline-edits--show))) {
  grid-template-columns: 180px minmax(450px, 1fr)
}

/* ===== Export dialog ===== */
:root {
  --exp-accent: #f59e0b;
  --exp-accent-hover: #d97706;
  --exp-border: #ececf1
}

.dialog-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 24, .5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 16px
}

.dialog-overlay--open {
  display: flex
}

.dialog {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 360px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(20, 20, 40, .25)
}

.dialog__actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 16px 20px 20px
}

.dialog__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 6px
}

.dialog__title {
  font-size: 19px;
  font-weight: 700;
  color: var(--text)
}

.dialog__close {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  border-radius: 50%;
  cursor: pointer;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center
}

.dialog__close:hover {
  background: #f2f2f5;
  color: var(--text)
}

.dialog__body {
  padding: 6px 20px 4px
}

.dialog__divider {
  margin: 16px 0;
  border: none;
  border-top: 1px solid var(--exp-border)
}

.dialog__footer {
  display: flex;
  justify-content: flex-end;
  padding: 16px 20px;
  margin-top: 12px;
  border-top: 1px solid var(--exp-border)
}

.form-group {
  margin-bottom: 16px
}

.form-group__label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px
}

.form-group input[type="number"] {
  width: 100%;
  box-sizing: border-box;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: #fafafb
}

.form-group input[type="number"]:focus {
  outline: none;
  border-color: var(--teal);
  background: #fff
}

.dialog#dlgTimeInput .dialog__body {
  padding: 16px 20px
}

.format-chips {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px
}

.format-chips+.format-chips {
  margin-top: 8px
}

.format-chip {
  padding: 10px 6px;
  border: 1.5px solid var(--exp-border);
  border-radius: 9px;
  background: #fafafb;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  text-align: center;
  transition: all .15s
}

.format-chip:hover {
  border-color: var(--exp-accent)
}

.format-chip--selected {
  border-color: var(--exp-accent);
  background: rgba(245, 158, 11, .1);
  color: var(--exp-accent)
}

.format-chip:disabled {
  opacity: .35;
  pointer-events: none
}

.settings-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 16px
}

.setting-item {
  display: flex;
  flex-direction: column;
  gap: 6px
}

.setting-item__label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600
}

.setting-item__select {
  padding: 10px 30px 10px 12px;
  border: 1.5px solid var(--exp-border);
  border-radius: 9px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: #fafafb url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237d8290' stroke-width='3'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 8px center;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  width: 100%
}

.setting-item__select:focus {
  outline: none;
  border-color: var(--exp-accent)
}

.dialog-btn {
  padding: 0 22px;
  height: 44px;
  border: none;
  border-radius: 10px;
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer
}

.dialog-btn--apply {
  background: var(--exp-accent);
  color: #fff
}

.dialog-btn--apply:hover {
  background: var(--exp-accent-hover)
}

.dialog-btn--apply:disabled {
  opacity: .5;
  cursor: not-allowed
}

/* ===== Loading dialog (generic spinner + message) ===== */
.dialog--loading {
  max-width: 220px
}

.loading-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 20px 0
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--exp-border);
  border-top-color: var(--exp-accent);
  border-radius: 50%;
  animation: loading-spin .8s linear infinite
}

@keyframes loading-spin {
  to {
    transform: rotate(360deg)
  }
}

.loading-message {
  font-size: 14px;
  font-weight: 600;
  color: var(--text)
}

/* ===== Progress dialog (matches final-ffmpeg-sdk's #dlgProgress) ===== */
.dialog--progress {
  max-width: 360px;
  padding: 16px 16px 24px
}

.dialog--progress .dialog__body {
  padding: 0
}

.progress-header {
  text-align: center;
  margin-bottom: 16px
}

.progress-header__filename {
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.4;
  word-break: break-all
}

.progress-circle-wrap {
  position: relative;
  width: 160px;
  height: 160px;
  margin: 0 auto 24px
}

.progress-circle {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg)
}

.progress-circle__bg {
  fill: none;
  stroke: #f0f0f3;
  stroke-width: 8
}

.progress-circle__fill {
  fill: none;
  stroke: var(--exp-accent);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 326.73;
  stroke-dashoffset: 326.73;
  transition: stroke-dashoffset .3s ease
}

.progress-circle__content {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center
}

.progress-circle__percent {
  font-size: 36px;
  font-weight: 700;
  color: var(--text);
  line-height: 1
}

.progress-circle__time {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px
}

.progress-notice {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 24px;
  opacity: .7
}

.progress-cancel {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 28px;
  border: 1.5px solid var(--exp-border);
  border-radius: 100px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  margin: 0 auto
}

.progress-cancel:hover {
  border-color: #ef4444;
  color: #ef4444;
  background: rgba(239, 68, 68, .06)
}

.progress-cancel:disabled {
  opacity: .4;
  cursor: not-allowed
}

/* ===== Result dialog (matches final-ffmpeg-sdk's #dlgResult) ===== */
.dialog--result {
  max-width: 480px;
  padding: 0;
  overflow: hidden
}

.dialog--result .dialog__body {
  padding: 0
}

.dialog--result .dialog__close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 10;
  background: rgba(0, 0, 0, .45);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  color: #fff
}

.result-video {
  width: 100%;
  aspect-ratio: 16/9;
  background: #000;
  position: relative
}

.result-video video {
  width: 100%;
  height: 100%;
  object-fit: contain
}

.result-info {
  padding: 16px 24px;
  text-align: center;
  background: #fafafb
}

.result-info__name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap
}

.result-info__meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  flex-wrap: wrap
}

.result-info__dot {
  color: var(--muted);
  opacity: .5
}

.result-actions {
  display: flex;
  gap: 24px;
  padding: 16px;
  background: #fafafb;
  border-top: 1px solid var(--exp-border)
}

.result-btn {
  flex: 1;
  padding: 12px 16px;
  height: 44px;
  border: none;
  border-radius: 10px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  display: flex;
  align-items: center;
  justify-content: center
}

.result-btn--close {
  background: transparent;
  color: var(--muted);
  border: 1.5px solid var(--exp-border)
}

.result-btn--close:hover {
  background: rgba(239, 68, 68, .1);
  color: #ef4444;
  border-color: #ef4444
}

.result-btn--download {
  background: var(--exp-accent);
  color: #fff
}

.result-btn--download:hover {
  background: var(--exp-accent-hover)
}

/* =====================================================================
   Layout redesign theo new-design.drawio (tham khảo clideo.com) — gộp từ
   new-style.css. Đặt SAU style component ở trên để override phần KHUNG
   layout (page/columns/panel/center/advanced/workspace/timeline).

   Layout mục tiêu (xem new-design.drawio):
   [Ad cố định] [Cột trái: Trim/Crop/.../Draw] [Cột giữa 6] [Cột phải 4]
   - Cột giữa: CHỈ video (tỉ lệ cố định) ở trên + Timeline/Edits scroll ở dưới.
   - Cột phải: params (font size, color...) ở trên + các grid chọn effect
     (#effectsGrid/#audioEffectsGrid/#texteffectsGrid/#elementsGrid) ở dưới,
     grid tự scroll trong vùng của nó — KHÔNG kéo scroll cả trang.
   - html/body neo cứng vào viewport thật (height:100%) để mọi overflow-y:auto
     bên trong thực sự có tác dụng; page chỉ scroll khi kích thước quá nhỏ.
   ===================================================================== */

html,
body {
  height: 100%;
}

body {
  overflow: auto;
}

.page {
  display: grid;
  /* Cột phải cần tối thiểu ~260px để dùng được; cột giữa giữ tỉ lệ 7:3 => tối thiểu = 260*7/3 */
  grid-template-columns: 145px 180px minmax(390px, 7fr) minmax(260px, 3fr);
  grid-template-rows: 1fr;
  gap: 12px;
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: none;
  margin: auto;
  padding: 0 12px 12px;
}

@media (max-width: 1250px) {
  .page {
    grid-template-columns: 145px 180px minmax(390px, 7fr) minmax(260px, 3fr);
  }
}

/* Rule cũ ở trên vẫn ẩn .ad khi màn hẹp — ghi đè lại, ad phải luôn hiển thị */
.ad {
  display: flex !important;
  visibility: hidden !important;
}

.editor,
.columns {
  display: contents;
}

/* ---- Cột trái: Trim/Crop/Rotate/Playback + Video/Audio Effects/Add Text/Add Image/Draw ---- */
.panel.basic {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  overflow-y: auto;
  overflow-x: hidden;
  max-height: 100%;
  align-self: start;
  min-width: 0;
}

.panel.basic .tool {
  height: 72px;
}

/* ---- Cột giữa: video (trên, cố định tỉ lệ) + Timeline/Edits (dưới, tự scroll) ---- */
.center {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  min-width: 0;
}

.preview-card {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  min-height: 0;
}

.preview-card .stage {
  flex-shrink: 0;
}

/* Trim/Crop/Rotate/Playback panels vẫn nằm cạnh video (form nhỏ, không phải grid to) */
.preview-card .workspace {
  flex: 0 1 auto;
  min-height: 0;
  max-height: 220px;
  overflow-y: auto;
}

/* Timeline/Edits: chỉ hiện khi CÓ item (timeline-edits--show, do renderTimelineEdits() toggle) VÀ
   #workspace (Trim/Crop/Rotate/Playback) đang KHÔNG active — 2 khu vực này không được đè lên nhau. */
.center>.timeline-edits {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #e6e7ec;
  border-radius: 14px;
  box-shadow: 0 3px 16px rgba(25, 25, 50, .025);
  padding: 14px 16px;
}

.center>.timeline-edits.timeline-edits--show {
  display: flex;
}

.center:has(#workspace.workspace--active)>.timeline-edits {
  display: none;
}

.center>.timeline-edits .timeline-edits__list {
  max-height: none;
  flex: 1;
}

/* ---- Cột phải: toàn bộ section tự scroll dọc (params + grids cùng 1 luồng, không scroll riêng) ---- */
.panel.advanced {
  display: flex;
  flex-direction: column;
  gap: 0px;
  padding: 16px;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  min-width: 0;
  background: #fff;
  border: 1px solid #e6e7ec;
  border-radius: 14px;
  box-shadow: 0 3px 16px rgba(25, 25, 50, .025);
}

.panel.advanced:not(:has(.tool-panel--active)) {
  display: none;
}

.advanced-params {
  min-width: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
}

.advanced-grids {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
}

/* Compact left tool rail: keep labels readable while giving the preview more room. */
.page {
  grid-template-columns: 145px 180px minmax(390px, 7fr) minmax(260px, 3fr);
}

.panel.basic {
  gap: 0;
  padding: 10px;
}

.panel.basic .tool,
.panel.basic .advanced-tool {
  width: 100%;
  height: auto;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  padding: 22px 8px;
  border: none;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
}

.panel.basic .tool:hover,
.panel.basic .advanced-tool:hover {
  background: #f7f6ff;
  border-color: transparent;
  transform: none;
  box-shadow: none;
}

.panel.basic .tool--active {
  background: #f2efff;
  border-color: transparent;
}

.panel.basic .tool:last-child,
.panel.basic .advanced-tool:last-child {
  border-bottom: none;
}

.panel.basic .tool img,
.panel.basic .advanced-tool img {
  width: 22px;
  height: 22px;
}

.panel.basic .tool__label,
.panel.basic .advanced-tool .tool__label {
  flex-direction: row;
  align-items: center;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.15;
  text-align: left;
}

@media (max-width: 1250px) {
  .page {
    grid-template-columns: 145px 160px minmax(390px, 7fr) minmax(260px, 3fr);
  }
}

/* Mỗi grid trong #advancedGrids chỉ hiện khi panel tương ứng đang active — trước đây các grid này
   nằm trong .workspace (ẩn theo cha), giờ chuyển sang #advancedGrids (luôn render) nên phải tự ẩn/hiện. */
#effectsGrid,
#audioEffectsGrid,
#texteffectsGrid {
  display: none !important;
}

#advancedParams:has(#panelVideoEffects.tool-panel--active)~#advancedGrids #effectsGrid {
  display: grid !important;
}

#advancedParams:has(#panelAudioEffects.tool-panel--active)~#advancedGrids #audioEffectsGrid {
  display: grid !important;
}

#advancedParams:has(#panelAddText.tool-panel--active)~#advancedGrids #texteffectsGrid {
  display: block !important;
}

/* Draw chỉ thấy được tab Animation trong #texteffectsGrid (Style/Effects là field riêng của Text) —
   xem setTextFxTabsForKind() trong overlay-filter.js. */
#advancedParams:has(#panelDraw.tool-panel--active)~#advancedGrids #texteffectsGrid {
  display: block !important;
}

/* Add Image: #texteffectsGrid (Animation) giờ là 1 trong các tab của #elementsCategoryOptions
   (Emoji/Stickers/GIF/Animation) chứ không phải luôn hiện — chỉ show khi tab Animation đang chọn
   (class .media-show-animation trên #panelMedia, xem app.js). */
#advancedParams:has(#panelMedia.tool-panel--active.media-show-animation)~#advancedGrids #texteffectsGrid {
  display: block !important;
}

/* Không còn tool-panel active nào trong advanced-params => ẩn cả advanced-params rỗng lẫn advanced-grids trống */
.advanced-params:not(:has(.tool-panel--active)) {
  display: none;
}

/* Video Effects: hide params by default when panel active, show only if an effect is selected */
.panel.advanced:has(#panelVideoEffects.tool-panel--active) > .advanced-params {
  display: none;
}

.panel.advanced:has(#panelVideoEffects.tool-panel--active) .advanced-params:has(~ #advancedGrids #effectsGrid .effect-card--selected) {
  display: block;
}

/* Audio Effects: hide params by default when panel active, show only if audio effect info exists */
.panel.advanced:has(#panelAudioEffects.tool-panel--active) > .advanced-params {
  display: none;
}

.panel.advanced:has(#panelAudioEffects.tool-panel--active) .advanced-params:has(.audio-effect-info) {
  display: block;
}

/* Draw, Add Text, và Add Image không có grid selectable items, nên advanced-params phải luôn hiển thị khi các panel này active */
.panel.advanced:has(#panelDraw.tool-panel--active, #panelAddText.tool-panel--active, #panelMedia.tool-panel--active) > .advanced-params {
  display: block !important;
}

/* Bỏ "Timeline 1" (thanh Time range riêng trong từng panel) — chỉ dùng "Timeline 2" (Timeline/Edits
   list) để xem VÀ chỉnh start/end time (xem .timeline-edit-item__time-val trong renderTimelineEdits()).
   Giữ nguyên các input range/span bên dưới trong DOM (ẩn thôi) để không phá logic bindTimeRange hiện có. */
#effectTimeRangeGroup,
#audioEffectTimeRangeGroup,
#panelAddText .transform-group:has(.trim-range),
#panelMedia .transform-group:has(.trim-range),
#panelDraw .transform-group:has(.trim-range) {
  display: none !important;
}

/* Background color picker with solid and gradient modes. */
#addTextStyleParams {
  position: relative;
}

#texteffectsGrid {
  position: relative;
}

#textBgPicker {
  position: fixed;
  z-index: 1000;
  top: 50%;
  left: 50%;
  width: min(620px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 14px 34px rgba(15, 23, 42, .16);
}

#textBgPicker[hidden] {
  display: none;
}

.bg-picker-popover__header,
.bg-picker-modes {
  display: flex;
  align-items: center;
}

.bg-picker-popover__header {
  justify-content: space-between;
  margin-bottom: 10px;
}

.bg-picker-popover__header strong {
  color: var(--text);
  font-size: 13px;
}

.bg-picker-popover__header .dialog__close {
  width: 28px;
  height: 28px;
}

.bg-picker-modes {
  gap: 6px;
  margin-bottom: 10px;
}

.bg-picker-mode {
  flex: 1;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 15px;
  font-weight: 500;
}

.bg-picker-mode--active {
  border-color: var(--teal);
  background: rgba(20, 145, 137, .08);
  color: var(--teal);
  font-weight: 600;
}

.gradient-picker {
  display: grid;
  grid-template-columns: repeat(8, minmax(60px, 1fr));
  gap: 6px;
  max-height: 440px;
  overflow-y: auto;
  padding: 2px;
}

.gradient-picker[hidden] {
  display: none;
}

.gradient-preset {
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 5px;
  appearance: none;
  cursor: pointer;
  box-shadow: none;
  transition: transform .12s ease;
}

.gradient-preset:hover,
.gradient-preset:focus-visible {
  outline: none;
  transform: translateY(-1px);
}

/* Keep Font Size and Text Color on one clean row. */
#advancedParams #panelAddTextControls > .control-section:first-child {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, auto);
  align-items: center;
  gap: 8px 14px;
}

#advancedParams #panelAddTextControls > .control-section:first-child .control-group--slider-row {
  grid-column: 1;
  grid-row: 1;
}

#advancedParams #panelAddTextControls > .control-section:first-child .color-row {
  grid-column: 2;
  grid-row: 1;
  min-width: 150px;
}

#advancedParams #panelAddTextControls > .control-section:first-child .control-group--inline {
  grid-column: 1 / -1;
  grid-row: 2;
}

@media (max-width: 640px) {
  #advancedParams #panelAddTextControls > .control-section:first-child {
    grid-template-columns: 1fr;
  }

  #advancedParams #panelAddTextControls > .control-section:first-child .control-group--slider-row,
  #advancedParams #panelAddTextControls > .control-section:first-child .color-row,
  #advancedParams #panelAddTextControls > .control-section:first-child .control-group--inline {
    grid-column: auto;
    grid-row: auto;
    min-width: 0;
  }
}

/* Header actions: a compact toolbar with a clear export primary action. */
.header-actions {
  gap: 8px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
}

.header-actions .button,
.header-actions .settings {
  height: 38px;
  border-radius: 9px;
  transition: background-color .16s ease, border-color .16s ease, transform .16s ease;
}

.header-actions .button.light {
  background: transparent;
  color: var(--text);
}

.header-actions .button.light:hover,
.header-actions .settings:hover {
  background: #f5f5f7;
  border-color: #e1e2e8;
}

.header-actions .primary {
  padding: 0 13px;
  background: var(--purple);
  border-color: var(--purple);
  box-shadow: none;
}

.header-actions .primary:hover {
  background: #513be5;
  border-color: #513be5;
  transform: translateY(-1px);
}

.header-actions .settings {
  width: 38px;
  padding: 0;
  background: transparent;
}

.header-actions .settings img {
  opacity: .72;
}

@media (max-width: 620px) {
  .header-actions {
    gap: 4px;
  }

  .header-actions .button.light,
  .header-actions .primary,
  .header-actions .settings {
    width: 38px;
    height: 38px;
  }
}

/* Empty preview state: make the first action clear without covering the poster. */
.empty {
  background: rgba(246, 247, 249, .22);
  color: var(--text);
  backdrop-filter: blur(.5px);
}

.empty__panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(280px, calc(100% - 32px));
  padding: 24px 22px 22px;
  border: 1px dashed rgba(96, 72, 245, .32);
  border-radius: 14px;
  background: rgba(255, 255, 255, .3);
  box-shadow: 0 8px 24px rgba(30, 32, 55, .08);
}

.empty__hint {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
}

.empty button {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin-top: 16px;
  padding: 9px 15px 9px 11px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: linear-gradient(#fff, #fff) padding-box, linear-gradient(110deg, #00BFA6, #5271FF 52%, #FF6B9A) border-box;
  color: #123B43;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 5px 14px rgba(38, 82, 116, .12);
  transition: background .16s ease, box-shadow .16s ease, transform .16s ease;
}

.empty button {
  background-clip: padding-box, border-box;
  opacity: 0.7;
}

.empty button .upload-label {
  background: linear-gradient(110deg, #00BFA6, #5271FF 52%, #FF6B9A);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.empty button:hover {
  background: linear-gradient(#f7fffe, #faf9ff) padding-box, linear-gradient(110deg, #00BFA6, #5271FF 52%, #FF6B9A) border-box;
  box-shadow: 0 8px 18px rgba(38, 82, 116, .18);
  transform: translateY(-1px);
}

.empty button .upload-icon {
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  background: linear-gradient(145deg, #00BFA6, #5271FF 52%, #FF6B9A);
  -webkit-mask: url("../icons/upload.svg") center / contain no-repeat;
  mask: url("../icons/upload.svg") center / contain no-repeat;
}
