/* Colours are tokens. Light here; dark in the two blocks below, which must hold the same values: one
   follows the system setting ("Auto", no data-theme), the other is the header button's "Dark"
   (web/theme.js). tests/js/theme.test.mjs checks they match and cover every token. */
:root {
  color-scheme: light dark;
  --fg: #171717;
  --muted: #6b6b6b;
  --line: #d9d9d9;
  --bg: #fafafa;
  --panel: #ffffff;
  --field: #ffffff;
  --accent: #1f4fd8;
  --accent-bg: #1f4fd8;
  --on-accent: #ffffff;
  --on-fg: #ffffff;
  --accent-soft: #eef3ff;
  --accent-faint: #f6f8ff;
  --accent-line: #b6c7f7;
  --code-bg: #e9eefc;
  --bad: #b3261e;
  --ok: #1e7a3c;
  --drop-bg: #fcfcfc;
  --drop-line: #bdbdbd;
  --drop-over: #f2f6ff;
  --notice-bg: #fff4e5;
  --notice-fg: #7a4b00;
  --notice-line: #f3d19c;
  --thumb-bg: #eeeeee;
  --badge-bg: #e6f4ea;
  --badge-fg: #1e6b34;
  --reader-bg: #ffffff;
  --pending-bg: #f2f2f2;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  color: var(--fg);
  background: var(--bg);
}
:root[data-theme="light"] { color-scheme: light; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --fg: #e6e6e6;
    --muted: #9a9a9a;
    --line: #383838;
    --bg: #121212;
    --panel: #1c1c1c;
    --field: #232323;
    --accent: #8aa8ff;
    --accent-bg: #2f5be0;
    --on-accent: #ffffff;
    --on-fg: #121212;
    --accent-soft: #243256;
    --accent-faint: #182036;
    --accent-line: #34467a;
    --code-bg: #26314f;
    --bad: #ff8a80;
    --ok: #6fcf8f;
    --drop-bg: #181818;
    --drop-line: #4a4a4a;
    --drop-over: #1b2540;
    --notice-bg: #3a2b12;
    --notice-fg: #f5c97b;
    --notice-line: #6e5220;
    --thumb-bg: #2a2a2a;
    --badge-bg: #1d3a27;
    --badge-fg: #8fdca8;
    --reader-bg: #161616;
    --pending-bg: #262626;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --fg: #e6e6e6;
  --muted: #9a9a9a;
  --line: #383838;
  --bg: #121212;
  --panel: #1c1c1c;
  --field: #232323;
  --accent: #8aa8ff;
  --accent-bg: #2f5be0;
  --on-accent: #ffffff;
  --on-fg: #121212;
  --accent-soft: #243256;
  --accent-faint: #182036;
  --accent-line: #34467a;
  --code-bg: #26314f;
  --bad: #ff8a80;
  --ok: #6fcf8f;
  --drop-bg: #181818;
  --drop-line: #4a4a4a;
  --drop-over: #1b2540;
  --notice-bg: #3a2b12;
  --notice-fg: #f5c97b;
  --notice-line: #6e5220;
  --thumb-bg: #2a2a2a;
  --badge-bg: #1d3a27;
  --badge-fg: #8fdca8;
  --reader-bg: #161616;
  --pending-bg: #262626;
}
* { box-sizing: border-box; }
/* Author display rules (.panel, .toolbar, a.btn-primary) would otherwise beat the browser's [hidden] rule. */
[hidden] { display: none !important; }
body { margin: 0; }
header {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 12px;
  padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.ext-pill {
  font-size: 12px; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--accent); color: var(--accent); text-decoration: none;
}
.ext-pill:hover { background: var(--accent-soft); }
/* Header theme button (web/theme.js): at the right end, with the icon of the current choice. It comes
   right after the title in the HTML; "order" moves it last on wide screens. */
.theme-toggle { order: 1; margin-left: auto; align-self: center; display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; font-size: 12.5px; }
.theme-toggle svg { display: none; width: 16px; height: 16px; flex: none; }
.theme-toggle[data-theme="auto"] .i-auto,
.theme-toggle[data-theme="light"] .i-light,
.theme-toggle[data-theme="dark"] .i-dark { display: block; }
.ext-banner { border-color: var(--accent-line); background: var(--accent-faint); }
.ext-banner-head { display: grid; gap: 4px; }
.ext-steps { margin: 0; padding-left: 22px; display: grid; gap: 8px; line-height: 1.5; }
.ext-steps li::marker { color: var(--muted); }
.ext-steps code, .ext-foot code { font-size: 12.5px; padding: 1px 5px; border-radius: 4px; background: var(--code-bg); overflow-wrap: anywhere; }
.ext-address { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; max-width: 100%; }
.ext-copy { padding: 1px 8px; font-size: 12px; }
.ext-foot { margin: 0; font-size: 12.5px; }
a.btn-primary {
  display: inline-block; padding: 6px 12px; border-radius: 6px;
  background: var(--accent-bg); border: 1px solid var(--accent-bg); color: var(--on-accent); text-decoration: none;
}
a.btn-primary:hover { filter: brightness(0.95); }
h1 { font-size: 16px; margin: 0; }
h1 a { color: inherit; text-decoration: none; }
h1 .logo { width: 20px; height: 20px; vertical-align: -4px; margin-right: 7px; }
.tagline { margin: 0; font-size: 13px; }
/* What the site is, under the app (index.html #about): plain text for readers and crawlers. */
.about { display: grid; gap: 14px; padding: 8px 2px 24px; border-top: 1px solid var(--line); line-height: 1.55; }
.about h2 { font-size: 18px; margin: 10px 0 0; }
.about h3 { font-size: 14.5px; margin: 0 0 4px; }
.about p, .about ol { margin: 0; }
.about ol { padding-left: 20px; display: grid; gap: 4px; }
.about .lead { max-width: 72ch; }
.about-grid, .faq-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px 24px; }
.faq { display: grid; gap: 12px; }
.not-found h2, .not-found p { margin: 0; }   /* web/404.html */
.about p, .about li { color: var(--muted); }
.about strong { color: var(--fg); }
main { max-width: 1100px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px; display: grid; gap: 12px; }
.muted { color: var(--muted); }
.row, .toolbar, .link-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.link-row input { flex: 1; min-width: 220px; }
input, select, button { font: inherit; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--field); color: inherit; }
input[type="number"] { width: 90px; }
/* Checkboxes: one size, no text-field padding, beside their label. */
input[type="checkbox"] { width: 16px; height: 16px; margin: 0; padding: 0; flex: none; accent-color: var(--accent); }
label:has(> input[type="checkbox"]) { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
input[type="checkbox"]:disabled { cursor: not-allowed; }
button { cursor: pointer; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent-bg); border-color: var(--accent-bg); color: var(--on-accent); }
button.danger { color: var(--bad); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: var(--field); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--fg); color: var(--on-fg); }
.seg button:disabled { opacity: .35; }
.drop {
  border: 1.5px dashed var(--drop-line); border-radius: 8px; padding: 26px; text-align: center;
  display: grid; gap: 4px; cursor: pointer; background: var(--drop-bg);
}
.drop.over { border-color: var(--accent); background: var(--drop-over); }
details summary { cursor: pointer; color: var(--muted); }
#advanced-body { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px 16px; margin: 12px 0; }
#advanced-body h3 { grid-column: 1 / -1; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 10px 0 0; }
.opt { display: grid; gap: 3px; align-content: start; }
.opt small { color: var(--muted); }
/* A checkbox option: the box left of its label, the help text under the label. */
.opt.check { display: grid; grid-template-columns: 16px 1fr; column-gap: 8px; row-gap: 3px; align-items: center; }
.opt.check small { grid-column: 2; }
.notice { font-size: 12.5px; padding: 2px 9px; border-radius: 999px; background: var(--notice-bg); color: var(--notice-fg); border: 1px solid var(--notice-line); }
.layout { display: grid; grid-template-columns: minmax(240px, 320px) 1fr; gap: 16px; align-items: start; }
@media (max-width: 760px) { .layout { grid-template-columns: 1fr; } }
/* Phones: room for thumbs, no keyboard hints, 16 px fields (no zoom on focus in iOS Safari). */
@media (max-width: 600px) {
  header { padding: 10px 12px; gap: 4px 10px; }
  /* The theme button shares the title's line; the tagline and the status take a line each. */
  .theme-toggle { order: 0; min-height: 34px; }
  .tagline, #status { flex-basis: 100%; }
  main { padding: 10px; gap: 10px; }
  .panel { padding: 12px; }
  .drop { padding: 18px 12px; }
  input, select, button { font-size: 16px; min-height: 40px; }
  input[type="checkbox"] { min-height: 0; width: 20px; height: 20px; }
  .opt.check { grid-template-columns: 20px 1fr; }
  .link-row input { min-width: 0; }
  .toolbar > label:has(select) { display: grid; grid-template-columns: 5.5em 1fr; align-items: center; width: 100%; }
  .toolbar > label select { width: 100%; }
  .toolbar > .seg { width: 100%; }
  .toolbar > .seg button { flex: 1; }
  .toolbar > button { flex: 1 1 auto; }
  .viewer .keys { display: none; }
  #advanced-body { grid-template-columns: 1fr; }
  .reader { padding: 12px 0 60vh; border-radius: 6px; gap: 16px; }
}
.queue:empty { display: none; }
.queue { list-style: none; margin: 0; padding: 0; display: grid; align-content: start; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px; position: sticky; top: 8px; max-height: calc(100vh - 16px); overflow: auto; }
.queue li { display: grid; grid-template-columns: 18px 56px 1fr auto; gap: 8px; align-items: center; padding: 4px; border-radius: 6px; cursor: pointer; }
.queue li.sel { background: var(--accent-soft); }
.queue img { width: 56px; height: 56px; object-fit: cover; border-radius: 4px; background: var(--thumb-bg); }
.queue .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue .st { font-size: 12px; color: var(--muted); }
.queue .st.done { color: var(--ok); }
.queue .st.error { color: var(--bad); }
.queue .badge { margin-left: 6px; padding: 0 5px; border-radius: 4px; font-size: 11px; background: var(--badge-bg); color: var(--badge-fg); }
/* One column (phones): the queue sits above the reader and scrolls away with the page. This has to come
   after the .queue rule above, or its sticky position and full-height cap win. */
@media (max-width: 760px) { .queue { position: static; max-height: 40vh; } }
.viewer { display: grid; gap: 0; min-width: 0; }
.viewer > .toolbar { position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 8px 0; }
.viewer .keys { margin-left: auto; font-size: 12px; }
kbd { font: inherit; font-size: 12px; line-height: 1.3; padding: 0 4px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; background: var(--panel); }
/* The reader: pages one after the other at one width, white space between them, like a comic. The space
   after the last page lets it scroll up to the top (it is then the current page). */
.reader { background: var(--reader-bg); border: 1px solid var(--line); border-radius: 8px; padding: 24px 16px 60vh; display: flex; flex-direction: column; align-items: center; gap: 32px; min-height: 300px; }
.reader .page { margin: 0; width: 100%; max-width: 900px; display: grid; gap: 6px; justify-items: center; }
.reader .page img { width: 100%; height: auto; display: block; }
/* Not loaded yet: a page-sized grey block (images load as they come near the window). */
.reader .page.pending { min-height: 70vh; background: var(--pending-bg); align-content: center; }
.reader .page.pending img { display: none; }
.reader figcaption { font-size: 12px; }
.reader figcaption:empty { display: none; }
.reader .empty { margin: 48px 0; }
