* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  background: #fff;
  color: #000;
}

a { color: inherit; }
.hidden { display: none !important; }

header {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 16px 20px 12px;
  background: #fff;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

h1 { margin: 0 0 8px; font-size: 18px; font-weight: 600; letter-spacing: 0.02em; }
.tagline { margin: 0 0 8px; font-size: 13px; opacity: 0.65; }

.workflow-note,
.panel-note,
.editor-guide {
  margin: 0 0 12px;
  font-size: 12px;
  line-height: 1.45;
  opacity: 0.65;
}

.panel-note { margin-bottom: 10px; }

.editor-guide {
  padding: 6px 10px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: rgba(0, 0, 0, 0.02);
  flex-shrink: 0;
}

.import-steps {
  margin: 14px auto 0;
  padding-left: 1.2rem;
  max-width: 28rem;
  text-align: left;
  font-size: 12px;
  line-height: 1.5;
  opacity: 0.7;
}

.import-steps li { margin-bottom: 4px; }

[data-tip] { cursor: help; }
button[data-tip], .chip[data-tip], .btn[data-tip] { cursor: pointer; }
input[data-tip], select[data-tip] { cursor: help; }

.hover-tip {
  position: fixed;
  z-index: 1000;
  max-width: min(280px, calc(100vw - 24px));
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.4;
  background: #000;
  color: #fff;
  border-radius: 2px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.18);
  pointer-events: none;
}

nav.steps {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  margin-bottom: 12px;
  font-size: 13px;
}

nav.steps button,
button.btn {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

nav.steps button.active { font-weight: 600; text-decoration: none; }
nav.steps button[disabled], button.btn[disabled] { opacity: 0.4; cursor: default; text-decoration: none; }

.header-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  align-items: center;
  font-size: 13px;
}

.header-controls label { display: flex; align-items: center; gap: 6px; }

.layout {
  display: flex;
  gap: 24px;
  padding: 16px 20px 20px;
  min-height: calc(100vh - 88px);
  align-items: stretch;
}

aside.sidebar {
  flex: 0 0 220px;
  font-size: 13px;
  max-height: calc(100vh - 108px);
  overflow: auto;
}

.workspace {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#editor:not(.hidden) {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.side-panel {
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  padding-bottom: 12px;
  margin-bottom: 8px;
}

.side-panel summary {
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
  list-style: none;
}

.side-panel summary::-webkit-details-marker { display: none; }

input[type="number"], select {
  font: inherit;
  color: inherit;
  background: #fff;
  border: 0;
  border-bottom: 1px solid #000;
  padding: 2px 0;
  border-radius: 0;
  min-width: 0;
  width: 100%;
}

input[type="range"] { width: 100%; accent-color: #000; }
input:focus, select:focus { outline: 1px solid #000; outline-offset: 2px; }

.compact-label, .side-panel label { display: block; margin-bottom: 8px; }
.compact-label select { width: 100%; margin-top: 4px; }

.field-row-duo {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.slider-grid label {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
}

.slider-grid label span {
  display: flex;
  justify-content: space-between;
  margin-bottom: 2px;
}

.slider-grid output { font-weight: 600; font-variant-numeric: tabular-nums; }

.check-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 8px;
  margin: 8px 0;
  font-size: 12px;
}

.check-grid label { display: flex; align-items: center; gap: 6px; margin: 0; }

.field { margin-bottom: 8px; }
.field-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; font-size: 12px; }
.field output, .field .val { font-weight: 600; font-variant-numeric: tabular-nums; }

.size-readout {
  margin: 8px 0;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.meta-inline { margin: 0 0 8px; font-size: 12px; opacity: 0.7; }

.preset-chips, .scale-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.chip {
  padding: 5px 8px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  background: #fff;
  font: inherit;
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
}

.chip.active { background: #000; color: #fff; border-color: #000; }

.import-zone {
  border: 1px dashed rgba(0, 0, 0, 0.2);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
}

.import-zone.dragover { border-color: #000; background: rgba(0, 0, 0, 0.03); }
.import-zone p { margin: 0 0 6px; }
.hint { font-size: 12px; opacity: 0.55; }

.preview-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.88fr) minmax(0, 1.12fr);
  gap: 16px;
  margin-bottom: 16px;
  flex: 1 1 auto;
  min-height: min(560px, calc(100vh - 280px));
  align-items: stretch;
}

.preview-grid.mode-pixel,
.preview-grid.mode-overlay {
  grid-template-columns: 1fr;
}

.preview-grid.mode-pixel .pixel-panel {
  min-height: min(720px, calc(100vh - 240px));
}

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  aside.sidebar { flex: none; max-height: none; }
  .preview-grid,
  .preview-grid.mode-split {
    grid-template-columns: 1fr;
  }
  .preview-grid.mode-pixel .pixel-panel {
    min-height: min(480px, calc(100vh - 260px));
  }
}

.preview-panel {
  border: 1px solid rgba(0, 0, 0, 0.1);
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.pixel-panel {
  min-height: 0;
}

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

.tool-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.tool-row .chip { padding: 3px 7px; }
.tool-row .btn { font-size: 11px; font-weight: 400; }

.preview-body {
  flex: 1 1 auto;
  background: rgba(0, 0, 0, 0.03);
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.source-viewport {
  position: relative;
  display: grid;
  place-items: center;
  padding: 8px;
  flex: 1 1 auto;
  min-height: 180px;
}

.source-viewport video {
  grid-area: 1 / 1;
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
}

.region-overlay {
  grid-area: 1 / 1;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

.region-overlay.active {
  pointer-events: auto;
  cursor: crosshair;
}

.region-hint {
  margin: 0;
  padding: 4px 10px 8px;
  font-size: 11px;
  opacity: 0.65;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.chip-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 7px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  font-size: 11px;
  cursor: pointer;
}

.chip-toggle:has(input:checked) {
  background: #000;
  color: #fff;
  border-color: #000;
}

.chip-toggle input { margin: 0; }

.pixel-viewport {
  position: relative;
  display: grid;
  place-items: center;
  place-content: center;
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  padding: 4px;
  overflow: hidden;
}

.pixel-viewport canvas {
  grid-area: 1 / 1;
}

.pixel-viewport canvas#preview-canvas {
  display: block;
  background: #fff;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
  z-index: 1;
}

.pixel-viewport canvas#preview-canvas.tool-draw { cursor: crosshair; }
.pixel-viewport canvas#preview-canvas.tool-fill { cursor: cell; }

.pixel-viewport canvas#onion-canvas {
  pointer-events: none;
  opacity: 0.35;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  z-index: 0;
}

.preview-body.overlay-mode {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-body.overlay-mode video { position: relative; z-index: 0; max-width: 100%; max-height: 100%; }

.preview-body.overlay-mode canvas#preview-canvas {
  position: absolute;
  z-index: 1;
  opacity: 0.65;
  mix-blend-mode: multiply;
}

.transport {
  border: 1px solid rgba(0, 0, 0, 0.1);
  padding: 10px 12px;
  margin-bottom: 16px;
  flex-shrink: 0;
}

.trim-bar {
  position: relative;
  margin: 4px 0 10px;
}

.trim-track {
  position: relative;
  height: 40px;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 2px;
  overflow: visible;
  touch-action: none;
  cursor: pointer;
  user-select: none;
}

.trim-exclude {
  position: absolute;
  top: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.12);
  pointer-events: none;
}

.trim-exclude-left { left: 0; width: 0; }
.trim-exclude-right { right: 0; width: 0; }

.trim-range {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  background: rgba(255, 255, 255, 0.45);
  border-top: 2px solid #000;
  border-bottom: 2px solid #000;
  cursor: pointer;
  touch-action: none;
  z-index: 2;
}

.trim-range.slide-active {
  cursor: grab;
  background: rgba(255, 255, 220, 0.55);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.trim-range.slide-active:active {
  cursor: grabbing;
}

.trim-slide-mode .trim-range {
  cursor: grab;
}

.trim-handle {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 14px;
  padding: 0;
  border: 2px solid #000;
  background: #fff;
  cursor: ew-resize;
  touch-action: none;
  z-index: 5;
}

.trim-handle::before {
  content: '';
  position: absolute;
  top: -8px;
  bottom: -8px;
  left: -12px;
  right: -12px;
}

.trim-handle::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2px;
  height: 18px;
  margin: -9px 0 0 -1px;
  background: #000;
  pointer-events: none;
}

.trim-handle-in {
  left: 0;
  transform: translateX(-50%);
  border-radius: 3px 0 0 3px;
}

.trim-handle-out {
  right: 0;
  transform: translateX(50%);
  border-radius: 0 3px 3px 0;
}

.trim-playhead {
  position: absolute;
  top: -4px;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: #c82828;
  pointer-events: none;
  z-index: 4;
}

.trim-playhead-cap {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid #c82828;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.trim-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  font-size: 12px;
}

.trim-summary {
  flex: 1 1 auto;
  min-width: 10rem;
  font-variant-numeric: tabular-nums;
  opacity: 0.75;
}


.transport-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 12px;
  align-items: center;
  margin-bottom: 8px;
  font-size: 13px;
}


.time-label {
  margin-left: auto;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.meta-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  font-size: 12px;
  opacity: 0.75;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.transport,
.progress-wrap,
#process-btn {
  flex-shrink: 0;
}

.meta-bar strong { opacity: 1; font-weight: 600; }

.progress-wrap { margin-bottom: 16px; }
.progress-track { height: 4px; background: rgba(0, 0, 0, 0.08); overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: #000; transition: width 0.1s linear; }
.progress-text { margin: 6px 0 0; font-size: 12px; opacity: 0.7; }

#export-pane {
  position: fixed;
  right: 16px;
  top: 128px;
  width: max-content;
  min-width: 200px;
  max-width: min(360px, calc(100vw - 32px));
  z-index: 30;
  display: none;
  flex-direction: column;
  border: 1px solid rgba(0, 0, 0, 0.14);
  background: #fff;
  box-shadow: -4px 6px 24px rgba(0, 0, 0, 0.1);
}

#export-pane.open { display: flex; }
#export-pane .preview-head span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.export-viewport {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  min-height: 120px;
}

.export-viewport canvas {
  max-width: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#export-pane .meta {
  padding: 6px 10px;
  font-size: 11px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}

#export-pane .actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 0 10px 10px;
  font-size: 12px;
}

footer {
  padding: 8px 20px 16px;
  font-size: 12px;
  opacity: 0.7;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  display: flex;
  gap: 16px;
}

@media (max-width: 900px) {
  #export-pane {
    position: static;
    max-width: none;
    width: 100%;
    margin-top: 16px;
    box-shadow: none;
  }
}
