/* =====================================================================
   52HzMisfit – CSS CHUNG CỦA WEBSITE
   Nạp SAU Bootstrap 5 để ghi đè. CSS riêng từng công cụ nằm trong assets/css/pages/.

   MỤC LỤC
   1. Biến màu & nền trang
   2. Bố cục chung (container, tiêu đề)
   3. Header + menu chính + menu 3 gạch (offcanvas)
   4. Thanh công cụ nhanh
   5. Footer
   6. Nút lên đầu trang
   7. Thành phần dùng lại (nút liên kết, trang chi tiết…)
   8. Form công cụ tạo ảnh trên điện thoại
   ===================================================================== */

/* ---------- 1. BIẾN MÀU & NỀN TRANG ---------- */
:root {
    --brand: #3b82f6;
    --brand-dark: #1d4ed8;
    --brand-deep: #1e3a8a;
    --brand-soft: #e0f2fe;
    --brand-softer: #f0f7ff;
    --brand-green: #10b981;
    --header-bg: rgba(96, 165, 250, .82);
    --header-text: #fff;
    --footer-bg: rgba(30, 58, 138, .9);
    --nav-bg: #fff;
    --nav-text: #34495e;
    --nav-hover: #eef5ff;
    --offcanvas-bg: #1e40af;
    --bg-line: #bae6fd;
    --bg-page-2: #f1f5f9;
    --bg-page-3: #e0f2fe;
    --bg-stars: none;
    --chip-filter: none;
    --logo-filter: none;

    /* Ghi đè màu Bootstrap theo màu web */
    --bs-primary: #3b82f6;
    --bs-primary-rgb: 59, 130, 246;
    --bs-link-color: #1d4ed8;
    --bs-link-color-rgb: 29, 78, 216;
    --bs-link-hover-color: #1e40af;
    --bs-body-font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    --bs-body-color: #1e3a8a;
    --bs-border-radius: .625rem;
}

html {
    -webkit-text-size-adjust: 100%;
    overflow-x: hidden;   /* dự phòng iOS cũ */
    overflow-x: clip;
    overscroll-behavior-x: none;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: clip;
    overscroll-behavior-x: none;
    background-color: var(--brand-softer);
    /* Nền giấy kẻ dòng + ngôi sao – màu lấy theo giao diện đang chọn (app/site/theme.php) */
    background-image:
        var(--bg-stars),
        repeating-linear-gradient(to bottom,
            var(--bg-line) 0, var(--bg-line) 1px, var(--brand-softer) 1px, var(--brand-softer) 32px,
            var(--bg-line) 32px, var(--bg-line) 33px, var(--bg-page-2) 33px, var(--bg-page-2) 64px,
            var(--bg-line) 64px, var(--bg-line) 65px, var(--brand-softer) 65px, var(--brand-softer) 96px,
            var(--bg-line) 96px, var(--bg-line) 97px, var(--bg-page-3) 97px, var(--bg-page-3) 128px);
    background-size: 160px 256px, auto;
}

/* Bootstrap đặt tiêu đề weight 500 – trả về đậm như trước để các trang cũ không đổi */
h1, h2, h3, h4, h5, h6 { font-weight: 700; }

/* Nút chính của Bootstrap theo màu giao diện */
.btn-primary {
    --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand-dark); --bs-btn-hover-border-color: var(--brand-dark);
    --bs-btn-active-bg: var(--brand-dark); --bs-btn-active-border-color: var(--brand-dark);
    --bs-btn-disabled-bg: var(--brand); --bs-btn-disabled-border-color: var(--brand);
}

/* iOS: chữ trong ô nhập < 16px sẽ bị phóng to màn hình */
input, textarea, select { font-size: 16px; touch-action: manipulation; }

/* ---------- 2. BỐ CỤC CHUNG ---------- */
.site-container {
    max-width: 1232px;          /* 1200px nội dung + 2×16px lề */
    padding-left: 16px;
    padding-right: 16px;
}

.site-main {
    padding-top: 16px;
    padding-bottom: 32px;
}

/* ---------- 3. HEADER ---------- */
.site-header {
    z-index: 1020;
    background: var(--header-bg);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    backdrop-filter: blur(14px) saturate(160%);
    box-shadow: 0 4px 12px rgba(59, 130, 246, .15);
    padding-top: env(safe-area-inset-top);
}

.site-header-bar { padding: 8px 0; }

.site-logo img { height: 44px; width: auto; display: block; filter: var(--logo-filter, none); transition: filter .3s; }

.site-search { max-width: 520px; min-width: 0; }
.site-search .input-group-text,
.site-search .form-control,
.site-search .btn { border-color: #bae6fd; }
.site-search .input-group-text { background: #fff; color: var(--brand); border-radius: 999px 0 0 999px; padding-left: 14px; }
.site-search .form-control { border-left: 0; font-size: 15px; color: var(--brand-deep); }
.site-search .form-control:focus { box-shadow: none; border-color: #bae6fd; }
.site-search .btn { border-radius: 0 999px 999px 0; padding: 0 16px; font-weight: 600; }

.site-menu-btn {
    width: 42px; height: 42px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 12px;
    color: var(--header-text); font-size: 22px;
    background: rgba(255, 255, 255, .18);
    border: 0;
}
.site-menu-btn:hover, .site-menu-btn:focus { background: rgba(255, 255, 255, .3); color: var(--header-text); }

/* Menu chính (hàng 2) */
.site-nav { background: var(--nav-bg); border-bottom: 1px solid rgba(0, 0, 0, .06); }
.site-nav .nav { gap: 6px; padding: 4px 0; }
.site-nav .nav-link {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 16px;
    border-radius: 10px;
    color: var(--nav-text); font-weight: 500; font-size: 14.5px;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}
.site-nav .nav-link i { color: var(--brand); font-size: 16px; }
.site-nav .nav-link:hover,
.site-nav .nav-link.active,
.site-nav .nav-link.show { background: var(--nav-hover); color: var(--brand-dark); }
.site-nav .nav-link.active { font-weight: 600; }
.site-nav .nav-link-store { color: var(--brand-green); background: rgba(16, 185, 129, .12); }
.site-nav .nav-link-store i { color: var(--brand-green); }
.site-nav .nav-link-store:hover { background: var(--brand-green); color: #fff; }
.site-nav .nav-link-store:hover i { color: #fff; }

.site-dropdown {
    min-width: 270px;
    max-height: 70vh;
    overflow-y: auto;
    padding: 8px;
    border: 1px solid #eef2f7;
    border-radius: 14px;
}
.site-dropdown .dropdown-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; border-radius: 8px;
    font-size: 14px; color: #34495e;
}
.site-dropdown .dropdown-item i { color: var(--brand); opacity: .8; }
.site-dropdown .dropdown-item:hover { background: var(--nav-hover); color: var(--brand-dark); }
.site-dropdown .dropdown-item.active { background: var(--brand); color: #fff; }
.site-dropdown .dropdown-item.active i { color: #fff; }

/* Menu 3 gạch */
.site-offcanvas {
    --bs-offcanvas-width: 300px;
    --bs-offcanvas-bg: var(--offcanvas-bg);
    --bs-offcanvas-color: #fff;
    padding-top: env(safe-area-inset-top);
}
.site-offcanvas .offcanvas-header { border-bottom: 1px solid rgba(255, 255, 255, .15); }
.site-offcanvas .menu-heading {
    margin: 18px 0 6px;
    font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
    color: rgba(255, 255, 255, .65);
}
.site-offcanvas .menu-heading:first-child { margin-top: 0; }
.site-offcanvas .list-group-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 10px; border: 0; border-radius: 8px;
    background: transparent; color: #fff; font-size: 14.5px;
}
.site-offcanvas .list-group-item i { color: rgba(255, 255, 255, .6); }
.site-offcanvas .list-group-item:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.site-offcanvas .list-group-item.active { background: #fff; color: var(--brand-dark); font-weight: 600; }
.site-offcanvas .list-group-item.active i { color: var(--brand); }

/* ---------- 4. THANH CÔNG CỤ NHANH ---------- */
.quick-tools-line {
    display: flex;
    flex-wrap: nowrap;
    gap: 20px;
    max-width: 1232px;
    margin: 0 auto;
    padding: 20px 16px;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    scroll-behavior: smooth;
    scrollbar-width: none;
    white-space: nowrap;
}
.quick-tools-line::-webkit-scrollbar { display: none; }

.tool-chip {
    position: relative;
    flex: 0 0 auto;
    display: inline-flex; align-items: center; gap: 6px;
    height: 36px;
    padding: 8px 14px;
    font-size: 13px; font-weight: 700; color: #fff;
    text-decoration: none;
    background: url("../images/backgrounds/button.jpg") center / cover no-repeat;
    border-radius: 999px;
    text-shadow: -1px -1px 0 #005bb5, 1px -1px 0 #005bb5, -1px 1px 0 #005bb5, 1px 1px 0 #005bb5, 0 2px 4px rgba(0, 0, 0, .5);
    box-shadow: 0 0 0 2px #fff, 0 0 0 4px #0099ff, 0 4px 8px rgba(0, 0, 0, .2);
    filter: var(--chip-filter);
    transition: .2s;
}
.tool-chip::after {   /* logo nhỏ góc phải */
    content: "";
    position: absolute; top: -15px; right: -10px;
    width: 50px; height: 50px;
    background: url("../images/logo/logo52hzn.png") center / contain no-repeat;
    z-index: 1;
}
.tool-chip:hover { color: #fff; transform: translateY(-1px); }
.tool-chip.is-active { box-shadow: 0 0 0 2px #fff, 0 0 0 4px #f59e0b, 0 4px 8px rgba(0, 0, 0, .2); }

/* ---------- 5. FOOTER ---------- */
.site-footer {
    margin-top: 24px;
    padding: 40px 0 calc(20px + env(safe-area-inset-bottom));
    background: var(--footer-bg);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    backdrop-filter: blur(14px) saturate(160%);
    color: rgba(255, 255, 255, .85);
    font-size: 14px;
}
.site-footer p { line-height: 1.6; margin: 0; }
.footer-title { font-size: 15px; color: #fff; margin-bottom: 12px; }
.footer-list { list-style: none; padding: 0; margin: 0; }
.footer-list li { display: flex; gap: 8px; align-items: baseline; margin-bottom: 8px; line-height: 1.5; }
.footer-list i { color: rgba(255, 255, 255, .6); }
.site-footer a { color: rgba(255, 255, 255, .9); text-decoration: none; }
.site-footer a:hover { color: #fff; text-decoration: underline; }
.footer-bottom {
    margin-top: 28px; padding-top: 14px;
    border-top: 1px solid rgba(255, 255, 255, .12);
    text-align: center; font-size: 13px; color: rgba(255, 255, 255, .7);
}
.footer-admin { font-weight: 600; }

/* ---------- 6. NÚT LÊN ĐẦU TRANG ---------- */
#backToTop {
    position: fixed;
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    width: 44px; height: 44px;
    display: none; align-items: center; justify-content: center;
    padding: 0;
    z-index: 1030;
}
#backToTop.is-visible { display: inline-flex; }

/* ---------- 7. THÀNH PHẦN DÙNG LẠI ---------- */
/* Nút liên kết dạng viền đứt (Group / PNG / Zalo) */
.lien-quan-btn {
    display: inline-block;
    padding: 8px 18px;
    margin: 5px 10px 5px 0;
    font-size: 16px; font-weight: 500;
    color: var(--brand);
    text-decoration: none;
    border: 2px dashed var(--brand);
    border-radius: 12px;
    background: #fff;
    transition: all .3s ease;
}
.lien-quan-btn:hover { background: var(--brand-soft); transform: scale(1.05); border-style: solid; color: var(--brand-dark); }

/* Dòng "Đang phát triển" */
.dev { text-align: center; font-style: italic; color: var(--brand-dark); margin-top: 40px; }

/* Trang chi tiết mẫu */
.detail-back { margin-bottom: 16px; }
.btn-back {
    display: inline-block; padding: 8px 14px;
    border-radius: 999px; background: var(--brand-soft); color: var(--brand-dark);
    font-weight: 600; font-size: 14px; text-decoration: none; transition: all .2s ease;
}
.btn-back:hover { background: #bae6fd; transform: translateX(-2px); }
.detail-code { text-align: center; font-size: 28px; font-weight: 800; margin: 30px 0 20px; color: var(--brand-dark); }
.detail-image {
    display: block; width: 100%; max-width: 520px; margin: 0 auto 24px;
    border-radius: 16px; box-shadow: 0 10px 24px rgba(59, 130, 246, .15);
}
.detail-desc { max-width: 640px; margin: 0 auto 24px; line-height: 1.7; font-size: 15px; color: #334155; }
.detail-links { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 30px; }
.btn.detail-link {
    display: inline-flex; align-items: center; gap: 6px; margin: 0 auto;
    padding: 10px 22px; border: 0; border-radius: 999px;
    background: linear-gradient(135deg, #60a5fa, #3b82f6); color: #fff; font-weight: 600;
    box-shadow: 0 6px 16px rgba(59, 130, 246, .3);
}
.btn.detail-link:hover { color: #fff; opacity: .9; }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 768px) {
    .site-header-bar { padding: 6px 0; }
    .site-logo img { height: 40px; }
    .site-search .btn { display: none; }                      /* điện thoại: Enter để tìm */
    .site-search .form-control { border-radius: 0 999px 999px 0 !important; border-right: 1px solid #bae6fd; }
    .site-nav .nav { gap: 2px; }
    .site-nav .nav-link { padding: 8px 10px; font-size: 13.5px; gap: 6px; }
    .quick-tools-line { gap: 16px; padding: 18px 16px; }
    .lien-quan-btn { font-size: 14px; padding: 7px 14px; margin: 4px 6px 4px 0; }

    /* ---------- 8. FORM CÔNG CỤ TẠO ẢNH (2 cột trên điện thoại) ---------- */
    .tao-wrapper { flex-direction: column; gap: 16px; padding: 12px; }
    .tao-controls {
        width: 100%; padding: 14px; border-radius: 14px; background: #fff;
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 12px;
    }
    .tao-controls label { font-size: 13px; color: var(--brand-dark); margin-bottom: 0; }
    .tao-controls select, .tao-controls input { font-size: 14px; padding: 8px 10px; border: 1px solid #bae6fd; width: 100%; }
    #playerNameInput, .switch-line, #createBtn, #saveBtn, .dev,
    #rankInputWrapper, #talentWrapper, #cupRankWrapper { grid-column: span 2 !important; }
    .tao-controls button { font-size: 15px; padding: 10px; background: linear-gradient(135deg, #60a5fa, #3b82f6); }
    .tao-preview { width: 100%; overflow-x: auto; }
    canvas#preview { width: 100%; height: auto; }
}

@media (max-width: 380px) {
    .site-nav .nav-link span { font-size: 13px; }
    .site-nav .nav-link i { display: none; }
}

/* Tiêu đề nằm trực tiếp trên nền trang (không trong khung trắng): thêm class "on-bg"
   để nền tối tự đổi sang chữ sáng. */
/* ---------- 9. GIAO DIỆN TỐI (Ban đêm / tự chỉnh nền tối) ----------
   Chỉ đổi phần khung web; các khung công cụ màu trắng vẫn giữ nguyên để dễ nhìn. */
.theme-dark .site-header { color-scheme: dark; }
.theme-dark .site-main > h1, .theme-dark .site-main > h2, .theme-dark .site-main > h3,
.theme-dark .site-main > p, .theme-dark .site-main > header h1, .theme-dark .site-main > header p,
.theme-dark .dev, .theme-dark .on-bg { color: #e2e8f0 !important; }
.theme-dark .site-search .input-group-text,
.theme-dark .site-search .form-control { background: #1e293b; color: #e2e8f0; border-color: #334155; }
.theme-dark .site-search .form-control::placeholder { color: #94a3b8; }
.theme-dark .site-dropdown { --bs-dropdown-bg: #1e293b; --bs-dropdown-border-color: #334155; --bs-dropdown-header-color: #94a3b8; --bs-dropdown-divider-bg: #334155; }
.theme-dark .site-dropdown .dropdown-item { color: #cbd5e1; }
.theme-dark .lien-quan-btn { background: rgba(15, 23, 42, .7); }


/* ---------- iPhone: không tự phóng to khi bấm vào ô nhập ----------
   Safari iOS tự zoom nếu chữ trong ô < 16px -> ép 16px trên điện thoại */
@media (max-width: 991.98px) {
    input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]),
    select, textarea, .form-control, .form-select {
        font-size: 16px !important;
    }
}
