/* ลอยกระทง แถบล่างหน้าแรก (templates/home-strip.php) · ทุกอย่างอยู่ใน #lkHome · โหมดมืดใช้ html[data-site-theme="dark"] */

#lkHome {
    --lkh-green: #00ae4d;
    --lkh-green2: #00d65d;
    --lkh-card: #ffffff;
    --lkh-text: #1f2937;
    --lkh-muted: #6b7280;
    --lkh-line: #e5e7eb;
    --lkh-bubble-bg: rgba(255, 255, 255, 0.94);
    --lkh-bubble-text: #374151;
    --lkh-sender: #5b6be0;
    font-family: inherit;
}

html[data-site-theme="dark"] #lkHome {
    --lkh-card: #111827;
    --lkh-text: #f3f4f6;
    --lkh-muted: #9ca3af;
    --lkh-line: #374151;
    --lkh-bubble-bg: rgba(17, 24, 39, 0.9);
    --lkh-bubble-text: #e5e7eb;
    --lkh-sender: #a5b4fc;
}

/* ───────── แถบกระทง: โปร่งใส คลิกทะลุไปที่ข่าวด้านล่างได้ ───────── */
#lkHome .lkh-river {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 170px;
    z-index: 1030;
    pointer-events: none;
    overflow: hidden;
}

#lkHome.lkh-off .lkh-water,
#lkHome.lkh-off .lkh-river,
#lkHome.lkh-off .lkh-bubble,
#lkHome.lkh-off .lkh-hide {
    display: none;
}

#lkHome .krathong {
    position: absolute;
    left: 0;
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    gap: 2px;
    animation: lkh-float 32s linear forwards;
    will-change: transform;
}

#lkHome .krathong-img {
    width: 72px;
    height: 72px;
    filter: drop-shadow(0 0 10px rgba(255, 200, 90, 0.75)) drop-shadow(0 4px 6px rgba(0, 0, 0, 0.25));
    animation: lkh-bob 2.4s ease-in-out infinite;
}

#lkHome .krathong-message {
    max-width: 160px;
    padding: 6px 10px;
    border-radius: 12px;
    background: var(--lkh-bubble-bg);
    color: var(--lkh-bubble-text);
    border: 1.5px solid rgba(255, 205, 90, 0.6);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    font-size: 12px;
    line-height: 1.5;
    text-align: center;
    word-break: break-word;
}

/* ตัดบรรทัดที่ตัวข้อความ (ไม่ใช่กล่องนอก) · line-clamp บนกล่องที่มีชื่อผู้ลอยกับข้อความเป็น block ซ้อนกัน
   Safari ตัดไม่อยู่ ข้อความที่เหลือล้นลงใต้กล่อง · line-height 1.5 เผื่อสระบน / วรรณยุกต์ไทยไม่ถูกตัด */
#lkHome .krathong-text {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

#lkHome .krathong-sender {
    font-size: 11px;
    font-weight: 700;
    font-style: italic;
    color: var(--lkh-sender);
    /* ชื่อยาวตัดเป็น … ในบรรทัดเดียว ไม่ดันกล่องให้สูงขึ้น */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#lkHome .krathong.mine .krathong-message {
    border-color: #ffc94a;
    box-shadow: 0 0 0 3px rgba(255, 201, 74, 0.4), 0 4px 18px rgba(255, 190, 60, 0.5);
}

#lkHome .krathong.lk-out {
    opacity: 0;
    transition: opacity 0.6s ease;
}

/* ───────── แม่น้ำที่ฐานกระทง ─────────
   คลื่น SVG ซ้ำแนวนอน เลื่อนด้วย transform (ใช้ GPU ไม่ต้องวาดใหม่ทุกเฟรม) · โปร่งแสง ไม่บังข่าว คลิกทะลุได้ */
#lkHome .lkh-water {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    overflow: hidden;
}

#lkHome .lkh-water-back {
    height: 46px;
    z-index: 1029;
    -webkit-mask-image: linear-gradient(to top, #000 55%, transparent);
    mask-image: linear-gradient(to top, #000 55%, transparent);
}

#lkHome .lkh-water-front {
    height: 16px;
    z-index: 1031;
    opacity: 0.55;
}

#lkHome .lkh-wave {
    position: absolute;
    left: 0;
    bottom: 0;
    width: calc(100% + 480px);
    height: 100%;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 480 46' preserveAspectRatio='none'%3E%3Cpath d='M0 14 C 60 4 120 4 180 14 S 300 24 360 14 S 450 6 480 14 V46 H0 Z' fill='%234aa3d8' fill-opacity='0.38'/%3E%3C/svg%3E") repeat-x;
    background-size: 480px 100%;
    animation: lkh-wave 9s linear infinite;
    will-change: transform;
}

#lkHome .lkh-wave-slow {
    bottom: -4px;
    opacity: 0.8;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 480 46' preserveAspectRatio='none'%3E%3Cpath d='M0 20 C 80 10 160 30 240 20 S 400 10 480 20 V46 H0 Z' fill='%232b7fb8' fill-opacity='0.32'/%3E%3C/svg%3E");
    animation-duration: 14s;
    animation-direction: reverse;
}

#lkHome .lkh-water-front .lkh-wave {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 480 16' preserveAspectRatio='none'%3E%3Cpath d='M0 6 C 60 1 120 1 180 6 S 300 11 360 6 S 450 2 480 6 V16 H0 Z' fill='%2363b6e6' fill-opacity='0.5'/%3E%3C/svg%3E");
    animation-duration: 6s;
}

/* ประกายแสงจันทร์บนผิวน้ำ */
#lkHome .lkh-water-back::after {
    content: '';
    position: absolute;
    /* กว้างกว่าจอ 130px แล้วเลื่อนด้วย transform (ไม่แอนิเมต background-position ที่ต้องวาดใหม่ทุกเฟรม) */
    inset: auto 0 10px -130px;
    height: 2px;
    background: repeating-linear-gradient(90deg, transparent 0 40px, rgba(255, 255, 255, 0.6) 52px, transparent 64px 130px);
    filter: blur(1px);
    animation: lkh-glint 5s linear infinite;
    will-change: transform;
    opacity: 0.35;
}

html[data-site-theme="dark"] #lkHome .lkh-wave { filter: brightness(1.25) saturate(1.2); }

/* Safari iOS (แถบควบคุมด้านล่างโปร่งแสง): element แบบ fixed bottom:0 อยู่เหนือแถบ เนื้อหาเว็บไหลลอดใต้แม่น้ำ
   Safari ย้อมแถบควบคุมตามสีของ element แบบ sticky ที่ติดขอบล่าง (แบบ fixed ไม่ได้ผลบนเว็บนี้ เพราะ
   head.php ตั้ง overflow-x: clip และ viewport-fit=cover) จึงวางแถบ sticky สีน้ำบางๆ ไว้ใต้แม่น้ำ
   ทดสอบแล้วใน iOS Simulator (iOS 27) ด้วยการตั้งค่าเดียวกับเว็บจริง
   ต้องเป็นลูกโดยตรงของ body (สคริปต์ใน home-strip.php ย้ายให้) · margin ติดลบ = ไม่กินพื้นที่หน้า */
.lkh-tint {
    position: sticky;
    bottom: 0;
    height: 10px;
    margin-top: -10px;
    z-index: 1029;
    pointer-events: none;
    background: #8ec4e8;
}

html[data-site-theme="dark"] .lkh-tint { background: #3f6f9e; }

.lkh-tint[hidden] { display: none !important; }
html[data-site-theme="dark"] #lkHome .lkh-water-back::after { opacity: 0.85; }

@keyframes lkh-wave {
    from { transform: translateX(0); }
    to   { transform: translateX(-480px); }
}

@keyframes lkh-glint {
    from { transform: translateX(0); }
    to   { transform: translateX(130px); }
}

/* วงคลื่นใต้กระทงแต่ละอัน */
#lkHome .krathong::after {
    content: '';
    position: absolute;
    left: 50%;
    bottom: -3px;
    width: 86px;
    height: 12px;
    margin-left: -43px;
    border-radius: 50%;
    border: 2px solid rgba(160, 215, 245, 0.7);
    box-shadow: 0 0 10px rgba(255, 210, 120, 0.35);
    animation: lkh-ripple 2.4s ease-out infinite;
    pointer-events: none;
    z-index: -1;
}

@keyframes lkh-ripple {
    0%   { transform: scale(0.55); opacity: 0.9; }
    100% { transform: scale(1.35); opacity: 0; }
}

@keyframes lkh-float {
    from { transform: translateX(-220px) rotate(-3deg); }
    25%  { transform: translateX(calc(25vw - 165px)) rotate(2deg); }
    50%  { transform: translateX(calc(50vw - 110px)) rotate(-2deg); }
    75%  { transform: translateX(calc(75vw - 55px)) rotate(3deg); }
    to   { transform: translateX(calc(100vw + 40px)) rotate(-3deg); }
}

@keyframes lkh-bob {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-6px); }
}

/* ───────── ปุ่มลอยกระทงมุมขวา ───────── */
#lkHome .lkh-cta {
    position: fixed;
    right: 18px;
    bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    z-index: 1035;
    display: flex;
    align-items: center;
    gap: 12px;
}

#lkHome .lkh-bubble {
    position: relative;
    padding: 9px 16px;
    border-radius: 18px;
    background: #fff;
    color: var(--lkh-green);
    font-weight: 700;
    font-size: 15px;
    white-space: nowrap;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
    animation: lkh-bubble 2s ease-in-out infinite;
}

#lkHome .lkh-bubble::after {
    content: '';
    position: absolute;
    right: -10px;
    top: 50%;
    transform: translateY(-50%);
    border-style: solid;
    border-width: 7px 0 7px 11px;
    border-color: transparent transparent transparent #fff;
}

@keyframes lkh-bubble {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-4px); }
}

#lkHome .lkh-btn {
    width: 62px;
    height: 62px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.45);
    background: linear-gradient(135deg, var(--lkh-green), var(--lkh-green2));
    box-shadow: 0 8px 22px rgba(0, 174, 77, 0.5);
    cursor: pointer;
    display: grid;
    place-items: center;
    padding: 0;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

#lkHome .lkh-btn span {
    font-size: 30px;
    line-height: 1;
    animation: lkh-pulse 2s ease-in-out infinite;
}

#lkHome .lkh-btn:hover {
    transform: scale(1.08) rotate(8deg);
    box-shadow: 0 10px 30px rgba(0, 174, 77, 0.65);
}

#lkHome .lkh-btn:focus-visible,
#lkHome .lkh-hide:focus-visible,
#lkHome .lkh-submit:focus-visible {
    outline: 3px solid #93c5fd;
    outline-offset: 2px;
}

@keyframes lkh-pulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.12); }
}

#lkHome .lkh-hide {
    position: absolute;
    right: 48px;
    top: -8px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 0;
    padding: 0;
    background: rgba(17, 24, 39, 0.65);
    color: #fff;
    font-size: 15px;
    line-height: 22px;
    cursor: pointer;
}

/* ───────── กล่องส่งคำอธิษฐาน ───────── */
#lkHome .lkh-modal,
#lkHome .lkh-success {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1060;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

#lkHome .lkh-success { z-index: 1061; }

#lkHome .lkh-modal.active,
#lkHome .lkh-success.active {
    display: flex;
}

#lkHome .lkh-dialog,
#lkHome .lkh-success-box {
    position: relative;
    width: 100%;
    max-width: 460px;
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    padding: 26px 24px 20px;
    border-radius: 18px;
    background: var(--lkh-card);
    color: var(--lkh-text);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
    animation: lkh-in 0.25s ease-out;
    overscroll-behavior: contain;
}

#lkHome .lkh-success-box {
    max-width: 380px;
    text-align: center;
    padding: 36px 24px;
}

@keyframes lkh-in {
    from { transform: translateY(-24px); opacity: 0; }
    to   { transform: none; opacity: 1; }
}

#lkHome .lkh-close {
    position: absolute;
    top: 10px;
    right: 12px;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--lkh-muted);
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
}

#lkHome .lkh-close:hover { background: rgba(127, 127, 127, 0.15); }

#lkHome .lkh-title {
    margin: 0 0 14px;
    font-size: 20px;
    font-weight: 700;
    color: var(--lkh-text);
}

#lkHome .lkh-label {
    display: block;
    margin: 10px 0 5px;
    font-size: 14px;
    font-weight: 600;
    color: var(--lkh-text);
}

#lkHome .lkh-input {
    display: block;
    width: 100%;
    padding: 11px 13px;
    border: 1.5px solid var(--lkh-line);
    border-radius: 10px;
    background: transparent;
    color: var(--lkh-text);
    font: inherit;
    font-size: 16px;
    resize: vertical;
}

#lkHome .lkh-input:focus {
    outline: none;
    border-color: var(--lkh-green);
}

#lkHome .lkh-count {
    margin-top: 4px;
    text-align: right;
    font-size: 12px;
    color: var(--lkh-muted);
}

#lkHome .lkh-rule {
    margin: 8px 0 0;
    padding: 8px 12px;
    border-radius: 10px;
    background: #fff7e0;
    border: 1px solid #f5d27a;
    color: #7a5200;
    font-size: 13px;
    line-height: 1.5;
}

html[data-site-theme="dark"] #lkHome .lkh-rule {
    background: rgba(245, 190, 60, 0.12);
    border-color: rgba(245, 190, 60, 0.4);
    color: #fcd877;
}

#lkHome .lkh-designs {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

#lkHome .lkh-design {
    position: relative;
    cursor: pointer;
    border-radius: 14px;
    padding: 6px;
    border: 2px solid transparent;
}

#lkHome .lkh-design input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

#lkHome .lkh-design img {
    display: block;
    width: 72px;
    height: 72px;
    object-fit: contain;
    filter: grayscale(100%) opacity(0.5);
    transition: filter 0.3s, transform 0.3s;
}

#lkHome .lkh-design:has(input:checked) {
    border-color: var(--lkh-green);
    background: rgba(0, 174, 77, 0.1);
}

#lkHome .lkh-design:has(input:checked) img {
    filter: none;
    transform: scale(1.05);
}

#lkHome .lkh-design:has(input:focus-visible) {
    outline: 3px solid #93c5fd;
}

#lkHome .lkh-submit {
    display: block;
    width: 100%;
    margin-top: 16px;
    padding: 12px;
    border: 0;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--lkh-green), var(--lkh-green2));
    color: #fff;
    font: inherit;
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
}

#lkHome .lkh-submit:disabled {
    background: #9ca3af;
    cursor: not-allowed;
}

#lkHome .lkh-more {
    display: block;
    margin-top: 10px;
    text-align: center;
    font-size: 13px;
    color: var(--lkh-muted);
}

#lkHome .message {
    display: none;
    margin-bottom: 8px;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 14px;
    text-align: center;
}

#lkHome .message.error {
    background: #fde8e8;
    color: #9b1c1c;
}

#lkHome .lkh-success-icon { font-size: 42px; margin-bottom: 10px; }
#lkHome .lkh-success-box h2 { margin: 0 0 8px; font-size: 22px; font-weight: 700; color: var(--lkh-green); }
#lkHome .lkh-success-box p { margin: 0; color: var(--lkh-muted); }

#lkHome .lkh-hp {
    position: absolute !important;
    left: -9999px !important;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

#lkHome [hidden] { display: none !important; }

/* ───────── มือถือ ───────── */
@media (max-width: 600px) {
    #lkHome .lkh-river { height: 128px; }
    #lkHome .lkh-water-back { height: 36px; }
    #lkHome .lkh-water-front { height: 12px; }
    #lkHome .krathong::after { width: 64px; margin-left: -32px; height: 10px; }
    #lkHome .krathong { animation-duration: 24s; }
    #lkHome .krathong-img { width: 52px; height: 52px; }
    #lkHome .krathong-message { max-width: 124px; font-size: 11px; padding: 5px 8px; }
    #lkHome .krathong-text { -webkit-line-clamp: 2; }
    #lkHome .krathong-sender { font-size: 10px; }
    #lkHome .lkh-cta { right: 12px; gap: 10px; }
    #lkHome .lkh-bubble { font-size: 13px; padding: 7px 12px; }
    #lkHome .lkh-btn { width: 54px; height: 54px; }
    #lkHome .lkh-btn span { font-size: 26px; }
    #lkHome .lkh-hide { right: 40px; }
    #lkHome .lkh-design img { width: 60px; height: 60px; }
}

@media (prefers-reduced-motion: reduce) {
    #lkHome .krathong-img,
    #lkHome .lkh-bubble,
    #lkHome .lkh-btn span,
    #lkHome .lkh-wave,
    #lkHome .lkh-water-back::after,
    #lkHome .krathong::after { animation: none; }
}

@media print {
    #lkHome { display: none; }
}

/* กระทงประกอบเอง (SVG) กว้างกว่าสูง: ขยายกล่องให้ขนาดใกล้เคียงรูปเดิม */
#lkHome div.krathong-img { width: 100px; height: 70px; }
@media (max-width: 600px) {
    #lkHome div.krathong-img { width: 74px; height: 52px; }
}

/* ───────── โคมลอยที่ผู้ชมปล่อย: ลอยจากขอบล่างของจอขึ้นไปจนพ้นด้านบน (loykrathong.js floatLantern) ───────── */
#lkHome .lkh-sky {
    position: fixed;
    inset: 0;
    z-index: 1034;
    pointer-events: none;
    overflow: hidden;
}

#lkHome.lkh-off .lkh-sky { display: none; }

#lkHome .lk-fly {
    position: absolute;
    top: 100%;
    width: 150px;
    margin-left: -75px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    opacity: 0;
    /* ลอยขึ้นด้วย Web Animations ใน loykrathong.js (floatLantern) · keyframe ที่ใช้ var() Safari ไม่ส่งให้ GPU */
    --fly-d: 24s;
    --fly-end: 0.66;
    will-change: transform, opacity;
}

#lkHome .lk-fly-art {
    width: 64px;
    height: 84px;
    filter: drop-shadow(0 0 14px rgba(255, 170, 70, 0.7));
}

#lkHome .lk-fly .krathong-message { max-width: 150px; }

#lkHome .lk-fly.mine .krathong-message {
    border-color: #ffc94a;
    box-shadow: 0 0 0 3px rgba(255, 201, 74, 0.4), 0 4px 18px rgba(255, 190, 60, 0.5);
}

@media (max-width: 600px) {
    #lkHome .lk-fly { width: 124px; margin-left: -62px; --fly-d: 20s; }
    #lkHome .lk-fly-art { width: 52px; height: 68px; }
}

/* กดที่กระทง / โคมเพื่อแชร์ลง Story · ส่วนอื่นของแถบยังคลิกทะลุไปที่ข่าวได้ */
.lk-can-share #lkHome .krathong,
.lk-can-share #lkHome .lk-fly {
    pointer-events: auto;
    cursor: pointer;
}

.lk-can-share #lkHome .krathong:hover .krathong-message,
.lk-can-share #lkHome .lk-fly:hover .krathong-message {
    border-color: #ffc94a;
}
