/* ===========================================================================
   สตอรี่ — แถบบนโปรไฟล์ + ตัวชมเต็มจอ (ระยะ 13)
   =========================================================================== */

/* ---- แถบสตอรี่บนโปรไฟล์ ---- */
.story-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 12px;
    overflow-x: auto;
}

.story-ring {
    position: relative;
    flex-shrink: 0;
    width: 66px;
    height: 66px;
    border-radius: 50%;
    padding: 0;
    background: none;
    border: 3px solid var(--mes-line, #2a2a2e);
    cursor: pointer;
    overflow: visible;
}
/* ยังไม่ดู = วงแหวนทองสว่าง / ดูแล้ว = จาง */
.story-ring.has-unseen { border-color: var(--mes-gold, #d4af37); }
.story-ring.seen { border-color: #4a4a50; }

.story-ring img,
.story-ring-initial {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1c1c20;
    color: var(--mes-gold, #d4af37);
    font-size: 1.5rem;
    border: 2px solid #0c0c0e;
}
.story-ring-count {
    position: absolute;
    bottom: -2px;
    right: -2px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 9px;
    background: var(--mes-gold, #d4af37);
    color: #0c0c0e;
    font-size: .68rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #0c0c0e;
}

.story-add-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--mes-text-dim, #a1938c);
    font-family: inherit;
}
.story-add-plus {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 2px dashed var(--mes-gold-dim, #8a7128);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    color: var(--mes-gold, #d4af37);
    line-height: 1;
}
.story-add-label { font-size: .72rem; }

/* ---- ตัวชมเต็มจอ ---- */
.story-viewer-overlay {
    position: fixed;
    inset: 0;
    z-index: 200000;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.story-stage {
    max-width: 500px;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.story-stage img,
.story-stage .fx-frame {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* แถบความคืบหน้าด้านบน (ขีดละสตอรี่) */
.story-progress {
    position: absolute;
    top: 8px;
    left: 8px;
    right: 8px;
    z-index: 5;
    display: flex;
    gap: 4px;
}
.story-progress-bar {
    flex: 1;
    height: 3px;
    border-radius: 2px;
    background: rgba(255, 255, 255, .3);
    overflow: hidden;
}
.story-progress-bar span {
    display: block;
    height: 100%;
    width: 0;
    background: #fff;
}

.story-close {
    position: absolute;
    top: 16px;
    right: 14px;
    z-index: 10;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, .4);
    color: #fff;
    font-size: 1.2rem;
    cursor: pointer;
}

/* โซนแตะซ้าย/ขวา — ครึ่งจอละฝั่ง */
.story-tap {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 35%;
    z-index: 3;
    cursor: pointer;
}
.story-tap-left { left: 0; }
.story-tap-right { right: 0; }

/* ===========================================================================
   [แก้รอบใหม่ ข้อ 2] วงแหวนสตอรี่รอบรูปโปรไฟล์ — แบบ "หลอดพลัง" นับถอยหลัง 24 ชม.
   ===========================================================================
   เต็มวง = เพิ่งโพสต์สตอรี่ / ค่อย ๆ ลดลงตามเวลาที่ผ่านไปจนหมดใน 24 ชม.
   องศาที่เหลือคำนวณจาก PHP ส่งมาทาง --story-remain (เช่น 270deg = เหลือ 18 ชม.)

   ใช้ conic-gradient วาดส่วนโค้ง แล้วเจาะรูตรงกลางด้วย mask ให้เป็นวงแหวนบาง ๆ
   ไม่ใช้ SVG เพราะแบบนี้ไม่ต้องแตะ HTML เพิ่มและปรับความหนาได้ที่เดียว
   =========================================================================== */
.mpc-avatar-box.has-story { cursor: pointer; }

.mpc-story-ring {
    position: absolute;
    /* กางออกนอกกรอบรูปโปรไฟล์เล็กน้อย ให้วงแหวนลอยรอบไม่ทับตัวรูป */
    inset: -7px;
    border-radius: 50%;
    z-index: 1;
    pointer-events: none;

    background: conic-gradient(
        from -90deg,
        var(--mes-gold, #d4af37) 0deg,
        #f0d98a var(--story-remain, 360deg),
        rgba(212, 175, 55, .12) var(--story-remain, 360deg) 360deg
    );

    /* เจาะกลางให้กลายเป็นวงแหวน (หนา 4px)
       ⚠️ ต้องระบุ closest-side — ถ้าเขียน circle เฉย ๆ เบราว์เซอร์จะใช้ farthest-corner
       ทำให้ 100% = ระยะถึงมุมกล่อง (ไกลกว่าขอบวงกลมราว 1.41 เท่า) รูที่เจาะจึงเล็กเกินไป
       และวงแหวนกลายเป็นแผ่นวงกลมทึบแทนที่จะเป็นเส้นขอบบาง ๆ */
    mask: radial-gradient(closest-side circle, transparent calc(100% - 4px), #000 calc(100% - 4px));
    -webkit-mask: radial-gradient(closest-side circle, transparent calc(100% - 4px), #000 calc(100% - 4px));
}

/* ยังไม่ได้ดู = เรืองแสงนิดหน่อยให้สะดุดตา (ดูแล้วจะเงียบลง) */
.mpc-avatar-box.story-unseen .mpc-story-ring {
    filter: drop-shadow(0 0 5px rgba(212, 175, 55, .55));
}

/* รูปโปรไฟล์ต้องอยู่เหนือวงแหวน ไม่ให้วงแหวนทับหน้าคน */
.mpc-avatar-box .mpc-avatar-img { position: relative; z-index: 2; }
.mpc-avatar-box .mpc-change-avatar-btn { z-index: 3; }

/* ===========================================================================
   [เพิ่มตามที่สั่ง ข้อ 6] แถบสตอรี่หน้าฟีด — การ์ดแนวนอนแบบเฟซบุ๊ก
   =========================================================================== */
.story-tray {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 4px 2px 10px;
    scrollbar-width: none;
}
.story-tray::-webkit-scrollbar { display: none; }

.story-tray-card {
    position: relative;
    flex: 0 0 108px;
    height: 190px;
    border-radius: 12px;
    overflow: hidden;
    border: none;
    padding: 0;
    cursor: pointer;
    background: #1c1c20;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    font-family: inherit;
}

/* พื้นหลัง = รูปสตอรี่ล่าสุดของคนนั้น (ลิงก์ตรง ไม่มีไฟล์บนเซิร์ฟเวอร์) */
.story-tray-bg {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
}
/* ไล่เฉดดำด้านล่างให้ชื่ออ่านออกแม้รูปสว่าง */
.story-tray-card::after {
    content: '';
    position: absolute;
    left: 0; right: 0; bottom: 0;
    height: 60%;
    background: linear-gradient(to bottom, transparent, rgba(0, 0, 0, .75));
}

.story-tray-avatar {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    overflow: hidden;
    border: 3px solid #4a4a50;   /* ดูแล้ว = เทา */
    background: #101013;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}
/* ยังไม่ดู = ขอบทอง (กติกาเดียวกับวงแหวนบนโปรไฟล์) */
.story-tray-card.has-unseen .story-tray-avatar { border-color: var(--mes-gold, #d4af37); }
.story-tray-avatar img { width: 100%; height: 100%; object-fit: cover; }
.story-tray-initial { color: var(--mes-gold, #d4af37); font-size: .9rem; }

.story-tray-name {
    position: relative;
    z-index: 2;
    padding: 6px 8px;
    color: #fff;
    font-size: .72rem;
    text-align: left;
    line-height: 1.25;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* การ์ดแรก "สร้างสตอรี่" — ไม่มีรูปพื้นหลัง */
.story-tray-add {
    background: var(--mes-bg-card, #141416);
    border: 1px dashed rgba(212, 175, 55, .4);
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.story-tray-add::after { display: none; }
.story-tray-plus {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(212, 175, 55, .12);
    color: var(--mes-gold, #d4af37);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
}
.story-tray-add .story-tray-name { text-align: center; color: var(--mes-gold, #d4af37); }

/* ===========================================================================
   แผงดูรูปเต็มจอในหน้าอัลบั้ม
   =========================================================================== */
.album-viewer {
    position: fixed;
    inset: 0;
    z-index: 200010;
    background: rgba(0, 0, 0, .92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 20px;
}
.album-viewer[hidden] { display: none; }
.album-viewer img { max-width: 100%; max-height: 78vh; object-fit: contain; border-radius: 8px; }
.album-viewer-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, .12);
    color: #fff;
    font-size: 1.2rem;
    cursor: pointer;
}
.album-viewer-music {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    color: #6ee7b7;
    font-size: .82rem;
}
.album-viewer-music[hidden] { display: none; }
.album-viewer-music audio { height: 36px; }
.album-cell.is-viewable { cursor: pointer; }

/* แถบสตอรี่บนหน้าโปรไฟล์ — ใช้การ์ดหน้าตาเดียวกับหน้าฟีด แค่เตี้ยลงเล็กน้อย */
.story-tray-profile {
    padding: 10px 12px 6px;
    border-bottom: 1px solid var(--mes-line, #2a2a2e);
}
.story-tray-profile .story-tray-card { height: 160px; flex-basis: 96px; }

.story-tray-empty {
    display: flex;
    align-items: center;
    color: var(--mes-text-mute, #6f6360);
    font-size: .78rem;
    padding: 0 8px;
}

/* กันภาพในตัวชมสตอรี่ล้นจนมองไม่เห็น (เคยเจอจอดำ) */
.story-stage img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}

/* ปุ่มลบสตอรี่ (โผล่เฉพาะสตอรี่ของตัวเอง) */
.story-delete {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    padding: 8px 16px;
    border-radius: 999px;
    border: 1px solid rgba(239, 68, 68, .6);
    background: rgba(0, 0, 0, .55);
    color: #fca5a5;
    font-size: .82rem;
    font-family: inherit;
    cursor: pointer;
}
.story-delete[hidden] { display: none; }

/* ==========================================================================
   ⭐ [เพิ่มใหม่] รายชื่อคนที่เข้ามาดูสตอรี่ (ลากขึ้น) — เฉพาะสตอรี่ของตัวเอง
   ========================================================================== */
.story-viewers-hint {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    z-index: 12;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 10px 0 16px;
    color: #fff;
    font-size: .8rem;
    background: linear-gradient(to top, rgba(0,0,0,.6), transparent);
    cursor: pointer;
    user-select: none;
}
.story-viewers-arrow {
    font-size: 1.1rem;
    line-height: 1;
    animation: svHintBounce 1.8s ease-in-out infinite;
}
@keyframes svHintBounce {
    0%, 100% { transform: translateY(0); opacity: .7; }
    50%      { transform: translateY(-5px); opacity: 1; }
}

/* แผงรายชื่อ — เลื่อนขึ้นมาจากด้านล่าง */
.story-viewers-sheet {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    z-index: 20;
    max-height: 62%;
    display: flex;
    flex-direction: column;
    background: #14100f;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    box-shadow: 0 -8px 30px rgba(0,0,0,.6);
    animation: svSheetUp .22s ease-out;
}
@keyframes svSheetUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}
.story-viewers-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid #2a2a2e;
    color: var(--gold-soft, #f0d98a);
    font-weight: 700;
    font-size: .88rem;
    flex-shrink: 0;
}
.story-viewers-close {
    background: none;
    border: 0;
    color: var(--text-mute, #9a938d);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0 4px;
}
.story-viewers-list {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 6px 0 14px;
}
.story-viewers-empty {
    padding: 26px 14px;
    text-align: center;
    color: var(--text-mute, #9a938d);
    font-size: .82rem;
}

.story-viewer-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
}
.story-viewer-avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    object-fit: cover;
    background: #2a2a2e;
    flex-shrink: 0;
}
.story-viewer-name {
    flex: 1;
    color: #ece5e0;
    font-size: .86rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.story-viewer-addfriend {
    flex-shrink: 0;
    font: inherit;
    font-size: .76rem;
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid var(--gold, #d4af37);
    background: rgba(212,175,55,.12);
    color: var(--gold-soft, #f0d98a);
    cursor: pointer;
}
.story-viewer-addfriend:disabled { opacity: .5; cursor: default; }
.story-viewer-isfriend {
    flex-shrink: 0;
    font-size: .76rem;
    color: #22c55e;
}
