
/* ═══════════════════════════════════════════
   reader.css — Full-screen reader (Scribd-style)
   ═══════════════════════════════════════════ */

/* Reader takes over the entire viewport — nav is hidden */
#reader-view {
  position: fixed;
  inset: 0;
  z-index: 200;
  flex-direction: row;
  background: var(--paper);
  color: var(--ink);
  display: none; /* toggled by JS */
}
#reader-view.active {
  display: flex;
}

/* ════════════════════════════════════════════
   SIDEBAR
   ════════════════════════════════════════════ */
.reader-sidebar {
  width: var(--sidebar-w);
  background: var(--cream);
  border-right: 1px solid var(--parchment);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  height: 100vh;
}

/* header */
.sidebar-header {
  padding: 16px 16px 14px;
  border-bottom: 1px solid var(--parchment);
  flex-shrink: 0;
}
.sidebar-back {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink);
  opacity: 0.45;
  cursor: pointer;
  margin-bottom: 14px;
  transition: opacity 0.18s, background 0.18s;
  background: none;
  border: 1px solid rgba(0,0,0,0.1);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  width: 100%;
  justify-content: center;
}
.sidebar-back:hover { opacity: 0.9; background: var(--parchment); }

.sidebar-poster-wrap {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
}
.sidebar-poster {
  width: 72px;
  height: 108px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #ccc;
  flex-shrink: 0;
  position: relative;
}
.sidebar-poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sidebar-poster-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  background: var(--parchment);
  opacity: 0.5;
}

.sidebar-meta { flex: 1; min-width: 0; }
.sidebar-title {
  font-family: var(--font-serif);
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 4px;
  line-height: 1.35;
}
.sidebar-year {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--ink);
  opacity: 0.38;
  letter-spacing: 0.1em;
  margin-bottom: 4px;
}
.sidebar-rating {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--gold);
  letter-spacing: 0.05em;
}

/* progress */
.sidebar-progress-wrap { margin-top: 6px; }
.sidebar-progress-label {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink);
  opacity: 0.35;
  margin-bottom: 5px;
}
.sidebar-progress-bar-wrap {
  height: 3px;
  background: var(--parchment);
  border-radius: 2px;
  overflow: hidden;
}
.sidebar-progress-bar {
  height: 100%;
  background: var(--gold);
  transition: width 0.6s ease;
  border-radius: 2px;
}

/* sidebar tabs */
.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--parchment);
  flex-shrink: 0;
}
.sidebar-tab {
  flex: 1;
  text-align: center;
  padding: 9px 4px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  color: var(--ink);
  opacity: 0.3;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: opacity 0.18s, border-color 0.18s, color 0.18s;
}
.sidebar-tab.active { opacity: 1; color: var(--gold); border-bottom-color: var(--gold); }

.sidebar-panel { display: none; flex: 1; overflow-y: auto; padding: 14px; }
.sidebar-panel.active { display: block; }

/* TOC */
.toc-item {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink);
  opacity: 0.45;
  transition: opacity 0.15s, background 0.15s;
  line-height: 1.45;
  margin-bottom: 2px;
}
.toc-item:hover { opacity: 0.85; background: var(--parchment); }
.toc-item.current { opacity: 1; background: rgba(200,151,58,0.12); color: #7a5c12; }
.toc-scene-num {
  font-size: 9px;
  opacity: 0.45;
  display: block;
  margin-bottom: 2px;
  letter-spacing: 0.08em;
}

/* Notes */
.notes-list { display: flex; flex-direction: column; gap: 9px; }
/* Info panel */
.info-section {
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--parchment);
}
.info-section:last-of-type { border-bottom: none; }
.info-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink);
  opacity: 0.35;
  margin-bottom: 5px;
  display: block;
}
.info-value {
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--ink);
  opacity: 0.8;
  line-height: 1.55;
  word-break: break-word;
  overflow-wrap: break-word;
}
.info-overview {
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--ink);
  opacity: 0.65;
  line-height: 1.7;
  margin-bottom: 16px;
  word-break: break-word;
}
.info-rating-stars {
  color: var(--gold);
  font-size: 13px;
  margin-right: 4px;
}
.info-genre-pill {
  display: inline-block;
  background: rgba(0,0,0,0.06);
  border-radius: 12px;
  padding: 3px 9px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.06em;
  color: var(--ink);
  opacity: 0.65;
  margin: 3px 3px 3px 0;
}

/* ════════════════════════════════════════════
   READER MAIN
   ════════════════════════════════════════════ */
.reader-main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  background: var(--paper);
  min-height: 0;  /* allows flex child to shrink below content size */
  display: flex;
  flex-direction: column;
}

/* Toolbar */
.reader-toolbar {
  position: sticky;
  top: 0;
  background: rgba(245,240,232,0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--parchment);
  padding: 9px 32px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 10;
  flex-shrink: 0;
}

.toolbar-btn {
  background: none;
  border: 1px solid var(--parchment-dark);
  border-radius: var(--radius-sm);
  padding: 5px 12px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  cursor: pointer;
  color: var(--ink);
  opacity: 0.5;
  transition: opacity 0.15s, background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}
.toolbar-btn:hover { opacity: 0.9; background: var(--cream); }
.toolbar-btn.active {
  opacity: 1;
  background: var(--blue-bg);
  border-color: var(--blue);
  color: var(--blue);
}

/* Highlight tool compound */
.highlight-tool-wrap {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--parchment-dark);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.highlight-tool-wrap .toolbar-btn {
  border: none;
  border-right: 1px solid var(--parchment-dark);
  border-radius: 0;
  opacity: 0.5;
}
.highlight-tool-wrap .toolbar-btn.active {
  opacity: 1;
  background: rgba(200,151,58,0.12);
  border-right-color: rgba(200,151,58,0.3);
  color: #7a5c12;
}
.hl-swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  display: inline-block;
  border: 1px solid rgba(0,0,0,0.1);
  flex-shrink: 0;
}
.hl-color-arrow {
  background: none;
  border: none;
  padding: 0 8px;
  cursor: pointer;
  color: var(--ink);
  opacity: 0.35;
  font-size: 10px;
  transition: opacity 0.15s, background 0.15s;
}
.hl-color-arrow:hover { opacity: 0.7; background: var(--cream); }

/* Color picker panel — fixed to escape backdrop-filter stacking context */
.color-picker-panel {
  position: fixed;
  background: white;
  border: 1px solid var(--parchment);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow-md);
  z-index: 9000;
  display: none;
  width: 220px;
}
.color-picker-panel.open { display: block; }
.cp-title {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink);
  opacity: 0.35;
  margin-bottom: 10px;
}
.cp-swatches {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 7px;
  margin-bottom: 12px;
}
.cp-swatch {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.15s, border-color 0.15s;
}
.cp-swatch:hover { transform: scale(1.12); }
.cp-swatch.selected { border-color: var(--ink); transform: scale(1.08); }
.cp-custom-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--parchment);
}
.cp-custom-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink);
  opacity: 0.4;
}
#cp-custom-color {
  width: 40px;
  height: 26px;
  border: 1px solid var(--parchment);
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 1px 2px;
  background: none;
}

.toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--parchment-dark);
  margin: 0 4px;
  opacity: 0.5;
}

.font-size-ctrl {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink);
  opacity: 0.4;
}
.font-size-ctrl button {
  background: none;
  border: 1px solid var(--parchment-dark);
  border-radius: var(--radius-sm);
  width: 24px;
  height: 24px;
  cursor: pointer;
  color: var(--ink);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  line-height: 1;
}
.font-size-ctrl button:hover { background: var(--cream); }
#font-size-label {
  min-width: 20px;
  text-align: center;
  opacity: 0.7;
}

/* ════════════════════════════════════════════
   FONT PICKER
   ════════════════════════════════════════════ */
.font-picker-wrap {
  position: relative;
}
.font-picker-trigger {
  font-family: var(--font-mono) !important;
  font-size: 10px !important;
  letter-spacing: 0.03em;
  min-width: 120px;
  justify-content: space-between;
  gap: 6px;
}
.font-picker-panel {
  display: none;
  position: fixed;  /* fixed so it escapes backdrop-filter stacking context on toolbar */
  background: #fff;
  color: #0e0e0e;  /* explicit dark text - panel is always light-bg regardless of night mode */
  border: 1px solid var(--parchment-dark);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  min-width: 260px;
  max-height: 70vh;
  overflow-y: auto;
  z-index: 9000;
  animation: fadeIn 0.14s ease;
}
.font-picker-panel.open { display: block; }

@keyframes fadeIn {
  from { opacity:0; transform: translateY(-4px); }
  to   { opacity:1; transform: translateY(0); }
}
.font-picker-heading {
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #0e0e0e;
  opacity: 0.45;
  padding: 10px 14px 6px;
  border-bottom: 1px solid #d9cdb8;
}
.font-option {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--parchment);
  transition: background 0.12s;
}
.font-option:last-child { border-bottom: none; }
.font-option:hover { background: #f0ece4; }
.font-option.active { background: rgba(200,151,58,0.08); }
.font-option.active .font-opt-name { color: var(--gold); }
.font-opt-name {
  font-size: 13px;
  color: #0e0e0e;
  line-height: 1.2;
}
.font-opt-meta {
  font-family: var(--font-mono);
  font-size: 9px;
  color: #0e0e0e;
  opacity: 0.45;
  letter-spacing: 0.04em;
}
.font-opt-preview {
  font-size: 11px;
  color: #0e0e0e;
  opacity: 0.55;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ════════════════════════════════════════════
   SCREENPLAY CONTENT
   ════════════════════════════════════════════ */
.screenplay-wrap {
  max-width: var(--reader-max);
  margin: 0 auto;
  padding: 52px 64px 60px;
  width: 100%;
}

/* Title page */
.screenplay-title-page {
  text-align: center;
  padding: 80px 0 100px;
  margin-bottom: 60px;
  border-bottom: 1px solid var(--parchment);
}
.sp-main-title {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 28px;
  color: var(--ink);
}
.sp-written-by {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink);
  opacity: 0.35;
  margin-bottom: 6px;
}
.sp-author {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink);
  opacity: 0.6;
}

/* Scene headings */
.sp-scene-heading {
  font-family: var(--font-mono);
  font-size: 1em;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 36px 0 10px;
  padding: 8px 0 6px;
  border-top: 1px solid rgba(0,0,0,0.07);
  color: var(--ink);
  scroll-margin-top: 80px;
}
.scene-number {
  color: var(--ink);
  opacity: 0.22;
  margin-right: 12px;
  font-size: 0.85em;
}

/* Action */
.sp-action {
  font-family: var(--font-mono);
  font-size: 1em;
  line-height: 1.72;
  margin-bottom: 12px;
  color: var(--ink);
}

/* Character */
.sp-character {
  font-family: var(--font-mono);
  font-size: 1em;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 20px 0 0 0;
  padding-left: 37%;
  color: var(--ink);
}

/* Parenthetical */
.sp-parenthetical {
  font-family: var(--font-mono);
  font-size: 0.93em;
  padding-left: 27%;
  color: var(--ink);
  opacity: 0.55;
  margin: 1px 0;
}

/* Dialogue */
.sp-dialogue {
  font-family: var(--font-mono);
  font-size: 1em;
  line-height: 1.68;
  padding: 0 15% 12px 20%;
  color: var(--ink);
}

/* Transition */
.sp-transition {
  font-family: var(--font-mono);
  font-size: 0.92em;
  text-transform: uppercase;
  text-align: right;
  margin: 24px 0 8px;
  color: var(--ink);
  opacity: 0.4;
  letter-spacing: 0.06em;
}

/* ════════════════════════════════════════════
   READER SEARCH BAR
   ════════════════════════════════════════════ */
.reader-search-bar {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 32px;
  background: #fffef9;
  border-bottom: 1px solid var(--parchment);
  flex-shrink: 0;
  position: sticky;
  top: 44px;
  z-index: 9;
  animation: slideDown 0.18s ease both;
}
.reader-search-bar.open { display: flex; }

@keyframes slideDown {
  from { opacity:0; transform: translateY(-8px); }
  to   { opacity:1; transform: translateY(0); }
}

.search-bar-icon {
  font-size: 16px;
  color: var(--ink);
  opacity: 0.35;
  flex-shrink: 0;
}
#reader-search-input {
  flex: 1;
  border: 1px solid var(--parchment);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--ink);
  background: white;
  outline: none;
  max-width: 360px;
}
#reader-search-input:focus { border-color: var(--gold); }
.search-status {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink);
  opacity: 0.4;
  min-width: 70px;
  letter-spacing: 0.06em;
}
.search-nav-btn {
  background: none;
  border: 1px solid var(--parchment-dark);
  border-radius: var(--radius-sm);
  width: 26px;
  height: 26px;
  cursor: pointer;
  color: var(--ink);
  opacity: 0.5;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.search-nav-btn:hover { opacity:1; background: var(--cream); }
.search-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink);
  opacity: 0.3;
  font-size: 16px;
  padding: 2px 4px;
  transition: opacity 0.15s;
}
.search-close-btn:hover { opacity: 0.8; }

/* Search match highlights */

/* Draft selector in sidebar */
.draft-selector-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink);
  opacity: 0.35;
  margin-bottom: 4px;
}
.draft-select {
  width: 100%;
  background: white;
  border: 1px solid var(--parchment);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--ink);
  outline: none;
  cursor: pointer;
  margin-bottom: 10px;
}

/* Info panel — drafts list */
.draft-list-item {
  font-family: var(--font-sans);
  font-size: 11px;
  color: var(--ink);
  opacity: 0.5;
  padding: 3px 0;
  display: flex;
  align-items: center;
  gap: 6px;
}
.draft-list-item.active { opacity: 0.9; font-weight: 500; }
.draft-active-tag {
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  background: var(--gold);
  color: var(--ink);
  padding: 1px 5px;
  border-radius: 2px;
}

/* Info panel admin actions */
.info-admin-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--parchment);
}
.info-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 7px 12px;
  background: none;
  border: 1px solid var(--parchment-dark);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink);
  opacity: 0.55;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}
.info-action-btn:hover { opacity: 1; background: var(--parchment); }
.upload-draft-btn { cursor: pointer; }

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  .reader-sidebar { display: none; }
  .screenplay-wrap { padding: 24px 16px 80px; }
  .sp-character { padding-left: 30%; }
  .sp-dialogue { padding: 0 5% 12px 15%; }
  .sp-parenthetical { padding-left: 18%; }
}

/* ════════════════════════════════════════════
   PDF VIEWER
   ════════════════════════════════════════════ */

/* Container replaces screenplay-wrap when in PDF mode */
.pdf-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #525659;  /* classic PDF viewer grey */
  padding: 24px 0 60px;
  gap: 16px;
  min-height: 100%;
}

/* Each rendered page */
.pdf-page {
  position: relative;
  box-shadow: 0 4px 24px rgba(0,0,0,0.45);
  background: #fff;
  /* Width controlled by parent; canvas stretches to fill */
  width: min(816px, calc(100vw - var(--sidebar-w) - 48px));
  flex-shrink: 0;
}
/* On mobile the sidebar is hidden so pdf pages get full width */
@media (max-width: 640px) {
  .pdf-page {
    width: calc(100vw - 16px) !important;
  }
}

.pdf-page canvas {
  display: block;
  width: 100%;
  height: auto;
}


/* PDF.js text layer — transparent overlay for selection */
.pdf-text-layer {
  position: absolute;
  top: 0;
  left: 0;
  overflow: visible;      /* display-scale: no clipping needed */
  opacity: 1;
  line-height: 1;
  z-index: 4;             /* above annot layer (z-index:3) so selection works */
  cursor: text;
  pointer-events: none;   /* layer itself passes through; spans handle events */
}

.pdf-text-layer span {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
  user-select: text;
  -webkit-user-select: text;
  pointer-events: all;    /* spans capture mouse for selection */
}

/* Text selections within the PDF */
.pdf-text-layer ::selection {
  background: rgba(200, 151, 58, 0.45);
  color: transparent;
}

/* Loading / error states */
.pdf-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  color: rgba(255,255,255,0.5);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.1em;
  padding: 80px;
}

.pdf-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255,255,255,0.12);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.pdf-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 80px 40px;
  color: rgba(255,255,255,0.5);
  font-family: var(--font-sans);
  max-width: 420px;
  margin: 0 auto;
}
.pdf-error h3 {
  font-family: var(--font-serif);
  font-size: 20px;
  color: var(--paper);
  margin-bottom: 10px;
}
.pdf-error p {
  font-size: 13px;
  line-height: 1.6;
  opacity: 0.6;
}

/* ── Empty state (no file uploaded) ── */
.sp-empty-state {
  text-align: center;
  padding: 80px 40px;
}
.sp-empty-icon {
  font-size: 52px;
  margin-bottom: 20px;
  opacity: 0.3;
}
.sp-empty-msg {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink);
  opacity: 0.45;
  margin-bottom: 10px;
  letter-spacing: 0.04em;
}
.sp-empty-hint {
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--ink);
  opacity: 0.5;
  line-height: 1.6;
}
.sp-empty-upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 20px;
  padding: 10px 22px;
  background: var(--gold);
  color: var(--ink);
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s;
  opacity: 1;
}
.sp-empty-upload-btn:hover { background: var(--gold-light); }

/* ════════════════════════════════════════
   PDF ANNOTATION OVERLAY LAYER
   ════════════════════════════════════════ */

/* Layer sits above canvas and text layer, below page-label */
.pdf-annot-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;   /* pass through scroll/clicks by default */
  z-index: 3;
}

/* Each annotation group (one highlight = one or more rects) */
.pdf-annot-group {
  pointer-events: all;    /* groups are clickable */
  cursor: pointer;
}

/* Individual highlight rect — positioned as % of page size */
.pdf-annot-rect {
  position: absolute;
  border-radius: 2px;
  transition: filter 0.12s;
}

.pdf-annot-group:hover .pdf-annot-rect {
  filter: brightness(0.82) saturate(1.3);
}

/* Note indicator pin shown on first rect of an annotation-type group */
.pdf-annot-group[data-kind="annotation"] .pdf-annot-rect:first-child::after {
  content: '✏';
  position: absolute;
  top: -14px;
  left: 0;
  font-size: 11px;
  line-height: 1;
  pointer-events: none;
  opacity: 0.7;
}

/* Note page reference in sidebar */
.note-page {
  font-family: var(--font-mono);
  font-size: 9px;
  opacity: 0.45;
  margin-left: 5px;
  letter-spacing: 0.05em;
}

/* ── PDF Search Overlays ── */
/* .pdf-search-layer sits inside .pdf-page (alongside .pdf-text-layer),
   positioned using client-rect coordinates relative to the page div. */
.pdf-search-layer {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 5;
}

.pdf-search-overlay {
  position: absolute;
  background: rgba(255, 213, 0, 0.55);
  border-radius: 2px;
  pointer-events: none;
  transition: background 0.1s;
}

.pdf-search-overlay.search-match-active {
  background: rgba(255, 140, 0, 0.75);
  outline: 2px solid rgba(200, 100, 0, 0.85);
}

/* ═══════════════════════════════════════════════════
   FOCUS MODE
   ═══════════════════════════════════════════════════ */
.screenplay-wrap.focus-mode .sp-scene-block {
  opacity: 0.15;
  transition: opacity 0.35s ease;
}
.screenplay-wrap.focus-mode .sp-scene-block.focus-active {
  opacity: 1;
}
/* Keep title page visible */
.screenplay-wrap.focus-mode .screenplay-title-page {
  opacity: 0.4;
}

/* ═══════════════════════════════════════════════════
   SCENE DURATION BADGES
   ═══════════════════════════════════════════════════ */
.scene-duration {
  display: inline-block;
  margin-left: 10px;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0.05em;
  color: #7a5c12;   /* dark gold — legible on white paper background */
  vertical-align: middle;
  background: rgba(200,151,58,0.10);
  border: 1px solid rgba(200,151,58,0.25);
  border-radius: 3px;
  padding: 1px 5px;
}

.sp-duration {
  font-family: var(--font-mono);
  font-size: 11px;
  color: #6a5010;   /* darker gold for white bg legibility */
  opacity: 0.75;
  margin-top: 16px;
  letter-spacing: 0.06em;
}

.toc-duration {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 9px;
  color: #7a5c12;
  opacity: 0.85;
  flex-shrink: 0;
  padding-left: 6px;
}

/* Make toc-item flex for duration alignment */
.toc-item {
  display: flex !important;
  align-items: baseline;
  gap: 4px;
  flex-wrap: nowrap;
}

.toc-item .toc-scene-num {
  flex-shrink: 0;
}


/* Duration badge colours in night mode — gold is bright enough on dark bg */
[data-theme="night"] .scene-duration {
  color: var(--gold);
  background: rgba(200,151,58,0.12);
  border-color: rgba(200,151,58,0.3);
}
[data-theme="night"] .sp-duration  { color: var(--gold); }
[data-theme="night"] .toc-duration { color: var(--gold); }
/* ═══════════════════════════════════════════════════
   KEYBOARD SHORTCUTS PANEL
   ═══════════════════════════════════════════════════ */
.shortcuts-panel {
  position: fixed;
  bottom: 80px;
  right: 32px;
  z-index: 500;
  background: #fff;
  border: 1px solid var(--parchment-dark);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 320px;
  overflow: hidden;
  display: none;
  animation: slideUp 0.18s ease;
}
.shortcuts-panel.visible { display: block; }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.shortcuts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--parchment);
}

.shortcuts-title {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink);
  opacity: 0.5;
}

.shortcuts-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--ink);
  opacity: 0.4;
  padding: 0 2px;
  line-height: 1;
}
.shortcuts-close:hover { opacity: 0.8; }

.shortcuts-list {
  padding: 8px 0 12px;
}

.shortcut-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 16px;
}

kbd.shortcut-key {
  font-family: var(--font-mono);
  font-size: 10px;
  background: var(--cream);
  border: 1px solid var(--parchment-dark);
  border-radius: 4px;
  padding: 3px 7px;
  white-space: nowrap;
  color: var(--ink);
  min-width: 72px;
  text-align: center;
  flex-shrink: 0;
}

.shortcut-desc {
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--ink);
  opacity: 0.7;
}

/* ═══════════════════════════════════════════════════
   MOBILE BOTTOM NAV & DRAWER
   ═══════════════════════════════════════════════════ */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 300;
  background: var(--cream);
  border-top: 1px solid var(--parchment-dark);
  height: 56px;
  align-items: stretch;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.18);
}

.mob-nav-btn {
  flex: 1;
  background: none;
  border: none;
  border-right: 1px solid var(--parchment);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--ink);
  opacity: 0.5;
  cursor: pointer;
  padding: 0 4px;
  transition: opacity 0.15s, background 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
}
.mob-nav-btn:last-child { border-right: none; }
.mob-nav-btn:hover  { opacity: 0.85; background: var(--parchment); }
.mob-nav-btn.active { opacity: 1; color: var(--gold); }

.mobile-drawer {
  display: none;  /* hidden on desktop; shown only in mobile media query */
  position: fixed;
  bottom: 56px;
  left: 0;
  right: 0;
  z-index: 290;
  background: var(--cream);
  border-top: 1px solid var(--parchment-dark);
  border-radius: 14px 14px 0 0;
  max-height: 70vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 -8px 40px rgba(0,0,0,0.28);
}
.mobile-drawer.open { transform: translateY(0); }

.mobile-drawer-handle {
  width: 36px;
  height: 4px;
  background: var(--parchment-dark);
  border-radius: 2px;
  margin: 12px auto 10px;
  cursor: pointer;
}

.mobile-drawer-content {
  padding: 8px 0 24px;
}

.mobile-drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 280;
  background: rgba(0,0,0,0.3);
}
.mobile-drawer.open ~ .mobile-drawer-backdrop,
.mobile-drawer-backdrop.active { display: block; }

/* ═══════════════════════════════════════════════════
   MOBILE RESPONSIVE — full reader overhaul
   ═══════════════════════════════════════════════════ */
@media (max-width: 640px) {
  /* Show mobile nav and drawer */
  .mobile-bottom-nav { display: flex; }
  .mobile-drawer { display: block; }

  /* Hide desktop sidebar completely */
  .reader-sidebar { display: none !important; }

  /* Compress toolbar to fit small screen */
  .reader-toolbar {
    padding: 7px 12px;
    gap: 5px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .reader-toolbar::-webkit-scrollbar { display: none; }

  /* Shrink toolbar buttons */
  .toolbar-btn {
    font-size: 10px !important;
    padding: 4px 8px !important;
    white-space: nowrap;
  }

  /* Hide non-essential toolbar items on mobile */
  #focus-mode-btn,
  #shortcuts-btn,
  #font-picker-sep,
  #font-picker-wrap,
  .toolbar-sep:nth-child(n+4) { display: none !important; }

  /* Full width screenplay */
  .screenplay-wrap {
    padding: 24px 16px 80px !important;
    max-width: 100% !important;
  }

  /* Tighter screenplay margins */
  .sp-character    { padding-left: 28% !important; }
  .sp-dialogue     { padding: 0 4% 10px 14% !important; }
  .sp-parenthetical { padding-left: 16% !important; }

  /* Bottom padding to clear nav */
  #screenplay-content { padding-bottom: 80px; }

  /* Shortcuts panel — full width at bottom */
  .shortcuts-panel {
    bottom: 64px;
    right: 8px;
    left: 8px;
    width: auto;
  }

  /* Library adjustments */
  .library-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)) !important;
    gap: 12px !important;
    padding: 16px !important;
  }

  .library-hero h1 { font-size: 28px !important; }
  .library-controls { padding: 0 12px 12px !important; flex-direction: column !important; gap: 10px !important; }

  nav { padding: 0 12px !important; }
  .nav-logo { font-size: 15px !important; }
  #admin-upload-btn { display: none !important; }
}
