:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-soft: #f2f1ec;
  --text: #1f2a2e;
  --muted: #5c6b72;
  --accent: #2f7c72;
  --accent-strong: #3dd1b5;
  --highlight: #ffd58a;
  --border: #e4dfd6;
  --shadow: 0 18px 40px rgba(28, 34, 40, 0.12);
  --radius-lg: 26px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --font-display: "Fraunces", serif;
  --font-body: "Inter", system-ui, sans-serif;
}

[hidden] {
  display: none !important;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text);
  background: radial-gradient(circle at 12% 8%, rgba(61, 209, 181, 0.16), transparent 45%),
    radial-gradient(circle at 90% 6%, rgba(255, 213, 138, 0.22), transparent 40%),
    var(--bg);
  min-height: 100vh;
}

.app-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 32px 100px;
}

.app-shell.dragging {
  box-shadow: 0 0 0 12px rgba(61, 209, 181, 0.12);
  border-radius: 32px;
  transition: box-shadow 0.2s ease;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 0 24px;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.3px;
  font-size: 1.2rem;
  text-decoration: none;
  color: var(--text);
}

.brand-dot {
  color: var(--accent);
}

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

.credits-pill {
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  background: rgba(61, 209, 181, 0.15);
  border: 1px solid rgba(61, 209, 181, 0.35);
}

.profile-menu {
  position: relative;
}

.profile-menu summary {
  list-style: none;
}

.profile-menu summary::-webkit-details-marker {
  display: none;
}

.profile-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
}

.user-avatar {
  font-weight: 600;
  color: var(--accent);
}

.profile-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 16px;
  min-width: 200px;
  display: grid;
  gap: 10px;
  z-index: 10;
}

.profile-menu:not([open]) .profile-dropdown {
  display: none;
}

.profile-email {
  font-size: 0.85rem;
  color: var(--muted);
}

.button {
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-family: var(--font-body);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.button.primary {
  background: linear-gradient(135deg, #39c6a3, #63e1cf);
  color: #0f1f1c;
  box-shadow: 0 12px 24px rgba(61, 209, 181, 0.3);
}

.button.primary:hover {
  transform: translateY(-1px);
}

.button.ghost {
  color: var(--text);
  background: rgba(47, 124, 114, 0.08);
  border: 1px solid rgba(47, 124, 114, 0.2);
}

.wizard {
  display: grid;
  gap: 36px;
}

.upload-hero {
  display: grid;
  gap: 18px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.upload-copy h1 {
  font-family: var(--font-display);
  margin: 0 0 12px;
  font-size: clamp(2rem, 3.6vw, 3rem);
}

.upload-copy p {
  margin: 0;
  color: var(--muted);
}

.upload-zone {
  position: relative;
  border: 2px dashed rgba(47, 124, 114, 0.25);
  border-radius: var(--radius-md);
  padding: 36px;
  text-align: center;
  background: rgba(61, 209, 181, 0.08);
  cursor: pointer;
  transition: border 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.upload-zone:hover {
  border-color: var(--accent);
  background: rgba(61, 209, 181, 0.16);
}

.upload-zone.dragging {
  border-color: var(--accent-strong);
  background: rgba(61, 209, 181, 0.24);
  box-shadow: 0 0 0 6px rgba(61, 209, 181, 0.12);
}

.upload-zone input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.upload-meta {
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

.progress {
  height: 8px;
  border-radius: 999px;
  background: rgba(31, 42, 46, 0.1);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  transition: width 0.2s ease;
}

.editor {
  display: grid;
  gap: 24px;
}

.video-shell {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 20px;
}

.video-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #e9e6df;
  border-radius: var(--radius-md);
  overflow: hidden;
}

.video-stage video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.overlay-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  pointer-events: none;
  z-index: 2;
}

.overlay-canvas.active {
  pointer-events: auto;
}

.draw-tip {
  position: absolute;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(31, 42, 46, 0.85);
  color: #fff;
  font-size: 0.75rem;
  transform: translate(-50%, -140%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 3;
}

.draw-tip.visible {
  opacity: 1;
}

.preview-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  background: rgba(247, 246, 242, 0.85);
  font-size: 0.95rem;
}

.processing-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(247, 246, 242, 0.82);
  backdrop-filter: blur(6px);
  z-index: 4;
}

.processing-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 24px 30px;
  text-align: center;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: grid;
  gap: 8px;
}

.processing-sub {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.processing-elapsed {
  margin: 0;
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 600;
}

.progress-ring {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 4px solid rgba(61, 209, 181, 0.2);
  border-top-color: var(--accent);
  animation: spin 1.1s linear infinite;
  margin: 0 auto;
}

.magic-bar {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 20px;
  display: grid;
  gap: 16px;
}

.magic-bar.shake {
  animation: shake 0.35s ease;
}

.mode-toggle {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.mode-btn {
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--muted);
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  font-family: var(--font-body);
  transition: all 0.2s ease;
}

.mode-btn.is-active {
  background: rgba(61, 209, 181, 0.18);
  color: var(--text);
  border-color: rgba(61, 209, 181, 0.4);
}

.mode-fields {
  display: grid;
  gap: 12px;
}

.mode-field label {
  font-size: 0.85rem;
  color: var(--muted);
}

.mode-field input {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-soft);
  font-family: var(--font-body);
}

.magic-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.credits-estimate {
  font-size: 0.9rem;
  color: var(--accent);
}

.helper-text {
  font-size: 0.85rem;
  color: var(--muted);
}

.timeline {
  display: grid;
  gap: 8px;
}

.timeline-track {
  position: relative;
  height: 28px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  overflow: hidden;
}

.timeline-selection {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 0%;
  width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(61, 209, 181, 0.4);
  background: linear-gradient(90deg, rgba(61, 209, 181, 0.2), rgba(63, 139, 245, 0.15));
  display: flex;
  justify-content: space-between;
  padding: 0 6px;
  cursor: grab;
  user-select: none;
}

.timeline-selection.dragging {
  cursor: grabbing;
}

.timeline-handle {
  width: 16px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.timeline-handle::before {
  content: "";
  width: 2px;
  height: 12px;
  background: rgba(31, 42, 46, 0.8);
  border-radius: 1px;
}

.timeline-handle.left,
.timeline-handle.right {
  cursor: ew-resize;
}

.timeline-tooltip {
  position: absolute;
  top: -30px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(31, 42, 46, 0.85);
  padding: 4px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  color: #fff;
  opacity: 0;
  pointer-events: none;
}

.timeline-handle.dragging .timeline-tooltip {
  opacity: 1;
}

.timeline-playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0%;
  width: 1px;
  background: var(--highlight);
  z-index: 3;
}

.playhead-tip {
  position: absolute;
  top: -6px;
  left: -4px;
  width: 8px;
  height: 8px;
  background: var(--highlight);
  transform: rotate(45deg);
  border-radius: 2px;
}

.model-help {
  font-size: 0.85rem;
  color: var(--muted);
}

.result {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 24px;
  display: grid;
  gap: 18px;
}

.result-header h2 {
  font-family: var(--font-display);
  margin: 0 0 8px;
}

.video-compare-container {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #e9e6df;
  width: 100%;
  --compare-width: 100%;
}

.video-compare-container::before {
  content: "";
  display: block;
  padding-top: 56.25%;
}

.video-compare-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.video-base {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.video-clipper {
  position: absolute;
  inset: 0;
  width: 50%;
  height: 100%;
  overflow: hidden;
  z-index: 2;
}

.video-compare {
  position: absolute;
  inset: 0;
  width: var(--compare-width);
  height: 100%;
}

.slider-handle {
  position: absolute;
  top: 0;
  left: 50%;
  width: 2px;
  height: 100%;
  transform: translateX(-50%);
  z-index: 3;
  cursor: ew-resize;
}

.handle-line {
  width: 2px;
  height: 100%;
  background: rgba(31, 42, 46, 0.6);
  box-shadow: 0 0 0 6px rgba(61, 209, 181, 0.2);
}

.handle-circle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(31, 42, 46, 0.15);
  color: #1f2a2e;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  box-shadow: 0 10px 24px rgba(31, 42, 46, 0.15);
}

.compare-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.8);
  color: var(--muted);
  font-size: 0.9rem;
  z-index: 4;
}

.video-compare-container.ready .compare-loading {
  display: none;
}

.result-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.debug-panel {
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 16px;
  box-shadow: var(--shadow);
}

.debug-panel summary {
  cursor: pointer;
  font-weight: 600;
}

.status-block {
  margin-top: 16px;
  display: grid;
  gap: 8px;
}

.status-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
}

.status-pill {
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(31, 42, 46, 0.08);
  font-size: 0.8rem;
}

.log {
  margin-top: 12px;
  max-height: 140px;
  overflow-y: auto;
  background: var(--surface-soft);
  border-radius: var(--radius-md);
  padding: 12px;
  font-size: 0.8rem;
  color: var(--muted);
}

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

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-6px);
  }
  50% {
    transform: translateX(6px);
  }
  75% {
    transform: translateX(-4px);
  }
}

@media (max-width: 900px) {
  .app-shell {
    padding: 20px;
  }

  .header-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .magic-actions {
    flex-direction: column;
    align-items: flex-start;
  }
}
