/* ================================================================
   UI LAYER — giao diện mới (nạp sau style.css, ghi đè có chủ đích)

   Định hướng: nền mực tối ấm, một màu nhấn tím oải hương duy nhất,
   không viền màu khi hover/click/focus. Ưu tiên mobile: lưới 2 cột,
   vùng chạm ≥ 44px, ít blur, hiệu ứng hover chỉ trên thiết bị có chuột.
   ================================================================ */

:root {
    --ink: #0d0e11;
    --surface: #16181d;
    --raised: #20232a;
    --line: rgba(255, 255, 255, 0.07);
    --text: #f3f0ea;
    --muted: #9b9ea6;
    --accent: #b8acff;
    --accent-ink: #17142b;
    --heart: #ff7a93;
    --r-card: 14px;
    --r-pill: 999px;
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
    --font: "Be Vietnam Pro", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ---------- Nền tảng ---------- */
html body,
html body button,
html body input,
html body select,
html body textarea {
    font-family: var(--font);
}

html body {
    background: var(--ink);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
}

* {
    -webkit-tap-highlight-color: transparent;
}

a,
button,
[role="button"],
.grid-video-item,
.nav-item,
.tab-btn {
    touch-action: manipulation;
}

/* Không viền/ánh khi click, chuột hay chạm. Bàn phím vẫn thấy vòng trung tính. */
html body a:focus,
html body button:focus,
html body .grid-video-item:focus,
html body .video-player:focus,
html body input:focus,
html body select:focus,
html body textarea:focus {
    outline: none;
}

html body a:focus-visible,
html body button:focus-visible,
html body .seek-bar:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.7);
    outline-offset: 2px;
}

html body .search-input:focus-visible,
html body .report-input:focus-visible {
    outline: none;
}

html body .app-container {
    height: 100vh;
    height: 100dvh;
}

/* ---------- Trang chủ / lưới ---------- */
html body .home-grid-container {
    height: 100vh;
    height: 100dvh;
    background: var(--ink) !important;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}

html body .home-header {
    background: rgba(13, 14, 17, 0.94) !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    border-bottom: 1px solid var(--line) !important;
    box-shadow: none !important;
}

html body .mobile-home-nav {
    background: var(--ink) !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    border-bottom: 0 !important;
}

html body .mobile-home-nav .home-nav-link,
html body .home-nav-link {
    background: transparent !important;
    border: 0 !important;
    color: var(--muted) !important;
    font-weight: 600 !important;
    letter-spacing: 0 !important;
    min-height: 40px;
    transition: color 0.2s ease, background-color 0.2s ease;
}

html body .home-nav-link:active {
    color: var(--text) !important;
    background: var(--raised) !important;
}

/* Tab: nút nền sáng khi đang chọn — tách bạch, không dùng màu đỏ */
html body .tab-navigation {
    background: var(--surface) !important;
    border: 0 !important;
    border-radius: var(--r-pill) !important;
}

html body .tab-btn {
    color: var(--muted) !important;
    min-height: 40px;
    font-size: 13.5px !important;
    font-weight: 600 !important;
    letter-spacing: 0 !important;
}

html body .tab-btn i {
    opacity: 0.85 !important;
}

html body .tab-btn.active {
    background: var(--text) !important;
    color: var(--ink) !important;
    box-shadow: none !important;
}

html body .tab-btn.active i {
    color: var(--ink) !important;
}

html body .tab-btn:hover:not(.active) {
    background: var(--raised) !important;
    color: var(--text) !important;
}

/* Tìm kiếm */
html body .search-input {
    background: var(--surface) !important;
    border: 1px solid transparent !important;
    border-radius: var(--r-pill) !important;
    box-shadow: none !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    color: var(--text) !important;
    font-size: 16px !important; /* ≥16px để iOS không tự phóng to khi focus */
    font-weight: 500 !important;
    height: 46px !important;
    padding: 0 46px !important;
    transition: background-color 0.2s ease !important;
}

html body .search-input:focus {
    background: var(--raised) !important;
    border-color: transparent !important;
    box-shadow: none !important;
}

html body .search-input::placeholder {
    color: var(--muted) !important;
}

html body .search-icon {
    color: var(--muted) !important;
}

html body .search-clear-btn {
    width: 32px !important;
    height: 32px !important;
    background: var(--raised) !important;
    color: var(--text) !important;
}

html body .clear-search-btn,
html body .search-empty-clear-btn {
    background: var(--text) !important;
    color: var(--ink) !important;
    border: 0 !important;
    box-shadow: none !important;
    font-weight: 600 !important;
}

html body .search-results-info {
    background: var(--surface) !important;
    border-bottom: 1px solid var(--line) !important;
}

/* Lưới video: 2 cột trên điện thoại, nở dần theo màn hình */
html body .videos-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
    padding: 12px 10px calc(96px + env(safe-area-inset-bottom, 0px)) !important;
    max-width: 1280px !important;
}

@media (min-width: 560px) {
    html body .videos-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        gap: 10px !important;
    }
}

@media (min-width: 860px) {
    html body .videos-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
        gap: 12px !important;
        padding-left: 16px !important;
        padding-right: 16px !important;
    }
}

@media (min-width: 1180px) {
    html body .videos-grid {
        grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
    }
}

html body .grid-video-item {
    border: 0 !important;
    border-radius: var(--r-card) !important;
    background: var(--surface) !important;
    box-shadow: none !important;
    transition: transform 0.18s var(--ease) !important;
    /* Chỉ vẽ thẻ khi gần vào khung nhìn: cuộn mượt hơn trên máy yếu */
    content-visibility: auto;
    contain-intrinsic-size: auto 280px;
    transform: translateZ(0);
}

html body .grid-video-item:hover {
    border: 0 !important;
}

html body .grid-video-item:active {
    transform: scale(0.97) !important;
}

html body .grid-video-link {
    display: block;
    width: 100%;
    height: 100%;
    color: inherit;
    text-decoration: none;
}

html body .grid-video-thumbnail {
    transition: opacity 0.3s ease !important;
}

html body .grid-video-item:hover .grid-video-thumbnail {
    transform: none !important;
}

html body .grid-video-overlay {
    background: linear-gradient(180deg, transparent 52%, rgba(0, 0, 0, 0.72) 100%) !important;
}

html body .grid-play-icon {
    display: none !important;
}

@media (hover: hover) and (pointer: fine) {
    /* Thẻ đang trỏ vào: phóng nhẹ + nổi lên bằng bóng, các thẻ khác mờ đi */
    html body .grid-video-item {
        transition: transform 0.22s var(--ease), box-shadow 0.22s ease, opacity 0.22s ease !important;
    }

    html body .grid-video-item:hover {
        transform: scale(1.05) !important;
        box-shadow: 0 14px 32px rgba(0, 0, 0, 0.6) !important;
        z-index: 5;
    }

    html body .videos-grid:hover .grid-video-item:not(:hover) {
        opacity: 0.62;
    }

    html body .grid-play-icon {
        display: flex !important;
        width: 48px !important;
        height: 48px !important;
        background: var(--text) !important;
        color: var(--ink) !important;
        box-shadow: none !important;
    }
}

html body .grid-video-info {
    padding: 28px 10px 10px !important;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.78), transparent) !important;
}

html body .grid-video-title {
    font-size: 12.5px !important;
    font-weight: 600 !important;
    line-height: 1.38 !important;
    letter-spacing: 0 !important;
    text-shadow: none !important;
}

html body .grid-video-stats {
    margin-top: 5px !important;
}

html body .grid-video-stat {
    padding: 0 !important;
    background: transparent !important;
    border: 0 !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    font-size: 11px !important;
    font-weight: 600 !important;
    color: rgba(255, 255, 255, 0.85) !important;
}

html body .grid-video-stat--likes i {
    color: var(--heart) !important;
    font-size: 10px !important;
}

html body .grid-video-duration-badge {
    background: rgba(0, 0, 0, 0.66) !important;
    border: 0 !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    border-radius: 6px !important;
}

html body .grid-video-placeholder {
    background: var(--surface) !important;
}

/* Trending */
html body .trending-container {
    padding-left: 10px !important;
    padding-right: 10px !important;
}

html body .trending-header-info h2 {
    color: var(--text) !important;
    letter-spacing: 0 !important;
    text-shadow: none !important;
}

html body .trending-header-info p {
    color: var(--muted) !important;
}

html body .trending-list-item {
    background: var(--surface) !important;
    border: 0 !important;
    box-shadow: none !important;
    border-radius: var(--r-card) !important;
}

html body .trending-list-item:hover {
    background: var(--raised) !important;
    transform: none !important;
    box-shadow: none !important;
}

html body .trending-list-item:active {
    background: var(--raised) !important;
}

html body .trending-rank,
html body .trending-rank.rank-1,
html body .trending-rank.rank-2,
html body .trending-rank.rank-3,
html body .trending-rank:not(.rank-1):not(.rank-2):not(.rank-3) {
    background: var(--raised) !important;
    border: 0 !important;
    box-shadow: none !important;
    color: var(--muted) !important;
}

html body .trending-rank.rank-1,
html body .trending-rank.rank-2,
html body .trending-rank.rank-3 {
    background: var(--accent) !important;
    color: var(--accent-ink) !important;
}

html body .trending-likes {
    color: var(--heart) !important;
}

/* ---------- Thanh điều hướng dưới ---------- */
html body .bottom-nav-bar {
    background: rgba(13, 14, 17, 0.96) !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    border-top: 1px solid var(--line) !important;
    padding-left: 12px !important;
    padding-right: 12px !important;
}

html body .nav-items {
    max-width: 420px;
    gap: 4px !important;
}

html body .nav-item {
    flex: 1 1 0;
    min-width: 0 !important;
    min-height: 48px;
    padding: 6px 8px !important;
    border-radius: 12px !important;
    color: var(--muted) !important;
    background: transparent !important;
    transform: none !important;
    animation: none !important;
    transition: color 0.2s ease, background-color 0.2s ease !important;
}

html body .nav-item i {
    transform: none !important;
}

html body .nav-item span {
    font-size: 11px !important;
    font-weight: 600 !important;
}

html body .nav-item:hover,
html body .nav-item.active {
    color: var(--text) !important;
    background: transparent !important;
    transform: none !important;
}

html body .nav-item:active {
    background: var(--surface) !important;
}

html body .nav-item.active i {
    color: var(--accent);
}

/* ---------- Trình phát ---------- */
html body .tiktok-page-container,
html body .tiktok-video-container {
    background: #000;
}

html body .like-controls {
    gap: 14px !important;
}

html body .like-controls .video-control-btn,
html body .like-controls .like-btn,
html body .navigation-controls .nav-btn {
    width: 46px !important;
    height: 46px !important;
    min-width: 46px !important;
    min-height: 46px !important;
    border: 0 !important;
    border-radius: 50% !important;
    background: rgba(0, 0, 0, 0.42) !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    box-shadow: none !important;
    color: #fff !important;
    font-size: 19px !important;
    transition: transform 0.15s var(--ease), background-color 0.2s ease !important;
}

html body .like-controls .video-control-btn:hover,
html body .like-controls .like-btn:hover,
html body .navigation-controls .nav-btn:hover {
    background: rgba(0, 0, 0, 0.42) !important;
    transform: none !important;
}

html body .like-controls .video-control-btn:active,
html body .like-controls .like-btn:active,
html body .navigation-controls .nav-btn:active {
    transform: scale(0.9) !important;
}

html body .like-controls .like-btn.liked,
html body .like-controls .like-btn.liked:hover {
    background: rgba(0, 0, 0, 0.42) !important;
    border: 0 !important;
    box-shadow: none !important;
    color: var(--heart) !important;
    transform: none;
}

html body .like-controls .report-btn i,
html body .report-btn i {
    color: #fff !important;
}

html body .like-action-label,
html body .like-controls .like-count {
    background: transparent !important;
    border: 0 !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    color: #fff !important;
    font-size: 11.5px !important;
    font-weight: 600 !important;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7) !important;
}

/* Vuốt là thao tác chính trên cảm ứng: ẩn nút lên/xuống cho gọn */
@media (pointer: coarse) {
    html body .navigation-controls {
        display: none !important;
    }
}

html body .video-title {
    font-weight: 600;
    letter-spacing: 0;
}

html body .video-overlay {
    background: linear-gradient(transparent 55%, rgba(0, 0, 0, 0.62) 100%);
}

/* Thanh tiến trình & tua */
html body #progress-bar,
html body .video-seek .seek-progress {
    background: var(--accent) !important;
    box-shadow: none !important;
}

html body #progress-bar::after {
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.5) !important;
}

html body .video-seek .seek-btn,
html body .video-seek .seek-center-play {
    border: 0 !important;
    box-shadow: none !important;
}

html body .swipe-hint {
    background: rgba(0, 0, 0, 0.6) !important;
    border: 0 !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
}

html body .toast {
    background: var(--raised);
    border: 0;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    font-size: 14px;
    padding: 12px 20px;
}

html body .video-close-btn,
html body .close-video-btn,
html body .video-header .video-control-btn {
    border: 0 !important;
    box-shadow: none !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    background: rgba(0, 0, 0, 0.42) !important;
}

html body .video-error {
    background: var(--surface);
}

html body .video-load-error .retry-button {
    background: var(--text) !important;
    color: var(--ink) !important;
    border: 0 !important;
    box-shadow: none !important;
}

/* ---------- Lịch sử ---------- */
html body .history-sidebar {
    height: 100vh;
    height: 100dvh;
    background: var(--ink) !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    border-left: 1px solid var(--line) !important;
}

html body .history-header,
html body .history-actions {
    border-color: var(--line) !important;
}

html body .history-item {
    background: var(--surface) !important;
    border: 0 !important;
    border-radius: 12px !important;
}

html body .history-item:hover,
html body .history-item:active {
    background: var(--raised) !important;
}

html body .history-clear {
    color: var(--muted) !important;
    background: transparent !important;
    border: 0 !important;
    min-height: 40px;
}

html body .history-clear:hover,
html body .history-clear:active {
    color: var(--text) !important;
    background: var(--surface) !important;
}

html body .history-close {
    min-width: 44px;
    min-height: 44px;
}

html body .history-overlay.show {
    background: rgba(0, 0, 0, 0.6);
}

/* ---------- Hộp báo cáo ---------- */
html body .report-modal-overlay {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: rgba(0, 0, 0, 0.7);
}

html body .report-modal-card {
    background: var(--surface) !important;
    border: 0 !important;
    border-radius: 20px !important;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5) !important;
    max-height: min(88vh, 640px);
    max-height: min(88dvh, 640px);
}

html body .report-modal-icon {
    background: var(--raised) !important;
    border: 0 !important;
    color: var(--text) !important;
}

html body .report-input {
    background: var(--raised) !important;
    border: 1px solid transparent !important;
    border-radius: 12px !important;
    box-shadow: none !important;
    color: var(--text) !important;
    font-size: 16px !important;
}

html body .report-input:focus {
    background: var(--raised) !important;
    border-color: rgba(255, 255, 255, 0.28) !important;
    box-shadow: none !important;
}

html body .report-required {
    color: var(--muted) !important;
}

html body .report-close-btn,
html body .report-cancel-btn {
    border: 0 !important;
    background: var(--raised) !important;
    color: var(--text) !important;
    box-shadow: none !important;
    min-height: 44px;
}

html body .report-submit-btn {
    background: var(--accent) !important;
    color: var(--accent-ink) !important;
    border: 0 !important;
    box-shadow: none !important;
    min-height: 44px;
    font-weight: 700 !important;
}

html body .report-submit-btn:hover:not(:disabled) {
    background: var(--accent) !important;
    box-shadow: none !important;
    transform: none !important;
    filter: brightness(1.05);
}

html body .report-submit-btn:active:not(:disabled) {
    transform: scale(0.98) !important;
}

/* ---------- Thiết bị cảm ứng: bỏ mọi hiệu ứng hover dính ---------- */
@media (hover: none) {
    html body .nav-item:hover,
    html body .tab-btn:hover:not(.active),
    html body .trending-list-item:hover {
        background: transparent !important;
    }

    html body .trending-list-item:hover {
        background: var(--surface) !important;
    }
}

/* ---------- Giảm chuyển động ---------- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ---------- Ô tìm kiếm: tuyệt đối không viền/glow màu ---------- */
html body input.search-input,
html body input.search-input:hover,
html body input.search-input:focus,
html body input.search-input:active,
html body input.search-input:invalid,
html body input.search-input:focus-visible {
    -webkit-appearance: none;
    appearance: none;
    outline: 0 !important;
    border: 1px solid transparent !important;
    box-shadow: none !important;
    caret-color: var(--accent);
}

html body input.search-input:focus {
    background: var(--raised) !important;
}

html body input.search-input:-webkit-autofill {
    -webkit-text-fill-color: var(--text);
    -webkit-box-shadow: 0 0 0 100px var(--surface) inset !important;
}

html body .search-input-wrapper,
html body .search-input-wrapper:focus-within,
html body .search-container {
    outline: 0 !important;
    box-shadow: none !important;
    border: 0 !important;
}

html body input.search-input::-webkit-search-cancel-button,
html body input.search-input::-webkit-search-decoration {
    -webkit-appearance: none;
}

html body input::selection,
html body ::selection {
    background: rgba(184, 172, 255, 0.35);
}

/* ---------- Số tim: chip ở góc trên trái (cân với nhãn thời lượng bên phải) ---------- */
html body .grid-video-info {
    inset: 0 !important;
    top: 0 !important;
    display: flex !important;
    align-items: flex-end !important;
    padding: 10px !important;
    background: none !important;   /* nền tối phía dưới đã do .grid-video-overlay đảm nhiệm */
    pointer-events: none;
}

html body .grid-video-info .grid-video-title {
    width: 100%;
}

html body .grid-video-info .grid-video-stats {
    position: absolute !important;
    top: 8px !important;
    left: 8px !important;
    margin: 0 !important;
}

html body .grid-video-info .grid-video-stat {
    padding: 3px 8px !important;
    border-radius: 8px !important;
    background: rgba(0, 0, 0, 0.55) !important;
    font-size: 11px !important;
    line-height: 1.2 !important;
}

/* ================================================================
   MÁY YẾU: tắt hoàn toàn làm mờ nền (backdrop-filter) trên mọi phần tử.
   Làm mờ đè lên video đang phát là thao tác nặng nhất với GPU yếu.
   `:not(#_)` nâng độ ưu tiên để thắng mọi quy tắc cũ trong style.css.
   Các lớp nền vốn trông cậy vào độ mờ được tô đậm hơn để vẫn đọc được.
   ================================================================ */
html body *:not(#_),
html body *:not(#_)::before,
html body *:not(#_)::after {
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
}

html body .control-btn:not(#_),
html body .video-counter:not(#_),
html body .trending-stats .like-count:not(#_) {
    background: rgba(0, 0, 0, 0.5) !important;
}

html body .video-seek .seek-center-play:not(#_) {
    background: rgba(0, 0, 0, 0.38) !important;
}

html body .video-seek .seek-btn:not(#_),
html body .play-icon-overlay:not(#_) {
    background: rgba(0, 0, 0, 0.55) !important;
}

html body .video-player-header:not(#_) {
    background: rgba(0, 0, 0, 0.72) !important;
}

html body .toast:not(#_),
html body .video-load-error:not(#_) {
    background: rgba(18, 18, 20, 0.96) !important;
}

/* ---------- Trình phát: thanh dưới + thanh thời gian tự ẩn khi đang xem ---------- */
html body.video-mode .bottom-nav-bar,
html body.video-mode #progress-wrap {
    transition: transform 0.25s ease, opacity 0.25s ease;
}

html body.video-mode.ui-idle .bottom-nav-bar {
    transform: translateY(100%);
    opacity: 0;
    pointer-events: none;
}

html body.video-mode.ui-idle #progress-wrap {
    opacity: 0;
    pointer-events: none;
}
