:root {
  color-scheme: light dark;
  --bg: #f4efe4;
  --fg: #2a2823;
  --card: #fffdf8;
  --muted: #5e5a50;
  --error: #b32942;
  --link: #2f6f6b;
  --accent: #2f6f6b;
  --star: #b7791f; /* the rating star: 3:1 against the card */
  --on-accent: #fff;
  --line: #e4dcc9;
}
/* Auto: follow the device unless the user forced light. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1b1a;
    --fg: #e8e8e6;
    --card: #272726;
    --muted: #a8a8a4;
    --error: #ff8a80;
    --link: #3acb89;
    --accent: #3acb89;
    --star: #f2b84b;
    --on-accent: #052e1f;
    --line: #3a3a38;
  }
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1b1b1a;
  --fg: #e8e8e6;
  --card: #272726;
  --muted: #a8a8a4;
  --error: #ff8a80;
  --link: #3acb89;
  --accent: #3acb89;
  --star: #f2b84b;
  --on-accent: #052e1f;
  --line: #3a3a38;
}
body { font-family: system-ui, sans-serif; margin: 0; background: var(--bg); color: var(--fg); }
a { color: var(--link); }
main { max-width: 640px; margin: 1.25rem auto; padding: 0 1rem calc(9rem + env(safe-area-inset-bottom)); } /* the bottom room keeps the floating Scan button off the last row */
.top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.top h1 { margin: 0 0 1rem; font-size: 1.5rem; }
#theme { margin-bottom: 1rem; font-size: .85rem; padding: .35rem .8rem; border-radius: 999px; }
form { display: flex; align-items: center; gap: .5rem; }
#isbn { flex: 1 1 auto; min-width: 0; padding: .5rem .75rem; font-size: 1rem; color: var(--fg); background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
button { padding: .5rem 1rem; font-size: 1rem; color: var(--fg); background: var(--card); border: 1px solid var(--line); border-radius: 10px; cursor: pointer; transition: background-color .15s, border-color .15s, opacity .15s; }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, #isbn:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Scan floats at the bottom centre on a phone (bottom right on desktop), in thumb reach; it hides while the ISBN field is being typed in. */
.scan-dock { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(1rem + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: .5rem; }
body:has(#isbn:focus) .scan-dock { display: none; }
/* On a desktop browser the dock sits higher, closer to where the pointer is; phones keep it at the bottom edge. */
@media (min-width: 700px) and (pointer: fine) { .scan-dock { left: auto; right: 2rem; transform: none; bottom: 2rem; } }
#scan { position: relative; overflow: hidden; display: inline-flex; align-items: center; gap: .5rem; min-height: 56px; padding: 0 1.9rem; border: 0; border-radius: 999px; background: var(--accent); color: var(--on-accent); font-weight: 600; box-shadow: 0 4px 18px rgba(0, 0, 0, .5), 0 1px 4px rgba(0, 0, 0, .4); touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.scan-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
#scan small { font-size: .65rem; font-weight: 400; opacity: .85; }
#scan.stop small { display: none; }
/* Holding the button fills it with red from left to right (the fill time is set from app.js); letting go early drains it quickly. */
#scan::before { content: ""; position: absolute; inset: 0; background: var(--error); transform: scaleX(0); transform-origin: left; transition: transform var(--drain, 200ms) ease-out; }
#scan.holding::before { transform: scaleX(1); transition: transform var(--hold, 800ms) linear; }
#scan > * { position: relative; }
#scan.stop { background: var(--error); color: var(--on-accent); }
#scanner { margin-top: 1rem; }
#view { display: block; width: 100%; aspect-ratio: 4 / 3; max-height: 50vh; background: #000; border-radius: 12px; } /* the picture is drawn here by drawPreview (src/scanner.js), always fitted to this box, whatever size the camera's frames are: the <video> shown by itself jumped on an iPhone while it started */
#preview { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; } /* the camera's stream plays here, out of sight but not display:none (a hidden video may stop playing) */
/* A brief shutter flash over the page when the camera reads a barcode (even if the scanner closes at once). */
#snap { position: fixed; inset: 0; pointer-events: none; opacity: 0; background: #ffb300; }
#snap.flash { animation: snap .5s ease-out; }
#snap.flash.again { background: #1e88e5; }
#snap.flash.full { background: #e53935; }
@keyframes snap { from { opacity: .55; } to { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { #snap.flash { animation: none; } button, .link-button { transition: none; } }
/* The status line takes room only when it has a message or the camera is on (a message may then appear without moving the page). */
#status { margin: .75rem 0 0; min-height: 1.5em; color: var(--muted); }
#status:empty { display: none; }
body:has(#scanner:not([hidden])) #status:empty { display: block; }
#result:not(:empty) { margin-top: 1.5rem; } /* the same gap as between the lists */
#status.error { color: var(--error); }
.book { background: var(--card); padding: 1rem; border-radius: 12px; border: 1px solid var(--line); }
.book-head { display: flex; align-items: flex-start; gap: 1rem; }
.book-main { flex: 1 1 auto; min-width: 0; } /* title and rating; the star button sits at the right edge, top-aligned with it */
.book-head .mark-toggle { flex: none; }
.book-head .cover { flex: none; width: 56px; max-height: 84px; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); }
.book-title { margin: 0; display: flex; align-items: center; gap: .5rem; font-size: 1.4rem; line-height: 1.25; }
/* The rating is the accent of the card: a gold star and a large number in the accent colour, with the count small and muted. */
.rating { display: flex; align-items: center; gap: .4rem; margin: .6rem 0 0; color: var(--accent); }
.rating-star { flex: none; width: 1.5rem; height: 1.5rem; fill: var(--star); }
.rating-value { font-size: 2rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.rating-count { font-size: .95rem; color: var(--muted); font-variant-numeric: tabular-nums; align-self: flex-end; padding-bottom: .1rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
/* Series and author under the head: a muted label and the name as a link; long names wrap instead of being cut. */
.facts-slot:not(:empty) { margin-top: .9rem; padding-top: .6rem; border-top: 1px solid var(--line); }
.facts { display: grid; grid-template-columns: auto 1fr; column-gap: 1rem; margin: 0; font-size: .95rem; line-height: 1.4; }
.facts dt { color: var(--muted); padding: .25rem 0; }
.facts dd { margin: 0; min-width: 0; padding: .25rem 0; overflow-wrap: anywhere; }
.series-number { color: var(--muted); font-variant-numeric: tabular-nums; }
.title-slot { flex: 0 1 auto; min-width: 0; } /* hugs the title so the spinner sits right after its last line */
.title-slot.editing { flex: 1 1 auto; } /* the editor field takes the whole line */
/* a small ring that turns while the lookup runs; it goes away when the answer (or its absence) is known */
.spinner { flex: none; width: .9rem; height: .9rem; box-sizing: border-box; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
/* The title looks like heading text with a dashed underline; tapping it swaps in a field with the same font.
   Both share one box (the negative margin cancels the padding and border), so nothing moves when editing starts. */
.title-edit, .title-input { display: block; box-sizing: border-box; margin: 0 calc(-.25rem - 1px); width: calc(100% + .5rem + 2px); padding: 0 .25rem; border: 1px solid transparent; border-radius: 4px; font: inherit; }
.title-edit { background: none; color: inherit; text-align: left; overflow-wrap: anywhere; cursor: text;
  /* a thin dashed line, always there, to show the title can be tapped; offset below the descenders */
  text-decoration: underline dashed; text-decoration-thickness: 1px; text-decoration-color: var(--muted); text-underline-offset: .22em; }
.title-edit:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.title-input { border-color: var(--link); background: var(--bg); color: var(--fg); }
/* The title-search pick list: the rows share one rounded rectangle, split by hairlines; each row is one tap target. */
#result:has(.candidates) { margin-top: .5rem; }
.candidates { list-style: none; margin: 0; padding: 0; overflow: hidden; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.candidates li + li { border-top: 1px solid var(--line); }
.candidate { display: flex; align-items: center; gap: .75rem; width: 100%; box-sizing: border-box; padding: .3rem .75rem; border: 0; border-radius: 0; background: none; text-align: left; }
.candidate:active { background: var(--bg); }
@media (hover: hover) { .candidate:hover { background: var(--bg); } }
.candidate:focus-visible { outline-offset: -2px; } /* the list clips what sticks out of it */
.candidate .cover { flex: none; width: 40px; height: 60px; object-fit: cover; border-radius: 3px; border: 1px solid var(--line); }
.candidate-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: .1rem; line-height: 1.25; }
.candidate-title { font-weight: 600; overflow-wrap: anywhere; }
.candidate-author { color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.candidate-author:empty { display: none; }
.warning { margin: 1rem 0 0; padding: .6rem .8rem; border-radius: 8px; border: 1px solid var(--error); color: var(--error); background: var(--card); }
.meta { color: var(--muted); margin: .25rem 0; }
.footer { margin-top: 2rem; font-size: .8rem; text-align: center; }
/* The lookup buttons under the name: the site icon at twice its 32px size, the name beneath. */
.link-row { display: flex; justify-content: center; gap: 1rem; margin-top: 1rem; }
.link-button { box-sizing: border-box; width: 88px; height: 88px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 4px; border: 1px solid var(--line); border-radius: 12px; color: var(--fg); text-decoration: none; font-size: .75rem; line-height: 1; transition: border-color .15s; }
.link-button:hover { border-color: var(--accent); }
.link-button img { width: 64px; height: 64px; border-radius: 6px; }
.link-button span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } /* a long name is cut, not overflowing */
.icon-link { box-sizing: border-box; width: 2.75rem; height: 2.75rem; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 6px; }
.icon-link { overflow: hidden; font-size: .6rem; line-height: 1; color: var(--fg); text-align: center; } /* the alt text, if the icon does not load */
.icon-link img { width: 28px; height: 28px; border-radius: 4px; }
.link-button:focus-visible, .icon-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.book-list { margin-top: 1.5rem; background: var(--card); padding: .75rem 1rem; border-radius: 12px; border: 1px solid var(--line); }
.book-list summary { position: relative; cursor: pointer; font-weight: 600; line-height: 2.25rem; padding-right: 2.75rem; }
/* The sort button sits at the right edge of the header; its menu drops under it. */
.book-list .sort-button { position: absolute; right: 0; top: 0; font-weight: 400; }
.sort-menu { position: absolute; right: 0; top: 100%; z-index: 2; display: flex; flex-direction: column; min-width: 11rem; padding: .25rem; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 4px 18px rgba(0, 0, 0, .35); font-weight: 400; line-height: 1.2; }
.sort-menu[hidden] { display: none; }
.sort-menu button { border: 0; background: none; text-align: left; padding: .6rem .75rem; font-size: .95rem; }
.sort-menu button[aria-pressed="true"] { color: var(--accent); font-weight: 600; }
.sort-menu button[aria-pressed="true"]::before { content: "✓ "; }
.sort-menu button[aria-pressed="false"]::before { content: "\00a0\00a0 "; }
.book-list summary::marker { color: var(--accent); }
.book-list ul { list-style: none; margin: .5rem 0; padding: 0; }
/* One line per book: the name on the left (cut with an ellipsis when it is too long; the card shows it in
   full), then the two site icons and the star or cross together at the right edge. The buttons are 36px so that
   a standard name like "ISBN 9789661092999" still fits in full next to them at 360px. */
.book-list li { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .5rem; padding: .35rem 0; } /* wraps only when the row is too narrow to give the name 8rem (very small screens, huge fonts): the buttons then drop under it, still right-aligned */
.row-rating { flex: none; display: inline-flex; align-items: center; gap: .2rem; font-size: .95rem; font-variant-numeric: tabular-nums; color: var(--muted); }
.row-star { color: var(--star); }
.row-actions { display: flex; flex: none; align-items: center; gap: .375rem; margin-left: auto; }
.book-list .open { display: block; flex: 1 1 8rem; min-width: 0; padding: .1em .15em .3em; margin-left: -.15em; border-radius: 0; border: 0; background: none; color: var(--link); font: inherit; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.icon { min-width: 2.75rem; min-height: 2.75rem; font-size: 1.2rem; line-height: 1; padding: 0 .55rem; cursor: pointer; } /* a touch-sized target (the card's star) */
.book-list .icon { min-width: 2.25rem; min-height: 2.25rem; padding: 0; font-size: 1.1rem; }
.book-list .icon-link { width: 2.25rem; height: 2.25rem; }
.book-list .icon-link img { width: 22px; height: 22px; }
/* The underline (also on the card's series and author links) sits well below the letters and is not interrupted by
   them; the padding gives it (and the edge of the first letter) room inside the box that cuts long names, and the negative margin keeps the text edge aligned. */
.book-list .open, .facts a { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: .3em; text-decoration-skip-ink: none; }
.book-list .open:disabled { color: var(--muted); cursor: default; }
.list-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
