  :root{
    --bg:#fcf9f4;
    --ink:#14151A;
    --ink-soft:#20201f;
    --accent:#2f629b;
    --accent-soft:rgba(13,71,161,0.1);
    --line:rgba(32,32,31,1);
    --line-strong:rgba(32,32,31,1);
    --card-bg:#FFFFFF;
    --card-border:#20201f;
    --font-display:'Mitr',sans-serif;
    --font-body:'Mitr',sans-serif;
    --font-mono:'Mitr',sans-serif;

    /* หาอ่าน brand palette */
    --brand-yellow:#eac653;
    --brand-navy:#2f629b;
    --brand-peach:#f99a7d;
    --brand-sage:#d9dfd3;
    --brand-orange-red:#ef6343;
    --brand-dark-navy:#2a3c51;
    --brand-ochre:#af8358;
    --brand-ice-blue:#d8e2e9;
    --brand-dark-grey:#3f3f3f;

    /* ===== สีไอคอน — แก้ตรงนี้ที่เดียว ปุ่มไอคอนทั้งเว็บ (about, donate, ปิด modal, ลิงก์ ↗) จะเปลี่ยนตาม =====
       หมายเหตุ: ไอคอนพวกนี้เป็น svg ที่ใช้ stroke/fill="currentColor" เวลา inspect เลยไม่เห็นค่าสีตรงๆ ในตัว svg
       เอง ต้องไล่ขึ้นไปดูที่ property "color" ของ element ที่ครอบมันอยู่แทน (เช่น .icon-btn) ซึ่งตอนนี้ผูกกับ
       ตัวแปรสองตัวนี้แล้ว */
    --icon-color:var(--ink-soft);        /* สีไอคอนตอนปกติ */
    --icon-color-hover:var(--accent);    /* สีไอคอนตอน hover/โฟกัส */

    /* ===== สีตัวอักษร/ไอคอนตอนอยู่บนพื้นหลังที่ใส่สีทึบแล้ว (ปุ่ม active, hover ที่เปลี่ยนพื้นเป็นสี, badge ผล
       การเช็คสถานะ, ปุ่มค้นหา) เดิมกระจายเป็น #fff ซ้ำๆ กันหลายจุดในไฟล์นี้ รวบมาไว้ตัวเดียวตรงนี้ ===== */
    --fg-inverse:#fff;

    /* ===== พื้นหลังทึบ/เงา — อิงจากสี --ink (20,21,26) เดิมพิมพ์เลข rgb ซ้ำๆ กันหลายจุด ปรับแค่ความโปร่งใส
       ต่างกันตามแต่ละจุดใช้งาน (modal เข้มน้อยสุด, loading เข้มสุด) ===== */
    --overlay-modal:rgba(20,21,26,0.45);       /* ฉากหลังทึบตอนเปิด modal */
    --overlay-loading:rgba(20,21,26,0.6);      /* ฉากหลังทึบตอนโหลด */
    --overlay-tutorial:rgba(20,21,26,0.4);     /* ฉากหลังทึบตอนโชว์ tutorial สไลด์การ์ดมือถือ */
    --shadow-card-hover:rgba(20,21,26,0.06);   /* เงาการ์ดตอน hover บน desktop */
    --shadow-stack-card:rgba(20,21,26,0.12);   /* เงาการ์ดแบบ stack บนมือถือ */
    --shadow-magnifier:rgba(0,0,0,0.45);       /* เงาไอคอนแว่นขยายตอน loading */
    --arrow-glow:rgba(255,255,255,0.92);       /* สีลูกศร swipe tutorial บนมือถือ */

    /* ===== ชุดตัวแปรสไตล์ "neobrutalism" (ขอบดำหนา + เงาทึบ offset ไม่มี blur) — แยกจากตัวแปรด้านบนทั้งหมด
       ใช้คู่กับ class .neo-card / .neo-image / .neo-btn / .neo-pill ด้านล่างของไฟล์นี้เท่านั้น ไม่กระทบสไตล์เดิม
       ปรับค่าตรงนี้ที่เดียว ทุกจุดที่ใส่ class .neo-* จะเปลี่ยนตาม ===== */
    --neo-border-color:#14151A;
    --neo-border-width:2.5px;
    --neo-shadow-color:#14151A;
    --neo-shadow-offset:6px;
    --neo-radius-card:10px;
    --neo-radius-image:10px;
    --neo-radius-pill:999px;
  }

  *{box-sizing:border-box;}
  html,body{margin:0;padding:0;}

  /* ===== SEO: ซ่อนไว้ทางสายตา แต่ search engine / screen reader ยังอ่านได้ (มาตรฐานทั่วไป ไม่ใช่การโกง)
     ใช้กับ H1 ของหน้าแรก เพราะ header จริงเป็นโลโก้รูปภาพ ไม่อยากยัดข้อความยาวๆ ลงไปทับ design ที่ยังพัฒนาอยู่
     ถ้าวันไหน design นิ่งแล้วอยากโชว์ H1 นี้จริงๆ ลบ class นี้ออกจาก <h1> ใน index.html ได้เลย ===== */
  .visually-hidden{
    position:absolute;
    width:1px;
    height:1px;
    padding:0;
    margin:-1px;
    overflow:hidden;
    clip:rect(0,0,0,0);
    white-space:nowrap;
    border:0;
  }
  body{
    background:var(--bg);
    color:var(--ink);
    font-family:var(--font-body);
    -webkit-font-smoothing:antialiased;
    min-height:100vh;
  }

  a,button,select,input{font-family:inherit;}
  button{cursor:pointer;}

  /* ---------- Top bar ---------- */
  .topbar{
    max-width:1220px;
    margin:0 auto;
    padding:48px 32px 28px;
    /* padding-top ของ <body> (ไม่ใช่ตรงนี้) ถูกตั้งค่าด้วย JS (applyLandingOffset ใน index.html) ตอนอยู่ใน
       สถานะ "landing" เพื่อดัน topbar ทั้งก้อนลงไปกึ่งกลางจอ (เดิมเคยลองใช้ margin-top ตรงนี้ตรงๆ แต่ margin
       ของลูกคนแรกใน body จะ collapse ทะลุออกไปนอก body ทำให้หน้าเว็บสูงเกิน viewport เปลี่ยนไปใช้ padding-top
       บน body แทนแล้ว) ตั้งใจไม่ใส่ transition ไว้ตรงนี้แบบถาวร เพราะตอนโหลดหน้าครั้งแรกจะเห็น topbar เลื่อนแบบ
       ไม่ได้ตั้งใจ (อยากให้ตอนโหลดครั้งแรกกระโดดไปอยู่ตำแหน่ง landing เลยทันที ไม่มี animation) — transition
       จะถูกเติมด้วย JS เฉพาะตอนออกจากสถานะ landing เท่านั้น (ดูฟังก์ชัน leaveLandingMode) */
  }
  /* สถานะหน้า landing (ก่อนค้นหาครั้งแรก) */
  /* 1) ซ่อนผลลัพธ์/ข้อความ empty-state ไว้ก่อน เพราะตอนนี้ยังไม่มีอะไรให้โชว์อยู่แล้ว (ยังไม่ได้ค้นหา) การซ่อนไว้
        ช่วยไม่ให้ข้อความ "พิมพ์ชื่อหนังสือ..." โผล่มาแทรกใต้ topbar ที่จัดกลางจอ */
  body.landing #results{display:none;}
  /* 2) บีบ .topbar ให้แคบลงเป็นก้อนกะทัดรัดกึ่งกลางจอ (แทนที่จะกว้างเต็ม 1220px แบบปกติ) — จุดประสงค์หลักคือ
        ทำให้ .search-row (ช่องค้นหา + ปุ่ม) แคบลงเหมือนกล่องค้นหาของ Google ไม่ใช่ยืดเต็มจอ ใช้ max-width เพราะ
        animate แบบ smooth ตอน leaveLandingMode() ได้ (ดู JS) ต่าง .topbar-head ด้านล่างที่ overwrite
        justify-content ตรงๆ เลย เพราะแค่บีบความกว้างเฉยๆ ไม่พอที่จะดึง logo (ชิดซ้าย) กับปุ่มไอคอน (ชิดขวา)
        เข้ามาเป็นกลุ่มกึ่งกลางเดียวกันได้ — space-between จะยังดันสุดขอบซ้าย/ขวาของกล่อง 640px อยู่ดี ต้อง
        เปลี่ยนเป็น center ตรงๆ ถึงจะได้ผลลัพธ์แบบในภาพ mockup (justify-content เปลี่ยนค่าแบบ animate ไม่ได้ก็จริง
        แต่ไม่มีปัญหา เพราะการสลับเกิดพร้อมกับตอนเอา class landing ออก ซึ่งเนื้อหาข้างในมันแคบพอที่จะขยับแค่
        นิดเดียวจนแทบไม่สังเกตเห็นการกระตุก) */
  body.landing .topbar{max-width:640px;}
  body.landing .topbar-head{justify-content:center;}
  /* 3) meta-row (แถวใต้ช่องค้นหา) ปกติใช้ space-between: result-summary (ข้อความ "เจอ N เล่ม") ชิดซ้าย,
        meta-controls (ปุ่ม "ใกล้ฉันที่สุด" + dropdown filter) ชิดขวา — ตอน landing ยังไม่ได้ค้นหา
        result-summary เลยว่างเปล่าอยู่แล้ว (แค่ &nbsp;) เลยซ่อนไปเลย แล้วสลับ meta-row เป็น center แทน
        ทำให้เหลือแค่ meta-controls กลุ่มเดียวลอยอยู่กึ่งกลาง เหมือนใน mockup */
  body.landing .result-summary{display:none;}
  body.landing .meta-row{justify-content:center;}
  .brand{
    display:flex;
    align-items:center;
  }
  .brand img{height:100px;width:auto;display:block;}
  @media (max-width:640px){
    .brand img{height:74px;}
  }

  .topbar-head{
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:12px;
    margin-bottom:22px;
  }
  .topbar-actions{display:flex; gap:8px; flex-shrink:0;}
  .icon-btn{
    width:38px;
    height:38px;
    border-radius:50%;
    border:1.5px solid var(--line);
    background:var(--card-bg);
    display:flex;
    align-items:center;
    justify-content:center;
    color:var(--icon-color);
    flex-shrink:0;
    transition:border-color .15s ease, background .15s ease, color .15s ease;
    outline:none;
  }
  .icon-btn svg{width:19px; height:19px;}
  .icon-btn:hover{border-color:var(--icon-color-hover); color:var(--icon-color-hover); background:var(--accent-soft);}
  .icon-btn:focus-visible{outline:2px solid var(--icon-color-hover); outline-offset:2px;}

  /* ---------- Search ---------- */
  .search-row{
    display:flex;
    gap:10px;
    align-items:stretch;
    margin-top:6px;
  }
  .search-box{
    flex:1;
    min-width:0;
    background:var(--card-bg);
    border:1.5px solid var(--line);
    border-radius:12px;
    padding:16px 18px;
    font-size:16px;
    font-family:var(--font-body);
    color:var(--ink);
    outline:none;
    transition:border-color .15s ease, box-shadow .15s ease;
  }
  .search-box:focus{
    border-color:var(--accent);
    box-shadow:0 0 0 4px var(--accent-soft);
  }
  .search-box::placeholder{color:var(--ink-soft);}
  .search-box:disabled{opacity:.6; cursor:not-allowed;}

  .search-btn{
    flex-shrink:0;
    background:var(--brand-dark-grey);
    color:var(--fg-inverse);
    border:none;
    border-radius:12px;
    padding:0 26px;
    font-size:15px;
    font-weight:600;
    font-family:var(--font-display);
    letter-spacing:0.01em;
    transition:background .15s ease, opacity .15s ease;
  }
  .search-btn:hover:not(:disabled){background: var(--brand-orange-red);;}
  .search-btn:disabled{opacity:.5; cursor:not-allowed;}

  .meta-row{
    display:flex;
    justify-content:space-between;
    align-items:center;
    gap:16px;
    margin-top:16px;
    flex-wrap:wrap;
  }
  .result-summary{
    font-size:13px;
    color:var(--ink-soft);
    font-family:var(--font-mono);
    min-height:18px;
  }
  .source-select{
    appearance:none;
    -webkit-appearance:none;
    background:var(--card-bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236B7280' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 14px center;
    border:1.5px solid var(--line);
    border-radius:10px;
    height:44px;
    box-sizing:border-box;
    padding:0 34px 0 14px;
    /* line-height สูงกว่าปกติ เพื่อกันไม่ให้วรรณยุกต์ไทย (เช่น ไม้โท) ที่ลอยเหนือตัวอักษรโดนตัดขอบบน
       (บั๊กที่พบใน native <select> บางเบราว์เซอร์ โดยเฉพาะ Safari ที่คำนวณความสูงบรรทัดแคบเกินไปสำหรับฟอนต์ไทย) */
    line-height:1.9;
    font-size:13px;
    color:var(--ink);
    cursor:pointer;
    transition:border-color .15s ease;
  }
  .source-select:focus{outline:none; border-color:var(--accent);}
  .source-select:disabled{opacity:.6; cursor:not-allowed;}

  /* ---------- Popular searches (SEO: คำค้นหายอดนิยม) ----------
     เพิ่มเข้ามาวันที่ 28 ก.ค. 2569 เป็น tag เรียงซ้ายใต้ filter ห้องสมุด ตั้งใจทำเรียบง่ายก่อน
     เพราะ design หลักของเว็บยังพัฒนาอยู่ ค่อยกลับมา restyle ทีหลังได้เมื่อ design นิ่งแล้ว ---------- */
  .popular-searches{
    margin-top:16px;
  }
  .popular-searches-label{
    font-size:12.5px;
    color:var(--ink-soft);
    font-family:var(--font-mono);
    margin-bottom:8px;
  }
  .popular-tags{
    display:flex;
    flex-wrap:wrap;
    gap:8px;
  }
  .popular-tag{
    border:1.5px solid var(--line);
    background:var(--card-bg);
    color:var(--ink);
    border-radius:999px;
    padding:6px 14px;
    font-size:13px;
    font-family:var(--font-body);
    cursor:pointer;
    transition:border-color .15s ease, background .15s ease, color .15s ease;
  }
  .popular-tag:hover:not(:disabled){
    border-color:var(--accent);
    color:var(--accent);
    background:var(--accent-soft);
  }
  .popular-tag:disabled{opacity:.6; cursor:not-allowed;}

  /* ซ่อน tag คำค้นหายอดนิยมบนมือถือหลังจากมีการค้นหาเกิดขึ้น 1 ครั้ง (body.has-searched ตั้งค่าใน leaveLandingMode()
     ใน index.html) คุยกับอาร์ธไว้ 28 ก.ค. 2569 — desktop ไม่กระทบ เพราะมีที่ว่างพอ 640px คือ breakpoint เดียวกับ
     card stack มือถือที่ใช้ทั่วไฟล์นี้
     ต้องใส่ !important เพราะ loadPopularSearches() ใน index.html เซ็ต inline style (element.style.display='block')
     ตรงๆ ตอนโหลดข้อมูลสำเร็จ ซึ่ง inline style มีความสำคัญสูงกว่า CSS จาก class เสมอ ไม่ว่าจะมี @media ครอบหรือไม่ก็ตาม
     ถ้าไม่ใส่ !important กฎนี้จะไม่มีผลเลย (บัคเจอจริง 28 ก.ค. 2569) */
  @media (max-width:640px){
    body.has-searched .popular-searches{display:none !important;}
  }

  .meta-controls{display:flex; gap:8px; align-items:center; flex-wrap:wrap;}
  .nearme-btn{
    position:relative;
    display:flex;
    align-items:center;
    gap:6px;
    height:44px;
    box-sizing:border-box;
    border:1.5px solid var(--line);
    background:var(--card-bg);
    border-radius:10px;
    padding:0 14px;
    font-size:13px;
    color:var(--ink);
    transition:background .15s ease, border-color .15s ease, color .15s ease, opacity .15s ease;
  }
  .nearme-btn:hover:not(:disabled){border-color:var(--line-strong);}
  .nearme-btn.active{
    background:var(--accent);
    border-color:var(--accent);
    color:var(--fg-inverse);
  }
  .nearme-btn:disabled{opacity:.55; cursor:not-allowed;}
  .nearme-icon{width:14px; height:14px; flex-shrink:0;}

  .btn-tooltip{
    position:absolute;
    bottom:calc(100% + 8px);
    left:50%;
    transform:translateX(-50%);
    background:var(--ink);
    color:var(--fg-inverse);
    font-size:11px;
    line-height:1.4;
    padding:5px 10px;
    border-radius:6px;
    white-space:nowrap;
    opacity:0;
    pointer-events:none;
    transition:opacity .15s ease;
    z-index:10;
  }
  .nearme-btn:hover .btn-tooltip{opacity:1;}
  /* คลาสนี้บังคับซ่อน tooltip ทันทีตอนกดปุ่ม กันปัญหา native permission dialog ของ browser
     มาขัดจังหวะ hover state จนทำให้ tooltip ค้างอยู่บนจอ (bug ที่เจอกับ title attribute เดิม) */
  .nearme-btn.tooltip-hidden .btn-tooltip{opacity:0 !important;}

  /* ---------- Results ---------- */
  .results{
    max-width:1220px;
    margin:0 auto;
    padding:8px 32px 90px;
  }
  .empty-state{
    padding:90px 0;
    text-align:center;
    color:var(--ink-soft);
    display:block;
  }
  .empty-state .glyph{
    font-family:var(--font-display);
    font-size:40px;
    color:var(--line-strong);
    margin-bottom:12px;
  }

  /* Desktop: grid การ์ด */
  .book-grid{
    display:grid;
    grid-template-columns:repeat(3, 1fr);
    gap:32px; /* ระยะห่างรอบด้านระหว่างการ์ด (ทั้งแนวนอน-แนวตั้ง) แก้ตัวเลขนี้ตัวเดียวพอ */
  }
  @media (max-width:900px) and (min-width:641px){
    .book-grid{grid-template-columns:repeat(2, 1fr);}
  }

  .book-card{
    border:1.5px solid var(--card-border);
    border-radius:10px;
    padding:20px 18px;
    background:var(--card-bg);
    cursor:pointer;
    transition:border-color .15s ease, transform .15s ease, box-shadow .15s ease;
    display:flex;
    flex-direction:column;
    min-height:230px;
  }
  .book-card:hover{
    /*border-color:var(--line-strong);*/
    border-color:var(--card-border);
    box-shadow:0 4px 16px var(--shadow-card-hover);
    transform:translateY(-2px);
  }
  .card-badge-row{margin-bottom:10px; display:flex; align-items:center; gap:6px; flex-wrap:wrap;}
  /* badge บอกแหล่งที่มา (TK Park / หอสมุดแห่งชาติ / ห้องสมุดมหาวิทยาลัย) ด้านบนการ์ด — ตั้งใจทำแบบไม่มีกรอบ
     (ต่างจาก .lib-badge ด้านล่างการ์ดที่มีกรอบ บอกชื่อสาขาห้องสมุดจริง) กันดูซ้ำซ้อนกัน ใช้แค่ไอคอน + ตัวอักษร
     สีอ้างอิงจาก --stack-title-color ตัวเดียวกับสีหัวข้อหนังสือ (คำนวณไว้แล้วว่าควรเป็นดำหรือขาวตามความเข้ม
     ของสีพื้นหลังการ์ดแต่ละใบ ดูฟังก์ชัน applyStackCoverColor ใน index.html) เลยเข้ากับพื้นหลังทุกสีอัตโนมัติ */
  .source-tag{
    display:inline-flex;
    align-items:center;
    gap:4px;
    font-family:var(--font-mono);
    font-size:14px;
    font-weight:500;
    color:var(--stack-title-color, var(--ink));
  }
  .source-tag-icon{width:12px; height:12px; flex-shrink:0;}
  .card-top-row{
  display:flex;
  align-items:flex-start;
  gap:10px;
  margin-bottom:10px;
}
.card-top-row .card-badge-row{
  flex:1 1 auto;
  margin-bottom:0;
}
.card-cover{
  width:68px;
  height:100px;
  object-fit:cover;
  border-radius:6px;
  border:1px solid var(--line);
  background:var(--bg);
  flex-shrink:0;
}
/* ย้ายมาต่อท้ายข้อความใน .card-title แล้ว (เดิมอยู่มุมขวาบนของการ์ด) ใช้ display:inline-flex เพื่อให้ไหลต่อ
   จากข้อความชื่อหนังสือได้ (flex ธรรมดาจะบังคับขึ้นบรรทัดใหม่) สีอ้างอิง --stack-title-color เหมือนกับ badge
   แหล่งที่มาด้านบนและปุ่ม .card-open-btn ด้านล่าง (เดิมใช้ --icon-color-on-card ที่ fix เป็นสีขาวตายตัว ซึ่งจริงๆ
   มองไม่เห็นบนการ์ดพื้นอ่อน เปลี่ยนมาใช้ตัวแปรที่คำนวณ contrast ตามสีพื้นจริงแทน ถูกต้องกว่า) */
.card-link-out{
  flex-shrink:0;
  width:26px;
  height:26px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  vertical-align:middle;
  margin-left:6px;
  border-radius:6px;
  border:1px solid var(--stack-title-color, var(--ink));
  color:var(--stack-title-color, var(--ink));
  font-size:14px;
  text-decoration:none;
  transition:background .15s ease, color .15s ease, border-color .15s ease;
  -webkit-tap-highlight-color:transparent;
  -webkit-touch-callout:none;
  outline:none;
}
.card-link-out:hover{
  background:var(--icon-color-hover);
  border-color:var(--icon-color-hover);
  color:var(--fg-inverse);
}
/* ปุ่มใหม่ที่มาแทนตำแหน่งเดิมของ .card-link-out (มุมขวาบนของการ์ด) ขอบ stroke เฉยๆ ไม่มีพื้นหลัง หลักการสี
   เดียวกับ .source-tag: พื้นการ์ดเข้ม -> ขาว, พื้นการ์ดอ่อน -> ดำ (ผ่าน --stack-title-color เหมือนกัน) */
.card-open-btn{
  /* เป็น <button> ธรรมดา (ไม่ใช่ <a> ลิงก์ออก) เลยต้องล้างสไตล์ default ของปุ่ม browser เองด้วย (background/
     border ที่ browser ใส่ให้ปุ่มมาโดยปริยาย โดยเฉพาะ Safari) ก่อนใส่สไตล์ของเราทับ */
  background:none;
  appearance:none;
  -webkit-appearance:none;
  flex-shrink:0;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:1px;
  padding:5px 10px;
  border-radius:6px;
  border:1px solid var(--stack-title-color, var(--ink));
  color:var(--stack-title-color, var(--ink));
  font-family:var(--font-display);
  font-size:10.5px;
  font-weight:600;
  line-height:1.3;
  text-align:center;
  text-decoration:none;
  white-space:nowrap;
  transition:background .15s ease, color .15s ease, border-color .15s ease;
  -webkit-tap-highlight-color:transparent;
  -webkit-touch-callout:none;
  outline:none;
}
.card-open-btn:hover{
  background:var(--icon-color-hover);
  border-color:var(--icon-color-hover);
  color:var(--fg-inverse);
}
.stack-card .card-cover{
  width:68px;
  height:100px;
}
  .badge{
    font-family:var(--font-mono);
    font-size:10.5px;
    padding:3px 8px;
    border-radius:5px;
    display:inline-block;
    background:var(--card-bg);
    color:var(--ink);
    border:1px solid var(--ink);
  }
  .badge.distance,
  .badge.tkpark,
  .badge.uctal,
  .badge.nlt{background:var(--card-bg); color:var(--ink); border:1px solid var(--ink);}

  .card-title{
    font-size:19px;
    font-weight:500;
    line-height:1.3;
    margin-bottom:8px;
    /* ลองเอา line-clamp ออกไปช่วงหนึ่ง (ให้การ์ดสูงตามเนื้อหา) แต่เจอชื่อหนังสือยาวมากๆ (เช่น รายการหนังของ
       หอสมุด ที่มีชื่อผู้สร้าง/ผู้กำกับต่อท้ายยาวเป็นย่อหน้า) ทำให้การ์ดสูงเกินไป เลยเอากลับมาจำกัด 2 บรรทัดเหมือนเดิม */
    display:-webkit-box;
    -webkit-line-clamp:2;
    -webkit-box-orient:vertical;
    overflow:hidden;
  }
  .card-libs{
    margin-top:auto;
    display:flex;
    flex-wrap:wrap;
    align-items:center;
    gap:6px;
    color:var(--ink-soft);
  }
  .lib-badge{
    display:inline-block;
    max-width:100%;
    font-family:var(--font-mono);
    font-size:11px;
    line-height:1.5;
    padding:4px 9px;
    border-radius:5px;
    background:var(--card-bg);
    color:var(--ink);
    border:1px solid var(--ink);
  }
  .lib-extra{
    font-family:var(--font-mono);
    font-size:11px;
    color:inherit;
  }

  /* ---------- Modal ---------- */
  .modal-overlay{
    position:fixed; inset:0;
    background:var(--overlay-modal);
    backdrop-filter:blur(2px);
    display:flex;
    align-items:center;
    justify-content:center;
    padding:24px;
    opacity:0;
    pointer-events:none;
    transition:opacity .18s ease;
    z-index:50;
  }
  .modal-overlay.open{opacity:1; pointer-events:auto;}

  .modal{
    background:var(--card-bg);
    border-radius:18px;
    max-width:520px;
    width:100%;
    max-height:85vh;
    overflow-y:auto;
    padding:32px;
    transform:translateY(12px);
    transition:transform .18s ease;
    position:relative;
  }
  .modal-overlay.open .modal{transform:translateY(0);}

  .modal-close{
  position:absolute;
  top:28px;
  right:28px;
  background:none;
  border:none;
  font-size:20px;
  color:var(--icon-color);
  line-height:1;
  padding:4px;
  transition:color .15s ease;
}
/* เดิมปุ่มปิดไม่มี hover เลย เพิ่มให้เข้าชุดกับปุ่มไอคอนอื่นๆ (about/donate/link-out) */
.modal-close:hover{color:var(--icon-color-hover);}
/* เดิมเป็นไอคอนเปล่าๆ สี่เหลี่ยม 26x26px ลอยมุมขวาบน ตอนนี้ใส่ข้อความ "ไปห้องสมุด" เข้าไปด้วยแล้ว (ดู
   openModal() ใน index.html) เลยเปลี่ยนจากกล่องสี่เหลี่ยมตายตัวเป็นปุ่มแคปซูลที่กว้างตามเนื้อหา ใช้ position:static
   อยู่แล้วเพราะ render อยู่ใน .modal-actions (flex row ร่วมกับปุ่มปิด) ตลอด เลยตัด position:absolute เดิมทิ้งได้ */
.modal-link-out{
  display:inline-flex;
  align-items:center;
  gap:6px;
  padding:7px 16px;
  border-radius:20px;
  border:1px solid var(--line);
  color:var(--icon-color);
  font-family:var(--font-display);
  font-size:13px;
  font-weight:600;
  text-decoration:none;
  transition:background .15s ease, color .15s ease, border-color .15s ease;
  -webkit-tap-highlight-color:transparent;
  -webkit-touch-callout:none;
  outline:none;
}
.modal-link-out:hover{
  background:var(--icon-color-hover);
  border-color:var(--icon-color-hover);
  color:var(--fg-inverse);
}
.modal-actions{
  display:flex;
  justify-content:flex-end;
  align-items:center;
  gap:22px;
  margin-bottom:14px;
}
.modal-actions .modal-close,
.modal-actions .modal-link-out{
  position:static;
}
.modal-cover-row{
  display:flex;
  gap:16px;
  align-items:flex-start;
  margin-bottom:4px;
}
.modal-cover{
  width:72px;
  height:98px;
  object-fit:cover;
  border-radius:8px;
  border:1px solid var(--line);
  background:var(--bg);
  flex-shrink:0;
}
.modal-cover-meta{
  flex:1 1 auto;
  min-width:0;
}
.modal-cover-meta .modal-title{padding-right:0;}
  .modal-title{
    font-family:var(--font-display);
    font-weight:500;
    font-size:22px;
    margin:0 0 6px;
    padding-right:32px;
  }
  .modal-author{color:var(--ink-soft); font-size:14px; margin-bottom:20px;}
  .modal-section-title{font-family:var(--font-display); font-weight:500; font-size:15px; color:var(--ink); margin:18px 0 8px;}
  .modal-section-title:first-of-type{margin-top:0;}
  .modal-list{padding-left:20px; margin:6px 0; color:var(--ink-soft); font-size:14px; line-height:1.7;}
  .modal-list li{margin-bottom:6px;}
  .modal-disclaimer{margin-top:16px; padding:14px 16px; background:var(--brand-peach); border-radius:10px; font-size:12.5px; color:var(--ink); line-height:1.7;}
  .donate-qr{width:220px; max-width:100%; aspect-ratio:1/1; display:block; margin:4px auto 14px; border-radius:12px; border:1.5px solid var(--line); object-fit:contain;}
  .donate-caption{text-align:center; font-size:13px; color:var(--ink-soft); margin-bottom:0;}

  .modal-field{
    display:flex;
    justify-content:space-between;
    gap:16px;
    padding:12px 0;
    border-top:1px solid var(--line);
    font-size:14px;
  }
  .modal-field .k{color:var(--ink-soft); flex-shrink:0;}
  .modal-field .v{font-family:var(--font-mono); text-align:right;}

  .modal-locations{margin-top:20px;}
  .modal-locations-label{
    font-size:12px;
    text-transform:uppercase;
    letter-spacing:0.06em;
    color:var(--ink-soft);
    margin-bottom:10px;
  }
  .location-item{
    display:flex;
    align-items:center;
    flex-wrap:wrap;
    justify-content:space-between;
    gap:6px 10px;
    padding:10px 0;
    font-size:14px;
    border-top:1px solid var(--line);
  }
  .location-item .dist{
    font-family:var(--font-mono);
    font-size:12.5px;
    color:var(--ink-soft);
    flex-shrink:0;
  }
  .location-item-right{
    display:flex;
    align-items:center;
    gap:10px;
    flex-shrink:0;
  }
  .location-link{color:var(--ink); text-decoration:none; overflow-wrap:break-word;}
  .location-link:hover{color:var(--accent); text-decoration:underline;}
  .avail-badge{
    font-family:var(--font-mono);
    font-size:11px;
    padding:3px 8px;
    border-radius:20px;
    white-space:nowrap;
    flex-shrink:0;
  }
  .avail-yes{background:var(--brand-navy); color:var(--fg-inverse);}
  .avail-no{background:var(--brand-peach); color:var(--fg-inverse);}

  .check-avail-btn{
    font-family:var(--font-mono);
    font-size:11px;
    padding:4px 10px;
    border-radius:20px;
    border:1px solid var(--line);
    background:transparent;
    color:var(--ink-soft);
    cursor:pointer;
    white-space:nowrap;
    flex-shrink:0;
  }
  .check-avail-btn:hover:not(:disabled){border-color:var(--accent); color:var(--accent);}
  .check-avail-btn:disabled{opacity:0.55; cursor:default;}
  .location-item-hint{
    font-size:12.5px;
    color:var(--ink-soft);
    flex:1 1 100%;
    min-width:0;
    text-align:left;
    overflow-wrap:break-word;
  }

  /* ---------- Loading overlay ---------- */
  .loading-overlay{
    position:fixed; inset:0;
    background:var(--overlay-loading);
    display:flex;
    align-items:center;
    justify-content:center;
    z-index:200;
    opacity:0;
    pointer-events:none;
    transition:opacity .2s ease;
  }
  .loading-overlay.active{opacity:1; pointer-events:auto;}

  .loading-content{
    display:flex;
    flex-direction:column;
    align-items:center;
    gap:18px;
  }
  .loading-book{
    width:64px;
    height:72px;
    position:relative;
    display:flex;
    align-items:center;
    justify-content:center;
    perspective:300px;
  }
  .loading-book-icon,
  .loading-magnifier{
    /* stroke="currentColor" ใน svg (ดู index.html) อ่านสีมาจากตรงนี้ */
    color:var(--fg-inverse);
  }
  .loading-book-icon{
    width:48px;
    height:56px;
    display:block;
    transform:rotateX(15deg);
  }
  .loading-magnifier{
    position:absolute;
    width:20px;
    height:20px;
    top:0;
    left:0;
    filter:drop-shadow(0 2px 3px var(--shadow-magnifier));
    animation:magnifierSweep 1.8s ease-in-out infinite;
  }
  @keyframes magnifierSweep{
    0%,100%{transform:translate(6px, 34px) rotate(-10deg);}
    25%{transform:translate(22px, 6px) rotate(6deg);}
    50%{transform:translate(40px, 34px) rotate(-10deg);}
    75%{transform:translate(22px, 48px) rotate(6deg);}
  }
  .loading-text{
    color:var(--fg-inverse);
    font-size:14px;
    font-family:var(--font-body);
    letter-spacing:0.01em;
  }

  /* ---------- Mobile: stacked "card catalog" swipe ---------- */
  .stack-wrap{display:none;}
  .stack-viewport{
    position:relative;
    flex:1 1 auto;
    min-height:0;
  }
  .stack-card{
    position:absolute;
    /* left, width, top, height กำหนดด้วย JS (sizeStackCards) ทั้งหมด เพื่อความแม่นยำ 100% ข้าม browser */
    background:var(--card-bg);
    /*border:1.5px solid var(--line-strong);*/
    border:1.5px solid var(--card-border);
    border-radius:16px;
    padding:28px 22px;
    box-shadow:0 12px 28px var(--shadow-stack-card);
    display:flex;
    flex-direction:column;
    justify-content:center;
    touch-action:none;
    user-select:none;
    will-change:transform, opacity;
    box-sizing:border-box;
  }
  .stack-card .card-title{
    font-family:var(--font-display);
    font-weight:500;
    font-size:23px;
    -webkit-line-clamp:6;
    color:var(--stack-title-color, var(--ink));
  }
  .stack-card .card-libs{
    font-size:14px;
    margin-top:16px;
    color:var(--stack-libs-color, var(--ink-soft));
  }
  /* !important ทั้งคู่: จำเป็นเพราะพี่แปะ class .neo-card ไว้ที่ .stack-card เอง (ดู index.html) ซึ่ง .neo-card
     เขียน border/box-shadow เป็น !important เลยกลบ rule นี้ทิ้งถ้า rule นี้ไม่ใส่ !important ด้วย (ผลคือการ์ด
     ที่ยังไม่มีหนังสือ เช่นตอนกำลังโหลดหน้าแรกครั้งแรก จะโผล่กรอบ+เงามาลอยๆ ทั้งที่ข้างในว่างเปล่า — บั๊กที่พี่เจอ) */
  .stack-card:empty{box-shadow:none !important; border-color:transparent !important;}

  /* การ์ดหนังสือบน desktop ใช้สีชุดเดียวกับ mobile (วน loop ตาม index เหมือนกัน) */
  .book-card .card-title{color:var(--stack-title-color, var(--ink));}
  .book-card .card-libs{color:var(--stack-libs-color, var(--ink-soft));}
  /* ปุ่ม link-out ใช้ขอบ/ไอคอนสีขาวคงที่ทุกการ์ด ไม่ขึ้นกับสีพื้นการ์ด (ดู .card-link-out base + :hover) */

  .stack-progress{
    display:none; /* ซ่อนเป็นค่าเริ่มต้น (desktop ใช้ grid ไม่มี pagination แบบนี้) โชว์เฉพาะมือถือใน @media ด้านล่าง */
    font-family:var(--font-mono);
    font-size:12.5px;
    color:var(--ink-soft);
    white-space:nowrap;
  }

  /* ---------- Swipe tutorial (แสดงครั้งแรกหลังค้นหาสำเร็จ) ---------- */
  .swipe-tutorial{
    position:absolute; inset:0;
    background:var(--overlay-tutorial);
    border-radius:16px;
    display:flex;
    flex-direction:column;
    align-items:center;
    justify-content:center;
    gap:16px;
    z-index:10;
    opacity:0;
    pointer-events:none;
    transition:opacity .35s ease;
  }
  .swipe-tutorial.active{opacity:1;}
  .swipe-tutorial-arrows{
    display:flex;
    flex-direction:column;
    align-items:center;
    gap:22px;
  }
  .swipe-arrow{
    width:0; height:0;
    border-left:11px solid transparent;
    border-right:11px solid transparent;
  }
  .swipe-arrow.up{
    border-bottom:16px solid var(--arrow-glow);
    animation:swipeArrowUp 1.3s ease-in-out infinite;
  }
  .swipe-arrow.down{
    border-top:16px solid var(--arrow-glow);
    animation:swipeArrowDown 1.3s ease-in-out infinite;
  }
  @keyframes swipeArrowUp{
    0%,100%{transform:translateY(0); opacity:.5;}
    50%{transform:translateY(-9px); opacity:1;}
  }
  @keyframes swipeArrowDown{
    0%,100%{transform:translateY(0); opacity:.5;}
    50%{transform:translateY(9px); opacity:1;}
  }
  .swipe-tutorial-text{
    color:var(--fg-inverse);
    font-size:13.5px;
    text-align:center;
    padding:0 24px;
    line-height:1.5;
  }

  /* ---------- Neobrutalism (ขอบดำหนา + เงาทึบ offset) — class เสริม ยังไม่ได้เอาไปแปะใช้ที่ไหนในไฟล์ index.html
     เลย ต้องเติมชื่อ class พวกนี้เข้าไปในแท็กเองถึงจะเห็นผล (เช่น <div class="book-card neo-card">) ถอดออก
     เมื่อไหร่ก็กลับไปเป็นสไตล์เดิมทันที ไม่กระทบ class เดิมเลย ปรับค่าตัวแปร --neo-* ใน :root ด้านบนของไฟล์นี้
     เพื่อเปลี่ยนความหนาขอบ/สี/ระยะเงาให้ทุกจุดที่ใช้ class นี้พร้อมกันทีเดียว ---------- */

  /* การ์ด: .book-card, .stack-card เดิมมี border-radius/border/box-shadow อยู่แล้ว — .neo-card จะ override
     ทับให้หมด (ต้องแปะไว้ "หลัง" ชื่อ class เดิมใน HTML เพื่อความชัดเจน แม้ CSS specificity จะเท่ากันเพราะเป็น
     class เดี่ยวทั้งคู่ ลำดับใน class="..." ไม่มีผลต่อ specificity แต่ลำดับ rule ในไฟล์นี้มีผล ซึ่ง .neo-card อยู่
     ท้ายไฟล์ เลยชนะอยู่แล้วไม่ว่าจะเรียงชื่อ class ยังไงใน HTML) */
  .neo-card{
    border:var(--neo-border-width) solid var(--neo-border-color) !important;
    border-radius:var(--neo-radius-card) !important;
    /* เงาเฉพาะด้านล่าง (offset-x เป็น 0) ตาม reference ที่พี่ส่งมา ต่างจาก .neo-btn/.neo-pill ด้านล่างที่ยังเป็น
       เงาเฉียงลง-ขวาปกติ ถ้าจะทำให้เหมือนกันทีหลังบอกได้ครับ */
    box-shadow:0 var(--neo-shadow-offset) 0 var(--neo-shadow-color) !important;
  }

  /* รูปภาพในการ์ด (เช่น .card-cover, .modal-cover) ขอบหนาเหมือนกันแต่มุมโค้งเล็กกว่า ไม่มีเงา (อยู่ในการ์ดที่มี
     เงาอยู่แล้ว ใส่เงาซ้อนอีกชั้นจะดูรก) */
  .neo-image{
    border:var(--neo-border-width) solid var(--neo-border-color) !important;
    border-radius:var(--neo-radius-image) !important;
  }

  /* ปุ่ม: .icon-btn, .search-btn, .nearme-btn ฯลฯ ขอบหนา + เงาทึบ พร้อม effect ตอนกด (ปุ่มขยับตามระยะเงาแล้ว
     เงาหายไป เหมือนปุ่มถูกกดจมลงจริงๆ) ต้องมี position:relative ไว้ก่อน (ปุ่มส่วนใหญ่ในเว็บนี้เป็น flex อยู่แล้ว
     ไม่กระทบ layout) */
  .neo-btn{
    position:relative;
    border:var(--neo-border-width) solid var(--neo-border-color) !important;
    /* เงาเฉพาะด้านล่าง (offset-x เป็น 0) ให้เข้าชุดกับ .neo-card */
    box-shadow:0 var(--neo-shadow-offset) 0 var(--neo-shadow-color) !important;
    transition:transform .1s ease, box-shadow .1s ease !important;
  }
  .neo-btn:active:not(:disabled){
    /* ขยับลงอย่างเดียว (ไม่ขยับขวา) ให้ตรงกับทิศทางเงาด้านบน */
    transform:translateY(var(--neo-shadow-offset));
    box-shadow:0 0 0 var(--neo-shadow-color) !important;
  }

  /* badge/pill เล็กๆ (เช่นกลุ่ม "..." + จำนวนคนดู ในภาพตัวอย่างที่พี่ส่งมา) ขอบหนา ไม่มี effect ตอนกด เพราะ
     ส่วนใหญ่ไม่ใช่ปุ่มที่กดได้ แค่ป้ายแสดงผล */
  .neo-pill{
    border:var(--neo-border-width) solid var(--neo-border-color) !important;
    border-radius:var(--neo-radius-pill) !important;
    /* เงาเฉพาะด้านล่าง เข้าชุดกับ .neo-card/.neo-btn */
    box-shadow:0 var(--neo-shadow-offset) 0 var(--neo-shadow-color) !important;
  }

  @media (max-width:640px){
    html{height:100%;}
    body{min-height:100vh; min-height:100dvh;}
    .topbar{padding:24px 20px 12px;}
    .meta-row{margin-top:12px;}
    .results{padding:0;}

    .stack-progress{display:block;}

    .book-grid{display:none;}
    .empty-state{
      position:fixed;
      left:0; right:0; bottom:0;
      /* top กำหนดด้วย JS (positionFixedPanels) = ขอบล่างของ topbar พอดี */
      display:flex;
      flex-direction:column;
      align-items:center;
      justify-content:center;
      background:var(--bg);
      padding:0 24px;
      z-index:2;
    }
    .stack-wrap{
      position:fixed;
      left:0; right:0; bottom:0;
      /* top กำหนดด้วย JS (positionFixedPanels) = ขอบล่างของ topbar พอดี */
      display:flex;
      flex-direction:column;
      background:var(--bg);
      z-index:1;
      padding:0 6px 6px;
    }
  }
