/* ============================================================
   REVEXTEND — design tokens
   ============================================================ */
:root {
  --void: #0b0221;
  --horizon: #1a0e3d;
  --panel: #170b33;
  --line: #3a2266;
  --hotline: #ff2ec4;
  --laser: #00f0ff;
  --sunbeam: #ffd93d;
  --grape: #7b2ff7;
  --chrome: #ece8fb;
  --chrome-dim: #a99fd1;
  --danger: #ff4d6d;
  --font-display: "Monoton", cursive;
  --font-ui: "Rajdhani", sans-serif;
  --radius: 10px;
  --shadow-glow: 0 0 24px rgba(255, 46, 196, .35);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--void);
  background-image:
    radial-gradient(ellipse at 50% -10%, rgba(123,47,247,.35), transparent 55%),
    linear-gradient(180deg, var(--void), #0a0119 60%);
  color: var(--chrome);
  font-family: var(--font-ui);
  font-weight: 500;
  min-height: 100vh;
  overflow-x: hidden;
}

.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 999;
  background-image: repeating-linear-gradient(0deg, rgba(255,255,255,.02) 0px, rgba(255,255,255,.02) 1px, transparent 1px, transparent 3px);
  mix-blend-mode: overlay;
  opacity: .5;
}

a { color: var(--laser); }
button { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--laser);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ============================================================
   TOPBAR — wordmark + functional sun-ring (doubles as progress ring)
   ============================================================ */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 40px) 22px;
  border-bottom: 1px solid var(--line);
  position: relative;
}
.topbar::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--hotline), var(--laser), transparent);
}

.wordmark-row { display: flex; align-items: center; gap: 16px; }

.sunring { width: 56px; height: 56px; flex: none; }
.sunring-track {
  fill: none; stroke: var(--line); stroke-width: 3;
}
.sunring-progress {
  fill: none; stroke: url(#sunGrad); stroke-width: 3; stroke-linecap: round;
  stroke-dasharray: 314; stroke-dashoffset: 314;
  transform: rotate(-90deg); transform-origin: 60px 60px;
  transition: stroke-dashoffset .25s linear;
}
.sunring-core { fill: url(#sunGrad); opacity: .9; }
.sunring.is-spinning .sunring-core { animation: sun-pulse 2.4s ease-in-out infinite; }
@keyframes sun-pulse { 0%,100% { opacity: .75; } 50% { opacity: 1; } }

.wordmark {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(22px, 4vw, 34px);
  margin: 0;
  line-height: 1;
  letter-spacing: 1px;
  background: linear-gradient(180deg, #fff 0%, var(--laser) 45%, var(--hotline) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 10px rgba(0,240,255,.35));
}
.tagline {
  margin: 4px 0 0; font-size: 13px; letter-spacing: .04em; color: var(--chrome-dim); text-transform: uppercase;
}
.tagline-brand { color: var(--sunbeam); }

.install-btn {
  background: transparent; border: 1px solid var(--line); color: var(--chrome);
  padding: 8px 14px; border-radius: 999px; font-size: 13px; cursor: pointer;
}
.install-btn:hover { border-color: var(--laser); color: var(--laser); }

/* ============================================================
   LAYOUT — stage rail + workspace
   ============================================================ */
.app-shell {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 0;
  min-height: calc(100vh - 100px);
}

.stage-rail {
  border-right: 1px solid var(--line);
  padding: 24px 12px;
  display: flex; flex-direction: column; gap: 6px;
}
.stage-btn {
  display: flex; align-items: baseline; gap: 10px;
  background: transparent; border: 1px solid transparent; color: var(--chrome-dim);
  padding: 12px 12px; border-radius: var(--radius); cursor: pointer; text-align: left;
  font-size: 15px; font-weight: 600; letter-spacing: .02em;
  transition: background .15s, color .15s, border-color .15s;
}
.stage-num { font-family: var(--font-ui); font-size: 12px; color: var(--grape); font-weight: 700; }
.stage-btn:hover:not(:disabled) { background: rgba(255,255,255,.04); color: var(--chrome); }
.stage-btn.is-active { color: var(--chrome); border-color: var(--hotline); background: rgba(255,46,196,.08); box-shadow: inset 3px 0 0 var(--hotline); }
.stage-btn.is-active .stage-num { color: var(--hotline); }
.stage-btn:disabled { opacity: .35; cursor: not-allowed; }

.workspace { padding: clamp(16px, 3vw, 32px); display: flex; flex-direction: column; gap: 22px; max-width: 980px; }

/* ============================================================
   PREVIEW DOCK
   ============================================================ */
.preview-dock { display: flex; flex-direction: column; gap: 10px; }
.preview-frame {
  position: relative; width: 100%; max-width: 480px;
  aspect-ratio: 16/9; background: #000;
  border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--line); box-shadow: var(--shadow-glow);
  container-type: size; container-name: preview;
}
.preview-frame video, .preview-frame canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000;
}
.preview-frame video.is-hidden-under-canvas { visibility: hidden; }

.crop-overlay { position: absolute; inset: 0; }
.crop-box {
  position: absolute; border: 2px dashed var(--laser); background: rgba(0,240,255,.08);
  touch-action: none;
}
.crop-handle {
  position: absolute; width: 14px; height: 14px; background: var(--laser); border-radius: 50%;
  transform: translate(-50%, -50%); cursor: nwse-resize; touch-action: none;
}
.crop-handle[data-handle="nw"] { top: 0; left: 0; }
.crop-handle[data-handle="ne"] { top: 0; left: 100%; cursor: nesw-resize; }
.crop-handle[data-handle="sw"] { top: 100%; left: 0; cursor: nesw-resize; }
.crop-handle[data-handle="se"] { top: 100%; left: 100%; }

.text-layer-overlay { position: absolute; inset: 0; }
.text-layer-node {
  position: absolute; transform: translate(-50%, -50%);
  cursor: grab; user-select: none; white-space: nowrap; touch-action: none;
  padding: 2px 6px; outline: 1px dashed transparent;
}
.text-layer-node:hover, .text-layer-node.is-selected { outline-color: var(--laser); }
.text-layer-node.is-dragging { cursor: grabbing; }

.preview-badge {
  position: absolute; top: 8px; left: 8px; background: rgba(11,2,33,.85);
  border: 1px solid var(--hotline); color: var(--sunbeam); font-size: 11px; font-weight: 700;
  padding: 4px 8px; border-radius: 999px; letter-spacing: .04em; text-transform: uppercase;
}

.preview-controls { display: flex; align-items: center; gap: 10px; max-width: 480px; }
.icon-btn {
  background: var(--panel); border: 1px solid var(--line); color: var(--chrome);
  width: 36px; height: 36px; border-radius: 50%; cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center; flex: none;
}
.icon-btn:hover { border-color: var(--laser); }
.scrubber { flex: 1; }
.time-readout { font-size: 12px; color: var(--chrome-dim); white-space: nowrap; font-variant-numeric: tabular-nums; }

input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 4px;
  background: var(--line); border-radius: 999px; outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--laser); box-shadow: 0 0 10px rgba(0,240,255,.7); cursor: pointer; border: none;
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%; background: var(--laser);
  box-shadow: 0 0 10px rgba(0,240,255,.7); cursor: pointer; border: none;
}

/* ============================================================
   STAGES + PANELS
   ============================================================ */
.stage { display: none; flex-direction: column; gap: 18px; }
.stage.is-active { display: flex; }

.panel {
  background: linear-gradient(180deg, var(--panel), var(--horizon));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px;
}
.panel-title {
  margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .12em;
  color: var(--sunbeam); font-weight: 700;
}
.panel-note { margin: 0 0 12px; font-size: 13px; color: var(--chrome-dim); line-height: 1.5; }
.panel-note-sm { font-size: 12px; }

/* dropzone */
.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius);
  padding: clamp(30px, 8vw, 60px) 20px; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.is-dragover { border-color: var(--hotline); background: rgba(255,46,196,.05); }
.dropzone-icon { width: 48px; height: 48px; fill: var(--laser); margin-bottom: 10px; filter: drop-shadow(0 0 8px rgba(0,240,255,.5)); }
.dropzone-title { font-size: 20px; font-weight: 700; margin: 0 0 4px; }
.dropzone-sub { margin: 0; color: var(--chrome-dim); font-size: 14px; }

.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.meta-item { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.meta-k { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--chrome-dim); }
.meta-v { display: block; font-size: 15px; font-weight: 700; margin-top: 2px; word-break: break-word; }

/* buttons */
.btn {
  font-family: var(--font-ui); font-weight: 700; letter-spacing: .03em; font-size: 15px;
  padding: 12px 22px; border-radius: 999px; border: 1px solid transparent; cursor: pointer;
  transition: transform .1s, box-shadow .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: linear-gradient(90deg, var(--hotline), var(--grape)); color: #fff; box-shadow: 0 0 18px rgba(255,46,196,.4); }
.btn-primary:hover:not(:disabled) { box-shadow: 0 0 26px rgba(255,46,196,.65); }
.btn-secondary { background: transparent; border-color: var(--laser); color: var(--laser); }
.btn-secondary:hover:not(:disabled) { background: rgba(0,240,255,.1); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--chrome-dim); }
.btn-ghost:hover:not(:disabled) { border-color: var(--chrome-dim); color: var(--chrome); }
.btn-sm { padding: 8px 14px; font-size: 13px; }

.stage-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

/* chips */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  background: transparent; border: 1px solid var(--line); color: var(--chrome-dim);
  padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 600; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center;
}
.chip:hover { border-color: var(--laser); color: var(--chrome); }
.chip.is-active { background: var(--laser); border-color: var(--laser); color: var(--void); }
.chip-vhs { border-color: var(--sunbeam); color: var(--sunbeam); margin-bottom: 16px; }
.chip-vhs:hover { background: rgba(255,217,61,.12); }
.chip.chip-vhs.is-active { background: var(--sunbeam); border-color: var(--sunbeam); color: var(--void); }

/* trim track */
.trim-track { position: relative; height: 36px; background: var(--line); border-radius: 999px; margin: 10px 0; }
.trim-range { position: absolute; top: 0; bottom: 0; background: linear-gradient(90deg, var(--hotline), var(--grape)); border-radius: 999px; }
.trim-handle {
  position: absolute; top: 50%; width: 22px; height: 22px; border-radius: 50%;
  background: var(--chrome); border: 3px solid var(--hotline); transform: translate(-50%, -50%);
  cursor: ew-resize; touch-action: none;
}
.trim-readout { display: flex; justify-content: space-between; font-size: 13px; color: var(--chrome-dim); font-variant-numeric: tabular-nums; }
.trim-selected { color: var(--sunbeam); font-weight: 700; }

/* sliders grid */
.slider-grid { display: flex; flex-direction: column; gap: 14px; }
.slider-row { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--chrome-dim); font-weight: 600; }

/* toggle switch */
.toggle-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; font-size: 14px; font-weight: 600; }
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track {
  position: absolute; inset: 0; background: var(--line); border-radius: 999px; cursor: pointer; transition: background .15s;
}
.switch-track::before {
  content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: var(--chrome);
  border-radius: 50%; transition: transform .15s;
}
.switch input:checked + .switch-track { background: var(--hotline); }
.switch input:checked + .switch-track::before { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--laser); outline-offset: 2px; }

/* text layer list */
.text-add-row { display: flex; gap: 8px; margin-bottom: 12px; }
.text-add-row input[type="text"] {
  flex: 1; background: var(--panel); border: 1px solid var(--line); color: var(--chrome);
  border-radius: 8px; padding: 10px 12px; font-family: var(--font-ui); font-size: 14px;
}
.text-layer-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.text-layer-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; font-size: 13px;
}
.text-layer-list button { background: transparent; border: none; color: var(--danger); cursor: pointer; font-size: 13px; font-weight: 700; }

.file-swap-row { display: flex; align-items: center; gap: 10px; margin: 12px 0; flex-wrap: wrap; }
.file-swap-name { font-size: 12px; color: var(--chrome-dim); }

/* render progress */
.render-progress { display: flex; align-items: center; gap: 12px; }
.render-progress-bar { flex: 1; height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.render-progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--laser), var(--hotline)); transition: width .2s; }
#renderProgressLabel, #loopExportProgressLabel { font-size: 12px; color: var(--chrome-dim); white-space: nowrap; }

/* loop stage */
.mode-row .chip { padding: 10px 18px; }
.loop-status { display: flex; align-items: center; gap: 14px; margin-top: 14px; font-variant-numeric: tabular-nums; }
.size-estimate { font-size: 13px; color: var(--chrome-dim); margin: 6px 0 4px; }
.size-warning { font-size: 13px; color: var(--sunbeam); background: rgba(255,217,61,.08); border: 1px solid var(--sunbeam); border-radius: 8px; padding: 10px 12px; margin: 6px 0 14px; }

/* share stage */
.share-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 4px; }
.share-app-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* toast */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel); border: 1px solid var(--hotline); color: var(--chrome);
  padding: 12px 20px; border-radius: 999px; font-size: 14px; font-weight: 600;
  box-shadow: 0 0 20px rgba(255,46,196,.4); z-index: 1000;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* footer */
.footer {
  border-top: 1px solid var(--line); padding: 20px clamp(16px, 4vw, 40px) 36px;
  color: var(--chrome-dim); font-size: 12px; line-height: 1.6; text-align: center;
}
.footer-brand { color: var(--grape); font-weight: 700; letter-spacing: .06em; text-transform: uppercase; margin-top: 6px; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 780px) {
  .app-shell { grid-template-columns: 1fr; }
  .stage-rail {
    flex-direction: row; border-right: none; border-bottom: 1px solid var(--line);
    padding: 10px 12px; overflow-x: auto; gap: 8px;
  }
  .stage-btn { flex-direction: column; align-items: center; gap: 2px; padding: 8px 14px; white-space: nowrap; }
  .stage-btn.is-active { box-shadow: inset 0 -3px 0 var(--hotline); }
  .preview-frame { max-width: 100%; }
  .preview-controls { max-width: 100%; }
}
