:root {
  color-scheme: light;
  --bg: #f5f3ef;
  --surface: #fffdf9;
  --surface-2: #eeeae2;
  --text: #26231f;
  --muted: #7b756c;
  --line: #ded8ce;
  --accent: #e4543d;
  --accent-soft: #f7ddd7;
  --shadow: 0 10px 30px rgba(48, 40, 31, .08);
  --radius: 18px;
}
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #161514;
  --surface: #211f1c;
  --surface-2: #2c2925;
  --text: #ece7df;
  --muted: #aaa299;
  --line: #3a3631;
  --accent: #ff704f;
  --accent-soft: #4a2c26;
  --shadow: 0 10px 30px rgba(0, 0, 0, .3);
}
* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(circle at 100% 0, var(--accent-soft), transparent 34rem), var(--bg);
  color: var(--text);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button { color: inherit; }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }
.auth-mode .tabbar { opacity: 0; pointer-events: none; }
.auth-card { width: min(420px, 100%); margin: 12vh auto 0; padding: 28px 22px; border: 1px solid var(--line); border-radius: 24px; background: color-mix(in srgb, var(--surface) 92%, transparent); box-shadow: var(--shadow); text-align: center; }
.auth-mark { display: grid; place-items: center; width: 54px; height: 54px; margin: 0 auto 14px; border-radius: 16px; background: var(--accent); color: white; font-size: 24px; font-weight: 800; }
.auth-card h1 { margin: 0; font-size: 26px; letter-spacing: -.03em; }
.auth-card p { margin: 8px 0 20px; color: var(--muted); }
.auth-form { display: grid; gap: 10px; }
.auth-form input { height: 50px; padding: 0 15px; border: 1px solid var(--line); border-radius: 14px; outline: none; background: var(--surface); color: var(--text); }
.auth-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.auth-error { min-height: 22px; margin-top: 10px; color: var(--accent); font-size: 13px; }
.app { width: min(980px, 100%); min-height: 100vh; margin: 0 auto; padding: env(safe-area-inset-top) 0 80px; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  height: 62px; padding: 0 18px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(18px); border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  transition: transform .22s ease, opacity .22s ease;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: .02em; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; color: white; background: var(--accent); }
.icon-button, .fab, .chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; cursor: pointer;
}
.icon-button { display: grid; place-items: center; width: 40px; height: 40px; padding: 0; }
.icon-button:hover, .chip:hover { border-color: var(--accent); }
.icon-button svg, .tabbar svg, .button svg { width: 20px; height: 20px; }
.topbar .brand { flex: 1; }
.main { padding: 18px; }
.hero h1 { margin: 18px 0 6px; font-size: clamp(28px, 5vw, 44px); line-height: 1.15; letter-spacing: -.03em; }
.hero p { margin: 0 0 18px; color: var(--muted); }
.searchbar { display: flex; gap: 10px; margin: 20px 0; }
.searchbar input {
  flex: 1; min-width: 0; height: 50px; padding: 0 16px; border: 1px solid var(--line);
  border-radius: 16px; outline: none; background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.searchbar input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.searchbar .button { flex: 0 0 auto; }
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border: 0; border-radius: 14px; background: var(--accent); color: white;
  font-weight: 700; cursor: pointer;
}
.button.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.button.compact { min-height: 38px; padding: 0 12px; border-radius: 12px; font-size: 14px; }
.button:disabled { opacity: .6; cursor: wait; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 22px 0 12px; }
.section-title h2 { margin: 0; font-size: 18px; }
.section-title span { color: var(--muted); font-size: 14px; }
.search-more { display: grid; place-items: center; min-height: 54px; color: var(--muted); font-size: 13px; }
.search-more .spinner { margin: 14px auto; }
.load-done { padding: 18px 0; color: var(--muted); font-size: 13px; }
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.book-card {
  display: grid; grid-template-columns: 78px 1fr; gap: 14px; padding: 12px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); cursor: pointer;
}
.book-card:hover { transform: translateY(-1px); border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.history-card { grid-template-columns: 78px minmax(0, 1fr) auto; align-items: start; }
.history-delete {
  display: inline-flex; align-items: center; gap: 4px; min-height: 34px; padding: 0 10px; border: 1px solid var(--line);
  border-radius: 999px; background: var(--surface-2); color: var(--muted); cursor: pointer; font-size: 12px;
}
.history-delete:hover { color: var(--accent); border-color: var(--accent); }
.history-delete svg { width: 15px; height: 15px; }
.cover {
  width: 78px; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 10px; background: var(--surface-2);
}
.book-card h3 { margin: 0 0 4px; font-size: 16px; line-height: 1.35; }
.meta { color: var(--muted); font-size: 13px; }
.abstract { display: -webkit-box; margin: 8px 0 0; overflow: hidden; color: var(--muted); font-size: 13px; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag, .pill { padding: 3px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 12px; }
.detail { display: grid; grid-template-columns: 132px 1fr; gap: 20px; align-items: start; padding: 8px 0 18px; }
.detail .cover { width: 132px; }
.detail h1 { margin: 0 0 8px; font-size: clamp(24px, 4vw, 36px); line-height: 1.2; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.chapter-tools { display: flex; gap: 10px; margin: 8px 0 14px; }
.chapter-tools input { flex: 1; min-width: 0; height: 42px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); color: var(--text); padding: 0 14px; }
.chapter-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.chapter-link { padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chapter-link.active { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.reader { max-width: 760px; margin: 0 auto; }
.reader-head { position: sticky; top: 62px; z-index: 10; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 8px 0 10px; background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(16px); transition: transform .22s ease, opacity .22s ease; }
.reader-title { min-width: 0; }
.reader-head .meta { margin: 0 0 1px; font-size: 12px; color: color-mix(in srgb, var(--muted) 82%, transparent); }
.reader-head h1 { margin: 0; overflow: hidden; color: color-mix(in srgb, var(--text) 72%, var(--muted)); font-size: 16px; font-weight: 500; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
.reader-progress { flex: 0 0 auto; color: color-mix(in srgb, var(--muted) 82%, transparent); font-size: 12px; }
.reader-content { padding: 18px 0 80px; font-size: var(--reader-size, 19px); line-height: 1.95; -webkit-tap-highlight-color: transparent; }
.reader-content p { margin: 0 0 1.15em; text-indent: 2em; }
.reader-content p.dialogue { text-indent: 0; }
.reader-nav {
  position: fixed; left: 50%; bottom: max(10px, env(safe-area-inset-bottom)); z-index: 28; transform: translateX(-50%);
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; width: min(720px, calc(100% - 28px));
  padding: 0; border: 0; border-radius: 0; background: transparent;
  transition: transform .22s ease, opacity .22s ease;
}
.reader-nav .button {
  min-height: 42px; padding: 0 10px; border: 1px solid color-mix(in srgb, var(--line) 58%, transparent);
  background: color-mix(in srgb, var(--surface) 82%, transparent); box-shadow: 0 8px 22px -18px color-mix(in srgb, var(--text) 60%, transparent);
  backdrop-filter: blur(18px);
}
.reader-nav .button:not(.secondary) { border-color: transparent; background: color-mix(in srgb, var(--accent) 88%, transparent); }
.reader-settings-panel {
  position: fixed; left: max(12px, calc((100vw - 1040px) / 2)); top: 96px; z-index: 29;
  display: flex; flex-direction: column; align-items: stretch; gap: 8px; padding: 10px; border: 1px solid var(--line);
  border-radius: 18px; background: color-mix(in srgb, var(--surface) 94%, transparent); box-shadow: var(--shadow); backdrop-filter: blur(18px);
  opacity: 0; pointer-events: none; transform: translateY(10px); transition: opacity .18s ease, transform .18s ease;
}
.reader-settings-panel.open { opacity: 1; pointer-events: auto; transform: translateY(0); }
.reader-settings-panel > span { color: var(--muted); font-size: 12px; text-align: center; }
.reader-settings-toggle {
  position: fixed; left: max(12px, calc((100vw - 1040px) / 2)); bottom: calc(82px + env(safe-area-inset-bottom)); z-index: 27;
  display: grid; place-items: center; width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 94%, transparent); color: var(--accent); font-weight: 800; cursor: pointer;
  box-shadow: var(--shadow); backdrop-filter: blur(18px); transition: opacity .18s ease, transform .18s ease;
}
.reader-settings-toggle:has(+ .reader-settings-panel.open) { opacity: 0; pointer-events: none; }
.reader-mode .tabbar { opacity: 0; pointer-events: none; transform: translateX(-50%) translateY(12px); }
.reader-mode .topbar { height: 52px; }
.reader-mode #backButton { width: 34px; height: 34px; border-color: transparent; background: transparent; color: var(--muted); }
.reader-mode #backButton svg { width: 18px; height: 18px; }
.reader-mode.chrome-hidden .topbar { transform: translateY(-105%); opacity: 0; }
.reader-mode.chrome-hidden .reader-head { transform: translateY(-100%); opacity: 0; }
.reader-mode.chrome-hidden .reader-nav { transform: translateX(-50%) translateY(130%); opacity: 0; pointer-events: none; }
.reader-mode.chrome-hidden .reader-settings-toggle { opacity: 0; pointer-events: none; transform: translateY(8px); }
.empty { padding: 60px 18px; text-align: center; color: var(--muted); }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.tabbar {
  position: fixed; left: 50%; bottom: max(10px, env(safe-area-inset-bottom)); z-index: 30; transform: translateX(-50%);
  display: grid; grid-template-columns: repeat(3, 72px); padding: 8px; border: 1px solid var(--line); border-radius: 22px;
  background: color-mix(in srgb, var(--surface) 92%, transparent); box-shadow: var(--shadow); backdrop-filter: blur(18px);
}
.tabbar { transition: opacity .2s ease, transform .2s ease; }
.tabbar a { display: grid; place-items: center; gap: 2px; color: var(--muted); font-size: 11px; }
.tabbar a.active { color: var(--accent); }
.tabbar svg { width: 21px; height: 21px; }
.toast { position: fixed; left: 50%; bottom: 88px; z-index: 50; transform: translate(-50%, 12px); opacity: 0; pointer-events: none; transition: .2s; padding: 10px 14px; border-radius: 999px; background: #222; color: white; font-size: 14px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.progress { height: 6px; overflow: hidden; border-radius: 999px; background: var(--surface-2); }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
@media (max-width: 640px) {
  .main { padding: 14px; }
  .detail { grid-template-columns: 96px 1fr; gap: 14px; }
  .detail .cover { width: 96px; }
  .book-grid { grid-template-columns: 1fr; }
  .history-card { grid-template-columns: 78px minmax(0, 1fr) 34px; }
  .history-delete { width: 34px; padding: 0; justify-content: center; }
  .history-delete span { display: none; }
  .tabbar {
    bottom: max(8px, env(safe-area-inset-bottom)); width: calc(100% - 20px); border-radius: 22px;
    padding: 7px 8px; grid-template-columns: repeat(3, 1fr);
  }
  .reader-content { font-size: var(--reader-size, 18px); }
  .reader-mode .main { padding: 8px 14px 0; }
  .reader-mode .topbar { position: fixed; left: 0; right: 0; height: 44px; padding: 0 10px; }
  .reader-mode .topbar .brand span:last-child, .reader-mode #themeButton { display: none; }
  .reader-mode #backButton { width: 32px; height: 32px; }
  .reader-mode .reader-head {
    position: fixed; left: 0; right: 0; top: 44px; padding: 5px 14px 8px;
    background: color-mix(in srgb, var(--bg) 58%, transparent);
    border-bottom: 1px solid color-mix(in srgb, var(--line) 34%, transparent);
    box-shadow: 0 10px 24px -22px color-mix(in srgb, var(--text) 55%, transparent);
  }
  .reader-mode .reader-head h1 { font-size: 15px; }
  .reader-mode .reader-head .meta { font-size: 11px; }
  .reader-mode .reader-progress { font-size: 11px; }
  .reader-mode .reader-content { padding: 68px 0 82px; transition: padding .22s ease; }
  .reader-mode.chrome-hidden .reader-content { padding-top: 12px; }
  .reader-nav { bottom: max(8px, env(safe-area-inset-bottom)); width: calc(100% - 20px); gap: 6px; padding: 0; }
  .reader-nav .button { min-height: 40px; padding: 0 6px; font-size: 14px; }
  .reader-settings-panel {
    left: 12px; right: auto; top: auto; bottom: calc(150px + env(safe-area-inset-bottom)); z-index: 29; flex-direction: row; align-items: center;
    opacity: 0; pointer-events: none; transform: translateY(10px); transition: opacity .18s ease, transform .18s ease;
  }
  .reader-settings-panel.open { opacity: 1; pointer-events: auto; transform: translateY(0); }
  .reader-settings-panel > span { padding: 0 4px; }
  .reader-settings-toggle {
    position: fixed; left: 12px; bottom: calc(150px + env(safe-area-inset-bottom)); z-index: 27;
    display: grid; place-items: center; width: 46px; height: 46px; border: 1px solid var(--line); border-radius: 999px;
    background: color-mix(in srgb, var(--surface) 94%, transparent); color: var(--accent); font-weight: 800; cursor: pointer;
    box-shadow: var(--shadow); backdrop-filter: blur(18px); transition: opacity .18s ease, transform .18s ease;
  }
  .reader-settings-toggle:has(+ .reader-settings-panel.open) { opacity: 0; pointer-events: none; }
  .toast { bottom: 76px; }
}
