:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --text: #1c2230;
  --muted: #6b7280;
  --line: #e4e6eb;
  --accent: #2557d6;
  --accent-ink: #ffffff;
  --viewer-bg: #e8eaee;
  --danger: #d23b3b;
  --gold: #d99a00;
  --shadow: 0 10px 30px rgba(16, 24, 40, 0.16);
  --radius: 12px;
  --topbar-h: 58px;
  --statusbar-h: 44px;
  --hl-op: 0.58;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1b1e24;
    --surface-2: #22262e;
    --text: #e8eaed;
    --muted: #9aa1ad;
    --line: #2d313a;
    --accent: #6d9bff;
    --accent-ink: #0b1220;
    --viewer-bg: #0c0e11;
    --danger: #ff6b6b;
    --gold: #f2b62e;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
html { touch-action: pan-x pan-y; } /* no page zoom by pinching on the bars */
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
[hidden] { display: none !important; }

.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ico.sm { width: 18px; height: 18px; }

#app { position: fixed; inset: 0; overflow: hidden; }
#main { position: absolute; inset: 0; display: flex; }
#reader { position: relative; flex: 1; min-width: 0; overflow: hidden; }

/* ---------------- top bar (floats over the PDF; hides in full screen) ---------------- */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 6px) max(12px, env(safe-area-inset-right)) 6px max(12px, env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  min-height: 58px;
  transition: transform 0.26s var(--ease);
}
body.immersive #topbar { transform: translateY(calc(-100% - 4px)); pointer-events: none; }
.proj {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px;
  padding: 4px 10px 5px; max-width: 230px; min-width: 120px; text-align: left; flex: none;
}
.proj-kicker { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.proj-row { display: flex; align-items: center; gap: 4px; max-width: 100%; }
.proj-name { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.qbar {
  flex: 1; min-width: 0; display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.qbar::-webkit-scrollbar { display: none; }
.qbar.ov-l { -webkit-mask-image: linear-gradient(to right, transparent, #000 26px); mask-image: linear-gradient(to right, transparent, #000 26px); }
.qbar.ov-r { -webkit-mask-image: linear-gradient(to left, transparent, #000 26px); mask-image: linear-gradient(to left, transparent, #000 26px); }
.qbar.ov-l.ov-r {
  -webkit-mask-image: linear-gradient(to right, transparent, #000 26px, #000 calc(100% - 26px), transparent);
  mask-image: linear-gradient(to right, transparent, #000 26px, #000 calc(100% - 26px), transparent);
}
.chip {
  --c: #ccc;
  display: inline-flex; align-items: center; gap: 7px; flex: none;
  padding: 7px 13px; border-radius: 999px; border: 1.5px solid var(--line);
  background: var(--surface); font-weight: 560; white-space: nowrap; line-height: 1.1;
}
.chip .dot, .fchip .dot, .radio .dot, .qsec-h .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.chip.active {
  border-color: color-mix(in srgb, var(--c) 70%, #000 30%);
  background: color-mix(in srgb, var(--c) 32%, var(--surface));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 30%, transparent);
}
.chip-n { font-size: 12px; color: var(--muted); font-weight: 600; }
.chip.active .chip-n { color: inherit; opacity: .7; }
.chip.add { border-style: dashed; color: var(--muted); gap: 4px; padding: 7px 11px; }
.chip.add .ico { width: 16px; height: 16px; }
.chip.star-chip { --c: #ffcc33; gap: 6px; }
.chip.star-chip .ico { width: 17px; height: 17px; color: var(--gold); }

.tb-actions { display: flex; align-items: center; gap: 2px; flex: none; }
.tb {
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  height: 40px; padding: 0 11px; border: 0; border-radius: 10px; background: transparent; font-weight: 600; font-size: 14px;
}
.tb:active, .icon-btn:active { background: var(--line); }
.tb.icon-only { padding: 0 9px; }
.badge {
  min-width: 19px; height: 19px; padding: 0 5px; border-radius: 999px; background: var(--accent); color: var(--accent-ink);
  font-size: 11.5px; display: inline-grid; place-items: center; font-weight: 700;
}
body.panel-open #btnPanel { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
@media (max-width: 1099px) { .tb-label { display: none; } .tb { padding: 0 9px; } }

/* ---------------- the PDF ---------------- */
#viewer {
  position: absolute; inset: 0; overflow: auto;
  background: var(--viewer-bg);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  touch-action: pan-x pan-y;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
/* at "fit width" the page can only move up and down */
#viewer.lock-x { overflow-x: hidden; touch-action: pan-y; }
/* one page at a time: swipe sideways, each page snaps into place */
#viewer.lock-y { overflow-y: hidden; touch-action: pan-x; scroll-snap-type: x mandatory; }
#sizer { position: relative; }
#pages { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.snap { position: absolute; top: 0; height: 1px; scroll-snap-align: start; scroll-snap-stop: always; pointer-events: none; }

.page {
  position: absolute; background: #fff; overflow: hidden; isolation: isolate;
  box-shadow: 0 1px 2px rgba(0,0,0,.14), 0 6px 18px rgba(0,0,0,.07);
}
.page:not(.ready)::before {
  content: attr(data-num); position: absolute; inset: 0; display: grid; place-items: center;
  color: #c3c7cf; font-size: 34px; font-weight: 300;
}
/* Highlights sit UNDER the page drawing, which is blended with "multiply":
   like a real marker, the colour shows on the paper and the letters stay black. */
.hl-layer, .sr-layer, .pv-layer { position: absolute; inset: 0; pointer-events: none; }
.hl-layer { z-index: 1; opacity: var(--hl-op); }
.sr-layer { z-index: 2; }
.pv-layer { z-index: 3; opacity: var(--hl-op); }
.page canvas { position: absolute; display: block; z-index: 4; pointer-events: none; }
/* the page drawing is transparent: the paper and the highlights show through it, no blending */
.page canvas.pg { inset: 0; width: 100%; height: 100%; }
/* the sharp zoomed part is opaque white and only screen-sized: blended */
.page canvas.detail { z-index: 5; mix-blend-mode: multiply; }
/* PDFs that paint their own white page: highlights go on top, blended like a marker */
.page.opaque .hl-layer, .page.opaque .sr-layer, .page.opaque .pv-layer { z-index: 6; mix-blend-mode: multiply; }

body.int-soft { --hl-op: .36; }
body.int-strong { --hl-op: .86; }
.hl, .pv-layer > div { position: absolute; background: var(--c); border-radius: 2px; }
body.hl-underline .hl, body.hl-underline .pv-layer > div {
  background: linear-gradient(to top, var(--c) 0, var(--c) 15%, transparent 15%); border-radius: 0;
}
body.hl-underline .hl-layer, body.hl-underline .pv-layer { opacity: 1; }
.hl.sel { box-shadow: 0 0 0 2px color-mix(in srgb, var(--c) 55%, #000); }
.hl.flash { animation: hlflash 1.4s ease-out; }
@keyframes hlflash {
  0%, 45% { box-shadow: 0 0 0 5px rgba(37, 87, 214, .85); }
  100% { box-shadow: 0 0 0 0 rgba(37, 87, 214, 0); }
}
.hl-star {
  position: absolute; width: 2.3%; aspect-ratio: 1; transform: translateY(-50%);
  background: #e0a100;
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='m12 2.5 2.9 6 6.6.9-4.8 4.6 1.2 6.5L12 17.4l-5.9 3.1 1.2-6.5L2.5 9.4l6.6-.9z'/></svg>") center / contain no-repeat;
  mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='m12 2.5 2.9 6 6.6.9-4.8 4.6 1.2 6.5L12 17.4l-5.9 3.1 1.2-6.5L2.5 9.4l6.6-.9z'/></svg>") center / contain no-repeat;
}
.sr { position: absolute; background: rgba(255, 152, 0, .4); border-radius: 2px; }
.sr.cur { background: rgba(255, 109, 0, .85); box-shadow: 0 0 0 2px rgba(255, 109, 0, .9); }

/* paper */
body.paper-sepia .page { background: #f5ecd6; }
body.paper-night #viewer { background: #15171a; }
body.paper-night .page { background: #060606; }
body.paper-night .page canvas { filter: invert(1) hue-rotate(180deg); }
body.paper-night .page canvas.detail { mix-blend-mode: screen; }
body.paper-night .page.opaque .hl-layer, body.paper-night .page.opaque .sr-layer, body.paper-night .page.opaque .pv-layer { mix-blend-mode: screen; }
body.paper-night .page:not(.ready)::before { color: #3a3d42; }
body.paper-night .tb-img img { filter: invert(1) hue-rotate(180deg); }

/* ---------------- footer (narrow, floats; hides in full screen) ---------------- */
#statusbar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 15;
  display: flex; align-items: center; gap: 4px;
  padding: 3px max(10px, env(safe-area-inset-right)) max(3px, calc(env(safe-area-inset-bottom) - 6px)) max(10px, env(safe-area-inset-left));
  background: var(--surface); border-top: 1px solid var(--line);
  font-size: 12.5px; color: var(--muted);
  transition: transform 0.26s var(--ease);
}
body.immersive #statusbar { transform: translateY(calc(100% + 4px)); pointer-events: none; }
.sb-page {
  border: 0; background: transparent; color: var(--text); font-weight: 650; font-size: 12.5px;
  padding: 5px 8px; border-radius: 8px; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.sb-page:active, .sb-icon:active, .zbtn:active { background: var(--line); }
.sb-icon { border: 0; background: transparent; width: 36px; height: 30px; display: grid; place-items: center; border-radius: 8px; color: var(--text); }
.doc-name {
  flex: 1 1 0; min-width: 0; text-align: center; font-weight: 600; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 8px;
}
/* an empty space on the right as wide as the buttons on the left, so the name sits in the middle */
#statusbar::after { content: ""; flex: 0 1 290px; min-width: 0; }
@media (min-width: 1000px) { body.panel-open:not(.panel-overlay) #statusbar::after { flex-basis: 0; } }
.zoom { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex: none; margin-right: 4px; }
.zbtn { border: 0; background: transparent; height: 28px; min-width: 32px; display: grid; place-items: center; color: var(--text); }
.zbtn.pct { font-size: 12px; font-weight: 650; min-width: 50px; border-left: 1px solid var(--line); border-right: 1px solid var(--line); font-variant-numeric: tabular-nums; }
body:not(.has-doc) #statusbar .zoom, body:not(.has-doc) .sb-page, body:not(.has-doc) .sb-icon { visibility: hidden; }

/* ---------------- full-screen helpers ---------------- */
.page-flash {
  position: absolute; z-index: 16; left: 50%; bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%); padding: 5px 12px; border-radius: 999px;
  background: rgba(20, 24, 32, .74); color: #fff; font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums;
  opacity: 0; transition: opacity .25s; pointer-events: none;
}
.page-flash.show { opacity: 1; }
body:not(.immersive) .page-flash { display: none; }

/* ---------------- search bar ---------------- */
.findbar {
  position: absolute; z-index: 18;
  top: calc(var(--topbar-h) + 10px); right: max(12px, env(safe-area-inset-right));
  width: min(460px, calc(100% - 24px));
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  overflow: hidden; transition: top 0.26s var(--ease);
}
body.immersive .findbar { top: calc(env(safe-area-inset-top) + 10px); }
.fb-row { display: flex; align-items: center; gap: 2px; padding: 3px 4px 3px 10px; }
.fb-lupa { color: var(--muted); }
#findInput {
  flex: 1; min-width: 60px; border: 0; outline: 0; background: transparent; color: var(--text);
  font-size: 16px; padding: 7px 6px; font-family: inherit;
}
.fb-count { font-size: 12px; color: var(--muted); white-space: nowrap; padding: 0 4px; font-variant-numeric: tabular-nums; }
.fb-list { max-height: min(50vh, 420px); overflow-y: auto; border-top: 1px solid var(--line); padding: 4px; -webkit-overflow-scrolling: touch; }
.fb-item {
  display: flex; gap: 10px; width: 100%; text-align: left; border: 0; background: transparent;
  padding: 8px; border-radius: 9px; font-size: 13.5px; line-height: 1.35; color: var(--text);
}
.fb-item.on { background: color-mix(in srgb, var(--accent) 11%, var(--surface)); }
.fb-pg { flex: none; min-width: 40px; font-size: 12px; font-weight: 700; color: var(--muted); padding-top: 1px; }
.fb-snip mark { background: #ffcf70; color: #1c2230; border-radius: 2px; padding: 0 1px; }

/* ---------------- empty state ---------------- */
.empty {
  position: absolute; inset: 0; z-index: 2; display: grid; place-items: center;
  padding: calc(var(--topbar-h) + 16px) 24px calc(var(--statusbar-h) + 16px);
  background: var(--viewer-bg); overflow: auto;
}
.empty-card {
  max-width: 470px; background: var(--surface); border-radius: 20px; padding: 30px 30px 24px;
  box-shadow: var(--shadow); text-align: center;
}
.empty-ico {
  width: 64px; height: 64px; margin: 0 auto 10px; border-radius: 18px; display: grid; place-items: center;
  background: #fff3c4; color: #8a6400;
}
.empty-ico .ico { width: 34px; height: 34px; }
.empty-card h1 { font-size: 22px; margin: 6px 0 14px; }
.empty-steps { text-align: left; padding-left: 22px; margin: 0 0 20px; color: var(--muted); }
.empty-steps li { margin: 8px 0; }
.empty-steps strong { color: var(--text); }
.empty-btns { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ---------------- side panel ---------------- */
#panel {
  width: 360px; flex: none; display: none; flex-direction: column; min-height: 0;
  background: var(--surface); border-left: 1px solid var(--line);
  padding-top: var(--topbar-h); transition: padding-top 0.26s var(--ease);
}
body.immersive #panel { padding-top: env(safe-area-inset-top); }
body.panel-open #panel { display: flex; }
#scrim { display: none; }
@media (max-width: 999px) {
  #panel {
    display: flex; position: fixed; top: 0; right: 0; bottom: 0; width: min(390px, 92vw); z-index: 30;
    padding-top: env(safe-area-inset-top); box-shadow: var(--shadow);
    transform: translateX(105%); transition: transform .22s ease;
  }
  body.panel-open #panel { transform: none; }
  #scrim { position: fixed; inset: 0; background: rgba(0,0,0,.28); z-index: 29; }
  body.panel-open #scrim { display: block; }
}
.panel-head { display: flex; align-items: center; gap: 8px; padding: 10px 8px 4px 16px; }
.panel-head h2 { margin: 0 auto 0 0; font-size: 18px; }
.panel-scope .seg-btn { padding: 4px 9px; font-size: 12.5px; }
.icon-btn { width: 38px; height: 38px; border: 0; background: transparent; border-radius: 10px; display: grid; place-items: center; color: var(--muted); flex: none; }
.icon-btn.sm { width: 34px; height: 34px; }
.icon-btn:disabled { opacity: .35; }
.icon-btn.on { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.filters { display: flex; gap: 6px; padding: 6px 12px; overflow-x: auto; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.fchip {
  --c: transparent; flex: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 10px; font-size: 13px; font-weight: 560; color: var(--muted);
}
.fchip.on { color: var(--text); border-color: var(--text); }
.search-wrap { padding: 4px 12px 8px; }
#search, .input {
  width: 100%; font-size: 16px; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); outline: none; font-family: inherit;
}
#search:focus, .input:focus { border-color: var(--accent); }
textarea.input { resize: vertical; line-height: 1.4; }

.hl-list { flex: 1; overflow-y: auto; padding: 0 12px 16px; -webkit-overflow-scrolling: touch; }
.qsec { --c: #ccc; margin-bottom: 8px; }
.qsec-h {
  position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 8px; margin: 0; padding: 10px 2px 6px;
  background: var(--surface); font-size: 15px;
}
.qsec-n { margin-left: auto; font-size: 12px; color: var(--muted); font-weight: 600; }
.doc-label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; font-weight: 600; margin: 8px 2px 2px; }
.dl-ico { display: grid; }
.dl-ico .ico { width: 15px; height: 15px; }
.dl-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flat { padding-top: 4px; }
.hl-item {
  --c: #ccc; position: relative; margin: 7px 0; padding: 10px 10px 6px 14px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--line); cursor: pointer;
}
.hl-item::before { content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 4px; border-radius: 0 3px 3px 0; background: var(--c); }
.hl-item.new { animation: pop .6s ease-out; }
@keyframes pop { 0% { transform: scale(.97); background: color-mix(in srgb, var(--c) 35%, var(--surface-2)); } 100% { transform: none; } }
.hl-text {
  margin: 0; font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif; font-size: 15px; line-height: 1.42;
  display: -webkit-box; -webkit-line-clamp: 7; -webkit-box-orient: vertical; overflow: hidden;
}
.hl-item.star .hl-text::before { content: "★ "; color: var(--gold); }
.hl-note { margin: 6px 0 0; font-size: 13px; color: var(--muted); font-style: italic; white-space: pre-line; }
.hl-note::before { content: "✎ "; font-style: normal; }
.hl-meta { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 4px; }
.hl-meta .pg { font-size: 12px; color: var(--muted); font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hl-actions { display: flex; gap: 0; flex: none; }
.mini { width: 31px; height: 30px; border: 0; background: transparent; border-radius: 8px; display: grid; place-items: center; color: var(--muted); }
.mini .ico { width: 18px; height: 18px; }
.mini:active { background: var(--line); }
.mini.on { color: var(--gold); }
.panel-empty { text-align: center; color: var(--muted); padding: 40px 18px; }
.pe-ico { width: 54px; height: 54px; margin: 0 auto 6px; border-radius: 16px; display: grid; place-items: center; background: #fff3c4; color: #8a6400; }
.panel-foot { display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.panel-foot .btn { flex: 1; }

/* ---------------- little menus (popovers) ---------------- */
.popover {
  position: fixed; z-index: 85; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: 0 12px 32px rgba(16, 24, 40, .24); padding: 4px;
  animation: popin .12s ease-out;
}
@keyframes popin { from { transform: scale(.94); opacity: 0; } }
.popover::before {
  content: ""; position: absolute; left: calc(var(--arrow-x, 50%) - 7px); bottom: -7px; width: 12px; height: 12px;
  background: var(--surface); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); transform: rotate(45deg);
}
.popover.below::before { bottom: auto; top: -7px; transform: rotate(225deg); }
.pop-row { display: flex; gap: 2px; }
.pop-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-width: 66px; padding: 8px 6px 7px; border: 0; background: transparent; border-radius: 10px;
  color: var(--text); font-size: 12px; font-weight: 640;
}
.pop-btn:active { background: var(--surface-2); }
.pb-ico { display: grid; }
.pb-ico .ico { width: 21px; height: 21px; }
.pop-btn.danger { color: var(--danger); }
.pop-btn.on { color: var(--gold); }

/* ---------------- buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 15px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  font-weight: 620; font-size: 15px; color: var(--text);
}
.btn:active { filter: brightness(.95); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn.sm { padding: 7px 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn .ico { width: 20px; height: 20px; }

/* segmented control */
.seg { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 2px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); flex: none; max-width: 100%; }
.seg-btn {
  border: 0; background: transparent; border-radius: 8px; padding: 6px 11px;
  font-size: 13.5px; font-weight: 620; color: var(--muted); white-space: nowrap;
}
.seg-btn.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.15); }

/* ---------------- modals ---------------- */
.modal-back {
  position: fixed; inset: 0; z-index: 50; background: rgba(10, 14, 22, .38);
  display: grid; place-items: center; padding: max(16px, env(safe-area-inset-top)) 16px 16px;
  animation: fade .15s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  width: min(480px, 100%); max-height: min(86vh, 760px); display: flex; flex-direction: column;
  background: var(--surface); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden;
  animation: rise .18s ease-out;
}
.modal.wide { width: min(620px, 100%); }
.modal.thumbs-modal { width: min(940px, 100%); max-height: 90vh; }
@keyframes rise { from { transform: translateY(10px); opacity: .6; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 10px 6px 20px; }
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-body { padding: 4px 20px 6px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px 18px; flex-wrap: wrap; }
.modal-foot .left { margin-right: auto; }
.msg { margin: 6px 0 10px; line-height: 1.5; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0; line-height: 1.45; }
.hint.center { text-align: center; }
.version { padding: 0 0 14px; }
.field { display: flex; flex-direction: column; gap: 6px; padding-bottom: 6px; }
.lbl { font-size: 12.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 10px; }
.quote {
  --c: #ccc; margin: 4px 0 0; padding: 12px 14px; border-left: 4px solid var(--c); border-radius: 8px;
  background: color-mix(in srgb, var(--c) 18%, var(--surface)); font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif; font-size: 16px; line-height: 1.45;
  max-height: 34vh; overflow-y: auto;
}
.qpick { display: flex; flex-wrap: wrap; gap: 8px; }
.star-row { margin-top: 8px; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { --c: #ccc; width: 38px; height: 38px; border-radius: 50%; border: 2px solid var(--surface); background: var(--c); box-shadow: 0 0 0 1px var(--line); }
.swatch.on { box-shadow: 0 0 0 3px var(--text); }

.menu-list { display: flex; flex-direction: column; gap: 2px; padding-bottom: 6px; }
.menu-item {
  display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 10px; border: 0; background: transparent; text-align: left; font-size: 16px;
}
.menu-item:active, .menu-item.current { background: var(--surface-2); }
.mi-ico { color: var(--muted); display: grid; }
.mi-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mi-check { color: var(--accent); font-weight: 800; }
.menu-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 0 8px; border-top: 1px solid var(--line); margin-top: 6px; }

.radio-list { display: flex; flex-direction: column; gap: 6px; }
.radio {
  --c: transparent; display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: 10px; border: 1.5px solid var(--line);
  background: var(--surface); text-align: left; font-weight: 560;
}
.radio.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }

.lib-list { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.lib-row { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.lib-ico { color: var(--muted); display: grid; }
.lib-info { flex: 1; min-width: 0; }
.lib-name { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-meta { font-size: 12.5px; color: var(--muted); }
.lib-btns { display: flex; gap: 6px; flex: none; }

/* switches */
.toggle { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.toggle:last-child { border-bottom: 0; }
.tg-text { flex: 1; display: flex; flex-direction: column; }
.tg-text .hint { margin: 2px 0 0; }
.toggle input, .switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch { position: relative; display: inline-flex; cursor: pointer; flex: none; }
.tg-ui { width: 50px; height: 30px; border-radius: 999px; background: var(--line); position: relative; transition: background .15s; flex: none; }
.tg-ui::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s; }
.toggle input:checked + .tg-ui, .switch input:checked + .tg-ui { background: #34c759; }
.toggle input:checked + .tg-ui::after, .switch input:checked + .tg-ui::after { transform: translateX(20px); }

/* settings */
.settings { padding-bottom: 6px; }
.set-h { margin: 18px 0 2px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.set-h:first-child { margin-top: 4px; }
.set-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.set-text { flex: 1 1 230px; display: flex; flex-direction: column; min-width: 0; }
.set-text .hint { margin: 2px 0 0; }

/* page thumbnails */
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 16px 14px; padding: 6px 2px 12px; }
.thumb { border: 0; background: transparent; padding: 0; display: flex; flex-direction: column; align-items: center; gap: 5px; }
.tb-img { position: relative; width: 100%; background: #fff; border-radius: 3px; overflow: hidden; box-shadow: 0 1px 2px rgba(0,0,0,.18), 0 4px 10px rgba(0,0,0,.08); }
.tb-img img { display: block; width: 100%; height: 100%; object-fit: cover; }
.thumb.cur .tb-img { box-shadow: 0 0 0 3px var(--accent); }
.tb-dots { position: absolute; right: 5px; bottom: 5px; display: flex; gap: 3px; }
.tb-dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 1.5px #fff; }
.tb-n { font-size: 12px; font-weight: 650; color: var(--muted); }
.thumb.cur .tb-n { color: var(--accent); }

.help { padding-left: 20px; margin: 4px 0 8px; }
.help li { margin: 0 0 12px; line-height: 1.45; }
.help li strong { display: block; }
.help li span { color: var(--muted); }

/* ---------------- toasts, banner, loading ---------------- */
#toastRoot {
  position: fixed; left: 50%; bottom: calc(var(--statusbar-h) + 12px); transform: translateX(-50%);
  z-index: 60; pointer-events: none; transition: bottom .26s var(--ease);
}
body.immersive #toastRoot { bottom: calc(env(safe-area-inset-bottom) + 60px); }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 14px; background: #1f2633; color: #fff;
  padding: 11px 14px 11px 16px; border-radius: 12px; box-shadow: var(--shadow); font-size: 14.5px; max-width: 90vw;
  animation: rise .18s ease-out;
}
.toast button { border: 0; background: transparent; color: #9cc1ff; font-weight: 700; padding: 2px 4px; }
#updateBanner {
  position: fixed; top: calc(env(safe-area-inset-top) + 10px); left: 50%; transform: translateX(-50%); z-index: 70;
  display: flex; align-items: center; gap: 12px; padding: 7px 7px 7px 16px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow); font-weight: 600; font-size: 14px;
}
#updateBanner button { border: 0; border-radius: 999px; padding: 7px 14px; background: var(--accent-ink); color: var(--accent); font-weight: 700; }
.loading { place-items: center; }
.loading-box { display: flex; align-items: center; gap: 12px; background: var(--surface); padding: 16px 20px; border-radius: 14px; box-shadow: var(--shadow); font-weight: 600; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ================= 1.2 ================= */

/* top bar: Home first, like Adobe */
.home-btn { margin-right: -4px; }
.chip.mark-chip { gap: 6px; padding: 7px 12px 7px 10px; border-style: dashed; }
.chip.mark-chip.active { border-style: solid; }
.chip-ico { display: grid; color: color-mix(in srgb, var(--c) 45%, var(--text)); }
.chip-ico .ico { width: 16px; height: 16px; }
.zbtn:disabled { opacity: .3; }

/* «Marcar» and highlights from other trabajos */
.hl.ghost { background: none; border-bottom: 2px dotted rgba(100, 108, 122, .95); border-radius: 0; }
body.hl-underline .hl.ghost { background: none; }
.hl.adjusting, .hl-star.adjusting { visibility: hidden; }

/* quick menu: question dots + actions */
.pop-col { display: flex; flex-direction: column; gap: 2px; }
.pop-dots { display: flex; flex-wrap: wrap; gap: 8px; padding: 6px 8px 4px; justify-content: center; max-width: 300px; }
.pop-dot {
  width: 26px; height: 26px; border-radius: 50%; border: 0; padding: 0; display: grid; place-items: center;
  background: var(--c); box-shadow: inset 0 0 0 1px rgba(0,0,0,.14);
}
.pop-dot.on { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text); }
.pop-dot.is-mark { background: color-mix(in srgb, var(--c) 70%, var(--surface)); }
.pd-ico { display: grid; color: rgba(0,0,0,.55); }
.pd-ico .ico { width: 14px; height: 14px; }
.pop-from { display: flex; align-items: center; gap: 8px; padding: 8px 10px 4px; font-size: 13px; color: var(--muted); font-weight: 600; max-width: 320px; }
.pop-from .dot { width: 11px; height: 11px; border-radius: 50%; background: var(--c); flex: none; }
.pop-btn.wide { min-width: 120px; }

/* handles to lengthen / shorten a highlight */
#handleLayer { position: absolute; inset: 0; z-index: 17; pointer-events: none; }
.hl-handle { position: absolute; width: 2px; margin-left: -1px; background: var(--accent); pointer-events: auto; touch-action: none; }
.hl-handle .knob {
  position: absolute; left: 50%; width: 15px; height: 15px; margin-left: -7.5px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 2px #fff, 0 1px 4px rgba(0,0,0,.35);
}
.hl-handle.start .knob { top: -14px; }
.hl-handle.end .knob { bottom: -14px; }
.hl-handle::before { content: ""; position: absolute; left: -21px; width: 44px; height: 46px; }
.hl-handle.start::before { top: -36px; }
.hl-handle.end::before { bottom: -36px; }

/* panel over the PDF on wide screens (option) */
@media (min-width: 1000px) {
  body.panel-overlay #panel {
    display: flex; position: absolute; top: var(--topbar-h); right: 0; bottom: 0; width: 360px; z-index: 19;
    padding-top: 0; box-shadow: var(--shadow); transform: translateX(105%); transition: transform .22s ease, top .26s var(--ease);
  }
  body.panel-overlay.panel-open #panel { transform: none; }
  body.panel-overlay.immersive #panel { top: 0; padding-top: env(safe-area-inset-top); }
}

/* ---------------- Home ---------------- */
#home {
  position: absolute; inset: 0; z-index: 40; background: var(--bg); overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.home-wrap { max-width: 980px; margin: 0 auto; padding: 18px 20px 40px; }
.home-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; }
.home-brand { display: flex; align-items: center; gap: 12px; }
.home-brand img { width: 46px; height: 46px; border-radius: 11px; box-shadow: 0 1px 4px rgba(0,0,0,.18); }
.home-brand h1 { margin: 0; font-size: 24px; }
.home-brand .hint { margin: 0; }
.home-actions { display: flex; align-items: center; gap: 6px; }
.home-actions .btn .ico { width: 18px; height: 18px; }
.home-h { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 26px 2px 10px; }
.btn.back { padding-left: 4px; }

.continue-card {
  width: 100%; display: flex; align-items: center; gap: 16px; margin-top: 18px; padding: 14px; text-align: left;
  border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: 0 2px 10px rgba(16,24,40,.06);
}
.continue-card .dr-thumb { width: 64px; height: 86px; }
.cc-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.cc-kicker { font-size: 12px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .05em; }
.cc-name { font-size: 17px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.continue-card .hint { margin: 0; }
.cc-go { display: grid; color: var(--muted); transform: rotate(180deg); }

.proj-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.proj-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 14px 16px; min-height: 104px; text-align: left;
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface);
}
.proj-card.current { border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 22%, transparent); }
.proj-card .hint { margin: auto 0 0; }
.pc-name { font-weight: 650; font-size: 16px; }
.pc-dots { display: flex; flex-wrap: wrap; gap: 6px 10px; }
.pc-q { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; font-weight: 650; color: var(--muted); }
.pc-q i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.pc-dots.big { margin: 4px 0 6px; }
.pc-dots.big .pc-q { font-size: 14px; padding: 5px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
.proj-card.add { align-items: center; justify-content: center; flex-direction: row; color: var(--muted); border-style: dashed; font-weight: 600; }
.proj-card.add .ico { width: 18px; height: 18px; }
.proj-title { font-size: 26px; margin: 10px 2px 6px; }

.doc-list { display: flex; flex-direction: column; gap: 8px; }
.doc-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 8px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.dr-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; border: 0; background: transparent; padding: 0; text-align: left; }
.dr-thumb {
  width: 46px; height: 62px; flex: none; border-radius: 4px; overflow: hidden; background: #fff; display: grid; place-items: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.18); color: #9aa1ad;
}
.dr-thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
body.paper-night .dr-thumb img { filter: invert(1) hue-rotate(180deg); }
.dr-info { display: flex; flex-direction: column; min-width: 0; }
.dr-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dr-info .hint { margin: 2px 0 0; }
.dr-btns { display: flex; align-items: center; gap: 2px; flex: none; }
.home-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.home-btns .ico { width: 18px; height: 18px; }
.news li { margin-bottom: 10px; }

/* pull down on Home to refresh */
.ptr {
  position: absolute; top: 0; left: 50%; z-index: 2; width: 38px; height: 38px; margin-top: env(safe-area-inset-top);
  display: grid; place-items: center; border-radius: 50%; background: var(--surface); color: var(--muted);
  box-shadow: 0 2px 10px rgba(0,0,0,.15); opacity: 0; transform: translate(-50%, -46px); pointer-events: none;
}
.ptr .ico { width: 20px; height: 20px; }
.ptr.ready { color: var(--accent); }
.ptr.spin .ico { animation: ptr-spin .7s linear infinite; }
@keyframes ptr-spin { to { transform: rotate(360deg); } }
