:root {
  --paper: #f4efe7;
  --paper-deep: #e9dfd2;
  --card: rgba(255,255,255,.68);
  --ink: #29231f;
  --muted: #776d65;
  --line: rgba(62,45,34,.14);
  --accent: #8b3f4d;
  --accent-strong: #71313e;
  --shadow: 0 24px 70px rgba(69, 44, 32, .12);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --paper: #171615;
  --paper-deep: #201d1b;
  --card: rgba(41,37,34,.76);
  --ink: #f4ede5;
  --muted: #b2a69d;
  --line: rgba(255,255,255,.12);
  --accent: #d08392;
  --accent-strong: #e09aaa;
  --shadow: 0 24px 70px rgba(0,0,0,.28);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--paper); font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body::before { content: ""; position: fixed; inset: 0; pointer-events: none; opacity: .22; background-image: radial-gradient(rgba(80,51,36,.23) .55px, transparent .55px); background-size: 5px 5px; }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
.eyebrow { margin: 0 0 10px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .22em; }
.brand-mark { width: 66px; height: 78px; display: grid; place-items: center; color: #fff; background: var(--accent); border-radius: 8px 8px 20px 20px; font-family: Georgia, serif; font-size: 34px; box-shadow: var(--shadow); }
.brand-mark.small { width: 38px; height: 44px; border-radius: 5px 5px 12px 12px; font-size: 20px; box-shadow: none; }
.primary { border: 0; border-radius: 999px; padding: 13px 20px; color: white; background: var(--accent); font-weight: 750; cursor: pointer; transition: transform .2s, background .2s; }
.primary:hover { transform: translateY(-1px); background: var(--accent-strong); }
.primary:disabled { opacity: .6; cursor: wait; }
.text-button, .icon-button { border: 0; color: var(--ink); background: transparent; cursor: pointer; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 50%; font-size: 19px; }
.error { min-height: 20px; color: #b33d3d; font-size: 13px; }
.toast { position: fixed; z-index: 50; left: 50%; bottom: 28px; transform: translate(-50%, 20px); padding: 11px 18px; border-radius: 999px; color: white; background: #282320; opacity: 0; pointer-events: none; transition: .25s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(540px, 100%); padding: 54px; border: 1px solid var(--line); border-radius: 30px; background: var(--card); backdrop-filter: blur(20px); box-shadow: var(--shadow); }
.login-card h1 { margin: 28px 0 8px; font: 500 clamp(36px, 7vw, 58px)/1 Georgia, "Times New Roman", serif; letter-spacing: -.04em; }
.login-copy { color: var(--muted); margin: 0 0 36px; }
.login-card label { display: block; margin-bottom: 9px; font-size: 13px; font-weight: 700; }
.password-row { display: flex; gap: 10px; }
input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 14px; padding: 13px 15px; color: var(--ink); background: rgba(255,255,255,.35); outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent); }

.app-shell { width: min(1240px, calc(100% - 40px)); margin: 0 auto; padding-bottom: 90px; }
.topbar { height: 94px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand strong, .brand small { display: block; }
.brand strong { font-family: Georgia, serif; font-size: 18px; }
.brand small { margin-top: 3px; color: var(--muted); font-size: 8px; letter-spacing: .18em; }
.topbar nav { display: flex; align-items: center; gap: 12px; }
.hero { min-height: 300px; display: flex; align-items: end; justify-content: space-between; gap: 44px; padding: 60px 3% 48px; }
.hero h1 { margin: 0; font: 500 clamp(42px, 6vw, 76px)/1.06 Georgia, "Songti SC", serif; letter-spacing: -.045em; }
.hero h1 em { color: var(--accent); font-weight: 400; }
.hero > p { max-width: 400px; margin: 0 0 10px; color: var(--muted); line-height: 1.8; }
.toolbar { display: flex; align-items: center; gap: 20px; margin: 8px 0 32px; }
.search-wrap { flex: 1; display: flex; align-items: center; gap: 8px; padding: 0 16px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); }
.search-wrap input { border: 0; box-shadow: none; background: transparent; }
.count { color: var(--muted); font-size: 13px; white-space: nowrap; }
.bookshelf { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 30px 22px; }
.book-card { position: relative; min-width: 0; cursor: pointer; }
.book-cover { aspect-ratio: 3/4.1; display: flex; flex-direction: column; justify-content: space-between; padding: 24px; border-radius: 8px 16px 16px 8px; color: #fffaf6; overflow: hidden; box-shadow: 10px 18px 32px rgba(50,34,26,.18); transition: transform .25s, box-shadow .25s; }
.book-card:hover .book-cover { transform: translateY(-6px) rotate(.4deg); box-shadow: 14px 25px 45px rgba(50,34,26,.24); }
.book-cover::before { content: ""; position: absolute; inset: 0 auto 0 9px; width: 1px; background: rgba(255,255,255,.25); box-shadow: 3px 0 rgba(0,0,0,.08); }
.book-cover.rose { background: linear-gradient(145deg,#a45a65,#69313c); }
.book-cover.plum { background: linear-gradient(145deg,#6f5a79,#3e3049); }
.book-cover.forest { background: linear-gradient(145deg,#527465,#263f36); }
.book-cover.ocean { background: linear-gradient(145deg,#52768d,#263f52); }
.book-cover.amber { background: linear-gradient(145deg,#ad7945,#6e4525); }
.book-cover.ink { background: linear-gradient(145deg,#45526b,#222b3d); }
.book-cover .ornament { font: 32px Georgia, serif; opacity: .72; }
.book-cover h2 { margin: auto 0 8px; font: 500 clamp(22px, 2.2vw, 32px)/1.14 Georgia, "Songti SC", serif; overflow-wrap: anywhere; }
.book-cover p { margin: 0; opacity: .7; font-size: 12px; letter-spacing: .08em; }
.book-meta { padding: 16px 5px 0; }
.book-meta p { height: 42px; margin: 0 0 10px; color: var(--muted); font-size: 13px; line-height: 1.6; overflow: hidden; }
.progress-track { height: 3px; overflow: hidden; border-radius: 99px; background: var(--line); }
.progress-track i { display: block; height: 100%; background: var(--accent); }
.book-meta small { display: flex; justify-content: space-between; margin-top: 8px; color: var(--muted); }
.empty { min-height: 360px; display: grid; place-items: center; align-content: center; text-align: center; border: 1px dashed var(--line); border-radius: 24px; }
.empty-book { font-size: 42px; color: var(--accent); }
.empty h2 { margin: 12px 0 0; font-family: Georgia, serif; font-size: 30px; }
.empty p { color: var(--muted); }

dialog { width: min(700px, calc(100% - 24px)); padding: 0; border: 0; border-radius: 26px; color: var(--ink); background: var(--paper); box-shadow: 0 40px 100px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(26,20,17,.55); backdrop-filter: blur(6px); }
.dialog-card { padding: 32px; }
.dialog-card header, .dialog-card footer { display: flex; align-items: center; justify-content: space-between; }
.dialog-card h2 { margin: 0; font: 500 34px Georgia, serif; }
.drop-zone { display: grid; place-items: center; gap: 6px; margin: 24px 0; padding: 28px; border: 1px dashed var(--accent); border-radius: 18px; color: var(--muted); background: color-mix(in srgb, var(--accent) 5%, transparent); cursor: pointer; }
.drop-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop-zone strong { color: var(--accent); }
.drop-zone span { font-size: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid label { display: grid; gap: 7px; font-size: 12px; font-weight: 700; }
.form-grid .wide { grid-column: 1/-1; }
.dialog-card footer { justify-content: flex-end; gap: 12px; padding-top: 10px; }

.reader { position: fixed; z-index: 30; inset: 0; display: grid; grid-template-rows: auto 1fr; background: var(--paper); }
.reader-bar { display: grid; grid-template-columns: 1fr 2fr 1fr; align-items: center; min-height: 72px; padding: 10px 26px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--paper) 88%, transparent); backdrop-filter: blur(18px); }
.reader-bar > div:nth-child(2) { text-align: center; }
.reader-bar strong, .reader-bar small { display: block; }
.reader-bar strong { font-family: Georgia, "Songti SC", serif; }
.reader-bar small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.reader-actions { display: flex; align-items: center; justify-content: flex-end; gap: 16px; font-size: 13px; }
.reader-scroll { overflow: auto; }
.reader-content { width: min(760px, calc(100% - 40px)); min-height: 100vh; margin: 0 auto; padding: 80px 0 180px; font: 400 19px/2 Georgia, "Songti SC", serif; white-space: pre-wrap; overflow-wrap: break-word; }

@media (max-width: 900px) {
  .bookshelf { grid-template-columns: repeat(3, 1fr); }
  .hero { min-height: 260px; }
}
@media (max-width: 680px) {
  .app-shell { width: min(100% - 28px, 1240px); }
  .topbar { height: 76px; }
  .brand strong { font-size: 16px; }
  .topbar .primary { width: 42px; padding: 12px 0; font-size: 0; }
  .topbar .primary::before { content: "+"; font-size: 20px; }
  .topbar .text-button { display: none; }
  .hero { min-height: 270px; display: block; padding: 48px 4px 30px; }
  .hero h1 { font-size: 42px; }
  .hero > p { margin-top: 24px; font-size: 13px; }
  .toolbar { margin-bottom: 24px; }
  .count { display: none; }
  .bookshelf { grid-template-columns: repeat(2, 1fr); gap: 24px 14px; }
  .book-cover { padding: 18px; }
  .book-cover h2 { font-size: 22px; }
  .login-card { padding: 34px 24px; }
  .password-row { display: grid; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .dialog-card { padding: 24px 18px; }
  .reader-bar { grid-template-columns: auto 1fr auto; padding: 10px 12px; }
  .reader-bar > div:nth-child(2) { text-align: left; min-width: 0; }
  .reader-bar strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .reader-author, #reader-author, #reader-progress { display: none; }
  .reader-actions { gap: 4px; }
  .reader-content { padding-top: 48px; font-size: 18px; line-height: 1.9; }
}
