:root{color-scheme:dark;--bg:#1b1a17;--surface:#25231f;--ink:#f5efdf;--muted:#c3b7a2;--accent:#f5d392;--line:#4c4437;--paper:#f7edda;font:16px/1.55 system-ui,sans-serif;
  --accent-ink:#251c0d;--accent-hover:#ffe3af;--field:#211f1c;--bar:#211e19;--bar-shadow:#0006;--raised:#221e18;--card:#25211b;--feature:#29231b;--feature-line:#594635;
  --cover:#3b3023;--track:#463b2c;--fill:#e4b76f;--cal:#2c271f;--lv1:#5a4630;--lv2:#8a6a3e;--lv3:#e4b76f;--btn-line:#594d3e;--btn-ink:#e0d3be;--btn-hover:#362b22;--btn-hover-ink:#fff0d9;
  --rule:#927047;--label:#ece0cb;--frame:#4c4031;--ok-ink:#c7f1ca;--ok-bg:#20462e;--ok-line:#7bb787;--bad-ink:#ffd5cc;--bad-bg:#642d2a;--bad-line:#de8b80;
  --shelf-line:#42392d;--shelf-ink:#f5ecdb;--shelf-muted:#c1b49e}
/* Light theme: warm paper. The reader page pins itself to dark. */
:root[data-theme=light]{color-scheme:light;--bg:#f6f0e4;--surface:#fffaf2;--ink:#2b2219;--muted:#665746;--accent:#8a5712;--line:#d6c7ad;
  --accent-ink:#fffaf2;--accent-hover:#6f4510;--field:#fffdf8;--bar:#efe5d3;--bar-shadow:#3b2a1414;--raised:#fbf5ea;--card:#fbf5ea;--feature:#f2e4cc;--feature-line:#d8bf97;
  --cover:#e6d8c0;--track:#e4d6bd;--fill:#b07a2e;--cal:#ebe1cf;--lv1:#e8d2a8;--lv2:#cf9f58;--lv3:#9a6720;--btn-line:#cbb796;--btn-ink:#4a3b2b;--btn-hover:#eadcc4;--btn-hover-ink:#2b2219;
  --rule:#b48a52;--label:#3d3125;--frame:#d6c7ad;--ok-ink:#1d4a2b;--ok-bg:#dcefdf;--ok-line:#6aa477;--bad-ink:#7a2a22;--bad-bg:#f9e0db;--bad-line:#d48479;
  --shelf-line:#ddcdb2;--shelf-ink:#2b2219;--shelf-muted:#665746}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}body{margin:0;background:var(--bg);color:var(--ink)}[hidden]{display:none!important}a{color:inherit;text-decoration:none}a:hover{color:var(--accent)}:focus-visible{outline:2px solid var(--accent);outline-offset:4px}
h1,h2,p{margin:0}h1,h2,.wordmark{font-family:Georgia,serif;font-weight:500;line-height:1.04}h1{font-size:clamp(3rem,7vw,5.8rem);letter-spacing:-.045em}h1 span,.wordmark span{color:var(--accent)}
button,input,select{font:inherit;color:inherit}button,select{min-height:44px;padding:.48rem .85rem;background:var(--surface);border:1px solid var(--line);border-radius:.4rem}button{cursor:pointer}button:hover:not(:disabled){border-color:var(--accent)}button:disabled{opacity:.45;cursor:default}.primary{background:var(--accent);color:var(--accent-ink);border-color:var(--accent);font-weight:700}.primary:hover:not(:disabled){background:var(--accent-hover)}
input:not([type=file]){width:100%;border:1px solid var(--line);border-radius:.4rem;background:var(--field);padding:.65rem .8rem}.muted{color:var(--muted)}.eyebrow{color:var(--accent);font-size:.72rem;font-weight:750;text-transform:uppercase;letter-spacing:.19em;margin-bottom:.65rem}.notice{color:var(--accent);min-height:1.6em}.visually-hidden{position:absolute;clip-path:inset(50%);width:1px;height:1px;overflow:hidden;white-space:nowrap}
.login-page{min-height:100svh;display:grid;place-items:center;padding:1.4rem;background:radial-gradient(ellipse at 50% 25%,#343021,var(--bg) 65%)}.login-card{width:min(100%,29rem);border-top:1px solid var(--accent);padding:2.2rem 0}.login-card p.muted{margin-top:.7rem}.login-card form{display:grid;gap:1rem;margin-top:2rem}.login-card label{display:grid;gap:.35rem}.login-card button{justify-self:start;min-width:8rem}
.masthead{border-bottom:1px solid var(--line);display:flex;justify-content:space-between;align-items:center;padding:1rem clamp(1rem,5vw,4rem)}.wordmark{font-size:1.75rem}.shelf{width:min(92%,76rem);margin:0 auto;padding:clamp(2rem,6vw,5rem) 0}.shelf-head{display:flex;align-items:end;justify-content:space-between;gap:1rem;margin-bottom:1.5rem;flex-wrap:wrap}.shelf-head .muted{margin-top:.75rem}
.books{display:grid;grid-template-columns:repeat(auto-fill,minmax(min(10rem,100%),1fr));gap:2rem 1.35rem;margin-top:1rem}.book-card{min-width:0;display:flex;flex-direction:column;gap:.55rem}.book-card h2{font-size:1.18rem;line-height:1.2;overflow-wrap:anywhere}.cover{background:var(--cover);border:1px solid var(--line);border-radius:.3rem;aspect-ratio:2/3;display:grid;place-items:center;overflow:hidden}.cover img{width:100%;height:100%;object-fit:cover}.cover span{font-family:Georgia,serif;color:var(--accent);font-size:1.2rem;text-align:center;padding:1rem}.book-card .muted{font-size:.8rem}.book-actions{display:flex;flex-wrap:wrap;gap:.4rem;margin-top:auto}.book-actions button{font-size:.85rem}.transfer{display:flex;align-items:center;justify-content:space-between;gap:1rem;border:1px solid var(--line);border-radius:.45rem;padding:1rem;background:var(--surface);margin:1rem 0}.transfer>div{flex:1}progress{width:min(100%,30rem);accent-color:var(--accent)}
#page-list{position:absolute;inset:0 auto 0 0;width:min(40vw,12rem);z-index:2;overflow:auto;padding:.55rem;background:var(--bg);border-right:1px solid var(--line)}#thumb-items button{display:grid;width:100%;place-items:center;gap:.25rem;margin-bottom:.45rem;min-height:5rem}#thumb-items img{max-width:100%;height:auto}dialog{background:var(--surface);color:var(--ink);border:1px solid var(--line);border-radius:.5rem;padding:1.3rem;width:min(28rem,92vw)}dialog::backdrop{background:#000a}dialog p{margin:.7rem 0}.dialog-actions{display:flex;gap:.5rem;flex-wrap:wrap}
@media(max-width:480px){.books{grid-template-columns:repeat(2,minmax(0,1fr));gap:1.5rem .8rem}}

.reader-page { overflow: hidden; background: #292829; }
.reader {
  --reader-bg: #292829;
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  width: 100%;
  height: 100dvh;
  background: var(--reader-bg);
  color: #ebe9e6;
}
.reader-header {
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 1rem;
  min-height: 2.8rem;
  padding: .35rem max(1rem, env(safe-area-inset-left));
  background: #1c1c1d;
}
.reader-header a { flex: none; font-size: .85rem; color: #d5d1cb; }
.reader-header h1 { font: 600 .9rem/1.3 system-ui, sans-serif; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-main { position: relative; min-height: 0; overflow: hidden; }
.reader-main #book { width: 100%; height: 100%; }
.reader-status {
  position: absolute;
  top: 1rem;
  left: 50%;
  z-index: 1;
  transform: translateX(-50%);
  max-width: 90%;
  padding: .5rem .8rem;
  border-radius: .3rem;
  background: #191a1b;
}
.reader-status:empty { display: none; }
.reader-tools {
  z-index: 4;
  display: flex;
  justify-content: center;
  align-items: center;
  justify-self: center;
  width: max-content;
  max-width: calc(100% - 1rem);
  margin: 0 auto max(.5rem, env(safe-area-inset-bottom));
  padding: .38rem .52rem;
  border: 1px solid #363537;
  border-radius: 1rem;
  background: #191a1b;
  box-shadow: 0 .5rem 2rem #0005;
}
.reader-tool-group { display: flex; align-items: center; gap: clamp(0rem, 1vw, .6rem); }
.reader-tool-group + .reader-tool-group { margin-left: .55rem; padding-left: .55rem; border-left: 1px solid #363537; }
.reader-tool-group > button, .reader-options summary {
  display: grid;
  place-items: center;
  width: clamp(2.3rem, 5.5vw, 3.4rem);
  min-height: 2.75rem;
  padding: 0;
  border: 1px solid transparent;
  border-radius: .65rem;
  background: transparent;
  color: #b1ada6;
  cursor: pointer;
}
.reader-tool-group > button:hover, .reader-options summary:hover { background: #262728; color: #ebe9e6; }
.reader-tool-group > button[aria-expanded="true"], .reader-options[open] summary {
  background: #302a21;
  border-color: #6e5837;
  color: #e9b765;
}
.reader-tools svg { width: 1.3rem; height: 1.3rem; fill: none; stroke: currentColor; stroke-width: 2.3; stroke-linecap: round; stroke-linejoin: round; }
.reader-options summary { list-style: none; }
.reader-options summary::-webkit-details-marker { display: none; }
.reader-tools #jump {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .2rem .48rem .2rem .2rem;
  border: 1px solid #303033;
  border-radius: .65rem;
  white-space: nowrap;
  font-size: .88rem;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}
.reader-tools #page-number {
  width: 2.8rem;
  padding: .34rem .12rem;
  border: 0;
  border-radius: .48rem;
  background: #252629;
  text-align: center;
  appearance: textfield;
}
.reader-tools #page-number::-webkit-inner-spin-button,
.reader-tools #page-number::-webkit-outer-spin-button { appearance: none; }
.reader-tools #total { color: #d5d1cb; }
.reader-options { position: relative; }
.reader-options-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + .75rem);
  display: grid;
  width: max-content;
  gap: .4rem;
  padding: .65rem;
  border: 1px solid #363537;
  border-radius: .7rem;
  background: #191a1b;
  box-shadow: 0 .5rem 2rem #0006;
  font-size: .9rem;
}
.reader-options-panel button, .reader-options-panel select { background: #252629; border-color: #414142; }
.reader-tools #fullscreen .exit-icon, .reader.is-fullscreen #fullscreen .enter-icon { display: none; }
.reader.is-fullscreen #fullscreen .exit-icon { display: block; }
.reader.is-fullscreen { position: fixed; inset: 0; z-index: 10; height: 100%; grid-template-rows: minmax(0, 1fr); }
.reader.is-fullscreen .reader-header { position: absolute; inset: 0 0 auto; }
.reader.is-fullscreen .reader-tools { position: absolute; inset: auto 0 0; }
.reader.is-fullscreen .reader-header, .reader.is-fullscreen .reader-tools { transition: opacity .18s ease-out; }
.reader.is-fullscreen .reader-status { top: 3.25rem; }
.reader.is-fullscreen #page-list { top: 2.8rem; bottom: 4.2rem; }
.reader.is-fullscreen.chrome-hidden .reader-header, .reader.is-fullscreen.chrome-hidden .reader-tools {
  opacity: 0;
  pointer-events: none;
}
@media (prefers-reduced-motion: reduce) {
  .reader.is-fullscreen .reader-header, .reader.is-fullscreen .reader-tools { transition: none; }
}

.library-page .shelf { width: min(calc(100% - 2rem), 78rem); padding-top: clamp(2rem, 5vw, 4rem); }
.library-page .shelf-head { margin-bottom: .8rem; }
.library-page .shelf-head h1 { font-size: clamp(3rem, 7vw, 5rem); }
.library-page .shelf-head .muted { max-width: 32rem; }
.library-page #status:empty { min-height: 0; }
.shelf-section { margin-top: 2.2rem; }
.shelf-section > h2 {
  display: flex;
  align-items: baseline;
  gap: .75rem;
  margin-bottom: .85rem;
  padding-bottom: .65rem;
  border-bottom: 1px solid var(--shelf-line);
  font-size: clamp(1.5rem, 2.5vw, 2rem);
}
#book-count { color: var(--shelf-muted); font: .75rem/1.4 system-ui, sans-serif; }
.library-page .books {
  grid-template-columns: repeat(auto-fill, minmax(min(9.4rem, 100%), 1fr));
  align-items: start;
  gap: 1.75rem 1rem;
}
.library-page .book-card h3 {
  margin: 0;
  color: var(--shelf-ink);
  font: 500 1.07rem/1.22 Georgia, serif;
  overflow-wrap: anywhere;
}
.library-page .cover {
  position: relative;
  display: grid;
  width: 100%;
  min-height: 0;
  padding: 0;
  border-color: var(--shelf-line);
  border-radius: .3rem;
  background: var(--cover);
}
.library-page .cover img { position: absolute; inset: 0; object-fit: cover; object-position: center; }
.library-page .cover > span:not(.storage-icon) { max-width: 100%; overflow-wrap: anywhere; }
.library-page button.cover:hover img { filter: brightness(.85); }
.book-details { display: grid; gap: .34rem; min-width: 0; }
.book-position {
  display: flex;
  justify-content: space-between;
  gap: .2rem;
  font-size: .77rem;
  font-variant-numeric: tabular-nums;
}
.book-position span { color: var(--accent); }
.book-reading { display: grid; gap: .28rem; }
.book-reading progress {
  display: block;
  width: 100%;
  height: .28rem;
  appearance: none;
  border: 0;
  border-radius: 100vw;
  background: var(--track);
}
.book-reading progress::-webkit-progress-bar { background: var(--track); border-radius: 100vw; }
.book-reading progress::-webkit-progress-value { background: var(--fill); border-radius: 100vw; }
.book-reading progress::-moz-progress-bar { background: var(--fill); border-radius: 100vw; }
.library-page .book-remove {
  min-height: 2rem;
  padding: .1rem .28rem;
  border-color: transparent;
  background: transparent;
  color: var(--shelf-muted);
  font-size: .73rem;
}
.library-page .continue-card {
  display: grid;
  grid-template-columns: minmax(5rem, 10rem) minmax(0, 1fr);
  align-items: center;
  gap: clamp(.9rem, 3vw, 2.2rem);
  padding: clamp(.85rem, 2.6vw, 1.6rem);
  border: 1px solid var(--feature-line);
  border-radius: .75rem;
  background: var(--feature);
}
.library-page .continue-card h3 { font-size: clamp(1.45rem, 4vw, 2.55rem); }
.continue-card .book-details { max-width: 30rem; gap: .55rem; }
.continue-card .book-actions { align-items: center; margin-top: .3rem; }
.recent-books { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(15rem, 100%), 1fr)); gap: .7rem; }
.library-page .recent-card {
  display: grid;
  grid-template-columns: 3.45rem minmax(0, 1fr);
  align-items: start;
  gap: .7rem;
  padding: .65rem;
  border: 1px solid var(--shelf-line);
  border-radius: .55rem;
  background: var(--card);
}
.library-page .recent-card .cover > span:not(.storage-icon) { font-size: .55rem; padding: .2rem; overflow-wrap: anywhere; }
@media (max-width: 420px) {
  .library-page .books { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .library-page .continue-card { grid-template-columns: minmax(4rem, 5.5rem) minmax(0, 1fr); }
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  font-size: clamp(1.35rem, 3vw, 1.8rem);
  line-height: 1;
  letter-spacing: -.035em;
}
.wordmark img { flex: none; border-radius: .35rem; }
.wordmark span { color: var(--ink); }
.logout-button {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  min-height: 2.75rem;
  padding: .4rem .78rem;
  border-color: var(--btn-line);
  border-radius: .45rem;
  background: transparent;
  color: var(--btn-ink);
  font-size: .84rem;
  font-weight: 650;
}
.logout-button:hover:not(:disabled) { background: var(--btn-hover); color: var(--btn-hover-ink); }
.logout-button svg { width: 1rem; height: 1rem; stroke: currentColor; stroke-width: 1.8; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.shelf-label { display: inline-block; margin: 0 0 .55rem; padding-bottom: .25rem; border-bottom: 1px solid var(--rule); }

.login-page {
  min-height: 100svh;
  padding: clamp(.8rem, 3vw, 2rem);
  background: var(--bg);
}
.login-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.04fr) minmax(0, 1fr);
  width: min(100%, 63rem);
  border: 1px solid var(--frame);
  border-radius: 1rem;
  overflow: hidden;
  background: var(--card);
}
.login-intro {
  position: relative;
  isolation: isolate;
  min-height: 36rem;
  padding: clamp(1.3rem, 4vw, 2.5rem);
  overflow: hidden;
  background: #38291e;
}
.login-intro .wordmark { margin-bottom: 3.2rem; }
.login-intro .wordmark span { color: #f7e9d0; }
.login-intro .eyebrow { color: #e7c18b; }
.login-tagline {
  color: #f7e9d0;
  font: 500 clamp(2.8rem, 5.6vw, 4.8rem)/.96 Georgia, serif;
  letter-spacing: -.052em;
}
.login-intro-copy { max-width: 16rem; margin-top: .95rem; color: #e0cbb1; }
.login-illustration {
  position: absolute;
  z-index: -1;
  right: -4rem;
  bottom: -5rem;
  width: 19rem;
  height: 19rem;
  transform: rotate(-14deg);
}
.login-volume {
  position: absolute;
  inset: 0 1.5rem 0 0;
  display: grid;
  align-content: start;
  justify-items: center;
  padding-top: 2.4rem;
  border: 1px solid #9a684a;
  border-left: .7rem solid #49291f;
  border-radius: .35rem 1rem 1rem .35rem;
  background: #643e2e;
  box-shadow: .45rem .6rem 0 #9a7254, .7rem .83rem 0 #392920;
}
.login-volume::before { content: ""; position: absolute; inset: .7rem; border: 1px solid #af7858; border-radius: .3rem .6rem .6rem .3rem; }
.login-volume img { position: relative; margin-right: 1rem; }
.login-layout .login-card {
  align-self: center;
  width: 100%;
  min-width: 0;
  padding: clamp(1.4rem, 4.4vw, 3.5rem);
  border: 0;
}
.login-card h1 { font-size: clamp(2.1rem, 4vw, 3.45rem); letter-spacing: -.042em; }
.login-card label { color: var(--label); font-size: .9rem; font-weight: 650; }
.login-card input { min-height: 3rem; font-size: 1rem; font-weight: 400; }
.login-card button.primary { display: flex; justify-content: space-between; width: 100%; min-height: 3rem; padding-inline: 1rem; }
.login-card .notice:empty { display: none; }

.recent-books { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.library-page .book-storage { display: flex; align-items: center; gap: .4rem; }
.storage-icon {
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 1.55rem;
  height: 1.55rem;
  padding: 0;
  border: 1px solid;
  border-radius: 50%;
}
.library-page .cover .storage-icon {
  position: absolute;
  right: .4rem;
  bottom: .4rem;
  width: 1.85rem;
  height: 1.85rem;
  padding: 0;
}
.library-page .recent-card .cover .storage-icon { right: .16rem; bottom: .16rem; width: 1.3rem; height: 1.3rem; }
.storage-icon.is-stored { color: var(--ok-ink); background: var(--ok-bg); border-color: var(--ok-line); }
.storage-icon.needs-download { color: var(--bad-ink); background: var(--bad-bg); border-color: var(--bad-line); }
.storage-icon svg { width: 65%; height: 65%; stroke: currentColor; stroke-width: 2.2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
@media (max-width: 780px) {
  .login-illustration { right: -6rem; bottom: -6rem; }
}
@media (max-width: 560px) {
  .login-page { align-items: start; padding: .75rem; }
  .login-layout { grid-template-columns: minmax(0, 1fr); }
  .login-intro { min-height: 0; padding: 1.3rem; }
  .login-intro .wordmark { margin-bottom: 1.2rem; }
  .login-tagline { font-size: clamp(2.4rem, 10vw, 3.5rem); }
  .login-tagline br { display: none; }
  .login-tagline br::after { content: " "; }
  .login-intro-copy { margin-top: .7rem; font-size: .88rem; }
  .login-illustration { display: none; }
  .login-layout .login-card { padding: 1.3rem; }
  .login-card form { margin-top: 1.3rem; }
}

.panel-heading { margin: .35rem 0 .5rem; color: var(--accent); font: 750 .7rem/1.4 system-ui, sans-serif; letter-spacing: .14em; text-transform: uppercase; }
.bookmark-items { display: grid; gap: .35rem; margin-bottom: 1rem; }
.bookmark-items button { display: block; width: 100%; min-height: 2.75rem; text-align: left; font-size: .82rem; overflow-wrap: anywhere; }
.bookmark-items strong { color: var(--accent); font-variant-numeric: tabular-nums; }
.bookmark-items p { color: var(--muted); font-size: .8rem; }
.reader-tool-group > button[aria-pressed="true"] { color: #e9b765; }
#bookmark[aria-pressed="true"] svg { fill: currentColor; }
.timer-pill {
  position: absolute;
  top: .6rem;
  right: .6rem;
  z-index: 2;
  padding: .2rem .6rem;
  border: 1px solid #6e5837;
  border-radius: 100vw;
  background: #191a1bd9;
  color: #e9b765;
  font: 650 .85rem/1.4 system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.reader.is-fullscreen .timer-pill { top: 3.25rem; }
.reader.is-fullscreen.chrome-hidden .timer-pill { top: .6rem; opacity: .7; }
dialog h2 { font-size: 1.5rem; }
dialog label { display: grid; gap: .35rem; margin-bottom: 1rem; }
dialog textarea { width: 100%; padding: .6rem .8rem; border: 1px solid var(--line); border-radius: .4rem; background: var(--field); font: inherit; color: inherit; resize: vertical; }
.timer-presets { display: flex; gap: .5rem; flex-wrap: wrap; margin: 1rem 0; }
.timer-presets button { flex: 1; }

.habit-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: clamp(1rem, 4vw, 3rem); align-items: start; }
.habit-figure { font: 500 clamp(1.8rem, 4vw, 2.6rem)/1.1 Georgia, serif; }
.habit-figure span { color: var(--muted); font: .95rem/1.4 system-ui, sans-serif; }
.habit-today { display: grid; gap: .6rem; }
.habit-today progress { width: 100%; height: .45rem; appearance: none; border: 0; border-radius: 100vw; background: var(--track); }
.habit-today progress::-webkit-progress-bar { background: var(--track); border-radius: 100vw; }
.habit-today progress::-webkit-progress-value { background: var(--fill); border-radius: 100vw; }
.habit-today progress::-moz-progress-bar { background: var(--fill); border-radius: 100vw; }
.goal-form summary { width: max-content; color: var(--muted); font-size: .85rem; cursor: pointer; }
.goal-form form { display: flex; align-items: end; gap: .5rem; margin-top: .6rem; }
.goal-form label { display: grid; gap: .3rem; font-size: .85rem; }
.goal-form input { width: 6rem !important; }
.habit-calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 2.2rem)); gap: .3rem; margin: 0 0 .6rem; padding: 0; list-style: none; }
.habit-calendar li { aspect-ratio: 1; border-radius: .3rem; background: var(--cal); }
.habit-calendar .dow { display: grid; place-items: center; aspect-ratio: auto; background: none; color: var(--muted); font-size: .7rem; }
.habit-calendar .blank { background: none; }
.habit-calendar .level-1 { background: var(--lv1); }
.habit-calendar .level-2 { background: var(--lv2); }
.habit-calendar .level-3 { background: var(--lv3); }
.habit-calendar .is-today { outline: 1px solid var(--ink); outline-offset: 1px; }
@media (max-width: 640px) { .habit-grid { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 560px) {
  .habit { margin-top: 1.6rem; padding: .85rem; border: 1px solid var(--shelf-line); border-radius: .65rem; background: var(--raised); }
  .habit > h2 { margin-bottom: .6rem; padding-bottom: .45rem; font-size: 1.15rem; }
  .habit-grid { gap: .6rem; }
  .habit-today { gap: .35rem; }
  .habit-figure { font-size: 1.4rem; }
  .habit-figure span, .habit-today .muted, #habit-week { font-size: .8rem; }
  .habit-calendar { grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .25rem; margin-bottom: .35rem; }
  .habit-calendar .past { display: none; }
  .habit-calendar li:not(.dow) { aspect-ratio: auto; height: 1.4rem; }
}
@media (max-width: 560px) {
  .library-page .shelf-head { flex-wrap: nowrap; align-items: center; }
  .library-page .shelf-head h1 { font-size: 2.3rem; }
  .library-page .shelf-head .muted { margin-top: .4rem; font-size: .9rem; }
  .library-page #import { flex: none; min-height: 2.5rem; padding: .3rem .75rem; font-size: .85rem; }
}
/* Phones zoom with a pinch or a double tap; the toolbar keeps one row for the controls that have no gesture. */
@media (max-width: 520px) {
  .reader-tools #zoom-in, .reader-tools #zoom-out { display: none; }
}

/* Menu hidden by a tap in the middle of the page, outside full screen too: the page takes the room. */
.reader:not(.is-fullscreen).chrome-hidden { grid-template-rows: minmax(0, 1fr); }
.reader:not(.is-fullscreen).chrome-hidden .reader-header,
.reader:not(.is-fullscreen).chrome-hidden .reader-tools { display: none; }

.tool-label { display: none; }
.reader-options-panel { max-height: min(70dvh, 34rem); overflow: auto; width: min(19rem, calc(100vw - 1.5rem)); }
.option-heading { margin-top: .4rem; color: #d5d1cb; font-size: .8rem; font-weight: 700; }
.option-row { display: flex; flex-wrap: wrap; gap: .4rem; }
.option-row > * { flex: 1; }
.option-check { display: flex; align-items: center; gap: .55rem; min-height: 2.75rem; }
.option-check input, .option-pill input { width: 1.15rem; height: 1.15rem; accent-color: #e9b765; }
.option-pill { display: flex; align-items: center; justify-content: center; gap: .35rem; min-height: 2.75rem; padding: 0 .5rem; border: 1px solid #414142; border-radius: .45rem; background: #252629; cursor: pointer; }
.option-pill:has(input:checked) { border-color: #e9b765; color: #e9b765; }
#brightness { width: 100%; accent-color: #e9b765; }
#large-ui[aria-pressed="true"] { border-color: #e9b765; color: #e9b765; }

.hint-dialog { width: min(32rem, 94vw); }
.hint-zones { display: grid; grid-template-columns: 3fr 4fr 3fr; gap: .35rem; margin: 1rem 0; text-align: center; font-size: .85rem; }
.hint-zones span { display: grid; place-items: center; min-height: 7rem; padding: .5rem; border: 1px dashed #6e5837; border-radius: .5rem; background: #2c271f; }
.hint-list { display: grid; gap: .5rem; margin: 0 0 1.2rem; padding-left: 1.2rem; }

.masthead-actions { display: flex; align-items: center; gap: .5rem; }
.large-icon { font: 700 .8rem/1 Georgia, serif; }
.large-icon span { font-size: 1.15rem; }
#large-ui[aria-pressed="true"] .large-icon { color: var(--accent); }
@media (max-width: 420px) {
  .masthead { padding-inline: 1rem; }
  .masthead .wordmark span { font-size: 1.15rem; }
  .masthead-actions .logout-button { padding-inline: .55rem; }
  .masthead-actions .large-text { position: absolute; clip-path: inset(50%); width: 1px; height: 1px; overflow: hidden; white-space: nowrap; }
}

/* Larger text and buttons, for readers who hold the phone further away. */
html.large-ui { font-size: 19px; }
.large-ui .eyebrow, .large-ui .library-page .book-remove, .large-ui .book-position, .large-ui .book-card .muted,
.large-ui #book-count, .large-ui .habit-calendar .dow, .large-ui .goal-form summary, .large-ui .goal-form label,
.large-ui .bookmark-items button, .large-ui .panel-heading, .large-ui .logout-button, .large-ui .reader-header a,
.large-ui .reader-header h1, .large-ui .habit-today .muted, .large-ui #habit-week, .large-ui .habit-figure span,
.large-ui .option-heading, .large-ui .reader-options-panel { font-size: max(.85rem, 16px); }
.large-ui .library-page .book-remove { min-height: 2.75rem; }
.large-ui .reader-tool-group > button, .large-ui .reader-options summary {
  width: auto;
  min-width: 3.1rem;
  min-height: 3.3rem;
  padding: .2rem .25rem;
  gap: .12rem;
  align-content: center;
}
.large-ui .tool-label { display: block; font: 600 .72rem/1.1 system-ui, sans-serif; }
/* On a phone the settings open as a sheet as wide as the toolbar, not hanging off the button. */
@media (max-width: 560px) {
  .reader-tools { position: relative; }
  .reader-options { position: static; }
  .reader-options-panel { left: 0; right: 0; width: auto; }
}

/* The masthead stays at the top while the shelf scrolls under it. */
.masthead { position: sticky; top: 0; z-index: 20; background: var(--bar); box-shadow: 0 .4rem 1.2rem var(--bar-shadow); }
.lang-toggle { gap: .3rem; letter-spacing: .04em; }
.lang-toggle [data-lang] { opacity: .55; }
.lang-toggle[data-lang="en"] [data-lang="en"], .lang-toggle[data-lang="id"] [data-lang="id"] { opacity: 1; color: var(--accent); }
.login-card .login-lang { display: flex; width: max-content; min-width: 0; margin: 0 0 1.2rem auto; }
@media (max-width: 420px) {
  .masthead-actions { gap: .35rem; }
  .masthead-actions .logout-text { position: absolute; clip-path: inset(50%); width: 1px; height: 1px; overflow: hidden; white-space: nowrap; }
}

/* Habit calendar: three levels by hours read, brightest glows. */
.habit-calendar .level-3, .habit-legend .level-3 { box-shadow: 0 0 .55rem color-mix(in srgb, var(--lv3) 50%, transparent); }
.habit-legend { display: flex; flex-wrap: wrap; gap: .3rem .9rem; margin: 0 0 .55rem; padding: 0; list-style: none; color: var(--muted); font-size: .78rem; }
.habit-legend li { display: flex; align-items: center; gap: .35rem; }
.habit-legend i { width: .8rem; height: .8rem; border-radius: .2rem; }
.habit-legend .level-1 { background: var(--lv1); }
.habit-legend .level-2 { background: var(--lv2); }
.habit-legend .level-3 { background: var(--lv3); }
.large-ui .habit-legend { font-size: 1rem; }

/* Library search, filter and sort. */
.shelf-tools { display: flex; flex-wrap: wrap; gap: .5rem; margin: 0 0 1rem; }
.shelf-tools .shelf-search { flex: 1 1 14rem; }
.shelf-tools input, .shelf-tools select { width: 100%; min-height: 2.75rem; }
.shelf-tools label:not(.shelf-search) { flex: 1 1 9rem; }
#no-match { margin: 0 0 1rem; }

/* Install banner. */
.install-banner { display: flex; align-items: center; gap: .85rem; margin: 0 0 1.2rem; padding: .8rem .9rem; border: 1px solid var(--shelf-line); border-radius: .7rem; background: var(--raised); }
.install-banner[hidden] { display: none; }
.install-banner img { flex: none; border-radius: .6rem; }
.install-banner > div:first-of-type { flex: 1; min-width: 0; }
.install-banner p { margin: .2rem 0 0; font-size: .85rem; }
.install-actions { display: flex; align-items: center; gap: .4rem; }
#install-close { display: grid; place-items: center; width: 2.75rem; height: 2.75rem; padding: 0; background: none; border-color: transparent; }
#install-close svg { width: 1.2rem; height: 1.2rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
@media (max-width: 560px) {
  .install-banner { flex-wrap: wrap; gap: .6rem .75rem; }
  .install-banner > div:first-of-type { flex: 1 1 calc(100% - 4rem); }
  .install-actions { width: 100%; justify-content: flex-end; }
}

/* Quote: drag a box over the page, then share it. */
.quote-layer { position: fixed; z-index: 30; touch-action: none; cursor: crosshair; background: #0003; }
.quote-layer[hidden] { display: none; }
.quote-help { position: absolute; inset: .6rem .6rem auto; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .5rem .8rem; margin: 0; padding: .55rem .8rem; border-radius: .6rem; background: #191a1bee; color: #f4efe6; font-size: .95rem; text-align: center; cursor: default; }
.quote-box { position: absolute; border: 2px solid #e4b76f; border-radius: .2rem; background: #e4b76f22; box-shadow: 0 0 0 100vmax #0006; pointer-events: none; }
.quote-box[hidden] { display: none; }
.quote-preview { display: block; max-width: 100%; max-height: 55dvh; margin: 0 auto 1rem; border-radius: .3rem; object-fit: contain; }
.reader-options-panel .option-primary { border-color: #8a6a3e; }

/* Keyboard shortcuts mean nothing on a touch screen. */
@media (hover: none) { .hint-keys { display: none; } }
/* Theme switch: the sun offers light, the moon offers dark. */
.library-page #large-ui[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.theme-toggle { justify-content: center; min-width: 2.75rem; padding-inline: .6rem; }
.theme-toggle .theme-moon, [data-theme=light] .theme-toggle .theme-sun { display: none; }
[data-theme=light] .theme-toggle .theme-moon { display: block; }
.login-card .login-switches { display: flex; justify-content: flex-end; gap: .4rem; margin: 0 0 1.2rem; }
.login-card .login-switches .login-lang { margin: 0; }
/* Admin dashboard. */
.admin-tabs { display: flex; gap: .25rem; margin: 1.2rem 0 .4rem; border-bottom: 1px solid var(--shelf-line); overflow-x: auto; }
.admin-tabs [role=tab] { min-height: 2.75rem; border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; color: var(--muted); font-weight: 650; white-space: nowrap; }
.admin-tabs [role=tab][aria-selected=true] { border-bottom-color: var(--accent); color: var(--ink); }
.admin-tabs [role=tab]:hover { color: var(--ink); }
.admin-page #status:empty { min-height: 0; }
.admin-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(10rem, 100%), 1fr)); gap: .7rem; margin: 1rem 0 2rem; }
.admin-stats div { padding: .9rem 1rem; border: 1px solid var(--shelf-line); border-radius: .6rem; background: var(--card); }
.admin-stats dt { color: var(--muted); font-size: .8rem; }
.admin-stats dd { margin: .2rem 0 0; font: 500 2rem/1.1 Georgia, serif; font-variant-numeric: tabular-nums; }
.admin-heading { font-size: clamp(1.3rem, 2.5vw, 1.7rem); margin: 0 0 .8rem; }
.admin-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem; margin: 1.2rem 0 .8rem; }
.admin-toolbar .admin-heading { margin: 0; }
.table-wrap { overflow-x: auto; border: 1px solid var(--shelf-line); border-radius: .6rem; background: var(--card); }
.admin-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.admin-table th { color: var(--muted); font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-align: left; text-transform: uppercase; }
.admin-table th, .admin-table td { padding: .6rem .8rem; border-bottom: 1px solid var(--shelf-line); vertical-align: middle; overflow-wrap: anywhere; }
.admin-table tbody tr:last-child td { border-bottom: 0; }
.admin-table td:last-child button { min-height: 2.5rem; padding-block: .3rem; font-size: .85rem; }
.admin-table .nowrap { white-space: nowrap; overflow-wrap: normal; }
.admin-sub { display: block; font-size: .8rem; }
.badge { display: inline-block; padding: .1rem .5rem; border: 1px solid var(--shelf-line); border-radius: 100vw; font-size: .78rem; font-weight: 650; white-space: nowrap; }
.badge.is-ok { color: var(--ok-ink); background: var(--ok-bg); border-color: var(--ok-line); }
.badge.is-bad { color: var(--bad-ink); background: var(--bad-bg); border-color: var(--bad-line); }
.badge.is-accent { color: var(--accent); border-color: var(--accent); }
.admin-more { margin-top: .8rem; }
.admin-page dialog { width: min(32rem, 94vw); }
.admin-page dialog select { width: 100%; }
.admin-form { display: grid; gap: .6rem; margin-top: 1.2rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.admin-form h3 { margin: 0; font: 650 1rem/1.3 system-ui, sans-serif; }
.admin-form label { margin: 0; }
.admin-form button { justify-self: start; }
.admin-danger h3 { color: var(--bad-line); }
button.danger { border-color: var(--bad-line); background: var(--bad-bg); color: var(--bad-ink); }
#manage-dialog > .dialog-actions:last-child { justify-content: flex-end; margin-top: 1.2rem; }
@media (max-width: 640px) {
  .admin-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-stats > :last-child { grid-column: 1 / -1; }
  .admin-table thead { display: none; }
  .admin-table, .admin-table tbody, .admin-table tr, .admin-table td { display: block; }
  .admin-table tr { padding: .6rem .8rem; border-bottom: 1px solid var(--shelf-line); }
  .admin-table tbody tr:last-child { border-bottom: 0; }
  .admin-table td { padding: .15rem 0; border: 0; }
  .admin-table td:last-child button { margin-top: .4rem; }
}

.dock-books, .dock-label { display: none; }
.library-dock { display: flex; align-items: center; gap: .5rem; }
.library-page .reader-shelf { padding-block: clamp(1.15rem, 3vw, 2.8rem) 3.5rem; }
.library-page .library-intro {
  align-items: end;
  flex-wrap: wrap;
  padding: clamp(1.15rem, 4vw, 3rem);
  border: 1px solid var(--feature-line);
  border-inline-start: .35rem solid var(--rule);
  border-radius: .45rem 1rem 1rem .45rem;
  background: var(--feature);
}
.library-page .library-intro h1 { font-size: clamp(2.3rem, 5vw, 4.8rem); }
.library-shortcuts { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.library-shortcuts a {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  min-height: 44px;
  padding: .45rem .85rem;
  border-radius: .4rem;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}
.library-shortcuts a:hover { background: var(--accent-hover); }
#catalog-heading { scroll-margin-top: 6rem; }
.shelf-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  width: min(92%, 76rem);
  margin: 0 auto;
  padding: 1rem 0 1.5rem;
  border-top: 1px solid var(--shelf-line);
}
.shelf-footer > p:first-child, .login-credit { font-family: Georgia, serif; font-size: 1.12rem; }
.shelf-footer span, .login-credit span { color: var(--muted); font: 600 .78rem system-ui, sans-serif; }
.login-credit { margin-top: 1.4rem; }
#request-confirmation { flex-basis: 100%; }
#request-confirmation:empty, #request-form .notice:empty { display: none; }
#request-dialog { width: min(33rem, 92vw); max-height: 90dvh; }
#request-form { display: grid; gap: .75rem; }
#request-form p { margin: 0; }
#request-form textarea { font: inherit; color: inherit; width: 100%; resize: vertical; border: 1px solid var(--line); border-radius: .4rem; background: var(--field); padding: .6rem .8rem; }
#request-form .dialog-actions { justify-content: flex-end; }
.admin-page .admin.shelf { padding-block: clamp(1.25rem, 4vw, 3.5rem); }
.admin-page .admin .shelf-head h1 { font-size: clamp(2.5rem, 5vw, 4rem); }
.r2-section { padding: clamp(.9rem, 2.5vw, 1.4rem); margin-bottom: 1.8rem; border: 1px solid var(--shelf-line); border-radius: .75rem; background: var(--raised); }
.r2-section .admin-toolbar { margin-top: 0; }
.r2-section .muted { font-size: .85rem; }
.usage-alert { border-inline-start: .25rem solid var(--ok-line); padding: .65rem .8rem; background: var(--ok-bg); color: var(--ok-ink); }
.usage-alert[data-tone=warning] { border-color: var(--rule); background: var(--feature); color: var(--ink); }
.usage-alert[data-tone=danger] { border-color: var(--bad-line); background: var(--bad-bg); color: var(--bad-ink); }
.usage-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(10rem, 100%), 1fr)); gap: .6rem; }
.usage-grid > div { min-width: 0; padding: .65rem .75rem; border: 1px solid var(--shelf-line); border-radius: .45rem; background: var(--field); }
.usage-grid dt { color: var(--muted); font-size: .8rem; }
.usage-grid dd { margin: .2rem 0 0; font-weight: 650; font-variant-numeric: tabular-nums; }
.usage-grid progress { display: block; width: 100%; height: .65rem; margin-top: .4rem; accent-color: var(--ok-line); }
.usage-grid progress[data-tone=warning] { accent-color: var(--rule); }
.usage-grid progress[data-tone=danger] { accent-color: var(--bad-line); }
.request-list { list-style: none; display: grid; gap: .65rem; padding: 0; }
.request-list li { display: flex; align-items: start; justify-content: space-between; flex-wrap: wrap; gap: .65rem; padding: .85rem 1rem; border: 1px solid var(--shelf-line); border-radius: .6rem; background: var(--card); overflow-wrap: anywhere; }
.request-list li > div { flex: 1 1 18rem; min-width: 0; }
.request-list h3 { margin: 0 0 .25rem; }
.request-note { white-space: pre-wrap; margin-top: .5rem; }

@media (max-width: 820px), (max-width: 1133px) and (pointer: coarse) {
  .library-page { padding-bottom: calc(5.5rem + env(safe-area-inset-bottom)); }
  .library-page .masthead { padding: .5rem 4%; gap: .45rem; }
  .library-page:not(.admin-page) .masthead {
    --btn-line: #88674d;
    --btn-ink: #f8e8d3;
    --btn-hover: #533b2a;
    --btn-hover-ink: #fff5e5;
    min-height: 4.5rem;
    padding-block: .85rem;
    background: #39291f;
    border-bottom-color: var(--btn-line);
  }
  [data-theme=light] .library-page:not(.admin-page) .masthead {
    --accent: #65370d;
    --btn-line: #a88965;
    --btn-ink: #3a281a;
    --btn-hover: #e8d2b4;
    --btn-hover-ink: #2b2219;
    background: #ddc2a0;
  }
  .masthead-actions #logout { min-width: 44px; justify-content: center; }
  .library-page .reader-shelf { padding-bottom: 2rem; }
  .library-page .library-intro { align-items: stretch; }
  .library-shortcuts > * { justify-content: center; flex: 1 1 auto; }
  .library-page #import { flex: 1 1 auto; min-height: 44px; font-size: inherit; }
  #catalog-heading { scroll-margin-top: 5.75rem; }
  .recent-books {
    position: relative;
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: min(82%, 19rem);
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scroll-snap-type: inline proximity;
    scroll-padding-inline: .25rem;
    padding: .25rem .25rem .65rem;
  }
  .recent-books > * { scroll-snap-align: start; }
  .library-dock, .admin-tabs {
    position: fixed;
    z-index: 25;
    inset: auto auto max(.65rem, env(safe-area-inset-bottom)) 50%;
    transform: translateX(-50%);
    display: flex;
    justify-content: space-evenly;
    gap: .12rem;
    width: min(calc(100% - 1rem), 28rem);
    margin: 0;
    padding: .25rem;
    border: 1px solid var(--btn-line);
    border-radius: .95rem;
    background: var(--bar);
    box-shadow: 0 .4rem 1.3rem var(--bar-shadow);
    overflow: visible;
  }
  .library-dock {
    --btn-line: #ad8b65;
    --btn-ink: #362419;
    --btn-hover: #ddc29d;
    --btn-hover-ink: #2b1d13;
    --accent: #784512;
    width: min(calc(100% - 1rem), 22rem);
    background: #eedcc1;
  }
  [data-theme=light] .library-dock {
    --btn-line: #6f503b;
    --btn-ink: #f8e8d3;
    --btn-hover: #533b2a;
    --btn-hover-ink: #fff5e5;
    --accent: #f5d392;
    background: #36261c;
  }
  .library-page .library-dock > * {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    justify-content: center;
    gap: .15rem;
    min-width: 0;
    min-height: 3.05rem;
    padding: .15rem .05rem;
    border: 0;
    font: 650 .73rem/1.15 system-ui, sans-serif;
    text-align: center;
  }
  .library-page .library-dock .logout-text { position: static; clip-path: none; width: auto; height: auto; white-space: normal; }
  .library-dock .large-text { display: none; }
  .library-dock .dock-label { display: inline; }
  .admin-tabs [role=tab] {
    flex: 1 1 0;
    min-width: 0;
    min-height: 3rem;
    padding: .25rem .2rem;
    border: 0;
    border-radius: .65rem;
    white-space: normal;
    line-height: 1.15;
    font-size: .77rem;
  }
  .admin-tabs [role=tab][aria-selected=true] { background: var(--feature); color: var(--accent); }
  .badge { white-space: normal; }
  .library-page .book-remove { min-height: 44px; }
}
@media (max-width: 850px) {
  .reader-tools { padding: 3px 5px; }
  .reader-tool-group { gap: 0; }
  .reader-tool-group + .reader-tool-group { margin: 0; padding: 0; border: 0; }
  #reader-tools .reader-tool-group > button, #reader-tools .reader-options summary {
    width: clamp(34px, 10vw, 44px);
    min-width: 0;
    min-height: 44px;
    padding: 0;
  }
  .reader-tools svg { width: 19px; height: 19px; }
  .reader-tools .tool-label { display: none; }
  .reader-tools #jump { gap: 3px; padding: 2px 4px; font-size: 13px; }
  .reader-tools #page-number { width: 36px; }
}
@media (max-width: 560px) {
  .reader-options-panel { max-height: min(55dvh, 30rem); }
  .reader-header a { display: flex; align-items: center; min-height: 44px; }
}
@media (max-width: 360px) {
  .reader-tools #total { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
}
@media (max-width: 420px) {
  .masthead .wordmark { min-width: 0; gap: .35rem; }
  .masthead .wordmark img { width: 30px; height: 30px; }
  .masthead .wordmark span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: clamp(1rem, 5vw, 1.15rem); }
  .masthead-actions { flex: none; gap: 4px; }
  .masthead-actions #lang { gap: .2rem; padding-inline: 6px; font-size: 13px; }
  .admin-page .masthead-actions > :not(#lang) { justify-content: center; width: 44px; min-width: 44px; padding-inline: 0; }
}
@media (max-width: 360px) {
  .admin-page .masthead { padding-inline: 10px; gap: 4px; }
  .admin-page .masthead .wordmark img { width: 26px; height: 26px; }
}
