/**
 * Help Center — Layer 2 (หน้าบ้าน · e-book reader)
 *
 * ขอบเขต: หน้ารวมหัวข้อ + หน้าเนื้อหาแบบ 1 step ต่อ 1 หน้าจอ
 * หลักการ: CSS ไฟล์เดียวของโมดูล · mobile-first · ไม่แตะ chrome เว็บ (header/footer ไม่ถูก include)
 *
 * breakpoint: 768px = ขอบมือถือ (มือถือ ≤ 768 · คอม ≥ 769) ตรงกับค่าที่ใช้มากที่สุดใน main.css
 *   → ค่าคงที่ฝั่ง PHP คือ HELP_INTRO_MOBILE_MAX = 768
 *
 * หมายเหตุ: ไฟล์นี้ไม่ประกาศ CSS variable ใหม่ในระดับ :root
 *   ตัวแปร --hi-* ถูกประกาศใต้ .hi-root เท่านั้น (ขอบเขตของโมดูล)
 */

/* ── พื้นฐาน: ตัดภาพพื้นหลังเพจของ main.css ออกให้หน้าสะอาดแบบ e-book ───────── */
body.page-help-intro {
    --page-bg-image-left: none;
    --page-bg-image-right: none;
    --page-bg-image-bottom: none;
    background: #f5f5f5;
    overscroll-behavior-y: none;
    /* เอฟเฟกต์เลื่อนเปลี่ยนขั้นขยับแนวนอนเล็กน้อย → กันแถบเลื่อนนอนโผล่ */
    overflow-x: hidden;
}

body.page-help-intro .page-shell::before,
body.page-help-intro .page-shell::after {
    content: none;
}

/* ── ธีม (4 ค่าใน HELP_INTRO_THEMES) ───────────────────────────────────────── */
.hi-root {
    --hi-bg: #f7f3ee;
    --hi-fg: #3b2f26;
    --hi-muted: #7c6b5c;
    --hi-surface: rgba(255, 255, 255, 0.66);
    --hi-line: rgba(59, 47, 38, 0.10);
    --hi-accent: #b89a64;
    background: var(--hi-bg);
    color: var(--hi-fg);
    min-height: 100dvh;
    min-height: 100vh;
}

.hi-root[data-theme="cool"] {
    --hi-bg: #eef4f8;
    --hi-fg: #0a1f44;
    --hi-muted: #536177;
    --hi-surface: rgba(255, 255, 255, 0.72);
    --hi-line: rgba(10, 31, 68, 0.10);
    --hi-accent: #163560;
}

.hi-root[data-theme="neutral"] {
    --hi-bg: #f5f6f7;
    --hi-fg: #1f2937;
    --hi-muted: #6b7280;
    --hi-surface: rgba(255, 255, 255, 0.78);
    --hi-line: rgba(31, 41, 55, 0.10);
    --hi-accent: #0a1f44;
}

.hi-root[data-theme="dark"] {
    --hi-bg: #14202e;
    --hi-fg: #f3f6fa;
    --hi-muted: #a9b8c9;
    --hi-surface: rgba(255, 255, 255, 0.08);
    --hi-line: rgba(255, 255, 255, 0.14);
    --hi-accent: #b89a64;
}

/* แอดมินกำหนด background_color เป็นสีเข้ม → พลิกสีตัวอักษรให้อ่านได้ */
.hi-root[data-on-dark="1"] {
    --hi-fg: #f3f6fa;
    --hi-muted: #c6d3e0;
    --hi-surface: rgba(255, 255, 255, 0.10);
    --hi-line: rgba(255, 255, 255, 0.16);
}

/* แอดมินกำหนด background_color เป็นสีอ่อน (แม้ธีมเดิมจะมืด) → กลับไปใช้ตัวอักษรเข้ม */
.hi-root[data-on-light="1"] {
    --hi-fg: #1f2937;
    --hi-muted: #6b7280;
    --hi-surface: rgba(255, 255, 255, 0.72);
    --hi-line: rgba(31, 41, 55, 0.10);
    --hi-accent: #0a1f44;
}

/* ── แท่งไอคอนลอย (พื้นขาวจาง — มองเห็นได้ทุกธีม) ─────────────────────────── */
.hi-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
    pointer-events: none;
}

.hi-bar__btn {
    pointer-events: auto;
    display: inline-grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.74);
    border: 1px solid rgba(255, 255, 255, 0.68);
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.14);
    color: #22303f;
    text-decoration: none;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    transition: transform 0.15s ease, background 0.15s ease;
}

.hi-bar__btn:active {
    transform: scale(0.95);
}

.hi-bar__btn svg {
    width: 21px;
    height: 21px;
    display: block;
}

/* ── หน้าเนื้อหา (1 step = 1 หน้าจอ) ──────────────────────────────────────── */
.hi-main {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
    min-height: 100dvh;
    min-height: 100vh;
    padding: calc(66px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom));
    box-sizing: border-box;
}

/* ชื่อหัวข้อ — ชิดขอบบน ตัวเล็ก */
.hi-topic {
    margin: 0 0 4px;
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.5;
    color: var(--hi-muted);
    letter-spacing: 0.01em;
}

/* ชุดเนื้อหาของอุปกรณ์หนึ่ง ๆ — เต็มความสูงที่เหลือของหน้าจอ */
.hi-set {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* โหมดแยกอุปกรณ์: แสดงชุดเดียวตามความกว้างจอ (768px = ขอบมือถือ) */
.hi-set[data-device="mobile"] {
    display: flex;
}

.hi-set[data-device="desktop"] {
    display: none;
}

@media (min-width: 769px) {
    .hi-set[data-device="mobile"] {
        display: none;
    }

    .hi-set[data-device="desktop"] {
        display: flex;
    }
}

/* ── สล็อตภาพ: จองพื้นที่คงที่ (aspect-ratio) → ข้อความไม่ขยับแม้ยังไม่มีรูป ── */
.hi-stage {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px 0;
}

.hi-media {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    max-height: 56vh;
    display: grid;
    place-items: center;
    overflow: hidden;
    border-radius: 24px;
    background: var(--hi-surface);
    border: 1px solid var(--hi-line);
}

.hi-media img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.hi-media__empty {
    font-size: 0.85rem;
    color: var(--hi-muted);
    text-align: center;
    padding: 8px;
}

/* ── ปุ่มลูกศรนำทาง ลอยทับบนรูป (ทั้ง Chrome/คอม และ LINE) ───────────────────
 * ขนาดคูณ --line-font-scale เพราะใน LINE root ถูก zoom ลง (Chrome: ไม่มีตัวแปร → 1)
 * ปุ่มเป็น <a href> ธรรมดา → ใช้ได้แม้ JS ปิด และไม่ชนกับตัวจับการปัด
 */
.hi-nav {
    position: absolute;
    top: 50%;
    z-index: 3;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: calc(46px * var(--line-font-scale, 1));
    height: calc(46px * var(--line-font-scale, 1));
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #ffffff;
    color: #14304f;
    box-sizing: border-box;
    box-shadow: 0 2px 10px rgba(8, 22, 47, 0.22), 0 0 0 1px rgba(8, 22, 47, 0.06);
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.hi-nav--prev {
    left: 10px;
}

.hi-nav--next {
    right: 10px;
}

.hi-nav:active {
    transform: translateY(-50%) scale(0.94);
}

.hi-nav:focus-visible {
    outline: 2px solid #14304f;
    outline-offset: 2px;
}

.hi-nav svg {
    display: block;
    width: calc(22px * var(--line-font-scale, 1));
    height: calc(22px * var(--line-font-scale, 1));
    pointer-events: none;
}

/* ── ส่วนล่าง: ตัวนับ step + หัวข้อ step + คำอธิบาย ────────────────────────── */
.hi-foot {
    margin-top: auto;
}

.hi-count {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    color: var(--hi-muted);
    text-transform: uppercase;
}

.hi-step-title {
    margin: 2px 0 6px;
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1.45;
    color: var(--hi-fg);
}

.hi-step-body {
    margin: 0;
    font-size: 0.98rem;
    line-height: 1.72;
    color: var(--hi-fg);
    opacity: 0.92;
    white-space: pre-line;
}

/* ── จุดนำทาง (แตะเพื่อข้าม step) ───────────────────────────────────────────
 * พื้นที่แตะ 30×36 px โดยจุดที่มองเห็นยังเป็น 7px (หรือ 22px ตอน current)
 * ระยะขอบลบชดเชยให้จุดยังห่างกัน ~16px เท่าเดิม — ไม่มีพื้นที่แตะซ้อนกันจริง
 */
.hi-dots {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 0 0;
}

.hi-dot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 36px;
    margin: 0 -11px;
    border-radius: 999px;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}

.hi-dot::before {
    content: "";
    display: block;
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: var(--hi-muted);
    opacity: 0.34;
    transition: width 0.18s ease, opacity 0.18s ease, background 0.18s ease;
}

.hi-dot[aria-current="true"]::before {
    width: 22px;
    opacity: 1;
    background: var(--hi-accent);
}

/* ── เอฟเฟกต์เลื่อนเปลี่ยนขั้น ───────────────────────────────────────────────
 * เข้า (enter): server ใส่ data-hi-enter จาก ?d=next|prev → เล่นตั้งแต่ paint แรก
 *               (ไม่ต้องรอ JS จึงไม่มีภาพกระพริบ)
 * ออก (leave): JS ใส่ data-hi-leave ก่อนสั่งไปหน้าถัดไป 170ms
 * ถ้า JS ปิด → ยังได้เอฟเฟกต์ตอนเข้าอย่างเดียว (ไม่เสีย functionality)
 */
.hi-root[data-hi-enter="next"] {
    animation: hi-enter-next 0.26s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

.hi-root[data-hi-enter="prev"] {
    animation: hi-enter-prev 0.26s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

.hi-root[data-hi-leave] {
    pointer-events: none;
}

.hi-root[data-hi-leave="next"] {
    animation: hi-leave-next 0.17s ease-in both;
}

.hi-root[data-hi-leave="prev"] {
    animation: hi-leave-prev 0.17s ease-in both;
}

@keyframes hi-enter-next {
    from { opacity: 0; transform: translateX(26px); }
    to { opacity: 1; transform: none; }
}

@keyframes hi-enter-prev {
    from { opacity: 0; transform: translateX(-26px); }
    to { opacity: 1; transform: none; }
}

@keyframes hi-leave-next {
    from { opacity: 1; transform: none; }
    to { opacity: 0; transform: translateX(-26px); }
}

@keyframes hi-leave-prev {
    from { opacity: 1; transform: none; }
    to { opacity: 0; transform: translateX(26px); }
}

/* ── หน้ารวมหัวข้อ ───────────────────────────────────────────────────────── */
.hi-list-main {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
    padding: calc(66px + env(safe-area-inset-top)) 20px calc(28px + env(safe-area-inset-bottom));
    box-sizing: border-box;
}

.hi-list-title {
    margin: 0 0 4px;
    font-size: 1.35rem;
    font-weight: 700;
}

.hi-list-sub {
    margin: 0 0 20px;
    font-size: 0.9rem;
    color: var(--hi-muted);
}

.hi-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.hi-card {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 12px;
    border-radius: 18px;
    background: var(--hi-surface);
    border: 1px solid var(--hi-line);
    text-decoration: none;
    color: inherit;
}

.hi-card:active {
    transform: scale(0.995);
}

.hi-card__thumb {
    flex: 0 0 84px;
    width: 84px;
    aspect-ratio: 1 / 1;
    border-radius: 14px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.04);
    display: grid;
    place-items: center;
}

.hi-card__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.hi-card__body {
    display: block;
    min-width: 0;
}

.hi-card__title,
.hi-card__summary,
.hi-card__meta {
    display: block;
}

.hi-card__title {
    margin: 0 0 2px;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.5;
}

.hi-card__summary {
    margin: 0 0 6px;
    font-size: 0.85rem;
    color: var(--hi-muted);
    line-height: 1.55;
}

.hi-card__meta {
    font-size: 0.76rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--hi-muted);
    text-transform: uppercase;
}

.hi-empty {
    padding: 40px 8px;
    text-align: center;
    color: var(--hi-muted);
    font-size: 0.92rem;
}

/* ── จอใหญ่: จำกัดความกว้างการอ่าน ไม่ให้บรรทัดยาวเกินไป ──────────────────── */
@media (min-width: 769px) {
    .hi-main {
        max-width: 680px;
        padding-top: calc(78px + env(safe-area-inset-top));
    }

    .hi-topic {
        font-size: 1rem;
    }

    .hi-step-title {
        font-size: 1.28rem;
    }
}

/* ── มือถือ: ยึดตำแหน่ง «ขั้นที่ x / y» + บรรทัดแรกของคำอธิบายให้คงที่ ──────────
 * ปัญหาเดิม: .hi-stage เป็น flex:1 และ .hi-foot เป็น margin-top:auto
 *   → ข้อความยาวขึ้น = เวทีถูกบีบ = รูปเลื่อนขึ้น และตัวนับเลื่อนขึ้นตามความยาวข้อความ
 * ใหม่: เวทีไม่ยืด/ไม่หด (flex 0 0 auto) · ข้อความต่อจากขอบล่างของรูปทันที (ไม่มี margin-top:auto)
 *   → รูปอยู่ชิดบน ข้อความเริ่มที่ตำแหน่งเดิมเสมอ ข้อความยาวแค่ไหนก็ยืดลงด้านล่าง
 *   → พื้นที่ว่างที่เหลือยกให้ .hi-dots (margin-top:auto) ไม่ใช่ยกให้รูป
 * เพดานความยาวข้อความถูกบังคับที่ฝั่งแอดมิน (HELP_INTRO_STEP_TITLE_MAX / STEP_BODY_MAX)
 * เพื่อไม่ให้ยืดลงจนล้นจอ — ตรงกับที่ตกลง 2026-11-24
 *
 * ⚠ บล็อกนี้ต้องอยู่ *หลัง* กฎฐานของ .hi-stage/.hi-media/.hi-foot/.hi-dots
 *   (specificity เท่ากัน — ลำดับในไฟล์เป็นตัวตัดสิน)
 */
@media (max-width: 768px) {
    .hi-set {
        flex: 0 0 auto;
    }

    .hi-stage {
        flex: 0 0 auto;
        align-items: flex-start;
        padding: 0 0 12px;
    }

    /* กันจอเตี้ย (เช่น 360×640): จองพื้นที่ให้ข้อความยาวสุด + จุดนำทางก่อน
     * → กล่องรูปยอมเตี้ยลง แต่ตำแหน่งข้อความยังคงที่ (ค่าขึ้นกับความสูงจอ ไม่ขึ้นกับข้อความ)
     * 468px = หัวข้อ + ข้อความยาวสุด 175 ตัวอักษร + จุดนำทาง + ขอบ + 1 บรรทัดที่เว้นให้ข้อความ (27px)
     */
    .hi-media {
        max-height: max(150px, min(56vh, calc(100dvh - 468px)));
    }

    /* เว้น 1 บรรทัดว่างก่อนบรรทัด «ขั้นที่ x / y» (เจ้าของขอ 2026-11-24 · อาจขยับเป็น 2 บรรทัดรอบถัดไป)
     * 27px ≈ 1 บรรทัดของคำอธิบาย (0.98rem × line-height 1.72) · ค่าคงที่ ไม่ขึ้นกับความยาวข้อความ
     */
    .hi-foot {
        margin-top: 27px;
    }

    .hi-dots {
        margin-top: auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    .hi-bar__btn,
    .hi-dot::before,
    .hi-nav {
        transition: none;
    }

    .hi-root[data-hi-enter],
    .hi-root[data-hi-leave] {
        animation: none;
    }
}
