:root {
  --bg: #0f1115;
  --panel: #171a21;
  --border: #2a2e38;
  --text: #eef0f4;
  --muted: #9aa1ae;
  --accent: #6c8bff;
  --accent-hover: #82a0ff;
  --good: #4ade80;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.wrap {
  max-width: 620px;
  margin: 0 auto;
  padding: 64px 24px;
}

.wrap.wide {
  max-width: 1100px;
}

h1 {
  font-size: 28px;
  margin: 0 0 4px;
}

.subtitle {
  color: var(--muted);
  margin: 0 0 32px;
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  background: var(--panel);
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  background: #1a1e2a;
}

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

.file-name {
  margin-top: 12px !important;
  color: var(--text) !important;
  font-weight: 600;
}

.field-label {
  display: block;
  margin-top: 20px;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.length-preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.toggle-row input {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

select {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

button {
  display: block;
  width: 100%;
  margin-top: 20px;
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #0b0d12;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

button:hover:not(:disabled) {
  background: var(--accent-hover);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.link-btn {
  display: inline-block;
  width: auto;
  margin: 0;
  padding: 0;
  background: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

.link-btn:hover:not(:disabled) {
  background: none;
  color: var(--accent);
  text-decoration: underline;
}

#cleanup-panel {
  margin-top: 40px;
  text-align: center;
}

#cleanup-panel .status-hint {
  margin-top: 8px;
}

.hidden {
  display: none !important;
}

#status-panel {
  text-align: center;
  padding: 40px 0;
}

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

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

#status-text {
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 8px;
}

.status-hint {
  color: var(--muted);
  font-size: 14px;
  margin: 0;
}

.inline-form {
  display: inline;
}

.progress-bar-outer {
  width: 100%;
  height: 8px;
  margin: 16px 0;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.4s ease;
}

.progress-bar-fill.indeterminate {
  width: 40% !important;
  animation: progress-indeterminate 1.2s ease-in-out infinite;
}

@keyframes progress-indeterminate {
  0% { margin-left: -40%; }
  100% { margin-left: 100%; }
}

.render-progress {
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 8px;
}

#error-panel {
  text-align: center;
  padding: 24px;
  background: #2a1418;
  border: 1px solid #4a2028;
  border-radius: 12px;
}

.error-text {
  color: #ff8a8a;
  margin: 0 0 16px;
}

#retry-btn {
  background: #3a2028;
  color: var(--text);
}

.stop-btn {
  display: inline-block;
  width: auto;
  margin: 20px 0 0;
  padding: 10px 20px;
  font-size: 14px;
  background: transparent;
  color: #ff8a8a;
  border: 1px solid #4a2028;
}

.stop-btn:hover:not(:disabled) {
  background: #2a1418;
}

.new-episode-link {
  display: inline-block;
  margin-bottom: 28px;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.new-episode-link:hover {
  text-decoration: underline;
}

.top-links-row {
  display: flex;
  gap: 20px;
  margin-bottom: 28px;
}

.top-links-row .new-episode-link {
  margin-bottom: 0;
}

.clip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
}

.clip-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.clip-video {
  position: relative;
  background: #000;
  aspect-ratio: 9 / 16;
  /* Lets the caption overlay size itself in cqh/cqw against this box's
     own rendered pixels, not the viewport - the burned-in equivalent
     (caption_renderer.py's ASS) sizes everything against the fixed
     1080x1920 output resolution, and this box always matches that
     exact 9:16 ratio, so cqh here is a direct stand-in for "fraction
     of PlayResY" with no separate JS measurement/resize-observer
     needed. */
  container-type: size;
}

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

.rerender-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(15, 17, 21, 0.82);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}

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

/* Preview-only caption layer - a JS/CSS stand-in for the ASS captions
   caption_renderer.py burns in at actual export time (see
   ensure_burned_export in caption_renderer.py). Toggling/restyling
   this is pure client-side state (results.html's JS) - never a fetch,
   never touches the video file. */
.caption-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.caption-overlay.hidden {
  display: none;
}

.caption-overlay-text {
  position: absolute;
  left: 0;
  right: 0;
  margin: 0;
  padding: 0 5.6%; /* ASS MarginL/MarginR=60 against PlayResX=1080 */
  padding-block: var(--cap-bg-padding-block, 0); /* bold_box's background-box padding only */
  text-align: center;
  font-family: "Arial Black", Arial, sans-serif;
  font-weight: 900;
  line-height: 1.25;
  text-transform: uppercase;
  white-space: pre-line;
  /* Set per-style by JS from window.CAPTION_STYLES - see results.html.
     Defaults here match CAPTION_STYLES.classic so the overlay still
     looks reasonable before JS has run. */
  font-size: var(--cap-font-size, 3.75cqh);
  color: var(--cap-color, #fff);
  -webkit-text-stroke: var(--cap-outline-width, 0.35cqh) var(--cap-outline-color, #000);
  paint-order: stroke fill;
  text-shadow: var(--cap-shadow, none);
  background: var(--cap-bg, none);
  border-radius: var(--cap-bg-radius, 0);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

/* Each word dims until it's the one actually being spoken right now
   (see results.html's updateOverlayText, keyed off each word's own
   timestamp from caption_renderer.py's _build_caption_cues) - the
   phrase still reads as a whole for context, but only one word tracks
   playback at a time, instead of the whole phrase appearing at once. */
.cap-word {
  opacity: 0.5;
  transition: opacity 0.08s linear;
}

.cap-word-active {
  opacity: 1;
}

/* "single" (default): lower-middle of the frame, clear of TikTok/
   Reels/Shorts's own bottom UI - matches ASS Alignment=2,
   MarginV=CAPTION_BOTTOM_SAFE_MARGIN_V (600) against PlayResY=1920. */
.caption-overlay.layout-single .caption-overlay-text {
  bottom: 31.25%;
}

/* "stacked": centered on the seam between the two speaker boxes,
   matching ASS Alignment=5 (middle-center). */
.caption-overlay.layout-stacked .caption-overlay-text {
  top: 50%;
  transform: translateY(-50%);
}

.clip-info {
  padding: 14px 16px 16px;
}

.clip-score-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.clip-rank {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.clip-score {
  background: rgba(74, 222, 128, 0.12);
  color: var(--good);
  font-weight: 700;
  font-size: 13px;
  padding: 3px 9px;
  border-radius: 999px;
}

.clip-caption {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 6px;
  line-height: 1.35;
}

.clip-time {
  color: var(--muted);
  font-size: 12px;
  margin: 0 0 14px;
}

.clip-description {
  font-size: 13px;
  color: var(--text);
  line-height: 1.4;
  margin: 0 0 8px;
}

.clip-hashtags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 14px;
}

.hashtag-chip {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(108, 139, 255, 0.12);
  padding: 3px 9px;
  border-radius: 999px;
}

.clip-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.download-btn,
.rerender-btn {
  display: block;
  text-align: center;
  padding: 10px;
  border-radius: 8px;
  background: var(--border);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  transition: background 0.15s, opacity 0.15s;
  border: none;
  width: 100%;
  margin: 0;
  cursor: pointer;
}

.download-btn:hover,
.rerender-btn:hover:not(:disabled) {
  background: #383e4c;
}

.clip-length-label {
  margin-top: 14px;
  margin-bottom: 6px;
  font-size: 11px;
}

.clip-thumbnail-label {
  margin-top: 0;
}

.thumbnail-picker-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.thumbnail-picker-item {
  padding: 0;
  border: 2px solid transparent;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  overflow: hidden;
  line-height: 0;
  flex: 1;
  aspect-ratio: 9 / 16;
  transition: border-color 0.15s, opacity 0.15s;
}

.thumbnail-picker-item img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.thumbnail-picker-item:hover:not(:disabled):not(.active) {
  border-color: var(--border);
}

.thumbnail-picker-item.active {
  border-color: var(--accent);
}

.thumbnail-picker-item:disabled {
  opacity: 0.5;
  cursor: default;
}

.length-preset-row-small .mode-btn {
  padding: 6px 10px;
  font-size: 12px;
}

.rerender-status {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.rerender-status.rerender-error {
  color: #ff8a8a;
}

.mode-toggle {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
}

.mode-btn {
  display: block;
  width: auto;
  margin: 0;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.mode-btn:hover {
  border-color: var(--accent);
}

.mode-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #0b0d12;
}

.clip-select-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}

.clip-captions-row {
  margin-top: 0;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--muted);
}

.clip-select-row input {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.clip-day-select {
  width: 100%;
  margin: 0 0 10px;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

.publish-panel {
  margin-top: 40px;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.publish-panel h2 {
  margin: 0 0 4px;
  font-size: 18px;
}

.publish-hint {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 10px;
}

.time-preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 22px;
}

.time-preset-row .mode-btn {
  padding: 8px 14px;
  font-size: 13px;
}

.platform-checkboxes {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
}

.platform-checkboxes label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.platform-checkboxes input {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

#schedule-btn {
  width: auto;
  margin-top: 0;
  padding: 12px 24px;
}

#auto-flow-btn {
  width: auto;
  margin-top: 4px;
  padding: 12px 24px;
}

.auto-confirm-text {
  font-size: 15px;
  line-height: 1.6;
  margin: 0 0 18px;
  color: var(--text);
}

.inline-edit-btn {
  display: inline;
  width: auto;
  margin: 0;
  padding: 2px 4px;
  font: inherit;
  font-weight: 700;
  color: var(--accent);
  background: none;
  border: none;
  border-bottom: 1px dashed var(--accent);
  border-radius: 0;
  cursor: pointer;
}

.inline-edit-btn:hover {
  color: var(--accent-hover);
  border-bottom-color: var(--accent-hover);
}

.publish-progress {
  margin-top: 16px;
}

.publish-progress-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.publish-progress .progress-bar-outer {
  margin: 0;
}

.publish-error {
  color: #ff8a8a;
  font-size: 14px;
  margin: 14px 0 0;
}

.publish-results {
  margin-top: 20px;
}

.publish-results h3 {
  font-size: 15px;
  margin: 0 0 10px;
}

.publish-results ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.publish-result-row {
  font-size: 13px;
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(74, 222, 128, 0.08);
}

.publish-result-row-error {
  background: rgba(255, 138, 138, 0.1);
}

.publish-result-ok {
  color: var(--good);
  font-weight: 700;
  margin-right: 8px;
}

.publish-result-fail {
  color: #ff8a8a;
  font-weight: 700;
  margin-right: 8px;
}
