/* สไตล์พื้นฐาน — ต้องอยู่ก่อน Tailwind (ใน <head>)
   ย้ายออกมาจาก index.html — ห้ามเปลี่ยนลำดับกฎในไฟล์นี้
   แก้ไฟล์นี้แล้วต้องบวกเลข ?v= ใน index.html ด้วย */

        :root { --bg-reader: #fcfaf7; --text-reader: #2d2d2d; --watermark-color: rgba(0,0,0,0.08);
                /* 🎨 โทนพรีเซ็ตหน้าตาใหม่ (26 ต.ค. 2569) — โหมดกลางคืนทับค่าใน app.css (html.night) */
                --bg: #f7f6fb; --card: #ffffff; --line: #e9e6f3; --muted: #6b6785; --text: #1c1638; }
        body { font-family: 'Sarabun', sans-serif; background-color: var(--bg); color: var(--text); -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none; }
        .font-title, .font-head { font-family: 'Kanit', 'Sarabun', sans-serif; font-weight: 600; letter-spacing: -.005em; }
        .card { background: var(--card); border: 1px solid var(--line); }
        .muted { color: var(--muted); }
        .line { border-color: var(--line); }
        #content-area { max-width: 750px; margin: 0 auto; line-height: 2.3; font-size: 1.3rem; position: relative; z-index: 10; }
        .watermark-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(5, 1fr); gap: 20px; padding: 20px; opacity: 0.5; }
        .watermark-text { font-size: 10px; color: var(--watermark-color); transform: rotate(-15deg); text-align: center; white-space: nowrap; font-family: sans-serif; }
        /* การ์ดนิยายหน้าแรก — ขอบ+เงาเห็นชัดตลอด (มือถือไม่มี hover ให้เห็นกรอบ)
           ยกการ์ด/ขยายปกเฉพาะอุปกรณ์ที่ชี้เมาส์ได้จริง ไม่งั้นมือถือแตะแล้วค้างสถานะ hover */
        .novel-card { transition: transform 0.35s cubic-bezier(0.165, 0.84, 0.44, 1), box-shadow 0.35s ease, border-color 0.2s ease;
                      background: var(--card); border: 1px solid var(--line); border-radius: 1rem; padding: 10px; position: relative;
                      box-shadow: 0 1px 2px rgb(28 22 56 / 0.04); }
        .novel-cover { border: 1px solid rgb(15 23 42 / 0.06); }
        @media (hover: hover) {
            .novel-card:hover { transform: translateY(-2px); border-color: #cfc9ec; box-shadow: 0 12px 28px -16px rgb(28 22 56 / 0.45); }
            .novel-card:hover .novel-cover img { transform: scale(1.05); }
        }
        .edit-overlay { position: absolute; top: 8px; right: 8px; opacity: 0; transition: opacity 0.3s ease; z-index: 20; }
        .novel-card:hover .edit-overlay { opacity: 1; }
        .sticky-header { position: sticky; top: 0; z-index: 50; background: rgba(255, 255, 255, 0.9); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
        .reader-container { background-color: var(--bg-reader); color: var(--text-reader); min-height: 100vh; transition: all 0.3s; position: relative; overflow-x: clip; }
        /* ซ่อนแถบเลื่อน (ใช้ตอนปัดแถบเครื่องมือบนมือถือ) */
        .scrollbar-hide::-webkit-scrollbar { display: none; }
        .scrollbar-hide { -ms-overflow-style: none; scrollbar-width: none; }
        /* กันไม่ให้ปุ่มในแถบเครื่องมือถูกบีบจนเพี้ยน เวลาปัดเลื่อนบนมือถือ */
        #reader-tools-wrapper > * { flex-shrink: 0; }
        /* 🍞 Toast */
        .toast-item { transform: translateY(-16px); opacity: 0; transition: all .35s cubic-bezier(.2,.8,.2,1); white-space: pre-line; }
        .toast-item.toast-show { transform: translateY(0); opacity: 1; }
        .toast-item.toast-hide { transform: translateY(-16px); opacity: 0; }
        @keyframes confirmPop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
        .hidden { display: none !important; }
        /* แถบเครื่องมืออ่านนิยาย (เปลี่ยนสีตาม Theme อัตโนมัติ) */
        .reader-toolbar { background-color: var(--bg-reader); color: var(--text-reader);box-shadow: 0 4px 15px rgba(0,0,0,0.08);opacity: 0.95; }
        .reader-toolbar-divider {width: 1px;height: 14px; background-color: var(--text-reader); opacity: 0.2; margin: 0 4px; }
        /* --- Admin Editor Styles --- */
        #admin-editor-container { background: white; border-radius: 1.5rem; border: 1px solid #e2e8f0; overflow: hidden; }
        #rich-editor-toolbar { background: #f8fafc; border-bottom: 1px solid #e2e8f0; padding: 10px; display: flex; flex-wrap: wrap; gap: 6px; position: sticky; top: 0; z-index: 20; }
        #rich-editor-toolbar button { background: white; border: 1px solid #cbd5e1; border-radius: 8px; padding: 6px 12px; font-size: 13px; cursor: pointer; transition: 0.2s; display: flex; align-items: center; justify-content: center; min-width: 40px; height: 40px; }
        #rich-editor-toolbar button:hover { background: #f1f5f9; border-color: #94a3b8; }
        #rich-editor-content { padding: 30px; min-height: 500px; outline: none; line-height: 2; font-size: 1.1rem; color: #1e293b; -webkit-user-select: text; user-select: text; }
        #rich-editor-content hr { border: none; border-top: 2px dashed #cbd5e1; margin: 2em 0; }
        #rich-editor-content blockquote { border-left: 4px solid #cbd5e1; padding-left: 1rem; color: #64748b; font-style: italic; }

        

/* คอนเทนเนอร์สำหรับปุ่มลอยเฉพาะ 2 ปุ่มนี้ */
/* ปุ่มลอยแบบ Fixed เกาะติดหน้าจอ */
.floating-tools {
    position: fixed;    /* เปลี่ยนจาก sticky เป็น fixed */
    top: 20px;          /* ระยะห่างจากขอบบนจอ (ปรับตามความชอบ) */
    right: 20px;        /* ระยะห่างจากขอบขวาจอ */
    z-index: 9999;      /* ให้อยู่บนสุดเหนือทุกอย่าง */
    display: flex;
    flex-direction: column; 
    gap: 10px;
}

.floating-tools button {
    width: 50px;
    height: 50px;
    border-radius: 50%; /* ทำเป็นปุ่มกลมเพื่อให้ดูเป็น Floating Action Button */
    background: #fbbf24; /* สีส้ม Amber */
    color: white;
    border: none;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    font-size: 20px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    align-items: center;
    justify-content: center;
}

.floating-tools button:hover {
    transform: scale(1.1) rotate(5deg);
    background: #f59e0b;
}

.floating-tools button:active {
    transform: scale(0.9);
}
/* =========================
📌 Reader Floating Navigation
========================= */
.reader-floating-nav {
    position: fixed;
    right: 15px;
    bottom: 100px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 9999;
}

.reader-floating-nav button {
    background: #1e293b;
    color: white;
    padding: 12px 14px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: bold;
    box-shadow: 0 5px 15px rgba(0,0,0,0.25);
}

/* =========================
📌 Table of Contents
========================= */
.toc-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 9999;
    display: none;
}

.toc-box {
    background: white;
    max-width: 500px;
    margin: 50px auto;
    border-radius: 20px;
    padding: 20px;
    max-height: 80vh;
    overflow-y: auto;
}

.toc-item {
    padding: 10px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
}

.toc-item.read {
    color: #94a3b8;
    opacity: 0.7;
}

.toc-item.lock {
    color: #ccc;
    cursor: not-allowed;
}
/* =========================
📚 TOC PRO UX
========================= */

.toc-item {
    padding: 12px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* hover */
.toc-item:hover {
    background: #f8fafc;
}

/* อ่านแล้ว */
.toc-item.read {
    color: #94a3b8;
}

/* ตอนปัจจุบัน */
.toc-item.current {
    background: #fef3c7;
    font-weight: bold;
    border-left: 4px solid #f59e0b;
}

/* badge */
.toc-badge {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 999px;
    font-weight: bold;
}

.badge-read {
    background: #e2e8f0;
    color: #475569;
}

.badge-current {
    background: #f59e0b;
    color: white;
}

.badge-latest {
    background: #10b981;
    color: white;
}

/* progress */
.toc-progress {
    height: 6px;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 10px;
}

.toc-progress-bar {
    height: 100%;
    background: #10b981;
}
/* ===== PRO UX ADD-ON ===== */

/* highlight ตอนล่าสุดที่อ่าน */
.episode-last-read {
    border: 2px solid #f59e0b !important;
    background: #fef3c7 !important;
}

/* bookmark icon */
.bookmark-btn {
    position: fixed;
    bottom: 90px;
    left: 20px;
    z-index: 9999;
    background: #1e293b;
    color: white;
    width: 48px;
    height: 48px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 18px rgba(0,0,0,.25);
    cursor: pointer;
    transition: .2s;
}
.bookmark-btn.active {
    background: #f59e0b;
}
/* อ่านแล้ว */
.episode-read {
    background: #f1f5f9 !important;
    color: #94a3b8;
}

/* badge ✔ */
.episode-read::after {
    content: " ✔";
    font-size: 11px;
}

/* ตอนล่าสุดที่อ่าน */
.episode-current {
    background: #fef3c7 !important;
    border: 2px solid #f59e0b !important;
    color: #92400e;
}
.notice-wrapper {
    overflow: hidden;
    position: relative;
    width: 100%;
}

/* ✅ CSS ใหม่สำหรับ Fade */
.notice-wrapper {
    position: relative;
    width: 100%;
    height: 24px; /* กำหนดความสูงให้คงที่ */
    overflow: hidden;
}

.notice-text {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    opacity: 0; /* เริ่มต้นซ่อนไว้ */
    transition: opacity 1s ease-in-out; /* กำหนดความนุ่มนวลตอนเฟด */
    font-size: 13px;
    color: #b45309;
    white-space: nowrap;
    text-overflow: ellipsis; /* ถ้าเวลายาวเกินให้ขึ้น ... */
    overflow: hidden;
    text-align: center; /* จัดกลางสวยๆ */
}

/* คลาสสำหรับสั่งให้โชว์ */
.notice-text.show {
    opacity: 1;
}

/* ลบ Gradient เก่าออกเพราะไม่ต้องใช้แล้ว */
.notice-wrapper::before,
.notice-wrapper::after {
    display: none;
}
.notice-wrapper::before,
.notice-wrapper::after {
    content: "";
    position: absolute;
    top: 0;
    width: 40px;
    height: 100%;
    z-index: 2;
}

.notice-wrapper::before {
    left: 0;
    background: linear-gradient(to right, #fef3c7, transparent);
}

.notice-wrapper::after {
    right: 0;
    background: linear-gradient(to left, #fef3c7, transparent);
}
.notice-wrapper:hover .notice-text {
    animation-play-state: paused;
}
.ep-num {
    font-size: 13px;
    opacity: 0.6;
    color: var(--text-reader);
}

.ep-name {
    font-size: 26px;
    font-weight: bold;
    color: var(--text-reader);
}
/* ===== FAB MENU ===== */
.fab-container{
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 9999;
}

.fab-main{
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #f59e0b;
    color: white;
    font-size: 26px;
    border: none;
    box-shadow: 0 8px 20px rgba(0,0,0,0.25);
    cursor: pointer;
    transition: 0.3s;
}

.fab-main.open{
    transform: rotate(45deg);
    background: #ef4444;
}

.fab-action{
    position: absolute;
    right: 0;
    bottom: 0;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: #1e293b;
    color: white;
    border: none;
    font-size: 18px;
    cursor: pointer;
    opacity: 0;
    transform: scale(0.5);
    transition: all 0.25s ease;
    pointer-events: none;
}

.fab-container.open .fab-action{
    opacity: 1;
    pointer-events: auto;
}

.fab-container.open .fab-action:nth-child(1){
    transform: translateY(-70px);
}
.fab-container.open .fab-action:nth-child(2){
    transform: translateY(-130px);
}
.fab-container.open .fab-action:nth-child(3){
    transform: translateY(-190px);
}

/* 🔥 กันปุ่มบังเนื้อหา */
#content-area{
    padding-bottom: 140px;
}
#fabMenu{
    transition: opacity 0.3s ease;
}
/* 🔴 สไตล์จุดแจ้งเตือนตอนใหม่ */
/* 🔖 คานไม้ใต้ชั้นหนังสือ */
.shelf-plank {
    border-bottom: 6px solid #ba7517;
    border-radius: 2px;
    box-shadow: 0 3px 6px -2px rgba(186, 117, 23, 0.35);
}

.update-badge {
    position: absolute;
    /* ซ้ายบนของปก (การ์ดมี padding 7px) ไม่ชนปุ่มเก็บเข้าชั้นขวาบน */
    top: 14px;
    left: 14px;

    background-color: #ef4444;
    color: white;
    font-size: 9px;
    font-weight: 800;
    line-height: 1.5;
    padding: 1px 7px;
    border-radius: 99px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.25);

    z-index: 30;
    pointer-events: none; /* เพื่อให้ยังกดคลิกที่รูปข้างใต้ได้ */
    /* เลิกกะพริบ (pulse-red) — ป้ายที่ขยับได้ทุกใบพร้อมกันคือสิ่งที่ทำให้หน้าแรกดูแน่นที่สุด */
}

/* ⚠️ สำคัญมาก: เช็คที่ novel-card หรือตัวหุ้มรูป */
/* ถ้ามีการตั้งค่า overflow: hidden; ให้ลองขยับ badge มาไว้ในจุดที่ไม่โดนตัดครับ */

@keyframes pulse-red {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}
/* =========================
   🧹 บังคับลบขนาดอักษรแปลกปลอม (แก้ตัวหนังสือเล็กผิดปกติ)
   ========================= */
#content-area p, 
#content-area span, 
#content-area div, 
#content-area font,
#content-area a {
    font-size: inherit !important;
    font-family: inherit !important;
    line-height: inherit !important;
}

/* 📌 ยกเว้น: ถ้าแอดมินจงใจตั้งเป็นหัวข้อ (H3) อนุญาตให้ใหญ่ขึ้นได้ */
#content-area h3 {
    font-size: 1.3em !important;
    font-weight: bold !important;
    margin-top: 1.5em;
    margin-bottom: 0.5em;
}

/* 📌 ยกเว้น: กล่องคำพูด (Blockquote) ให้มีสไตล์ตามเดิม */
#content-area blockquote {
    font-size: inherit !important;
}
@keyframes coin-pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); color: #10b981; }
    100% { transform: scale(1); }
}
.coin-animate {
    animation: coin-pop 0.4s ease-out;
}
#toc-container {
    transition: opacity 0.5s ease, transform 0.3s ease;
    opacity: 0.3; /* ค่าเริ่มต้นให้จางไว้ก่อน */
}

/* เมื่อเมาส์ชี้ หรือมีการเลื่อน จะให้ชัดขึ้น */
#toc-container.active {
    opacity: 1;
}

/* =========================
   ✨ เอฟเฟกต์หน้าปกซูมเข้าออกช้าๆ
   ========================= */
@keyframes zoom-cover {
    0% { transform: scale(1); }
    50% { transform: scale(1.03); } /* ซูมเข้าแค่ 3% ให้ดูนุ่มนวล */
    100% { transform: scale(1); }
}
.animate-zoom-cover {
    /* ปรับเวลาเป็น 6 วินาที (จากเดิม 4s) เพื่อให้ช้าและสมูทที่สุด */
    animation: zoom-cover 20s ease-in-out infinite; 
}
