:root {
  --cream: #F7EEE5;
  --cream-2: #EEE0D1;
  --paper: #FFFAF4;
  --line: #E2D2C1;
  --green: #467A3C;
  --green-ink: #2E5427;
  --green-soft: #E1EAD9;
  --pink: #FB5FA3;
  --pink-ink: #3D0E24;
  --pink-soft: #FFE1EE;
  --ink: #22301E;
  --muted: #6D7465;
  --stage: #1E241B;
  --radius: 16px;
  --font: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Fraunces", Georgia, serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
.muted { color: var(--muted); }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  border: 0; border-radius: 999px; padding: .62em 1.15em;
  font-weight: 600; cursor: pointer; text-decoration: none;
  transition: transform .15s ease, background-color .15s ease, box-shadow .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .step-head:focus-visible, .filter-card:focus-visible, .seg button:focus-visible,
.thumb:focus-visible { outline: 3px solid var(--pink); outline-offset: 2px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-pink { background: var(--pink); color: var(--pink-ink); box-shadow: 0 6px 18px -8px rgba(251, 95, 163, .9); }
.btn-pink:hover:not(:disabled) { background: #ff73b0; }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover:not(:disabled) { background: var(--green-ink); }
.btn-ghost { background: transparent; color: var(--green-ink); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn-ghost:hover:not(:disabled) { background: var(--green-soft); box-shadow: inset 0 0 0 1.5px transparent; }
.btn-text { background: none; color: var(--muted); padding-inline: .3em; }
.btn-text:hover { color: var(--ink); }
.btn-sm { padding: .42em .85em; font-size: 13.5px; }
.btn-xl { padding: 1em 1.8em; font-size: 18px; }
.btn-xl svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.btn-xl svg circle { fill: currentColor; stroke: none; }
.btn-block { width: 100%; }

/* ---------------------------------------------------------------- landing */
.landing {
  position: relative; min-height: 100vh; overflow: hidden;
  display: grid; place-items: center; padding: 24px 16px;
}
.tunnel { position: absolute; inset: 0; pointer-events: none; }
.tunnel svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.tunnel path { stroke: var(--green); stroke-opacity: .22; stroke-width: 1.5; vector-effect: non-scaling-stroke; fill: none; }
.ring {
  position: absolute; left: 50%; top: 50%;
  width: 100vw; height: 100vh; margin: -50vh 0 0 -50vw;
  border: 2px solid var(--green); border-radius: 28px;
  opacity: 0; transform: scale(.06);
  animation: zoomout 10s cubic-bezier(.55, 0, .9, .4) infinite;
}
.ring.r2 { animation-delay: -2s; border-color: var(--pink); }
.ring.r3 { animation-delay: -4s; }
.ring.r4 { animation-delay: -6s; border-color: var(--pink); }
.ring.r5 { animation-delay: -8s; }
@keyframes zoomout {
  0%   { transform: scale(.06); opacity: 0; }
  12%  { opacity: .45; }
  100% { transform: scale(1.25); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .ring { animation: none; opacity: .25; }
  .ring.r1 { transform: scale(.35); } .ring.r2 { transform: scale(.55); }
  .ring.r3 { transform: scale(.75); } .ring.r4 { transform: scale(.92); } .ring.r5 { display: none; }
}
.landing-card {
  position: relative; text-align: center; max-width: 560px;
  background: color-mix(in srgb, var(--cream) 86%, transparent);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border-radius: 28px; padding: 44px 36px 32px;
}
.eyebrow {
  margin: 0 0 12px; color: var(--green); font-weight: 700;
  letter-spacing: .14em; text-transform: uppercase; font-size: 12.5px;
}
.landing h1 {
  font-family: var(--display); font-weight: 700; font-size: clamp(34px, 6vw, 52px);
  line-height: 1.05; letter-spacing: -.02em; margin: 0 0 16px; color: var(--green-ink);
}
.lede { margin: 0 auto 28px; max-width: 44ch; color: #4c5646; font-size: 16px; }
.hint { margin: 16px 0 0; color: var(--muted); font-size: 13.5px; }

/* ---------------------------------------------------------------- editor shell */
.editor { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 24px; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-weight: 700; font-size: 20px; color: var(--green-ink); }
.brand-mark { position: relative; width: 26px; height: 22px; }
.brand-mark i { position: absolute; border: 2px solid var(--green); border-radius: 4px; }
.brand-mark i:nth-child(1) { inset: 0; }
.brand-mark i:nth-child(2) { inset: 5px 7px; border-color: var(--pink); }
.brand-mark i:nth-child(3) { inset: 9px 11px; background: var(--green); }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.topbar-actions .muted { font-size: 13.5px; margin-right: 6px; }

.workspace {
  flex: 1; display: grid; gap: 20px; padding: 20px 24px 24px;
  grid-template-columns: minmax(0, 1fr) 320px;
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas: "stage rail" "strip rail";
  min-height: 0;
}

/* ---------------------------------------------------------------- stage */
.stage-area {
  grid-area: stage; position: relative; min-height: 340px;
  background: var(--cream-2); border-radius: var(--radius);
  display: grid; place-items: center; padding: 20px; overflow: hidden;
}
.stage {
  position: relative; background: var(--stage); border-radius: 6px; overflow: hidden;
  box-shadow: 0 24px 48px -24px rgba(34, 48, 30, .55);
}
/* Only the interactive layers capture touch; elsewhere the stage still scrolls the page. */
.tag-layer, .split-layer { touch-action: none; }
.stage canvas { display: block; width: 100%; height: 100%; }
.stage-chip {
  position: absolute; left: 10px; top: 10px; max-width: calc(100% - 20px);
  background: rgba(20, 24, 18, .62); color: #fff; font-size: 12.5px;
  padding: 4px 10px; border-radius: 999px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  pointer-events: none; backdrop-filter: blur(4px);
}

/* position tag */
.tag-layer { position: absolute; inset: 0; cursor: crosshair; }
.tag {
  position: absolute; background-size: cover; background-position: center;
  outline: 2px solid var(--pink); outline-offset: 0; border-radius: 2px;
  box-shadow: 0 0 0 4px rgba(251, 95, 163, .28);
  cursor: grab;
}
.tag-layer.dragging .tag { cursor: grabbing; }
.tag-ring {
  position: absolute; inset: -14px; border: 2px solid var(--pink); border-radius: 8px;
  animation: pulse 1.6s ease-out infinite; pointer-events: none;
}
@keyframes pulse { 0% { opacity: .9; transform: scale(.7); } 100% { opacity: 0; transform: scale(1.5); } }
@media (prefers-reduced-motion: reduce) { .tag-ring { animation: none; opacity: .6; } }
.tag-label {
  position: absolute; left: 50%; bottom: calc(100% + 12px); transform: translateX(-50%);
  background: var(--pink); color: var(--pink-ink); font-size: 12px; font-weight: 700;
  padding: 3px 9px; border-radius: 999px; white-space: nowrap; pointer-events: none;
}
.tag.below .tag-label { bottom: auto; top: calc(100% + 12px); }

/* split compare */
.split-layer { position: absolute; inset: 0; cursor: ew-resize; }
.split-line { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; transform: translateX(-1px); pointer-events: none; }
.split-line button {
  position: absolute; top: 50%; left: 50%; width: 34px; height: 34px; margin: -17px 0 0 -17px;
  border-radius: 50%; border: 0; background: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, .35);
  pointer-events: auto; cursor: ew-resize;
}
.split-line button::before { content: "‹ ›"; font-weight: 700; color: var(--green-ink); letter-spacing: 2px; }
.split-line span {
  position: absolute; bottom: 12px; font-size: 12px; font-weight: 700; color: #fff;
  background: rgba(20, 24, 18, .62); padding: 3px 9px; border-radius: 999px; white-space: nowrap;
}
.split-line span:first-child { right: 12px; }
.split-line span:last-child { left: 12px; }

/* player */
.player {
  position: absolute; left: 10px; right: 10px; bottom: 10px;
  display: flex; align-items: center; gap: 12px;
  background: rgba(20, 24, 18, .66); backdrop-filter: blur(6px);
  border-radius: 999px; padding: 6px 14px 6px 6px; color: #fff;
}
.play-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--pink); cursor: pointer; flex: none;
  display: grid; place-items: center;
}
.play-btn::before { content: ""; border-left: 12px solid var(--pink-ink); border-top: 7px solid transparent; border-bottom: 7px solid transparent; margin-left: 3px; }
.play-btn.playing::before { border: 0; width: 11px; height: 13px; margin: 0; background: linear-gradient(90deg, var(--pink-ink) 0 35%, transparent 35% 65%, var(--pink-ink) 65%); }
.player-track { flex: 1; height: 4px; background: rgba(255, 255, 255, .25); border-radius: 2px; overflow: hidden; cursor: pointer; }
.player-track div { height: 100%; width: 0; background: var(--pink); }
.player-time { font-variant-numeric: tabular-nums; font-size: 12.5px; min-width: 7ch; text-align: right; }

/* ---------------------------------------------------------------- rail */
.rail { grid-area: rail; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
/* flex: none keeps each step at full height; otherwise short windows squash and clip the steps
   (overflow: hidden lets them shrink to 0) instead of letting the rail scroll. */
.step { flex: none; border-radius: var(--radius); background: var(--paper); box-shadow: inset 0 0 0 1px var(--line); overflow: hidden; }
.step-head {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  border: 0; cursor: pointer; padding: 14px 16px; font-weight: 700; font-size: 15.5px;
  background: transparent; color: var(--green-ink);
}
.step-head b {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font-size: 13px; background: var(--green-soft); color: var(--green-ink);
}
.step.done .step-head b { background: var(--green); color: #fff; }
.step.active { background: var(--green); box-shadow: none; }
.step.active .step-head { color: #fff; }
.step.active .step-head b { background: #fff; color: var(--green); }
.step-body { display: none; padding: 2px 16px 16px; color: #F2F6EE; }
.step.active .step-body { display: flex; flex-direction: column; gap: 14px; }
.step-body p { margin: 0; font-size: 14px; }
.step-body em { color: #fff; font-style: normal; font-weight: 700; text-decoration: underline; text-decoration-color: var(--pink); text-underline-offset: 3px; }
.step-body .btn-ghost { color: #fff; box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .35); }
.step-body .btn-ghost:hover:not(:disabled) { background: rgba(255, 255, 255, .12); }
.step-body .btn-text { color: rgba(255, 255, 255, .75); }
.step-body .btn-text:hover { color: #fff; }
.step-body .btn-green { background: #fff; color: var(--green-ink); }
.step-body .btn-green:hover:not(:disabled) { background: var(--cream); }
.step-nav { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; }

.switch-row { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.switch-row > span { flex: 1; display: flex; flex-direction: column; }
.switch-row small { color: rgba(255, 255, 255, .72); font-size: 12.5px; line-height: 1.35; }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch { width: 42px; height: 24px; border-radius: 999px; background: rgba(255, 255, 255, .25); position: relative; flex: none; transition: background .15s; }
.switch::after { content: ""; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch-row input:checked + .switch { background: var(--pink); }
.switch-row input:checked + .switch::after { transform: translateX(18px); }
.switch-row input:focus-visible + .switch { outline: 3px solid var(--pink); outline-offset: 2px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; font-weight: 600; display: flex; justify-content: space-between; color: rgba(255, 255, 255, .9); }
.field-label output { font-variant-numeric: tabular-nums; color: #fff; }
input[type=range] { width: 100%; accent-color: var(--pink); }
.seg { display: flex; flex-wrap: wrap; gap: 4px; background: rgba(0, 0, 0, .16); padding: 4px; border-radius: 12px; }
.seg button {
  flex: 1 1 auto; border: 0; border-radius: 9px; padding: 6px 8px; cursor: pointer;
  background: transparent; color: #fff; font-size: 13px; font-weight: 600; line-height: 1.2;
}
.seg button small { display: block; font-weight: 400; opacity: .75; font-size: 11px; }
.seg button[aria-pressed=true] { background: #fff; color: var(--green-ink); }

.pager { display: flex; align-items: center; gap: 8px; }
.pager span { flex: 1; text-align: center; font-size: 13.5px; font-weight: 600; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn-grid .btn:first-child { grid-column: 1 / -1; }

.filter-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.filter-card {
  border: 0; padding: 6px; border-radius: 12px; cursor: pointer;
  background: rgba(255, 255, 255, .12); display: flex; flex-direction: column; gap: 6px; font-weight: 700; font-size: 13.5px; color: #fff;
}
.filter-card canvas { width: 100%; height: auto; aspect-ratio: 4 / 3; border-radius: 7px; background: var(--stage); display: block; }
.filter-card[aria-pressed=true] { background: #fff; color: var(--green-ink); box-shadow: 0 0 0 3px var(--pink); }
.filter-opts { display: flex; flex-direction: column; gap: 14px; }
.filter-opts.off { opacity: .4; pointer-events: none; }

.summary { font-size: 13px !important; color: rgba(255, 255, 255, .8); }
.progress-track { height: 8px; border-radius: 4px; background: rgba(255, 255, 255, .22); overflow: hidden; }
.progress-track div { height: 100%; width: 0; background: var(--pink); transition: width .1s linear; }
.progress-row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; margin-top: 6px; }
.result { display: flex; flex-direction: column; gap: 10px; }
.result video { width: 100%; border-radius: 10px; background: var(--stage); display: block; }

/* ---------------------------------------------------------------- strip */
.strip-area { grid-area: strip; min-width: 0; }
.strip-head { display: flex; justify-content: space-between; align-items: baseline; margin: 0 4px 8px; font-size: 14px; }
.strip-head strong { color: var(--green-ink); }
.strip {
  display: flex; gap: 10px; overflow-x: auto; padding: 10px; border-radius: var(--radius);
  background: var(--paper); box-shadow: inset 0 0 0 1px var(--line);
  scrollbar-width: thin;
}
.thumb {
  position: relative; flex: none; height: 84px; border-radius: 8px; overflow: hidden; cursor: grab;
  background: var(--stage) center / cover no-repeat; border: 0; padding: 0;
  box-shadow: 0 0 0 2px transparent; transition: box-shadow .12s;
}
.strip.locked .thumb { cursor: pointer; }
.thumb.selected { box-shadow: 0 0 0 3px var(--pink); }
.thumb .num {
  position: absolute; left: 5px; top: 5px; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 999px; background: var(--green); color: #fff; font-size: 11.5px; font-weight: 700;
  display: grid; place-items: center;
}
.thumb .del {
  position: absolute; right: 4px; top: 4px; width: 22px; height: 22px; border-radius: 50%; border: 0;
  background: rgba(20, 24, 18, .7); color: #fff; cursor: pointer; font-size: 13px; line-height: 1;
  opacity: 0; transition: opacity .12s;
}
.thumb:hover .del, .thumb:focus-within .del { opacity: 1; }
.thumb .pin {
  position: absolute; width: 9px; height: 9px; margin: -4.5px 0 0 -4.5px; border-radius: 50%;
  background: var(--pink); box-shadow: 0 0 0 2px #fff; pointer-events: none;
}
.thumb.ghost { opacity: .35; }
.thumb.chosen { cursor: grabbing; }
.add-tile {
  flex: none; height: 84px; width: 84px; border-radius: 8px; border: 2px dashed var(--line);
  background: transparent; color: var(--green); font-size: 26px; cursor: pointer;
}
.add-tile:hover { border-color: var(--green); background: var(--green-soft); }

/* ---------------------------------------------------------------- overlays */
.overlay { position: fixed; inset: 0; background: rgba(247, 238, 229, .82); display: grid; place-items: center; z-index: 50; backdrop-filter: blur(3px); }
.busy-card { text-align: center; color: var(--green-ink); font-weight: 600; }
.spinner { width: 40px; height: 40px; margin: 0 auto 12px; border-radius: 50%; border: 4px solid var(--green-soft); border-top-color: var(--pink); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.drop-veil { position: fixed; inset: 12px; border: 3px dashed var(--pink); border-radius: 24px; background: rgba(255, 225, 238, .7); display: grid; place-items: center; z-index: 60; pointer-events: none; }
.drop-veil p { font-family: var(--display); font-size: 28px; color: var(--pink-ink); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  transition: opacity .2s, transform .2s; pointer-events: none; z-index: 70; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------------------------------------------------------- responsive */
@media (min-width: 961px) {
  .editor { height: 100vh; height: 100dvh; min-height: 560px; }
  .workspace { overflow: hidden; }
  .rail { overflow-y: auto; padding-bottom: 2px; }
}
@media (max-width: 960px) {
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-areas: "stage" "strip" "rail"; padding: 16px; gap: 16px; }
  .stage-area { min-height: 0; height: 56vh; padding: 12px; }
  .topbar { padding: 12px 16px; }
}
@media (max-width: 520px) {
  .landing-card { padding: 32px 20px 24px; }
  .topbar-actions .muted { display: none; }
  .topbar { flex-wrap: wrap; row-gap: 8px; }
  .brand { font-size: 17px; white-space: nowrap; gap: 8px; }
  .topbar-actions { flex-wrap: nowrap; gap: 6px; margin-left: auto; }
  .topbar-actions .btn { font-size: 13px; padding: 7px 10px; white-space: nowrap; }
  .thumb, .add-tile { height: 68px; }
  .add-tile { width: 68px; }
}
