*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --orange:       #F97316;
  --orange-dark:  #EA6A0A;
  --orange-light: #FFF0E6;
  --bg:           #F2F2F7;
  --surface:      #FFFFFF;
  --surface-2:    #F8F8F8;
  --border:       #E4E4E4;
  --text:         #1A1A1A;
  --text-2:       #6B6B6B;
  --text-3:       #ABABAB;
  --shadow-sm:    0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:    0 4px 12px rgba(0,0,0,0.10), 0 2px 4px rgba(0,0,0,0.06);
  --radius:       14px;
  --radius-sm:    10px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  touch-action: none;
  padding-top:   env(safe-area-inset-top);
  padding-left:  env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ── Screens ──────────────────────────────────────────────────────────────── */

.screen { display: none; width: 100%; height: 100%; }
.screen.active { display: flex; flex-direction: column; }

/* ── Upload ───────────────────────────────────────────────────────────────── */

#upload-screen {
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.upload-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 40px 32px;
  text-align: center;
  background: var(--surface);
  border-radius: 24px;
  box-shadow: var(--shadow-md);
  max-width: 320px;
  width: 90%;
}

.brand-icon {
  width: 80px;
  height: auto;
}

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

.upload-content h1 {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -1px;
  color: var(--text);
}

#brand-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 2px;
}

#btn-new-video {
  background: none;
  border: none;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}
#btn-new-video:active { background: var(--border); }

.wordmark {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.4px;
  color: var(--text);
}

.tagline {
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.5;
  max-width: 240px;
}

.upload-divider {
  width: 40px;
  height: 3px;
  background: var(--orange);
  border-radius: 2px;
}

.upload-btn {
  display: inline-block;
  padding: 15px 36px;
  background: var(--orange);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  border-radius: var(--radius);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 4px 14px rgba(249,115,22,0.35);
  transition: opacity 0.15s, transform 0.1s;
}

.upload-btn:active {
  opacity: 0.9;
  transform: scale(0.98);
}

#video-input { display: none; }

.hint {
  font-size: 12px;
  color: var(--text-3);
}

/* ── Editor ───────────────────────────────────────────────────────────────── */

#editor-screen { flex-direction: column; background: #000; }

#canvas-wrap {
  flex: 1;
  position: relative;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  min-height: 0;
}

#canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  cursor: crosshair;
  touch-action: none;
}

/* ── Controls panel ───────────────────────────────────────────────────────── */

#controls {
  flex-shrink: 0;
  padding: 8px 22px calc(12px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 7px;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
}

/* Top info row */
#top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#frame-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

#fps-toggle {
  background: var(--orange-light);
  color: var(--orange-dark);
  padding: 4px 10px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
  border: none;
  transition: background 0.15s;
}

#fps-toggle:active { background: #FFE0CC; }

#mark-count {
  font-size: 13px;
  font-weight: 600;
  color: var(--orange);
}

/* Scrubber */
#scrubber {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  outline: none;
}

#scrubber::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--orange);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(249,115,22,0.4);
}

/* Nav buttons */
#nav-row {
  display: flex;
  gap: 8px;
}

.nav-btn {
  flex: 1;
  height: 40px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  box-shadow: var(--shadow-sm);
  transition: background 0.1s;
}

.nav-btn.large { font-size: 19px; }

.nav-btn:active { background: var(--border); }

/* Action buttons */
#action-row { display: flex; gap: 8px; }

/* Customize panel */
#customize-panel {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
#customize-panel[hidden] { display: none; }

.action-btn {
  flex: 1;
  height: 40px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  box-shadow: var(--shadow-sm);
  transition: background 0.1s, opacity 0.1s;
}

.action-btn:active  { background: var(--border); }
.action-btn:disabled { opacity: 0.4; pointer-events: none; }

.action-btn.primary {
  background: var(--orange);
  color: #fff;
  font-weight: 600;
  border-color: var(--orange);
  box-shadow: 0 3px 10px rgba(249,115,22,0.35);
}

.action-btn.primary:active {
  background: var(--orange-dark);
  border-color: var(--orange-dark);
}

.action-btn.export {
  background: var(--surface);
  color: var(--orange);
  font-weight: 600;
  border-color: var(--orange);
}

.action-btn.export:active { background: var(--orange-light); }

/* Save-to-Photos modal */
#save-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

#save-modal[hidden] { display: none; }

#save-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 20px 20px 24px;
  width: min(340px, 94vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-md);
}

#save-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}

#save-preview {
  width: 100%;
  max-height: 260px;
  border-radius: 10px;
  background: #000;
  object-fit: contain;
}

#save-instruction {
  font-size: 14px;
  color: var(--text-2);
  text-align: center;
  line-height: 1.6;
}

#save-instruction strong { color: var(--text); }

#btn-save-close {
  width: 100%;
  padding: 13px;
  background: var(--orange);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(249,115,22,0.35);
  -webkit-tap-highlight-color: transparent;
}

#btn-save-close:active { background: var(--orange-dark); }

/* ── Paywall overlay ────────────────────────────────────────────────────── */
#paywall-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
}
#paywall-overlay[hidden] { display: none; }

#paywall-card {
  background: var(--surface);
  border-radius: 24px;
  padding: 32px 28px 24px;
  width: min(340px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-md);
  position: relative;
}

#btn-paywall-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: none;
  border: none;
  font-size: 18px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}

.paywall-icon { margin-bottom: 2px; }

.paywall-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.paywall-used {
  font-size: 14px;
  color: var(--text-muted);
  margin: 0;
  text-align: center;
}

.paywall-features {
  list-style: none;
  padding: 0;
  margin: 4px 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.paywall-features li {
  font-size: 14px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}
.paywall-features li::before { content: none; }

.paywall-price-box {
  background: var(--orange-light);
  border-radius: 12px;
  padding: 14px 20px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.paywall-trial {
  font-size: 20px;
  font-weight: 700;
  color: var(--orange);
}
.paywall-then {
  font-size: 13px;
  color: var(--text-muted);
}

#btn-subscribe {
  width: 100%;
  padding: 14px;
  font-size: 16px;
}

.paywall-restore {
  background: none;
  border: none;
  color: var(--orange);
  font-size: 14px;
  cursor: pointer;
  padding: 4px;
}

.paywall-legal {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.5;
  margin: 0;
}
.paywall-legal a {
  color: var(--orange);
  text-decoration: none;
}

/* Export progress overlay */
#export-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#export-overlay[hidden] { display: none; }

#export-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 28px 28px 22px;
  width: min(320px, 88vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-md);
}

#export-status {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

#export-bar-wrap {
  width: 100%;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}

#export-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--orange);
  border-radius: 4px;
  transition: width 0.1s linear;
}

#export-pct {
  font-size: 13px;
  font-weight: 600;
  color: var(--orange);
}

#btn-cancel-export {
  margin-top: 4px;
  padding: 8px 24px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-2);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

#btn-cancel-export:active { background: var(--border); }

/* Control labels */
.ctrl-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.ctrl-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.ctrl-label-row span:last-child {
  color: var(--orange);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: none;
}

/* Trace control sliders */
.ctrl-slider {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}

.ctrl-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--orange);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(249,115,22,0.4);
}

/* Gradient swatches */
#gradient-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 2px 0;
}

#gradient-row::-webkit-scrollbar { display: none; }

.gradient-swatch {
  flex-shrink: 0;
  width: 44px;
  height: 22px;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, transform 0.1s;
  box-shadow: var(--shadow-sm);
}

.gradient-swatch:active { transform: scale(0.95); }

.gradient-swatch.selected {
  border-color: var(--orange);
  box-shadow: 0 0 0 1px var(--orange);
}

/* Status */
#status {
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
  min-height: 16px;
}

/* Hidden file input */
#video-input { display: none; }

/* Touch crosshair */
#crosshair {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  display: none;
  filter: drop-shadow(0 0 5px rgba(0,0,0,0.75));
}
