:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-soft: #f8fbff;
  --line: #d2dbe5;
  --line-soft: #dbe5ef;
  --text: #12202f;
  --muted: #64758b;
  --accent: #7ea1d8;
  --accent-soft: #eaf3fd;
  --accent-line: #c6d6e8;
  --thumb: #b5bfcc;
  --danger: #b54343;
  --shadow: 0 10px 24px rgba(18, 32, 47, 0.12);
  --radius: 14px;
  font-family: "Avenir Next", "Segoe UI", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(1320px 680px at 50% 700px, rgba(154, 183, 221, 0.38) 0%, rgba(154, 183, 221, 0.08) 64%, rgba(154, 183, 221, 0) 86%),
    linear-gradient(180deg, #ffffff 0%, #ffffff 360px, #f2f7fe 540px, #e4edf9 100%);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

body.converter-page {
  display: flex;
  flex-direction: column;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.converter-header {
  flex: 0 0 auto;
  background: #ffffff;
  padding: 27px 0 24px;
  position: relative;
  z-index: 20;
}

.converter-header::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  width: 100vw;
  height: 100%;
  transform: translateX(-50%);
  background: #ffffff;
  z-index: -1;
}

.converter-topbar {
  width: min(1200px, 94vw);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.converter-header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  display: block;
  width: 105px;
  height: auto;
  object-fit: contain;
}

.converter-title-divider {
  width: 1px;
  height: 32px;
  background: #6f869d;
  flex: 0 0 auto;
}

.converter-title-label {
  color: #2f4760;
  font-size: clamp(0.932rem, 1.701vw, 1.175rem);
  font-weight: 400;
}

.soft-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 41px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #ffffff;
  color: var(--text);
  border: 1px solid var(--line);
  font-weight: 400;
  line-height: 1.2;
  white-space: nowrap;
}

.soft-btn:hover {
  background: #edf4fb;
  border-color: #c6d6e8;
}

.converter-close-btn,
.header-export-button,
.compact-drop-zone {
  min-height: 41px;
  height: 41px;
}

.converter-close-btn,
.header-export-button {
  width: auto;
  min-width: 108px;
  padding: 0 18px;
  font-size: 0.92rem;
  font-weight: 400;
}

.compact-drop-zone {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 210px;
  padding: 0 18px;
  border-style: solid;
  border-radius: 10px;
}

.app {
  flex: 1 1 auto;
  width: min(1200px, 94vw);
  height: auto;
  min-height: 0;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(330px, 430px) 1fr;
  background: rgba(255, 255, 255, 0.82);
  overflow: hidden;
}

.sidebar {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px 24px 30px;
  background: rgba(255, 255, 255, 0.92);
  overflow: auto;
}

.eyebrow,
.section-head h2 {
  margin: 0;
}

.eyebrow {
  color: #3d4d60;
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0;
}

.panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.upload-panel {
  display: none;
  padding: 0;
  border: 0;
}

.upload-panel:empty {
  display: none;
}

.format-panel {
  padding-top: 0;
  padding-inline: 0;
  border: 0;
}

.placement-panel {
  padding-inline: 0;
  border: 0;
}

.duration-panel {
  padding-inline: 0;
  border: 0;
}

.drop-zone {
  display: grid;
  gap: 5px;
  min-height: 132px;
  place-content: center;
  border: 1px dashed #c9d6e5;
  border-radius: 14px;
  background: #ffffff;
  text-align: center;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease;
}

.compact-drop-zone.drop-zone {
  gap: 0;
  min-height: 41px;
  height: 41px;
  place-content: initial;
  border: 1px dashed #c9d6e5;
  border-radius: 10px;
  background: #ffffff;
}

.drop-zone:hover,
.drop-zone.is-over {
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

.drop-zone input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.drop-title {
  color: #27394c;
  font-size: 1rem;
  font-weight: 600;
}

.compact-drop-zone .drop-title {
  font-size: 0.92rem;
  font-weight: 500;
  white-space: nowrap;
}

.drop-meta,
.format-button small,
.clip-item small,
.time-readout {
  color: var(--muted);
  font-size: 0.86rem;
}

.library {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.library:empty {
  display: none;
}

.clip-item {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  gap: 3px 10px;
  width: 100%;
  padding: 12px 10px 12px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
  text-align: left;
  cursor: pointer;
}

.clip-item.is-active {
  border-color: var(--line);
  background: var(--accent-soft);
}

.clip-name {
  grid-column: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.clip-meta {
  grid-column: 1;
}

.remove-clip {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  justify-self: end;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  background: #ffffff;
  font-size: 1rem;
  line-height: 1;
  font-weight: 600;
}

.remove-clip:hover,
.remove-clip:focus-visible {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--text);
  outline: none;
}

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

.section-head h2 {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0;
  color: #3d4d60;
  font-weight: 600;
}

.format-panel .section-head,
.placement-panel .section-head,
.duration-panel .section-head {
  justify-content: center;
}

.format-panel .section-head {
  margin: 8px 0 24px;
}

.placement-panel .section-head h2 {
  transform: translateY(-10px);
}

.duration-panel {
  margin-top: 10px;
}

.duration-panel .section-head h2 {
  transform: translateY(-15px);
}

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

.format-button,
.segmented button,
.ghost-button {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
  cursor: pointer;
}

.format-button {
  display: grid;
  gap: 4px;
  padding: 12px;
  text-align: left;
}

.format-button span {
  font-weight: 600;
  font-size: 0.92rem;
}

.format-button.is-active,
.segmented button.is-active {
  border-color: var(--line);
  background: var(--accent-soft);
  color: var(--text);
}

.ghost-button {
  min-height: 40px;
  padding: 0 16px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
}

.range-row,
.number-row {
  display: grid;
  align-items: center;
  gap: 12px;
  color: #27394c;
  font-size: 0.86rem;
}

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

.number-row {
  grid-template-columns: minmax(0, 1fr) 118px;
  margin: 0;
}

.number-row[hidden] {
  display: none;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 16px;
  padding: 0;
  border: 0;
  background: transparent;
  outline: none;
}

input[type="range"]:focus,
input[type="range"]:focus-visible {
  outline: none;
  box-shadow: none;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: #dfe8f2;
  border-radius: 999px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border: 0;
  border-radius: 50%;
  background: var(--thumb);
}

input[type="range"]::-moz-range-track {
  height: 4px;
  background: #dfe8f2;
  border-radius: 999px;
}

input[type="range"]::-moz-range-progress {
  height: 4px;
  background: var(--accent);
  border-radius: 999px;
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 0;
  border-radius: 50%;
  background: var(--thumb);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.segmented:has(#stretchButton) {
  grid-template-columns: repeat(3, 1fr);
}

.segmented button {
  min-height: 40px;
  font-size: 0.8rem;
  font-weight: 600;
}

.stretch-controls {
  margin-top: 10px;
}

.stretch-controls[hidden] {
  display: none;
}

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

.segmented.compact button {
  min-height: 34px;
  font-size: 0.66rem;
}

.radio-stack {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.duration-option {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px 12px;
  align-items: center;
  min-height: 54px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
}

.duration-option:has(input:checked) {
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

.duration-option:has(.number-row:not([hidden])) {
  row-gap: 14px;
}

.duration-option > label {
  display: flex;
  align-items: center;
  min-height: 32px;
  min-width: 0;
  cursor: pointer;
}

.radio-stack input[type="radio"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.duration-option:has(input:focus-visible) {
  outline: 2px solid var(--accent-line);
  outline-offset: 3px;
}

.duration-option > .number-row {
  grid-column: 1 / -1;
  padding: 0;
}

.duration-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.mini-button {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}

.mini-button.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.number-row input {
  min-width: 0;
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
  color: var(--text);
}

.primary-button {
  width: 100%;
  min-height: 50px;
  border: 0;
  border-radius: 12px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  color: #102033;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.converter-header .header-export-button {
  min-height: 41px;
  height: 41px;
}

.workspace {
  min-width: 0;
  position: relative;
  background: #ffffff;
  overflow: hidden;
}

.workspace-export {
  position: absolute;
  top: 24px;
  right: 48px;
  z-index: 4;
  width: 0;
}

.export-progress {
  position: absolute;
  top: 0;
  right: 0;
  display: none;
  width: min(280px, calc(100vw - 96px));
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.export-progress.is-visible {
  display: grid;
  gap: 8px;
}

.export-progress-head,
.export-eta {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.25;
}

.export-progress-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

#exportStatus {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#exportPercent {
  color: var(--text);
  font-weight: 600;
}

.export-progress-track {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: #dfe8f2;
}

.export-progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 180ms ease;
}

.export-progress.has-error .export-progress-track span {
  background: var(--danger);
}

.stage-wrap {
  position: absolute;
  top: 22px;
  right: 48px;
  bottom: 112px;
  left: 48px;
  overflow: hidden;
  background: #ffffff;
}

.stage-shell {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 14px;
  box-shadow: none;
  background: #ffffff;
  overflow: hidden;
}

#previewCanvas {
  display: block;
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--preview-width, 680px);
  max-width: none;
  aspect-ratio: var(--preview-aspect, 4 / 5);
  transform: translate(var(--crop-offset-x, -50%), var(--crop-offset-y, -50%));
  cursor: grab;
}

#sourceVideo {
  display: none;
}

#previewCanvas.is-dragging {
  cursor: grabbing;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  background: #ffffff;
  text-align: center;
}

.empty-state strong {
  font-size: clamp(1.5rem, 4.5vw, 3.75rem);
  line-height: 0.95;
}

.empty-state span {
  color: var(--muted);
  font-weight: 600;
  opacity: 0.5;
  transform: translateY(30px);
}

.empty-state.is-hidden {
  display: none;
}

.transport {
  position: absolute;
  left: 48px;
  right: 48px;
  bottom: 26px;
  z-index: 4;
  display: grid;
  grid-template-columns: 82px 1fr;
  gap: 10px;
  align-items: center;
  background: transparent;
}

.transport.is-trim-editing {
  grid-template-columns: 82px auto 1fr;
}

.time-readout {
  grid-column: 1 / -1;
  grid-row: 1;
  display: grid;
  grid-template-columns: subgrid;
}

#currentTime {
  grid-column: 1;
  justify-self: center;
}

#totalTime {
  grid-column: 2;
  justify-self: end;
}

.transport.is-trim-editing #totalTime {
  grid-column: 3;
}

.play-button,
.from-in-button {
  grid-column: 1;
  grid-row: 2;
  justify-self: start;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
}

.play-button {
  min-width: 82px;
}

.from-in-button {
  grid-column: 2;
  width: 38px;
  min-height: 38px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--muted);
}

.from-in-button[hidden] {
  display: none;
}

.from-in-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.play-button:disabled,
.from-in-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

#scrubber {
  grid-column: 2;
  grid-row: 2;
}

.trim-selector {
  grid-column: 2;
  grid-row: 2;
  height: 36px;
  align-content: center;
}

.transport.is-trim-editing #scrubber,
.transport.is-trim-editing .trim-selector {
  grid-column: 3;
}

.trim-selector[hidden] {
  display: none;
}

.trim-track {
  position: relative;
  height: 6px;
  border-radius: 999px;
  background: #dfe8f2;
  cursor: pointer;
}

.trim-selection {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: inherit;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
}

.trim-duration {
  position: absolute;
  z-index: 2;
  bottom: 13px;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.2;
  pointer-events: none;
  transform: translateX(-50%);
  white-space: nowrap;
}

.trim-playhead {
  position: absolute;
  z-index: 2;
  top: 50%;
  width: 2px;
  height: 24px;
  border-radius: 999px;
  background: #12202f;
  box-shadow: 0 1px 4px rgba(18, 32, 47, 0.18);
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.trim-handle {
  position: absolute;
  z-index: 3;
  top: 50%;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 1px 5px rgba(18, 32, 47, 0.22);
  cursor: ew-resize;
  transform: translate(-50%, -50%);
}

.trim-handle:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 3px;
}

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

  .sidebar {
    border-bottom: 0;
  }

  .workspace {
    min-height: 70vh;
  }

  .workspace-export {
    top: 18px;
    right: 18px;
  }

}

@media (max-width: 520px) {
  .sidebar,
  .transport {
    padding-left: 14px;
    padding-right: 14px;
  }

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