:root {
  color-scheme: dark;
  font: 15px/1.5 "Segoe UI", system-ui, sans-serif;
  color: #f0eee3;
  background: #171d1b;
  --panel: #202725;
  --stroke: #38433e;
  --muted: #aab8ad;
  --accent: #c9dbad;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
button, select, input { font: inherit; color: inherit; }
button, select { cursor: pointer; }
button { background: transparent; border: 0; }
button:disabled { opacity: .35; cursor: default; }
:focus-visible { outline: 2px solid #dcecbd; outline-offset: -2px; }
.masthead { display: flex; flex: 0 0 60px; align-items: center; padding: 0 18px; gap: 14px; background: #141918; border-bottom: 1px solid var(--stroke); }
.brand { display: flex; gap: 12px; align-items: baseline; min-width: 0; }
.brand strong { letter-spacing: .12em; font-size: .94rem; color: var(--accent); }
.brand span { color: var(--muted); font-size: .86rem; }
.top-tools { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.top-button { color: var(--accent); display: inline-flex; gap: 6px; align-items: center; padding: 0 10px; height: 38px; border-radius: 7px; white-space: nowrap; }
.top-button span { font-size: 1.65rem; line-height: 1; }
.icon { display: grid; place-items: center; width: 40px; height: 40px; font-size: 1.45rem; line-height: 1; border-radius: 7px; }
.icon:hover:not(:disabled), .top-button:hover { background: #303b34; }
.workspace { flex: 1; min-height: 0; display: flex; position: relative; }
.panel { width: 288px; flex: 0 0 288px; height: 100%; background: var(--panel); border-right: 1px solid var(--stroke); display: flex; flex-direction: column; }
.book-card { padding: 20px 16px; display: flex; gap: 13px; align-items: flex-start; }
.book-card img { object-fit: cover; border-radius: 3px; background: #353c33; box-shadow: 0 4px 12px #0006; }
h1 { font-family: Georgia, serif; font-size: 1.12rem; margin: 1px 0 6px; font-weight: normal; line-height: 1.25; }
.book-card p, .muted { color: var(--muted); font-size: .82rem; margin: 0; }
.tabs { display: flex; padding: 0 14px; border-bottom: 1px solid var(--stroke); }
.tabs button { flex: 1; color: var(--muted); padding: 10px 0; border-bottom: 2px solid transparent; }
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.pane { flex: 1; min-height: 0; overflow: auto; scrollbar-color: #4b5c53 transparent; overscroll-behavior: contain; }
.thumbnails { padding: 14px; display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.thumbnail { color: var(--muted); padding: 8px; border: 1px solid transparent; border-radius: 7px; text-align: center; font-size: .82rem; min-width: 0; }
.thumbnail canvas, .thumbnail:not(:has(canvas))::before { display: block; width: 100%; height: auto; aspect-ratio: .71; background: #e9e4d7; margin-bottom: 5px; }
.thumbnail:not(:has(canvas))::before { content: ""; background: #2e3931; }
.thumbnail:hover, .thumbnail[aria-current="page"] { border-color: #6a805d; background: #323e32; color: #e1efc9; }
.search-pane { padding: 16px; }
.search-row { display: flex; margin: 7px 0 12px; gap: 5px; }
.search-row input { flex: 1; min-width: 0; padding: 6px; border: 1px solid var(--stroke); background: #151c18; border-radius: 5px; }
.search-row button { padding: 4px 8px; border-radius: 5px; background: var(--accent); color: #1d281a; }
#search-results { list-style: none; padding: 0; }
#search-results button { text-align: left; width: 100%; padding: 8px 0; border-top: 1px solid var(--stroke); }
#search-results strong { display: block; color: var(--accent); }
#search-results span { overflow-wrap: anywhere; font-size: .86rem; }
.reader { flex: 1; min-width: 0; position: relative; display: flex; flex-direction: column; background: radial-gradient(ellipse at 50% 35%,#39443a,#272f2a 64%,#202623); }
.stage { position: relative; flex: 1; min-height: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; isolation: isolate; }
#flip-host { width: calc(100% - 32px); height: calc(100% - 30px); display: grid; place-items: center; }
.flip-book { width: 100%; height: 100%; touch-action: pan-y; transform: translateX(var(--cover-offset,0px)); transition: transform 170ms ease-out; }
@media (prefers-reduced-motion: reduce) { .flip-book { transition: none; } }
.sheet { background: #f5f2e8; overflow: hidden; }
.sheet img { display: block; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.zoom-surface { position: absolute; inset: 0; z-index: 20; display: block; overflow: auto; background: #2b352d; padding: 16px; overscroll-behavior: contain; touch-action: pan-x pan-y; }
.zoom-surface canvas { display: block; margin: auto; background: #faf8f0; box-shadow: 0 10px 30px #0005; }
#status { position: absolute; z-index: 21; top: 10px; left: 50%; transform: translateX(-50%); max-width: 90%; padding: 6px 12px; border-radius: 7px; background: #151c17; color: var(--accent); font-size: .86rem; pointer-events: none; }
#status:empty { display: none; }
.controls { min-height: 60px; display: flex; justify-content: center; align-items: center; gap: 16px; padding: 5px 8px; border-top: 1px solid var(--stroke); background: #181f1b; }
.pagination, .scale, #page-form { display: flex; align-items: center; gap: 5px; }
#page-form { color: var(--muted); }
#page, #zoom-level { padding: 6px 4px; background: #252e27; border: 1px solid var(--stroke); border-radius: 5px; }
#page { width: 57px; text-align: center; appearance: textfield; }
#page::-webkit-inner-spin-button { appearance: none; }
#zoom-level { width: 110px; }
.sr-only { clip-path: inset(50%); width: 1px; height: 1px; overflow: hidden; position: absolute; white-space: nowrap; }
@media (max-width: 760px) {
  .masthead { padding: 0 8px; flex-basis: 50px; gap: 7px; }
  .brand { display: block; line-height: 1.15; }
  .brand span { display: block; font-size: .71rem; }
  .panel { position: absolute; width: min(310px,88%); inset: 0 auto 0 0; z-index: 30; box-shadow: 15px 0 35px #0007; }
  .controls { gap: 5px; min-height: 51px; padding-bottom: max(5px,env(safe-area-inset-bottom)); }
  .controls .icon { width: 33px; height: 35px; }
  #flip-host { width: calc(100% - 14px); height: calc(100% - 14px); }
}
@media (pointer: coarse) {
  #flip-host { max-width: 470px; }
}
