/* ============================================================
   styleIP.css — Tối ưu iPhone / iOS Safari
   ============================================================ */
:root {
    --bg:          #0a0a0c;
    --card-bg:     rgba(28, 28, 30, 0.85);
    --blue:        #0a84ff;
    --border:      rgba(255, 255, 255, 0.1);
    --text:        #ffffff;
    --dim:         #8e8e93;
    --safe-top:    env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}
html { -webkit-text-size-adjust: 100%; }

body {
    font-family: -apple-system, "SF Pro Text", sans-serif;
    margin: 0; padding: 0;
    padding-top: var(--safe-top);
    color: var(--text);
    background-color: var(--bg);
    background-image:
        radial-gradient(at 0% 0%,   rgba(58,58,60,0.2)  0px, transparent 50%),
        radial-gradient(at 100% 0%, rgba(10,132,255,0.1) 0px, transparent 40%);
    background-attachment: scroll;
    overscroll-behavior-y: none;
    -webkit-overflow-scrolling: touch;
    min-height: 100vh;
    min-height: -webkit-fill-available;
}

/* ============================================================
   MÀN HÌNH KHÓA
   ============================================================ */
#lock {
    position: fixed; inset: 0; z-index: 9999;
    background: radial-gradient(circle at center, #2c2c2e 0%, #000 100%);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    text-align: center; overflow: hidden;
    padding: 20px 20px calc(20px + var(--safe-bottom));
}
#lock::before {
    content: "";
    position: absolute; width: 200%; height: 200%;
    background: url('https://www.transparenttextures.com/patterns/carbon-fibre.png');
    opacity: 0.08; pointer-events: none;
    animation: bgMove 60s linear infinite;
}
@keyframes bgMove {
    from { transform: translate(0,0); }
    to   { transform: translate(-50%,-50%); }
}
#lock > div:first-child {
    font-size: 80px; margin-bottom: 16px; z-index: 1;
    filter: drop-shadow(0 0 12px rgba(255,255,255,0.15));
    animation: float 3s ease-in-out infinite;
}
@keyframes float {
    0%,100% { transform: translateY(0); }
    50%      { transform: translateY(-12px); }
}
#lock h2 {
    font-size: 18px; font-weight: 300; letter-spacing: 5px;
    text-transform: uppercase; color: #f2f2f7;
    margin: 0 0 32px; z-index: 1;
}
#pinInput {
    background: rgba(255,255,255,0.07);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 14px; padding: 16px;
    font-size: 22px; color: #fff;
    width: 160px; text-align: center;
    outline: none; -webkit-appearance: none; appearance: none;
    letter-spacing: 8px; z-index: 1;
    transition: border-color 0.3s, width 0.3s;
}
#pinInput::placeholder {
    color: rgba(255,255,255,0.3);
    font-size: 13px; letter-spacing: 2px; text-transform: uppercase;
}
#pinInput:focus { border-color: rgba(255,255,255,0.4); width: 200px; }

/* ============================================================
   THANH TÌM KIẾM LƠ LỬNG
   ============================================================ */
.header {
    position: sticky;
    top: 16px;            /* Cách mép trên — hiệu ứng lơ lửng */
    z-index: 1000;
    display: flex;
    justify-content: center;
    width: 100%;
    padding: 0 16px;
    pointer-events: none; /* Không chặn tap vào nền phía sau */
}
#search {
    pointer-events: auto;
    width: 100%; max-width: 500px;
    padding: 13px 18px 13px 44px;
    background: rgba(30,30,32,0.88)
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 30 30'%3E%3Cpath fill='%238e8e93' d='M13 3C7.489 3 3 7.489 3 13s4.489 10 10 10c2.397 0 4.597-.851 6.322-2.264l5.971 5.971a1 1 0 1 0 1.414-1.414l-5.971-5.971A9.954 9.954 0 0 0 23 13C23 7.489 18.511 3 13 3zm0 2c4.43 0 8 3.57 8 8s-3.57 8-8 8-8-3.57-8-8 3.57-8 8-8z'/%3E%3C/svg%3E")
        no-repeat 14px center;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 16px;
    color: var(--text); font-size: 16px;
    outline: none; -webkit-appearance: none; appearance: none;
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    box-shadow: 0 8px 32px rgba(0,0,0,0.45), 0 2px 8px rgba(0,0,0,0.3);
    transition: border-color 0.25s, box-shadow 0.25s;
}
#search:focus {
    border-color: var(--blue);
    background-color: rgba(40,40,44,0.95);
    box-shadow: 0 0 0 3px rgba(10,132,255,0.2), 0 10px 36px rgba(0,0,0,0.5);
}
#search::placeholder { color: var(--dim); }

/* ============================================================
   GRID
   ============================================================ */
.grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding: 60px 12px calc(16px + var(--safe-bottom));
    /* padding-top 60px để grid không bị header lơ lửng che */
    max-width: 1300px; margin: 0 auto;
}
@media (min-width: 600px) {
    .grid { grid-template-columns: repeat(3,1fr); gap: 16px; padding: 70px 16px 16px; }
}
@media (min-width: 900px) {
    .grid { grid-template-columns: repeat(auto-fill,minmax(210px,1fr)); gap: 22px; padding: 80px 24px 24px; }
}

/* ============================================================
   CARD
   ============================================================ */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 14px; overflow: hidden;
    cursor: pointer; will-change: transform;
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
    -webkit-tap-highlight-color: rgba(10,132,255,0.15);
}
.card:active {
    transform: scale(0.96);
    border-color: var(--blue);
    box-shadow: 0 4px 16px rgba(10,132,255,0.25);
}
@media (hover: hover) {
    .card:hover {
        border-color: var(--blue);
        transform: translateY(-4px);
        box-shadow: 0 8px 20px rgba(10,132,255,0.2);
    }
}
.card img {
    width: 100%; aspect-ratio: 1/1;
    object-fit: cover; background: #fff; display: block;
}
.info { padding: 10px 12px 12px; }
.info b {
    display: -webkit-box;
    -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 13px; font-weight: 600;
    color: var(--text); line-height: 1.35; margin-bottom: 5px;
}
.info span {
    font-size: 11px; font-weight: 700; color: var(--blue);
    background: rgba(10,132,255,0.1);
    padding: 2px 7px; border-radius: 5px; display: inline-block;
}

/* ============================================================
   MODAL CHI TIẾT — FIX SAFARI iOS
   Dùng position absolute thay vì flexbox để tránh Safari bug
   ============================================================ */
#detail-view {
    display: none;
    position: fixed; inset: 0; z-index: 2000;
    background: #000;
    /* Không dùng flex column — Safari iOS không tính chiều cao đúng */
    overflow: hidden;
}

/* Gallery: chiếm 85% chiều cao màn hình */
.gallery {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 85vh;
    background: #000;
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
}

/* Content: chiếm ~15% phía dưới, scroll nếu nội dung dài */
.content {
    position: absolute;
    top: calc(85vh - 20px); /* Gallery chiếm 85vh, content 15vh */
    left: 0; right: 0;
    bottom: 0;
    background: #fff;
    border-radius: 24px 24px 0 0;
    padding: 16px 20px calc(12px + var(--safe-bottom));
    color: #1c1c1e;
    display: flex; flex-direction: column; gap: 8px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    z-index: 1;
    /* Tối thiểu đủ hiện tên + mã, tối đa 40vh khi kéo */
    min-height: 120px;
}

/* PC — dùng lại flex row */
@media (min-width: 900px) {
    #detail-view {
        display: none;
        position: fixed;
        inset: 30px; margin: auto;
        max-width: 1000px;
        height: calc(100vh - 60px);
        border-radius: 24px;
        overflow: hidden;
        box-shadow: 0 25px 60px rgba(0,0,0,0.5);
        flex-direction: row; /* flex chỉ dùng trên PC */
    }
    .gallery {
        position: relative;
        top: auto; left: auto; right: auto;
        height: 100%; width: auto;
        flex: 2; border-radius: 24px 0 0 24px;
    }
    .content {
        position: relative;
        top: auto; left: auto; right: auto; bottom: auto;
        flex: 1; border-radius: 0 24px 24px 0;
        padding: 32px; justify-content: center;
        overflow-y: auto;
    }
}

.gallery img {
    max-width: 100%; max-height: 100%;
    object-fit: contain;
    user-select: none; -webkit-user-select: none;
    pointer-events: none;
    transform: rotate(0deg) scale(1);
    transition: transform 0.25s cubic-bezier(0.4,0,0.2,1);
    will-change: transform;
}

.detail-title { font-size: 20px; font-weight: 700; color: #000; line-height: 1.3; }
.detail-code {
    font-size: 13px; font-weight: 700; color: var(--blue);
    background: rgba(10,132,255,0.1);
    padding: 4px 10px; border-radius: 7px;
    display: inline-block; width: fit-content;
}
.detail-desc {
    font-size: 14px; line-height: 1.65; color: #3a3a3c;
    border-top: 1px solid #f2f2f7; padding-top: 12px;
    white-space: pre-wrap; margin: 0;
}

/* Nút đóng */
.close-btn {
    position: absolute;
    top: calc(14px + var(--safe-top)); right: 16px;
    background: rgba(0,0,0,0.5); color: #fff;
    border: none; border-radius: 50%;
    width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; z-index: 2100; cursor: pointer;
    touch-action: manipulation;
}

/* Nút xoay */
.rotate-btn {
    position: absolute; bottom: calc(15vh + 32px); left: 16px;
    background: rgba(255,255,255,0.15); color: #fff;
    border: 1px solid rgba(255,255,255,0.25);
    width: 44px; height: 44px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; cursor: pointer; z-index: 2100;
    touch-action: manipulation;
}
@media (min-width: 900px) {
    .rotate-btn { bottom: 16px; left: 16px; }
}

/* Counter */
.counter {
    position: absolute;
    bottom: calc(15vh + 8px); right: 16px;
    background: rgba(0,0,0,0.6); color: #fff;
    padding: 5px 12px; border-radius: 20px;
    font-size: 12px; font-weight: 600; z-index: 2100;
}
@media (min-width: 900px) {
    .counter { bottom: 16px; right: 16px; }
}

/* Nút prev/next — ẩn mobile */
.nav-btn { display: none; }
@media (min-width: 900px) {
    .nav-btn {
        display: flex; position: absolute;
        top: 50%; transform: translateY(-50%);
        background: rgba(255,255,255,0.1); color: #fff;
        border: none; padding: 22px 14px;
        font-size: 22px; cursor: pointer; z-index: 2100;
        align-items: center; transition: background 0.2s;
    }
    .nav-btn:hover { background: rgba(255,255,255,0.2); }
    .btn-prev { left: 0; border-radius: 0 10px 10px 0; }
    .btn-next { right: 0; border-radius: 10px 0 0 10px; }
}