/* Shell, theming and the components every platform reuses.
   A body class (.theme-*) swaps the custom properties; icons are inline SVG
   drawn with currentColor, so they follow 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;
}

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-account {
  --bg: #0f0d14; --surface: #1a1622; --surface2: #141019;
  --text: #fff; --muted: #9a91a8; --border: #2c2536;
  --accent: #a855f7; --accent-contrast: #fff;
  --grad: linear-gradient(135deg, #a855f7, #7c3aed);
  --preview-aspect: 1 / 1;
}

html, body { margin: 0; height: 100%; }
/* Never let a wide child (long history titles/URLs) make the page pan sideways. */
html { overflow-x: hidden; }
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);
}
body.no-scroll { overflow: hidden; }

/* flex: none is required: WebKit shrinks an SVG that carries its own aspect
   ratio (a viewBox) to zero width inside a flex container, which silently
   blanks inline icons on iOS. */
svg { width: 1em; height: 1em; display: block; flex: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
.hidden { display: none !important; }
.flip { transform: scaleX(-1); }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideup { from { transform: translateY(100%); } to { transform: none; } }

/* 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 { padding: 14px 16px 28px; max-width: 640px; margin: 0 auto; }

/* input */
.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 */
.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);
}
.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-pill.watch { color: var(--accent); border-color: var(--accent); }
.icon-btn { display: flex; align-items: center; justify-content: center; padding: 6px; }

.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; }

/* lists */
.video-list { display: flex; flex-direction: column; gap: 12px; }
.list-title { font-size: 15px; font-weight: 700; margin: 2px 0 12px; color: var(--muted); }
.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(--accent); border: none;
  display: flex; align-items: center; justify-content: center; font-size: 20px; color: var(--accent-contrast);
}
body.theme-instagram .vrow-dl { background: var(--grad); }
.vrow-dl:active { transform: scale(.94); }
/* Pin the glyph size: a button's font-size is not inherited in Safari, so 1em
   cannot be trusted here. */
.vrow-dl svg, .hitem-go svg, .post-dl svg { width: 20px; height: 20px; }

.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); }
.crow-go .flip { width: 20px; height: 20px; }
.ig-badge { color: #3897f0; font-size: 17px; display: inline-flex; }

/* bottom sheet */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 40;
  animation: fade .2s var(--ease);
}
.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);
}
.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 .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); }
/* Subscriber-only tier: dimmed but still tappable so a tap can explain why. */
.qbtn.locked { opacity: .6; }
.qbtn.locked .qres, .qbtn.locked .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 {
  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; }
.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; }
/* display:block is required for ellipsis: as inline spans the title didn't clip
   and ran into the subtitle, widening the row and panning the whole page. */
.hitem-title { display: block; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hitem-sub { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hitem-go { font-size: 20px; color: var(--accent); flex: 0 0 auto; }
.hitem-play { flex: 0 0 auto; font-size: 22px; color: var(--accent); padding: 6px; display: flex; }

/* 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;
}

/* toast + gate */
.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 {
  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; }

/* ---- subscription sheet (opened from locked quality / comments) ---- */
.sub-wrap { position: fixed; inset: 0; z-index: 70; }
.sub-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); animation: fade .2s var(--ease); }
.sub-sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-width: 640px; margin: 0 auto;
  background: var(--surface); border-top-left-radius: 20px; border-top-right-radius: 20px;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -1px 0 var(--border), 0 -18px 50px rgba(0,0,0,.5);
  animation: slideup .28s var(--ease);
}
.sub-head { display: flex; align-items: center; gap: 10px; margin: 4px 0 12px; }
.sub-gem { display: flex; color: var(--accent); font-size: 24px; }
.sub-title { margin: 0; font-size: 19px; font-weight: 800; }
.sub-status { color: var(--accent); font-size: 13px; font-weight: 600; margin: -6px 0 12px; }
.sub-perks { list-style: none; margin: 0 0 18px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.sub-perks li { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.sub-perks li svg { flex: none; width: 20px; height: 20px; color: var(--accent); }
.sub-plans { display: flex; flex-direction: column; gap: 12px; }
.sub-plan {
  position: relative; display: flex; align-items: center; justify-content: space-between;
  min-height: 54px; padding: 14px 16px; border-radius: 14px;
  background: var(--surface2); border: 1px solid var(--border); color: var(--text);
  transition: transform .08s var(--ease), border-color .15s var(--ease);
}
.sub-plan:active { transform: scale(.96); }
.sub-plan:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sub-plan-top { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.sub-plan-badge {
  position: absolute; top: -9px; inset-inline-start: 14px; padding: 2px 9px; border-radius: 999px;
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; letter-spacing: .01em;
}
.sub-plan-days { font-size: 16px; font-weight: 700; }
.sub-plan-price { display: flex; align-items: center; gap: 5px; font-size: 16px; font-weight: 800; }
.sub-plan-price svg { width: 18px; height: 18px; }
.sub-note { text-align: center; color: var(--muted); font-size: 12.5px; margin: 12px 0 4px; }
.sub-close { display: block; width: 100%; padding: 12px; margin-top: 4px; background: none; border: none; color: var(--muted); font-weight: 600; font-size: 15px; }
/* Comments subscription gate + its CTA. */
.pc-gate { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 20px 0; text-align: center; }
.pc-gate-txt { color: var(--muted); font-size: 14px; }
.pc-gate-btn {
  padding: 11px 20px; border-radius: 999px; background: var(--accent); border: none; color: #fff;
  font-weight: 700; font-size: 14px; transition: transform .08s var(--ease);
}
.pc-gate-btn:active { transform: scale(.96); }
.pc-gate-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  .sub-sheet, .sub-backdrop { animation: none; }
  .sub-plan:active, .pc-gate-btn:active { transform: none; }
}

/* ---- author-subscription follow button (in profile headers) ---- */
.sub-btn { display: inline-flex; align-items: center; gap: 6px; margin-top: 8px;
  padding: 7px 14px; border: 0; border-radius: 999px; cursor: pointer;
  background: var(--accent); color: var(--accent-contrast, #fff);
  font-size: 13px; font-weight: 700; line-height: 1;
  transition: filter .15s var(--ease), background .15s var(--ease); }
.sub-btn svg { width: 16px; height: 16px; }
.sub-btn:active { filter: brightness(.92); }
.sub-btn.subbed { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.sub-btn.hidden { display: none; }
.ig-follow { width: 100%; margin: 0; justify-content: center; }
/* The "My subscriptions" list styling lives in account.css (its only screen). */
