:root { font: 16px/1.45 system-ui, sans-serif; color: #292620; background: #f4efe5; color-scheme: light; }
* { box-sizing: border-box; }
body { margin: 0; height: 100dvh; min-height: 300px; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden; }
button, input, select { font: inherit; }
button { min-height: 44px; padding: .5rem .85rem; border: 1px solid #c8bba7; border-radius: .65rem; background: #fffdf8; color: inherit; cursor: pointer; }
button:hover:not(:disabled) { background: #efe6d8; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid #b7794d; outline-offset: 2px; }
button:disabled { opacity: .45; cursor: default; }
a { color: #78482c; }
.appbar { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 1rem; min-height: 64px; padding: .55rem 1rem; border-bottom: 1px solid #ded3c3; background: #faf7f1; }
.brand { color: #473421; font: 700 1.4rem Georgia, serif; letter-spacing: -.03em; text-decoration: none; }
#status { min-width: 0; margin: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: #61594f; text-align: center; }
.app-actions { display: flex; gap: .5rem; }
.app-actions button { min-height: 42px; }
#reader { min-height: 0; min-width: 0; background: #fffdf9; }
foliate-view { display: block; width: 100%; height: 100%; }
.pager { display: grid; grid-template-columns: minmax(7rem, 1fr) minmax(5rem, 2fr) minmax(7rem, 1fr); align-items: center; gap: .7rem; min-height: 64px; padding: .45rem max(1rem, env(safe-area-inset-right)) .45rem max(1rem, env(safe-area-inset-left)); border-top: 1px solid #ded3c3; background: #faf7f1; }
.pager button { width: 100%; height: 48px; font-weight: 600; }
.pager button:first-child { justify-self: start; }
.pager button:last-child { justify-self: end; }
#position { min-width: 0; text-align: center; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: .88rem; color: #665d50; font-variant-numeric: tabular-nums; }
#selection { position: fixed; z-index: 4; left: 1rem; right: 1rem; bottom: 4.4rem; padding: .6rem .8rem; border-radius: .6rem; background: #332d25; color: white; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#diagnostic { position: fixed; z-index: 5; top: 4.5rem; left: 1rem; right: 1rem; max-height: 30vh; margin: 0; padding: .75rem 1rem; overflow: auto; border: 1px solid #d99b8b; border-radius: .6rem; background: #fff5f2; color: #84251d; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: 0 8px 24px #30251b24; }
.welcome { display: grid; justify-items: center; align-content: center; gap: .8rem; height: 100%; padding: 2rem; text-align: center; }
.welcome-mark { display: grid; place-items: center; width: 4rem; height: 4rem; border-radius: 1rem; background: #5e452d; color: #fdf8ee; font: 700 2.4rem Georgia, serif; box-shadow: 0 10px 24px #5e452d30; }
.welcome h1 { margin: .3rem 0 0; font: 600 clamp(1.5rem, 3vw, 2.5rem) Georgia, serif; }
.welcome p { max-width: 28rem; margin: 0; color: #6f6559; }
.welcome-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: .6rem; margin-top: .5rem; }
.welcome-actions button:first-child { background: #5e452d; border-color: #5e452d; color: white; }
.welcome-actions button:first-child:hover { background: #76583a; }
dialog { width: min(92vw, 920px); max-height: min(88dvh, 780px); padding: 0; border: 1px solid #d4c7b4; border-radius: 1rem; background: #faf7f1; color: inherit; box-shadow: 0 24px 70px #29211755; overflow: auto; }
dialog::backdrop { background: #19150fcc; }
#settings, #progress-choice, #login-wait { width: min(92vw, 430px); }
.dialog-head { position: sticky; z-index: 1; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.25rem; border-bottom: 1px solid #ded3c3; background: #faf7f1; }
.dialog-head small { color: #8b7058; font-size: .68rem; font-weight: 700; letter-spacing: .14em; }
.dialog-head h2 { margin: .1rem 0 0; font: 600 1.65rem Georgia, serif; }
.icon-button { width: 44px; height: 44px; padding: 0; font-size: 1.7rem; line-height: 1; }
#library-guest, #library-content { margin: 0; padding: 1rem 1.25rem 1.25rem; }
#library-guest p { margin: 0 0 .7rem; }
.login-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1rem; }
#account { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; }
.login-code { padding: .1rem .5rem; border-radius: .4rem; background: #efe6d8; color: #473421; font: 700 1.25rem ui-monospace, monospace; letter-spacing: .18em; }
#upload-form { display: flex; flex-wrap: wrap; align-items: end; gap: .6rem; }
#upload-form label { display: grid; gap: .3rem; flex: 1 1 16rem; font-weight: 600; }
input[type=file] { max-width: 100%; font-size: .9rem; }
#library-status { min-height: 1.5rem; margin: .7rem 0; color: #665d50; font-size: .9rem; }
#books { display: grid; grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); gap: .75rem; margin: .4rem 0 0; padding: 0; }
#books li { min-width: 0; list-style: none; }
.book-card { display: grid; justify-items: center; align-content: start; gap: .55rem; width: 100%; height: 100%; padding: .7rem .45rem; text-align: center; background: transparent; border: 2px solid transparent; }
.book-card:hover, .book-card:focus-visible { border-color: #bda688; background: #efe6d8; }
.book-card.is-active { border-color: #875735; background: #f1e4d0; box-shadow: inset 0 0 0 1px #875735; }
.book-card img, .book-placeholder { display: block; width: 7rem; height: 10rem; object-fit: contain; border-radius: .25rem; box-shadow: 0 2px 9px #27241e30; }
.book-placeholder { display: grid; place-items: center; padding: .5rem; color: #5d513d; background: #e3d5bd; font-size: .75rem; }
.book-title { overflow-wrap: anywhere; font-weight: 600; line-height: 1.25; }
.badge { display: inline-block; min-width: 1.35rem; padding: 0 .35rem; border-radius: 999px; background: #875735; color: #fff; font-size: .75rem; font-weight: 700; line-height: 1.35rem; text-align: center; }
.badge[hidden] { display: none; }
.book-card.is-new { border-color: #c9a36f; }
.book-new { color: #fff; background: #875735; padding: .05rem .45rem; border-radius: 999px; font-size: .68rem; font-weight: 700; letter-spacing: .06em; }
.book-current { color: #704424; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.settings-fields { display: grid; gap: .55rem; padding: 1.15rem 1.25rem; }
.settings-fields label { font-weight: 600; }
.settings-fields input[type=range] { width: 100%; accent-color: #875735; }
.settings-fields select { min-height: 44px; padding: .5rem; border: 1px solid #c8bba7; border-radius: .55rem; background: white; }
.settings-fields input[type=file] { margin-bottom: .45rem; }
.settings-fields .toggle { display: flex; align-items: center; gap: .6rem; min-height: 44px; }
.settings-fields .toggle input { width: 1.25rem; height: 1.25rem; accent-color: #875735; }
#push-hint { margin: .2rem 0 0; font-size: .9rem; }
#push-hint:empty { display: none; }
#font-value { float: right; font-weight: 400; color: #665d50; }
#offline, #sync-status, #account { margin: 0; padding: .8rem 1.25rem; border-top: 1px solid #ded3c3; color: #665d50; font-size: .88rem; }
.progress-choice-body { display: grid; gap: .6rem; padding: 1.2rem 1.25rem; }
.progress-choice-body p { margin: 0 0 .3rem; }
.progress-choice-body button { width: 100%; }
@media (max-width: 640px) {
    .appbar { grid-template-columns: 1fr auto; gap: .3rem .6rem; padding: .4rem .65rem; }
    .brand { font-size: 1.2rem; }
    #status { grid-column: 1 / -1; grid-row: 2; text-align: left; font-size: .82rem; }
    .app-actions { grid-column: 2; grid-row: 1; }
    .app-actions button { min-height: 40px; padding: .35rem .5rem; font-size: .84rem; }
    .pager { grid-template-columns: 3.5rem minmax(0, 1fr) 3.5rem; gap: .4rem; min-height: 58px; padding: .3rem .6rem; }
    .pager button { height: 46px; padding: 0; font-size: 1.3rem; }
    .pager button span { display: none; }
    dialog { width: 96vw; max-height: 92dvh; }
    #books { grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr)); gap: .35rem; }
}
