/* Apple Books look, on Android. UI: Inter (SF stand-in); titles: Source Serif 4 (New York stand-in). */
:root {
  --bg: #ffffff;
  --grouped: #f2f2f7;
  --card: #ffffff;
  --text: #000000;
  --secondary: #6c6c70;
  --tertiary: #8e8e93;
  --separator: rgba(60, 60, 67, .18);
  --fill: rgba(120, 120, 128, .14);
  --glass: rgba(249, 249, 249, .82);
  --glass-dark: rgba(36, 36, 38, .97);
  --solid: #f2f2f4;
  --tint: #ff9500;
  --danger: #ff3b30;
  --shadow: 0 1px 2px rgba(0,0,0,.1), 0 8px 24px rgba(0,0,0,.12);
  --cover-shadow: 0 1px 1px rgba(0,0,0,.08), 0 6px 14px rgba(0,0,0,.18);
  --hl-1: #a6e37c; --hl-2: #a9c8ff; --hl-3: #ffe066; --hl-4: #ffa8c5; --hl-5: #d4b3ff;
  --ui: Inter, system-ui, -apple-system, Roboto, sans-serif;
  --serif: "Source Serif 4", "New York", Georgia, serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --grouped: #000000;
    --card: #1c1c1e;
    --text: #ffffff;
    --secondary: #aeaeb2;
    --tertiary: #8e8e93;
    --separator: rgba(84, 84, 88, .55);
    --fill: rgba(120, 120, 128, .32);
    --glass: rgba(44, 44, 46, .82);
    --solid: #2c2c2e;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow-x: clip; }
body { background: var(--bg); color: var(--text); font: 16px/1.35 var(--ui); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
svg { width: 24px; height: 24px; flex: none; }
:focus-visible { outline: 2px solid var(--tint); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.secondary { color: var(--secondary); }
.small { font-size: 14px; }
.large-title { font: 700 34px/1.15 var(--serif); letter-spacing: -.01em; margin: 0; }
.section-title { font: 700 22px/1.2 var(--serif); margin: 0 0 12px; display: flex; align-items: center; gap: 4px; }
.screen { min-height: 100%; padding-top: env(safe-area-inset-top); }

/* PIN */
.pin { max-width: 380px; margin: 0 auto; padding: 96px 16px 24px; display: grid; gap: 16px; }
.pin p { margin: 0; }
.field { font: inherit; font-size: 20px; letter-spacing: .5px; padding: 14px 16px; border-radius: 12px; border: 0; background: var(--fill); color: var(--text); }
.primary-btn { padding: 15px; border-radius: 14px; background: var(--text); color: var(--bg); font-weight: 600; }
.error { color: var(--danger) !important; min-height: 1.35em; font-size: 14px; }

/* Tab screens */
.tab-screen { padding-bottom: calc(112px + env(safe-area-inset-bottom)); }
.title-bar { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; padding: 16px 24px 8px; }
.title-bar .small { padding-bottom: 6px; }
main { max-width: 760px; margin: 0 auto; }
.band { padding: 16px 24px 24px; }
.band + .band { border-top: 8px solid var(--grouped); }
@media (prefers-color-scheme: dark) { .band + .band { border-top: 1px solid var(--separator); } }
.empty { color: var(--secondary); padding: 24px; }

/* Continue card: tinted from the cover, as Apple does */
.continue { display: grid; grid-template-columns: 56px 1fr; gap: 14px; align-items: center; width: 100%; text-align: left; padding: 12px; border-radius: 14px; background: var(--tintbg, #6b4a3a); color: #fff; box-shadow: var(--shadow); }
.continue .cover { width: 56px; }
.continue > span { min-width: 0; overflow-wrap: anywhere; }
.continue-title { font-weight: 600; font-size: 16px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.continue-meta { display: block; font-size: 14px; opacity: .82; margin-top: 2px; }
.continue-sync { display: block; font-size: 13px; opacity: .7; margin-top: 6px; }
.continue + .continue { margin-top: 12px; }

/* Covers */
.cover { position: relative; aspect-ratio: 2 / 3; border-radius: 3px 5px 5px 3px; overflow: hidden; box-shadow: var(--cover-shadow); background: var(--fill); }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(0,0,0,.18), rgba(255,255,255,.12) 3%, rgba(0,0,0,0) 7%); pointer-events: none; }
.cover.generated { display: grid; align-content: space-between; padding: 12% 10%; color: #fff; }
.cover.generated .g-title { font: 600 15px/1.2 var(--serif); }
.cover.generated .g-author { font-size: 12px; opacity: .85; }

.rail { display: grid; grid-auto-flow: column; grid-auto-columns: 132px; gap: 16px; overflow-x: auto; scroll-snap-type: x mandatory; scroll-padding-inline: 24px; margin: 0 -24px; padding: 4px 24px 8px; scrollbar-width: none; }
.rail::-webkit-scrollbar { display: none; }
.rail > * { scroll-snap-align: start; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 28px 20px; padding: 16px 24px; align-items: end; }
.tile { display: grid; gap: 8px; text-align: left; width: 100%; }
.tile[disabled] { cursor: default; }
.tile-foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; min-height: 20px; font-size: 13px; color: var(--secondary); }
.badge { font-size: 11px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; padding: 2px 6px; border-radius: 4px; background: var(--fill); color: var(--secondary); }
.tile { min-width: 0; }
.tile .tile-title { font-size: 14px; font-weight: 500; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; color: var(--text); }
.count-line { text-align: center; color: var(--secondary); font-size: 14px; padding: 8px 24px 24px; }
details.apple-only summary { list-style: none; cursor: pointer; padding: 16px 24px; color: var(--secondary); font-size: 14px; text-align: center; }
details.apple-only summary::-webkit-details-marker { display: none; }

/* Floating tab bar */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; gap: 10px; align-items: center; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); z-index: 10; pointer-events: none; }
.tabs > * { pointer-events: auto; }
.tab-pill { flex: 1; display: flex; gap: 4px; padding: 4px; border-radius: 32px; background: var(--glass); backdrop-filter: blur(20px) saturate(1.8); -webkit-backdrop-filter: blur(20px) saturate(1.8); box-shadow: var(--shadow); }
.tab { flex: 1; display: grid; justify-items: center; gap: 1px; padding: 6px 0 5px; border-radius: 28px; font-size: 11px; font-weight: 600; color: var(--text); }
.tab[aria-current="page"] { background: var(--fill); }
.search-pill { display: flex; align-items: center; gap: 4px; border-radius: 32px; background: var(--glass); backdrop-filter: blur(20px) saturate(1.8); -webkit-backdrop-filter: blur(20px) saturate(1.8); box-shadow: var(--shadow); }
.tab-round { width: 56px; height: 56px; display: grid; place-items: center; border-radius: 28px; }
.tabs.searching .tab-pill { flex: 0 0 56px; overflow: hidden; }
.tabs.searching .tab-pill .tab:not([aria-current="page"]) { display: none; }
.tabs.searching .tab span { display: none; }
.tabs.searching .search-pill { flex: 1; }
.search-input { flex: 1; min-width: 0; font: inherit; border: 0; background: none; color: var(--text); padding: 0 0 0 16px; height: 56px; outline: none; }

/* Reader */
#reader { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--page-bg, #fff); color: var(--page-text, #000); padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); transition: background .25s; }
.reader-top, .reader-bottom { position: relative; height: 52px; display: flex; align-items: center; justify-content: center; padding: 0 16px; }
.reader-meta { font-size: 14px; color: var(--page-meta, #8e8e93); font-variant-numeric: tabular-nums; }
.round-btn { width: 44px; height: 44px; border-radius: 22px; display: grid; place-items: center; background: var(--page-btn, rgba(120,120,128,.16)); color: var(--page-text, #000); }
.round-btn.small { width: 32px; height: 32px; background: var(--fill); color: var(--secondary); }
.round-btn.small svg { width: 18px; height: 18px; }
.chrome { position: absolute; right: 16px; transition: opacity .2s, transform .2s; }
#reader:not(.show-chrome) .chrome { opacity: 0; transform: scale(.8); pointer-events: none; }
#viewer { flex: 1; min-height: 0; position: relative; overflow: hidden; margin: 0 4px; }
#viewer canvas { display: block; margin: 0 auto; max-width: 100%; }
/* Taps on the page itself turn pages; these stay for keyboards and screen readers. */
.turn { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.turn:focus-visible { clip: auto; width: 44px; height: 44px; top: 50%; border-radius: 22px; background: var(--page-btn); z-index: 5; }
.turn-prev:focus-visible { left: 8px; } .turn-next:focus-visible { right: 8px; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; background: var(--page-bg, #fff); z-index: 6; }
.loading p { color: var(--page-meta, #8e8e93); }

.reader-menu { position: absolute; right: 16px; bottom: calc(60px + env(safe-area-inset-bottom)); width: min(300px, calc(100% - 32px)); display: grid; gap: 8px; z-index: 7; animation: pop .18s ease-out; transform-origin: bottom right; }
.menu-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 48px; padding: 0 16px; border-radius: 24px; background: var(--solid); backdrop-filter: blur(20px) saturate(1.8); -webkit-backdrop-filter: blur(20px) saturate(1.8); box-shadow: var(--shadow); color: var(--text); font-size: 16px; text-align: left; }
.menu-row.dark { background: rgba(44,44,46,.94); color: #fff; }
.menu-row svg { width: 22px; height: 22px; }
.menu-row .count { color: var(--secondary); }
.aa { font-weight: 500; font-size: 14px; letter-spacing: -.02em; } .aa b { font-size: 19px; }
.menu-icons { display: flex; justify-content: flex-end; gap: 8px; }
.menu-icon { width: 48px; height: 48px; border-radius: 24px; display: grid; place-items: center; background: var(--solid); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); box-shadow: var(--shadow); color: var(--text); }
.menu-icon[aria-pressed="true"] { background: var(--danger); color: #fff; }
.menu-icon[aria-pressed="true"] path { fill: currentColor; }
@keyframes pop { from { opacity: 0; transform: scale(.92); } }

/* Highlight popover */
.popover { position: absolute; z-index: 8; left: 12px; right: 12px; max-width: 360px; margin: 0 auto; padding: 10px; border-radius: 16px; background: var(--glass-dark); color: #fff; box-shadow: 0 10px 30px rgba(0,0,0,.35); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); animation: pop .15s ease-out; }
.swatches { display: flex; justify-content: space-between; gap: 6px; padding: 2px 2px 10px; border-bottom: 1px solid rgba(255,255,255,.14); }
.swatch { width: 36px; height: 36px; border-radius: 18px; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0,0,0,.1); display: grid; place-items: center; }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--glass-dark), 0 0 0 4px #fff; }
.swatch.underline { background: rgba(255,255,255,.12); }
.swatch.underline span { font-weight: 600; text-decoration: underline 2px #ff453a; text-underline-offset: 3px; }
.swatch.trash { background: rgba(255,255,255,.12); }
.swatch.trash svg { width: 20px; height: 20px; }
.pop-actions { display: flex; }
.pop-actions button { flex: 1; padding: 12px 8px 4px; font-size: 15px; }
.pop-actions button + button { border-left: 1px solid rgba(255,255,255,.14); }

/* Bottom sheet */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.28); z-index: 20; animation: fade .2s; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; max-height: 82vh; display: flex; flex-direction: column; background: var(--bg); color: var(--text); border-radius: 22px 22px 0 0; z-index: 21; padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -10px 40px rgba(0,0,0,.2); animation: rise .25s cubic-bezier(.2,.8,.2,1); }
@media (prefers-color-scheme: dark) { .sheet { background: #1c1c1e; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px 20px; }
.sheet-head h2 { margin: 0; font-size: 20px; font-weight: 700; }
.sheet-body { overflow-y: auto; padding: 4px 16px 24px; }
@keyframes rise { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

.list { list-style: none; margin: 0; padding: 0; }
.list button { width: 100%; text-align: left; display: flex; align-items: baseline; gap: 12px; padding: 14px 4px; border-bottom: 1px solid var(--separator); }
.list .sub { padding-left: 20px; }
.list .now { font-weight: 700; }
.list .pg { margin-left: auto; color: var(--secondary); font-size: 14px; font-variant-numeric: tabular-nums; }
.list .mark { display: grid; gap: 6px; align-items: start; }
.mark .quote { font-family: var(--serif); font-size: 16px; padding-left: 10px; border-left: 4px solid var(--c, var(--hl-3)); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.mark .note { font-size: 14px; color: var(--secondary); padding-left: 14px; }
.mark .where { font-size: 13px; color: var(--tertiary); padding-left: 14px; }
.chapter-label { font: 600 15px/1.3 var(--ui); color: var(--text); margin: 20px 4px 4px; }
.group-label { font-size: 13px; font-weight: 600; color: var(--secondary); text-transform: uppercase; letter-spacing: .04em; margin: 16px 4px 0; }
.search-row { display: flex; gap: 8px; margin-bottom: 8px; }
.search-row input { flex: 1; font: inherit; padding: 10px 14px; border-radius: 10px; border: 0; background: var(--fill); color: var(--text); }
.search-hit mark { background: var(--hl-3); color: #000; border-radius: 2px; }

/* Themes & Settings */
.size-row { display: flex; gap: 8px; margin-bottom: 16px; }
.seg { flex: 1; display: flex; border-radius: 22px; background: var(--fill); overflow: hidden; }
.seg button { flex: 1; height: 44px; }
.seg button + button { border-left: 1px solid var(--separator); }
.seg .sm { font-size: 14px; } .seg .lg { font-size: 20px; }
.mode button[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.themes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.theme { height: 92px; border-radius: 16px; display: grid; place-content: center; gap: 2px; text-align: center; box-shadow: inset 0 0 0 1px var(--separator); }
.theme .aa-big { font-size: 26px; }
.theme small { font-size: 14px; }
.theme[aria-pressed="true"] { box-shadow: inset 0 0 0 3px var(--text); }
.note-area { width: 100%; min-height: 140px; font: 17px/1.45 var(--serif); padding: 12px; border-radius: 12px; border: 0; background: var(--fill); color: var(--text); resize: vertical; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 12px; }
.sheet-actions button { padding: 10px 18px; border-radius: 20px; font-weight: 600; }
.sheet-actions .go { background: var(--text); color: var(--bg); }

.toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: rgba(44,44,46,.94); color: #fff; padding: 10px 16px; border-radius: 20px; font-size: 14px; z-index: 30; animation: fade .2s; }

/* Opening a book: the cover grows into the page (View Transitions) */
.loading-cover { width: 46%; max-width: 220px; view-transition-name: book; }
::view-transition-group(book) { animation-duration: .38s; animation-timing-function: cubic-bezier(.2,.8,.2,1); }
@media (prefers-reduced-motion: reduce) { ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; } }

/* Customise */
.custom-group { display: grid; gap: 8px; margin-top: 20px; }
.custom-group > span { font-size: 13px; font-weight: 600; color: var(--secondary); text-transform: uppercase; letter-spacing: .04em; padding-left: 4px; }
.fonts { display: grid; gap: 0; border-radius: 12px; overflow: hidden; background: var(--fill); }
.fonts button { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; font-size: 18px; text-align: left; }
.fonts button + button { border-top: 1px solid var(--separator); }
.fonts button[aria-pressed="true"]::after { content: "✓"; font-family: var(--ui); font-weight: 700; color: var(--tint); }
.seg button[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.customise-btn { width: 100%; margin-top: 12px; height: 48px; border-radius: 24px; background: var(--fill); font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 8px; }

/* Library collections */
.title-bar .round-btn { background: var(--fill); color: var(--text); }
.collections { position: absolute; right: 16px; top: calc(env(safe-area-inset-top) + 64px); z-index: 12; width: 240px; border-radius: 14px; background: var(--solid); box-shadow: var(--shadow); overflow: hidden; animation: pop .15s ease-out; transform-origin: top right; }
.collections button { display: flex; justify-content: space-between; width: 100%; padding: 13px 16px; font-size: 16px; text-align: left; }
.collections button + button { border-top: 1px solid var(--separator); }
.collections button[aria-checked="true"]::after { content: "✓"; font-weight: 700; }
.collection-title { padding: 0 24px; margin: -4px 0 4px; color: var(--secondary); font-size: 15px; }
