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

:root {
  --red: #FF0000;
  --red-dark: #CC0000;
  --red-soft: #fff0f0;
  --bg: #f5f5f5;
  --surface: #ffffff;
  --border: #e8e8e8;
  --text: #111111;
  --muted: #888888;
  --input-bg: #fafafa;
  --shadow: 0 2px 12px rgba(0,0,0,0.07);
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f0f;
    --surface: #1a1a1a;
    --border: #2a2a2a;
    --text: #f0f0f0;
    --muted: #888;
    --input-bg: #222;
    --red-soft: #2a0808;
    --shadow: 0 2px 12px rgba(0,0,0,0.4);
  }
}

html { font-size: 16px; }
body {
  font-family: 'Vazirmatn', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* HERO */
.hero {
  background: linear-gradient(135deg, #FF0000 0%, #CC0000 50%, #990000 100%);
  padding: 40px 20px 60px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: '';
  position: absolute;
  bottom: -1px; left: 0; right: 0;
  height: 32px;
  background: var(--bg);
  border-radius: 32px 32px 0 0;
}
.hero-inner { position: relative; z-index: 1; }
.logo {
  display: inline-flex; align-items: center; gap: 10px;
  margin-bottom: 16px;
}
.logo-icon { width: 40px; height: 40px; }
.logo-icon svg { width: 40px; height: 40px; border-radius: 10px; }
.logo-text { font-size: 24px; font-weight: 700; color: #fff; }
.hero-title { font-size: 26px; font-weight: 700; color: #fff; margin-bottom: 6px; }
.hero-sub { font-size: 14px; color: rgba(255,255,255,.75); }

/* MAIN */
.main { flex: 1; max-width: 680px; margin: -16px auto 0; width: 100%; padding: 0 16px 40px; }

/* CARD */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

/* SEARCH */
.input-group {
  display: flex; align-items: center; gap: 8px;
  background: var(--input-bg);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  transition: border-color .2s;
  margin-bottom: 14px;
}
.input-group:focus-within { border-color: var(--red); }
.input-icon { width: 16px; height: 16px; flex-shrink: 0; opacity: .45; color: var(--text); }
.input-group input {
  flex: 1; border: none; outline: none;
  font-size: 14px; font-family: 'Vazirmatn', sans-serif;
  background: transparent; color: var(--text); direction: ltr; text-align: right;
}
.input-group input::placeholder { color: var(--muted); direction: rtl; text-align: right; }
.btn-paste, .btn-clear {
  background: none; border: none; cursor: pointer;
  font-family: 'Vazirmatn', sans-serif; font-size: 12px; font-weight: 500;
  color: var(--red); display: flex; align-items: center; gap: 4px;
  padding: 4px 8px; border-radius: 8px; transition: background .15s; white-space: nowrap;
}
.btn-paste:hover { background: var(--red-soft); }
.btn-clear { color: var(--muted); font-size: 14px; }
.btn-clear:hover { color: var(--text); }
.btn-fetch {
  width: 100%; background: linear-gradient(135deg, #FF0000, #CC0000);
  color: #fff; border: none; border-radius: 12px; padding: 14px;
  font-size: 15px; font-weight: 600; font-family: 'Vazirmatn', sans-serif;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: opacity .15s, transform .15s;
}
.btn-fetch:hover { opacity: .9; }
.btn-fetch:active { transform: scale(.98); }
.btn-fetch:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.disclaimer { font-size: 11px; color: var(--muted); text-align: center; margin-top: 12px; line-height: 1.6; }

/* LOADING */
.spinner-wrap {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  padding: 8px 0;
}
.spinner {
  width: 28px; height: 28px; flex-shrink: 0;
  border: 3px solid var(--border); border-top-color: var(--red);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinner-wrap span { font-size: 14px; color: var(--muted); }

/* ERROR */
.error-card { border-color: #ffcccc; background: #fff5f5; }
@media (prefers-color-scheme: dark) { .error-card { background: #2a0808; border-color: #550000; } }
.error-inner { display: flex; align-items: flex-start; gap: 12px; }
.error-icon { font-size: 22px; flex-shrink: 0; }
.error-title { font-size: 14px; font-weight: 600; color: #cc0000; margin-bottom: 4px; }
.error-msg { font-size: 13px; color: var(--muted); line-height: 1.5; direction: ltr; }

/* VIDEO INFO */
.video-info {
  display: flex; gap: 14px; align-items: flex-start;
  padding-bottom: 20px; margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.video-thumb {
  width: 120px; height: 68px; border-radius: 8px; object-fit: cover;
  flex-shrink: 0; background: var(--border);
}
.video-title { font-size: 14px; font-weight: 600; line-height: 1.5; margin-bottom: 6px; }
.video-meta { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.video-duration { display: inline-flex; align-items: center; gap: 4px; }

/* TABS */
.formats-header {
  display: flex; gap: 8px; margin-bottom: 16px;
}
.tab {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 99px; cursor: pointer;
  font-size: 13px; font-weight: 500; border: 1.5px solid var(--border);
  color: var(--muted); transition: all .15s;
}
.tab:hover { border-color: var(--red); color: var(--text); }
.tab.active { background: var(--red); color: #fff; border-color: var(--red); }

/* FORMAT ITEMS */
.format-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border);
  margin-bottom: 8px; cursor: pointer; transition: border-color .15s, background .15s;
}
.format-item:hover { border-color: var(--red); background: var(--red-soft); }
.format-left { display: flex; flex-direction: column; gap: 3px; }
.format-label { font-size: 14px; font-weight: 600; }
.format-size { font-size: 12px; color: var(--muted); }
.btn-dl {
  background: var(--red); color: #fff; border: none; border-radius: 8px;
  padding: 8px 18px; font-size: 13px; font-weight: 600;
  font-family: 'Vazirmatn', sans-serif; cursor: pointer;
  transition: opacity .15s;
}
.btn-dl:hover { opacity: .85; }

/* PROGRESS */
.progress-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.progress-label { font-size: 14px; font-weight: 600; }
.progress-pct { font-size: 20px; font-weight: 700; color: var(--red); }
.progress-bar-track {
  height: 10px; background: var(--border); border-radius: 99px; overflow: hidden; margin-bottom: 8px;
}
.progress-bar-fill {
  height: 100%; background: linear-gradient(90deg, #ff6666, #FF0000);
  border-radius: 99px; transition: width .4s ease; width: 0%;
}
.progress-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.progress-done { text-align: center; padding-top: 20px; margin-top: 20px; border-top: 1px solid var(--border); }
.done-icon { font-size: 36px; margin-bottom: 8px; }
.done-text { font-size: 16px; font-weight: 600; margin-bottom: 16px; }
.btn-download {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: linear-gradient(135deg, #FF0000, #CC0000);
  color: #fff; text-decoration: none; border-radius: 12px;
  padding: 12px 32px; font-size: 15px; font-weight: 600;
  margin-bottom: 12px; transition: opacity .15s;
}
.btn-download:hover { opacity: .9; }
.btn-another {
  display: block; width: 100%; background: none; border: 1.5px solid var(--border);
  border-radius: 12px; padding: 10px; font-size: 14px; color: var(--muted);
  font-family: 'Vazirmatn', sans-serif; cursor: pointer; transition: border-color .15s;
}
.btn-another:hover { border-color: var(--red); color: var(--text); }

/* SITES */
.sites-section { margin-bottom: 16px; }
.sites-title { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 10px; }
.sites-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.site-badge {
  padding: 6px 14px; border-radius: 99px; font-size: 12px; font-weight: 600;
  border: 1.5px solid;
}
.site-badge.yt  { background: #fff0f0; color: #cc0000; border-color: #ffcccc; }
.site-badge.ig  { background: #f0f0ff; color: #5528aa; border-color: #d0c8ff; }
.site-badge.tw  { background: #f0f8ff; color: #0055aa; border-color: #c0dcff; }
.site-badge.fb  { background: #f0f4ff; color: #0040aa; border-color: #c0ccff; }
.site-badge.tt  { background: #f0fffe; color: #007766; border-color: #b0eeee; }
.site-badge.vm  { background: #fff4f0; color: #aa4400; border-color: #ffd0b0; }
.site-badge.sc  { background: #fff8f0; color: #aa5500; border-color: #ffdda0; }
.site-badge.more { background: var(--input-bg); color: var(--muted); border-color: var(--border); }

/* FEATURES */
.features-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.feat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 14px;
}
.feat-ico { font-size: 24px; margin-bottom: 8px; }
.feat-name { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.feat-desc { font-size: 12px; color: var(--muted); line-height: 1.5; }

/* FOOTER */
.footer {
  text-align: center; padding: 20px; font-size: 12px; color: var(--muted);
  border-top: 1px solid var(--border);
}

@media (max-width: 480px) {
  .hero { padding: 28px 16px 48px; }
  .hero-title { font-size: 20px; }
  .video-info { flex-direction: column; }
  .video-thumb { width: 100%; height: 180px; }
  .features-grid { grid-template-columns: 1fr 1fr; }
}

/* ── TRIM SECTION ─────────────────────────────────────────────── */
.trim-section {
  margin-top: 20px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}
.trim-header {
  display: flex; justify-content: space-between; align-items: center;
  cursor: pointer; padding: 4px 0; user-select: none;
  transition: opacity .15s;
}
.trim-header:hover { opacity: .8; }
.trim-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; color: var(--text);
}
.trim-badge {
  font-size: 11px; font-weight: 600; color: var(--red);
  animation: pulse 1.5s infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.5} }
.trim-chevron { color: var(--muted); transition: transform .2s; flex-shrink:0; }
.trim-chevron.open { transform: rotate(180deg); }

.trim-body { padding-top: 16px; }
.trim-note {
  font-size: 12px; color: var(--muted); margin-bottom: 16px; line-height: 1.6;
}
.trim-note code {
  background: var(--input-bg); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 5px; font-size: 11px;
  font-family: monospace;
}

/* Dual range slider timeline */
.trim-timeline { margin-bottom: 16px; }
.timeline-track {
  position: relative; height: 28px; display: flex; align-items: center;
}
.timeline-track::before {
  content: '';
  position: absolute; left: 0; right: 0; height: 6px;
  background: var(--border); border-radius: 3px; z-index: 0;
}
.timeline-selected {
  position: absolute; height: 6px; background: var(--red);
  border-radius: 3px; z-index: 1; pointer-events: none;
}
.trange {
  position: absolute; width: 100%;
  -webkit-appearance: none; appearance: none;
  background: transparent; pointer-events: none; z-index: 2;
}
.trange::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; border: 2.5px solid var(--red);
  cursor: pointer; pointer-events: all;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
  transition: transform .1s;
}
.trange::-webkit-slider-thumb:hover { transform: scale(1.15); }
.trange::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; border: 2.5px solid var(--red);
  cursor: pointer; pointer-events: all;
}
.timeline-labels {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 8px;
}
.tl-time { font-size: 12px; font-weight: 600; color: var(--text); }
.tl-dur  { font-size: 11px; color: var(--muted); }

/* Text inputs */
.trim-inputs {
  display: flex; align-items: flex-end; gap: 10px; margin-bottom: 10px;
}
.trim-field { flex: 1; display: flex; flex-direction: column; gap: 5px; }
.trim-field label {
  font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .4px;
}
.trim-field input {
  width: 100%; padding: 9px 12px; border-radius: 10px;
  border: 1.5px solid var(--border); background: var(--input-bg);
  font-size: 14px; font-family: monospace; color: var(--text);
  outline: none; transition: border-color .2s; text-align: center;
}
.trim-field input:focus { border-color: var(--red); }
.trim-field input.valid   { border-color: #22c55e; }
.trim-field input.invalid { border-color: #ef4444; }
.trim-arrow {
  flex-shrink: 0; padding-bottom: 10px; color: var(--muted); display:flex; align-items:center;
}
.trim-hint {
  font-size: 12px; color: var(--muted); min-height: 18px; margin-bottom: 10px;
}
.trim-hint.ok  { color: #22c55e; }
.trim-hint.err { color: #ef4444; }

.btn-trim-clear {
  display: flex; align-items: center; gap: 6px;
  background: none; border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 14px;
  font-size: 12px; color: var(--muted);
  font-family: 'Vazirmatn', sans-serif; cursor: pointer;
  transition: border-color .15s, color .15s;
}
.btn-trim-clear:hover { border-color: var(--red); color: var(--red); }
