
:root {
    color-scheme: dark;

    /* Nền & bề mặt (từ tối → sáng) */
    --bg:        #0e1014;
    --bg2:       #15181f;
    --bg3:       #1c2029;
    --bg4:       #252a35;
    --bg5:       #2f3542;

    /* Viền */
    --border:    #232833;
    --border2:   #303644;

    /* Màu nhấn */
    --accent:        #ff4d7d;   /* hồng sakura — nút chính, active */
    --accent-hover:  #ff6b93;
    --accent-soft:   rgba(255, 77, 125, .14);
    --accent2:       #3ec7f0;   /* xanh cyan — link, thông tin phụ */
    --accent2-soft:  rgba(62, 199, 240, .14);
    --accent3:       #ff6b9d;   /* yêu thích */
    --on-accent:     #ffffff;

    /* Chữ */
    --text1:     #eef0f6;
    --text2:     #a4aabc;
    --text3:     #6c7387;

    /* Trạng thái */
    --green:     #34d399;
    --red:       #f8576b;
    --yellow:    #fbbf24;
    --blue:      #4ea8ff;

    /* Hình khối */
    --r-sm:      6px;
    --radius:    10px;
    --radius-lg: 14px;
    --r-pill:    999px;

    /* Bố cục */
    --container: 1280px;
    --gutter:    12px;
    --header-h:  60px;
    --mnav-h:    56px;

    /* Tỉ lệ ảnh thumbnail của card.
       2 / 3 = poster dọc (mặc định) · 16 / 9 = ảnh ngang */
    --thumb-ratio: 2 / 3;

    /* Typography */
    --font: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans JP", "Hiragino Sans", sans-serif;
    --fs-xs: 11px;
    --fs-sm: 12px;
    --fs:    14px;
    --fs-md: 15px;
    --fs-lg: 18px;
    --fs-xl: 22px;

    --tr: .18s cubic-bezier(.4, 0, .2, 1);
}

@media (min-width: 768px) {
    :root { --gutter: 20px; }
}

/* =====================================================================
   2. RESET & BASE
   ===================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
    background: var(--bg);
}

body {
    min-width: 280px;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text1);
    font-family: var(--font);
    font-size: var(--fs);
    line-height: 1.5;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--text1);
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: -.01em;
}
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); }
h4, h5, h6 { font-size: var(--fs); }

a {
    color: var(--accent2);
    text-decoration: none;
    transition: color var(--tr), background-color var(--tr), border-color var(--tr);
}
a:hover { color: var(--text1); }

img, svg, video, iframe { max-width: 100%; }
img { object-fit: cover; border: 0; }

ul, ol { list-style: none; }

input, select, textarea, button {
    font: inherit;
    color: inherit;
    outline: none;
}

button {
    background: none;
    border: 0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
button:disabled { cursor: not-allowed; }

input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="search"]::-webkit-search-cancel-button { filter: invert(.6); }

::placeholder { color: var(--text3); opacity: 1; }
::selection { background: var(--accent); color: #fff; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Scrollbar */
* { scrollbar-width: thin; scrollbar-color: var(--bg5) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg5); border-radius: var(--r-pill); }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* Bài viết / khối nội dung — trung tính (theme cũ có nền trắng) */
article {
    position: relative;
    background: transparent;
    border: 0;
    padding: 0;
}

.clearfix { clear: both; }
.left  { float: left; }
.right { float: right; }

/* =====================================================================
   3. LAYOUT
   ===================================================================== */
#body {
    width: 100%;
    max-width: var(--container);
    margin: 0 auto;
    padding: 16px var(--gutter) 24px;
}

/* =====================================================================
   4. TOP BAR (dòng chữ trên cùng — #sub-nav đầu tiên trong <body>)
   ===================================================================== */
body > #sub-nav:first-child {
    display: block;
    padding: 6px var(--gutter);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    color: var(--text3);
    font-size: var(--fs-sm);
    line-height: 1.4;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
body > #sub-nav:first-child a { color: var(--text2) !important; font-weight: 600; }
body > #sub-nav:first-child a:hover { color: var(--accent) !important; }

/* =====================================================================
   5. HEADER
   ===================================================================== */
#masthead {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    height: var(--header-h);
    padding: 0 max(var(--gutter), calc((100% - var(--container)) / 2 + var(--gutter)));
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    color: var(--text1);
    text-align: left;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    z-index: 2;
}

.logo-text {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text1);
    font-size: 19px;
    font-weight: 800;
    letter-spacing: -.02em;
    white-space: nowrap;
}
.logo-text::before {
    content: "";
    width: 12px;
    height: 12px;
    border-radius: 3px;
    background: var(--accent);
    transform: rotate(45deg);
    flex-shrink: 0;
}
.logo-text:hover { color: var(--accent); }
.logo-text strong { font-weight: inherit; }

.header-left img { display: block; border-radius: 4px; }

.header-center {
    flex: 0 1 620px;
    display: flex;
    justify-content: center;
    margin: 0 12px;
}

.yt-search-form {
    position: relative;
    display: flex;
    width: 100%;
    max-width: 620px;
    margin: 0;
    background: none;
}

.yt-search-input {
    flex: 1;
    width: 100%;
    min-width: 0;
    height: 40px;
    padding: 0 16px;
    background: var(--bg3);
    border: 1px solid var(--border2);
    border-right: 0;
    border-radius: var(--radius) 0 0 var(--radius);
    color: var(--text1);
    font-size: var(--fs);
    transition: border-color var(--tr), background-color var(--tr);
}
.yt-search-input:focus { border-color: var(--accent); background: var(--bg); }

.yt-search-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 40px;
    flex-shrink: 0;
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 0 var(--radius) var(--radius) 0;
    transition: background-color var(--tr);
}
.yt-search-btn:hover { background: var(--accent-hover); }
.yt-search-btn svg { width: 20px; height: 20px; fill: var(--on-accent); }

.mobile-back-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin-right: 6px;
    border-radius: var(--radius);
    flex-shrink: 0;
}
.mobile-back-btn:hover { background: var(--bg4); }
.mobile-back-btn svg { width: 22px; height: 22px; fill: var(--text1); }

.header-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    z-index: 2;
}

.mobile-search-trigger {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    transition: background-color var(--tr);
}
.mobile-search-trigger:hover,
.mobile-search-trigger:active { background: var(--bg4); }
.mobile-search-trigger svg { width: 22px; height: 22px; fill: var(--text1); }

.auth-btn-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 38px;
    padding: 0 14px;
    background: var(--accent-soft);
    border-radius: var(--radius);
    color: var(--accent);
    font-size: var(--fs);
    font-weight: 700;
    white-space: nowrap;
}
.auth-btn-link:hover { background: var(--accent); color: var(--on-accent); }
.auth-btn-link svg { width: 20px; height: 20px; }

.user-avatar-wrap {
    display: block;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--bg4);
    border: 2px solid var(--border2);
    transition: border-color var(--tr);
}
.user-avatar-wrap:hover { border-color: var(--accent); }
.user-avatar-wrap img { display: block; width: 100%; height: 100%; object-fit: cover; }

.header-avatar-letter {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    user-select: none;
}

.btn-logout-mini {
    padding: 6px;
    color: var(--text2);
    font-size: var(--fs-sm);
}

/* =====================================================================
   6. SUB NAV (chip menu dưới header)
   ===================================================================== */
#sub-nav {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 10px var(--gutter);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
}
#sub-nav::-webkit-scrollbar { display: none; }

.nav-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    height: 34px;
    padding: 0 14px;
    background: var(--bg3);
    border-radius: var(--r-pill);
    color: var(--text2);
    font-size: 13px;
    font-weight: 600;
}
.nav-chip:hover { background: var(--bg4); color: var(--text1); }
.nav-chip.active { background: var(--accent); color: var(--on-accent); }
.nav-chip svg { width: 16px; height: 16px; fill: currentColor; }

/* ---- Ô tìm kiếm cuối trang (chỉ hiện trên điện thoại) ---- */
.m-search {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 32px 0 0;
    padding: 14px;
    background: var(--bg2);
    border-radius: var(--radius-lg);
}
.m-search + #sub-nav { margin-top: 16px !important; }
.m-search-icon {
    position: absolute;
    left: 28px;
    width: 18px;
    height: 18px;
    fill: var(--text3);
    pointer-events: none;
}
.m-search-input {
    flex: 1;
    min-width: 0;
    height: 44px;
    padding: 0 12px 0 42px;
    background: var(--bg3);
    border: 1px solid var(--border2);
    border-radius: var(--radius);
    color: var(--text1);
    font-size: 16px; /* 16px để iOS không tự phóng to khi bấm vào */
    -webkit-appearance: none;
    appearance: none;
    transition: border-color var(--tr), background-color var(--tr);
}
.m-search-input:focus { border-color: var(--accent); background: var(--bg2); }
.m-search:focus-within .m-search-icon { fill: var(--accent); }
.m-search-btn {
    flex-shrink: 0;
    height: 44px;
    padding: 0 16px;
    background: var(--accent);
    border-radius: var(--radius);
    color: var(--on-accent);
    font-size: var(--fs);
    font-weight: 800;
    transition: background-color var(--tr);
}
.m-search-btn:hover,
.m-search-btn:active { background: var(--accent-hover); }

@media (min-width: 768px) {
    .m-search { display: none; }
}

/* Chip menu lặp lại ở cuối trang (foot.html) → hiển thị như footer */
#body > #sub-nav {
    flex-wrap: wrap;
    margin: 40px calc(var(--gutter) * -1) 0;
    padding: 20px var(--gutter);
    border-top: 1px solid var(--border);
    border-bottom: 0;
    background: transparent;
}

/* =====================================================================
   7. MODAL ĐĂNG NHẬP (head.html)
   ===================================================================== */
.auth-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    padding: 16px;
    background: rgba(5, 6, 9, .82);
    overflow-y: auto;
}
.auth-content {
    position: relative;
    width: min(380px, 100%);
    margin: 12vh auto 0;
    padding: 28px 24px 24px;
    background: var(--bg2);
    border: 1px solid var(--border2);
    border-radius: var(--radius-lg);
    color: var(--text1);
    animation: kf-pop .22s ease;
}
.auth-content h2 { margin-bottom: 12px; font-size: var(--fs-xl); }
.close-auth {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: var(--r-sm);
    color: var(--text2);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}
.close-auth:hover { background: var(--bg4); color: var(--text1); }
.auth-form input {
    display: block;
    width: 100%;
    height: 44px;
    margin: 10px 0;
    padding: 0 14px;
    background: var(--bg3);
    border: 1px solid var(--border2);
    border-radius: var(--radius);
    color: var(--text1);
}
.auth-form input:focus { border-color: var(--accent); }
.submit-btn {
    width: 100%;
    height: 44px;
    margin-top: 10px;
    background: var(--accent);
    border-radius: var(--radius);
    color: var(--on-accent);
    font-weight: 700;
    transition: background-color var(--tr);
}
.submit-btn:hover { background: var(--accent-hover); }
.auth-switch { margin-top: 16px; color: var(--text2); font-size: 13px; text-align: center; }
.auth-switch a { color: var(--accent); font-weight: 600; }
.auth-msg { min-height: 20px; margin-top: 10px; font-size: 13px; text-align: center; }

/* =====================================================================
   8. COMPONENT DÙNG CHUNG
   ===================================================================== */

/* ---- Tiêu đề trang (#primary .entry-header) ---- */
#primary .entry-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
    margin: 0 0 18px;
    padding: 0 0 14px;
    background: none;
    border: 0;
    border-bottom: 1px solid var(--border);
    text-align: left;
}
#primary .entry-title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    padding: 0;
    color: var(--text1);
    font-family: var(--font);
    font-size: clamp(18px, 2.4vw, 24px);
    font-weight: 800;
    line-height: 1.25;
    word-break: break-word;
}
#primary .entry-title::before {
    content: "";
    width: 4px;
    align-self: stretch;
    min-height: 20px;
    border-radius: 2px;
    background: var(--accent);
    flex-shrink: 0;
}
#primary .archive-total-count,
#primary .search-total-count {
    padding: 4px 12px;
    background: var(--bg3);
    border-radius: var(--r-pill);
    color: var(--text2);
    font-size: var(--fs-sm);
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
}

/* ---- Lưới card anime ---- */
.ext-json-grid,
.schedule-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px 10px;
}
@media (min-width: 560px)  { .ext-json-grid, .schedule-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 900px)  { .ext-json-grid, .schedule-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px 14px; } }
@media (min-width: 1200px) { .ext-json-grid, .schedule-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } }

.ext-json-item,
.schedule-grid-item {
    position: relative;
    min-width: 0;
    background: var(--bg2);
    border-radius: var(--radius);
    overflow: hidden;
    transition: background-color var(--tr);
}
.ext-json-item:hover,
.schedule-grid-item:hover { background: var(--bg3); }

.ext-json-item a,
.schedule-grid-item a {
    display: block;
    color: inherit;
    text-align: left;
    text-decoration: none;
}

.ext-json-thumb,
.schedule-grid-thumb {
    position: relative;
    display: block;
    aspect-ratio: var(--thumb-ratio);
    background: var(--bg3);
    overflow: hidden;
}
.ext-json-thumb img,
.schedule-grid-thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform .35s ease;
}
@media (hover: hover) {
    .ext-json-item:hover .ext-json-thumb img,
    .schedule-grid-item:hover .schedule-grid-thumb img { transform: scale(1.05); }
}

/* Badge tập / trạng thái */
.ext-json-noti,
.schedule-grid-noti {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 2;
    max-width: calc(100% - 16px);
    padding: 3px 8px;
    background: var(--accent);
    border-radius: var(--r-sm);
    color: var(--on-accent);
    font-size: var(--fs-xs);
    font-weight: 700;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ext-json-info { padding: 10px 10px 12px; }

.ext-json-name,
.schedule-grid-name {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    min-height: calc(1.4em * 2);
    margin: 0;
    color: var(--text1);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.4;
    white-space: normal;
    overflow: hidden;
    word-break: break-word;
    transition: color var(--tr);
}
.schedule-grid-name { padding: 10px 10px 12px; min-height: calc(1.4em * 2 + 22px); }
.ext-json-item:hover .ext-json-name,
.schedule-grid-item:hover .schedule-grid-name { color: var(--accent); }

.ext-json-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    color: var(--text3);
    font-size: var(--fs-sm);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ext-json-meta .ext-json-season {
    margin: 0;
    padding: 0 0 0 6px;
    border-left: 1px solid var(--border2);
    overflow: hidden;
    text-overflow: ellipsis;
}
.ext-json-meta .ext-json-season:empty { display: none; }

.ext-json-grid > .loading,
.ext-json-grid > .error,
.ext-json-grid > .ext-json-error,
.ext-json-grid > .status-msg,
.ext-json-grid > .msg-box {
    grid-column: 1 / -1;
}
.ext-json-grid .loading,
.ext-json-grid .error {
    padding: 32px 0;
    color: var(--text3);
    font-size: var(--fs-md);
    font-style: normal;
    text-align: center;
}
.ext-json-grid .error { color: var(--red); }
.ext-json-error { color: var(--text3); font-style: normal !important; }

/* ---- Hộp thông báo / trạng thái ---- */
.msg-box {
    padding: 40px 20px;
    background: var(--bg2);
    border: 1px dashed var(--border2);
    border-radius: var(--radius-lg);
    color: var(--text2);
    font-style: normal;
    text-align: center;
    line-height: 1.8;
}
.msg-box a {
    display: inline-block;
    margin-top: 6px;
    padding: 6px 16px;
    background: var(--accent);
    border-radius: var(--r-pill);
    color: var(--on-accent);
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}
.msg-box a:hover { background: var(--accent-hover); color: var(--on-accent); }

.status-msg {
    grid-column: 1 / -1;
    padding: 40px 20px;
    color: var(--text3);
    font-style: normal;
    text-align: center;
}

/* ---- Phân trang dùng chung ---- */
.pagination-dark,
#pagination-container.pagination-dark {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 28px;
    padding: 0;
    background: none;
    border: 0;
    font-family: var(--font);
}
.pagination-dark button,
#pagination-container.pagination-dark button,
.page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 0 12px;
    background: var(--bg3);
    border: 0;
    border-radius: var(--radius);
    color: var(--text1);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color var(--tr), color var(--tr);
}
.pagination-dark button:hover:not(:disabled),
#pagination-container.pagination-dark button:hover:not(:disabled),
.page-btn:hover:not(:disabled) { background: var(--bg4); color: var(--accent); }
.page-btn.active { background: var(--accent); color: var(--on-accent); }
.page-btn.active:hover { background: var(--accent-hover) !important; color: var(--on-accent) !important; }
.pagination-dark button:disabled,
#pagination-container.pagination-dark button:disabled,
.page-btn:disabled {
    background: var(--bg2);
    color: var(--text3);
    opacity: .6;
    cursor: not-allowed;
}

.pagination-dark .page-info,
#pagination-container.pagination-dark .page-info {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0 6px;
    color: var(--text2);
    font-size: 13px;
}
.pagination-dark input[type="number"],
#pagination-container.pagination-dark input[type="number"] {
    width: 56px;
    height: 40px;
    margin: 0;
    padding: 0 6px;
    background: var(--bg);
    border: 1px solid var(--border2);
    border-radius: var(--radius);
    color: var(--text1);
    font-weight: 700;
    text-align: center;
}
.pagination-dark input[type="number"]:focus { border-color: var(--accent); }
.pagination-dark .page-info button { margin-left: 0 !important; padding: 0 14px !important; background: var(--accent); color: var(--on-accent); }
.pagination-dark .page-info button:hover:not(:disabled) { background: var(--accent-hover) !important; color: var(--on-accent) !important; }

/* ---- Skeleton shimmer dùng chung ---- */
@keyframes kf-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
@keyframes kf-pop {
    from { opacity: 0; transform: translateY(8px) scale(.98); }
    to   { opacity: 1; transform: none; }
}
@keyframes kf-fadein {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* =====================================================================
   9. RESPONSIVE HEADER
   ===================================================================== */
@media (max-width: 767px) {
    :root { --header-h: 56px; }

    .header-center { display: none; }
    .mobile-search-trigger { display: inline-flex; }
    .logo-text { font-size: 17px; }

    body.search-active .header-left,
    body.search-active .header-right { display: none; }

    body.search-active .header-center {
        display: flex;
        flex: 1;
        margin: 0;
        animation: fadeIn .18s ease;
    }
    body.search-active .mobile-back-btn { display: inline-flex; }

    #sub-nav { justify-content: flex-start; }
    .auth-btn-link { padding: 0 10px; }
    .auth-btn-link span { display: none; }
}

@media (max-width: 380px) {
    .header-left > div { display: none !important; } /* ẩn icon MXH khi màn quá hẹp */
}

/* =====================================================================
   10. GIẢM CHUYỂN ĐỘNG
   ===================================================================== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}
