/*
 * หน้าเว็บผู้อ่าน — ห้องสมุดดิจิทัลสำหรับคนตาบอด
 *
 * ข้อกำหนดที่ยึด (WCAG 2.2 AA):
 *   - คอนทราสต์ข้อความอย่างน้อย 4.5:1 (คำนวณและตรวจแล้วทุกคู่สี)
 *   - กรอบโฟกัสเห็นชัด ห้ามซ่อน
 *   - เป้าหมายสัมผัสอย่างน้อย 44x44 px
 *   - ข้อความขยายได้ถึง 200% โดยไม่พัง (ใช้ rem ไม่ใช่ px)
 *   - ไม่สื่อความหมายด้วยสีอย่างเดียว
 */

/* ------------------------------------------------------------------
   ตัวอักษร — เสิร์ฟจากเซิร์ฟเวอร์เอง (นโยบายความปลอดภัยไม่ให้โหลดจากที่อื่น
   และไม่ส่งข้อมูลผู้อ่านไปให้บริการภายนอก) สัญญาอนุญาต OFL อยู่ใน assets/fonts
   Sarabun สำหรับเนื้อความ Anuphan สำหรับหัวข้อ
   ------------------------------------------------------------------ */
@font-face { font-family: "Sarabun"; font-weight: 400; font-display: swap;
    src: url("fonts/sarabun-thai-400-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Sarabun"; font-weight: 400; font-display: swap;
    src: url("fonts/sarabun-latin-400-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Sarabun"; font-weight: 700; font-display: swap;
    src: url("fonts/sarabun-thai-700-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Sarabun"; font-weight: 700; font-display: swap;
    src: url("fonts/sarabun-latin-700-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Anuphan"; font-weight: 600; font-display: swap;
    src: url("fonts/anuphan-thai-600-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Anuphan"; font-weight: 600; font-display: swap;
    src: url("fonts/anuphan-latin-600-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+FEFF, U+FFFD; }

:root {
    /* คู่สีที่ผ่านเกณฑ์คอนทราสต์ — ตรวจด้วยการคำนวณจริง ไม่ใช่กะเอา */
    --text: #1a1a1a;          /* บนพื้นขาว = 16.9:1 */
    --text-muted: #4a5462;    /* บนพื้นขาว = 8.1:1  */
    --bg: #ffffff;
    --bg-alt: #f5f1fc;
    --primary: #5b2a9e;       /* ม่วง (2.6) ตัวอักษรขาวบนพื้นนี้ = 9.3:1 บน --primary-soft 8.1:1 */
    --primary-soft: #f3eefc;  /* พื้นแบนเนอร์และการ์ด --text บนพื้นนี้ 15.3:1 */
    --primary-strong: #3d1a75;
    --ink: #2a1858;           /* หัวข้อบนหน้าบ้าน บน --primary-soft 13.5:1 */
    --line: #e4dcf3;          /* เส้นขอบตกแต่ง (ไม่ใช่ขอบของช่องกรอก) */
    --primary-text: #ffffff;
    --border: #6b7280;        /* บนพื้นขาว = 4.8:1 (ผ่านเกณฑ์ non-text 3:1) */
    --focus: #b3541e;         /* สีกรอบโฟกัส ตัดกับทั้งพื้นขาวและพื้นน้ำเงิน */
    --danger: #a4262c;        /* บนพื้นขาว 7.3:1 บน --bg-alt 6.7:1 */
    --warning: #7a4a00;       /* บนพื้นขาว 7.5:1 บน --bg-alt 6.9:1 */
    --success: #1e6b34;       /* บนพื้นขาว 6.6:1 บน --bg-alt 6.0:1 */
    --surface: #ffffff;       /* พื้นแผงชั้นหนังสือ บนพื้นหน้า --page */
    --page: #fcfbff;          /* --text บนพื้นนี้ 16.6:1 */
    --chip: #efe8fb;          /* --text บนพื้นนี้ 14.6:1 */
    --line-height: 1.7;       /* ผู้อ่านปรับได้: กว้าง 2.0 กว้างมาก 2.3 */
    /* สีปกอัตโนมัติ 5 สีตามหมวด ตัวอักษรขาวบนทุกสีเกิน 7:1 */
    --tone-1: #12508f; --tone-2: #5b3577; --tone-3: #1d5c4a; --tone-4: #8a3a1a; --tone-5: #3d4f63;
    --tone-text: #ffffff;
}

/* ใช้ rem ทั้งหมดเพื่อให้ผู้ใช้ขยายตัวอักษรได้จากการตั้งค่าเบราว์เซอร์ */
html { font-size: 100%; }

body {
    margin: 0;
    font-family: "Sarabun", "Noto Sans Thai", system-ui, sans-serif;
    /* 1.125rem = 18px เริ่มต้น อ่านง่ายกว่า 16px สำหรับผู้ใช้สายตาเลือนราง */
    font-size: 1.125rem;
    /* บรรทัดห่าง 1.6 ตามเกณฑ์ WCAG 1.4.12 */
    line-height: var(--line-height);
    color: var(--text);
    background: var(--page);
}

/* ------------------------------------------------------------------
   ลิงก์ข้ามไปเนื้อหาหลัก
   ซ่อนจนกว่าจะได้โฟกัส แล้วต้องเห็นชัดทันที
   ------------------------------------------------------------------ */
.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    padding: 0.75rem 1.25rem;
    background: var(--primary);
    color: var(--primary-text);
    z-index: 100;
}

.skip-link:focus {
    left: 0;
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

/* ------------------------------------------------------------------
   กรอบโฟกัส — ห้ามลบเด็ดขาด
   ผู้ใช้คีย์บอร์ดและผู้ใช้สายตาเลือนรางจะไม่รู้ว่าอยู่ตรงไหน
   ------------------------------------------------------------------ */
:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

/* ------------------------------------------------------------------
   ข้อความสำหรับ screen reader เท่านั้น
   ห้ามใช้ display:none เพราะ screen reader จะอ่านไม่เจอ
   ------------------------------------------------------------------ */
.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ------------------------------------------------------------------
   โครงหน้า
   ------------------------------------------------------------------ */
header[role="banner"],
footer[role="contentinfo"] {
    padding: 1rem;
    background: var(--bg-alt);
}

main {
    /* 70ch อ่านสบายตา ไม่ต้องกวาดสายตาไกล */
    max-width: 70ch;
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
}

.site-name { margin: 0; font-weight: 700; }

/* เจ้าหน้าที่ที่เปิดหน้าผู้อ่านเห็นทางกลับหลังบ้าน (ผู้อ่านทั่วไปไม่เห็นแถบนี้) */
.staff-bar { padding: 0.4rem 1rem; background: var(--text); text-align: right; font-size: 1rem; }
.staff-bar a { color: var(--bg); }

/* เมนูหลักแนวนอนบนจอกว้าง ขึ้นบรรทัดใหม่เองบนจอแคบหรือเมื่อขยายตัวอักษร */
.site-nav { list-style: none; margin: 0.5rem 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; }
.site-nav a { display: inline-block; padding: 0.35rem 0; }

.announcement { border-left: 4px solid var(--primary); padding: 0.25rem 1rem; background: var(--bg-alt); }
.rating, .recommend-note { margin: 0.25rem 0; }
.recommend-note { font-style: italic; }
.review-meta { font-weight: 600; margin-bottom: 0.25rem; }
.reviews > li { margin-bottom: 1rem; }
fieldset { margin: 1rem 0; padding: 0.75rem 1rem; }
legend { font-weight: 700; padding: 0 0.25rem; }

h1 { font-size: 1.75rem; margin-top: 0; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.2rem; margin-bottom: 0.25rem; }

/* ขีดเส้นใต้ลิงก์เสมอ — ไม่แยกลิงก์ด้วยสีอย่างเดียว */
a { color: var(--primary); text-decoration: underline; }
a:hover { text-decoration-thickness: 3px; }

/* ------------------------------------------------------------------
   แถบแจ้งโหมดทดสอบ
   ต้องเห็นชัดและมีข้อความ ไม่ใช่แค่เปลี่ยนสีพื้นหลัง
   ------------------------------------------------------------------ */
.mode-banner {
    padding: 0.75rem 1rem;
    background: #fff4e5;
    color: #6b3d00;   /* บนพื้น #fff4e5 = 8.2:1 */
    border-bottom: 4px solid #b3541e;
    font-weight: 600;
}

/* ------------------------------------------------------------------
   ฟอร์ม
   ------------------------------------------------------------------ */
.field { margin-bottom: 1.25rem; }

label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.field-help {
    margin: 0 0 0.4rem;
    font-size: 0.95rem;
    color: var(--text-muted);
}

/*
 * ทุกชนิดของช่องกรอก ไม่ใช่แค่ text/search
 * ช่องที่ไม่มีกฎ (email, password, date, number, textarea) ใช้ตัวอักษรของเบราว์เซอร์ 13.33px
 * ซึ่งไม่ขยายตามขนาดตัวอักษรของห้องสมุด (font_scale) และสูงแค่ 21px
 * ทั้งที่หน้าเข้าสู่ระบบคือหน้าที่ผู้อ่านสายตาเลือนรางใช้บ่อยที่สุด
 * (1rem ตามขนาดของ html จึงขยายตาม font_scale และการตั้งค่าเบราว์เซอร์)
 */
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="image"]):not([type="range"]):not([type="color"]),
input[type="file"],
textarea,
select {
    width: 100%;
    box-sizing: border-box;
    line-height: 1.5;
    /* 44px ตามเกณฑ์เป้าหมายสัมผัส WCAG 2.5.8 */
    min-height: 44px;
    padding: 0.6rem 0.75rem;
    /* 1rem = 16px กัน iOS ซูมอัตโนมัติตอนโฟกัส ซึ่งทำให้ผู้ใช้สับสน */
    font-size: 1rem;
    font-family: inherit;
    color: var(--text);
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 4px;
}

button {
    min-height: 44px;
    padding: 0.6rem 1.5rem;
    font-size: 1rem;
    font-family: inherit;
    color: var(--primary-text);
    background: var(--primary);
    border: 2px solid transparent;
    border-radius: 4px;
    cursor: pointer;
}

button:hover { background: #0d3d6f; }

textarea { min-height: 6rem; resize: vertical; }
input[type="file"] { padding: 0.5rem; }
input[type="checkbox"], input[type="radio"] { width: 1.5rem; height: 1.5rem; }

/* ------------------------------------------------------------------
   ข้อความผิดพลาด คำเตือน และข้อความแจ้งผล
   ทุกแบบมีคำนำหน้าเป็นตัวอักษร ("ผิดพลาด:" "ข้อควรทราบ:") และกรอบ/ความหนา
   ไม่สื่อด้วยสีอย่างเดียว (WCAG 1.4.1) สีทุกชุดผ่าน 4.5:1 บนทั้ง --bg และ --bg-alt
   ------------------------------------------------------------------ */
.error-message,
.field-error,
.error {
    color: var(--danger);
    font-weight: 700;
}

.field-error { margin: 0 0 0.4rem; }

.warning { color: var(--warning); font-weight: 700; }
.ok { color: var(--success); font-weight: 700; }

/* กล่องประกาศข้อผิดพลาดต้นหน้า (role="alert" จาก liveRegion และ errorSummary) */
.error-summary,
[role="alert"] {
    border: 3px solid var(--danger);
    border-left-width: 8px;
    padding: 0.5rem 1rem;
    margin: 1rem 0;
    background: var(--bg);
}

/* สรุปข้อผิดพลาดที่ซ้อนอยู่ในกล่อง alert อีกชั้น ไม่ต้องมีกรอบซ้ำ */
[role="alert"] .error-summary { border: 0; padding: 0; margin: 0; }

.error-summary h2 { margin-top: 0.25rem; color: var(--danger); }
.error-summary a { color: var(--danger); font-weight: 700; }

/* ข้อความแจ้งผล (role="status" จาก liveRegion) */
.notice,
main [role="status"] {
    border-left: 6px solid var(--success);
    padding: 0.25rem 1rem;
    margin: 1rem 0;
}

/* ช่องที่ผิด: ขอบหนาขึ้นและเป็นสีอันตราย ประกอบกับข้อความผิดพลาดที่อยู่เหนือช่อง */
[aria-invalid="true"] {
    border-color: var(--danger) !important;
    border-width: 3px !important;
}

.field-invalid > label { color: var(--danger); }

/* ------------------------------------------------------------------
   ผลการค้นหา
   ------------------------------------------------------------------ */
.results {
    list-style: none;
    padding: 0;
    margin: 1rem 0;
}

.results > li {
    padding: 1rem 0;
    border-bottom: 1px solid var(--border);
}

.results > li:last-child { border-bottom: 0; }

/* ฟอร์แมตที่มี — ข้อมูลสำคัญที่ผู้ใช้ต้องรู้ก่อนคลิก จึงเน้นให้ชัด */
.formats {
    margin: 0.25rem 0;
    font-weight: 600;
}

.summary {
    margin: 0.5rem 0 0;
    color: var(--text-muted);
}

/* ------------------------------------------------------------------
   โหมดคอนทราสต์สูงของระบบปฏิบัติการ
   บางเบราว์เซอร์ตัดสีพื้นหลังออก ต้องบังคับให้ยังเห็นขอบเขต
   ------------------------------------------------------------------ */
@media (forced-colors: active) {
    button,
    input,
    textarea,
    select {
        border: 2px solid currentColor;
    }

    /* สีถูกตัดออกในโหมดนี้ ช่องที่ผิดจึงต้องต่างด้วยความหนาของขอบ */
    [aria-invalid="true"] { border-width: 4px; }
}

/* ผู้ใช้ที่ตั้งค่าลดการเคลื่อนไหว */
@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}

/* ------------------------------------------------------------------
   ตัวอ่านหนังสือบนเว็บ

   ผู้ใช้สายตาเลือนรางจำนวนมากอ่านด้วยการขยายหน้าจอมาก
   บรรทัดจึงต้องไม่ยาวเกินไป และระยะห่างบรรทัดต้องพอให้สายตาไม่หลงบรรทัด
   ------------------------------------------------------------------ */
.section-body {
    max-width: 38em;
    line-height: 1.9;
    font-size: 1.05rem;
}

.section-body p {
    margin: 0 0 1.1em;
}

.section-body blockquote {
    margin: 1em 0;
    padding-left: 1em;
    border-left: 4px solid var(--border);
}

/* เลขหน้าไม่แสดงเป็นข้อความ แต่ยังอ่านได้ด้วยโปรแกรมอ่านหน้าจอ */
.pagenum {
    display: block;
    width: 0;
    height: 0;
    margin: 0;
    border: 0;
    overflow: hidden;
}

.position,
.book-context,
.capability {
    color: var(--text-muted);
    margin: 0.25rem 0;
}

.section-nav {
    list-style: none;
    padding: 0;
    margin: 1rem 0;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

/* สารบัญที่มีหลายระดับ ย่อหน้าตามระดับเพื่อให้เห็นลำดับชั้น */
.toc { line-height: 2; }
.toc-level-2 { margin-left: 1.5rem; }
.toc-level-3 { margin-left: 3rem; }
.toc-level-4 { margin-left: 4.5rem; }
.toc-level-5,
.toc-level-6 { margin-left: 6rem; }

.shortcuts { margin: 1.5rem 0; }

.shortcuts-table {
    border-collapse: collapse;
    margin: 0.5rem 0;
}

.shortcuts-table th,
.shortcuts-table td {
    text-align: left;
    padding: 0.35rem 1rem 0.35rem 0;
    border-bottom: 1px solid var(--border);
}

audio {
    width: 100%;
    max-width: 38em;
    margin: 0.5rem 0 1rem;
}

/* ------------------------------------------------------------------
   ชุดสี — ห้องสมุดเลือกค่าเริ่มต้น ผู้อ่านเลือกเองได้ที่หน้าบัญชีของฉัน
   ทุกคู่สีคำนวณความต่างแล้ว (ตัวเลขในวงเล็บคืออัตราบนพื้นหลักของชุดนั้น)
   ------------------------------------------------------------------ */
html[data-theme="dark"] {
    --surface: #1b1d26; --page: #121417; --chip: #2a2340;
    --tone-1: #24548a; --tone-2: #5c3d78; --tone-3: #22604f; --tone-4: #84401f; --tone-5: #44566b;
    --text: #eceff1;          /* 16.0:1 */
    --text-muted: #b8c0c8;    /* 10.0:1 */
    --bg: #121417;
    --bg-alt: #1e2227;        /* ตัวอักษรบนพื้นนี้ 13.9:1 */
    --primary: #c3a6ff;       /* 9.0:1 */
    --primary-text: #1d0f3a;  /* บนปุ่มสีหลัก 8.7:1 */
    --primary-soft: #221a33;  /* --primary บนพื้นนี้ 8.1:1 */
    --primary-strong: #dccbff;
    --ink: #efe7ff;
    --line: #3a3150;
    --border: #8a939e;        /* 5.9:1 */
    --focus: #ffb86b;         /* 10.8:1 */
    --danger: #ff8a8a;        /* 8.1:1 บน --bg-alt 7.1:1 */
    --warning: #ffcc66;       /* 12.4:1 บน --bg-alt 10.7:1 */
    --success: #7ddc94;       /* 11.0:1 บน --bg-alt 9.6:1 */
    color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
    html[data-theme="auto"] {
        --surface: #1b1d26; --page: #121417; --chip: #2a2340;
        --tone-1: #24548a; --tone-2: #5c3d78; --tone-3: #22604f; --tone-4: #84401f; --tone-5: #44566b;
        --text: #eceff1;
        --text-muted: #b8c0c8;
        --bg: #121417;
        --bg-alt: #1e2227;
        --primary: #c3a6ff;
        --primary-text: #1d0f3a;
        --primary-soft: #221a33;
        --primary-strong: #dccbff;
        --ink: #efe7ff;
        --line: #3a3150;
        --border: #8a939e;
        --focus: #ffb86b;
        --danger: #ff8a8a;
        --warning: #ffcc66;
        --success: #7ddc94;
        color-scheme: dark;
    }
}

/* สีตัดกันสูง: พื้นดำ ตัวอักษรเหลือง ลิงก์ฟ้า — สำหรับผู้อ่านสายตาเลือนราง */
html[data-theme="contrast"] {
    --surface: #000000; --page: #000000; --chip: #000000;
    --text: #ffff00;          /* 19.6:1 */
    --text-muted: #ffffff;    /* 21:1 */
    --bg: #000000;
    --bg-alt: #000000;
    --primary: #00ffff;       /* 16.8:1 */
    --primary-text: #000000;
    --primary-soft: #000000;
    --primary-strong: #00ffff;
    --ink: #ffff00;
    --line: #ffffff;
    --border: #ffffff;
    --focus: #ffffff;
    --danger: #ff6b6b;        /* 7.6:1 */
    --warning: #ffd166;       /* 14.6:1 */
    --success: #66ff66;       /* 16.1:1 */
    color-scheme: dark;
}

html[data-theme="dark"] button:hover,
html[data-theme="contrast"] button:hover { background: var(--text); color: var(--bg); }

@media (prefers-color-scheme: dark) {
    html[data-theme="auto"] button:hover { background: var(--text); color: var(--bg); }
}

html[data-theme="dark"] .mode-banner,
html[data-theme="contrast"] .mode-banner { background: #2a2210; color: #ffd166; }  /* 10.9:1 */

.site-logo { max-height: 4rem; width: auto; vertical-align: middle; margin-right: 0.5rem; }
.site-footer-text { white-space: pre-line; }

/* รหัสเครื่องเล่นและเลขสมาชิก — ตัวใหญ่ เว้นระยะ ตัวเลขกว้างเท่ากัน จดตามได้ไม่ผิด */
.device-code {
    font-family: ui-monospace, "Cascadia Mono", "Courier New", monospace;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    font-variant-numeric: tabular-nums;
}

/* รายการ "ชื่อข้อมูล: ค่า" — ใช้แทน dl เพราะ VoiceOver iOS อ่าน dt ว่า "คำศัพท์" */
.detail-list { margin: 0.5rem 0 1rem; }
.detail-row { margin: 0.4rem 0; }
.detail-label { font-weight: 700; margin-right: 0.25em; }

.device-code-details .detail-row { margin-top: 0.75rem; }
.device-code-details .detail-value { display: block; margin-top: 0.25rem; }

/* ==================================================================
   รุ่น 2.3 — ชั้นหนังสือแบ่งหมวด ปก แถบตั้งค่าการแสดงผล
   ================================================================== */

h1, h2, h3 { font-family: "Anuphan", "Sarabun", "Noto Sans Thai", system-ui, sans-serif; font-weight: 600; line-height: 1.35; text-wrap: balance; }

html[data-spacing="wide"] { --line-height: 2; }
html[data-spacing="wider"] { --line-height: 2.3; }
html[data-covers="hide"] .cover { display: none !important; }

/* หน้าผู้อ่านกว้างพอสำหรับชั้นหนังสือ แต่ย่อหน้ายังคุมความยาวบรรทัดไว้ */
html:not(.admin) main { max-width: 80rem; padding-left: max(1rem, env(safe-area-inset-left, 0px)); padding-right: max(1rem, env(safe-area-inset-right, 0px)); }
html:not(.admin) main p, html:not(.admin) main li > p { max-width: 70ch; }

header[role="banner"], footer[role="contentinfo"] { background: var(--surface); border-bottom: 1px solid var(--border); }
footer[role="contentinfo"] { border-top: 1px solid var(--border); border-bottom: 0; }

/* ---------------- แถบตั้งค่าการแสดงผล ---------------- */
.display-tools { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0.4rem max(1rem, env(safe-area-inset-right, 0px)) 0.4rem max(1rem, env(safe-area-inset-left, 0px)); }
.display-tools summary { display: inline-flex; align-items: center; min-height: 44px; padding: 0 0.9rem; border: 2px solid var(--border); border-radius: 8px; cursor: pointer; font-weight: 700; }
.display-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 0.75rem 1.5rem; padding-block: 0.75rem; align-items: end; }
.display-field label { display: block; font-weight: 700; }
.display-field select { width: 100%; }
.display-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.staff-bar { padding: 0.4rem max(1rem, env(safe-area-inset-right, 0px)) 0.4rem max(1rem, env(safe-area-inset-left, 0px)); }

/* ---------------- หมวดหมู่ ---------------- */
.cat-nav { margin: 1.5rem 0 2.5rem; }
.cat-nav ul { list-style: none; padding: 0; margin: 0.75rem 0 0; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.cat-nav a { display: inline-flex; gap: 0.4rem; align-items: baseline; min-height: 44px; padding: 0.45rem 0.95rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); text-decoration: none; color: var(--text); }
.cat-nav a:hover { border-color: var(--primary); text-decoration: underline; }
.cat-nav .count { color: var(--text-muted); font-size: 0.9em; }

/* ---------------- ชั้นหนังสือ: แต่ละกลุ่มเป็นแผงแยก ไม่ติดกัน ---------------- */
.shelf { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 1.5rem; margin: 0 0 2.5rem; }
.shelf-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.25rem 1rem; padding-bottom: 0.9rem; margin-bottom: 1.25rem; border-bottom: 3px solid var(--primary); }
.shelf-head h2 { margin: 0; }
.shelf-head p { margin: 0; color: var(--text-muted); }
.shelf .more { margin: 1.25rem 0 0; font-weight: 700; }

.books { list-style: none; padding: 0; margin: 1rem 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); gap: 1.5rem; }
.books > li, .results > li.book { display: grid; grid-template-columns: 5rem minmax(0, 1fr); gap: 1rem; align-items: start; }
html[data-covers="hide"] .books > li, html[data-covers="hide"] .results > li.book { grid-template-columns: minmax(0, 1fr); }
.books h3, .books h2 { font-size: 1.15rem; margin: 0 0 0.25rem; }
.book-body > p { margin: 0.15rem 0; }
.book-body .formats { display: inline-block; padding: 0.05rem 0.5rem; border-radius: 4px; background: var(--chip); font-size: 0.95rem; }

/* ---------------- ปก ---------------- */
.cover { width: 100%; height: auto; max-width: 100%; aspect-ratio: 2 / 3; border-radius: 4px 8px 8px 4px; display: block; object-fit: cover; }
/*
 * ปกอัตโนมัติ 12 ชุดสี x 6 ลาย (2.6)
 *
 * สีมาจากหมวดหมู่ (หมวดเลือกเองหรือให้ระบบเลือก) ลายมาจากรหัสเรื่อง
 * หนังสือในหมวดเดียวกันจึงสีเดียวกันแต่ลายต่างกัน ชั้นหนังสือไม่ซ้ำกันทั้งแถว
 * ทุกชุดตรวจแล้วว่าตัวอักษรตัดกับพื้นอย่างน้อย 4.5:1 รวมจุดที่ลายทับ (ดูตัวเลขท้ายบรรทัด)
 * ปกเหล่านี้ไม่เปลี่ยนตามโหมดมืด เพราะเป็นภาพของหนังสือ แต่โหมดสีตัดกันสูงเปลี่ยนเป็นขาวดำ
 */
.cover-auto { box-sizing: border-box; display: flex; flex-direction: column; justify-content: flex-end; gap: 0.3rem; padding: 0.5rem; color: var(--ink, #ffffff); font-family: "Anuphan", "Sarabun", sans-serif; font-weight: 600; font-size: 0.7rem; line-height: 1.3; box-shadow: inset 5px 0 0 rgba(0, 0, 0, 0.25); overflow: hidden; overflow-wrap: anywhere;
    --c1: #4b2a8f; --c2: #6a3fb5; --pat: rgba(255, 255, 255, 0.12);
    background: linear-gradient(160deg, var(--c1), var(--c2)); }
.cover-auto.tone-1 { --c1: #4b2a8f; --c2: #6a3fb5; --ink: #ffffff; --pat: rgba(255, 255, 255, 0.12); } /* ลาเวนเดอร์ ตัวอักษรบนพื้น 5.3:1 */
.cover-auto.tone-2 { --c1: #0a4a75; --c2: #0f6292; --ink: #ffffff; --pat: rgba(255, 255, 255, 0.12); } /* ทะเล ตัวอักษรบนพื้น 5.1:1 */
.cover-auto.tone-3 { --c1: #1a5532; --c2: #246a3f; --ink: #ffffff; --pat: rgba(255, 255, 255, 0.12); } /* ใบไม้ ตัวอักษรบนพื้น 5.0:1 */
.cover-auto.tone-4 { --c1: #ffd9ad; --c2: #ffbf7a; --ink: #3b1d00; --pat: rgba(0, 0, 0, 0.1); } /* ส้มยามเย็น ตัวอักษรบนพื้น 7.3:1 */
.cover-auto.tone-5 { --c1: #8f1c55; --c2: #b02f6f; --ink: #ffffff; --pat: rgba(255, 255, 255, 0.12); } /* ชมพูบานเย็น ตัวอักษรบนพื้น 4.9:1 */
.cover-auto.tone-6 { --c1: #1b1f4b; --c2: #2c3577; --ink: #ffe9a8; --pat: rgba(255, 255, 255, 0.12); } /* ครามราตรี ตัวอักษรบนพื้น 6.6:1 */
.cover-auto.tone-7 { --c1: #cdf2e4; --c2: #a3e2cb; --ink: #0f3d2c; --pat: rgba(0, 0, 0, 0.1); } /* มิ้นต์ ตัวอักษรบนพื้น 6.4:1 */
.cover-auto.tone-8 { --c1: #ffe68f; --c2: #f6cb4b; --ink: #3a2b00; --pat: rgba(0, 0, 0, 0.1); } /* มัสตาร์ด ตัวอักษรบนพื้น 6.8:1 */
.cover-auto.tone-9 { --c1: #82291b; --c2: #a63722; --ink: #ffffff; --pat: rgba(255, 255, 255, 0.12); } /* อิฐ ตัวอักษรบนพื้น 5.2:1 */
.cover-auto.tone-10 { --c1: #0c5050; --c2: #126868; --ink: #ffffff; --pat: rgba(255, 255, 255, 0.12); } /* เขียวหัวเป็ด ตัวอักษรบนพื้น 5.0:1 */
.cover-auto.tone-11 { --c1: #d6e9ff; --c2: #abd0ff; --ink: #0b2c55; --pat: rgba(0, 0, 0, 0.1); } /* ฟ้าใส ตัวอักษรบนพื้น 6.7:1 */
.cover-auto.tone-12 { --c1: #472d20; --c2: #66412e; --ink: #ffe7cf; --pat: rgba(255, 255, 255, 0.12); } /* ช็อกโกแลต ตัวอักษรบนพื้น 5.4:1 */
.cover-auto.pat-1 { background: repeating-radial-gradient(circle at 0 100%, transparent 0 14px, var(--pat) 14px 17px), linear-gradient(160deg, var(--c1), var(--c2)); }
.cover-auto.pat-2 { background: radial-gradient(var(--pat) 22%, transparent 24%) 0 0 / 14px 14px, linear-gradient(160deg, var(--c1), var(--c2)); }
.cover-auto.pat-3 { background: repeating-linear-gradient(135deg, var(--pat) 0 6px, transparent 6px 18px), linear-gradient(160deg, var(--c1), var(--c2)); }
.cover-auto.pat-4 { background: radial-gradient(circle at 85% 18%, var(--pat) 0 32%, transparent 33%), radial-gradient(circle at 10% 45%, var(--pat) 0 14%, transparent 15%), linear-gradient(160deg, var(--c1), var(--c2)); }
.cover-auto.pat-5 { background: linear-gradient(45deg, var(--pat) 25%, transparent 25% 75%, var(--pat) 75%) 0 0 / 20px 20px, linear-gradient(-45deg, var(--pat) 25%, transparent 25% 75%, var(--pat) 75%) 0 0 / 20px 20px, linear-gradient(160deg, var(--c1), var(--c2)); }
.cover-auto.pat-6 { background: linear-gradient(180deg, var(--pat) 0 22%, transparent 22% 28%, var(--pat) 28% 31%, transparent 31%), linear-gradient(160deg, var(--c1), var(--c2)); }
.cover-large { max-width: 12rem; }
.cover-large.cover-auto { font-size: 1.05rem; padding: 1rem; }
.cover-author { font-weight: 400; font-size: 0.85em; }
html[data-theme="contrast"] .cover-auto { background: #000 !important; color: var(--text); border: 2px solid var(--text); box-shadow: none; }

.book-head { display: grid; grid-template-columns: 12rem minmax(0, 1fr); gap: 2rem; align-items: start; margin-bottom: 1.5rem; }
html[data-covers="hide"] .book-head { grid-template-columns: minmax(0, 1fr); }
@media (max-width: 40rem) { .book-head { grid-template-columns: 1fr; } .book-head .cover-large { max-width: 9rem; } }

.cover-admin { display: grid; grid-template-columns: 9rem minmax(0, 1fr); gap: 1.5rem; align-items: start; }
@media (max-width: 40rem) { .cover-admin { grid-template-columns: 1fr; } }

/* ---------------- เส้นทางเดิน (หน้าผู้อ่าน) ---------------- */
.crumb { font-size: 1rem; margin-bottom: 1rem; }
.crumb ol { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 0.25rem; }
.crumb li + li::before { content: "›"; margin: 0 0.4rem; color: var(--text-muted); }

.filters { display: flex; flex-wrap: wrap; gap: 0.75rem 1rem; align-items: flex-end; margin: 1rem 0; }
.filters .field { margin: 0; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1.25rem; margin-bottom: 1.5rem; }

/* รายการเล่มของชุดอักษรเบรลล์ */
.volume-list { margin: 0.5rem 0 0; padding-left: 1.5rem; display: grid; gap: 0.35rem; }

/* ==================================================================
   หน้าบ้านรุ่น 2.6 — โทนขาวม่วง ตามแบบหน้าแรกของสำนักหอสมุดเบญญาลัย
   ทุกสีมาจากตัวแปรด้านบน จึงเปลี่ยนตามโหมดมืดและสีตัดกันสูงเอง
   เป้าคลิกอย่างน้อย 44 พิกเซล ขยายตัวอักษร 200% แล้วไม่ล้นแนวนอน
   ================================================================== */
body { background: var(--page); }
header.site-header { background: var(--surface); border-bottom: 1px solid var(--line); padding: 0; }
.header-inner { max-width: 80rem; margin: 0 auto; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem 1.5rem; padding: 0.7rem max(1rem, env(safe-area-inset-right, 0px)) 0.7rem max(1rem, env(safe-area-inset-left, 0px)); }
.site-name a { display: flex; align-items: center; gap: 0.75rem; text-decoration: none; color: var(--ink); min-height: 44px; }
.site-name a:hover .site-title { text-decoration: underline; }
.site-mark { width: 3rem; height: 3rem; color: var(--primary); flex: none; }
.site-name .site-logo { max-height: 3.25rem; margin: 0; }
.site-name-text { display: flex; flex-direction: column; min-width: 0; }
.site-title { font-family: "Anuphan", "Sarabun", sans-serif; font-size: 1.35rem; font-weight: 600; line-height: 1.25; }
.site-tagline { font-size: 0.9rem; font-weight: 400; color: var(--text-muted); line-height: 1.3; }

.main-nav { flex: 1 1 auto; }
.site-header .site-nav { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: stretch; gap: 0.2rem; }
.site-header .site-nav li { display: flex; }
.site-header .site-nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.2rem; min-width: 4.6rem; min-height: 44px; padding: 0.45rem 0.6rem; border-radius: 12px; text-decoration: none; color: var(--ink); font-size: 0.92rem; line-height: 1.25; text-align: center; }
.site-header .site-nav a:hover { background: var(--primary-soft); text-decoration: underline; }
.site-header .site-nav a[aria-current="page"] { background: var(--primary-soft); color: var(--primary); font-weight: 700; box-shadow: inset 0 -3px 0 var(--primary); }
.nav-icon { width: 1.6rem; height: 1.6rem; flex: none; }
.site-header .nav-login a, .site-header .nav-login a[aria-current="page"] { flex-direction: row; gap: 0.5rem; align-self: center; margin-left: 0.6rem; padding: 0.65rem 1.3rem; border-radius: 999px; background: var(--primary); color: var(--primary-text); font-weight: 600; box-shadow: none; }
.site-header .nav-login a:hover { background: var(--primary-strong); color: var(--primary-text); }
.nav-login .nav-icon { width: 1.3rem; height: 1.3rem; }

.header-search-band { background: var(--primary-soft); border-top: 1px solid var(--line); padding: 0.55rem max(1rem, env(safe-area-inset-right, 0px)) 0.55rem max(1rem, env(safe-area-inset-left, 0px)); }
.header-search { max-width: 80rem; margin: 0 auto; display: flex; align-items: center; gap: 0.5rem; }
.header-search input#top-q { margin: 0; flex: 1 1 auto; min-width: 0; max-width: 36rem; min-height: 44px; padding: 0.4rem 1rem; border: 2px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text); font: inherit; }
.header-search button { min-height: 44px; border-radius: 999px; padding: 0 1.25rem; }
.search-icon { width: 1.5rem; height: 1.5rem; color: var(--primary); flex: none; }

/* ---------------- แบนเนอร์ ---------------- */
.hero { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); align-items: center; gap: 1.5rem 2rem; margin: 0.5rem 0 2.5rem; padding: clamp(1.5rem, 4vw, 3rem); border-radius: 24px; background: linear-gradient(115deg, var(--primary-soft) 0%, var(--surface) 55%, var(--primary-soft) 100%); border: 1px solid var(--line); overflow: hidden; }
.hero h1 { font-family: "Anuphan", "Sarabun", sans-serif; font-size: clamp(2rem, 4.4vw, 3.3rem); line-height: 1.22; color: var(--ink); margin: 0 0 0.75rem; text-wrap: balance; }
.hero-accent { display: block; color: var(--primary); }
.hero-sub { font-size: 1.15rem; color: var(--text-muted); margin: 0 0 1.5rem; }
.hero-search { display: flex; align-items: center; gap: 0.6rem; max-width: 40rem; padding: 0.35rem 0.35rem 0.35rem 1.1rem; border: 2px solid var(--primary); border-radius: 999px; background: var(--surface); box-shadow: 0 8px 24px rgba(91, 42, 158, 0.12); }
.hero-search:focus-within { outline: 3px solid var(--focus); outline-offset: 3px; }
.hero-search input#home-q { flex: 1 1 auto; min-width: 0; max-width: none; margin: 0; min-height: 44px; border: 0; box-shadow: none; background: transparent; color: var(--text); font: inherit; font-size: 1.1rem; padding: 0.5rem 0.2rem; }
.hero-search input#home-q:focus { outline: none; box-shadow: none; }
.hero-search button { flex: none; min-height: 48px; padding: 0 1.8rem; border: 0; border-radius: 999px; background: var(--primary); color: var(--primary-text); font-weight: 700; font-size: 1.05rem; }
.hero-search button:hover { background: var(--primary-strong); }
.hero-help { margin: 0.6rem 0 0 1.2rem; font-size: 0.92rem; color: var(--text-muted); }
.hero-art { justify-self: end; width: 100%; max-width: 30rem; }
.hero-illustration { display: block; width: 100%; height: auto; }
.hero-photo { display: block; width: 100%; height: auto; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 20px; }
.ha-blob { fill: var(--primary); opacity: 0.12; }
.ha-blob-2 { fill: var(--primary); opacity: 0.08; }
.ha-wave { stroke: var(--primary); opacity: 0.55; }
.ha-page { fill: var(--surface); stroke: var(--primary); stroke-width: 4; }
.ha-page-2 { fill: var(--chip); stroke: var(--primary); stroke-width: 4; }
.ha-spine { stroke: var(--primary); }
.ha-lines { stroke: var(--primary); opacity: 0.45; }
.ha-dots { fill: var(--primary); }
.ha-phones { stroke: var(--ink); }
.ha-cup { fill: var(--primary); }

/* ---------------- หัวของแต่ละส่วน ---------------- */
.home-block { margin: 0 0 2.75rem; }
.block-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.25rem 1rem; margin: 0 0 1rem; }
.block-head h2 { display: flex; align-items: center; gap: 0.6rem; margin: 0; font-family: "Anuphan", "Sarabun", sans-serif; font-size: 1.45rem; line-height: 1.3; color: var(--ink); }
.block-icon { width: 2rem; height: 2rem; color: var(--primary); flex: none; }
.block-note { font-family: "Sarabun", sans-serif; font-weight: 400; font-size: 1rem; color: var(--text-muted); }
.see-all { display: inline-flex; align-items: center; gap: 0.35rem; min-height: 44px; font-weight: 600; color: var(--primary); }
.see-all-icon { width: 1.15rem; height: 1.15rem; }

/* ---------------- กล่องหมวดหนังสือ ---------------- */
.cat-tiles { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(8.75rem, 1fr)); gap: 0.9rem; }
.cat-tile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.45rem; min-height: 8.75rem; height: 100%; box-sizing: border-box; padding: 1rem 0.75rem; border-radius: 16px; border: 1px solid transparent; background: var(--tile-bg, var(--primary-soft)); color: var(--text); text-align: center; text-decoration: none; }
.cat-tile:hover { border-color: var(--tile-ink, var(--primary)); text-decoration: underline; }
.tile-icon { width: 2.6rem; height: 2.6rem; color: var(--tile-ink, var(--primary)); }
.tile-name { font-weight: 600; line-height: 1.3; }
.tile-count { font-size: 0.88rem; color: var(--text-muted); }
/* สีอ่อนตามชุดสีปกของหมวด ไอคอนตัดกับพื้นเกิน 3:1 ตัวอักษรใช้ --text */
.tint-1 { --tile-bg: #ede5fb; --tile-ink: #5b2a9e; } .tint-2 { --tile-bg: #ddeefd; --tile-ink: #0a4a75; }
.tint-3 { --tile-bg: #e3f4e6; --tile-ink: #1a5532; } .tint-4 { --tile-bg: #fdeedd; --tile-ink: #9a4a00; }
.tint-5 { --tile-bg: #fde5ee; --tile-ink: #8f1c55; } .tint-6 { --tile-bg: #e6e8f8; --tile-ink: #2c3577; }
.tint-7 { --tile-bg: #dcf4ec; --tile-ink: #0f5c45; } .tint-8 { --tile-bg: #fdf1d9; --tile-ink: #7a5a00; }
.tint-9 { --tile-bg: #fbe3dc; --tile-ink: #82291b; } .tint-10 { --tile-bg: #d9f1ef; --tile-ink: #0c5050; }
.tint-11 { --tile-bg: #e2edfb; --tile-ink: #0b4f9c; } .tint-12 { --tile-bg: #f3e8df; --tile-ink: #66412e; }

/* ---------------- ประเภทสื่อ ---------------- */
.media-cards { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); gap: 1rem; }
.media-card { display: flex; align-items: center; gap: 1rem; height: 100%; box-sizing: border-box; min-height: 6rem; padding: 0.85rem 1rem; border-radius: 16px; border: 1px solid var(--line); background: var(--primary-soft); color: var(--text); text-decoration: none; }
.media-card:hover { border-color: var(--primary); text-decoration: underline; }
.media-art { flex: none; display: grid; place-items: center; width: 4.75rem; height: 4.75rem; border-radius: 14px; background: var(--surface); color: var(--primary); }
.media-icon { width: 2.9rem; height: 2.9rem; }
.media-text { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; }
.media-name { font-weight: 700; font-size: 1.05rem; color: var(--ink); line-height: 1.3; }
.media-en { font-size: 0.9rem; color: var(--text-muted); }
.media-count { margin-top: 0.15rem; font-size: 0.9rem; font-weight: 600; color: var(--primary); }
.media-go { flex: none; width: 2.1rem; height: 2.1rem; padding: 0.4rem; box-sizing: border-box; border-radius: 50%; background: var(--surface); color: var(--primary); }

/* ---------------- ชั้นหนังสือสามกล่อง ---------------- */
.shelf-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(19rem, 1fr)); gap: 1.25rem; margin: 0 0 2.75rem; }
.shelf-card { padding: 1rem 1.1rem 1.25rem; border-radius: 18px; border: 1px solid var(--line); background: var(--surface); box-shadow: 0 4px 18px rgba(42, 24, 88, 0.06); min-width: 0; }
.shelf-card .block-head h2 { font-size: 1.25rem; }
.shelf-popular .block-icon { color: #9a6a00; }
.shelf-recommended .block-icon { color: #b07800; }
.mini-covers { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.6rem; }
.mini-covers a { display: flex; flex-direction: column; gap: 0.35rem; color: var(--text); text-decoration: none; min-height: 44px; }
.mini-covers a:hover .mini-title { text-decoration: underline; }
.mini-covers .cover { border-radius: 4px 8px 8px 4px; }
.mini-covers .cover-auto { font-size: 0.6rem; padding: 0.35rem; }
.mini-title { font-size: 0.85rem; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
html[data-covers="hide"] .mini-covers { grid-template-columns: minmax(0, 1fr); }

.news-block .news-list { margin: 0; padding-left: 1.25rem; }
.news-block .news-list li { margin: 0.35rem 0; }
.request-block { padding: 1.25rem 1.5rem; border-radius: 18px; background: var(--primary-soft); border: 1px solid var(--line); }
.welcome { margin: 0 0 2rem; }

/* ---------------- ท้ายหน้า ---------------- */
footer.site-footer { background: var(--primary-soft); border-top: 1px solid var(--line); padding: 0; }
.footer-inner { max-width: 80rem; margin: 0 auto; padding: 1.5rem max(1rem, env(safe-area-inset-right, 0px)) 2rem max(1rem, env(safe-area-inset-left, 0px)); }
.footer-name { font-family: "Anuphan", "Sarabun", sans-serif; font-weight: 600; font-size: 1.15rem; color: var(--ink); margin: 0 0 0.25rem; }

/* ---------------- จอแคบและตัวอักษรขยาย ---------------- */
@media (max-width: 64rem) {
    .site-header .site-nav { justify-content: flex-start; }
}
@media (max-width: 48rem) {
    .header-inner { flex-direction: column; align-items: stretch; }
    .site-header .site-nav { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .site-header .site-nav a { min-width: 0; padding: 0.4rem 0.2rem; font-size: 0.82rem; }
    .site-header .nav-account { grid-column: span 2; }
    .site-header .nav-login { grid-column: 1 / -1; }
    .site-header .nav-login a { margin: 0.25rem 0 0; width: 100%; justify-content: center; }
    .hero { grid-template-columns: minmax(0, 1fr); }
    .hero-art { justify-self: center; max-width: 18rem; }
    .hero-search { padding-left: 0.8rem; }
    .hero-search button { padding: 0 1.1rem; }
    .mini-title { font-size: 0.78rem; }
}

@media (prefers-reduced-motion: no-preference) {
    .cat-tile, .media-card { transition: transform 0.15s ease, border-color 0.15s ease; }
    .cat-tile:hover, .media-card:hover { transform: translateY(-2px); }
}

/* โหมดมืด: กล่องหมวดใช้พื้นของธีม ไม่ใช้สีพาสเทล (ตัวอักษรสีอ่อนบนพื้นพาสเทลอ่านไม่ออก) */
html[data-theme="dark"] .cat-tile { --tile-bg: var(--surface); --tile-ink: var(--primary); border-color: var(--line); }
@media (prefers-color-scheme: dark) {
    html[data-theme="auto"] .cat-tile { --tile-bg: var(--surface); --tile-ink: var(--primary); border-color: var(--line); }
}

/* สีตัดกันสูง: ไม่มีพื้นสี ไม่มีเงา ทุกกล่องมีกรอบชัด */
html[data-theme="contrast"] .hero,
html[data-theme="contrast"] .cat-tile,
html[data-theme="contrast"] .media-card,
html[data-theme="contrast"] .shelf-card,
html[data-theme="contrast"] .request-block,
html[data-theme="contrast"] .media-art,
html[data-theme="contrast"] .media-go,
html[data-theme="contrast"] .hero-search { background: #000 !important; border: 2px solid var(--border); box-shadow: none; --tile-ink: var(--text); }
html[data-theme="contrast"] .hero-illustration { display: none; }

/* ------------------------------------------------------------------
   เครื่องเล่นหนังสือ (2.6) — สร้างโดย /assets/player.js
   ปุ่มใหญ่อย่างน้อย 44px ปุ่มเล่นเด่นที่สุด เวลาเขียนเป็นคำไม่ใช่ตัวเลขนาฬิกา
   แผงทั้งแผงมีกรอบโฟกัสชัดเพราะเป็นที่รับคีย์ลัด
   ------------------------------------------------------------------ */
.player-section { margin: 1.5rem 0; }
.player-section > h2 { margin-bottom: 0.25rem; }
.player-type { margin: 0 0 1rem; color: var(--text); font-weight: 600; }
.player {
    display: grid;
    gap: 1rem;
    padding: 1.25rem;
    background: var(--primary-soft);
    border: 2px solid var(--line);
    border-radius: 16px;
}
.player:focus-visible { outline: 4px solid var(--primary); outline-offset: 3px; }
.player.is-playing { border-color: var(--primary); }
.player-main, .player-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.player-main { justify-content: center; }
.player-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 1rem;
    color: var(--text);
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 999px;
}
.player-btn:hover { background: var(--bg-alt); border-color: var(--primary); }
.player-btn.primary, .player-play { color: var(--primary-text); background: var(--primary); border-color: var(--primary); }
.player-btn.primary:hover, .player-play:hover { background: var(--primary-strong); color: var(--primary-text); }
.player-play { min-width: 9rem; justify-content: center; font-size: 1.125rem; font-weight: 700; padding: 0.75rem 1.5rem; }
.player-btn.danger { color: var(--danger); border-color: var(--danger); background: var(--surface); }
.player-key {
    font-size: 0.8rem;
    font-weight: 700;
    padding: 0.05rem 0.4rem;
    border: 1px solid currentColor;
    border-radius: 4px;
}
.player-seek { display: grid; gap: 0.25rem; }
.player-seek input[type="range"], .player-field input[type="range"] { width: 100%; min-height: 44px; padding: 0; border: 0; background: transparent; accent-color: var(--primary); }
.player-times { display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; margin: 0; font-variant-numeric: tabular-nums; }
.player-time-label { font-weight: 700; }
.player-settings { display: grid; gap: 0.75rem 1rem; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); }
.player-field { display: grid; gap: 0.25rem; margin: 0; }
.player-check { display: flex; align-items: center; gap: 0.5rem; }
.player-dialog {
    width: min(36rem, calc(100vw - 2rem));
    max-height: calc(100vh - 2rem);
    overflow: auto;
    padding: 1.5rem;
    color: var(--text);
    background: var(--surface);
    border: 2px solid var(--primary);
    border-radius: 16px;
}
.player-dialog::backdrop { background: rgb(0 0 0 / 55%); }
.player-dialog h2 { margin-top: 0; }
.player-dialog form { display: grid; gap: 0.5rem; margin-bottom: 1rem; }
.player-dialog-close { margin: 0; justify-items: end; }
.player-bookmarks { list-style: none; padding: 0; display: grid; gap: 0.5rem; }
.player-bookmarks li { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.player-bib th { text-align: left; padding-right: 1rem; vertical-align: top; white-space: nowrap; }
.player-bib td { padding-bottom: 0.4rem; }
.bookmark-list { padding-left: 1.5rem; }
.bookmark-list > li { margin-bottom: 1.5rem; }
.bookmark-list h2 { font-size: 1.25rem; margin-bottom: 0.25rem; }
.inline-actions { display: inline-block; margin: 0 0.5rem 0.5rem 0; }
@media (max-width: 480px) {
    .player { padding: 1rem; }
    .player-main .player-btn:not(.player-play) { flex: 1 1 45%; justify-content: center; }
    .player-play { flex: 1 1 100%; order: -1; }
}
/* ปุ่มลบในหน้าผู้อ่าน: ตัวอักษรสีอันตรายบนพื้นปกติ ต่างจากปุ่มหลักทั้งสีและกรอบ */
button.danger { color: var(--danger); background: var(--surface); border: 2px solid var(--danger); }
button.danger:hover { background: var(--bg-alt); }
/* ย่อหน้าที่เสียงอ่านกำลังอ่าน — พื้นและเส้นข้าง ไม่ใช้สีอย่างเดียว */
.section-body .tts-current { background: var(--primary-soft); box-shadow: inset 4px 0 0 var(--primary); padding-left: 0.75rem; border-radius: 4px; }
.screen-form { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: end; margin: 1.5rem 0; }

/* แผ่นรับคีย์ลัด (2.6.2) — ชิ้นเดียวที่เป็น role=application ปุ่มอื่นอยู่ในหน้าตามปกติ */
.player-keys {
    padding: 0.6rem 0.9rem;
    border: 2px dashed var(--border);
    border-radius: 10px;
    color: var(--text);
    background: var(--surface);
    cursor: pointer;
}
.player-keys:focus-visible { outline: 4px solid var(--primary); outline-offset: 2px; border-style: solid; border-color: var(--primary); }
.player-now { margin: 0; font-size: 1.05rem; }
.player-note { margin: 0; padding: 0.6rem 0.9rem; border-left: 4px solid var(--primary); background: var(--surface); }
.continued-title { margin-top: 2rem; }
/* ปุ่มในแผงตั้ง display เอง จึงต้องบังคับให้ hidden ซ่อนจริง */
.player [hidden], .upload-progress[hidden], .upload-progress [hidden] { display: none !important; }
.player-wide { grid-column: 1 / -1; }

/*
 * แบนเนอร์ประชาสัมพันธ์บนหน้าแรก (2.12)
 * แสดงนิ่งเรียงกัน ไม่เลื่อนสลับ รูปย่อตามความกว้างและไม่ถูกตัด เพราะรูปที่มีข้อความถูกตัดแล้วอ่านไม่ได้
 */
.banners { display: grid; gap: 1rem; margin: 1.5rem 0; }
.banners > h2 { margin: 0; }
.banner { display: grid; gap: 1rem; padding: 1rem 1.25rem; border: 1px solid var(--border); border-left: 6px solid var(--primary); border-radius: 0.75rem; background: var(--bg-alt); }
.banner-with-image { grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); align-items: center; }
.banner-image { width: 100%; height: auto; max-height: 20rem; object-fit: contain; border-radius: 0.5rem; }
.banner-text h3 { margin-top: 0; }
.banner-text p:last-child { margin-bottom: 0; }
.banner-link { font-weight: 700; }
@media (max-width: 640px) { .banner-with-image { grid-template-columns: 1fr; } }

/* หน้าติดต่อและแผนที่ (2.12) */
.contact-list { padding-left: 1.25rem; }
.contact-list li { margin: 0.5rem 0; }
.contact-note { color: var(--text-muted, inherit); }
.map-frame { display: block; width: 100%; height: min(70vh, 32rem); border: 1px solid var(--border); border-radius: 0.5rem; }

/* สื่อออนไลน์ (2.14) — ตัวเล่นวิดีโอสัดส่วน 16:9 คลิปแนวตั้งและโพสต์สูงกว่า ตัวเล่นเสียงเตี้ย */
.media-list { padding-left: 1.25rem; }
.media-list li { margin: 0.6rem 0; }
.media-facts, .media-note-short, .media-platform { color: var(--text-muted, inherit); }
.media-note { border-left: 4px solid var(--primary); padding: 0.25rem 0 0.25rem 1rem; margin: 1rem 0; }
.media-frame { display: block; width: 100%; max-width: 56rem; aspect-ratio: 16 / 9; height: auto; border: 1px solid var(--border); border-radius: 0.5rem; }
.media-frame-tall { max-width: 26rem; aspect-ratio: 9 / 16; }
.media-frame-audio { aspect-ratio: auto; height: 10rem; }
.media-error { border-left: 4px solid var(--danger, #b00020); padding-left: 0.75rem; }
.search-others { margin-top: 2rem; }
.results-others li { margin: 0.6rem 0; }
.result-summary { color: var(--text-muted, inherit); }
.inline-form { display: inline; }

/* เครื่องเล่นพ็อดแคสต์ (2.15) — ปุ่มใหญ่ แตะง่ายบนโทรศัพท์ และไม่พึ่งสีอย่างเดียว */
.podcast-player { border: 1px solid var(--border); border-radius: 0.75rem; padding: 1rem; margin: 1rem 0; max-width: 44rem; }
.podcast-player audio { width: 100%; }
.pp-controls { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.pp-controls button { min-height: 2.75rem; min-width: 2.75rem; padding: 0.5rem 1rem; font-size: 1.05rem; }
.pp-controls .pp-play { font-weight: 700; min-width: 9rem; }
.pp-clock { font-variant-numeric: tabular-nums; font-size: 1.25rem; margin: 0.75rem 0 0.25rem; }
.pp-field { display: flex; flex-direction: column; gap: 0.25rem; margin: 0.5rem 0; }
.pp-field input[type=range] { width: 100%; min-height: 2.75rem; }
.pp-settings { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; }
.pp-settings .pp-field { min-width: 12rem; flex: 1 1 12rem; }
.pp-check { display: flex; gap: 0.5rem; align-items: center; min-height: 2.75rem; }
.pp-pad { border: 2px dashed var(--border); border-radius: 0.5rem; padding: 0.75rem; margin: 0.75rem 0; }
.pp-pad:focus { outline: 3px solid var(--focus, var(--primary)); outline-offset: 2px; border-style: solid; }
.player-resume { font-weight: 600; }
