html[data-theme="light"] { --bg:#ffffff; --fg:#222; --muted:#888; --card:#f6f6f6; --line:#e5e5e5; --accent:#8b5e34; --accent-fg:#fff; }
html[data-theme="sepia"] { --bg:#f4ecd8; --fg:#4a3b27; --muted:#9a8b72; --card:#ece2c8; --line:#dccfae; --accent:#8b5e34; --accent-fg:#fff; }
html[data-theme="dark"]  { --bg:#121214; --fg:#d4d1ca; --muted:#7c7a74; --card:#1c1b1f; --line:#2b2a30; --accent:#d09a64; --accent-fg:#121214; }

html, body { height: 100%; overflow: hidden; }
body { padding: 0; -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }

.view { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); }
.bar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.bar button { padding: 6px 10px; font-size: 15px; white-space: nowrap; }
.bar button.accent { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
.barlink { color: var(--accent); text-decoration: none; font-size: 15px; white-space: nowrap; padding: 6px 4px; }
.bar-title { flex: 1; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quota { color: var(--muted); font-size: 12px; white-space: nowrap; }

.gate { padding: 80px 24px; text-align: center; }
.btn-link { display: inline-block; margin-top: 8px; padding: 12px 24px; border-radius: 10px; background: var(--accent); color: var(--accent-fg); text-decoration: none; font-weight: 600; }

/* 书架 */
.books { flex: 1; overflow-y: auto; padding: 12px; display: grid; gap: 10px; align-content: start; -webkit-overflow-scrolling: touch; }
.book { display: flex; align-items: center; gap: 12px; padding: 14px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.book .info { flex: 1; min-width: 0; cursor: pointer; }
.book .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book .meta { font-size: 13px; color: var(--muted); }
.book .del { border: 0; background: none; color: var(--muted); font-size: 13px; padding: 6px; }
.empty { margin: auto; text-align: center; padding: 24px; }
.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 8px 16px; border-radius: 20px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90%; }
.toast.on { opacity: 1; }

/* 阅读 */
.scroller { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.text { max-width: 680px; margin: 0 auto; padding: 20px 20px 80px; font-size: var(--fs, 18px); line-height: 1.85; }
.text h3 { font-size: 1.25em; line-height: 1.5; margin: 0.6em 0 1em; }
.text p { margin: 0 0 0.9em; text-align: justify; text-indent: 2em; overflow-wrap: anywhere; }
.foot { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px); border-top: 1px solid var(--line); background: var(--bg); color: var(--muted); font-size: 13px; }
/* 选中文字后出现的工具条 */
.selbar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 64px);
  display: flex; gap: 6px; padding: 8px; border-radius: 16px;
  background: var(--card); border: 1px solid var(--line); box-shadow: 0 4px 20px rgba(0,0,0,.3);
}
.selbar button, .sheet button.m-highlight, .sheet button.m-unsure, .sheet button.m-key { padding: 8px 12px; font-size: 15px; white-space: nowrap; }
.primary-btn { background: var(--accent) !important; color: var(--accent-fg) !important; border-color: var(--accent) !important; font-weight: 600; }
.danger-btn { color: var(--danger); }

/* 三种标记的颜色 */
:root { --hl: rgba(255, 214, 10, .35); --un: rgba(255, 99, 71, .28); --ky: rgba(80, 170, 255, .30); }
mark { color: inherit; border-radius: 3px; padding: 1px 0; }
.m-highlight { background: var(--hl); }
.m-unsure { background: var(--un); text-decoration: underline wavy rgba(255, 99, 71, .85); text-underline-offset: 3px; }
.m-key { background: var(--ky); font-weight: 600; }
button.m-highlight.on, button.m-unsure.on, button.m-key.on { outline: 2px solid var(--accent); }
.ms-text { font-size: 15px; line-height: 1.7; color: var(--muted); max-height: 120px; overflow: auto; }

/* 读完一章的提示 */
.modal { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; padding: 24px; }
.modal-card { background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 16px; padding: 22px; width: 100%; max-width: 380px; }
.modal-card b { font-size: 18px; }
.modal-card p { margin: 10px 0 18px; color: var(--muted); line-height: 1.7; }
.modal-card .row button { flex: 1; padding: 12px; }

/* 抽屉 */
.sheet { position: fixed; left: 0; right: 0; bottom: 0; top: 8%; background: var(--bg); border-radius: 16px 16px 0 0; box-shadow: 0 -8px 32px rgba(0,0,0,.25); display: flex; flex-direction: column; z-index: 10; padding-bottom: env(safe-area-inset-bottom); }
.sheet.small { top: auto; }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.sheet-head b { flex: 1; }
.sheet-body { flex: 1; overflow-y: auto; padding: 12px 16px; -webkit-overflow-scrolling: touch; }
.sheet.small .sheet-body { flex: none; }
.list button { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: none; padding: 12px 4px; }
.list button.cur { color: var(--accent); font-weight: 600; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row span { min-width: 36px; text-align: center; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* 聊天 */
.chat-ctx { padding: 8px 16px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); max-height: 72px; overflow: hidden; }
.chat-log { display: flex; flex-direction: column; gap: 12px; }
.bubble { max-width: 90%; padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.7; font-size: 15px; }
.bubble.user { align-self: flex-end; background: var(--accent); color: var(--accent-fg); }
.bubble.ai { align-self: flex-start; background: var(--card); border: 1px solid var(--line); }
.bubble.err { align-self: center; color: var(--danger); background: none; font-size: 14px; }
.chat-form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); align-items: flex-end; }
.chat-form textarea { resize: none; max-height: 120px; }
.chat-form .send { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; white-space: nowrap; }
