/* =====================================================================
   VideoStudio Pro - Mobile-first CapCut-like UI
   ===================================================================== */

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --bg:        #0a0a0a;
  --bg-2:     #131316;
  --surface:  #1c1c1e;
  --surface-2:#2a2a2e;
  --border:   #2a2a2e;
  --text:     #f5f5f7;
  --text-2:   #a1a1a6;
  --text-3:   #6e6e73;
  --accent:   #fe2c55;
  --accent-2: #25f4ee;
  --warn:     #ff9f0a;
  --ok:       #30d158;
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --topbar-h: 48px;
  --playbar-h: 56px;
  --bottomnav-h: calc(64px + var(--safe-bottom));
  --sheet-h: 70vh;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr auto auto var(--bottomnav-h);
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  padding-top: var(--safe-top);
}

/* ============ Top bar ============ */
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 0 8px;
  background: rgba(10,10,10,0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}
.project-name {
  flex: 1; font-size: 15px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-align: center;
}
.topbar-actions { display: flex; gap: 4px; }

.iconbtn {
  min-width: 40px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: none; color: var(--text);
  font-size: 18px; border-radius: 8px;
  transition: background .15s;
  cursor: pointer;
}
.iconbtn:active { background: var(--surface-2); }
.iconbtn.small { min-width: 32px; height: 28px; font-size: 14px; }
.iconbtn.primary {
  background: var(--accent); color: #fff;
  font-weight: 700;
}
.iconbtn.play {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 16px;
}

/* ============ Stage / preview ============ */
.stage {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  background: #000;
  overflow: hidden;
  min-height: 0;
}
.stage-inner {
  position: relative;
  height: 100%; width: 100%;
  display: flex; align-items: center; justify-content: center;
}
#preview {
  max-width: 100%; max-height: 100%;
  display: block;
  background: #000;
  box-shadow: 0 0 60px rgba(0,0,0,0.5);
  border-radius: 4px;
}
.aspect-toggle {
  position: absolute; top: 8px; left: 8px;
  display: flex; gap: 4px;
  background: rgba(0,0,0,0.6);
  border-radius: 8px; padding: 2px;
  backdrop-filter: blur(10px);
}
.aspect-toggle button {
  background: transparent; border: none; color: var(--text-2);
  font-size: 11px; padding: 4px 8px; border-radius: 6px;
  font-weight: 600;
}
.aspect-toggle button.active { background: var(--accent); color: #fff; }

.time-display {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.7);
  padding: 4px 10px; border-radius: 12px;
  font-size: 11px; font-variant-numeric: tabular-nums;
  color: var(--text-2); font-weight: 500;
  backdrop-filter: blur(10px);
}

/* ============ Playbar ============ */
.playbar {
  height: var(--playbar-h);
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 0 12px;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.zoom-controls {
  margin-left: auto; display: flex; gap: 2px;
}

/* ============ Timeline ============ */
.timeline-wrap {
  background: var(--bg-2);
  padding: 4px 8px 8px;
  min-height: 130px;
  max-height: 200px;
  overflow: hidden;
  position: relative;
}
.timeline-ruler {
  height: 18px;
  background: var(--surface);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
  font-size: 9px;
  color: var(--text-3);
}
.timeline-ruler::before {
  content: ''; position: absolute; inset: 0;
  background-image:
    linear-gradient(to right, var(--surface-2) 1px, transparent 1px),
    linear-gradient(to right, var(--border) 1px, transparent 1px);
  background-size: 20px 100%, 100px 100%;
}
.timeline-tracks {
  margin-top: 4px;
  display: flex; flex-direction: column; gap: 4px;
  position: relative;
  min-height: 100px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}
.track {
  height: 36px;
  background: var(--surface);
  border-radius: 6px;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
  min-width: 100%;
}
.track.audio { height: 28px; background: #1a2a1a; }
.track.text { height: 28px; background: #2a1a2a; }
.track.sticker { height: 28px; background: #2a2a1a; }

.clip {
  position: absolute;
  top: 2px; bottom: 2px;
  background: linear-gradient(180deg, #3a3a3e, #2a2a2e);
  border: 1px solid var(--surface-2);
  border-radius: 4px;
  display: flex; align-items: center; padding: 0 6px;
  overflow: hidden; white-space: nowrap;
  font-size: 10px; color: var(--text);
  cursor: pointer;
  touch-action: none;
}
.clip.video { background: linear-gradient(180deg, #2d3a5e, #1e2a4a); border-color: #4a6db8; }
.clip.audio { background: linear-gradient(180deg, #2d5e3a, #1e4a2a); border-color: #4ab86d; top:1px; bottom:1px; }
.clip.text { background: linear-gradient(180deg, #5e2d5e, #4a1e4a); border-color: #b84ab8; }
.clip.image { background: linear-gradient(180deg, #5e3a2d, #4a2a1e); border-color: #b86d4a; }
.clip.sticker { background: linear-gradient(180deg, #5e5e2d, #4a4a1e); border-color: #b8b84a; }

.clip-thumb {
  width: 100%; height: 100%;
  background-size: cover; background-position: center;
  border-radius: 3px;
}
.clip-label {
  position: absolute; left: 4px; top: 50%; transform: translateY(-50%);
  font-size: 9px; color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
  pointer-events: none;
}
.clip.trim-handle {
  position: absolute; top: 0; bottom: 0; width: 12px;
  background: rgba(255,255,255,0.3);
  border-radius: 2px;
  cursor: ew-resize;
  display: none;
}
.clip.selected { outline: 2px solid var(--accent); outline-offset: -1px; z-index: 2; }
.clip.selected .clip.trim-handle { display: block; }

.playhead-line {
  position: absolute; top: 0; bottom: 0; width: 2px;
  background: var(--accent);
  pointer-events: none;
  z-index: 10;
  box-shadow: 0 0 8px var(--accent);
}
.playhead-line::before {
  content: ''; position: absolute; top: -4px; left: -7px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 8px rgba(254,44,85,0.6);
}

/* ============ Bottom nav ============ */
.bottomnav {
  display: flex;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  padding: 4px 4px calc(4px + var(--safe-bottom));
  overflow-x: auto;
  scrollbar-width: none;
}
.bottomnav::-webkit-scrollbar { display: none; }
.navbtn {
  flex: 1 0 auto;
  min-width: 64px;
  background: transparent; border: none;
  color: var(--text-2);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 10px; padding: 4px;
  cursor: pointer;
}
.nav-ico {
  font-size: 20px; line-height: 1;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  transition: all .15s;
}
.navbtn.active .nav-ico {
  background: linear-gradient(180deg, var(--accent), #c4223f);
  color: #fff;
}
.navbtn.active { color: var(--accent); }
.nav-label { font-size: 10px; font-weight: 500; }

/* ============ Sheet (bottom sheet) ============ */
.sheet-scrim {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  opacity: 0; pointer-events: none;
  transition: opacity .25s;
  z-index: 50;
}
.sheet-scrim.open { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: var(--sheet-h);
  background: var(--bg-2);
  border-radius: 16px 16px 0 0;
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.2,.9,.3,1);
  z-index: 51;
  display: flex; flex-direction: column;
  padding-bottom: var(--safe-bottom);
  box-shadow: 0 -10px 40px rgba(0,0,0,0.6);
}
.sheet.open { transform: translateY(0); }
.sheet-handle {
  width: 36px; height: 4px;
  background: var(--surface-2);
  border-radius: 2px;
  margin: 8px auto;
  flex-shrink: 0;
}
.sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 16px 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sheet-header h2 { font-size: 16px; font-weight: 600; }
.sheet-body {
  flex: 1; overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

/* ============ Modal ============ */
.modal-scrim {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
  padding: 16px;
}
.modal-scrim.open { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--bg-2);
  border-radius: 12px;
  width: 100%; max-width: 480px;
  max-height: 85vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-body {
  flex: 1; overflow-y: auto;
  padding: 16px;
}

/* ============ Form controls ============ */
.input, .textarea, .select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--accent); }
.textarea { resize: vertical; min-height: 80px; }
.label {
  display: block;
  font-size: 12px; color: var(--text-2);
  margin-bottom: 6px; margin-top: 12px;
  font-weight: 500;
}
.label:first-child { margin-top: 0; }

.btn {
  width: 100%;
  padding: 12px;
  background: var(--accent); color: #fff;
  border: none; border-radius: 8px;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}
.btn:active { opacity: 0.7; }
.btn.secondary { background: var(--surface); color: var(--text); }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn-row { display: flex; gap: 8px; margin-top: 12px; }
.btn-row .btn { flex: 1; }

/* ============ Sheet content patterns ============ */
.section-title {
  font-size: 12px; color: var(--text-2);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin: 16px 0 8px;
  font-weight: 600;
}
.section-title:first-child { margin-top: 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 8px;
  text-align: center;
  cursor: pointer;
  font-size: 11px;
  color: var(--text);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  transition: all .15s;
}
.tile:active { transform: scale(0.97); background: var(--surface-2); }
.tile .tile-ico { font-size: 24px; }
.tile.selected { border-color: var(--accent); background: rgba(254,44,85,0.15); }

.filter-preview {
  width: 100%; aspect-ratio: 1.5;
  background-size: cover; background-position: center;
  border-radius: 6px;
  margin-bottom: 4px;
}

.slider-row {
  display: flex; align-items: center; gap: 12px;
  margin: 8px 0;
}
.slider-row label {
  flex: 0 0 80px; margin: 0;
  font-size: 12px; color: var(--text-2);
}
.slider-row input[type=range] {
  flex: 1;
  -webkit-appearance: none; appearance: none;
  height: 4px; background: var(--surface-2);
  border-radius: 2px; outline: none;
}
.slider-row input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}
.slider-row input[type=range]::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: none;
}
.slider-row .val {
  flex: 0 0 50px; text-align: right;
  font-size: 11px; color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

/* ============ Toast ============ */
.toast {
  position: fixed; bottom: calc(var(--bottomnav-h) + 16px);
  left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--surface);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 20px;
  font-size: 13px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  opacity: 0; pointer-events: none;
  transition: all .25s;
  z-index: 200;
  max-width: 80%; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--accent); color: #fff; }
.toast.success { background: var(--ok); color: #fff; }

/* ============ Loading overlay ============ */
.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 300;
  gap: 16px;
}
.loading-overlay[hidden] { display: none; }
.loading-spinner {
  width: 48px; height: 48px;
  border: 3px solid var(--surface-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: var(--text); font-size: 14px; }

/* ============ Progress bar ============ */
.progress {
  width: 100%; height: 4px;
  background: var(--surface-2);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 8px;
}
.progress-fill {
  height: 100%; background: var(--accent);
  transition: width .2s;
  width: 0;
}

/* ============ Chip ============ */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--surface); border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 12px;
  font-size: 11px; color: var(--text);
  cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

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

/* ============ Templates list ============ */
.template-card {
  background: var(--surface);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  display: flex; align-items: center; gap: 12px;
}
.template-card:active { background: var(--surface-2); }
.template-thumb {
  width: 56px; height: 56px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 8px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
}
.template-info { flex: 1; min-width: 0; }
.template-info h4 { font-size: 14px; font-weight: 600; }
.template-info p { font-size: 11px; color: var(--text-2); margin-top: 2px; }

/* ============ Preview animation styles for text ============ */
.text-overlay {
  position: absolute;
  padding: 6px 12px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border-radius: 6px;
  font-weight: 700;
  text-shadow: 0 2px 4px rgba(0,0,0,0.6);
  pointer-events: none;
}

/* ============ Templates panel ============ */
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px; background: var(--surface);
  border-radius: 8px; margin-bottom: 6px;
  cursor: pointer;
}
.list-item:active { background: var(--surface-2); }
.list-item .ico { font-size: 24px; }
.list-item .info { flex: 1; min-width: 0; }
.list-item .info h4 { font-size: 14px; font-weight: 500; }
.list-item .info p { font-size: 11px; color: var(--text-2); }

/* ============ Responsive: bigger screens ============ */
@media (min-width: 768px) {
  :root { --topbar-h: 56px; --playbar-h: 64px; }
  .stage #preview { max-height: calc(100vh - 350px); }
  .grid { grid-template-columns: repeat(6, 1fr); }
  .nav-label { font-size: 12px; }
}

/* ============ Hint banner ============ */
.hint-banner {
  background: linear-gradient(135deg, rgba(254,44,85,0.15), rgba(37,244,238,0.1));
  border: 1px solid var(--accent);
  padding: 12px;
  border-radius: 8px;
  font-size: 12px;
  color: var(--text);
  margin-bottom: 12px;
  line-height: 1.4;
}

/* ============ Empty state ============ */
.empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-3);
  font-size: 13px;
}
.empty .ico { font-size: 48px; display: block; margin-bottom: 8px; opacity: 0.4; }

/* ============ Help text ============ */
.help-text {
  font-size: 11px; color: var(--text-3);
  margin-top: 4px; line-height: 1.4;
}

/* ============ Picker (file input fallback) ============ */
input[type=file] { display: none; }
