/* ── Reset & tokens ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Fix: CSS display rules must not override the HTML hidden attribute */
[hidden] { display: none !important; }

:root {
  --bg:        #0f0f11;
  --surface:   #1a1a1f;
  --border:    #2e2e35;
  --accent:    #6c63ff;
  --accent-h:  #8a83ff;
  --text:      #e8e8f0;
  --muted:     #888899;
  --error:     #ff6b6b;
  --x-color:   #1d9bf0;
  --th-color:  #000;
  --radius:    10px;
  --font:      -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100dvh;
}

.container {
  width: 100%;
  max-width: 720px;
  margin-inline: auto;
  padding-inline: 16px;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
.site-header {
  border-bottom: 1px solid var(--border);
  padding-block: 16px;
}

.site-header .container {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.3px;
}

.logo-icon { font-size: 22px; }

.tagline {
  color: var(--muted);
  font-size: 13px;
}

/* ── Main sections ──────────────────────────────────────────────────────────── */
main.container { padding-block: 32px; }

.input-section { margin-bottom: 24px; }

.url-field {
  display: flex;
  gap: 8px;
}

.url-input-wrap {
  flex: 1;
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color .15s;
  overflow: hidden;
}
.url-input-wrap:focus-within { border-color: var(--accent); }

.url-input-wrap input[type="url"] {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 15px;
  padding: 12px 14px;
  outline: none;
  min-width: 0;
}
.url-input-wrap input[type="url"]::placeholder { color: var(--muted); }

.paste-btn {
  background: transparent;
  border: none;
  border-left: 1px solid var(--border);
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  padding: 0 14px;
  white-space: nowrap;
  transition: background .15s;
}
.paste-btn:hover { background: rgba(108,99,255,.1); }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  padding: 12px 20px;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}

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

.btn--primary {
  background: var(--accent);
  color: #fff;
}
.btn--primary:hover:not(:disabled) { background: var(--accent-h); }

.btn--secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn--secondary:hover:not(:disabled) { border-color: var(--accent); }

/* submit button inside url-field */
#fetchBtn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  padding: 0 22px;
  transition: background .15s;
  position: relative;
}
#fetchBtn:hover { background: var(--accent-h); }
#fetchBtn:disabled { opacity: .5; cursor: not-allowed; }

/* spinner */
.btn-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Error ──────────────────────────────────────────────────────────────────── */
.error-msg {
  color: var(--error);
  font-size: 13px;
  margin-top: 8px;
}

/* ── Result section ─────────────────────────────────────────────────────────── */
.result-section {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.video-preview video {
  width: 100%;
  border-radius: var(--radius);
  background: #000;
  max-height: 420px;
  object-fit: contain;
}

.meta-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 8px;
}

.badge {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.badge--x         { background: var(--x-color);  color: #fff; }
.badge--threads   { background: var(--th-color);  color: #fff; }

.meta-author { color: var(--muted); font-size: 13px; padding-top: 3px; }
.meta-caption {
  width: 100%;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}

/* ── Quality selector ───────────────────────────────────────────────────────── */
.quality-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.quality-label {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.quality-select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  padding: 6px 10px;
  cursor: pointer;
  outline: none;
  transition: border-color .15s;
}
.quality-select:focus { border-color: var(--accent); }

/* ── Editor ─────────────────────────────────────────────────────────────────── */
.editor-section,
.naming-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section-title {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
}

.trim-controls { display: flex; flex-direction: column; gap: 10px; }

/* ── Control groups (時長、比例、旋轉) ─────────────────────────────────────── */
.control-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.control-group:last-of-type { border-bottom: none; }

.control-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 14px;
  transition: all .15s;
}
.chip:hover { border-color: var(--accent); }
.chip.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── 單軌雙端點 ── */
.trim-track-wrap { padding: 8px 0 4px; }

.trim-track {
  position: relative;
  height: 28px;
  display: flex;
  align-items: center;
}

/* 底層灰色軌道 */
.trim-track::before {
  content: '';
  position: absolute;
  left: 0; right: 0;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
}

/* 選取範圍高亮 */
.trim-range-fill {
  position: absolute;
  height: 4px;
  background: var(--accent);
  border-radius: 2px;
  pointer-events: none;
  left: 0%;
  right: 0%;
}

/* 兩個 range 疊在同一條軌道上 */
.trim-handle {
  position: absolute;
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: transparent;
  outline: none;
  pointer-events: none;
  margin: 0;
}

.trim-handle::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 3px solid var(--bg);
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
  pointer-events: auto;
}

.trim-handle::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 3px solid var(--bg);
  pointer-events: auto;
}

.trim-labels {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  padding: 0 2px;
}

/* ── Progress ───────────────────────────────────────────────────────────────── */
.progress-bar-wrap {
  background: var(--border);
  border-radius: 4px;
  height: 6px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  width: 0%;
  transition: width .2s;
}

.progress-label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

.sab-warning {
  font-size: 13px;
  color: var(--error);
  background: rgba(255,107,107,.08);
  border: 1px solid rgba(255,107,107,.2);
  border-radius: 6px;
  padding: 10px 14px;
}

/* ── Naming ─────────────────────────────────────────────────────────────────── */
.naming-row {
  display: flex;
  align-items: center;
  gap: 0;
}

.naming-row input[type="text"] {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
  color: var(--text);
  font-size: 14px;
  padding: 10px 12px;
  outline: none;
  transition: border-color .15s;
}
.naming-row input[type="text"]:focus { border-color: var(--accent); }

.ext-badge {
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--muted);
  font-size: 13px;
  padding: 10px 12px;
  white-space: nowrap;
  user-select: none;
}

/* ── Name suggestions ───────────────────────────────────────────────────────── */
.name-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.name-chip {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 12px;
  transition: border-color .15s, background .15s;
}
.name-chip:hover { border-color: var(--accent); background: rgba(108,99,255,.12); }

/* ── Action row ─────────────────────────────────────────────────────────────── */
.action-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.action-row .btn { flex: 1; min-width: 140px; }

/* ── Ad slots ───────────────────────────────────────────────────────────────── */
.ad-slot {
  min-height: 90px;
  background: transparent;
  border-radius: var(--radius);
  margin-block: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── SEO content ────────────────────────────────────────────────────────────── */
.seo-section {
  margin-top: 48px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.seo-section h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.seo-section p {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.7;
}

.seo-section code {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 13px;
  color: var(--accent-h);
}

/* ── Footer ─────────────────────────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border);
  padding-block: 20px;
  margin-top: 48px;
}

.site-footer p {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

/* ── Display utilities ──────────────────────────────────────────────────────── */
.d-none    { display: none !important; }

@media (min-width: 768px) {
  .d-md-block { display: block !important; }
  .d-md-none  { display: none !important; }
}

/* ── Mobile tweaks ──────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .url-field { flex-direction: column; }
  #fetchBtn  { padding: 12px; }
}
