/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; }
body {
  font-family: system-ui, -apple-system, sans-serif;
  background: #0f0f12;
  color: #eee;
  margin: 0;
  min-height: 100vh;
}

/* === Layout === */
.wrap {
  max-width: 960px;           /* fills desktop; the clips grid uses the width */
  margin: 0 auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
/* Keep the URL field from stretching absurdly on wide screens. */
.input-row { max-width: 620px; }

/* === Hero (index) === */
.hero {
  text-align: center;
  padding: 48px 0 32px;
}
.logo-mark {
  font-size: 3rem;
  line-height: 1;
  margin-bottom: 8px;
  color: #e1306c;
}
h1 {
  font-size: 2.4rem;
  font-weight: 800;
  margin: 0 0 8px;
  letter-spacing: -0.03em;
}
.tagline {
  color: #888;
  font-size: 1.05rem;
  margin: 0 0 32px;
}

/* === Submit Card === */
.submit-card {
  background: #16161c;
  border: 1px solid #232329;
  border-radius: 16px;
  padding: 28px 24px;
  margin-bottom: 24px;
}
.field-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}
.input-row {
  display: flex;
  gap: 10px;
}
.input-row input[type="url"] {
  flex: 1;
  min-width: 0;
}

/* === Form controls === */
input, button, select {
  font-size: 16px;            /* >=16px keeps iOS from zooming on focus */
  padding: .5em .75em;
  border-radius: 10px;
  border: 1px solid #2a2a33;
  background: #1a1a20;
  color: #eee;
  transition: border-color 0.15s;
  min-height: 44px;          /* comfortable touch target */
}
.seg input[type="checkbox"] { min-height: 0; }

/* === Caption / template controls === */
.caption-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  align-items: center;
  margin-bottom: 18px;
  font-size: 0.9rem;
  color: #bbb;
}
.caption-controls label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.caption-controls select { min-height: 40px; }
input:focus {
  outline: none;
  border-color: #e1306c;
}
button {
  background: #e1306c;
  border: none;
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  padding: .5em 1.1em;
  letter-spacing: 0.01em;
}
button:hover { background: #c81059; }
button:active { transform: scale(0.98); }
.btn-icon { font-size: 0.85em; }

/* === Upload progress bar === */
.upload-progress {
  position: relative;
  height: 24px;
  background: #1a1a20;
  border: 1px solid #2a2a33;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 12px;
}
.upload-progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #e1306c, #ff6492);
  transition: width 0.15s ease;
}
.upload-progress-pct {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* === Error === */
.error-msg {
  color: #f87171;
  margin: 10px 0 0;
  font-size: 0.92rem;
}

/* === Library (clips grouped by video) === */
.library { margin-bottom: 24px; }
.recent-title {
  font-size: 1rem;
  font-weight: 700;
  color: #ccc;
  margin: 0 0 12px;
}
.lib-group { margin-bottom: 22px; }
.lib-group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 2px;
  margin-bottom: 8px;
  border-bottom: 1px solid #1e1e26;
  color: #eee;
  text-decoration: none;
}
.lib-group-head:hover { text-decoration: none; }
.lib-group-head:hover .lib-group-title { color: #e1306c; }
.lib-group-title {
  font-weight: 700;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lib-group-meta { color: #888; font-size: 0.8rem; white-space: nowrap; }

/* === Project Header === */
.top-nav {
  margin-bottom: 20px;
}
.back-link {
  color: #888;
  text-decoration: none;
  font-size: 0.9rem;
}
.back-link:hover { color: #e1306c; }
.project-header {
  margin-bottom: 24px;
}

/* === Status === */
.status {
  color: #9ad;
  font-size: 0.95rem;
  margin: 4px 0 0;
}

/* === Segments === */
.segments-section {
  margin-bottom: 16px;
}
.seg {
  display: flex;
  flex-direction: column;
  gap: .55em;
  background: #16161c;
  border: 1px solid #1e1e26;
  padding: .8em .9em;
  border-radius: 12px;
  margin: .6em 0;
}
.seg-head { display: flex; align-items: center; gap: .7em; }
.seg-check { display: flex; align-items: center; gap: .4em; font-size: 0.85rem; color: #ccc; cursor: pointer; }
.seg-preview {
  margin-left: auto; min-height: 0; padding: .35em .8em;
  font-size: 0.8rem; font-weight: 600;
  background: #23232c; border: 1px solid #34343f; color: #fff; border-radius: 8px; cursor: pointer;
}
.seg-preview:hover { border-color: #e1306c; }
.seg .title { font-size: 0.95rem; font-weight: 600; width: 100%; }
.seg-reason { color: #7a7a85; font-size: 0.8rem; line-height: 1.4; font-style: italic; }
.seg-trim { display: flex; align-items: center; gap: .45em; flex-wrap: wrap; }
.seg .start, .seg .end {
  width: 5.5em; font-size: 0.86rem; text-align: right;
  font-variant-numeric: tabular-nums;
}
.seg-arrow { color: #555; }
.seg-set {
  min-height: 0; padding: .3em .6em; font-size: 0.74rem; font-weight: 600;
  background: transparent; border: 1px solid #2e2e38; color: #bbb; border-radius: 7px; cursor: pointer;
}
.seg-set:hover { border-color: #e1306c; color: #fff; }
.seg-dur { margin-left: auto; color: #8a8a92; font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.seg-caption-toggle {
  min-height: 0; padding: .35em .8em; font-size: 0.8rem; font-weight: 600;
  background: #23232c; border: 1px solid #34343f; color: #fff; border-radius: 8px; cursor: pointer;
}
.seg-caption-toggle:hover { border-color: #e1306c; }
.seg-caption { display: flex; flex-direction: column; gap: 4px; }
.caption-text {
  width: 100%; resize: vertical; min-height: 48px;
  background: #0f0f14; border: 1px solid #2e2e38; color: #f0f0f3;
  border-radius: 8px; padding: 8px 10px; font: inherit; font-size: 0.88rem; line-height: 1.4;
}
.caption-text:focus { outline: none; border-color: #e1306c; }
.seg-caption-hint { color: #7a7a85; font-size: 0.72rem; }
.editor-intro { color: #8a8a92; font-size: 0.85rem; margin: 4px 0 0; }
.editor-preview[hidden] { display: none; }
.editor-preview {
  position: sticky; top: 8px; z-index: 5;
  background: #0f0f14; border: 1px solid #232330; border-radius: 14px;
  padding: 10px; margin-bottom: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.preview-video {
  width: auto; max-width: 100%; max-height: 46vh;
  aspect-ratio: 16 / 9; background: #000; border-radius: 8px;
}
.preview-hint { color: #7a7a85; font-size: 0.76rem; text-align: center; margin: 0; }
.seg input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #e1306c;
  cursor: pointer;
  padding: 0;
  border: none;
  background: none;
}

/* === Render bar === */
.render-bar {
  margin: 12px 0 20px;
}
#renderBtn {
  width: 100%;
  justify-content: center;
  padding: .65em 1em;
  font-size: 1rem;
  border-radius: 12px;
}

/* === Clips (Opus-inspired cards) === */
.clips-section h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #ccc;
  margin: 0 0 12px;
}
.clips-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 16px;
}
.clip-card {
  background: #15151b;
  border: 1px solid #232330;
  border-radius: 16px;
  overflow: hidden;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.clip-card:hover {
  transform: translateY(-3px);
  border-color: #e1306c;
  box-shadow: 0 12px 30px -12px rgba(225, 48, 108, 0.4);
}
.clip-video-wrap {
  position: relative;
  aspect-ratio: 9 / 16;
  background: #000;
  overflow: hidden;
}
.clip-video-wrap::before {            /* top scrim so the score stays readable */
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 42%;
  background: linear-gradient(to bottom, rgba(0,0,0,0.5), transparent);
  z-index: 1;
  pointer-events: none;
}
.clip-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .4s ease;
}
.clip-card:hover .clip-video { transform: scale(1.04); }
.clip-meta { padding: 10px 12px 12px; }
.clip-title {
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.25;
  margin-bottom: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.clip-reason {
  color: #7a7a86;
  font-size: 0.72rem;
  font-style: italic;
  margin: 2px 0 10px;
  line-height: 1.3;
}
.clip-dl {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #fff;
  background: #e1306c;
  padding: 7px 12px;
  border-radius: 9px;
}
.clip-dl:hover { background: #c81059; text-decoration: none; }
.clip-desc {
  background: #0f0f14;
  border: 1px solid #232330;
  border-radius: 8px;
  padding: 7px 9px;
  margin: 0 0 8px;
  font-size: 0.72rem;
  line-height: 1.4;
  color: #cfcfd6;
  white-space: pre-wrap;
  max-height: 96px;
  overflow: auto;
}
.clip-copy {
  width: 100%;
  margin-bottom: 8px;
  background: transparent;
  border: 1px solid #2a2a33;
  color: #ccc;
  font-size: 0.74rem;
  font-weight: 600;
  padding: 7px 10px;
  border-radius: 8px;
  min-height: 0;
  cursor: pointer;
}
.clip-copy:hover { border-color: #e1306c; color: #fff; background: transparent; }
.clip-placeholder { padding: 14px 12px; color: #bbb; font-size: 0.85rem; }

/* === Loading / processing panel === */
.loading-panel[hidden] { display: none; }  /* class display: flex must not beat hidden */
.loading-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
  padding: 40px 20px 44px;
  margin: 8px 0 24px;
  background: linear-gradient(180deg, #16161d 0%, #121218 100%);
  border: 1px solid #232330;
  border-radius: 16px;
}
.loading-spinner {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 4px solid #2a2a35;
  border-top-color: #e1306c;
  animation: cf-spin 0.85s linear infinite;
}
@keyframes cf-spin { to { transform: rotate(360deg); } }
.loading-msg { font-size: 1.05rem; font-weight: 600; color: #f2f2f5; }
.loading-steps {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 22px;
  margin: 4px 0 0;
  padding: 0;
}
.loading-steps li {
  position: relative;
  padding-left: 22px;
  font-size: 0.86rem;
  color: #6c6c78;
}
.loading-steps li::before {
  content: "";
  position: absolute;
  left: 0; top: 50%;
  width: 12px; height: 12px;
  margin-top: -6px;
  border-radius: 50%;
  background: #2c2c38;
}
.loading-steps li.done { color: #9be29b; }
.loading-steps li.done::before {
  content: "✓"; background: transparent; color: #4caf50;
  font-size: 0.9rem; line-height: 1; margin-top: -7px; width: auto; height: auto;
}
.loading-steps li.active { color: #ffb3cf; font-weight: 600; }
.loading-steps li.active::before { background: #e1306c; animation: cf-pulse 1.2s ease-in-out infinite; }
@keyframes cf-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(225,48,108,0.55); }
  50% { box-shadow: 0 0 0 6px rgba(225,48,108,0); }
}
.loading-hint { font-size: 0.78rem; color: #7a7a85; }
.cf-progress {
  width: min(380px, 80%);
  height: 8px;
  background: #2a2a35;
  border-radius: 99px;
  overflow: hidden;
}
.cf-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #e1306c, #ff7eb3);
  border-radius: 99px;
  transition: width 0.4s ease;
}
.cf-progress-pct { font-size: 0.78rem; color: #ffb3cf; font-weight: 600; }
.notice-msg {
  background: #2a2410;
  border: 1px solid #5a4a1c;
  color: #ffd98a;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.85rem;
  margin: 6px 0 0;
}
.lib-dl-all, .clips-dl-all {
  display: inline-block;
  margin-left: 10px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #e1306c;
  text-decoration: none;
}
.lib-dl-all:hover, .clips-dl-all:hover { text-decoration: underline; }
.loading-failed {
  padding: 18px 16px;
  background: #2a1418;
  border: 1px solid #5a232c;
  border-radius: 12px;
  color: #ff9aa8;
  font-size: 0.92rem;
}

/* === Virality score badge === */
.score-badge {
  display: inline-block;
  font-weight: 800;
  font-size: 0.8rem;
  padding: 2px 8px;
  border-radius: 999px;
  color: #0a0a0a;
  font-variant-numeric: tabular-nums;
}
.score-green { background: #22c55e; }
.score-orange { background: #f59e0b; }
.score-red { background: #ef4444; }
/* Prominent score chip over clip thumbnails: big number + "VIRALITÉ" label. */
.clip-video-wrap .score-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  padding: 5px 9px;
  border-radius: 11px;
  font-size: 1.1rem;
  font-weight: 900;
  box-shadow: 0 3px 12px rgba(0,0,0,0.5), inset 0 0 0 1px rgba(255,255,255,0.18);
}
.clip-video-wrap .score-badge::after {
  content: "VIRALITÉ";
  font-size: 0.46rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  margin-top: 2px;
  opacity: 0.82;
}
.clip-video-wrap .score-green  { box-shadow: 0 3px 16px rgba(34,197,94,0.45), inset 0 0 0 1px rgba(255,255,255,0.2); }
.clip-video-wrap .score-orange { box-shadow: 0 3px 16px rgba(245,158,11,0.45), inset 0 0 0 1px rgba(255,255,255,0.2); }
.clip-video-wrap .score-red    { box-shadow: 0 3px 16px rgba(239,68,68,0.45), inset 0 0 0 1px rgba(255,255,255,0.2); }

/* === Links === */
a {
  color: #e1306c;
  text-decoration: none;
}
a:hover { text-decoration: underline; }

/* === Footer === */
.footer {
  margin-top: auto;
  padding-top: 40px;
  text-align: center;
  color: #333;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}

/* === Mobile (phones) === */
@media (max-width: 640px) {
  .wrap { padding: 16px 14px; }
  .hero { padding: 28px 0 20px; }
  h1 { font-size: 1.9rem; }
  .logo-mark { font-size: 2.4rem; }
  .tagline { font-size: 0.98rem; margin-bottom: 22px; }
  .submit-card { padding: 20px 16px; border-radius: 14px; }

  /* URL field + button stack full width */
  .input-row { flex-direction: column; }
  .input-row button { width: 100%; justify-content: center; }
  .upload-row { flex-wrap: wrap; }
  .upload-row button { width: 100%; justify-content: center; }

  /* Segment rows: wrap instead of a cramped 5-column grid */
  .seg {
    display: flex;
    flex-wrap: wrap;
    gap: .5em .6em;
    padding: .7em;
  }
  .seg input[type="checkbox"] { order: 0; }
  .seg .title { order: 1; flex: 1 1 60%; min-width: 0; }
  .seg .time { order: 2; flex: 1 1 auto; }
  .seg .start, .seg .end { order: 3; flex: 0 0 auto; width: 5em; }
  .seg small { order: 4; flex: 1 1 100%; }

  /* Caption/template controls: label text above a full-width select */
  .caption-controls { flex-direction: column; align-items: stretch; gap: 14px; }
  .caption-controls label { flex-direction: column; align-items: stretch; gap: 5px; }
  .caption-controls select { width: 100%; }
  /* the emoji checkbox label stays a single row */
  .caption-controls label:has(input[type="checkbox"]) {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  /* Clip grid: 2 columns that fit a narrow phone */
  .clips-grid { grid-template-columns: repeat(auto-fill, minmax(135px, 1fr)); gap: 10px; }

  .footer { padding-top: 28px; }
}

/* === Very small phones === */
@media (max-width: 380px) {
  .clips-grid { grid-template-columns: 1fr 1fr; }
}
