/* ============================================================
   Media Downloader — Mini App styles.
   Per-platform themes are driven by a body class (.theme-*) that
   swaps CSS custom properties. Icons are inline SVG using
   currentColor, so they recolor with the theme automatically.
   ============================================================ */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --radius: 14px;
  --radius-sm: 10px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --bg: #0f0f0f;
  --surface: #212121;
  --surface2: #181818;
  --text: #fff;
  --muted: #aaa;
  --border: #303030;
  --accent: #ff0033;
  --accent-contrast: #fff;
  --grad: none;
  --preview-aspect: 16 / 9;
}

/* ---- Per-platform themes ---- */
body.theme-youtube {
  --bg: #0f0f0f; --surface: #212121; --surface2: #181818;
  --text: #fff; --muted: #aaa; --border: #303030;
  --accent: #ff0033; --accent-contrast: #fff;
  --grad: linear-gradient(90deg, #ff0033, #cc0029);
  --preview-aspect: 16 / 9;
}
body.theme-tiktok {
  --bg: #000; --surface: #161616; --surface2: #0d0d0d;
  --text: #fff; --muted: #a1a1a1; --border: #2a2a2a;
  --accent: #fe2c55; --accent2: #25f4ee; --accent-contrast: #fff;
  --grad: linear-gradient(90deg, #25f4ee, #fe2c55);
  --preview-aspect: 9 / 16;
}
body.theme-instagram {
  --bg: #000; --surface: #161616; --surface2: #0d0d0d;
  --text: #fff; --muted: #a8a8a8; --border: #262626;
  --accent: #e1306c; --accent-contrast: #fff;
  --grad: linear-gradient(45deg, #feda75, #fa7e1e, #d62976, #962fbf, #4f5bd5);
  --preview-aspect: 1 / 1;
}
body.theme-twitch {
  --bg: #0e0e10; --surface: #18181b; --surface2: #1f1f23;
  --text: #efeff1; --muted: #adadb8; --border: #2a2a2d;
  --accent: #9146ff; --accent-contrast: #fff;
  --grad: linear-gradient(90deg, #9146ff, #772ce8);
  --preview-aspect: 16 / 9;
}

html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  transition: background .25s var(--ease);
  padding-bottom: env(safe-area-inset-bottom);
}

svg { width: 1em; height: 1em; display: block; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
.hidden { display: none !important; }

/* ---- Top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px 6px;
}
.brand-ic { font-size: 24px; color: var(--accent); display: flex; }
.brand-name { font-size: 19px; font-weight: 800; letter-spacing: .2px; flex: 1; }
.brand-history { font-size: 22px; color: var(--muted); }

.tabs { display: flex; gap: 4px; padding: 0 8px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 12px 12px; color: var(--muted);
  font-size: 13.5px; font-weight: 600; white-space: nowrap;
  border-bottom: 2.5px solid transparent; transition: color .15s, border-color .15s;
}
.tab svg { font-size: 18px; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab.active svg { color: var(--accent); }

/* ---- Content ---- */
.content { padding: 14px 16px 28px; max-width: 640px; margin: 0 auto; }

/* ---- Input card ---- */
.input-card { margin-bottom: 16px; }
.input-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0 12px; height: 50px;
}
.input-row:focus-within { border-color: var(--accent); }
.input-ic { font-size: 20px; color: var(--muted); display: flex; }
#urlInput {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-size: 15px; height: 100%;
}
#urlInput::placeholder { color: var(--muted); }
.clear-btn { font-size: 18px; color: var(--muted); padding: 6px; }

.primary-btn {
  margin-top: 10px; width: 100%; height: 50px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: var(--accent-contrast);
  border-radius: var(--radius); font-size: 16px; font-weight: 700;
  transition: transform .08s, filter .15s;
}
body.theme-instagram .primary-btn { background: var(--grad); }
.primary-btn svg { font-size: 20px; }
.primary-btn:active { transform: scale(.98); filter: brightness(1.05); }
.primary-btn[disabled] { opacity: .55; pointer-events: none; }

.ghost-btn {
  width: 100%; height: 46px; border-radius: var(--radius);
  border: 1px solid var(--border); color: var(--muted); font-weight: 600;
}
.hint { color: var(--muted); font-size: 13px; margin: 10px 2px 0; min-height: 1em; }

/* ---- Result card (YouTube-style) ---- */
.result-area { display: flex; flex-direction: column; gap: 14px; }
.vcard {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  animation: rise .25s var(--ease);
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.vthumb {
  position: relative; width: 100%; aspect-ratio: var(--preview-aspect);
  background: var(--surface2);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
body.theme-tiktok .vthumb, body.theme-instagram .vthumb { max-height: 62vh; }
.vthumb-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.vthumb .thumb-fallback { font-size: 46px; color: var(--border); }
.vthumb .play-badge {
  position: absolute; z-index: 2; font-size: 42px; color: #fff; opacity: .92;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,.5));
}
.duration-badge {
  position: absolute; z-index: 2; right: 8px; bottom: 8px;
  background: rgba(0,0,0,.82); color: #fff; font-size: 12px; font-weight: 700;
  padding: 2px 6px; border-radius: 6px; letter-spacing: .3px;
  display: flex; align-items: center; gap: 4px;
}
.duration-badge svg { font-size: 13px; }

.vbody { padding: 12px 14px 14px; }
.vtitle { font-size: 15.5px; font-weight: 600; line-height: 1.3; margin: 0 0 6px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.vmeta { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.vmeta .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--muted); display: inline-block; }
.vactions { display: flex; gap: 8px; margin-top: 12px; }
.vactions .primary-btn { margin-top: 0; }
.vactions .icon-pill {
  flex: 0 0 auto; width: 50px; height: 50px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface2);
  display: flex; align-items: center; justify-content: center; font-size: 22px; color: var(--text);
}

.icon-btn { display: flex; align-items: center; justify-content: center; padding: 6px; }

/* ---- Empty / status text ---- */
.placeholder {
  text-align: center; color: var(--muted); padding: 40px 20px; font-size: 14px;
}
.placeholder .big { font-size: 44px; color: var(--border); display: inline-flex; margin-bottom: 10px; }

/* ---- Video list (search results / channel videos) ---- */
.video-list { display: flex; flex-direction: column; gap: 12px; }
.vrow { display: flex; gap: 10px; align-items: flex-start; animation: rise .2s var(--ease); }
.vrow-thumb {
  position: relative; flex: 0 0 44%; max-width: 168px; aspect-ratio: 16/9;
  border-radius: var(--radius-sm); overflow: hidden; background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
}
.vrow-thumb .vthumb-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.vrow-thumb .thumb-fallback { font-size: 30px; color: var(--border); }
.vrow-thumb .duration-badge { right: 5px; bottom: 5px; font-size: 11px; padding: 1px 5px; }
.vrow-body { flex: 1; min-width: 0; }
.vrow-title {
  font-size: 14px; font-weight: 600; line-height: 1.3; margin-bottom: 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.vrow-chan {
  font-size: 12.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px;
}
.vrow-chan:active { color: var(--text); }
.vrow-meta { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.vrow-meta svg { font-size: 13px; }
.vrow-dl {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--accent);
  display: flex; align-items: center; justify-content: center; font-size: 20px; color: var(--accent);
}
.vrow-dl:active { transform: scale(.94); }
.list-title { font-size: 15px; font-weight: 700; margin: 2px 0 12px; color: var(--muted); }

/* channel result row */
.crow {
  display: flex; align-items: center; gap: 12px; padding: 6px 2px;
  animation: rise .2s var(--ease);
}
.crow-ava {
  position: relative; flex: 0 0 auto; width: 60px; height: 60px; border-radius: 50%;
  overflow: hidden; background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
}
.crow-ava-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.crow-ava-fb { font-size: 26px; color: var(--border); }
.crow-body { flex: 1; min-width: 0; }
.crow-name { font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crow-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.crow-go { flex: 0 0 auto; font-size: 20px; color: var(--muted); }

/* ---- Channel / artist page ---- */
.channel-view {
  position: fixed; inset: 0; z-index: 30; background: var(--bg);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding-bottom: calc(28px + env(safe-area-inset-bottom));
}
body.no-scroll { overflow: hidden; }
.channel-back {
  position: sticky; top: 0; z-index: 3; width: 100%;
  display: flex; align-items: center; gap: 6px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: var(--surface2); border-bottom: 1px solid var(--border);
  color: var(--text); font-weight: 600; font-size: 15px;
}
.channel-back svg { font-size: 22px; color: var(--accent); }
.channel-banner {
  height: 120px; background: var(--surface2) center/cover no-repeat;
}
.channel-banner.empty { background: linear-gradient(120deg, var(--surface2), var(--surface)); }
.channel-head { display: flex; align-items: center; gap: 14px; padding: 12px 16px 6px; }
.channel-avatar {
  flex: 0 0 auto; width: 76px; height: 76px; border-radius: 50%;
  background: var(--surface2) center/cover no-repeat; border: 3px solid var(--bg);
  margin-top: -42px; box-shadow: 0 2px 10px rgba(0,0,0,.4);
}
.pl-back {
  display: inline-flex; align-items: center; gap: 6px; margin-bottom: 12px;
  padding: 8px 12px; border-radius: 10px; background: var(--surface2);
  border: 1px solid var(--border); color: var(--text); font-weight: 600; font-size: 14px;
}
.pl-back svg { font-size: 18px; }
.pl-badge {
  position: absolute; z-index: 2; right: 6px; top: 6px; font-size: 15px; color: #fff;
  background: rgba(0,0,0,.7); border-radius: 6px; padding: 2px 5px; display: flex;
}
.channel-info { min-width: 0; }
.channel-name { font-size: 20px; font-weight: 800; line-height: 1.2; }
.channel-sub { font-size: 13px; color: var(--muted); margin-top: 3px; display: flex; align-items: center; gap: 5px; }
.channel-sub svg { font-size: 14px; }
.channel-tabs { display: flex; gap: 6px; padding: 8px 16px 0; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.ctab {
  padding: 8px 4px 12px; margin-right: 14px; color: var(--muted);
  font-size: 14px; font-weight: 700; border-bottom: 2.5px solid transparent;
}
.ctab.active { color: var(--text); border-bottom-color: var(--accent); }
.channel-view .video-list { padding: 0 16px; }
.channel-about { padding: 0 16px; color: var(--muted); font-size: 14px; white-space: pre-wrap; line-height: 1.5; }

/* ---- Bottom sheet ---- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 40;
  animation: fade .2s var(--ease);
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  background: var(--surface); border-top-left-radius: 20px; border-top-right-radius: 20px;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto;
  animation: slideup .28s var(--ease);
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: none; } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 6px auto 12px; }
.sheet-title { margin: 0 0 12px; font-size: 16px; font-weight: 700; }
.quality-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px; }
.qbtn {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 12px 4px; border-radius: var(--radius-sm);
  background: var(--surface2); border: 1px solid var(--border);
  transition: transform .08s, border-color .15s;
}
.qbtn:active { transform: scale(.97); }
.qbtn.selectable { border-color: var(--accent); }
.qbtn .qres { font-size: 15px; font-weight: 800; }
.qbtn .qsize { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 3px; }
.qbtn .qsize svg { font-size: 12px; }
.qbtn.disabled { opacity: .45; pointer-events: none; }
.qbtn.disabled .qsize { color: var(--accent); }

.sheet-row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 14px 12px; border-radius: var(--radius-sm);
  background: var(--surface2); border: 1px solid var(--border); margin-top: 4px;
}
.sheet-row-ic { font-size: 22px; color: var(--accent); display: flex; }
.sheet-row-label { font-weight: 600; }

/* ---- Progress overlay ---- */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.progress-card {
  width: 100%; max-width: 340px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 20px; padding: 24px 20px;
  text-align: center;
}
.progress-ring { font-size: 46px; color: var(--accent); display: flex; justify-content: center; margin-bottom: 12px; }
.progress-ring.ok { color: #2ecc71; }
.progress-ring.err { color: #ff4d4f; }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress-title { font-weight: 700; font-size: 16px; margin-bottom: 14px; }
.progress-bar { height: 8px; background: var(--surface2); border-radius: 6px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: var(--accent); border-radius: 6px; transition: width .3s var(--ease); }
body.theme-instagram .progress-fill { background: var(--grad); }
.progress-fill.indeterminate { width: 40% !important; animation: indet 1.2s ease-in-out infinite; }
@keyframes indet { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }
.progress-meta { color: var(--muted); font-size: 13px; margin-top: 10px; min-height: 1em; }
.progress-actions { margin-top: 18px; display: flex; flex-direction: column; gap: 8px; }
.progress-actions .primary-btn { margin-top: 0; }

/* ---- History ---- */
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.section-head h2 { margin: 0; font-size: 18px; }
.section-head .icon-btn { font-size: 22px; color: var(--muted); }
.history-list { display: flex; flex-direction: column; gap: 8px; }
.hitem {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.hitem-ic { font-size: 22px; color: var(--accent); display: flex; flex: 0 0 auto; }
.hitem-body { flex: 1; min-width: 0; }
.hitem-title { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hitem-sub { font-size: 12px; color: var(--muted); }
.hitem-go { font-size: 20px; color: var(--accent); flex: 0 0 auto; }

/* ---- TikTok profile ---- */
.tt-profile {
  position: fixed; inset: 0; z-index: 31; background: var(--bg);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding-bottom: calc(28px + env(safe-area-inset-bottom));
}
.tt-head { display: flex; align-items: flex-start; gap: 14px; padding: 12px 16px 4px; }
.tt-head-text { flex: 1; min-width: 0; }
.tt-name { font-size: 22px; font-weight: 800; line-height: 1.15; }
.tt-handle { font-size: 14px; color: var(--muted); margin-top: 4px; }
.tt-avatar {
  flex: 0 0 auto; width: 92px; height: 92px; border-radius: 50%; overflow: hidden;
  background: var(--surface2); display: flex; align-items: center; justify-content: center;
}
.tt-avatar img { width: 100%; height: 100%; object-fit: cover; }
.tt-avatar .fb { font-size: 34px; color: var(--border); }
.tt-stats { display: flex; gap: 6px; padding: 12px 16px 6px; }
.tt-stat { flex: 1; text-align: center; }
.tt-stat b { display: block; font-size: 18px; font-weight: 800; }
.tt-stat span { font-size: 12.5px; color: var(--muted); }
.tt-bio { padding: 6px 16px 14px; font-size: 14px; line-height: 1.45; white-space: pre-wrap; }
.tt-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; padding: 0 2px; }
.tt-cell { position: relative; aspect-ratio: 9 / 16; background: var(--surface2); overflow: hidden; }
.tt-cell img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tt-cell .fb { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 26px; color: var(--border); }
.tt-cell:active { opacity: .85; }
.tt-views {
  position: absolute; left: 6px; bottom: 6px; z-index: 2;
  display: flex; align-items: center; gap: 4px; color: #fff; font-size: 12px; font-weight: 700;
  text-shadow: 0 1px 3px rgba(0,0,0,.85);
}
.tt-views svg { font-size: 14px; }

/* ---- In-app player ---- */
.player-overlay {
  position: fixed; inset: 0; z-index: 55; background: #000;
  display: flex; align-items: center; justify-content: center;
}
.player-video { width: 100%; max-height: 100%; background: #000; display: block; }
.player-close {
  position: absolute; z-index: 2; top: calc(10px + env(safe-area-inset-top)); right: 12px;
  width: 40px; height: 40px; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 22px;
}
.icon-pill.watch { color: var(--accent); border-color: var(--accent); }
.hitem-play { flex: 0 0 auto; font-size: 22px; color: var(--accent); padding: 6px; display: flex; }

/* ---- Toast ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 60;
  background: #2b2b2b; color: #fff; border: 1px solid var(--border);
  padding: 12px 18px; border-radius: 12px; font-size: 14px; max-width: 86%;
  box-shadow: 0 8px 24px rgba(0,0,0,.4); animation: rise .2s var(--ease);
}
.toast.err { border-color: #ff4d4f; }

/* ---- Gate ---- */
.gate { position: fixed; inset: 0; z-index: 70; background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 32px; }
.gate-card { text-align: center; max-width: 320px; }
.gate-ic { font-size: 52px; color: var(--accent); display: inline-flex; margin-bottom: 14px; }
.gate-card h2 { margin: 0 0 8px; font-size: 19px; }
.gate-card p { margin: 0; color: var(--muted); font-size: 14px; }
