/* Reader: calm, Apple-Books-like. Themes set the variables on <body data-theme>. */
:root { color-scheme: light dark; --bg: #fff; --fg: #1c1c1e; --dim: #8a8a8e; --line: rgba(0,0,0,.1); --card: #f2f2f7; --acc: #e8742e;
  --saved: rgba(232,116,46,.16); --tap: rgba(0,122,255,.2); --pop: #fff; --shadow: 0 12px 40px rgba(0,0,0,.18);
  --serif: "Iowan Old Style", "Palatino", Georgia, serif; --sans: -apple-system, system-ui, "Helvetica Neue", sans-serif;
  --top: env(safe-area-inset-top, 0px); --bot: env(safe-area-inset-bottom, 0px); }
body[data-theme="sepia"] { --bg: #f8f1e3; --fg: #3b2f22; --dim: #9a8a73; --line: rgba(80,60,30,.14); --card: #efe5d0; --pop: #fbf6ea; --saved: rgba(200,110,40,.2); }
body[data-theme="gray"] { --bg: #4a4a4d; --fg: #e9e9ea; --dim: #a5a5a8; --line: rgba(255,255,255,.14); --card: #5a5a5e; --pop: #57575b; --saved: rgba(255,170,90,.25); --tap: rgba(120,180,255,.3); color-scheme: dark; }
body[data-theme="dark"] { --bg: #121212; --fg: #d6d6d6; --dim: #7c7c80; --line: rgba(255,255,255,.12); --card: #1f1f21; --pop: #262628; --saved: rgba(255,150,70,.22); --tap: rgba(80,150,255,.35); --shadow: 0 12px 40px rgba(0,0,0,.6); color-scheme: dark; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font: 17px/1.4 var(--sans); }
body { overflow: hidden; overscroll-behavior: none; transition: background .25s, color .25s; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
.r-hide { display: none !important; }

/* ---------- library */
.r-lib { position: fixed; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: calc(var(--top) + 12px) max(20px, env(safe-area-inset-right)) calc(var(--bot) + 40px) max(20px, env(safe-area-inset-left)); }
.r-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; max-width: 1100px; margin: 0 auto; padding: 8px 0 4px; }
.r-head h1 { font: 700 34px/1.1 var(--sans); margin: 0; letter-spacing: -.01em; }
.r-tools { display: flex; gap: 6px; align-items: center; }
.r-ibtn { height: 38px; min-width: 38px; padding: 0 12px; border-radius: 19px; background: var(--card); font-size: 16px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.r-ibtn b { font-weight: 600; color: var(--acc); }
.r-sub { max-width: 1100px; margin: 2px auto 18px; color: var(--dim); font-size: 15px; }
.r-grid { max-width: 1100px; margin: 0 auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 34px 26px; }
.r-book { text-align: left; display: flex; flex-direction: column; gap: 8px; position: relative; }
.r-cover { aspect-ratio: 2 / 3; width: 100%; border-radius: 4px 8px 8px 4px; overflow: hidden; box-shadow: 0 2px 6px rgba(0,0,0,.18), 0 10px 24px rgba(0,0,0,.12);
  background: linear-gradient(135deg, #5b6f8a, #2f3e52); color: #fff; display: flex; align-items: flex-end; position: relative; }
.r-cover img { width: 100%; height: 100%; object-fit: cover; display: block; position: absolute; inset: 0; }
.r-cover span { padding: 14px; font: 600 17px/1.2 var(--serif); }
.r-meta { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 13px; color: var(--dim); min-height: 22px; }
.r-meta .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r-more { width: 30px; height: 24px; border-radius: 12px; font-size: 18px; line-height: 1; color: var(--dim); flex: none; }
.r-empty { max-width: 520px; margin: 12vh auto 0; text-align: center; color: var(--dim); line-height: 1.5; }
.r-empty b { color: var(--fg); font-size: 20px; display: block; margin-bottom: 6px; }
.r-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(255,255,255,.35); }
.r-progress i { display: block; height: 100%; background: var(--acc); }

/* ---------- reader */
.r-reader { position: fixed; inset: 0; background: var(--bg); touch-action: none; }
.r-reader .r-bar { touch-action: auto; }
.r-vp { position: absolute; overflow: hidden; touch-action: none; }
#bk .r-end { display: inline; }
#bk { height: 100%; column-fill: auto; font-family: var(--rf); font-size: var(--rs); line-height: var(--rl); hyphens: var(--hy); -webkit-hyphens: var(--hy);
  text-align: var(--ta); overflow-wrap: break-word; -webkit-user-select: text; user-select: text; will-change: transform; color: var(--fg); }
#bk.r-anim { transition: transform .28s cubic-bezier(.25,.8,.3,1); }
#bk .r-chap { min-height: 100%; }
#bk p { margin: 0; text-indent: 1.4em; }
#bk p:first-child, #bk h1 + p, #bk h2 + p, #bk h3 + p, #bk h4 + p, #bk hr + p, #bk div + p { text-indent: 0; }
#bk p + p { margin-top: 0; }
#bk h1, #bk h2, #bk h3, #bk h4, #bk h5 { font-family: var(--rf); line-height: 1.25; text-align: left; hyphens: none; break-after: avoid; text-indent: 0; }
#bk h1 { font-size: 1.6em; margin: 1.2em 0 .8em; font-weight: 600; }
#bk h2 { font-size: 1.35em; margin: 1.1em 0 .7em; font-weight: 600; }
#bk h3 { font-size: 1.15em; margin: 1em 0 .5em; font-weight: 600; }
#bk img, #bk svg { max-width: 100%; max-height: calc(var(--ph) - 1.5em); height: auto; object-fit: contain; display: block; margin: .6em auto; break-inside: avoid; }
#bk figure { margin: 1em 0; break-inside: avoid; }
#bk blockquote { margin: 1em 1.2em; }
#bk hr { border: 0; border-top: 1px solid var(--line); margin: 1.4em 25%; }
#bk a { color: inherit; text-decoration: none; }
#bk a[data-href], #bk a[data-ext] { color: var(--acc); }
#bk sup { line-height: 0; }
#bk table { border-collapse: collapse; max-width: 100%; font-size: .9em; }
#bk td, #bk th { padding: .2em .4em; border: 1px solid var(--line); }
#bk pre { white-space: pre-wrap; font-size: .85em; }
#bk .r-saved { background: var(--saved); border-radius: 3px; box-shadow: 0 0 0 1px var(--saved); }
::highlight(r-tap) { background-color: var(--tap); }

.r-foot { position: absolute; left: 0; right: 0; bottom: calc(var(--bot) + 10px); text-align: center; font-size: 12px; color: var(--dim); pointer-events: none; font-variant-numeric: tabular-nums; }
.r-head2 { position: absolute; left: 0; right: 0; top: calc(var(--top) + 12px); text-align: center; font-size: 12px; color: var(--dim); pointer-events: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 80px; transition: opacity .2s; }
.r-bar { position: absolute; left: 0; right: 0; display: flex; align-items: center; gap: 8px; padding: 8px max(14px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 86%, transparent); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  transition: transform .25s, opacity .25s; z-index: 5; }
.r-bar.top { top: 0; padding-top: calc(var(--top) + 8px); border-bottom: 1px solid var(--line); }
.r-bar.bottom { bottom: 0; padding-bottom: calc(var(--bot) + 10px); border-top: 1px solid var(--line); flex-direction: column; align-items: stretch; gap: 6px; }
.r-reader:not(.chrome) .r-bar.top { transform: translateY(-100%); opacity: 0; pointer-events: none; }
.r-reader:not(.chrome) .r-bar.bottom { transform: translateY(100%); opacity: 0; pointer-events: none; }
.r-reader.chrome .r-head2 { opacity: 0; }
.r-bar .ttl { flex: 1; text-align: center; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-bar .r-ibtn { background: transparent; font-size: 20px; padding: 0 8px; }
.r-bar input[type=range] { width: 100%; accent-color: var(--acc); }
.r-bar .row { display: flex; justify-content: space-between; font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; }
.r-selbtn { position: fixed; z-index: 20; padding: 8px 14px; border-radius: 18px; background: var(--fg); color: var(--bg); font-size: 15px; font-weight: 600; box-shadow: var(--shadow); }

/* ---------- popover / sheets */
.r-scrim { position: fixed; inset: 0; z-index: 30; }
.r-scrim.dark { background: rgba(0,0,0,.25); }
.r-pop { position: fixed; z-index: 31; width: min(400px, calc(100vw - 24px)); max-height: min(70vh, 560px); overflow-y: auto; background: var(--pop); color: var(--fg);
  border-radius: 16px; box-shadow: var(--shadow); padding: 16px 18px 14px; font-family: var(--sans); -webkit-user-select: none; user-select: none; }
@media (max-width: 600px) { .r-pop { left: 0 !important; right: 0; width: 100%; top: auto !important; bottom: 0; border-radius: 16px 16px 0 0; padding-bottom: calc(var(--bot) + 16px); max-height: 75vh; } }
.r-pop .w { display: flex; align-items: baseline; gap: 10px; }
.r-pop .w h2 { margin: 0; font: 600 26px/1.15 var(--serif); }
.r-pop .w .sp { font-size: 18px; color: var(--acc); padding: 4px; }
.r-pop .w .x { margin-left: auto; color: var(--dim); font-size: 22px; padding: 0 4px; }
.r-pop .sub { color: var(--dim); font-size: 14px; margin: 2px 0 10px; }
.r-pop .sec { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--dim); margin: 12px 0 6px; }
.r-sense { display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 10px; margin: 0 0 4px; border: 1px solid transparent; }
.r-sense .g { display: block; font-size: 12px; color: var(--dim); }
.r-sense .d { display: block; font-size: 16px; }
.r-sense.on { background: color-mix(in srgb, var(--acc) 12%, transparent); border-color: color-mix(in srgb, var(--acc) 45%, transparent); }
.r-def { font-size: 14px; line-height: 1.4; margin: 0 0 6px; }
.r-def i { color: var(--dim); font-style: normal; font-size: 12px; margin-right: 4px; }
.r-def .ex { display: block; color: var(--dim); font-style: italic; margin-top: 2px; }
.r-add { display: flex; gap: 8px; margin-top: 10px; }
.r-addbar { position: sticky; bottom: -14px; margin: 8px -18px -14px; padding: 2px 18px 14px; background: var(--pop); border-top: 1px solid var(--line); }
@media (max-width: 600px) { .r-addbar { bottom: calc(-16px - var(--bot)); margin-bottom: calc(-16px - var(--bot)); padding-bottom: calc(16px + var(--bot)); } }
.r-moresense { color: var(--acc); font-size: 14px; padding: 4px 10px; }
.r-add input { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 16px; }
.r-pbtn { padding: 10px 16px; border-radius: 10px; background: var(--acc); color: #fff; font-weight: 600; white-space: nowrap; }
.r-pbtn:disabled { opacity: .5; }
.r-pbtn.ghost { background: var(--card); color: var(--fg); }
.r-note { font-size: 13px; color: var(--dim); margin-top: 8px; min-height: 1em; }
.r-note.ok { color: #2e9b4f; }
.r-note.err { color: #d0453b; }
.r-ctx { font: italic 14px/1.4 var(--serif); color: var(--dim); margin: 6px 0 0; }

.r-sheet { position: fixed; z-index: 31; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 60px);
  background: var(--pop); border-radius: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; }
@media (max-width: 600px) { .r-sheet { top: auto; bottom: 0; transform: translateX(-50%); width: 100%; border-radius: 18px 18px 0 0; max-height: 88vh; } }
.r-sheet header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.r-sheet header h3 { margin: 0; font-size: 18px; }
.r-sheet header button { color: var(--acc); font-weight: 600; }
.r-sheet .body { overflow-y: auto; padding: 8px 18px calc(var(--bot) + 18px); -webkit-overflow-scrolling: touch; }
.r-list { list-style: none; margin: 0; padding: 0; }
.r-list li { padding: 11px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; }
.r-list li:last-child { border-bottom: 0; }
.r-list .main { flex: 1; min-width: 0; }
.r-list .main b { font-family: var(--serif); font-size: 18px; font-weight: 600; }
.r-list .main .de { display: block; }
.r-list .main small { display: block; color: var(--dim); font-size: 13px; margin-top: 2px; }
.r-list .del { color: var(--dim); font-size: 15px; padding: 4px 6px; }
.r-toc li { padding: 0; }
.r-toc button { display: block; width: 100%; text-align: left; padding: 11px 0; }
.r-toc button.cur { color: var(--acc); font-weight: 600; }
.r-field { margin: 14px 0; }
.r-field label { display: block; font-size: 13px; color: var(--dim); margin-bottom: 6px; }
.r-field input[type=text], .r-field input[type=password] { width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 16px; }
.r-switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; }
.r-switch input { width: 22px; height: 22px; accent-color: var(--acc); }
.r-seg { display: flex; gap: 8px; flex-wrap: wrap; }
.r-seg button { flex: 1; min-width: 64px; padding: 10px 8px; border-radius: 10px; border: 1.5px solid var(--line); font-size: 15px; }
.r-seg button.on { border-color: var(--acc); color: var(--acc); font-weight: 600; }
.r-theme { height: 46px; border-radius: 23px !important; }
.r-steps { line-height: 1.5; padding-left: 1.2em; margin: 6px 0; }
.r-steps li { margin: 6px 0; }
.r-code { display: flex; gap: 8px; align-items: center; background: var(--card); border-radius: 10px; padding: 8px 10px; font: 13px ui-monospace, Menlo, monospace; word-break: break-all; }
.r-code span { flex: 1; }
.r-login { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 24px; }
.r-login form { width: min(340px, 100%); text-align: center; }
.r-login h1 { font: 600 30px var(--serif); margin: 0 0 6px; }
.r-login p { color: var(--dim); margin: 0 0 20px; }
.r-login input { width: 100%; padding: 14px; font-size: 17px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); margin-bottom: 12px; }
.r-login button { width: 100%; padding: 14px; border-radius: 12px; background: var(--acc); color: #fff; font-weight: 600; font-size: 17px; }
.r-toast { position: fixed; left: 50%; bottom: calc(var(--bot) + 28px); transform: translateX(-50%); z-index: 40; background: var(--fg); color: var(--bg); padding: 10px 16px;
  border-radius: 20px; font-size: 15px; box-shadow: var(--shadow); max-width: calc(100vw - 40px); text-align: center; }
.r-loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--dim); }
