:root {
  --bg: #e9ebee;
  --surface: #ffffff;
  --fg: #1d232c;
  --muted: #5b6574;
  --line: #d4d8de;
  --accent: #2f5d8a;
  --accent-fg: #ffffff;
  --danger: #a32020;
  --shadow: 0 1px 3px rgb(0 0 0 / 0.25);
  color-scheme: light;
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #23272e;
    --surface: #2e333b;
    --fg: #e6e9ee;
    --muted: #a2abb8;
    --line: #424954;
    --accent: #8ab4e0;
    --accent-fg: #10161d;
    --danger: #ff8a8a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { display: flex; flex-direction: column; background: var(--bg); color: var(--fg); }

.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px;
  padding: 6px 10px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.toolbar .group { display: flex; align-items: center; gap: 4px; }
.toolbar .end { margin-left: auto; }
body:not(.has-file) .needs-file { display: none; }
button, select, input[type=text] {
  font: inherit; color: var(--fg); background: var(--surface);
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; min-height: 30px;
}
button { cursor: pointer; }
button:hover { border-color: var(--muted); }
button:focus-visible, select:focus-visible, input:focus-visible, .viewport:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.icon { min-width: 32px; padding: 4px 6px; font-size: 16px; line-height: 1; }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button[aria-pressed="false"] { opacity: 0.6; }
.icon-link { min-width: 32px; min-height: 30px; display: inline-flex; align-items: center; justify-content: center; font-size: 16px; color: var(--fg); text-decoration: none; border: 1px solid var(--line); border-radius: 6px; }
.icon-link:hover { border-color: var(--muted); }
html.web .icon-link { display: none; }
.file-name { max-width: 28ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.page-box { display: flex; align-items: center; gap: 4px; color: var(--muted); }
.page-box input { width: 4.5em; text-align: right; padding: 4px 6px; }

.banner { padding: 8px 12px; background: #fff4d6; color: #4b3a00; border-bottom: 1px solid #e8d48a; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.banner.error { background: #fde8e8; color: #6b1010; border-color: #f0b4b4; }
@media (prefers-color-scheme: dark) {
  .banner { background: #4a3f1c; color: #f6e7b8; border-color: #6b5b26; }
  .banner.error { background: #4d2222; color: #ffd6d6; border-color: #7a3434; }
}
.banner .msg { flex: 1 1 300px; }
.banner a, .banner button { font-size: 13px; }

.layout { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 150px; flex: none; overflow-y: auto; background: var(--surface); border-right: 1px solid var(--line);
  padding: 8px; display: flex; flex-direction: column; gap: 10px; align-items: center;
}
body.no-sidebar .sidebar, body:not(.has-file) .sidebar { display: none; }
.thumb { all: unset; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: 12px; }
.thumb canvas { background: #fff; box-shadow: var(--shadow); max-width: 120px; display: block; }
.thumb .ph { background: #fff; box-shadow: var(--shadow); opacity: 0.5; }
.thumb.current canvas, .thumb.current .ph { outline: 3px solid var(--accent); }
.thumb:focus-visible canvas { outline: 2px solid var(--accent); }

.viewport { flex: 1; overflow: auto; position: relative; outline: none; }
.pages { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 16px; min-width: max-content; }
body:not(.has-file) .pages { display: none; }
.page {
  position: relative; background: #fff; box-shadow: var(--shadow); flex: none;
}
.page canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.page .err { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; text-align: center; color: var(--danger); background: var(--surface); font-size: 13px; }
.page.loading::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 28px; height: 28px; margin: -14px;
  border: 3px solid #c9ced6; border-top-color: #2f5d8a; border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; }
body.has-file .empty { display: none; }
.drop-card {
  max-width: 460px; text-align: center; background: var(--surface); border: 2px dashed var(--line);
  border-radius: 14px; padding: 28px 24px;
}
.drop-card h1 { font-size: 20px; margin: 8px 0; }
.drop-card .privacy { color: var(--muted); font-size: 13px; margin-top: 18px; }
.drop-card .hint { color: var(--muted); font-size: 12px; }
.drop-overlay {
  position: fixed; inset: 0; background: rgb(47 93 138 / 0.25); border: 4px dashed var(--accent);
  display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 600; z-index: 10;
  pointer-events: none;
}
.drop-overlay span { background: var(--surface); padding: 10px 18px; border-radius: 10px; }

dialog { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--fg); min-width: min(380px, 92vw); }
dialog::backdrop { background: rgb(0 0 0 / 0.35); }
dialog h2 { margin: 0 0 12px; font-size: 17px; }
dialog fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 12px; display: grid; gap: 6px; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 14px 0 0; }
dialog progress { width: 100%; }
.error { color: var(--danger); }
.info { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; }
.info dt { color: var(--muted); }
.info dd { margin: 0; overflow-wrap: anywhere; }

.print-root { display: none; }
@media print {
  @page { margin: 0; }
  body > *:not(.print-root) { display: none !important; }
  body { display: block; background: #fff; }
  .print-root { display: block; }
  .print-root .sheet { width: 100vw; height: 100vh; display: flex; align-items: center; justify-content: center; break-after: page; overflow: hidden; }
  .print-root .sheet:last-child { break-after: auto; }
  .print-root img { max-width: 100%; max-height: 100%; object-fit: contain; }
}

.muted { color: var(--muted, #667); }
dialog menu .menu-link { margin-right: auto; align-self: center; }
a.button { display: inline-flex; align-items: center; padding: 6px 12px; border-radius: 6px; text-decoration: none; border: 1px solid var(--line); }
a.button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
