:root {
  --fg: #171717;
  --muted: #6b6b6b;
  --line: #d9d9d9;
  --bg: #fafafa;
  --panel: #ffffff;
  --accent: #1f4fd8;
  --bad: #b3261e;
  --ok: #1e7a3c;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  color: var(--fg);
  background: var(--bg);
}
* { 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: #eef3ff; }
.ext-banner { border-color: #b6c7f7; background: #f6f8ff; }
.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: #e9eefc; 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); border: 1px solid var(--accent); color: #fff; text-decoration: none;
}
a.btn-primary:hover { filter: brightness(0.95); }
h1 { font-size: 16px; margin: 0; }
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: #fff; 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); border-color: var(--accent); color: #fff; }
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: #fff; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--fg); color: #fff; }
.seg button:disabled { opacity: .35; }
.drop {
  border: 1.5px dashed #bdbdbd; border-radius: 8px; padding: 26px; text-align: center;
  display: grid; gap: 4px; cursor: pointer; background: #fcfcfc;
}
.drop.over { border-color: var(--accent); background: #f2f6ff; }
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: #fff4e5; color: #7a4b00; border: 1px solid #f3d19c; }
.layout { display: grid; grid-template-columns: minmax(240px, 320px) 1fr; gap: 16px; align-items: start; }
@media (max-width: 760px) { .layout { grid-template-columns: 1fr; } .queue { position: static; max-height: 40vh; } }
/* 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; }
  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: #eef3ff; }
.queue img { width: 56px; height: 56px; object-fit: cover; border-radius: 4px; background: #eee; }
.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: #e6f4ea; color: #1e6b34; }
.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: #fff; 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: #f2f2f2; align-content: center; }
.reader .page.pending img { display: none; }
.reader figcaption { font-size: 12px; }
.reader figcaption:empty { display: none; }
.reader .empty { margin: 48px 0; }
