/* ========== READER (PDF) ========== */
.reader-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.reader-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.reader-toolbar {
  gap: 6px;
  flex-wrap: wrap;
  user-select: none;
  -webkit-user-select: none;
}
.reader-controls { user-select: none; -webkit-user-select: none; }
.reader-toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--md-sys-color-outline-variant);
  margin: 0 2px;
  flex-shrink: 0;
}
.reader-open-btn {
  width: auto;
  min-width: 72px;
  min-height: 44px;
  margin-bottom: 0;
  text-align: center;
  justify-content: center;
  padding: 7px 14px;
  font-size: var(--md-sys-typescale-body-medium-size);
}
.reader-file-name {
  font-size: var(--md-sys-typescale-label-medium-size);
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
  flex: 1;
  min-width: 0;
}
.reader-page-nav,
.reader-zoom {
  display: flex;
  align-items: center;
  gap: 6px;
}
.reader-nav-btn {
  min-width: 44px;
  min-height: 44px;
  width: 44px;
  height: 44px;
  padding: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-small);
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  font-size: var(--md-sys-typescale-title-medium-size);
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-emphasized), background var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-emphasized), color var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-emphasized);
  flex-shrink: 0;
}
.reader-nav-btn:hover:not(:disabled) { border-color: var(--md-sys-color-primary); color: var(--md-sys-color-primary); background: var(--md-sys-color-secondary-container); }
.reader-nav-btn:disabled { opacity: 0.4; cursor: default; }
.reader-nav-btn.active { border-color: var(--md-sys-color-primary); background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary); }
.reader-nav-btn:focus-visible { outline: 2px solid var(--md-sys-color-primary); outline-offset: 2px; }
.reader-toggle-btn { font-size: var(--md-sys-typescale-body-medium-size); }
.reader-page-indicator,
.reader-zoom-label {
  font-size: var(--md-sys-typescale-label-medium-size);
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
  font-variant-numeric: tabular-nums;
  min-width: 56px;
  text-align: center;
}
.reader-zoom-label { min-width: 44px; }
.reader-fit-btn { font-size: var(--md-sys-typescale-label-medium-size); }
.reader-hint {
  font-size: var(--md-sys-typescale-body-small-size);
  color: var(--md-sys-color-on-surface-variant);
  line-height: 1.45;
  padding: 8px 12px;
  border: 1px dashed var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-small);
  background: var(--md-sys-color-surface-container-low);
}
.reader-hint:not([hidden]) { display: block; }
.reader-main {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px var(--page-gutter) 24px;
  gap: 12px;
  min-height: 0;
}
.reader-empty {
  text-align: center;
  padding: 48px 20px 32px;
  max-width: 420px;
  width: 100%;
}
.reader-empty-icon { font-size: 42px; margin-bottom: 12px; }
.reader-empty-sub { font-size: var(--md-sys-typescale-body-medium-size); color: var(--text-2); line-height: 1.5; }
.reader-viewer {
  position: relative;
  width: 100%;
  max-width: 900px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  touch-action: pan-x pan-y;
}
.reader-viewer[hidden] { display: none !important; }
/* scroll modes */
.reader-viewer.mode-scroll {
  overflow: auto;
  max-height: 72vh;
  gap: 12px;
  padding: 8px;
  align-items: flex-start;
  justify-content: flex-start;
  scrollbar-width: thin;
  overscroll-behavior: contain;
}
.reader-viewer.mode-scroll.dir-vertical {
  flex-direction: column;
  overflow-y: auto;
  overflow-x: auto;
}
.reader-viewer.mode-scroll.dir-horizontal {
  flex-direction: row;
  overflow-x: auto;
  overflow-y: auto;
  flex-wrap: nowrap;
}
.reader-viewer.mode-single {
  overflow: auto;
  max-height: 72vh;
  justify-content: center;
  overscroll-behavior: contain;
}
/* placeholders */
.reader-page-placeholder {
  position: relative;
  flex-shrink: 0;
  background: var(--md-sys-color-surface-container-lowest);
  box-shadow: var(--md-shadow-level2);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-extra-small);
  overflow: hidden;
}
html.dark .reader-page-placeholder { box-shadow: var(--md-shadow-level3); }
.reader-page-placeholder canvas { display: block; width: 100%; height: auto; }
.reader-spread-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: flex-start;
  flex-shrink: 0;
  width: 100%;
}
.reader-viewer.dir-horizontal .reader-spread-row {
  flex-direction: column;
  width: auto;
  height: 100%;
}
/* single mode wraps */
.reader-page-wrap {
  position: relative;
  display: inline-flex;
  gap: 12px;
  justify-content: center;
  align-items: flex-start;
  flex-shrink: 0;
}
.reader-page-wrap .reader-page-placeholder { flex-shrink: 0; }
.reader-text-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  line-height: 1;
  user-select: text;
  -webkit-user-select: text;
}
.reader-text-layer span {
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0 0;
  color: transparent;
}
.reader-text-layer span::selection { background: color-mix(in srgb, var(--md-sys-color-primary) 25%, transparent); }
.reader-text-layer .nb-hz { display: inline; }
.reader-text-layer .hz-char {
  color: transparent;
  cursor: pointer;
  border-radius: var(--md-sys-shape-corner-extra-small);
  transition: background 0.12s;
  touch-action: pan-y;
}
.reader-text-layer .hz-char:hover { background: rgba(255,235,59,0.35); color: transparent; }
.reader-text-layer .hz-char:active { background: rgba(255,235,59,0.55); }
.reader-text-layer .hz-char.hz-pen-active { background: var(--accent); color: var(--md-sys-color-on-primary); }
.reader-drag-over {
  outline: 2px dashed var(--md-sys-color-primary);
  outline-offset: -2px;
  background: var(--md-sys-color-secondary-container);
}
@media (pointer: coarse) {
  .reader-toolbar { gap: 10px; }
  .reader-toolbar .reader-nav-btn + .reader-nav-btn { margin-left: 2px; }
}
@media (max-width: 600px) {
  .reader-toolbar { gap: 8px; }
  .reader-file-name { max-width: 100px; }
  .reader-viewer.mode-scroll { max-height: 65vh; }
  .reader-viewer.mode-single { max-height: 65vh; }
}
/* Fullscreen / maximize */
#view-reader:fullscreen { background: var(--md-sys-color-surface); overflow: auto; }
#view-reader:-webkit-full-screen { background: var(--md-sys-color-surface); overflow: auto; }
#view-reader.reader-max {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--md-sys-color-surface);
  overflow: auto;
  display: flex;
  flex-direction: column;
}
#view-reader.reader-max .page-content.reader-main { flex: 1; min-height: 0; }
body.reader-max-active { overflow: hidden; }
body.reader-max-active .header { display: none; }
.reader-controls.reader-controls--immersive {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--md-sys-color-surface);
  transition: transform var(--md-sys-motion-duration-medium4) var(--md-sys-motion-easing-emphasized), opacity var(--md-sys-motion-duration-medium4) var(--md-sys-motion-easing-emphasized);
}
.reader-controls.reader-controls--hidden {
  transform: translateY(-100%);
  opacity: 0;
  pointer-events: none;
}
#view-reader:fullscreen .reader-controls,
#view-reader.reader-max .reader-controls {
  position: sticky;
}
/* Outline / bookmarks panel */
.reader-outline-backdrop {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--md-sys-color-scrim) 32%, transparent);
  z-index: 20;
}
.reader-outline-backdrop[hidden] { display: none !important; }
.reader-outline-panel {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: min(320px, 85vw);
  max-width: 90vw;
  background: var(--md-sys-color-surface-container);
  border-right: 1px solid var(--md-sys-color-outline-variant);
  box-shadow: var(--md-shadow-level3);
  z-index: 21;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.reader-outline-panel[hidden] { display: none !important; }
.reader-outline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  flex-shrink: 0;
  background: var(--md-sys-color-surface-container);
}
.reader-outline-title { font-size: var(--md-sys-typescale-title-small-size); font-weight: var(--md-sys-typescale-title-small-weight); color: var(--md-sys-color-on-surface); }
.reader-outline-close { width: 44px; height: 44px; min-width: 44px; min-height: 44px; font-size: var(--md-sys-typescale-title-medium-size); }
.reader-outline-list {
  list-style: none;
  margin: 0;
  padding: 6px 0;
  overflow-y: auto;
  flex: 1;
  max-height: 100%;
}
.reader-outline-item { margin: 0; }
.reader-outline-link {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  color: var(--md-sys-color-on-surface);
  font-size: var(--md-sys-typescale-body-medium-size);
  line-height: var(--md-sys-typescale-body-medium-line-height);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.reader-outline-link:hover { background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }
.reader-outline-link:focus-visible { outline: 2px solid var(--md-sys-color-primary); outline-offset: -2px; }
#view-reader:fullscreen .reader-outline-panel,
#view-reader.reader-max .reader-outline-panel { z-index: 30; }
#view-reader:fullscreen .reader-outline-backdrop,
#view-reader.reader-max .reader-outline-backdrop { z-index: 29; }