/*
 * =============================================
 * 🚀 1. กำหนดตัวแปรสี (Color Palette)
 * =============================================
 */
:root {
  /* --- Light Mode (Default) --- */
  --color-bg: #f0f0f0;            /* สีพื้นหลังเว็บ (เทาอ่อน) */
  --color-paper-bg: #ffffff;        /* สีหน้ากระดาษ (ขาว) */
  --color-text-primary: #222222;      /* สีตัวอักษรหลัก (ดำเข้ม) */
  --color-text-secondary: #555555;    /* สีตัวอักษรรอง (เทา) */
  --color-widget-bg: #ffffff;         /* สีพื้นหลัง Widget */
  --color-widget-header-bg: #f9f9f9;  /* สีหัว Widget */
  --color-border: #eeeeee;            /* สีเส้นขอบ */
  --color-fab: #2c3e50;            /* สีปุ่ม FAB (ใช้กับ active/toggle) */
  --color-fab-text: #ffffff;          /* สีตัวอักษร FAB */
  --color-slider-track: #e0e0e0;      /* สีราง Slider */
  --color-slider-thumb: #2c3e50;      /* สีปุ่ม Slider */
  
  --shadow-paper: 0 2px 8px rgba(0,0,0,0.1); 
  --shadow-widget: 0 6px 20px rgba(0,0,0,0.2);
  
  /* สีสำหรับปุ่ม Like */
  --color-like: #e53e3e; 
  --color-like-bg: #fee2e2; 

  /* สีสำหรับปุ่มโดเนท */
  --color-donate: #f97316; 
  --color-donate-text: #ffffff;
  --color-donate-icon-bg: #facc15; 
  --color-donate-icon-text: #ffffff;
  
  /* สี Danger สำหรับ Toast Error */
  --color-danger: #e53e3e;
}

html.dark {
  /* --- Dark Mode Overrides --- */
  --color-bg: #1a1a1a;            
  --color-paper-bg: #2b2b2b;        
  --color-text-primary: #e0e0e0;      
  --color-text-secondary: #aaaaaa;    
  --color-widget-bg: #333333;
  --color-widget-header-bg: #444444;
  --color-border: #555555;
  --color-fab: #4a90e2;            
  --color-fab-text: #ffffff;
  --color-slider-track: #555555;
  --color-slider-thumb: #4a90e2;      
  
  --shadow-paper: 0 2px 8px rgba(0,0,0,0.25);
  --shadow-widget: 0 6px 20px rgba(0,0,0,0.4);

  /* สี Like โหมดมืด */
  --color-like: #fc8181; 
  --color-like-bg: #4a2525; 

  /* สีโดเนท โหมดมืด */
  --color-donate: #fb923c; 
  --color-donate-text: #ffffff;
  --color-donate-icon-bg: #fde047; 
  --color-donate-icon-text: #f97316; 
}

/*
 * 2. ประกาศฟอนต์
 */
@font-face {
  font-family: 'RakNiyaiCloud';
  src: url('/assets/fonts/RakNiyaiCloud.woff2') format('woff2');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

/*
 * 3. Body และ H1
 */
html, body {
  font-family: 'RakNiyaiCloud', serif;
  background-color: var(--color-bg);
  color: var(--color-text-primary);
  margin: 0;
  padding: 0;
  padding-top: 50px; 
  transition: background-color 0.3s ease, color 0.3s ease;
}

h1 {
  color: var(--color-text-secondary);
  transition: color 0.3s ease;
  font-size: 1.6em; 
  margin-top: 15px;
  margin-bottom: 15px;
  line-height: 1.3;
  padding: 0 10px;
  text-align: center; /* จัดกลาง */
}

/*
 * 4. .novel-content
 */
.novel-content {
  width: 21cm;
  min-height: 29.7cm;
  margin: 30px auto 0 auto; 
  background-color: var(--color-paper-bg);
  box-shadow: var(--shadow-paper);
  padding: 2.5cm 2cm; 
  box-sizing: border-box; 
  
  white-space: pre-wrap;
  overflow-wrap: break-word;
  letter-spacing: 0.03em;
  
  font-size: var(--novel-font-size, 2.0em);
  line-height: var(--novel-line-height, 1.7);
  
  transition: font-size 0.1s ease-out, 
            line-height 0.1s ease-out,
            background-color 0.3s ease, 
            box-shadow 0.3s ease;
}

/*
 * 7. Widget Styles (Settings & Chapter List)
 */
#settings-widget,
#chapter-list-widget {
  position: fixed;
  top: 70px;
  right: 25px;
  width: 300px;
  background-color: var(--color-widget-bg);
  border-radius: 8px;
  box-shadow: var(--shadow-widget);
  z-index: 1001;
  overflow: hidden;
  
  visibility: visible;
  opacity: 1;
  transform: translateY(0);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275),
            background-color 0.3s ease;
}

#settings-widget.widget-hidden,
#chapter-list-widget.widget-hidden {
  visibility: hidden;
  opacity: 0;
  transform: translateY(-20px);
}

.widget-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 15px;
  background-color: var(--color-widget-header-bg);
  border-bottom: 1px solid var(--color-border);
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.widget-header h3 {
  margin: 0;
  font-size: 1.1em;
  color: var(--color-text-primary);
  transition: color 0.3s ease;
}

#close-widget-btn,
#close-chapter-widget-btn {
  background: none;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: var(--color-text-secondary);
  cursor: pointer;
  padding: 0 5px;
  transition: color 0.3s ease;
}
#close-widget-btn:hover,
#close-chapter-widget-btn:hover {
  color: var(--color-text-primary);
}

.widget-content {
  padding: 20px;
}

/*
 * 8. Styles for Sliders
 */
.slider-group {
  margin-bottom: 15px;
}

.slider-group label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.95em;
  color: var(--color-text-secondary);
  transition: color 0.3s ease;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  background: var(--color-slider-track);
  border-radius: 5px;
  outline: none;
  transition: background-color 0.3s ease;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  background: var(--color-slider-thumb);
  border-radius: 50%;
  cursor: pointer;
  margin-top: -2px; 
  transition: background-color 0.3s ease;
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background: var(--color-slider-thumb);
  border-radius: 50%;
  cursor: pointer;
  border: none;
  margin-top: -2px; 
  transition: background-color 0.3s ease;
}


/*
 * 9. Theme Switch
 */
.theme-switch-group {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  padding-top: 15px;
  border-top: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  font-size: 0.95em;
  transition: border-color 0.3s ease, color 0.3s ease;
}

.theme-switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
}

.theme-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--color-slider-track);
  border-radius: 34px;
  transition: background-color 0.3s ease;
}

.switch-slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  border-radius: 50%;
  transition: transform 0.3s ease, background-color 0.3s ease;
}

input:checked + .switch-slider {
  background-color: var(--color-fab);
}

input:checked + .switch-slider:before {
  transform: translateX(22px); 
}

/*
 * 10. Topbar
 */
.novel-topbar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 60px;
  background-color: var(--color-paper-bg); 
  box-shadow: var(--shadow-paper);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  box-sizing: border-box;
  z-index: 900;
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 15px;
  min-width: 150px; 
}
.topbar-left { justify-content: flex-start; }
.topbar-right { justify-content: flex-end; }
.topbar-center {
  flex-grow: 1;
  text-align: center;
  overflow: hidden;
}

.topbar-title {
  font-size: 1.1em;
  font-weight: bold;
  color: var(--color-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
  max-width: 100%;
}

.topbar-btn {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--color-text-secondary);
  padding: 8px;
  border-radius: 6px;
  transition: background-color 0.2s ease, color 0.2s ease;
  outline: none; 
  -webkit-tap-highlight-color: transparent; 
}

.topbar-btn:focus { outline: none; }

.topbar-btn:hover {
  background-color: var(--color-bg);
  color: var(--color-text-primary);
}

.topbar-btn svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
  flex-shrink: 0;
}

/*
 * =============================================
 * 🚀 ZEN MODE (ขยายเฉพาะเนื้อหานิยายแบบ Reader Mode)
 * =============================================
 */

/* 1. เมื่อเปิดโหมดนี้ ให้ซ่อน Scrollbar ของ Body หลัก */
body.zen-mode-on {
    overflow: hidden !important;
}

/* 2. แปลงร่าง novel-container ให้ยึดเต็มจอทับทุกอย่าง */
#novel-container.active-zen-mode {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 2000 !important; /* อยู่เหนือ Topbar และทุกอย่าง */
    
    margin: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    
    /* ให้ Scroll ได้ภายในตัวมันเอง */
    overflow-y: auto !important; 
    -webkit-overflow-scrolling: touch; /* ให้ลื่นบน iOS */
    
    /* จัด Padding ให้อ่านง่าย */
    padding: 20px 20px 80px 20px !important; /* padding บน-ซ้าย-ล่าง-ขวา */
    box-sizing: border-box !important;
    
    /* สีพื้นหลังต้องชัดเจน (ดึงจาก Theme) */
    background-color: var(--color-paper-bg) !important;
    color: var(--color-text-primary) !important;
}

/* 3. ดัน Sidebar (ปุ่มเมนูขวาล่าง) ให้ลอยเหนือเนื้อหา เพื่อให้กดยกเลิกได้ */
.floating-sidebar {
    z-index: 2100 !important; 
}

/* 4. ซ่อน Topbar และส่วนอื่นๆ ที่อาจจะลอยขึ้นมาบัง */
body.zen-mode-on .novel-topbar,
body.zen-mode-on .novel-pagination,
body.zen-mode-on .chapter-end-card,
body.zen-mode-on .comment-section {
    display: none !important;
}


/* * =============================================
 * 🚀 Mobile Ghost Button (ปุ่มออกจาก Fullscreen แบบจางๆ)
 * ============================================= 
 */
.mobile-zen-exit-btn {
    display: none; /* ซ่อนไว้ก่อนเป็นค่าเริ่มต้น */
    position: fixed;
    top: 15px;      /* ระยะห่างจากขอบบน */
    right: 15px;    /* ระยะห่างจากขอบขวา */
    z-index: 3000;  /* ต้องสูงกว่าเนื้อหา (2000) */
    
    background: transparent; /* ไม่มีพื้นหลัง */
    border: none;
    padding: 10px; /* เพิ่มพื้นที่สัมผัสให้กดยู่ง่ายขึ้น */
    
    color: var(--color-text-secondary); /* ใช้สีเดียวกับตัวอักษร */
    opacity: 0.3; /* 🚀 จางมากๆ (Ghost Style) */
    transition: opacity 0.3s ease;
    
    cursor: pointer;
    -webkit-tap-highlight-color: transparent; 
}

.mobile-zen-exit-btn svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
    filter: drop-shadow(0 0 2px rgba(255,255,255,0.5)); 
}

/* เมื่อแตะหรือ Hover ให้ชัดขึ้นนิดนึง */
.mobile-zen-exit-btn:active,
.mobile-zen-exit-btn:hover {
    opacity: 1; 
}

/* เงื่อนไขการแสดงผล: จอเล็ก + Zen Mode */
@media (max-width: 1024px) {
    body.zen-mode-on .mobile-zen-exit-btn {
        display: block; /* โชว์ปุ่มขึ้นมา */
        animation: fadeIn 0.5s ease; /* ค่อยๆ เฟดมา */
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 0.3; }
}


/*
 * 11. Chapter List Widget Style
 */
#chapter-list-widget .widget-content {
  padding: 0;
  max-height: 450px;
  overflow-y: auto;
}

.chapter-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.chapter-list li a {
  display: block;
  padding: 14px 20px;
  color: var(--color-text-secondary);
  text-decoration: none;
  border-bottom: 1px solid var(--color-border);
  transition: background-color 0.2s ease, color 0.2s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chapter-list li:last-child a {
  border-bottom: none;
}

.chapter-list li a:hover {
  background-color: var(--color-bg);
  color: var(--color-text-primary);
}

.chapter-list li a.active {
  color: var(--color-fab);
  font-weight: bold;
  background-color: var(--color-bg);
}

/*
 * 12. Pagination
 */
.novel-pagination {
  display: flex;
  width: 21cm;
  margin: 0 auto 0 auto; 
  background-color: var(--color-paper-bg); 
  border: 1px solid var(--color-slider-track);
  border-radius: 0 0 8px 8px; 
  box-sizing: border-box;
  transition: background-color 0.3s ease, border-color 0.3s ease;
  box-shadow: var(--shadow-paper); 
}

.novel-pagination a,
.novel-pagination span.disabled {
  flex: 1; 
  padding: 20px 25px;
  text-decoration: none;
  color: var(--color-text-secondary);
  transition: background-color 0.2s ease, color 0.2s ease;
  font-size: 1.1em;
  font-weight: 500;
}

.novel-pagination a.prev-chapter,
.novel-pagination span.disabled.prev-chapter {
  text-align: left;
  border-right: 1px solid var(--color-slider-track);
  transition: border-color 0.3s ease;
}

.novel-pagination a.next-chapter {
  text-align: right;
}

.novel-pagination span.disabled {
  color: var(--color-slider-track); 
  cursor: not-allowed;
}

.novel-pagination a:hover {
  background-color: var(--color-bg); 
  color: var(--color-text-primary);
}

/*
 * 13. Floating Sidebar
 */
.floating-sidebar {
    position: fixed;
    left: calc(50% + 410px); 
    bottom: 50px; 
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 950; 
}

@media (max-width: 1400px) {
    .floating-sidebar {
        left: auto;
        right: 20px;
    }
}

/* ซ่อนบนมือถือ/แท็บเล็ต (เพราะเกะกะ) */
@media (max-width: 1024px) {
    .floating-sidebar {
        display: none;
    }
}

.sidebar-btn {
    width: 50px;
    height: 50px;
    background-color: var(--color-paper-bg); 
    border: 1px solid var(--color-border);
    border-radius: 8px; 
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: var(--color-text-secondary);
    box-shadow: var(--shadow-paper);
    transition: all 0.2s ease;
    padding: 5px;
    box-sizing: border-box; 
}

.sidebar-btn svg {
    width: 22px; 
    height: 22px;
    fill: currentColor;
}

.sidebar-btn:hover {
    background-color: var(--color-bg);
    color: var(--color-fab); 
    transform: translateY(-2px);
}

/*
 * 14. Comment Section
 */
.comment-section {
    background-color: var(--color-paper-bg); 
    width: 21cm; 
    margin: 30px auto; 
    padding: 40px 0;
    border-radius: 8px; 
    box-shadow: var(--shadow-paper); 
    border-top: none; 
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.comment-container {
    padding: 0 2cm; 
    box-sizing: border-box;
}

.comment-header {
    font-size: 1.5em;
    color: var(--color-text-primary);
    margin-top: 0;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--color-border);
    transition: color 0.3s ease, border-color 0.3s ease;
}

/* Avatar Wrapper & Top Fan Badge */
.comment-avatar-wrapper {
    position: relative;
    flex-shrink: 0;
    margin-top: 5px;
    width: 40px;
    height: 40px;
}

.comment-avatar-wrapper .comment-avatar {
    width: 100%;
    height: 100%;
    margin-top: 0;
    border-radius: 50%;
    object-fit: cover;
}

.top-fan-badge {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    background-color: var(--color-paper-bg); 
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--color-border);
    z-index: 2;
}

.top-fan-badge svg {
    width: 12px;
    height: 12px;
    fill: #0ea5e9; 
}

.comment-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    margin-top: 5px; 
}

/* UI ฟอร์มความคิดเห็น */
.comment-form,
.reply-form {
    display: flex;
    gap: 15px; 
    align-items: flex-start; 
    margin-bottom: 35px; 
}

.comment-input-wrapper {
    flex-grow: 1;
    position: relative;
    display: flex; 
    flex-direction: column; 
    background-color: var(--color-bg); 
    border: 1px solid var(--color-border);
    border-radius: 16px; 
    transition: all 0.3s ease;
}

.comment-input-wrapper:focus-within {
    background-color: var(--color-paper-bg); 
    border-color: var(--color-border);
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

#comment-textarea,
.reply-textarea { 
    width: 100%;
    background-color: transparent; 
    border: none;
    outline: none; 
    padding: 15px 20px; 
    font-size: 1em; 
    font-family: 'RakNiyaiCloud', serif;
    color: var(--color-text-primary);
    resize: none; 
    overflow: hidden; 
    box-sizing: border-box;
    line-height: 1.5; 
    min-height: 50px; 
}

#comment-textarea::placeholder,
.reply-textarea::placeholder {
    color: var(--color-text-secondary);
    transition: color 0.3s ease;
}

.comment-input-footer {
    display: none; 
    justify-content: space-between;
    align-items: center;
    padding: 8px 15px;
    border-top: 1px solid var(--color-border);
    animation: fadeInFooter 0.2s ease-in-out; 
}

@keyframes fadeInFooter {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

.comment-input-wrapper:focus-within .comment-input-footer {
    display: flex;
}

.comment-tools-left {
    display: flex;
    gap: 8px;
}

.comment-tool-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    color: var(--color-text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.comment-tool-btn:hover {
    background-color: var(--color-bg); 
    color: var(--color-fab);
}

.comment-tool-btn svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
}

.comment-submit-btn-new {
    background: none;
    border: none;
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--color-slider-track); 
    transition: all 0.2s ease;
}

.comment-submit-btn-new svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.comment-submit-btn-new.enabled {
    background-color: var(--color-fab); 
    color: #ffffff; 
    transform: scale(1.05);
}

.comment-submit-btn-new.enabled:hover {
    opacity: 0.9;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.comment-list {
    display: flex;
    flex-direction: column;
    gap: 20px; 
}

.comment-item {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.comment-content {
    flex-grow: 1;
}

.comment-bubble {
    background-color: var(--color-bg); 
    border: 1px solid var(--color-border);
    border-radius: 18px; 
    padding: 10px 15px;
    position: relative;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.comment-author {
    font-weight: bold;
    color: var(--color-text-primary);
    font-size: 0.9em;
    margin-bottom: 2px;
    transition: color 0.3s ease;
}

.comment-text {
    margin: 0;
    color: var(--color-text-primary);
    line-height: 1.6;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    font-size: 0.95em; 
    transition: color 0.3s ease;
}

.comment-text-emojionly {
    font-size: 2.5em; 
    line-height: 1.3; 
    margin-top: 5px;
    margin-bottom: 5px;
}

.comment-reactions .reaction-icon {
    width: 18px;
    height: 18px;
    vertical-align: middle; 
}

.comment-reactions .reaction-icon-bg {
    fill: #3182CE; 
}

.comment-reactions .reaction-icon-fg {
    fill: #FFFFFF; 
}

.comment-reactions {
    position: absolute;
    bottom: -12px;
    right: 10px;
    background-color: var(--color-paper-bg); 
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 2px 6px;
    display: flex;
    align-items: center;
    gap: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    font-size: 0.8em;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.comment-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px; 
    margin-left: 15px; 
    font-size: 0.85em;
    color: var(--color-text-secondary);
}

.comment-action-btn {
    font-family: 'RakNiyaiCloud';
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    font-weight: bold;
    color: var(--color-text-secondary);
    transition: color 0.2s ease;

}

.comment-action-btn:hover {
    color: var(--color-text-primary);
    text-decoration: underline;
}

.comment-action-btn.active {
    color: var(--color-fab); 
}

.comment-time {
    font-weight: normal;
}

/*
 * 15. UI ตอบกลับ (Reply)
 */
.reply-form.hidden {
    display: none;
}

.reply-form {
    gap: 8px; 
    margin-top: 12px; 
    margin-bottom: 0; 
}

.reply-form .comment-avatar-wrapper {
    width: 32px;
    height: 32px;
}
.reply-form .comment-avatar {
    width: 32px;
    height: 32px;
    margin-top: 5px; 
}

.reply-textarea {
    min-height: 48px; 
    font-size: 0.9em; 
    padding: 12px 15px; 
}

.reply-form .comment-tool-btn svg {
    width: 20px;
    height: 20px;
}

.comment-replies {
    margin-top: 15px; 
    padding-left: 20px; 
    border-left: 2px solid var(--color-border); 
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.comment-item.is-reply .comment-avatar-wrapper {
    width: 32px;
    height: 32px;
}

.comment-item.is-reply .top-fan-badge,
.reply-form .top-fan-badge {
    width: 14px;
    height: 14px;
    bottom: -2px;
    right: -2px;
}

.comment-item.is-reply .top-fan-badge svg,
.reply-form .top-fan-badge svg {
    width: 10px;
    height: 10px;
}

.comment-item.is-reply .comment-avatar {
    width: 32px;
    height: 32px;
}

.comment-item.is-reply .comment-bubble {
    padding: 8px 12px; 
}
.comment-item.is-reply .comment-author {
    font-size: 0.85em; 
}
.comment-item.is-reply .comment-text {
    font-size: 0.9em; 
}

.comment-item.is-reply .comment-actions {
    font-size: 0.8em; 
    margin-top: 6px;
    margin-left: 12px;
}

.comment-item.is-reply .comment-reactions {
    bottom: -10px;
    font-size: 0.75em;
}


/*
 * 16. Dark Mode Overrides for Comments
 */
html.dark .comment-section {
    background-color: var(--color-paper-bg); 
    border-color: var(--color-border);
}

html.dark .comment-input-wrapper {
    background-color: var(--color-bg); 
    border-color: var(--color-border);
}

html.dark .comment-input-wrapper:focus-within {
    background-color: #333; 
}

html.dark .comment-tool-btn:hover {
    background-color: #444;
}

html.dark .comment-bubble {
    background-color: var(--color-bg); 
    border-color: var(--color-border);
}

html.dark .comment-reactions {
    background-color: var(--color-paper-bg);
    border-color: var(--color-border);
}

html.dark .comment-reactions .reaction-icon-bg {
    fill: #4a90e2; 
}
html.dark .comment-reactions .reaction-icon-fg {
    fill: #FFFFFF; 
}

/* * 17. ปุ่มลบ (Delete Button)
 */
.comment-delete-btn {
    position: absolute;
    top: 5px;   
    right: 8px; 
    width: 22px;
    height: 22px;
    background: none;
    border: none;
    padding: 0;
    
    font-size: 20px; 
    line-height: 1;
    color: var(--color-text-secondary); 
    cursor: pointer;
    
    opacity: 0;
    visibility: hidden;
    
    transition: opacity 0.2s ease, color 0.2s ease;
    z-index: 10; 
}

.comment-bubble:hover .comment-delete-btn {
    opacity: 1;
    visibility: visible;
}

.comment-delete-btn:hover {
    color: #e53e3e; 
    transform: scale(1.1);
}

.comment-bubble.is-editing {
    background-color: var(--color-paper-bg); 
    border-color: var(--color-fab);          
    box-shadow: 0 0 0 2px rgba(44, 62, 80, 0.1); 
    cursor: text;
}

.comment-text[contenteditable="true"] {
    outline: none; 
    min-height: 24px;
}

/*
 * 18. Chapter End Card (Like/Follow)
 */
.chapter-end-card {
    width: 21cm;
    margin: 30px auto; 
    background-color: var(--color-paper-bg);
    border-radius: 8px;
    box-shadow: var(--shadow-paper);
    padding: 25px 2.5cm; 
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 25px;
    align-items: stretch; 
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.chapter-end-card-top-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.chapter-author-promo {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-grow: 1; 
}

.author-avatar {
    width: 50px; 
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.author-details {
    display: flex;
    flex-direction: column;
}

.author-name {
    font-size: 1.1em;
    font-weight: bold;
    color: var(--color-text-primary);
    transition: color 0.3s ease;
}

.author-followers {
    font-size: 0.9em;
    color: var(--color-text-secondary);
    transition: color 0.3s ease;
}

.follow-btn {
    font-family: 'RakNiyaiCloud', serif;
    font-size: 0.9em;
    font-weight: bold;
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid var(--color-fab);
    color: var(--color-fab);
    background-color: transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0; 
}

.follow-btn:hover {
    background-color: var(--color-fab);
    color: var(--color-fab-text);
}


.follow-btn.following {
    background-color: var(--color-fab);
    color: var(--color-fab-text);
    border-color: var(--color-fab);
}
.follow-btn.following:hover {
    opacity: 0.9;
}

.chapter-like-action {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0; 
}

.like-btn {
    font-family: 'RakNiyaiCloud', serif;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 1.05em;
    font-weight: bold;
    border: 1px solid var(--color-slider-track);
    background-color: var(--color-bg);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.like-btn:hover {
    border-color: var(--color-like);
    color: var(--color-like);
}

.like-btn svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
    transition: all 0.2s ease;
}

.like-btn.liked {
    background-color: var(--color-like-bg);
    border-color: var(--color-like);
    color: var(--color-like);
}
.like-btn.liked .heart-icon-outline {
    display: none;
}
.like-btn.liked .heart-icon-filled {
    display: inline-block;
    transform: scale(1.1); 
}

.like-btn:not(.liked) .heart-icon-outline {
    display: inline-block;
}
.like-btn:not(.liked) .heart-icon-filled {
    display: none;
}


.like-count {
    font-size: 0.95em;
    color: var(--color-text-secondary);
    transition: color 0.3s ease;
}

.chapter-end-card-donate-row {
    display: flex;
    width: 100%;
}

.donate-btn-large {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 60%; 
    margin: 0 auto;
    padding: 14px 20px; 
    font-size: 1.1em;
    font-weight: bold;
    color: var(--color-donate-text);
    background-color: var(--color-donate);
    border: none;
    border-radius: 9999px; 
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'RakNiyaiCloud', serif;
    box-shadow: 0 4px 14px 0 rgba(249, 115, 22, 0.3); 
}

.donate-btn-large:hover {
    opacity: 0.9;
    transform: scale(1.01);
}

.donate-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background-color: var(--color-donate-icon-bg);
    color: var(--color-donate-icon-text);
    font-weight: bold;
    border-radius: 50%;
    font-size: 0.8em;
    line-height: 1;
    flex-shrink: 0;
}

/* Emoji Picker Styles */
.emoji-picker-widget {
    position: absolute;
    top: 0;
    transform: translateY(calc(-100% - 8px));
    left: 10px;
    z-index: 100;
}

.emoji-picker-widget.hidden {
    display: none;
}

/* GIPHY Picker Styles */
.gif-picker-container {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 500px;
    max-height: 70vh;
    background-color: var(--color-paper-bg);
    border-radius: 8px;
    box-shadow: var(--shadow-widget);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--color-border);
}

.gif-picker-container.hidden {
    display: none;
}

.gif-picker-header {
    display: flex;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid var(--color-border);
    gap: 10px;
}

#gif-search-input {
    flex-grow: 1;
    padding: 10px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background-color: var(--color-bg);
    color: var(--color-text-primary);
    font-family: 'RakNiyaiCloud', serif;
    font-size: 1em;
}
#gif-search-input:focus {
    outline: none;
    border-color: var(--color-fab);
}

#close-gif-picker-btn {
    background: none;
    border: none;
    font-size: 28px;
    line-height: 1;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: 0 5px;
}

.gif-grid-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
}

.gif-grid-content img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 4px;
    cursor: pointer;
    transition: transform 0.2s ease, opacity 0.2s ease;
}
.gif-grid-content img:hover {
    transform: scale(1.05);
    opacity: 0.9;
}

/* Loading Spinner */
#gif-loading-spinner {
    display: none; 
    margin: 40px auto;
    border: 4px solid var(--color-slider-track);
    border-top: 4px solid var(--color-fab);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ContentEditable (Rich Textarea) */
.rich-textarea {
    width: 100%;
    background-color: transparent; 
    border: none;
    outline: none;
    padding: 15px 20px;
    font-size: 1em; 
    font-family: 'RakNiyaiCloud', serif;
    color: var(--color-text-primary);
    resize: none; 
    box-sizing: border-box;
    line-height: 1.5;
    min-height: 50px;
    
    overflow-y: auto; 
    max-height: 200px; 
    
    cursor: text;
    white-space: pre-wrap; 
    word-wrap: break-word; 
}

.reply-form .rich-textarea {
    min-height: 48px;
    font-size: 0.9em;
    padding: 12px 15px;
}

.rich-textarea:empty::before {
    content: attr(data-placeholder);
    color: var(--color-text-secondary);
    pointer-events: none; 
}

.rich-textarea img {
    max-height: 120px !important; 
    width: auto !important; 
    max-width: 100%; 
    
    border-radius: 4px;
    margin: 4px 0;
    display: block; 
}

/* CSS ปุ่มเลื่อนตอนด้านข้าง */
.side-nav-btn {
    position: fixed;
    top: 50%; 
    transform: translateY(-50%);
    width: 40px;
    height: 60px; 
    background-color: rgba(255, 255, 255, 0.8); 
    border: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 90; 
    color: var(--color-text-secondary);
    border-radius: 8px; 
    transition: all 0.2s ease;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    text-decoration: none; 
}

.side-nav-btn:hover {
    background-color: var(--color-bg);
    color: var(--color-text-primary);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transform: translateY(-50%) scale(1.05); 
}

.side-nav-btn.prev { left: 10px; }
.side-nav-btn.next { right: 10px; }

.side-nav-btn svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
}

html.dark .side-nav-btn {
    background-color: rgba(40, 40, 40, 0.6);
    border-color: #444;
    color: #bbb;
}
html.dark .side-nav-btn:hover {
    background-color: #333;
    color: #fff;
}   


/*
 * =============================================
 * 🚀 (สำคัญ) Combined Media Query สำหรับจอเล็ก (มือถือ) - (รวมไว้ที่นี่)
 * =============================================
 */
@media (max-width: 820px) {

  /* --- 1. Novel Content --- */
  .novel-content {
    width: 100%;
    margin: 0;
    padding: 25px 20px 5px 20px; 
    box-shadow: none;
    box-sizing: border-box;
    border: none;
    font-size: var(--novel-font-size, 1.8em);
    line-height: var(--novel-line-height, 1.7);
  }

  h1 {
      font-size: 1.3em;
      margin-top: -5px;
      margin-bottom: 20px;
  }

  /* --- 2. Pagination --- */
  .novel-pagination {
    width: 100%;
    margin: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
    box-sizing: border-box; 
  }
  
  .novel-pagination a,
  .novel-pagination span.disabled {
    padding: 15px 20px;
    font-size: 0.95em;
  }
  
  /* --- 3. Comment Section --- */
  .novel-card, 
  .comment-section {
      width: 100% !important;
      margin: 0 !important;
      border-radius: 0 !important;
      box-shadow: none !important;
      border: none !important;
      padding: 30px 0 0 0; 
      box-sizing: border-box;
      margin-top: 0 !important; 
  }
  
  .comment-container {
      width: 100%;
      padding: 0 20px; 
      box-sizing: border-box; 
      border: none;
      padding-bottom: 20px; 
  }

  /* --- 4. Chapter End Card --- */
  .chapter-end-card {
      width: 100% !important;
      margin: 0 !important; 
      border-radius: 0 !important;
      box-shadow: none !important;
      border-top: 1px solid var(--color-slider-track) !important;
      border-bottom: 1px solid var(--color-slider-track) !important;
      border-left: none !important;
      border-right: none !important;
      padding: 30px 20px 10px 20px; 
      box-sizing: border-box;
      align-items: center;
  }
  
  .chapter-end-card-top-row {
      flex-direction: column;
      width: 100%;
      gap: 25px;
  }

  .chapter-author-promo {
      width: 100%; 
      justify-content: center;
      flex-wrap: nowrap;
      flex-direction: column;
      text-align: center;
      gap: 10px;
  }

  .author-details {
    align-items: center;
  }

  .chapter-like-action {
      width: 100%; 
      justify-content: center; 
  }
  .like-btn {
      flex-grow: 0;
  }

  .chapter-end-card-donate-row {
      width: 100%;
      justify-content: center;
  }

  .donate-btn-large {
      width: 90%;
      margin: 0 auto; 
  }

  /* --- 5. Topbar Adjustments --- */
  .topbar-title {
      display: none;
  }

  #topbar-settings-btn {
      display: inline-flex;
  }

  #topbar-settings-btn span {
      display: inline-block; 
  }
  
  /* (ปรับแต่งปุ่มปิดในมือถือ) */
  .donate-modal-close-btn,
  .tts-modal-close-btn {
      top: 10px;
      right: 10px;
      background-color: transparent;
      box-shadow: none;
  }

  .side-nav-btn {
      width: 30px;
      height: 50px;
      background-color: transparent;
      border: none;
      box-shadow: none;
  }
} 
/* 🚀 (สำคัญ) ปิดวงเล็บ Media Query ตรงนี้! ห้ามลืม! */


/*
 * =============================================
 * 🚀 19. (แก้ไขใหม่) สไตล์สำหรับ Donate Modal (Global)
 * =============================================
 */
.donate-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 2900;
    transition: opacity 0.3s ease;
}

.donate-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--color-paper-bg);
    border-radius: 16px;
    box-shadow: var(--shadow-widget);
    width: 90%;
    max-width: 400px;
    z-index: 3000;
    transition: opacity 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), 
                transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.donate-overlay.hidden,
.donate-modal.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.donate-modal.hidden {
    transform: translate(-50%, -40%) scale(0.95);
}

.donate-modal-close-btn,
.tts-modal-close-btn {
    position: absolute;
    top: -27px;
    right: -27px;
    background-color: var(--color-paper-bg);
    border-radius: 9999px;
    padding: 6px;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    color: var(--color-text-secondary);
    line-height: 1;
    cursor: pointer;
    transition: color 0.2s ease;
    z-index: 3001;
    border: none;
}

.donate-modal-close-btn:hover,
.tts-modal-close-btn:hover {
    color: var(--color-text-primary);
}

.donate-modal-close-btn svg,
.tts-modal-close-btn svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
}

.donate-modal-content {
    padding: 0 25px 25px 25px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-sizing: border-box;
}

.donate-modal-icon {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.2em;
    font-weight: bold;
    margin-bottom: 15px;
    background-color: #facc15;
    color: #ffffff;
}

html.dark .donate-modal-icon {
    background-color: #fde047;
    color: #f97316;
}

.donate-modal-title {
    font-size: 1.3em;
    color: var(--color-text-primary);
    margin-top: 0;
    margin-bottom: 20px;
    font-weight: bold;
}

/* Inputs */
.donate-input-group {
    width: 100%;
    margin-bottom: 20px;
    position: relative;
}

.donate-input-group label {
    display: block;
    font-size: 0.9em;
    color: var(--color-text-secondary);
    margin-bottom: 8px;
    font-weight: bold;
}

.donate-input-group input[type="text"],
.donate-input-group textarea {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background-color: var(--color-bg);
    color: var(--color-text-primary);
    font-family: 'RakNiyaiCloud', serif;
    font-size: 1em;
    box-sizing: border-box;
    outline: none;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.donate-input-group input:focus,
.donate-input-group textarea:focus {
    background-color: var(--color-paper-bg);
    border-color: var(--color-fab);
}

.donate-input-group textarea {
    resize: none;
}

.donate-coin-balance,
.donate-char-count {
    display: block;
    text-align: right;
    font-size: 0.85em;
    color: var(--color-text-secondary);
    margin-top: 8px;
}

/* Checkbox */
.donate-checkbox-group {
    width: 100%;
    display: flex;
    align-items: center;
    margin-bottom: 25px;
    font-size: 0.95em;
    color: var(--color-text-primary);
}

.custom-checkbox-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    gap: 10px;
    font-size: 1em;
    color: var(--color-text-primary);
}

.custom-checkbox-input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.custom-checkbox-box {
    width: 24px;
    height: 24px;
    background-color: var(--color-paper-bg);
    border: 2px solid var(--color-slider-track);
    border-radius: 6px;
    display: inline-block;
    position: relative;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.custom-checkbox-tick {
    width: 16px;
    height: 16px;
    color: #ffffff;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.custom-checkbox-input:checked + .custom-checkbox-box {
    background-color: var(--color-fab);
    border-color: var(--color-fab);
}

.custom-checkbox-input:checked + .custom-checkbox-box .custom-checkbox-tick {
    opacity: 1;
}

html.dark .custom-checkbox-box {
    background-color: var(--color-widget-bg);
    border-color: var(--color-border);
}

html.dark .custom-checkbox-input:checked + .custom-checkbox-box {
    background-color: var(--color-fab);
    border-color: var(--color-fab);
}

/* Submit Button */
.donate-submit-btn {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 9999px;
    background-color: var(--color-donate);
    color: var(--color-donate-text);
    font-size: 1.1em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: 'RakNiyaiCloud', serif;
}

.donate-submit-btn:hover {
    opacity: 0.9;
}

.donate-modal-icon-small {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7em;
    font-weight: bold;
    line-height: 1;
    background-color: var(--color-donate-icon-bg);
    color: var(--color-donate-icon-text);
}

.donate-modal-cancel-btn,
.tts-modal-cancel-btn {
    background: none;
    border: none;
    color: var(--color-text-secondary);
    font-size: 1em;
    font-weight: bold;
    margin-top: 15px;
    cursor: pointer;
    font-family: 'RakNiyaiCloud', serif;
    padding: 5px 10px;
}

.donate-modal-cancel-btn:hover,
.tts-modal-cancel-btn:hover {
    color: var(--color-text-primary);
}


/*
 * =============================================
 * 🚀 20. (แก้ไขใหม่) สไตล์สำหรับ TTS Modal (Global)
 * =============================================
 */
.tts-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 2900;
    transition: opacity 0.3s ease;
}

.tts-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--color-paper-bg);
    border-radius: 16px;
    box-shadow: var(--shadow-widget);
    width: 90%;
    max-width: 360px;
    z-index: 3000;
    transition: opacity 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), 
                transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.tts-overlay.hidden,
.tts-modal.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.tts-modal.hidden {
    transform: translate(-50%, -40%) scale(0.95);
}

.tts-modal-content {
    padding: 30px 25px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    min-height: 250px;
}

.tts-processing.hidden,
.tts-ready.hidden {
    display: none;
}

.tts-processing,
.tts-ready {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.tts-modal-title {
    font-size: 1.3em;
    color: var(--color-text-primary);
    margin-top: 0;
    margin-bottom: 25px;
    font-weight: bold;
}

.tts-modal-subtitle {
    font-size: 1.0em;
    color: var(--color-text-secondary);
    margin-top: 25px;
    margin-bottom: 0;
    transition: color 0.3s ease;
}

/* Audio Wave */
.audio-wave-container {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    height: 80px;
    gap: 6px;
    transition: opacity 0.3s ease;
}

.audio-wave-bar {
    width: 8px;
    height: 10px;
    background-color: var(--color-fab);
    border-radius: 4px;
    animation: wave-animation 1.2s ease-in-out infinite;
}

.audio-wave-bar:nth-child(2) { animation-delay: -1.0s; }
.audio-wave-bar:nth-child(3) { animation-delay: -0.8s; }
.audio-wave-bar:nth-child(4) { animation-delay: -0.6s; }
.audio-wave-bar:nth-child(5) { animation-delay: -0.4s; }
.audio-wave-bar:nth-child(6) { animation-delay: -0.2s; }
.audio-wave-bar:nth-child(7) { animation-delay: -0.0s; }

@keyframes wave-animation {
    0%   { height: 10px; opacity: 0.5; }
    50%  { height: 80px; opacity: 1.0; }
    100% { height: 10px; opacity: 0.5; }
}

/* TTS Play Button */
.tts-play-btn {
    width: 80px;
    height: 80px;
    background-color: var(--color-fab);
    color: var(--color-fab-text);
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 4px 14px 0 rgba(44, 62, 80, 0.3);
}

.tts-play-btn:hover {
    opacity: 0.9;
    transform: scale(1.05);
}

html.dark .tts-play-btn {
    box-shadow: 0 4px 14px 0 rgba(74, 144, 226, 0.3);
}

.tts-play-btn svg {
    width: 36px;
    height: 36px;
    fill: currentColor;
    margin-left: 5px;
}

/*
 * =============================================
 * 🚀 21. (แก้ไขใหม่) สไตล์สำหรับ TTS Progress Bar (Global)
 * =============================================
 */
.tts-progress-bar-container {
    width: 80%;
    height: 10px;
    background-color: var(--color-slider-track);
    border-radius: 5px;
    overflow: hidden;
    margin-top: 20px;
    transition: opacity 0.3s ease;
}

.tts-progress-bar-container.hidden {
    opacity: 0;
    pointer-events: none;
}

.tts-progress-bar-inner {
    width: 0%;
    height: 100%;
    background-color: var(--color-fab);
    border-radius: 5px;
    transition: width 0.5s ease-in-out;
}

.disabled-textarea {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #666;
    cursor: not-allowed;
    font-size: 14px;
}

/* * =============================================
 * 🚀 22. Toast Notification (Global)
 * =============================================
 */
#toast-container {
    position: fixed;
    top: 80px;
    right: 20px;
    z-index: 100000;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
}

.toast-item {
    background-color: var(--color-paper-bg);
    color: var(--color-text-primary);
    padding: 16px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-width: 300px;
    max-width: 380px;
    border-left: 5px solid transparent;
    pointer-events: auto;
    animation: toastSlideIn 0.3s ease forwards;
}

.toast-item.leaving {
    animation: toastFadeOut 0.3s ease forwards;
}

.toast-item.success {
    border-left-color: #28a745;
}
.toast-item.success .toast-icon {
    color: #28a745;
}

.toast-item.error {
    border-left-color: var(--color-danger);
}
.toast-item.error .toast-icon {
    color: var(--color-danger);
}

.toast-icon svg {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.toast-content {
    flex-grow: 1;
}

.toast-title {
    font-weight: bold;
    font-size: 1em;
    margin-bottom: 2px;
}

.toast-message {
    font-size: 0.9em;
    color: var(--color-text-secondary);
    line-height: 1.4;
}

@keyframes toastSlideIn {
    from { opacity: 0; transform: translateY(-30px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes toastFadeOut {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(-50px); }
}

/* * =============================================
 * 🚀 Immersive Mode (Fullscreen Overlay) 
 * =============================================
 */
.immersive-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--color-paper-bg); /* ใช้สีตามธีม (มืด/สว่าง) */
    z-index: 9999; /* ทับทุกอย่าง */
    overflow-y: auto; /* ให้เลื่อนดูเนื้อหาได้ */
    padding: 0;
    
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

/* คลาสสำหรับแสดงผล */
.immersive-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* กล่องเนื้อหาภายใน Overlay */
.immersive-content-wrapper {
    width: 100%;
    max-width: 900px; /* จำกัดความกว้างให้อ่านง่าย */
    margin: 0 auto;
    padding: 60px 20px 100px 20px; /* เว้นขอบบนล่างซ้ายขวา */
    box-sizing: border-box;
    
    /* ดึงค่าตัวแปร Font มาใช้ (จะถูก set ด้วย JS อีกที) */
    font-size: var(--novel-font-size, 2.0em);
    line-height: var(--novel-line-height, 1.7);
    color: var(--color-text-primary);
    
    white-space: pre-wrap;
    overflow-wrap: break-word;
    font-family: 'RakNiyaiCloud', serif;
}

/* แก้จาก . เป็น # เพื่อบังคับใช้กับ ID โดยตรง */
#immersive-exit-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    
    /* 🚀 บังคับลบค่า Default */
    background: transparent !important;
    background-color: transparent !important; /* ย้ำอีกที */
    border: none !important;
    box-shadow: none !important;
    
    width: 50px;
    height: 50px;
    
    /* จัดกึ่งกลาง */
    display: flex;
    align-items: center;
    justify-content: center;
    
    color: var(--color-text-secondary);
    cursor: pointer;
}

#immersive-exit-btn svg {
    width: 32px !important;
    height: 32px !important;
    fill: currentColor !important;
}

#immersive-exit-btn:hover {
    color: var(--color-text-primary);
    transform: scale(1.1);
}
/* Dark Mode Hover */
html.dark .immersive-exit-btn:hover {
    background-color: rgba(255, 255, 255, 0.1) !important;
}

/* 🚀 บังคับขนาดไอคอน SVG */
.immersive-exit-btn svg {
    width: 32px !important;
    height: 32px !important;
    fill: currentColor !important;
    pointer-events: none; /* ให้คลิกทะลุไปที่ปุ่ม */
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.2)); /* เพิ่มเงาให้ไอคอนนิดหน่อยให้เห็นชัดบนพื้นขาว */
}

/* ซ่อน Scrollbar ของ Overlay (Optional: ถ้าอยากให้สวยเนียน) */
.immersive-overlay::-webkit-scrollbar {
    width: 8px;
}
.immersive-overlay::-webkit-scrollbar-thumb {
    background-color: var(--color-slider-track);
    border-radius: 4px;
}

.immersive-chapter-block {
    display: flex;        /* ใช้ Flexbox เพื่อจัดการ Layout */
    flex-direction: column;
    width: 100%;
    
    /* 🚀 หัวใจสำคัญ: สั่งให้ทุกอย่างติดกันเป็นเนื้อเดียว */
    gap: 0;              
    margin: 0;
    padding: 0;
    border: none;
    
    /* ป้องกัน Line-height ของ Container ดันพื้นที่ */
    line-height: 0;
}



/* ปรับแต่งชื่อตอน (ลดขนาดลงตามที่คุณต้องการ) */
.immersive-chapter-title {
    margin: 0;           /* ลบ margin default ของ h1 */
    margin-bottom: 20px; /* ระยะห่างจากเนื้อหา */
    
    text-align: center;
    font-size: 1.2em;
    font-weight: bold;
    color: var(--color-text-secondary);
    line-height: 1.4;    /* คืนค่า line-height */
    display: block;
}

/* ปรับแต่งเนื้อหานิยายในโหมดนี้ */
.immersive-chapter-block .novel-content {
    /* 🚀 บังคับลบค่า Default ของคลาสเดิมทิ้งให้หมด */
    margin: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
    min-height: auto !important;
    
    /* คืนค่าการอ่านปกติ */
    line-height: var(--novel-line-height, 1.7) !important; 
    display: block;
}

.immersive-chapter-body {
    /* ใช้ Style เดียวกับ novel-content ปกติ */
    font-size: inherit; 
    line-height: inherit;
}

/* ปรับแต่งดาวคั่น */
.immersive-divider {
/* ถ้าอยากได้ระยะห่าง ให้ใส่ margin ตรงนี้แทน */
    margin-top: 40px;    /* ระยะห่างจากตอนบน */
    margin-bottom: 20px; /* ระยะห่างจากชื่อตอน */
    
    text-align: center;
    font-size: 1.2em;
    opacity: 0.5;
    line-height: normal; /* คืนค่า line-height ให้ตัวอักษร */
    display: block;      /* ป้องกัน space แปลกๆ ของ inline */
}

/* Loader ตอนโหลดตอนใหม่ */
.immersive-loader {
    text-align: center;
    padding: 20px;
    color: var(--color-text-secondary);
    font-style: italic;
}
.immersive-loader.hidden {
    display: none;
}















/* 🔒 Locked Gate Styles (Design Match) */
    .immersive-chapter-block.locked-gate-container {
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 60px 20px;
        min-height: 400px;
        background-color: transparent; /* พื้นหลังใส (เพื่อให้เห็นพื้นหลัง Reader) */
    }

    .locked-card {
        background-color: var(--color-paper-bg, #ffffff);
        border-radius: 12px;
        padding: 40px 30px;
        width: 100%;
        max-width: 500px;
        text-align: center;
        box-shadow: 0 4px 20px rgba(0,0,0,0.08); /* เงาบางๆ */
        display: flex;
        flex-direction: column;
        align-items: center;
        border: 1px solid var(--color-border, #eeeeee);
    }

    .locked-icon-circle {
        width: 60px;
        height: 60px;
        background-color: #fff9c4; /* สีเหลืองอ่อนพาสเทล */
        color: #fbc02d; /* สีเหลืองเข้ม */
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-bottom: 20px;
    }
    
    .locked-icon-circle svg {
        width: 28px;
        height: 28px;
    }

    .locked-title {
        font-size: 1.2em;
        font-weight: bold;
        color: var(--color-text-primary, #333);
        margin: 0 0 10px 0;
        line-height: 1.4;
    }

    .locked-price-text {
        font-size: 1.1em;
        color: #d97706; /* สีส้มทอง */
        font-weight: bold;
        margin-bottom: 25px;
        margin-top: 25px;
    }

    .btn-unlock-immersive-orange {
        background-color: #d97706; /* สีส้มตามรูป */
        color: #ffffff;
        border: none;
        border-radius: 12px; /* โค้งมน */
        padding: 16px 24px;
        font-size: 1.1em;
        font-weight: bold;
        cursor: pointer;
        width: 100%;
        transition: background-color 0.2s, transform 0.1s;
        font-family: inherit;
        box-shadow: 0 4px 6px rgba(217, 119, 6, 0.3);
    }

    .btn-unlock-immersive-orange:hover {
        background-color: #b45309; /* เข้มขึ้นเมื่อ Hover */
        transform: translateY(-1px);
    }
    
    .btn-unlock-immersive-orange:active {
        transform: translateY(1px);
        box-shadow: none;
    }

    /* Dark Mode Adjustment */
    html.dark .locked-card {
        background-color: #2d2d2d;
        border-color: #444;
        box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    }
    html.dark .locked-icon-circle {
        background-color: #423e20;
        color: #ffca28;
    }
    html.dark .locked-title {
        color: #e0e0e0;
    }
    html.dark .locked-price-text {
        color: #f59e0b;
    }

    .locked-actions {
        display: flex;
        flex-direction: column; /* เรียงแนวตั้งบนมือถือ */
        gap: 10px;
        width: 100%;
    }


    .btn-unlock-immersive-outline {
        background-color: transparent;
        color: #d97706; /* สีส้ม */
        border: 2px solid #d97706;
        border-radius: 12px;
        padding: 14px 20px;
        font-size: 1.1em;
        font-weight: bold;
        cursor: pointer;
        width: 100%;
        transition: all 0.2s;
        font-family: inherit;
    }

    .btn-unlock-immersive-outline:hover {
        background-color: #fff8e1; /* สีพื้นหลังอ่อนๆ เมื่อ hover */
        transform: translateY(-1px);
    }

    /* ปรับ Layout แนวนอนสำหรับจอใหญ่ */
    @media (min-width: 600px) {
        .locked-actions {
            flex-direction: row; /* เรียงแนวนอน */
        }
    }

    /* จัดกลุ่มปุ่ม */
    .locked-actions {
        display: flex;
        flex-direction: column; /* เรียงแนวตั้ง */
        gap: 15px;              /* 🚀 ระยะห่างระหว่างปุ่ม */
        width: 100%;
        margin-top: 10px;
    }

    /* (Optional) ถ้าจอใหญ่ อยากให้เรียงแนวนอน ให้ uncomment ด้านล่างนี้ */
    /* @media (min-width: 600px) {
        .locked-actions {
            flex-direction: row;
        }
    } 
    */

    /* Overlay (พื้นหลังดำจางๆ) */
    .unlock-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.6);
        z-index: 3100;
        transition: opacity 0.3s ease;
    }

    /* ตัว Modal (ลอกสไตล์ donate-modal) */
    .unlock-modal {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        background-color: var(--color-paper-bg, #ffffff);
        border-radius: 16px; /* ความโค้งเท่ากัน */
        box-shadow: var(--shadow-widget, 0 6px 20px rgba(0,0,0,0.2));
        width: 90%;
        max-width: 400px; /* ขนาดเท่ากัน */
        z-index: 3200;
        padding: 0; /* Padding จัดการใน content */
        text-align: center;
        transition: opacity 0.3s ease, transform 0.3s ease;
    }

    /* ซ่อน Modal */
    .unlock-overlay.hidden,
    .unlock-modal.hidden {
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
    }
    .unlock-modal.hidden {
        transform: translate(-50%, -40%) scale(0.95);
    }

    /* เนื้อหาข้างใน */
    .unlock-modal-content {
        padding: 30px 25px;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    /* ไอคอนวงกลมใหญ่ */
    .unlock-icon-wrapper {
        width: 70px;
        height: 70px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 2.2em;
        margin-bottom: 15px;
        background-color: var(--color-donate, #f97316); 
        color: #ffffff;
    }
    .unlock-icon-wrapper svg {
        width: 36px;
        height: 36px;
        fill: currentColor;
    }

    /* หัวข้อ */
    .unlock-title {
        font-size: 1.3em;
        font-weight: bold;
        color: var(--color-text-primary, #222);
        margin: 0 0 15px 0;
    }

    /* รายละเอียด */
    .unlock-desc {
        color: var(--color-text-secondary, #555);
        font-size: 1em;
        margin: 0 0 25px 0;
        line-height: 1.6;
    }
    .highlight-price {
        color: var(--color-donate, #f97316);
        font-weight: bold;
        font-size: 1.1em;
    }

    /* ปุ่มกด */
    .unlock-actions {
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .btn-confirm-unlock {
        width: 100%;
        padding: 14px;
        border: none;
        border-radius: 9999px; /* ทรงแคปซูล */
        background-color: var(--color-donate, #f97316);
        color: #ffffff;
        font-size: 1.1em;
        font-weight: bold;
        cursor: pointer;
        transition: opacity 0.2s ease;
        font-family: 'RakNiyaiCloud', serif;
    }
    .btn-confirm-unlock:hover {
        opacity: 0.9;
    }

    .btn-cancel-unlock {
        background: none;
        border: none;
        color: var(--color-text-secondary, #555);
        font-size: 1em;
        font-weight: bold;
        cursor: pointer;
        font-family: 'RakNiyaiCloud', serif;
        padding: 10px;
        margin-top: 5px;
    }
    .btn-cancel-unlock:hover {
        color: var(--color-text-primary, #222);
    }


    /* 🚀 ดันให้ Modal และ Overlay ของมัน อยู่สูงกว่า Immersive Mode */
    
    /* 1. ตัวพื้นหลังสีดำจางๆ ของ Modal */
    .unlock-overlay {
        z-index: 99990 !important; /* ค่าเดิมอาจจะแค่ 3100 ไม่พอ */
    }

    /* 2. ตัวกล่อง Modal */
    .unlock-modal {
        z-index: 99999 !important; /* ค่าสูงสุดๆ ให้ทับทุกอย่าง */
    }
    
    /* (แถม) ถ้ามี Buy All Modal ก็ต้องแก้ด้วย */
    #buy-all-modal {
        z-index: 99999 !important;
    }

    /* 📱 แก้ไข Responsive สำหรับมือถือ */
    @media (max-width: 600px) {
        
        /* 1. ปรับ Container หลักไม่ให้กว้างเกิน */
        .immersive-chapter-block.locked-gate-container {
            padding: 40px 15px; /* ลด Padding ด้านข้างเหลือ 15px */
            min-height: auto;   /* ไม่บังคับความสูง */
            width: 100%;        /* เต็มจอ */
            box-sizing: border-box; /* สำคัญ: รวม padding ใน width */
        }

        /* 2. ปรับการ์ดให้ยืดหยุ่น */
        .locked-card {
            width: 100%;
            max-width: 100%; /* ไม่ให้เกินจอ */
            padding: 30px 20px; /* ลด Padding ภายในการ์ด */
            box-sizing: border-box;
            margin: 0; /* ลบ margin ที่อาจจะดันออก */
        }

        /* 3. ปรับขนาดตัวหนังสือให้เล็กลงนิดหน่อย */
        .locked-title {
            font-size: 1.2em;
        }
        
        .locked-price-text {
            font-size: 1.0em;
            margin: 15px 0;
            margin-top: 25px;

        }

        /* 4. ปุ่มกดเต็มความกว้าง */
        .locked-actions {
            width: 100%;
        }
        
        .btn-unlock-immersive-orange,
        .btn-unlock-immersive-outline {
            width: 100%;
            padding: 12px;
            font-size: 1em;
        }
    }

    /* ... existing styles ... */
/* 🚀 Media Query สำหรับจอเล็ก (Mobile) */
@media (max-width: 768px) {
    /* ให้ Content เป็นจุดอ้างอิง */
    .tts-modal-content {
        position: relative !important;
        padding-top: 40px; /* เว้นที่ด้านบนไม่ให้ปุ่มทับเนื้อหา */
    }

    /* 🚀 ลบ Outline และ Shadow ของทั้ง 3 ปุ่ม */
    #tts-play-btn,
    #tts-close-btn,
    #tts-modal-close-x-btn {
        outline: none !important;
        box-shadow: none !important;
        -webkit-tap-highlight-color: transparent; /* ลบสีฟ้าๆ เวลาแตะปุ่มในมือถือ (Android/iOS) */
    }

    /* จัดปุ่มไปที่มุมขวาบน */
    #tts-modal-close-x-btn {
        position: absolute;
        top: 10px;
        right: 10px;
        z-index: 50;
        
        /* ปรับขนาดปุ่มให้กดง่ายในมือถือ */
        width: 32px; 
        height: 32px;
        background: transparent;
        border: none;
        padding: 0;
        cursor: pointer;

        /* 🚀 (ใหม่) เอา Shadow ออก */
        box-shadow: none !important;
        filter: none !important; 
    }
}

/* CSS สำหรับเบลอหน้าจอเมื่อสลับหน้าต่าง */

/* 1. สั่งเบลอเฉพาะ "ไส้ใน" ของ container เพื่อให้ขอบ Card ยังคมชัด */
.blur-content #novel-container > *, 
.blur-content h1,
.blur-content .novel-pagination {
    filter: blur(5px);      /* ลดเหลือ 5px ก็อ่านไม่ออกแล้วครับ */
    opacity: 0.6;           /* ให้จางลงแค่พอประมาณ ไม่ต้องถึงกับหายไป (0.1) */
    transition: all 0.2s ease;
}

/* 2. ตัว Container หลักไม่ต้องเบลอ (เพื่อให้เห็น Card/Background ชัดเจน) */
.blur-content #novel-container {
    /* ไม่ต้องใส่ filter blur ตรงนี้ ถ้าอยากให้กรอบยังคม */
    pointer-events: none;   /* ป้องกันการคลิก */
    user-select: none;      /* ป้องกันการคลุมดำ */
}

/* ป้องกันการลากคลุมดำ (Highlight Text) - คงเดิม */
.novel-content {
    -webkit-user-select: none;
    -ms-user-select: none; 
    user-select: none; 
}

/* CSS สำหรับม่านบังตา */
#screenshot-blocker {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: #000; /* สีดำทึบ หรือเปลี่ยนเป็นสีอื่น */
    z-index: 9999999; /* อยู่บนสุดของทุกเลเยอร์ */
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    text-align: center;
}

/* คลาสสำหรับซ่อน/แสดง */
#screenshot-blocker.hidden {
    display: none !important;
}

.blocker-content h1 {
    font-size: 2em;
    color: #ff4444;
    margin-bottom: 20px;
}