:root{
  --bg:#0f1115; --panel:#181b22; --line:#262a33; --text:#e8eaf0; --muted:#8b92a3;
  --accent:#6ea8ff; --danger:#ff6b6b; --ok:#5ad19a;
  --safe-t:env(safe-area-inset-top,0px); --safe-b:env(safe-area-inset-bottom,0px);
}
@media (prefers-color-scheme: light){
  :root{--bg:#f5f6f8;--panel:#fff;--line:#e2e5ea;--text:#16181d;--muted:#667085;--accent:#2563eb}
}
*{box-sizing:border-box}
html,body{margin:0;background:var(--bg);color:var(--text);font:16px/1.5 -apple-system,"Sarabun","Noto Sans Thai",system-ui,sans-serif;-webkit-text-size-adjust:100%}
button,input{font:inherit;color:inherit}
button{border:1px solid var(--line);background:var(--panel);border-radius:10px;padding:.55rem .9rem;min-height:44px;cursor:pointer}
button.primary{background:var(--accent);border-color:var(--accent);color:#fff;font-weight:600}
button.ghost{background:transparent}
button.danger{color:var(--danger);border-color:var(--danger);background:transparent}
input{width:100%;background:var(--bg);border:1px solid var(--line);border-radius:10px;padding:.6rem .8rem;min-height:44px}
label{display:block;margin:.7rem 0;color:var(--muted);font-size:.9rem}
label input{margin-top:.25rem;color:var(--text)}
.bar{position:sticky;top:0;z-index:5;display:flex;gap:.5rem;align-items:center;padding:calc(.6rem + var(--safe-t)) 1rem .6rem;background:color-mix(in srgb,var(--bg) 88%,transparent);backdrop-filter:blur(10px);border-bottom:1px solid var(--line)}
.bar h1{font-size:1.15rem;margin:0 auto 0 0;white-space:nowrap}
.bar input[type=search]{max-width:240px}
.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:1rem;padding:1rem}
.card{position:relative;background:var(--panel);border:1px solid var(--line);border-radius:14px;overflow:hidden;cursor:pointer}
.card .cvw{position:relative;aspect-ratio:2/3;background:var(--line);overflow:hidden}
.card .ph{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;font-size:3rem;font-weight:700;color:var(--muted)}
.card .cv{position:absolute;inset:0;width:100%;height:100%;display:block;object-fit:cover}
.card .meta{padding:.55rem .65rem .7rem}
.card .t{font-weight:600;font-size:.95rem;line-height:1.3;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
.card .r{color:var(--muted);font-size:.8rem;margin-top:.25rem}
.card .site{color:var(--muted);font-size:.72rem}
.badge{position:absolute;top:.5rem;right:.5rem;background:var(--ok);color:#06210f;font-weight:700;font-size:.75rem;border-radius:999px;padding:.1rem .55rem}
.empty{text-align:center;color:var(--muted);padding:4rem 1rem}
dialog{width:min(640px,94vw);max-height:90vh;overflow:auto;border:1px solid var(--line);border-radius:18px;background:var(--panel);color:var(--text);padding:1.2rem}
dialog::backdrop{background:rgba(0,0,0,.6)}
dialog h2{margin:.1rem 0 .5rem}
dialog h3{margin:1.1rem 0 .2rem;font-size:.95rem}
menu{display:flex;gap:.5rem;justify-content:flex-end;padding:0;margin:1rem 0 0;flex-wrap:wrap}
.msg{color:var(--muted);font-size:.85rem;margin:.3rem 0}
.detail-head{display:flex;gap:1rem}
.detail-head img{width:110px;aspect-ratio:2/3;object-fit:cover;border-radius:10px;background:var(--line);flex:none}
.row{display:flex;gap:.5rem;flex-wrap:wrap}
.chapters{list-style:none;margin:1rem 0 0;padding:0;max-height:42vh;overflow:auto;border-top:1px solid var(--line)}
.chapters li{display:flex;justify-content:space-between;gap:1rem;padding:.7rem .2rem;border-bottom:1px solid var(--line);cursor:pointer}
.chapters li.cur{color:var(--accent);font-weight:600}
.chapters li span:last-child{color:var(--muted);font-size:.8rem}
/* reader */
#readerView{background:#000;min-height:100vh}
.reader-bar{transition:transform .2s}
.reader-bar.hide{transform:translateY(-110%)}
.rtitle{display:flex;flex-direction:column;margin-right:auto;min-width:0}
.rtitle strong,.rtitle span{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.rtitle span{color:var(--muted);font-size:.8rem}
#pages{max-width:900px;margin:0 auto}
#pages img{display:block;width:100%;height:auto;aspect-ratio:auto 2/3;background:#111}
#rFoot{text-align:center;padding:2rem 1rem calc(3rem + var(--safe-b))}
#toast{position:fixed;left:50%;bottom:calc(1.2rem + var(--safe-b));transform:translateX(-50%) translateY(200%);background:var(--text);color:var(--bg);padding:.6rem 1rem;border-radius:999px;transition:transform .25s;z-index:50;max-width:90vw}
#toast.on{transform:translateX(-50%) translateY(0)}
@media (max-width:600px){.bar h1{display:none}.bar input[type=search]{max-width:none;flex:1}}
