:root {
    color-scheme: light;
    --bg: #f3f1ed;
    --surface: #ffffff;
    --ink: #171717;
    --muted: #6b675f;
    --line: #d9d4cb;
    --accent: #8b1e2d;
    --accent-dark: #64141f;
    --gold: #a3832f;
    --danger: #93222b;
    --radius: 14px;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html { background: #242424; }
body { margin: 0; background: #242424; color: var(--ink); }
button, input, select, textarea { font: inherit; }
a { color: inherit; }
.mobile-shell { position: relative; width: 100%; max-width: 560px; min-height: 100vh; margin: 0 auto; background: var(--bg); box-shadow: 0 0 28px rgba(0,0,0,.25); }
.app-header { position: sticky; top: 0; z-index: 20; background: #171717; color: #fff; padding-top: env(safe-area-inset-top); }
.top-line { min-height: 54px; display: flex; align-items: center; justify-content: space-between; padding: 0 14px; }
.brand { text-decoration: none; font-weight: 800; letter-spacing: .03em; }
.account-menu { position: relative; }
.account-menu summary { cursor: pointer; list-style: none; font-size: .9rem; color: #ddd; }
.account-menu summary::-webkit-details-marker { display: none; }
.account-panel { position: absolute; right: 0; top: 32px; min-width: 165px; background: #fff; color: var(--ink); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.3); overflow: hidden; }
.account-panel a, .account-panel .link-button { display: block; width: 100%; padding: 13px 15px; text-align: left; text-decoration: none; border: 0; background: #fff; color: var(--ink); }
.main-nav { position: fixed; z-index: 30; left: 50%; bottom: 0; transform: translateX(-50%); width: min(100%, 560px); display: grid; grid-template-columns: 1fr 1.15fr 1fr; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: rgba(23,23,23,.98); border-top: 1px solid #3b3b3b; box-shadow: 0 -8px 24px rgba(0,0,0,.18); }
.main-nav a { display: grid; justify-items: center; gap: 2px; padding: 5px 6px; border-radius: 10px; color: #c9c9c9; text-decoration: none; font-size: .68rem; font-weight: 750; }
.main-nav a span { font-size: 1.28rem; line-height: 1; }
.main-nav a.active { color: #fff; background: #353535; }
.main-nav .add-nav { margin-top: -18px; min-height: 58px; align-content: center; background: var(--accent); color: #fff; border: 4px solid #171717; border-radius: 18px; box-shadow: 0 4px 12px rgba(0,0,0,.3); }
.main-nav .add-nav.active { background: var(--accent-dark); }
.page-content { padding: 14px 12px calc(88px + env(safe-area-inset-bottom)); }
h1 { margin: 5px 0 16px; font-size: 1.45rem; line-height: 1.2; }
h2 { margin: 0; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.auth-page { min-height: 100vh; padding: 48px 18px; background: var(--bg); }
.auth-page h1 { font-size: 1.8rem; }
.form-stack { display: grid; gap: 13px; }
label { display: grid; gap: 6px; font-size: .82rem; font-weight: 750; color: #45413b; }
input, select, textarea { width: 100%; border: 1px solid #bbb5ab; border-radius: 10px; background: #fff; padding: 12px; color: var(--ink); outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(139,30,45,.12); }
textarea { resize: vertical; }
.primary-button, .secondary-button, .danger-button { display: inline-flex; align-items: center; justify-content: center; min-height: 45px; border-radius: 10px; padding: 10px 14px; text-decoration: none; font-weight: 850; font-size: .78rem; letter-spacing: .035em; border: 1px solid transparent; cursor: pointer; }
.primary-button { background: var(--accent); color: #fff; }
.primary-button:hover { background: var(--accent-dark); }
.secondary-button { background: #fff; color: var(--ink); border-color: #aaa49a; }
.danger-button { background: #fff; color: var(--danger); border-color: #c7979c; }
.compact { min-height: 38px; font-size: .68rem; padding: 8px 10px; }
button:disabled { opacity: .6; cursor: default; }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.flash { margin: 12px; padding: 12px 14px; border-radius: 10px; background: #e6edf5; border: 1px solid #b9cadf; }
.flash.error, .search-message.error { background: #f7e3e5; border-color: #d4a3a8; color: #7a1821; }
.search-message.success { color: #255a31; font-weight: 750; }
.flash.success { background: #e2f0e6; border-color: #a8cbb1; color: #255a31; }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 3px 1px 11px; }
.list-switch { flex: 1; font-size: .75rem; }
.list-switch select { font-size: 1.08rem; font-weight: 800; padding: 10px 36px 10px 11px; }
.list-actions { display: flex; align-items: center; gap: 7px; }
.local-search { margin-bottom: 12px; }
.local-search input { min-width: 0; }
.list-count { flex: 0 0 auto; color: var(--muted); font-size: .78rem; }
.view-toggle { min-height: 42px; padding: 8px 10px; border: 1px solid #aaa49a; border-radius: 10px; background: #fff; color: var(--ink); font-size: .82rem; font-weight: 800; cursor: pointer; }
.book-list { display: grid; gap: 10px; }
.book-card { display: grid; grid-template-columns: 78px 1fr; min-height: 116px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; text-decoration: none; }
.cover-small { width: 78px; min-height: 116px; background: #dedbd4; display: flex; align-items: center; justify-content: center; overflow: hidden; color: #777168; text-align: center; font-size: .55rem; font-weight: 800; padding: 5px; }
.cover-small img { width: 100%; height: 100%; min-height: 116px; object-fit: cover; }
.book-data { padding: 11px 12px; min-width: 0; }
.book-data h2 { font-size: 1rem; line-height: 1.25; margin-bottom: 5px; }
.book-data p { margin: 3px 0; line-height: 1.3; }
.authors { color: #48443e; font-size: .81rem; }
.subtitle, .identifier { color: var(--muted); font-size: .73rem; }
.series-line { color: var(--accent); font-weight: 750; font-size: .76rem; }
.book-list.two-column { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.book-list.two-column .book-card { grid-template-columns: 1fr; min-height: 0; align-content: start; }
.book-list.two-column .cover-small { width: 100%; min-height: 0; aspect-ratio: 2 / 3; }
.book-list.two-column .cover-small img { width: 100%; height: 100%; min-height: 0; aspect-ratio: 2 / 3; object-fit: cover; }
.book-list.two-column .book-data { padding: 12px; }
.book-list.two-column .book-data h2 { font-size: 1rem; line-height: 1.32; }
.book-list.two-column .authors { font-size: .84rem; }
.book-list.two-column .series-line { font-size: .82rem; }
.book-list.two-column .identifier { font-size: .78rem; }
.empty-state { padding: 34px 16px; text-align: center; color: var(--muted); border: 1px dashed #bdb7ad; border-radius: var(--radius); background: rgba(255,255,255,.45); }
.search-panel h1 { margin-top: 0; }
.scan-main-button { width: 100%; min-height: 58px; font-size: .9rem; }
.or-divider { display: flex; align-items: center; gap: 10px; margin: 15px 0; color: var(--muted); font-size: .72rem; }
.or-divider::before, .or-divider::after { content: ""; height: 1px; flex: 1; background: var(--line); }
.search-composer { display: grid; grid-template-columns: 1fr auto; }
.search-composer input { min-width: 0; border-radius: 10px 0 0 10px; }
.search-submit { border: 0; border-radius: 0 10px 10px 0; padding: 0 15px; background: #282828; color: #fff; font-weight: 800; cursor: pointer; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.optional { color: var(--muted); font-weight: 500; }
.input-hint { color: var(--muted); font-size: .75rem; font-weight: 500; line-height: 1.35; }
.photo-upload input[type="file"] { padding: 8px; background: #faf9f7; }
.photo-upload input[type="file"]::file-selector-button { margin-right: 9px; border: 0; border-radius: 8px; padding: 9px 11px; background: #282828; color: #fff; font: inherit; font-weight: 750; cursor: pointer; }
.manual-cover-preview { width: 112px; aspect-ratio: 2 / 3; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: #dedbd4; }
.manual-cover-preview img { width: 100%; height: 100%; object-fit: cover; }
.small-note { color: var(--muted); font-size: .76rem; line-height: 1.45; }
.search-message { min-height: 22px; margin: 10px 2px; font-size: .82rem; }
.search-progress { display: flex; align-items: center; gap: 9px; min-height: 34px; font-size: .88rem; font-weight: 750; color: #45413b; }
.search-spinner { width: 19px; height: 19px; flex: 0 0 19px; border: 3px solid #d4cec4; border-top-color: var(--accent); border-radius: 50%; animation: search-spin .8s linear infinite; }
.preview-card { border-color: #c6ab78; box-shadow: 0 0 0 1px rgba(163,131,47,.08); }
@keyframes search-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .search-spinner { animation-duration: 1.6s; } }
.online-card { color: var(--ink); }
.remote-placeholder { background: #d8d4cc; }
.manual-entry { margin-top: 16px; }
.manual-entry > summary, .edit-details > summary { cursor: pointer; font-size: .86rem; font-weight: 850; color: var(--accent); }
.manual-entry[open] > summary { margin-bottom: 14px; }
.more-fields { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 11px 0; }
.more-fields summary, .remove-book summary { cursor: pointer; color: var(--muted); font-size: .78rem; font-weight: 750; }
.more-fields[open] { display: grid; gap: 12px; }
.more-fields[open] summary { margin-bottom: 2px; }
.save-choice, .online-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 8px; }
.result-destination { font-size: .65rem; }
.result-destination select { padding: 8px 30px 8px 9px; font-size: .76rem; }
.online-actions { margin-top: 10px; }
.online-actions .primary-button { min-height: 39px; }
.primary-button.saved { background: #356442; }
.scanner-modal { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.92); padding: max(20px, env(safe-area-inset-top)) 12px max(20px, env(safe-area-inset-bottom)); }
.scanner-box { position: relative; max-width: 540px; height: 100%; margin: auto; display: flex; flex-direction: column; justify-content: center; gap: 16px; color: #fff; text-align: center; }
.scanner-box video { width: 100%; max-height: 65vh; background: #000; border-radius: 16px; object-fit: cover; }
.scan-guide { position: absolute; top: 43%; left: 8%; right: 8%; height: 90px; border: 2px solid #fff; border-radius: 10px; pointer-events: none; box-shadow: 0 0 0 999px rgba(0,0,0,.18); }
.detail-head { display: grid; grid-template-columns: 105px 1fr; gap: 14px; align-items: start; margin-bottom: 14px; }
.detail-head h1 { font-size: 1.2rem; margin: 5px 0 6px; }
.detail-head p { margin: 0; color: var(--muted); font-size: .82rem; }
.detail-head .detail-series { margin-top: 7px; color: var(--accent); font-weight: 750; }
.status-pill { display: inline-block; margin-bottom: 3px; padding: 4px 8px; border-radius: 999px; background: #eadde0; color: var(--accent); font-size: .66rem; font-weight: 800; }
.status-pill.read { background: #deeadf; color: #356442; }
.cover-large { width: 105px; height: 158px; display: flex; align-items: center; justify-content: center; overflow: hidden; border-radius: 12px; background: #ddd9d1; color: var(--muted); font-size: .62rem; text-align: center; }
.cover-large img { width: 100%; height: 100%; object-fit: cover; }
.edit-details[open] > summary { margin-bottom: 15px; }
.remove-book { text-align: center; padding-top: 5px; }
.remove-book .danger-button { width: 100%; }
.series-group { margin-bottom: 16px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.series-group h2 { font-size: 1.05rem; }
.missing-line { color: var(--danger); font-size: .78rem; font-weight: 750; }
.series-books { display: grid; gap: 7px; margin-top: 10px; }
.series-entry { display: grid; grid-template-columns: 39px 1fr; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.series-number { display: flex; align-items: center; justify-content: center; background: #282828; color: #fff; font-weight: 850; }
.series-title { padding: 9px 10px; font-size: .82rem; }
.series-title small { display: block; margin-top: 3px; color: var(--muted); font-size: .62rem; font-weight: 850; }
.series-entry.read .series-number { background: #356442; }
.series-entry.wishlist .series-number { background: var(--accent); }
.series-entry.missing { border-style: dashed; opacity: .75; }
.series-entry.missing .series-number { background: #8b8274; }
.token-box { width: 100%; min-height: 92px; word-break: break-all; margin: 8px 0 12px; }
.compact-list { display: grid; gap: 7px; }
.compact-list > div { display: flex; justify-content: space-between; gap: 10px; padding: 10px; border-radius: 9px; background: #fff; border: 1px solid var(--line); font-size: .74rem; }
.compact-list span { color: var(--muted); text-align: right; }
@media (max-width: 370px) {
    .button-row, .two-cols, .save-choice, .online-actions { grid-template-columns: 1fr; }
    .book-card { grid-template-columns: 70px 1fr; }
    .cover-small { width: 70px; }
    .list-count { display: none; }
}
