:root {
  color-scheme: light dark;
  --brand: #872d15; --cream: #feebcb;
  --bg: #fdf8ef; --surface: #fff; --text: #2a1a14; --muted: #6f5a50; --line: #e6d8c6;
  --chip: #f8e3c2; --chip-text: #74240f; --error: #a61b1b;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1512; --surface: #2a1f1a; --text: #fbf1e2; --muted: #c0aa9b; --line: #43332b;
    --chip: #57301f; --chip-text: #ffe6c2; --error: #ffa198;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font: 1rem/1.4 system-ui, sans-serif; }
button, input, select { font: inherit; color: inherit; }
button, select, .button { min-height: 44px; cursor: pointer; }
:focus-visible { outline: 3px solid #d98336; outline-offset: 2px; }
.wrap { max-width: 800px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }

header { position: sticky; top: 0; z-index: 1; background: var(--brand); color: var(--cream);
  padding: max(8px, env(safe-area-inset-top)) 0 12px; }
.bar { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.bar img { border-radius: 8px; }
h1 { font-size: 1.2rem; margin: 0; flex: 1; }
.plain { background: none; border: 0; padding: 0 8px; text-decoration: underline; text-underline-offset: 3px; }
.controls { display: flex; gap: 8px; }
.search { position: relative; flex: 1; min-width: 0; }
input:not([type=file]), select { width: 100%; min-height: 48px; padding: 8px 12px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--surface); color: var(--text); }
#q { font-size: 1.2rem; padding-right: 48px; }
#q::placeholder { color: var(--muted); }
#clear { position: absolute; right: 2px; top: 2px; width: 44px; border: 0; background: none; color: var(--muted); font-size: 1.6rem; line-height: 1; }
#book { width: 11rem; }
@media (max-width: 480px) { #book { width: 7.5rem; } }

#status { color: var(--muted); margin: 12px 0 4px; }
#results { list-style: none; margin: 0; padding: 0 0 max(32px, env(safe-area-inset-bottom)); }
#results li { padding: 12px 0; border-bottom: 1px solid var(--line); }
#results li.divider { padding-top: 28px; color: var(--muted); font-weight: 600; }
.title { font-size: 1.2rem; font-weight: 600; overflow-wrap: anywhere; }
.title mark { background: none; color: inherit; text-decoration: underline 2px #d98336; text-underline-offset: 4px; }
.books { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip { display: inline-flex; align-items: center; min-height: 44px; padding: 6px 12px; border-radius: 8px;
  border: 1px solid transparent; background: var(--chip); color: var(--chip-text); text-align: left; text-decoration: none; }
button.chip { background: none; border-color: var(--line); color: var(--text); }
span.chip { background: none; color: var(--muted); padding-left: 0; }

dialog { width: min(600px, calc(100% - 24px)); max-height: calc(100dvh - 24px); padding: 20px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--bg); color: var(--text); overflow-y: auto; }
dialog::backdrop { background: rgb(0 0 0 / .55); }
h2 { margin: 0; font-size: 1.3rem; }
h3 { margin: 24px 0 4px; font-size: 1.05rem; }
dialog p { margin: 4px 0 8px; color: var(--muted); }
dialog label:not(.button) { display: block; margin: 12px 0 4px; }
.button { display: inline-flex; align-items: center; border: 0; border-radius: 8px; padding: 8px 16px; background: var(--brand); color: var(--cream); }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.end { justify-content: flex-end; margin-top: 20px; }
#settings-error { color: var(--error); }
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; }
#file:focus-visible { outline: none; }
.row:has(#file:focus-visible) label { outline: 3px solid #d98336; outline-offset: 2px; }
.row:has(#file:disabled) label, button:disabled { opacity: .5; pointer-events: none; }
