/* ============================================================
   ConvTube – modern YouTube converter UI
   ============================================================ */
:root {
  --bg: #0b0d17;
  --bg-soft: #12152400;
  --card: rgba(23, 27, 46, 0.72);
  --card-border: rgba(255, 255, 255, 0.08);
  --text: #eef0f7;
  --muted: #9aa1bd;
  --accent: #7c5cff;
  --accent-2: #ff4d6d;
  --accent-grad: linear-gradient(120deg, #7c5cff 0%, #ff4d6d 100%);
  --good: #2bd99a;
  --error-bg: rgba(255, 77, 109, 0.12);
  --chip: rgba(255, 255, 255, 0.05);
  --chip-border: rgba(255, 255, 255, 0.1);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --radius: 18px;
}
[data-theme="light"] {
  --bg: #f5f6fc;
  --card: rgba(255, 255, 255, 0.78);
  --card-border: rgba(20, 24, 50, 0.08);
  --text: #161a2e;
  --muted: #5c6383;
  --chip: rgba(20, 24, 50, 0.04);
  --chip-border: rgba(20, 24, 50, 0.1);
  --error-bg: rgba(255, 77, 109, 0.12);
  --shadow: 0 24px 60px rgba(60, 70, 120, 0.18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
/* Ensure [hidden] always wins over explicit display values (e.g. .preview is
   display:flex, which would otherwise override the UA [hidden] rule). */
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
  transition: background .4s ease, color .4s ease;
}

/* --- animated background orbs --- */
.bg-orbs { position: fixed; inset: 0; z-index: -1; overflow: hidden; }
.orb { position: absolute; border-radius: 50%; filter: blur(90px); opacity: .55; }
.orb-1 { width: 480px; height: 480px; background: #7c5cff; top: -120px; left: -80px; animation: float 18s ease-in-out infinite; }
.orb-2 { width: 420px; height: 420px; background: #ff4d6d; bottom: -140px; right: -60px; animation: float 22s ease-in-out infinite reverse; }
.orb-3 { width: 360px; height: 360px; background: #2bd9c0; top: 40%; right: 30%; opacity: .3; animation: float 26s ease-in-out infinite; }
@keyframes float { 0%,100% { transform: translate(0,0); } 50% { transform: translate(40px,-30px); } }

/* --- top bar --- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 920px; margin: 0 auto; padding: 22px 20px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 800; }
.brand-mark {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: var(--accent-grad); color: #fff; font-size: 14px;
  box-shadow: 0 6px 18px rgba(124, 92, 255, .45);
}
.brand-name { font-size: 1.2rem; letter-spacing: -.02em; }
.icon-btn {
  background: var(--chip); border: 1px solid var(--chip-border); color: var(--text);
  width: 40px; height: 40px; border-radius: 12px; cursor: pointer; font-size: 1.05rem;
  transition: transform .15s ease, background .2s ease;
}
.icon-btn:hover { transform: translateY(-2px); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* --- layout --- */
.container { max-width: 820px; margin: 0 auto; padding: 10px 20px 60px; }
.hero { text-align: center; margin: 26px 0 30px; }
.hero h1 { font-size: clamp(2rem, 5vw, 3.1rem); font-weight: 800; letter-spacing: -.03em; }
.grad { background: var(--accent-grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.subtitle { color: var(--muted); max-width: 560px; margin: 14px auto 0; font-size: 1.02rem; }

/* --- cards --- */
.card {
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: var(--radius); padding: 22px; backdrop-filter: blur(18px);
  box-shadow: var(--shadow); margin-bottom: 20px;
}
.url-card { padding: 16px; }
.url-row { display: flex; gap: 12px; }
.url-input-wrap {
  flex: 1; display: flex; align-items: center; gap: 8px;
  background: var(--chip); border: 1px solid var(--chip-border);
  border-radius: 14px; padding: 4px 6px 4px 14px; transition: border-color .2s ease;
}
.url-input-wrap:focus-within { border-color: var(--accent); }
.url-icon { opacity: .7; }
#urlInput { flex: 1; background: none; border: none; outline: none; color: var(--text); font-size: 1rem; padding: 12px 0; }
#urlInput::placeholder { color: var(--muted); }
.ghost-btn {
  background: var(--chip); border: 1px solid var(--chip-border); color: var(--muted);
  border-radius: 10px; padding: 8px 12px; font-size: .85rem; cursor: pointer; transition: color .2s, border-color .2s;
}
.ghost-btn:hover { color: var(--text); border-color: var(--accent); }

/* --- buttons --- */
.primary-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--accent-grad); color: #fff; border: none; border-radius: 14px;
  padding: 14px 22px; font-size: 1rem; font-weight: 600; cursor: pointer; text-decoration: none;
  box-shadow: 0 10px 26px rgba(124, 92, 255, .4); transition: transform .15s ease, box-shadow .2s, filter .2s;
  white-space: nowrap;
}
.primary-btn:hover { transform: translateY(-2px); box-shadow: 0 14px 32px rgba(124, 92, 255, .5); }
.primary-btn:disabled { filter: grayscale(.4) brightness(.8); cursor: not-allowed; transform: none; box-shadow: none; }
.convert-btn { width: 100%; margin-top: 6px; padding: 16px; }
.btn-spinner {
  width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-box {
  margin-top: 12px; padding: 12px 14px; border-radius: 12px; font-size: .9rem;
  background: var(--error-bg); color: var(--accent-2); border: 1px solid rgba(255,77,109,.25);
}

/* --- result preview --- */
.result-card { animation: rise .4s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.preview { display: flex; gap: 16px; margin-bottom: 20px; }
.thumb-wrap { position: relative; flex-shrink: 0; width: 168px; aspect-ratio: 16/9; border-radius: 12px; overflow: hidden; background: var(--chip); }
.thumb-wrap img { width: 100%; height: 100%; object-fit: cover; }
.duration-badge {
  position: absolute; right: 6px; bottom: 6px; background: rgba(0,0,0,.78); color: #fff;
  font-size: .75rem; font-weight: 600; padding: 2px 7px; border-radius: 6px;
}
.meta { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.meta h2 { font-size: 1.12rem; font-weight: 700; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.uploader { color: var(--muted); font-size: .9rem; margin-top: 4px; }

/* --- tabs --- */
.tabs { display: flex; gap: 8px; background: var(--chip); padding: 5px; border-radius: 13px; margin-bottom: 20px; }
.tab {
  flex: 1; background: none; border: none; color: var(--muted); font-size: .95rem; font-weight: 600;
  padding: 10px; border-radius: 10px; cursor: pointer; transition: all .2s ease;
}
.tab.active { background: var(--accent-grad); color: #fff; box-shadow: 0 6px 16px rgba(124,92,255,.4); }

/* --- option chips --- */
.option-group { margin-bottom: 18px; }
.option-label { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 10px; }
.chip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 10px; }
.chip {
  background: var(--chip); border: 1.5px solid var(--chip-border); border-radius: 12px;
  padding: 11px 12px; cursor: pointer; text-align: left; transition: all .18s ease; color: var(--text);
}
.chip:hover { border-color: var(--accent); transform: translateY(-2px); }
.chip.active { border-color: transparent; background: linear-gradient(120deg, rgba(124,92,255,.22), rgba(255,77,109,.22)); box-shadow: 0 0 0 1.5px var(--accent) inset; }
.chip.disabled { opacity: .35; pointer-events: none; }
.chip-title { display: block; font-weight: 700; font-size: .95rem; }
.chip-desc { display: block; font-size: .76rem; color: var(--muted); margin-top: 2px; }

/* --- progress --- */
.progress-card { animation: rise .4s ease; }
.progress-head { display: flex; justify-content: space-between; font-size: .92rem; margin-bottom: 10px; }
#progressPhase { color: var(--muted); }
#progressPct { font-weight: 700; }
.progress-track { height: 12px; background: var(--chip); border-radius: 100px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent-grad); border-radius: 100px; transition: width .35s ease; box-shadow: 0 0 14px rgba(124,92,255,.6); }

.done-box { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 20px; flex-wrap: wrap; animation: rise .4s ease; }
.done-info { display: flex; align-items: center; gap: 12px; }
.done-check { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: rgba(43,217,154,.16); color: var(--good); font-size: 1.1rem; }
.done-info strong { display: block; font-size: .98rem; }
.done-size { color: var(--muted); font-size: .85rem; }

/* --- features --- */
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-top: 10px; }
.feature { display: flex; gap: 12px; padding: 16px; border-radius: 14px; background: var(--card); border: 1px solid var(--card-border); }
.feature span { font-size: 1.4rem; }
.feature strong { font-size: .95rem; }
.feature p { font-size: .82rem; color: var(--muted); margin-top: 2px; }

/* --- footer --- */
.footer { text-align: center; padding: 30px 20px 50px; color: var(--muted); font-size: .85rem; }
.footer .muted { opacity: .6; margin-top: 6px; font-size: .78rem; }

/* --- playlist --- */
.playlist-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.playlist-head h2 { font-size: 1.15rem; font-weight: 700; }
.selectall { display: flex; align-items: center; gap: 7px; font-size: .9rem; color: var(--muted); cursor: pointer; white-space: nowrap; }
.selectall input, .pl-check { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }
.playlist-entries { max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; padding-right: 4px; }
.pl-item { display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 12px; background: var(--chip); border: 1px solid transparent; transition: border-color .15s ease; }
.pl-item:hover { border-color: var(--chip-border); }
.pl-item img { width: 84px; aspect-ratio: 16/9; object-fit: cover; border-radius: 8px; flex-shrink: 0; background: var(--bg); }
.pl-item .pl-title { font-size: .9rem; font-weight: 500; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pl-item .pl-dur { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.pl-item .pl-body { min-width: 0; flex: 1; }

/* --- trim --- */
.trim-toggle { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-weight: 600; font-size: .92rem; }
.trim-toggle input { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }
.trim-inputs { display: flex; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.trim-field { display: flex; flex-direction: column; gap: 4px; }
.trim-field label { font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.trim-field input { width: 110px; background: var(--chip); border: 1.5px solid var(--chip-border); border-radius: 10px; color: var(--text); padding: 9px 12px; font-size: .95rem; outline: none; transition: border-color .2s; }
.trim-field input:focus { border-color: var(--accent); }
.trim-sep { color: var(--muted); align-self: flex-end; padding-bottom: 9px; }
.trim-hint { font-size: .78rem; color: var(--muted); align-self: flex-end; padding-bottom: 9px; }

/* --- api key bar --- */
.api-key-bar { display: flex; align-items: center; gap: 10px; padding: 12px 14px; }
.api-key-bar .key-icon { opacity: .8; }
.api-key-bar input { flex: 1; background: var(--chip); border: 1px solid var(--chip-border); border-radius: 10px; color: var(--text); padding: 10px 12px; outline: none; font-size: .95rem; }
.api-key-bar input:focus { border-color: var(--accent); }

/* --- multi-select hint --- */
.multi-hint { font-size: .8rem; color: var(--muted); margin: -8px 0 16px; opacity: .85; }
.convert-hint { font-size: .8rem; color: var(--muted); margin: 12px 0 0; opacity: .85; text-align: center; line-height: 1.5; }

/* --- thumbnail button on preview --- */
#thumbBtn { margin-top: 10px; align-self: flex-start; }

/* --- footer link --- */
.footer-link { color: var(--accent); text-decoration: none; }
.footer-link:hover { text-decoration: underline; }

/* --- stats page --- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.stat-box { background: var(--chip); border: 1px solid var(--chip-border); border-radius: 14px; padding: 18px; }
.stat-num { font-size: 1.8rem; font-weight: 800; background: var(--accent-grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.stat-label { font-size: .82rem; color: var(--muted); margin-top: 4px; }
.bar-row { display: flex; align-items: center; gap: 12px; margin-bottom: 9px; }
.bar-key { width: 90px; flex-shrink: 0; font-size: .85rem; color: var(--muted); text-align: right; }
.bar-track { flex: 1; height: 22px; background: var(--chip); border-radius: 8px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent-grad); border-radius: 8px; min-width: 2px; transition: width .5s ease; }
.bar-val { width: 48px; flex-shrink: 0; font-size: .85rem; font-weight: 600; }
.card h3 { font-size: 1.05rem; font-weight: 700; margin-bottom: 16px; }

/* --- queue --- */
.queue-card { animation: rise .4s ease; }
.queue-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.queue-head h3 { font-size: 1.05rem; font-weight: 700; }
.queue-actions { display: flex; align-items: center; gap: 10px; }
.primary-btn.small { padding: 9px 14px; font-size: .85rem; border-radius: 11px; box-shadow: 0 6px 16px rgba(124,92,255,.35); }
.queue-list { display: flex; flex-direction: column; gap: 10px; }
.queue-item { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 14px; background: var(--chip); border: 1px solid var(--chip-border); animation: rise .3s ease; }
.qi-thumb { width: 72px; aspect-ratio: 16/9; object-fit: cover; border-radius: 8px; flex-shrink: 0; background: var(--bg); }
.qi-body { flex: 1; min-width: 0; }
.qi-title { display: block; font-size: .92rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qi-badge { display: inline-block; font-size: .72rem; font-weight: 600; color: var(--accent); background: rgba(124,92,255,.14); padding: 1px 7px; border-radius: 6px; margin-left: 4px; vertical-align: middle; }
.muted-note { color: var(--muted); font-size: .9rem; padding: 6px 2px; }
.qi-status { font-size: .8rem; color: var(--muted); margin: 3px 0 7px; }
.qi-status.err { color: var(--accent-2); }
.progress-track { height: 8px; background: rgba(255,255,255,.08); border-radius: 100px; overflow: hidden; }
[data-theme="light"] .progress-track { background: rgba(20,24,50,.08); }
.progress-fill { height: 100%; width: 0; background: var(--accent-grad); border-radius: 100px; transition: width .35s ease; }
.qi-action { flex-shrink: 0; }
.qi-dl { display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; background: var(--accent-grad); color: #fff; text-decoration: none; font-size: 1.15rem; box-shadow: 0 8px 20px rgba(124,92,255,.4); transition: transform .15s; }
.qi-dl:hover { transform: translateY(-2px); }
.qi-spin { width: 18px; height: 18px; border: 2px solid var(--chip-border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
.qi-check { color: var(--good); font-size: 1.3rem; }

/* --- responsive --- */
@media (max-width: 600px) {
  .url-row { flex-direction: column; }
  .loadBtn, .url-row .primary-btn { width: 100%; }
  .preview { flex-direction: column; }
  .thumb-wrap { width: 100%; }
}
