:root {
  --bg: #f6f4ef; --fg: #1d1d1f; --muted: #6b6b70; --card: #fff; --line: #e0ddd4; --accent: #1e6fd9;
  --desk: #e9e6df;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #17171a; --fg: #f1f1f3; --muted: #9a9aa2; --card: #232327; --line: #34343a; --accent: #6ea8ff; --desk: #101012; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font: 15px/1.5 -apple-system, "PingFang SC", "Segoe UI", sans-serif; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--fg); text-decoration: none; }
.brand img { border-radius: 6px; }
.title { flex: 1; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.home { color: var(--accent); text-decoration: none; font-size: 14px; margin-left: auto; }
main { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 0 16px 16px; }
.drop { margin: 40px auto; max-width: 560px; width: 100%; text-align: center; padding: 40px 24px; border: 2px dashed var(--line); border-radius: 16px; background: var(--card); }
.drop.over { border-color: var(--accent); }
.drop h1 { margin: 0 0 8px; font-size: 24px; }
.privacy { color: var(--accent); font-weight: 600; font-size: 14px; }
.note { color: var(--muted); font-size: 13px; }
.btn, .toolbar button { font: inherit; padding: 6px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--fg); cursor: pointer; }
.btn { background: var(--accent); color: #fff; border-color: var(--accent); padding: 9px 22px; }
.btn:focus-visible, .toolbar button:focus-visible, .drop:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.error { color: #c0392b; text-align: center; margin: 8px 0; }
.viewer { flex: 1; display: flex; min-height: 0; gap: 12px; margin-top: 12px; }
.thumbs { width: 120px; flex: none; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px; }
.thumbs button { border: 2px solid transparent; border-radius: 6px; background: none; padding: 2px; cursor: pointer; color: var(--muted); font-size: 12px; }
.thumbs button.active { border-color: var(--accent); }
.thumbs canvas { display: block; width: 100%; height: auto; background: #fff; border-radius: 3px; }
.stage-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-bottom: 8px; }
.toolbar .sep { width: 1px; height: 20px; background: var(--line); }
.banner { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.scroller { flex: 1; overflow: auto; background: var(--desk); border-radius: 10px; padding: 16px; }
.page-box { position: relative; margin: 0 auto; box-shadow: 0 2px 14px rgba(0,0,0,.25); background: #fff; }
.stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.stage canvas { position: absolute; left: 0; top: 0; }
.ov { position: absolute; white-space: pre-wrap; overflow: hidden; word-break: break-word; line-height: 1.25; }
.ov.eq { font-family: ui-monospace, Menlo, monospace; opacity: .85; }
.ov.eq.typeset { opacity: 1; font-family: inherit; }
.ov.img img { display: block; width: 100%; height: 100%; object-fit: cover; }
.ov.tape { border-radius: 4px; }
.ov.tape.revealed { border: 1px dashed transparent; }
.ov.link { display: flex; align-items: center; padding: 0 12px 0 26px; border-radius: 8px; background: rgba(74,144,217,.10); border: 1px solid rgba(74,144,217,.35); font: 13px/1.35 Helvetica, Arial, sans-serif; color: #4A90D9; white-space: nowrap; text-overflow: ellipsis; }
.ov.link .glyph { position: absolute; left: 8px; }
.ov.link a { color: inherit; text-decoration: none; }
.ov.link a:hover { text-decoration: underline; }
.pdf-ph { position: absolute; left: 0; right: 0; top: 40%; text-align: center; color: #888; font-size: 20px; pointer-events: none; }
@media (max-width: 640px) {
  .viewer { flex-direction: column-reverse; }
  .thumbs { width: auto; flex-direction: row; overflow-x: auto; overflow-y: hidden; }
  .thumbs button { width: 64px; flex: none; }
}
