/* ===================== ห้องอ่านหนังสือ — โทนกระดาษ หมึก และปกผ้าสีเขียว ===================== */
:root {
  --paper: #f5f0e6; --sheet: #fffdf8; --ink: #27231d; --ink-2: #5d564b; --line: #e3dacb;
  --accent: #2f5d50; --accent-ink: #fff; --accent-soft: #e4ede8; --gold: #b5852f;
  --red: #a63d32; --red-soft: #f6e3df; --amber: #8a6411; --amber-soft: #f7ecd0; --ok-soft: #e2efe6;
  --hl: #fbeaa9; --shadow: 0 1px 2px rgba(60, 45, 20, .06), 0 4px 18px rgba(60, 45, 20, .06);
  --radius: 12px; --sans: 'Sarabun', 'Leelawadee UI', Tahoma, sans-serif; --serif: 'Noto Serif Thai', 'Sarabun', serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1b1a17; --sheet: #23221e; --ink: #ece6da; --ink-2: #aaa293; --line: #39362f;
    --accent: #7fb8a3; --accent-ink: #10201b; --accent-soft: #24332d; --gold: #d6aa5a;
    --red: #e58b7f; --red-soft: #3a2421; --amber: #e2bd6a; --amber-soft: #352d1b; --ok-soft: #22322a;
    --hl: #4a4220; --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 17px/1.65 var(--sans); }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .4em; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.05rem; }
code, .mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85em; }
.muted { color: var(--ink-2); } .small { font-size: .86rem; } .err { color: var(--red); } .err-inline { color: var(--red); }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; background: var(--sheet); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--ink); text-decoration: none; font-size: 1.1rem; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); position: relative; }
.brand-mark::after { content: ''; position: absolute; inset: 7px 6px; border-left: 2px solid var(--paper); border-right: 2px solid var(--paper); border-radius: 2px; }
.top nav { display: flex; gap: 4px; flex-wrap: wrap; }
.top nav a { padding: 6px 12px; border-radius: 999px; text-decoration: none; color: var(--ink-2); }
.top nav a.on, .top nav a:hover { background: var(--accent-soft); color: var(--accent); }
.wrap { max-width: 1100px; margin: 0 auto; padding: 24px 16px 60px; }
.narrow .wrap { max-width: 480px; }
.foot { text-align: center; color: var(--ink-2); font-size: .8rem; padding: 0 0 24px; }

.bar { padding: 10px 20px; font-weight: 500; }
.bar-red { background: var(--red-soft); color: var(--red); border-bottom: 1px solid var(--red); }
.bar-amber { background: var(--amber-soft); color: var(--amber); }
.flash { padding: 12px 16px; border-radius: var(--radius); margin: 0 0 16px; }
.flash-ok { background: var(--ok-soft); } .flash-err { background: var(--red-soft); color: var(--red); } .flash-warn { background: var(--amber-soft); color: var(--amber); }

.card { background: var(--sheet); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin: 0 0 18px; box-shadow: var(--shadow); }
.empty { text-align: center; padding: 48px 20px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 0; max-width: 60ch; }

label { display: block; margin: 0 0 12px; font-weight: 500; font-size: .95rem; }
label.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-weight: 400; }
label.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; }
label.check input { margin-top: 6px; width: 18px; height: 18px; accent-color: var(--accent); }
input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]), select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font: inherit; font-weight: 400; color: var(--ink);
  background: var(--paper); border: 1px solid var(--line); border-radius: 9px; }
label.inline select { width: auto; margin: 0; padding: 6px 8px; max-width: 220px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 2fr; gap: 0 16px; }
@media (max-width: 680px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--sheet); color: var(--ink); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; line-height: 1.3; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn.small { padding: 5px 12px; font-size: .88rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.floating { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 30; box-shadow: var(--shadow); background: var(--ink); color: var(--paper); }
.file-btn { cursor: pointer; }
.actions { display: flex; gap: 10px; align-items: center; margin-top: 8px; }
.wrap-actions { flex-wrap: wrap; }

.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 22px; text-align: center; background: var(--paper); cursor: pointer; }
.drop:hover { border-color: var(--accent); }
.drop input { display: block; margin: 0 auto 8px; }
.drop-text, .drop-file { display: block; font-weight: 400; }

.meter { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; flex: 1; }
.meter span { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s; }
.meter.small { height: 5px; margin: 8px 0 6px; }
.progress-row { display: flex; align-items: center; gap: 12px; margin: 12px 0 4px; }
.pct { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 3em; text-align: right; }
.status-line { margin: 4px 0 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tag { display: inline-block; padding: 1px 10px; border-radius: 99px; background: var(--line); color: var(--ink-2); font-size: .8rem; font-weight: 600; white-space: nowrap; }
.tag-working, .tag-ocr { background: var(--amber-soft); color: var(--amber); }
.tag-done { background: var(--ok-soft); color: var(--accent); }
.tag-paused, .tag-uploading { background: var(--line); }
.tag-error { background: var(--red-soft); color: var(--red); }

.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 18px; }
.book { display: flex; flex-direction: column; background: var(--sheet); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; text-decoration: none; color: inherit; box-shadow: var(--shadow); transition: transform .15s; }
.book:hover { transform: translateY(-2px); }
.cover { aspect-ratio: 3 / 4; background: linear-gradient(135deg, var(--accent), #1f3e35); overflow: hidden; border-bottom: 1px solid var(--line); }
.cover img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.book-body { padding: 12px 14px; }
.book-body h3 { margin: 0; font-size: 1rem; }
.book-body p { margin: 0; }

.book-head { margin-bottom: 8px; }
.crumb { margin-bottom: 6px; font-size: .9rem; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 16px 0 20px; overflow-x: auto; }
.tabs a { padding: 10px 16px; text-decoration: none; color: var(--ink-2); border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.tts-bar { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; background: var(--sheet); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; position: sticky; top: 62px; z-index: 10; box-shadow: var(--shadow); margin-bottom: 18px; }
.tts-bar.compact { position: static; margin-top: 18px; }
.tts-bar input[type=range] { width: 100px; accent-color: var(--accent); }
.tts-bar output { font-variant-numeric: tabular-nums; min-width: 2.6em; }

.book-text, .summary { font-family: var(--serif); font-size: 1.12rem; line-height: 1.95; max-width: 70ch; margin: 0 auto; }
.book-text p, .summary p { margin: 0 0 .9em; text-indent: 2em; }
.book-text h2, .book-text h3, .summary h2, .summary h3 { font-family: var(--sans); margin-top: 1.3em; }
.summary h2 { font-size: 1.5rem; } .summary h3 { color: var(--accent); }
.summary p { text-indent: 0; }
.book-text li, .summary li { margin-bottom: .3em; }
.book-text blockquote { margin: 0 0 1em; padding-left: 1em; border-left: 3px solid var(--gold); color: var(--ink-2); }
.say { cursor: pointer; border-radius: 6px; transition: background .2s; }
.say:hover { background: color-mix(in srgb, var(--hl) 35%, transparent); }
.say.speaking { background: var(--hl); box-shadow: 0 0 0 4px var(--hl); }
.pmark { font-family: var(--sans); font-size: .8rem; color: var(--ink-2); text-align: center; margin: 2em 0 1em; display: flex; align-items: center; gap: 10px; }
.pmark::before, .pmark::after { content: ''; flex: 1; border-top: 1px solid var(--line); }
.pmark a { color: var(--ink-2); }
.pmark:first-child { margin-top: 0; }

.page-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
.pg { display: block; text-decoration: none; color: var(--ink-2); font-size: .82rem; text-align: center; }
.pg img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; object-position: top; border-radius: 8px; border: 2px solid var(--line); background: var(--sheet); display: block; margin-bottom: 4px; }
.pg-done img { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.pg-error img { border-color: var(--red); } .pg-error { color: var(--red); }
.pg-new img, .pg-ocr img { opacity: .6; }

.page-nav { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.pn { display: flex; gap: 10px; align-items: center; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 860px) { .split { grid-template-columns: 1fr; } }
.scan { margin: 0; position: sticky; top: 70px; }
.scan img { width: 100%; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: zoom-in; display: block; }
.editor textarea { font-family: var(--serif); font-size: 1.05rem; line-height: 1.8; min-height: 360px; }
.preview { font-size: 1rem; margin-top: 10px; }
.raw { margin: 14px 0; } .raw pre { white-space: pre-wrap; background: var(--paper); padding: 12px; border-radius: 8px; font-size: .9rem; max-height: 320px; overflow: auto; }
dialog#zoom { max-width: 96vw; max-height: 96vh; padding: 10px; border: 0; border-radius: 10px; background: var(--sheet); }
dialog#zoom img { max-width: 92vw; display: block; margin-bottom: 8px; }
dialog::backdrop { background: rgba(0, 0, 0, .6); }

.danger-zone { border-color: var(--red-soft); }
.login h1 { font-size: 1.4rem; }
table.list { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.list th, table.list td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { color: var(--ink-2); font-weight: 600; }
.table-scroll { overflow-x: auto; }
ul.files { margin: 4px 0 12px; padding-left: 1.2em; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; }
.checks li { margin-bottom: 6px; }
.quota-line { margin: -8px 0 16px; }
.estimate { background: var(--accent-soft); padding: 8px 12px; border-radius: 9px; }
.estimate:empty { display: none; }
.estimate.warn { background: var(--amber-soft); color: var(--amber); }
