/**
 * ป๊อปอัปประชาสัมพันธ์หน้าแรก
 *
 * หลักการ: รูปต้องไม่ผิดสัดส่วนและต้องเห็นเต็มใบบนทุกอุปกรณ์
 * จึงไม่กำหนดความกว้างหรือสูงตายตัวให้รูป แต่ใช้ max-width + max-height
 * แล้วปล่อยให้เบราว์เซอร์คำนวณอีกด้านเอง (width/height เป็น auto)
 * ซึ่งรักษาอัตราส่วนเดิมเสมอ ไม่ว่าจอจะกว้างหรือสูงแค่ไหน
 */

.hp-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    /* เผื่อขอบจอโค้งและแถบของเบราว์เซอร์บนมือถือ */
    padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
    background: rgba(15, 23, 42, 0.72);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.hp-overlay.is-open {
    opacity: 1;
    visibility: visible;
}

.hp-dialog {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    max-width: min(94vw, 900px);
    transform: scale(0.96);
    transition: transform 0.25s ease;
}

.hp-overlay.is-open .hp-dialog { transform: scale(1); }

.hp-figure {
    position: relative;
    margin: 0;
    display: flex;
    max-width: 100%;
}

/* โหมดขยาย: ให้รูปสูงเต็มพื้นที่แล้วเลื่อนดูแนวนอนได้
   จำเป็นบนมือถือแนวตั้ง เพราะรูป 16:9 ถูกจำกัดด้วยความกว้างจนตัวหนังสือเล็ก */
.hp-figure.is-zoom {
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    border-radius: 16px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.hp-figure.is-zoom .hp-img {
    max-width: none;
    width: auto;
    height: calc(100vh - 140px);
    height: calc(100dvh - 140px);
    max-height: none;
    border-radius: 0;
    cursor: zoom-out;
}

.hp-img { cursor: zoom-in; }

/* ป้ายบอกวิธีใช้ แสดงเฉพาะจอแคบที่รูปถูกย่อจนตัวหนังสือเล็ก */
.hp-hint {
    display: none;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.78rem;
    font-weight: 300;
    color: rgba(255, 255, 255, 0.82);
}

@media (max-width: 760px) {
    .hp-hint { display: inline-flex; }
}

.hp-dialog.is-zoomed .hp-hint { display: none; }

/* หัวใจของการไม่ให้รูปเพี้ยน: จำกัดได้ทั้งสองด้าน แต่ไม่บังคับขนาดใดขนาดหนึ่ง */
.hp-img {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: calc(100vh - 140px);
    max-height: calc(100dvh - 140px); /* dvh กันแถบ URL ของมือถือบังรูป */
    object-fit: contain;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 30px 60px -25px rgba(0, 0, 0, 0.7);
}

.hp-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.94);
    color: #0f172a;
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 6px 18px -6px rgba(0, 0, 0, 0.55);
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.16s ease, background 0.16s ease;
}

.hp-close:hover { background: #fff; transform: scale(1.06); }
.hp-close:focus-visible { outline: 3px solid #38bdf8; outline-offset: 2px; }

.hp-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
}

.hp-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    min-height: 40px;
    padding: 0 1.1rem;
    border: 1px solid rgba(255, 255, 255, 0.45);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-family: inherit;
    font-size: 0.86rem;
    font-weight: 400;
    text-decoration: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.16s ease;
}

.hp-btn:hover,
.hp-btn:focus-visible { background: rgba(255, 255, 255, 0.24); color: #fff; }
.hp-btn:focus-visible { outline: 2px solid #38bdf8; outline-offset: 2px; }

/* ล็อกการเลื่อนหน้าเว็บขณะเปิดป๊อปอัป */
body.hp-locked { overflow: hidden; }

/* จอเตี้ย เช่น มือถือแนวนอน: ให้รูปใช้พื้นที่ได้มากที่สุดและย่อปุ่มลง */
@media (max-height: 520px) {
    .hp-overlay { padding: 10px; }
    .hp-figure.is-zoom .hp-img {
        height: calc(100vh - 76px);
        height: calc(100dvh - 76px);
    }
    .hp-dialog { gap: 0.5rem; }
    .hp-img {
        max-height: calc(100vh - 76px);
        max-height: calc(100dvh - 76px);
        border-radius: 12px;
    }
    .hp-btn { min-height: 34px; font-size: 0.8rem; padding: 0 0.85rem; }
}

/* จอแคบมาก: ใช้พื้นที่กว้างเต็มที่ */
@media (max-width: 420px) {
    .hp-overlay { padding: 12px; }
    .hp-dialog { max-width: 96vw; }
    .hp-img { border-radius: 12px; }
}

@media (prefers-reduced-motion: reduce) {
    .hp-overlay,
    .hp-dialog,
    .hp-close { transition: none; }
}
