:root {
    --bg: #0f1115;
    --bg-elev: #171a21;
    --card: #1a1e26;
    --card-hover: #22283300;
    --border: #2a2f3a;
    --text: #e8eaed;
    --text-dim: #9aa0a6;
    --accent: #ff0033;
    --accent-glow: rgba(255, 0, 51, 0.35);
    --radius: 14px;
    --radius-lg: 18px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
}

body {
    background:
        radial-gradient(1100px 480px at 15% -10%, rgba(255, 0, 51, 0.13), transparent 60%),
        var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    min-height: 100vh;
    line-height: 1.5;
}

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.1rem 2rem;
    max-width: 1280px;
    margin: 0 auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    text-decoration: none;
    color: var(--text);
    font-weight: 800;
    font-size: 1.25rem;
    letter-spacing: -0.02em;
}

.brand-logo {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--accent);
    position: relative;
    box-shadow: 0 2px 14px var(--accent-glow);
}

.brand-logo::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 0;
    height: 0;
    transform: translate(-35%, -50%);
    border: 6px solid transparent;
    border-left: 9px solid #fff;
}

.brand-name span { color: var(--accent); }

/* ---- Site nav ---- */

.site-nav {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    min-width: 0;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    color: var(--text);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 600;
    padding: 0.45rem 1rem;
    border-radius: 999px;
    background: var(--card);
    border: 1px solid var(--border);
    transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.nav-link.active {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 2px 12px var(--accent-glow);
}

.nav-link[hidden] {
    display: none !important;
}

.nav-link svg {
    width: 16px;
    height: 16px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.page {
    max-width: 1280px;
    margin: 0 auto;
    padding: 1.5rem 2rem;
}

.hero {
    text-align: center;
    padding: 2.5rem 1rem 2.25rem;
}

.hero-title {
    font-size: clamp(1.9rem, 4.6vw, 3.2rem);
    margin: 0 0 0.75rem;
    font-weight: 900;
    letter-spacing: -0.03em;
    line-height: 1.15;
}

.hero-title span {
    color: var(--accent);
    position: relative;
}

.hero-sub {
    color: var(--text-dim);
    margin: 0 auto 1.75rem;
    max-width: 560px;
    font-size: 1.05rem;
}

.search-form {
    max-width: 640px;
    margin: 0 auto;
}

.filter-bar {
    display: flex;
    justify-content: center;
    gap: 0.9rem;
    flex-wrap: wrap;
    margin: 1.15rem auto 0;
    max-width: 640px;
}

.filter-item {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.35rem 0.4rem 0.35rem 0.95rem;
    transition: border-color 0.2s;
}

.filter-item:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.filter-label {
    color: var(--text-dim);
    font-size: 0.82rem;
    white-space: nowrap;
}

.filter-select {
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    border: 0;
    outline: 0;
    color: var(--text);
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0.4rem 1.6rem 0.4rem 0.5rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239aa0a6' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.45rem center;
}

.filter-select option {
    background: var(--bg-elev);
    color: var(--text);
}

.search-box {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.4rem 0.5rem 0.4rem 1.2rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-box:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-glow);
}

.search-icon {
    width: 20px;
    height: 20px;
    flex: none;
    fill: none;
    stroke: var(--text-dim);
    stroke-width: 2;
    stroke-linecap: round;
}

#search-input,
#dl-input,
#sm-input {
    flex: 1;
    min-width: 0;
    background: none;
    border: 0;
    outline: 0;
    color: var(--text);
    font-size: 1.05rem;
    padding: 0.6rem 0;
}

#search-input::placeholder,
#dl-input::placeholder,
#sm-input::placeholder { color: var(--text-dim); }

#search-input::-webkit-search-cancel-button,
#dl-input::-webkit-search-cancel-button { display: none; }

.clear-btn {
    flex: none;
    width: 34px;
    height: 34px;
    border-radius: 999px;
    border: 0;
    background: var(--border);
    color: var(--text-dim);
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.clear-btn:hover { background: var(--accent); color: #fff; }

/* ---- Results ---- */

.results {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem 1.3rem;
    margin-top: 0.75rem;
}

.result-heading {
    grid-column: 1 / -1;
    color: var(--text-dim);
    font-size: 0.9rem;
    margin: 0.25rem 0 0;
}

.pl-panel {
    grid-column: 1 / -1;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.9rem 1rem;
    margin-top: 0rem;
}
.pl-head-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0rem;
}
.pl-head {
    color: var(--text);
    font-size: 0.98rem;
    font-weight: 600;
}
.pl-toggle {
    flex-shrink: 0;
    font: inherit;
    font-size: 0.8rem;
    padding: 0.25rem 0.7rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg-elev);
    color: var(--text-dim);
}
.pl-toggle:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--bg-elev);
}
.pl-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.pl-list.hidden {
    display: none;
}
.pl-li {
    position: relative;
    padding-left: 1.05rem;
}
.pl-li::before {
    content: "\2022";
    position: absolute;
    left: 0;
    top: 0.68rem;
    font-size: 0.85rem;
    line-height: 1;
    color: var(--text-dim);
}
.pl-item {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    border-radius: 6px;
    padding: 0.45rem 0.6rem;
    font: inherit;
    font-size: 0.92rem;
    color: var(--text);
    cursor: pointer;
    transition: background-color 0.15s;
}
.pl-item:hover {
    background: var(--bg-elev);
}
.pl-item.on {
    font-weight: 700;
}
.pl-item.pl-back {
    color: var(--text-dim);
    font-size: 0.85rem;
}

.card {
    position: relative;
    background: var(--card);
    border: 1px solid transparent;
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.18s, border-color 0.18s, box-shadow 0.18s;
}

.card:hover {
    transform: translateY(-4px);
    border-color: var(--border);
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45);
}

.card-link {
    display: block;
    color: inherit;
    text-decoration: none;
}

.card-thumb {
    position: relative;
    aspect-ratio: 16 / 9;
    background: var(--bg-elev);
    overflow: hidden;
}

.card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.25s;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.card:hover .card-thumb img { transform: scale(1.05); }

.card-duration {
    position: absolute;
    right: 8px;
    bottom: 8px;
    background: rgba(0, 0, 0, 0.82);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.12rem 0.45rem;
    border-radius: 6px;
    letter-spacing: 0.02em;
}

.card-body { padding: 0.85rem 1rem 1rem; }

.card-title {
    margin: 0 0 0.5rem;
    font-size: 0.98rem;
    font-weight: 600;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-meta {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    color: var(--text-dim);
    font-size: 0.82rem;
    min-height: 36px;
}

.card-meta img {
    width: 26px;
    height: 26px;
    border-radius: 999px;
    flex: none;
    object-fit: cover;
}

.card-channel {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.card-channel:hover { color: var(--text); }

.dot { opacity: 0.6; }

/* ---- States ---- */

.state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3.5rem 1rem;
    color: var(--text-dim);
}

.state-icon {
    width: 54px;
    height: 54px;
    margin: 0 auto 1rem;
    border-radius: 999px;
    background: var(--card);
    border: 1px solid var(--border);
    display: grid;
    place-items: center;
    font-size: 1.5rem;
}

.state p { margin: 0 0 0.35rem; color: var(--text-dim); }

.state .state-main {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
}

.chips {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.6rem;
    margin-top: 1.4rem;
}

.chip {
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    font: inherit;
    font-size: 0.9rem;
    padding: 0.5rem 1.1rem;
    border-radius: 999px;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.chip:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--bg-elev);
}

/* ---- Load more ---- */

.load-more {
    grid-column: 1 / -1;
    justify-self: center;
    margin-top: 1.75rem;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    color: var(--text);
    font: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    padding: 0.75rem 2.4rem;
    border-radius: 999px;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background 0.15s, opacity 0.15s;
}

.load-more:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--bg-elev);
}

.load-more:disabled {
    opacity: 0.55;
    cursor: default;
}

.skeleton-card .card-thumb,
.skeleton-card .sk {
    background: linear-gradient(100deg, var(--card) 40%, var(--bg-elev) 50%, var(--card) 60%);
    background-size: 200% 100%;
    animation: shimmer 1.3s infinite;
}

.skeleton-card { cursor: default; }
.skeleton-card:hover { transform: none; border-color: transparent; box-shadow: none; }

.skeleton-card .sk-line {
    height: 12px;
    margin: 0.85rem 1rem 0.5rem;
    border-radius: 6px;
}

.skeleton-card .sk-line.sk-short { width: 55%; height: 10px; margin-top: 0; }

@keyframes shimmer {
    to { background-position: -200% 0; }
}

/* ---- Modal ---- */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(6, 8, 12, 0.78);
    backdrop-filter: blur(6px);
    display: grid;
    place-items: center;
    padding: 1.25rem;
    z-index: 50;
    animation: fade-in 0.16s ease;
}

.modal[hidden] {
    display: none;
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-card {
    width: min(860px, 100%);
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
    animation: rise 0.22s ease;
}

@keyframes rise {
    from { transform: translateY(18px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-frame {
    position: relative;
    aspect-ratio: 16 / 9;
    background: #000;
}

#player {
    width: 100%;
    height: 100%;
}

#player iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}

.modal-close {
    position: absolute;
    top: 28px;
    right: 32px;
    width: 40px;
    height: 40px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg-elev);
    color: var(--text);
    font-size: 0.9rem;
    cursor: pointer;
    z-index: 1;
    transition: background 0.15s, transform 0.15s;
}

.modal-close:hover { background: var(--accent); border-color: var(--accent); transform: scale(1.06); }

.modal-meta { padding: 1rem 1.25rem 1.25rem; }

.modal-title {
    margin: 0 0 0.25rem;
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.35;
}

.modal-channel { margin: 0; color: var(--text-dim); font-size: 0.9rem; }

/* ---- Scroll to top ---- */

.scroll-top {
    position: fixed;
    right: 22px;
    bottom: 22px;
    width: 46px;
    height: 46px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg-elev);
    color: var(--text);
    font-size: 1.15rem;
    cursor: pointer;
    z-index: 40;
    display: grid;
    place-items: center;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    transition: background 0.15s, border-color 0.15s, transform 0.15s, opacity 0.2s;
}

.scroll-top:hover {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
    transform: translateY(-2px);
}

.scroll-top[hidden] { display: none; }

/* ---- Ads (quảng cáo) ---- */
.ads-slot {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    text-align: center;
    overflow: hidden;
}
.ads-slot iframe {
    max-width: 100%;
    vertical-align: top;
}
.ads-slot[hidden] { display: none; }

.ads-footer {
    max-width: 1280px;
    margin: 0 auto 1rem;
    padding: 0 1.5rem 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 1rem;
}

.ads-searchbox {
    max-width: 640px;
    margin: 2.5rem auto 0;
}

/* ---- Pull-to-refresh (iOS standalone PWA — Safari tắt gesture gốc) ---- */
.ptr-indicator {
    position: fixed;
    top: 0;
    left: 50%;
    width: 54px;
    height: 54px;
    margin-left: -27px;
    z-index: 999;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    transition: opacity 0.2s ease;
    opacity: 0;
    transform: translateY(-60px);
}
.ptr-indicator.ptr-armed {
    opacity: 1;
}
.ptr-indicator svg {
    width: 27px;
    height: 27px;
    fill: none;
    stroke: #fff;
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.ptr-indicator.ptr-armed svg {
    animation: ptr-spin 0.7s linear infinite;
}
@keyframes ptr-spin { to { transform: rotate(360deg); } }


/* ---- Responsive ---- */

@media (max-width: 720px) {
    .site-header { padding: 1rem; flex-wrap: wrap; }
    .header-left { flex-wrap: wrap; gap: 0.75rem 1rem; }
    .site-nav { order: 3; width: 100%; justify-content: flex-start; }
    .page { padding: 0.75rem 1rem 3rem; }
    .hero { padding: 1.5rem 0.5rem 1.75rem; }
    .modal-close { top: 18px; right: 22px; }
    .pl-li::before { font-size: 1.05rem; top: 0.6rem; color: var(--text); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---- YouTube Downloader ---- */

.dl-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    margin: 0 0 1.75rem;
}

.dl-brand-icon {
    width: 72px;
    height: 72px;
    flex: none;
    fill: none;
    stroke: var(--accent);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.dl-brand-text {
    margin: 0;
    font-size: clamp(1.9rem, 4.6vw, 3.2rem);
    font-weight: 900;
    letter-spacing: -0.03em;
    line-height: 1.15;
    color: var(--text);
}

.dl-brand-text span { color: var(--accent); }

.dl-brand[hidden] { display: none; }

.dl-output { margin-top: 1rem; }

.dl-video {
    position: relative;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
}

.dl-video .ft-star--top {
    top: 1rem;
    right: 1rem;
    bottom: auto;
}
.dl-video .dl-title { padding-right: 2.6rem; }

.dl-title {
    margin: 0 0 0.4rem;
    font-size: clamp(1.1rem, 2.6vw, 1.4rem);
    font-weight: 800;
    line-height: 1.3;
}

.dl-meta { margin: 0 0 0.35rem; color: var(--text-dim); font-size: 0.92rem; }

.dl-meta a.dl-meta-author {
    color: var(--text-dim);
    text-decoration: none;
    transition: color 0.15s;
}
.dl-meta a.dl-meta-author:hover {
    color: var(--accent);
}

.dl-id {
    margin: 0;
    color: var(--text-dim);
    font-size: 0.8rem;
}

.dl-id code {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 0.05rem 0.4rem;
    color: var(--text);
}

.dl-section { margin-top: 1.6rem; }

/* Khối thumbnail: position relative để neo nút ✕ góc phải. */
.dl-thumb-section { position: relative; }

.dl-sec-close {
    position: absolute;
    top: -0.15rem;
    right: -0.1rem;
    background: none;
    border: 0;
    color: var(--text-dim);
    font-size: 0.95rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.2rem 0.45rem;
    border-radius: 6px;
    z-index: 2;
}

.dl-sec-close:hover { color: var(--text); background: var(--card); }

.dl-section h3 {
    font-size: 0.98rem;
    font-weight: 700;
    margin: 0 0 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.dl-section .count {
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--text-dim);
    background: var(--bg-elev);
    border: 1px solid var(--border);
    padding: 0.1rem 0.55rem;
    border-radius: 999px;
}

.dl-note {
    margin: 0.9rem 0;
    color: var(--text-dim);
    font-size: 0.85rem;
    line-height: 1.55;
}

.dl-table-wrap {
    position: relative;
    overflow-x: auto;
    margin-bottom: 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--card);
}

.dl-table-close {
    position: absolute;
    top: 0.35rem;
    right: 0.45rem;
    z-index: 2;
    border: 0;
    background: transparent;
    color: var(--text-dim);
    font-size: 1rem;
    line-height: 1;
    padding: 0.3rem 0.45rem;
    cursor: pointer;
    border-radius: var(--radius);
}
.dl-table-close:hover {
    color: var(--accent);
    background: var(--bg-elev);
}

.dl-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    min-width: 560px;
}

.dl-table-cap {
    caption-side: top;
    text-align: left;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text);
    padding: 0.75rem 0.9rem 0.4rem;
    padding-right: 2.2rem;
    background: var(--bg-elev);
}

.dl-table th {
    text-align: left;
    color: var(--text-dim);
    font-weight: 600;
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.55rem 0.9rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.dl-table td {
    padding: 0.6rem 0.9rem;
    border-top: 1px solid var(--border);
    vertical-align: middle;
}

.dl-table tbody tr:first-child td { border-top: 0; }

.dl-table tbody tr:hover { background: rgba(255, 255, 255, 0.02); }

.dl-fmt-name { font-weight: 600; white-space: nowrap; }

.badge {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 0.12rem 0.45rem;
    border-radius: 5px;
    margin-right: 0.4rem;
    vertical-align: 1px;
    letter-spacing: 0.02em;
    line-height: 1.4;
}

.badge.mp4 { background: rgba(37, 99, 235, 0.18); color: #7db4ff; }
.badge.webm { background: rgba(52, 199, 89, 0.16); color: #7fe0a0; }
.badge.m4a { background: rgba(255, 159, 10, 0.16); color: #ffc46b; }
.badge.3gp { background: rgba(255, 255, 255, 0.1); color: var(--text-dim); }
.badge.audio { background: rgba(255, 0, 51, 0.16); color: #ff7a94; }

.dl-fmt-mime { color: var(--text-dim); font-size: 0.8rem; }

.dl-codec { color: var(--text-dim); opacity: 0.7; font-size: 0.74rem; }

.dl-fmt-size { color: var(--text-dim); white-space: nowrap; text-align: right; }

.dl-fmt-action { white-space: nowrap; }

.dl-sig {
    display: inline-block;
    color: var(--text-dim);
    font-size: 0.78rem;
    font-weight: 600;
    border: 1px dashed var(--border);
    border-radius: 999px;
    padding: 0.32rem 0.7rem;
    margin-right: 0.45rem;
}

.dl-link {
    display: inline-block;
    color: var(--accent);
    text-decoration: none;
    font-weight: 700;
    font-size: 0.84rem;
    border: 1px solid var(--accent);
    padding: 0.32rem 0.9rem;
    border-radius: 999px;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}

.dl-link:hover { background: var(--accent); color: #fff; }

.dl-copy {
    display: inline-block;
    border: 1px solid var(--border);
    background: var(--bg-elev);
    color: var(--text);
    font: inherit;
    font-size: 0.78rem;
    font-weight: 700;
    padding: 0.32rem 0.7rem;
    border-radius: 999px;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}

.dl-copy:hover { border-color: var(--accent); color: var(--accent); }
.dl-copy:disabled { opacity: 0.6; cursor: default; }

.dl-thumbs {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.9rem;
}

.dl-thumb {
    display: block;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    text-decoration: none;
    color: var(--text);
    transition: border-color 0.15s, transform 0.15s;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}
.dl-thumb img { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }

.dl-thumb:hover { transform: translateY(-2px); }

.dl-thumb img {
    width: 100%;
    display: block;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    background: #000;
}

.dl-thumb-name {
    display: block;
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    color: var(--text-dim);
    font-weight: 600;
}

.dl-captions {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 0.6rem;
}

.dl-caption {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.7rem 0.9rem;
}

.dl-caption-info { min-width: 0; }

.dl-caption-name { font-weight: 600; font-size: 0.92rem; }

.dl-caption-name .auto {
    font-size: 0.7rem;
    color: var(--text-dim);
    border: 1px solid var(--border);
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    margin-left: 0.45rem;
    font-weight: 600;
}

.dl-caption-code { color: var(--text-dim); font-size: 0.8rem; }

.dl-caption-actions {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex-wrap: wrap;
}

.dl-btn {
    display: inline-block;
    background: none;
    color: var(--accent);
    text-decoration: none;
    font: inherit;
    font-weight: 700;
    font-size: 0.84rem;
    border: 1px solid var(--accent);
    padding: 0.32rem 0.9rem;
    border-radius: 999px;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.dl-btn:hover { background: var(--accent); color: #fff; }
.dl-btn:disabled { opacity: 0.6; cursor: default; }

/* ---- Chế độ tập trung xem phụ đề: ẩn trang, chỉ còn player (slot ngoài output,
        không bị các rule dưới tác động) + đúng track ngôn ngữ đang mở ---- */

body.sub-focus #dl-output > :not(.dl-captions-section):not(.dl-sub-viewer) { display: none !important; }
body.sub-focus .dl-captions-section > :not(.dl-captions):not(.dl-sub-viewer) { display: none !important; }
body.sub-focus .dl-captions-section .dl-captions > li:not(.dl-sub-active) { display: none !important; }

/* ---- Inline video player ---- */

.dl-player-section { margin-bottom: 0.25rem; }

.dl-player {
    position: relative;
    width: 100%;
    height: 0;
    /* 16:9 bằng padding-top — tương thích cả trình duyệt cũ (aspect-ratio bị bỏ qua
       trên Safari/iOS < 15, Chrome < 88 làm box cao 0 → player vô hình). */
    padding-top: 56.25%;
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
}

.dl-player iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}

/* ---- Subtitle viewer ---- */

.dl-sub-viewer {
    position: relative;
    flex-basis: 100%;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin-top: 0.9rem;
    border: 1px solid var(--border);
    background: var(--bg-elev);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
}

.dl-sub-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.55rem;
    margin-bottom: 0.7rem;
    padding-right: 1.7rem;
}

.dl-sub-title {
    font-weight: 700;
    font-size: 0.88rem;
    margin-right: auto;
}

.dl-sub-ts {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--text-dim);
    font-size: 0.82rem;
    cursor: pointer;
}

.dl-sub-ts input { accent-color: var(--accent); }

.dl-sub-toolbar select {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.3rem 0.5rem;
    font: inherit;
    font-size: 0.82rem;
}

.dl-sub-close {
    position: absolute;
    top: 1.18rem;
    right: 0.8rem;
    background: none;
    border: 0;
    color: var(--text-dim);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.15rem 0.4rem;
    border-radius: 6px;
}

.dl-sub-close:hover { color: var(--text); background: var(--card); }

.dl-sub-content {
    max-height: 320px;
    overflow: auto;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.8rem;
    font-size: 0.9rem;
    line-height: 1.55;
}

.srt-line {
    padding: 0.22rem 0;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.05);
    cursor: pointer;
}

.srt-line:hover { background: rgba(255, 255, 255, 0.04); }
.srt-line:hover .srt-time { color: var(--accent); }
.srt-line:hover .srt-text { color: #fff; }

/* Dòng phụ đề đang phát — style giống hover, chữ to hơn nhẹ. */
.srt-line.srt-active { background: rgba(255, 255, 255, 0.04); }
.srt-line.srt-active .srt-time { color: var(--accent); }
.srt-line.srt-active .srt-text { font-size: 1.06em; font-weight: bold; background: #fffcde; color: #574100; }
.srt-line.srt-active[data-start="0"] .srt-text { background: none; color: inherit; }

/* Word-level highlight trong câu đang phát — từ hiện tại nền vàng #ffbc06, đè khớp
   chiều cao khối highlight câu: khối câu (block/flex) trùm cả lead height còn span
   chữ chỉ nội dung glyph → box-shadow mở rộng theo half-leading để hai mép trùng. */
.srt-line.srt-active .srt-text span[data-wi] { color: inherit; }
.srt-line.srt-active .srt-text span[data-wi].word-active {
    background: #ffbc06;
    color: inherit;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
    box-shadow: 0 0.28em 0 0 #ffbc06, 0 -0.28em 0 0 #ffbc06;
}

/* Ô "Search in transcript..." — cùng kiểu với search box chính. */
.dl-sub-viewer .search-box.sub-search {
    max-width: none;
    margin-top: 0.55rem;
    padding: 0.25rem 0.35rem 0.25rem 0.9rem;
}

.dl-sub-viewer .search-box.sub-search .search-icon { width: 15px; height: 15px; }

#dl-sub-search {
    flex: 1;
    min-width: 0;
    background: none;
    border: 0;
    outline: 0;
    color: var(--text);
    font-size: 0.88rem;
    padding: 0.45rem 0;
}

#dl-sub-search::placeholder { color: var(--text-dim); }
#dl-sub-search::-webkit-search-cancel-button { display: none; }

.dl-sub-viewer .search-box.sub-search .clear-btn {
    width: 28px;
    height: 28px;
    font-size: 0.7rem;
}

.sub-search-count {
    flex: none;
    font-size: 0.7rem;
    color: var(--text-dim);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.srt-line.srt-hidden { display: none !important; }

.dl-sub-content mark {
    background: var(--accent);
    color: #fff;
    border-radius: 3px;
    padding: 0 2px;
}


.srt-line:last-child { border-bottom: 0; }

.srt-time {
    color: var(--text-dim);
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    margin-right: 0.5rem;
}

.srt-text { overflow-wrap: anywhere; }

.dl-sub-empty { color: var(--text-dim); margin: 0; padding: 0.4rem 0; }

.dl-sub-error { color: var(--accent); margin: 0; padding: 0.4rem 0; }

.spinner {
    display: inline-block;
    width: 26px;
    height: 26px;
    border-radius: 999px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Sm: Summarizer module ---- */
.sm-output { margin-top: 1rem; }

.sm-summary-card { position: relative; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); }
.sm-output .dl-video + .sm-summary-card { margin-top: 0.9rem; }
.sm-tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); overflow: hidden; border-radius: calc(var(--radius) - 1px) calc(var(--radius) - 1px) 0 0; }
.sm-tab { flex: 1; padding: 0.55rem 1rem; font-size: 0.9rem; font-weight: 600; cursor: pointer; background: transparent; color: var(--text-dim); border: none; border-bottom: 2px solid transparent; transition: color 0.15s, border-color 0.15s; }
.sm-tab:hover { color: var(--text); }
.sm-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.sm-content { padding: 1rem 1.15rem; font-size: 0.92rem; line-height: 1.65; color: var(--text); }
.sm-content h3 { font-size: 1rem; font-weight: 700; margin: 1rem 0 0.4rem; color: var(--text); }
.sm-content h3:first-child { margin-top: 0; }
.sm-content h4 { font-size: 0.92rem; font-weight: 600; margin: 0.8rem 0 0.3rem; color: var(--text); }
.sm-content p { margin: 0 0 0.6rem; }
.sm-content p:last-child { margin-bottom: 0; }
.sm-content ul { margin: 0 0 0.6rem; padding-left: 1.3rem; }
.sm-content li { margin-bottom: 0.25rem; }
.sm-content strong { font-weight: 600; }
.sm-content a { color: var(--accent); text-decoration: underline; }

.sm-actions { display: flex; gap: 0.5rem; padding: 0 1.15rem 0.9rem; }
.sm-copy { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.4rem 0.8rem; font-size: 0.82rem; border-radius: 999px; border: 1px solid var(--border); background: var(--card); color: var(--text-dim); cursor: pointer; transition: background 0.15s, border-color 0.15s; }
.sm-copy:hover { background: var(--bg); border-color: var(--text-dim); }
.sm-copy:disabled { opacity: 0.6; cursor: default; }

.sm-loading { padding: 1.5rem 0; }
.sm-loading-text { display: flex; align-items: center; gap: 0.6rem; justify-content: center; color: var(--text-dim); font-size: 0.9rem; }
.sum-spinner { display: inline-block; width: 22px; height: 22px; border-radius: 999px; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }

/* ---- Sm: Text-to-speech (nút Đọc + chọn giọng) ---- */
.sm-actions { position: relative; }

/* Mobile: khối nút chức năng bám đáy khi cuộn. position:sticky (bottom:0) thuần CSS —
   dính xuống đáy khung nhìn tới khi khối trở lại vị trí tự nhiên. Lưu ý: sticky không
   hoạt động nếu tổ tiên có overflow:hidden → thẻ .sm-summary-card bỏ overflow, chuyển
   phần cắt góc tab sang .sm-tabs. margin âm để bar tràn đúng 2 mép + đáy thẻ: PHAI khớp
   padding mobile của .page (1rem) — dùng -1.15rem (padding nội dung thẻ) làm bar rộng
   hơn viewport ~2.4px mỗi bên → tràn ngang xộc xệch trong khung PWA; downloader đã dùng
   -1rem đúng quy ước. Padding nội dung bar giữ 1.15rem để cột nút thẳng hàng chữ thẻ. */
 @media (max-width: 720px) {
     .sm-actions {
         position: sticky;
         bottom: 0;
         background: var(--card);
         border-top: 1px solid var(--border);
         box-shadow: 0 -4px 14px rgba(0, 0, 0, 0.14);
         margin: 0 -1rem -0.9rem;
         padding: 0.55rem 1.15rem 0.9rem;
         z-index: 60;
     }
    /* Mobile: nút Đọc chỉ hiện biểu tượng Speaker (bỏ chữ "Đọc") — nút Tạm dừng/Tiếp tục
       vẫn giữ text. */
    .sm-actions #sm-read-btn span { display: none; }
    .sm-actions #sm-read-btn { padding: 0.4rem 0.55rem; }
}

/* Câu đang đọc: nền #fffcde (vàng kem nhạt), chữ tối để đọc rõ */
.sm-content [data-seg] { cursor: pointer; }
.sm-content span[data-seg] {
    border-radius: 5px;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
    transition: background 0.2s ease, color 0.2s ease, font-size 0.15s ease;
}
/* Hover câu: chỉ sáng lên — KHÔNG áp cho câu đang đọc (trắng trên vàng ko đọc được) */
.sm-content span[data-seg]:hover:not(.sm-speaking) {
    color: #fff;
}
.sm-speaking {
    background: #fffcde;
    color: #574100;
    font-weight: bold;
}
.sm-speaking span[data-wi] { color: inherit; }
.sm-speaking span[data-wi].word-active {
    background: #ffbc06;
    color: inherit;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
    box-shadow: 0 0.32em 0 0 #ffbc06, 0 -0.32em 0 0 #ffbc06;
}

/* Dòng tóm tắt vừa click (chỉ 1 dòng; click ngoài khối tóm tắt sẽ bỏ) */
.sm-clicked {
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* Slider tốc độ đọc trong picker giọng (downloader) — hàng cuối, full width */
.dl-read-speed {
    flex-basis: 100%;
    min-width: 0;
    margin-top: 0.6rem;
    padding-top: 0.55rem;
    border-top: 1px solid var(--border);
}
.dl-speed-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-dim);
    margin-bottom: 6px;
    white-space: nowrap;
}
.dl-speed-val { color: var(--accent); font-variant-numeric: tabular-nums; }
/* Slider dùng style native của trình duyệt, chỉ tô màu accent (thanh đỏ) */
.dl-read-speed input[type="range"] { width: 100%; margin: 0; accent-color: var(--accent); }

/* Cụm Pause+Đọc luôn ghim bên phải nhờ spacer (pause ẩn vẫn giữ vị trí Đọc) */
.sm-flex-spacer { flex: 1 1 0; min-width: 0; }
.sm-read {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.8rem;
    font-size: 0.82rem;
    font-weight: 600;
    font-family: inherit;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text-dim);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.sm-read:hover { background: var(--bg); border-color: var(--accent); color: var(--accent); }
.sm-read.loading { opacity: 0.65; cursor: wait; }
.sm-read[hidden] { display: none; }

/* Nút Tạm dừng đứng ngay trước nút Đọc trong cụm bên phải */
.sm-pause.paused { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Nút Loop — sáng accent khi bật (tự đọc lại từ đầu khi hết phụ đề) */
.dl-tts-loop.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Nút Dừng — hiển thị khi đang đọc */
.sm-stop-btn { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Picker neo vào .sm-actions (position:relative), layout flex thuần + margin —
   không grid/gap/min() để không vỡ trên trình duyệt cũ. */
.sm-read-picker {
    position: absolute;
    right: 0;
    bottom: calc(100% + 6px);
    z-index: 30;
    display: flex;
    padding: 0.7rem;
    width: 280px;
    max-width: calc(100vw - 2rem);
    box-sizing: border-box;
    background: var(--card);
    border: 0.1px solid var(--text-dim);
    border-radius: var(--radius);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
.sm-read-picker[hidden] { display: none; }
/* Cho phép hàng phụ (slider tốc độ) wrap xuống dòng riêng — 2 nhóm giọng vẫn ngang nhau */
.sm-read-picker { flex-wrap: wrap; }

.sm-read-group {
    flex: 1 1 0;
    min-width: 0;
    display: block;
}
.sm-read-group + .sm-read-group { margin-left: 0.7rem; }
.sm-read-group-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--accent);
    margin-bottom: 4px;
    white-space: nowrap;
}
.sm-read-group-label svg { flex: none; }
.sm-read-opt {
    display: block;
    width: 100%;
    box-sizing: border-box;
    padding: 0.32rem 0.55rem;
    margin-top: 3px;
    font-size: 0.82rem;
    font-family: inherit;
    text-align: left;
    border-radius: 8px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.12s, border-color 0.12s;
}
.sm-read-opt:hover { background: var(--bg-elev); border-color: var(--border); color: var(--accent); }
.sm-read-opt.current { color: var(--accent); border-color: var(--accent); }
.sm-read-opt[disabled] { opacity: 0.55; cursor: wait; }

@media (max-width: 720px) {
    .sm-read-picker {
        position: fixed;
        left: 50%;
        right: auto;
        bottom: auto;
        top: 40%;
        transform: translate(-50%, -50%);
        -webkit-transform: translate(-50%, -50%);
        width: 300px;
    }
}

@media (max-width: 720px) {
    .dl-caption { flex-direction: column; align-items: flex-start; }
    .dl-fmt-action { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
    .dl-sig { margin-right: 0; }

    .dl-sub-viewer { padding: 0.7rem 0.75rem; flex-basis: auto; }
    .dl-sub-close { top: 0.7rem; right: 0.75rem; }
    .dl-sub-toolbar { gap: 0.5rem; }
    .dl-sub-title { flex-basis: 100%; margin-right: 0; }
    .dl-sub-toolbar select {
        flex: 1 1 100%;
        min-width: 0;
        text-overflow: ellipsis;
    }
    .dl-sub-content { font-size: 0.85rem; padding: 0.6rem; }
    .srt-line { display: flex; flex-direction: column; gap: 0.1rem; }
    .srt-time { margin-right: 0; }

    .sm-content { padding: 0.8rem; }
}

/* Hàng công cụ phụ đề: ô tìm kiếm + cụm Đọc (Loop/speaker/Pause/Stop). Mặc định cùng
   hàng, cụm Đọc ghim cạnh phải; trên màn hẹp cho phép XUỐNG DÒNG để tránh nút Pause/
   Stop (xuất hiện khi đang đọc) làm bung rộng khối phụ đề. Chỉ thêm class mới. */
.dl-sub-toolsrow { display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem; margin-top: 0.55rem; }
.dl-sub-toolsrow .search-box.sub-search { flex: 1 1 auto; min-width: 0; margin-top: 0; }
.dl-tts-cluster { position: relative; flex: none; margin-left: auto; display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }

@media (max-width: 720px) {
    /* Mobile: hàng công cụ phụ đề (ô tìm + cụm Đọc) dính đáy khung nhìn khi cuộn —
       giống .sm-actions của summarizer. margin âm để bar tràn đúng 2 mép + đáy thẻ
       (.dl-sub-viewer padding 1rem/0.85rem). */
    .dl-sub-toolsrow {
        position: sticky;
        bottom: 0;
        background: var(--bg-elev);
        border-top: 1px solid var(--border);
        box-shadow: 0 -4px 14px rgba(0, 0, 0, 0.14);
        margin: 0 -1rem -0.85rem;
        padding: 0.55rem 1rem 0.85rem;
        z-index: 60;
    }
    /* Thu các nút Stop/Loop/Đọc về chỉ biểu tượng — nhưng NÚT TẠM DỪNG/TIẾP TỤC giữ
       text trên mobile (như yêu cầu; nhãn đổi nhờ syncTtsPauseBtn). */
    .dl-tts-cluster .sm-read:not(#dl-tts-pause) span { display: none; }
    .dl-tts-cluster .sm-read { padding: 0.4rem 0.55rem; }
    .dl-tts-cluster #dl-tts-pause { padding: 0.4rem 0.8rem; }
}

/* ===========================================================================
   Module SEO (SSR landing page video) — chèn vào #dl-output / #sm-output.
   Chỉ phục vụ crawler/SEO; JS xoá/replace nội dung này ngay khi fetch xong.
   =========================================================================== */
.seo-video,
.seo-summary {
    max-width: 720px;
    margin: 0 auto 1.4rem;
    padding: 1rem 1.1rem;
    background: var(--card, #1a1e26);
    border: 1px solid var(--border, #2a2f3a);
    border-radius: var(--radius, 14px);
}
.seo-video .dl-title,
.seo-summary .dl-title {
    margin: 0 0 0.5rem;
    font-size: clamp(1.15rem, 2.8vw, 1.5rem);
    font-weight: 800;
    line-height: 1.3;
    color: var(--text);
}
.seo-author { margin: 0 0 0.7rem; color: var(--text-dim); font-size: 0.92rem; }
.seo-video img.dl-thumb {
    display: block;
    max-width: 100%;
    width: 480px;
    height: auto;
    border-radius: 10px;
    border: 1px solid var(--border);
    margin: 0 0 0.7rem;
}
.seo-video .seo-links a.dl-srclink,
.seo-summary .seo-links a.dl-srclink {
    color: var(--text-dim) !important;
    font-weight: 600 !important;
    text-decoration: none !important;
    background-color: var(--card) !important;
}
.seo-links a.dl-srclink:hover { text-decoration: underline; }
.seo-note { color: var(--text-dim); font-size: 0.9rem; margin: 0.5rem 0 0; }
.seo-summary .seo-summary-body {
    color: var(--text);
    font-size: 0.95rem;
    line-height: 1.6;
    white-space: normal;
}
.seo-summary .seo-summary-body p { margin: 0 0 0.7rem; }

/* ---- Anonymous Playlist / Favorites (★) ---- */
.ft-star {
    position: absolute;
    right: 10px;
    bottom: 10px;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.62);
    color: #fff;
    cursor: pointer;
    z-index: 3;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    transition: transform 0.15s, color 0.15s, background 0.15s;
}
.ft-star svg {
    width: 17px;
    height: 17px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linejoin: round;
    pointer-events: none;
}
.ft-star:hover { transform: scale(1.12); background: rgba(0, 0, 0, 0.8); }
.ft-star.on { color: #ffbc06; }
.ft-star.on svg { fill: #ffbc06; stroke: #ffbc06; }

/* Nút ★ trong header trang đơn (download/summarize) — tách khỏi chữ tiêu đề */
.ft-star--top {
    top: 1rem;
    right: 1rem;
    bottom: auto;
}
.card .card-meta { padding-right: 2.4rem; }

/* Nút nav Playlist + badge đếm */
.ft-nav { position: relative; }
.ft-nav .ft-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.35em;
    height: 1.35em;
    padding: 0 0.3em;
    margin-left: 0.35rem;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
}

.ft-panel {
    position: fixed;
    z-index: 1200;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    will-change: transform;
    width: min(430px, calc(100vw - 2rem));
    max-height: min(78vh, 560px);
    display: flex;
    flex-direction: column;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}
.ft-panel[hidden], .ft-backdrop[hidden] { display: none; }
/* Khoá trang khi Playlist mở: body không cuộn + overscroll containment — chống
   scroll-chain từ .ft-panel-body tràn ra trang / khối nội dung (phụ đề) bên dưới trên
   MỌI trình duyệt (iOS cũ bỏ qua overscroll-behavior → overflow:hidden là hàng rào
   cuối). Backdrop + panel phủ toàn màn (z-index 1150+) nên mọi phần tử bên dưới không
   thể nhận gesture nữa. */
body.ft-panel-open {
    overflow: hidden;
    overscroll-behavior: contain;
}
/* iOS cuộn documentElement chứ KHÔNG cuộn <body> — body overflow:hidden là chưa đủ,
   trang phía sau vẫn giãn/rubber-band được và "nuốt" gesture khi chạm panel (playlist
   đơ tới khi vuốt ra ngoài ép scroll → repaint). Phải khoá luôn html. */
html.ft-panel-open {
    overflow: hidden;
    overscroll-behavior: contain;
}
.ft-backdrop {
    position: fixed;
    z-index: 1150;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
}
.ft-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.95rem 1.1rem;
    border-bottom: 1px solid var(--border);
}
.ft-panel-head h2 { margin: 0; font-size: 1.05rem; font-weight: 800; }
.ft-panel-head h2 svg { width: 16px; height: 16px; fill: #ffbc06; stroke: #ffbc06; vertical-align: -2px; }
.ft-panel-close {
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 1rem;
    cursor: pointer;
    padding: 0.4rem;
    line-height: 1;
}
.ft-panel-close:hover { color: var(--text); }
/* Nút đảo ngược thứ tự — đứng NGAY TRƯỚC nút x; margin-left:auto đẩy nó + nút x
   về sát mép phải (trang player: .pv-pl-modes đã giữ auto, bị đè margin-left:0
   trong player.css để cả cụm dồn phải liên tục). */
.ft-panel-rev {
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    padding: 0;
    line-height: 0;
    margin-left: auto;
    transition: color .12s, border-color .12s;
    -webkit-tap-highlight-color: transparent;
}
.ft-panel-rev svg { width: 15px; height: 15px; fill: currentColor; flex: none; }
.ft-panel-rev:hover { color: var(--accent); border-color: var(--accent); }
.ft-panel-body { overflow-y: auto; padding: 0.75rem 1rem; overscroll-behavior: contain; }
.ft-empty {
    color: var(--text-dim);
    text-align: center;
    font-size: 0.92rem;
    line-height: 1.6;
    padding: 1.5rem 0.5rem;
    margin: 0;
}
.ft-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.55rem 0;
    border-bottom: 1px solid var(--border);
    transition: opacity 0.12s ease;
}
.ft-item:last-child { border-bottom: none; }
.ft-item-main {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    flex: 1;
    min-width: 0;
    color: inherit;
    text-decoration: none;
}
.ft-item-thumb {
    width: 96px;
    height: 54px;
    border-radius: 8px;
    object-fit: cover;
    background: var(--bg-elev);
    flex-shrink: 0;
}
.ft-item-thumb-ph { background: var(--bg-elev); }
.ft-item-info { display: flex; flex-direction: column; min-width: 0; touch-action: none; }
.ft-item-title {
    font-size: 0.86rem;
    font-weight: 600;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.ft-item-author { color: var(--text-dim); font-size: 0.76rem; margin-top: 0.2rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ft-item-actions { display: flex; align-items: center; gap: 0.35rem; flex-shrink: 0; }
.ft-item-act {
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    text-decoration: none;
}
.ft-item-act svg { width: 15px; height: 15px; fill: none; }
.ft-item-act:hover { color: var(--text); background: var(--bg-elev); }
.ft-item-del:hover { color: var(--accent); }

.ft-grip {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 30px;
    color: var(--text-dim);
    cursor: grab;
    touch-action: none; /* cho phép Pointer Events kéo liên tục trên mobile */
    -webkit-touch-callout: none;
    user-select: none;
}
.ft-grip:active { cursor: grabbing; }
.ft-grip svg { width: 16px; height: 16px; display: block; }
.ft-item[draggable="true"] { cursor: grab; }
.ft-item.ft-dragging {
    /* Item đang được nhấc ra khỏi list: làm MỜ (vẫn giữ chỗ, vẫn thấy vị trí gốc). */
    opacity: 0.4;
    filter: grayscale(0.3);
}
/* Chặn select/highlight text TOÀN KHỐI .ft-panel (kể cả link/button con, mọi tầng).
   iOS đặc biệt cần -webkit-user-select; đặt trên cả cha lẫn hậu duệ để link con không
   thắng được. */.ft-panel,
.ft-panel * {
    -webkit-touch-callout: none;
    -webkit-user-select: none !important;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Bản clone nổi theo con trỏ lúc kéo: GIỮ NGUYÊN cả khối .ft-item (grip + thumb + actions). */
.ft-drag-clone {
    position: fixed;
    left: 0;
    top: 0;
    margin: 0;
    pointer-events: none;
    z-index: 1200;
    background: var(--card);
    border: none;
    border-radius: 10px;
    box-shadow: none;
    opacity: 0.92;
    transform: scale(1.03);
    cursor: grabbing;
    -webkit-user-drag: none;
    user-select: none;
    transition: none;
}
.ft-drag-clone img { pointer-events: none; }

.ft-panel-foot {
    flex: none;
    margin: 0;
    padding: 0.6rem 1rem 0.7rem;
    border-top: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 0.74rem;
    text-align: center;
}