/* Perfect House – Industry Media • KENDAFI Logic */
:root {
  /* PIC corporate: blue + red */
  --bg: #05070f;
  --surface: #0c1220;
  --surface-2: #141c2e;
  --border: #1e2a44;
  --text: #f3f4f6;
  --muted: #8b9bb8;
  --accent: #0066ff;
  --accent-dim: #0052cc;
  --accent-bright: #1a7dff;
  --pic-red: #e60000;
  --pic-red-bright: #ff1a1a;
  --success: #22c55e;
  --warning: #fbbf24;
  --danger: #e60000;
  --radius: 12px;
  --font: "Inter", system-ui, -apple-system, sans-serif;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px 24px;
}

/* HEADER */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 20;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-mark {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, #0066ff 0%, #0047b3 45%, #e60000 100%);
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: -0.5px;
  color: #fff;
  box-shadow: 0 0 0 1px rgba(0,102,255,0.35), 0 4px 14px rgba(230,0,0,0.25);
}

.header h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.tagline {
  font-size: 0.7rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.step-indicator {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent);
  background: var(--surface-2);
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

/* PROGRESS RAIL */
.progress-rail {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 18px 0 8px;
  overflow-x: auto;
}

.rail-step {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-weight: 700;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.rail-step.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #0b1120;
  box-shadow: 0 0 0 4px rgba(0, 102, 255, 0.3);
}

.rail-step.done {
  border-color: var(--success);
  background: var(--success);
  color: #0b1120;
}

.rail-line {
  width: 28px;
  height: 2px;
  background: var(--border);
  flex-shrink: 0;
}

.rail-line.done {
  background: var(--success);
}

/* STAGES */
.stages {
  flex: 1;
  padding: 12px 0 24px;
}

.stage {
  display: none;
  animation: fadeIn 0.25s ease;
}

.stage.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.stage-header {
  margin-bottom: 20px;
}

.stage-code {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
  background: rgba(0, 102, 255, 0.15);
  padding: 3px 8px;
  border-radius: 6px;
  margin-bottom: 6px;
}

.stage-header h2 {
  font-size: 1.4rem;
  font-weight: 700;
}

.stage-header p {
  color: var(--muted);
  font-size: 0.9rem;
}

.stage-actions {
  display: flex;
  gap: 10px;
  margin-top: 28px;
  flex-wrap: wrap;
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 10px;
  border: none;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  color: inherit;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #0b1120;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-dim);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn-sm {
  padding: 7px 12px;
  font-size: 0.8rem;
}

.btn-lg {
  padding: 14px 28px;
  font-size: 1rem;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}

/* UPLOAD */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  background: var(--surface);
  transition: border-color 0.2s, background 0.2s;
  cursor: pointer;
}

.upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.06);
}

.upload-prompt svg {
  color: var(--muted);
  margin-bottom: 10px;
}

.upload-prompt p {
  margin-bottom: 4px;
}

.upload-prompt small {
  color: var(--muted);
  font-size: 0.8rem;
}

.media-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.media-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}

.media-thumb {
  width: 56px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--surface-2);
}

.media-info {
  flex: 1;
  min-width: 0;
}

.media-info strong {
  display: block;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.media-info span {
  font-size: 0.75rem;
  color: var(--muted);
}

.media-item .remove-btn {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 4px;
}

/* TEMPLATES */
.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.template-card {
  cursor: pointer;
}

.template-card input {
  display: none;
}

.card-inner {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
  height: 100%;
}

.template-card input:checked + .card-inner {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 102, 255, 0.25);
}

.ratio-preview {
  background: var(--surface-2);
  border-radius: 6px;
  margin-bottom: 10px;
  position: relative;
}

.ratio-16-9 { aspect-ratio: 16/9; }
.ratio-9-16 { aspect-ratio: 9/16; max-height: 90px; margin-inline: auto; }
.ratio-1-1 { aspect-ratio: 1; max-height: 80px; margin-inline: auto; }
.ratio-4-3 { aspect-ratio: 4/3; }
.ratio-21-9 { aspect-ratio: 21/9; }

.tv-style::after {
  content: "LOGO";
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 0.55rem;
  background: rgba(0,0,0,0.6);
  color: #fff;
  padding: 2px 5px;
  border-radius: 3px;
}

.card-inner strong {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 2px;
}

.card-inner span {
  font-size: 0.7rem;
  color: var(--muted);
}

/* EDIT LAYOUT */
.edit-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 16px;
}

@media (max-width: 760px) {
  .edit-layout {
    grid-template-columns: 1fr;
  }
}

.preview-panel {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.preview-frame {
  position: relative;
  background: #000;
  aspect-ratio: 16/9;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-frame video,
.preview-frame img#preview-image {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

/* Template fill: media FILL the chosen template frame (cover + center crop),
   exactly like the rendered output — no mismatched letterboxing */
#preview-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#review-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.logo-overlay {
  position: absolute;
  pointer-events: none;
  z-index: 5;
}

.logo-overlay img {
  display: block;
  max-width: 100%;
  height: auto;
}

.logo-overlay.pos-top-right { top: 3%; right: 3%; }
.logo-overlay.pos-top-left { top: 3%; left: 3%; }
.logo-overlay.pos-bottom-right { bottom: 3%; right: 3%; }
.logo-overlay.pos-bottom-left { bottom: 3%; left: 3%; }
.logo-overlay.pos-center { top: 50%; left: 50%; transform: translate(-50%, -50%); }

.preview-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: linear-gradient(transparent, rgba(0,0,0,0.75));
}

.icon-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  width: 32px;
  height: 32px;
}

#seek {
  flex: 1;
  accent-color: var(--accent);
}

#time-display {
  font-size: 0.7rem;
  color: #e5e7eb;
  font-variant-numeric: tabular-nums;
  min-width: 70px;
  text-align: right;
}

.tools-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tool-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.tool-group h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 10px;
}

.switch {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  cursor: pointer;
}

.switch input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.voiceover-row,
.trim-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

.trim-row label {
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 4px;
}

.trim-row input[type="number"] {
  width: 70px;
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}

.logo-controls {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.logo-controls label {
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.logo-controls select,
.logo-controls input[type="range"] {
  accent-color: var(--accent);
}

.logo-controls select {
  padding: 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}

.status-text, .hint {
  font-size: 0.8rem;
  color: var(--muted);
}

/* REVIEW */
.review-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.review-card ul {
  list-style: none;
  margin-top: 8px;
}

.review-card li {
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}

.review-card li:last-child {
  border-bottom: none;
}

.review-preview {
  max-width: 640px;
  margin: 0 auto;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

/* RENDER */
.render-panel {
  text-align: center;
  padding: 40px 20px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.render-status {
  margin-bottom: 24px;
  min-height: 60px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 0.8s linear infinite;
}

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

.progress-bar {
  height: 8px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
  max-width: 280px;
  margin: 12px auto 0;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s;
}

/* DOWNLOAD */
.download-panel {
  text-align: center;
  padding: 48px 20px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.success-mark {
  width: 64px;
  height: 64px;
  background: var(--success);
  color: #0b1120;
  font-size: 2rem;
  font-weight: 800;
  border-radius: 50%;
  display: grid;
  place-items: center;
  margin: 0 auto 16px;
}

.download-panel h3 {
  margin-bottom: 6px;
}

.download-panel p {
  color: var(--muted);
  margin-bottom: 20px;
}

/* FOOTER */
.footer {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px 0 8px;
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
  color: var(--muted);
  letter-spacing: 0.03em;
}

/* UTIL */
[hidden] {
  display: none !important;
}

/* ===== ADVANCED / API additions ===== */
.api-stock-bar {
  display: flex;
  gap: 8px;
  margin: 14px 0 8px;
  flex-wrap: wrap;
}
.api-stock-bar input {
  flex: 1;
  min-width: 160px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.stock-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}
.stock-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color 0.15s;
}
.stock-card:hover {
  border-color: var(--accent);
}
.stock-card strong {
  display: block;
  margin-bottom: 2px;
}
.text-overlay {
  position: absolute;
  left: 0;
  right: 0;
  padding: 2% 4%;
  color: #fff;
  font-weight: 700;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
  pointer-events: none;
  z-index: 6;
  text-align: center;
}
.text-overlay.pos-bottom { bottom: 8%; }
.text-overlay.pos-top { top: 8%; }
.text-overlay.pos-center { top: 50%; transform: translateY(-50%); }

.preview-frame video,
.preview-frame img#preview-image {
  filter: none;
}
.preview-frame.filter-grayscale video,
.preview-frame.filter-grayscale img { filter: grayscale(1); }
.preview-frame.filter-sepia video,
.preview-frame.filter-sepia img { filter: sepia(0.8); }
.preview-frame.filter-contrast video,
.preview-frame.filter-contrast img { filter: contrast(1.4); }
.preview-frame.filter-brightness video,
.preview-frame.filter-brightness img { filter: brightness(1.25); }
.preview-frame.filter-blur video,
.preview-frame.filter-blur img { filter: blur(1.5px); }

.render-mode {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 16px;
}
.modal[hidden] { display: none !important; }
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 400px;
  width: 100%;
}
.modal-card h3 { margin-bottom: 8px; }
.modal-card label {
  display: block;
  margin: 14px 0 6px;
  font-size: 0.85rem;
}
.modal-card input[type="url"] {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 18px;
}
.tool-group input[type="text"] {
  width: 100%;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  margin-bottom: 6px;
}
.tool-group select {
  width: 100%;
  padding: 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  margin-bottom: 6px;
}

/* Audio replacement upload */
.voiceover-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
}
.voiceover-row .btn-primary {
  background: var(--accent);
  color: #0b1120;
  border: none;
  font-weight: 600;
}
#vo-player-wrap audio {
  border-radius: 6px;
  background: var(--surface-2);
}
.tool-group .hint {
  font-size: 0.75rem;
  color: var(--muted);
}

/* ===== STORY TIMELINE ===== */
.story-timeline {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 10px 12px 12px;
}
.timeline-label {
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 8px;
  letter-spacing: 0.03em;
}
.timeline-track {
  position: relative;
  height: 36px;
  background: #0b1120;
  border-radius: 6px;
  overflow: visible;
  border: 1px solid var(--border);
}
.timeline-clip {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 0;
  right: 0;
  border-radius: 4px;
  background: linear-gradient(90deg, #0ea5e9, #38bdf8);
  opacity: 0.85;
}
.timeline-clip.active-clip {
  background: linear-gradient(90deg, #0284c7, #38bdf8);
  box-shadow: 0 0 0 1px rgba(56,189,248,0.5);
}
.trim-handle {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 12px;
  background: #38bdf8;
  border-radius: 3px;
  cursor: ew-resize;
  z-index: 5;
  box-shadow: 0 0 6px rgba(56,189,248,0.7);
}
.trim-handle::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 14px;
  background: #0b1120;
  border-radius: 1px;
}
.handle-start { left: 0; }
.handle-end { right: 0; left: auto; }
.playhead {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 2px;
  background: #fbbf24;
  left: 0;
  z-index: 6;
  pointer-events: none;
  box-shadow: 0 0 4px #fbbf24;
}
.extra-clips {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.extra-clip-bar {
  position: absolute;
  top: 4px;
  bottom: 4px;
  background: linear-gradient(90deg, #dc2626, #f87171);
  border-radius: 4px;
  opacity: 0.9;
  border: 1px solid #fca5a5;
  pointer-events: auto;
  cursor: pointer;
  font-size: 0.6rem;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  white-space: nowrap;
  padding: 0 4px;
}
.timeline-times {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

.story-clip-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.story-clip-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 0.8rem;
}
.story-clip-item .clip-color {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: #f87171;
  flex-shrink: 0;
}
.story-clip-item button {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 1rem;
}

/* Multi-clip timeline drop zone */
.timeline-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.timeline-track.drop-zone {
  min-height: 52px;
  height: auto;
  padding: 6px 4px;
  border: 2px dashed var(--border);
  transition: border-color 0.15s, background 0.15s;
}
.timeline-track.drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.08);
}
.timeline-drop-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: var(--muted);
  pointer-events: none;
  z-index: 1;
}
.timeline-drop-hint.hidden-hint {
  display: none;
}
.timeline-clips-row {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 3px;
  min-height: 40px;
  width: 100%;
  z-index: 2;
}
.tl-clip {
  position: relative;
  flex: 1 1 0;
  min-width: 48px;
  height: 40px;
  border-radius: 6px;
  background: linear-gradient(135deg, #b30000, #e60000);
  border: 2px solid #ff4d4d;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 600;
  user-select: none;
  transition: box-shadow 0.15s, transform 0.1s;
}
.tl-clip.main-clip {
  background: linear-gradient(135deg, #0052cc, #0066ff);
  border-color: #4d94ff;
}
.tl-clip.selected {
  box-shadow: 0 0 0 2px #fbbf24, 0 0 12px rgba(251, 191, 36, 0.4);
  z-index: 3;
}
.tl-clip .clip-name {
  padding: 0 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  pointer-events: none;
}
.tl-clip .clip-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 10px;
  line-height: 1;
  cursor: pointer;
  display: none;
  padding: 0;
}
.tl-clip:hover .clip-remove { display: grid; place-items: center; }
.tl-clip .edge-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: ew-resize;
  z-index: 4;
  background: transparent;
}
.tl-clip .edge-handle.left { left: 0; }
.tl-clip .edge-handle.right { right: 0; }
.tl-clip.selected .edge-handle {
  background: rgba(251, 191, 36, 0.5);
}
.timeline-times {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
#tl-trim-info {
  font-size: 0.65rem;
  color: var(--accent);
}

.selected-clip-bar {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.8rem;
}
#selected-clip-name { color: var(--accent); font-weight: 600; }
#selected-clip-range { color: var(--muted); font-variant-numeric: tabular-nums; }

.story-timeline {
  margin-top: 0;
}
.timeline-track.drop-zone {
  min-height: 64px;
}
.tl-clip {
  min-width: 72px;
  height: 48px;
  font-size: 0.7rem;
}
.timeline-clips-row {
  min-height: 48px;
  gap: 4px;
}

/* Fix empty-looking buttons */
.tools-panel .btn-primary,
.story-timeline .btn-primary,
.btn-primary {
  background: linear-gradient(135deg, #0066ff, #0052cc) !important;
  color: #ffffff !important;
  border: none !important;
  font-weight: 700 !important;
  min-height: 32px;
  padding: 8px 14px !important;
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #1a7dff, #0066ff) !important;
}
.tools-panel .btn-sm {
  min-height: 32px;
}
.trim-row input[type="number"] {
  background: #1f2937 !important;
  color: #f3f4f6 !important;
  border: 1px solid #4b5563 !important;
  min-width: 64px;
}


/* ===== PIC corporate polish (blue + red) ===== */
.header {
  border-bottom-color: #1e2a44;
}
.step-indicator {
  background: linear-gradient(135deg, rgba(0,102,255,0.2), rgba(230,0,0,0.15));
  border-color: #0066ff;
  color: #4d94ff;
}
.rail-step.active {
  background: #0066ff;
  border-color: #0066ff;
  color: #fff;
}
.rail-step.done {
  background: #e60000;
  border-color: #e60000;
  color: #fff;
}
.rail-line.done {
  background: linear-gradient(90deg, #0066ff, #e60000);
}
.stage-code {
  color: #4d94ff;
  border: 1px solid rgba(0,102,255,0.35);
}
.upload-zone.dragover,
.timeline-track.drop-zone.drag-over {
  border-color: #0066ff;
  background: rgba(0, 102, 255, 0.08);
}
.template-card input:checked + .card-inner {
  border-color: #0066ff;
  box-shadow: 0 0 0 3px rgba(0, 102, 255, 0.22);
}
.success-mark {
  background: #0066ff;
  color: #fff;
}
.progress-fill {
  background: linear-gradient(90deg, #0066ff, #e60000);
}
#selected-clip-name {
  color: #4d94ff;
}
.tl-clip.selected {
  box-shadow: 0 0 0 2px #e60000, 0 0 14px rgba(230, 0, 0, 0.45);
}
.link-btn {
  color: #4d94ff;
}
.tagline {
  color: #8b9bb8;
}
.footer {
  border-top-color: #1e2a44;
}

/* ===== MOBILE-FIRST + AE TIMELINE ===== */
.app {
  max-width: 1100px;
  padding: 0 12px 88px; /* bottom space for sticky next */
}
@media (min-width: 768px) {
  .app { padding: 0 20px 32px; }
}

.header {
  padding: 12px 0;
  gap: 8px;
}
.header h1 { font-size: 1rem; }
.logo-mark { width: 36px; height: 36px; font-size: 12px; }

.progress-rail {
  padding: 12px 0 4px;
  gap: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.rail-step { width: 32px; height: 32px; font-size: 0.7rem; }
.rail-line { width: 16px; }
@media (min-width: 600px) {
  .rail-line { width: 28px; }
  .rail-step { width: 36px; height: 36px; }
}

.stage-header h2 { font-size: 1.2rem; }
.stage-header { margin-bottom: 14px; }

/* Sticky Next — always findable on phone */
.sticky-actions {
  position: sticky;
  bottom: 0;
  z-index: 30;
  background: linear-gradient(transparent, var(--bg) 28%);
  padding: 14px 0 16px;
  margin-top: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: stretch;
}
.sticky-actions .btn-next {
  flex: 1 1 auto;
  min-width: 140px;
  min-height: 48px;
  font-size: 1rem;
  box-shadow: 0 4px 20px rgba(0, 102, 255, 0.35);
}
.sticky-actions .btn-ghost {
  min-height: 48px;
}

.inline-next {
  display: flex;
  justify-content: flex-end;
  margin: 12px 0 4px;
}
.inline-next .btn-next {
  min-height: 44px;
  padding: 10px 20px;
}

/* Preview respects template aspect */
.preview-panel {
  border-radius: var(--radius);
  overflow: hidden;
}
.preview-frame {
  width: 100%;
  max-height: 52vh;
  margin: 0 auto;
  background: #000;
}
@media (max-width: 600px) {
  .edit-layout {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }
  .preview-frame {
    max-height: 42vh;
  }
  .tools-panel {
    order: 2;
  }
  .template-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .card-inner {
    padding: 10px;
  }
  .upload-zone {
    padding: 28px 14px;
  }
}

/* AE-style transparent timeline */
.ae-timeline {
  position: relative;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  min-height: 120px;
  -webkit-overflow-scrolling: touch;
}
.ae-timeline.drag-over {
  border-color: var(--accent);
  background: rgba(0, 102, 255, 0.06);
}
.time-ruler {
  position: sticky;
  top: 0;
  height: 22px;
  background: rgba(12, 18, 32, 0.95);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  font-size: 0.6rem;
  color: var(--muted);
  z-index: 4;
  min-width: 100%;
  pointer-events: none;
}
.time-ruler .tick {
  position: absolute;
  bottom: 0;
  transform: translateX(-50%);
  border-left: 1px solid #334155;
  height: 8px;
  padding-left: 3px;
  white-space: nowrap;
}
.time-ruler .tick.major {
  height: 12px;
  color: #cbd5e1;
  border-left-color: #64748b;
}
.ae-tracks {
  position: relative;
  min-height: 96px;
  padding: 6px 0 10px;
}
.ae-track-row {
  position: relative;
  height: 36px;
  margin: 4px 0;
  background: rgba(255,255,255,0.03);
  border-radius: 4px;
}
.ae-clip {
  position: absolute;
  top: 3px;
  height: 30px;
  border-radius: 5px;
  background: rgba(0, 102, 255, 0.35);
  border: 1px solid rgba(0, 102, 255, 0.65);
  color: #e2e8f0;
  font-size: 0.65rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  padding: 0 8px;
  overflow: hidden;
  cursor: pointer;
  backdrop-filter: blur(4px);
  white-space: nowrap;
  text-overflow: ellipsis;
  box-sizing: border-box;
}
.ae-clip.selected {
  background: rgba(230, 0, 0, 0.35);
  border-color: #e60000;
  box-shadow: 0 0 0 1px #e60000;
  z-index: 2;
}
.ae-clip .trans-mark {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 10px;
  background: linear-gradient(90deg, transparent, rgba(0,0,0,0.55));
  pointer-events: none;
}
.ae-timeline .playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #e60000;
  z-index: 6;
  pointer-events: none;
  box-shadow: 0 0 6px rgba(230,0,0,0.6);
}
.tl-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.tl-tools .btn-sm {
  min-height: 36px;
  padding: 6px 10px !important;
}

/* Text overlay live preview */
.text-overlay {
  position: absolute;
  left: 0;
  right: 0;
  padding: 2% 4%;
  color: #fff;
  font-weight: 700;
  text-shadow: 0 2px 8px rgba(0,0,0,0.85);
  pointer-events: none;
  z-index: 6;
  text-align: center;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Safe area for notched phones */
@supports (padding: max(0px)) {
  .sticky-actions {
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
  .app {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
}


/* Drag-to-trim handles — both ends of each clip */
.ae-clip {
  padding: 0 18px !important;
  touch-action: none;
  min-height: 36px;
}
.ae-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 18px;
  z-index: 8;
  cursor: ew-resize;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ae-handle::after {
  content: "";
  width: 4px;
  height: 60%;
  border-radius: 2px;
  background: #fff;
  box-shadow: 0 0 4px rgba(0,0,0,0.5);
}
.ae-handle-l {
  left: 0;
  border-radius: 5px 0 0 5px;
  background: linear-gradient(90deg, #0066ff, rgba(0,102,255,0.35));
}
.ae-handle-r {
  right: 0;
  border-radius: 0 5px 5px 0;
  background: linear-gradient(270deg, #e60000, rgba(230,0,0,0.35));
}
.ae-clip.selected .ae-handle-l,
.ae-clip.selected .ae-handle-r {
  width: 20px;
}
.ae-handle:active, .ae-handle:hover {
  filter: brightness(1.2);
}
.ae-clip-label {
  pointer-events: none;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  padding: 0 4px;
}

/* Seamless composition stage (one-flow preview) */
.comp-stage {
  position: absolute;
  inset: 0;
  background: #000;
  overflow: hidden;
}
.comp-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.55s ease;
  background: #000;
  pointer-events: none;
}
.comp-layer.active-layer {
  opacity: 1;
  z-index: 1;
}
.comp-layer.fade-out {
  opacity: 0;
  z-index: 0;
}
.comp-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
}
.preview-frame {
  position: relative;
}
/* keep controls above layers */
.preview-controls,
.logo-overlay,
.text-overlay {
  z-index: 10;
}

/* Install App — primary CTA */
.btn-install {
  background: linear-gradient(135deg, #0066ff, #e60000) !important;
  color: #fff !important;
  font-weight: 700 !important;
  min-height: 40px;
  padding: 8px 14px !important;
  border: none !important;
  white-space: nowrap;
}
.install-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 90;
  pointer-events: none;
}
.install-banner-inner {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: #0c1220;
  border: 1px solid #0066ff;
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
.install-banner-inner strong { display: block; font-size: 0.95rem; }
.install-banner-inner p { margin: 0; font-size: 0.75rem; color: var(--muted); }
.install-banner-inner .btn-primary { margin-left: auto; min-height: 44px; }

.license-card {
  max-width: 420px;
}
.license-card input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  letter-spacing: 0.04em;
  font-family: ui-monospace, monospace;
}
.license-error {
  color: #ff6b6b;
  font-size: 0.85rem;
  margin-top: 8px;
}
#license-modal:not([hidden]) {
  display: grid !important;
}
.app.license-locked .stages,
.app.license-locked .progress-rail {
  pointer-events: none;
  filter: blur(3px);
  opacity: 0.45;
  user-select: none;
}


/* ===== TRIM HANDLES: both ends, always visible ===== */
.ae-clip {
  position: absolute !important;
  box-sizing: border-box !important;
  padding: 0 22px !important;
  overflow: visible !important;
  border: 2px solid rgba(255,255,255,0.35) !important;
}
.ae-handle {
  position: absolute !important;
  top: -4px !important;
  bottom: -4px !important;
  width: 22px !important;
  z-index: 20 !important;
  cursor: ew-resize !important;
  touch-action: none !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  opacity: 1 !important;
  pointer-events: auto !important;
}
.ae-handle::before {
  content: "⋮" !important;
  color: #fff !important;
  font-size: 14px !important;
  font-weight: 900 !important;
  line-height: 1 !important;
  text-shadow: 0 1px 3px #000 !important;
}
.ae-handle-l {
  left: -6px !important;
  border-radius: 6px !important;
  background: #0066ff !important;
  border: 2px solid #fff !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5) !important;
}
.ae-handle-r {
  right: -6px !important;
  border-radius: 6px !important;
  background: #e60000 !important;
  border: 2px solid #fff !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5) !important;
}
.ae-track-row {
  overflow: visible !important;
  height: 44px !important;
}
.ae-tracks {
  overflow: visible !important;
  padding-top: 8px !important;
  padding-bottom: 12px !important;
}
.ae-timeline {
  overflow-x: auto !important;
  overflow-y: visible !important;
}

/* ===== v2.2 fixes: playing-clip highlight + preview error hint ===== */
.ae-clip.live {
  box-shadow: 0 0 0 2px rgba(0, 102, 255, 0.7);
}
.ae-clip.live::after {
  content: "▶";
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 9px;
  color: rgba(255, 255, 255, 0.9);
  pointer-events: none;
}
.ae-clip.live .trans-mark {
  display: none;
}
.preview-error {
  position: absolute;
  left: 6%;
  right: 6%;
  bottom: 20%;
  z-index: 12;
  text-align: center;
  font-size: 12px;
  line-height: 1.4;
  color: #ffe1e1;
  background: rgba(140, 24, 24, 0.78);
  border-radius: 8px;
  padding: 6px 8px;
  pointer-events: none;
}

.render-job-banner{position:sticky;top:0;z-index:50;background:linear-gradient(90deg,#0052cc,#e60000);color:#fff;padding:10px 12px;margin:0 -12px 12px}
.render-job-inner{display:flex;flex-wrap:wrap;gap:8px;align-items:center;max-width:1100px;margin:0 auto}
.render-job-inner .btn-primary{background:#fff!important;color:#0052cc!important}
