/* ==========================================================
   css/library.css — hipSea Library Component Library
   ตาม _library-src/HCS-v1.1.md §4 (Article Skeleton)
   โทนสีอิงกับระบบ Article ที่มีอยู่แล้ว (แดง #e74c3c, การ์ดโค้งมน
   เงาเบา, ฟอนต์ Open Sans) ให้กลืนกับเว็บเดิม ไม่แยกธีมใหม่
   ========================================================== */

/* ---------- หน้ารายการ (library.php) ---------- */
/* Hero: สไลด์รูปจริงจาก images/hero/ แบบเดียวกับ .article-hero ใน article.php
   (ใช้ชื่อคลาสแยก lib-hero-* เพื่อไม่ชนกับ inline <style> ของ article.php แต่พฤติกรรม/สัดส่วนเหมือนกัน) */
.lib-hero {
    position: relative;
    height: 340px;
    overflow: hidden;
    background: #0a1428;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: #fff;
}
.lib-hero-slide {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-size: cover;
    background-position: center;
    opacity: 0;
    transition: opacity 1.4s ease-in-out;
    z-index: 1;
}
.lib-hero-slide.active { opacity: 1; }
.lib-hero-overlay {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(rgba(10,20,40,.45), rgba(10,20,40,.68));
    z-index: 2;
}
.lib-hero-inner { position: relative; z-index: 3; padding: 0 20px; }
.lib-hero h1 {
    font-family: 'Open Sans', sans-serif;
    font-weight: 800;
    font-size: 60px;
    margin: 0 0 16px;
    letter-spacing: .5px;
    text-shadow: 0 2px 18px rgba(0,0,0,.5);
}
.lib-hero p {
    font-size: 18px;
    max-width: 560px;
    margin: 0 auto;
    opacity: .95;
    text-shadow: 0 1px 10px rgba(0,0,0,.5);
}
.lib-hero-dots {
    position: absolute; bottom: 16px; left: 0; right: 0;
    text-align: center; z-index: 4;
}
.lib-hero-dots span {
    display: inline-block; width: 9px; height: 9px;
    border-radius: 50%; background: rgba(255,255,255,.45);
    margin: 0 4px; cursor: pointer; transition: background .2s, transform .2s;
}
.lib-hero-dots span.active { background: #e74c3c; transform: scale(1.3); }
@media (max-width: 640px) {
    .lib-hero { height: 240px; }
    .lib-hero h1 { font-size: 32px; }
    .lib-hero p { font-size: 14px; }
}

.lib-wrap { padding: 3em 0; background: #f8f9fa; }
.lib-empty, .lib-empty-vol { text-align: center; padding: 3em 1em; color: #999; }

.lib-volume { max-width: 960px; margin: 0 auto 3em; background: #fff; border-radius: 8px; box-shadow: 0 3px 14px rgba(0,0,0,.08); overflow: hidden; }

/* Volume cover (รูปปกเล่ม แบบ book-cover thumbnail ด้านซ้าย) + head —
   คลิก/Enter/Space เพื่อ toggle แสดง-ซ่อนการ์ดบทของเล่มนี้ */
.lib-volume-toggle { cursor: pointer; display: flex; flex-wrap: wrap; align-items: stretch; }
.lib-volume-toggle:focus { outline: 2px solid #e74c3c; outline-offset: -2px; }
.lib-volume-cover-thumb {
    position: relative;
    flex: 0 0 240px;
    max-width: 240px;
    min-height: 180px;
    overflow: hidden;
    background: linear-gradient(135deg, #0a1428, #1b3a55);
}
.lib-volume-cover-thumb img {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    object-fit: cover;
    display: block;
}
.lib-volume-cover-thumb.lib-thumb-broken { background: linear-gradient(135deg, #0a1428, #1b3a55); }
.lib-volume-cover-icon {
    position: absolute;
    right: 12px; bottom: 12px;
    z-index: 2;
    width: 30px; height: 30px;
    border-radius: 50%;
    background: rgba(255,255,255,.92);
    color: #e74c3c;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,.25);
    transition: transform .25s ease;
}
.lib-volume.is-open .lib-volume-cover-icon { transform: rotate(180deg); }
@media (max-width: 640px) {
    .lib-volume-cover-thumb { flex: 1 1 100%; max-width: 100%; height: 160px; min-height: 0; }
}

.lib-volume-head {
    flex: 1 1 260px;
    padding: 26px 30px;
    border-left: 6px solid #e74c3c;
    background: #fdfdfd;
    border-bottom: 1px solid #eee;
}
.lib-volume-number {
    display: inline-block;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: #e74c3c;
    margin-bottom: 6px;
}
.lib-volume-head h2 {
    margin: 0 0 8px;
    font-family: 'Open Sans', sans-serif;
    font-weight: 700;
    font-size: 26px;
    color: #222;
}
.lib-volume-en { font-size: 15px; font-weight: 400; color: #999; }
.lib-volume-subtitle { margin: 0 0 8px; color: #777; font-size: 14px; line-height: 1.7; }
.lib-volume-hint { display: inline-block; font-size: 12px; color: #e74c3c; font-weight: 600; }

/* ปิดไว้ก่อนตาม default — คลิก cover/head แล้วค่อยเปิด (.is-open)
   แบ่ง 3 ช่องต่อแถวบนจอปกติ (grid แทน flex เพื่อคุมจำนวนคอลัมน์ตรงๆ) */
.lib-chapter-grid { display: none; grid-template-columns: repeat(3, 1fr); padding: 20px; gap: 18px; }
.lib-volume.is-open .lib-chapter-grid { display: grid; }
@media (max-width: 860px) {
    .lib-chapter-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
    .lib-chapter-grid { grid-template-columns: 1fr; }
}
.lib-chapter-card {
    display: block;
    overflow: hidden;
    border: 1px solid #eee;
    border-radius: 6px;
    text-decoration: none;
    color: inherit;
    background: #fff;
    transition: transform .2s ease, box-shadow .2s ease;
}
.lib-chapter-card:hover, .lib-chapter-card:focus {
    transform: translateY(-4px);
    box-shadow: 0 8px 20px rgba(0,0,0,.12);
    text-decoration: none;
    color: inherit;
    border-color: #e74c3c;
}
/* รูปประกอบบนการ์ดบท — แบบเดียวกับ .art-thumb ในหน้า article.php */
.lib-chapter-thumb {
    position: relative;
    width: 100%;
    padding-top: 56%;
    overflow: hidden;
    background: #f2f2f2;
}
.lib-chapter-thumb img {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    object-fit: cover;
    transition: transform .35s ease;
}
.lib-chapter-card:hover .lib-chapter-thumb img { transform: scale(1.05); }
.lib-chapter-thumb.lib-thumb-broken { background: linear-gradient(135deg, #eef1f4, #e2e6ea); }
.lib-chapter-body { padding: 18px 20px 20px; }
.lib-chapter-num { font-size: 11px; font-weight: 700; color: #999; text-transform: uppercase; letter-spacing: .5px; }
.lib-chapter-card h3 { margin: 6px 0 8px; font-size: 17px; font-weight: 700; color: #222; font-family: 'Open Sans', sans-serif; }
.lib-chapter-summary { font-size: 13px; color: #777; line-height: 1.7; margin: 0 0 14px; }
.lib-chapter-meta { display: flex; align-items: center; justify-content: space-between; }
.lib-chapter-reading { font-size: 12px; color: #999; }

/* ---------- badge (difficulty / evidence) ---------- */
.badge--difficulty, .badge--evidence {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 20px;
    letter-spacing: .3px;
}
.badge--beginner     { background: #eafaf0; color: #1e8a4c; }
.badge--intermediate { background: #fff6e5; color: #b8790b; }
.badge--advanced     { background: #fdeaea; color: #c0392b; }
.badge--peer-reviewed { background: #eaf4fe; color: #2980b9; }
.badge--mixed         { background: #f3ecfc; color: #7d3fc9; }
.badge--anecdotal     { background: #f5f5f5; color: #666; }

/* ---------- หน้าอ่าน (library-read.php) — Article Skeleton ---------- */
.hs-article { display: block; }
.article-header {
    background: #0e1f2b;
    color: #fff;
    padding: 30px 0 34px;
}
.breadcrumb-lib { font-size: 13px; color: rgba(255,255,255,.65); margin-bottom: 14px; }
.breadcrumb-lib a { color: rgba(255,255,255,.85); text-decoration: none; }
.breadcrumb-lib a:hover { color: #fff; text-decoration: underline; }
.breadcrumb-lib .sep { margin: 0 6px; opacity: .5; }
.breadcrumb-lib .current { color: #fff; }

.article-title {
    font-family: 'Open Sans', sans-serif;
    font-weight: 800;
    font-size: 34px;
    margin: 0 0 12px;
    line-height: 1.3;
}
.article-summary { font-size: 15px; line-height: 1.8; color: rgba(255,255,255,.85); max-width: 720px; margin: 0 0 18px; }

.article-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; font-size: 13px; color: rgba(255,255,255,.75); }
.article-meta .meta-chapter, .article-meta .meta-volume, .article-meta .meta-reading, .article-meta .meta-updated { white-space: nowrap; }

.figure--hero { margin: 24px 0 0; }
.figure--hero img { width: 100%; max-height: 420px; object-fit: cover; border-radius: 6px; }
.figure--hero .figure-credit { font-size: 11px; color: rgba(255,255,255,.5); margin-top: 6px; }

/* TOC */
.table-of-content {
    max-width: 800px;
    margin: 30px auto 0;
    padding: 18px 22px;
    background: #f8f9fa;
    border-radius: 6px;
    border: 1px solid #eee;
}
.table-of-content .toc-heading { margin: 0 0 8px; font-size: 13px; font-weight: 700; color: #999; text-transform: uppercase; letter-spacing: .5px; }
.table-of-content ul { list-style: none; margin: 0; padding: 0; }
.table-of-content li { margin: 4px 0; }
.table-of-content li a { color: #2980b9; text-decoration: none; font-size: 14px; }
.table-of-content li a:hover { text-decoration: underline; }
.table-of-content .toc-level-3 { padding-left: 18px; font-size: 13px; }

/* Body */
.article-body { max-width: 800px; margin: 0 auto; padding: 30px 0 10px; }
.article-body section { margin-bottom: 34px; }
.article-body h2 { font-size: 24px; font-weight: 700; color: #222; margin: 0 0 16px; font-family: 'Open Sans', sans-serif; }
.article-body h3 { font-size: 18px; font-weight: 700; color: #222; margin: 20px 0 10px; }
.article-body p { font-size: 15px; line-height: 1.9; color: #444; margin: 0 0 16px; text-indent: 6ch; }
.article-body a { color: #e74c3c; }

/* ย่อหน้าในกล่อง callout / คำอธิบายรูป / ตาราง / สมการ / TOC ไม่ควรมีการเยื้องบรรทัดแรก
   (จำกัดเฉพาะย่อหน้าเนื้อหาหลักของบทความเท่านั้น) */
.article-body aside p,
.article-body .figure p,
.article-body .figure figcaption,
.article-body .table-wrap p,
.article-body .equation p,
.article-body li p {
    text-indent: 0;
}

/* รายการแบบจุด/ตัวเลข — ให้เครื่องหมายอยู่ในกรอบเนื้อหา ไม่ยื่นล้ำออกไปทางซ้าย */
.article-body ul,
.article-body ol {
    margin: 0 0 16px;
    padding-left: 1.5em;
}
.article-body li {
    font-size: 15px;
    line-height: 1.9;
    color: #444;
    margin: 0 0 8px;
}
.article-body li:last-child { margin-bottom: 0; }
.article-body li > ul,
.article-body li > ol {
    margin-top: 8px;
}

/* Callouts */
.article-body aside {
    padding: 16px 20px;
    margin: 20px 0;
    border-radius: 0 6px 6px 0;
    border-left: 4px solid;
    font-size: 14px;
    line-height: 1.8;
}
.article-body aside p:last-child { margin-bottom: 0; }
.article-body aside.tip        { background: #eafaf0; border-color: #1e8a4c; }
.article-body aside.warning    { background: #fdeaea; border-color: #c0392b; }
.article-body aside.key-point  { background: #fff6e5; border-color: #b8790b; }
.article-body aside.science    { background: #eaf4fe; border-color: #2980b9; }
.article-body aside.definition { background: #f3ecfc; border-color: #7d3fc9; }
.article-body aside.reef       { background: #e6f7fb; border-color: #1B7A8C; }
.article-body aside.myth       { background: #f5f5f5; border-color: #888; }
.article-body aside .definition-title { font-weight: 700; margin: 0 0 6px; color: #7d3fc9; }

/* Figure / Table / Equation */
.article-body .figure { margin: 24px 0; text-align: center; }
.article-body .figure img { max-width: 100%; height: auto; border-radius: 6px; box-shadow: 0 2px 14px rgba(0,0,0,.1); }
.article-body .figure figcaption { font-size: 13px; color: #777; margin-top: 8px; }
.article-body .figure .figure-credit { font-size: 11px; color: #aaa; }
.article-body .figure--illus img { box-shadow: none; opacity: .9; }
.article-body .figure-missing {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 160px; border: 2px dashed #e0d9d2; border-radius: 6px;
    background: #faf8f6; color: #b0a89e; font-size: 14px;
}
.article-body .figure-missing i { font-size: 20px; }

.article-body .table-wrap { margin: 24px 0; overflow-x: auto; }
.article-body .table-wrap figcaption { font-size: 13px; color: #777; margin-bottom: 10px; font-weight: 600; }
.article-body .table-wrap table { width: 100%; border-collapse: collapse; font-size: 14px; }
.article-body .table-wrap th, .article-body .table-wrap td { padding: 10px 14px; border: 1px solid #eee; text-align: left; }
.article-body .table-wrap th { background: #f8f9fa; font-weight: 700; color: #222; }

.article-body .equation {
    margin: 24px 0;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 6px;
    text-align: center;
    overflow-x: auto;
}
.article-body .equation p { font-size: 12px; color: #999; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .5px; }

/* Glossary term tooltip */
.term { border-bottom: 1px dashed #e74c3c; color: #e74c3c; cursor: help; position: relative; }
.term-tooltip {
    display: none;
    position: absolute;
    z-index: 20;
    bottom: 100%;
    left: 0;
    width: 260px;
    background: #222;
    color: #fff;
    font-size: 12px;
    line-height: 1.7;
    padding: 12px 14px;
    border-radius: 6px;
    margin-bottom: 8px;
}
.term-tooltip a { color: #ffb6a3; }
.term:hover .term-tooltip, .term:focus .term-tooltip { display: block; }

/* Reference footnote mark */
.ref-mark a { color: #e74c3c; text-decoration: none; font-size: 12px; }

/* FAQ */
.faq { max-width: 800px; margin: 0 auto 20px; }
.faq h2 { font-size: 22px; font-weight: 700; color: #222; margin: 0 0 16px; }
.faq-item { padding: 16px 0; border-bottom: 1px solid #eee; }
.faq-item h3 { font-size: 15px; font-weight: 700; color: #222; margin: 0 0 8px; }
.faq-item p { font-size: 14px; color: #555; line-height: 1.8; margin: 0; }

/* Footer: references / related / chapter-nav */
.article-footer { max-width: 800px; margin: 0 auto; padding: 20px 0 60px; }
.references { list-style: none; margin: 0 0 30px; padding: 18px 20px; background: #f8f9fa; border-radius: 6px; font-size: 13px; color: #666; line-height: 1.9; }
.references li { margin-bottom: 8px; }
.references .ref-icon { margin-right: 4px; }
.references a { color: #2980b9; }

.related { margin: 0 0 30px; }
.related-heading { font-size: 13px; font-weight: 700; color: #999; text-transform: uppercase; letter-spacing: .5px; margin: 0 0 10px; }
.related ul { list-style: none; margin: 0; padding: 0; }
.related li { display: inline-block; margin: 0 8px 8px 0; }
.related a {
    display: inline-block;
    background: #eaf4fe;
    color: #2980b9;
    font-size: 13px;
    padding: 6px 14px;
    border-radius: 16px;
    text-decoration: none;
}
.related a:hover { background: #2980b9; color: #fff; }

.chapter-nav { display: flex; justify-content: space-between; gap: 16px; margin: 0 0 24px; border-top: 1px solid #eee; padding-top: 20px; }
.chapter-nav a { flex: 1; text-decoration: none; padding: 14px 16px; border: 1px solid #eee; border-radius: 6px; transition: border-color .2s; }
.chapter-nav a:hover { border-color: #e74c3c; text-decoration: none; }
.chapter-nav-next { text-align: right; }
.chapter-nav-label { display: block; font-size: 11px; color: #999; text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px; }
.chapter-nav-title { display: block; font-size: 14px; font-weight: 700; color: #222; }

.lib-back { text-align: center; margin-top: 10px; }

@media (max-width: 640px) {
    .article-title { font-size: 26px; }
    .article-body { padding: 20px 16px 10px; }
    .table-of-content { margin: 20px 16px 0; }
    .article-footer { padding: 20px 16px 40px; }
    .chapter-nav { flex-direction: column; }
    .chapter-nav-next { text-align: left; }
}
