* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #1a1a2e;
  --bg-light: #16213e;
  --surface: #0f3460;
  --surface-hover: #1a4a7a;
  --primary: #e94560;
  --primary-hover: #ff6b81;
  --text: #eee;
  --text-muted: #aaa;
  --border: #2a2a4a;
  --danger: #e94560;
  --success: #2ed573;
  --sidebar-width: 220px;
  --toolbar-height: 52px;
}

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  max-width: 100vw;
}

/* Screens */
.screen { display: none; height: 100vh; width: 100vw; max-width: 100vw; overflow: hidden; }
.screen.active { display: flex; }

/* Upload Screen */
#upload-screen { display: none; overflow-y: auto; padding: 40px 24px 24px; text-align: center; position: relative; }
#upload-screen.active { display: block; }
#upload-screen > * { margin-left: auto; margin-right: auto; margin-bottom: 32px; }

.upload-area {
  border: 3px dashed var(--border);
  border-radius: 20px;
  padding: 40px 60px;
  text-align: center;
  transition: border-color 0.3s, background 0.3s;
  cursor: pointer;
}
.upload-area.dragover { border-color: var(--primary); background: rgba(233,69,96,0.05); }
.upload-icon { font-size: 64px; margin-bottom: 12px; display: none; }
.upload-area { display: flex; align-items: flex-start; gap: 24px; text-align: center; }
.upload-area-content { flex: 1; }
.upload-logo { width: 296px; height: 268px; object-fit: contain; flex-shrink: 0; }
@media (max-width: 1200px) { .upload-logo { width: clamp(120px, 24vw, 296px); height: auto; } }
@media (max-width: 600px) { .upload-area { flex-direction: column; align-items: center; } .upload-logo { width: 150px; height: auto; } }
.upload-area h1 { font-size: 28px; margin-bottom: 8px; }
.upload-area p { color: var(--text-muted); margin-bottom: 16px; }
.upload-privacy { font-size: 11px; color: var(--success); margin-bottom: 8px; line-height: 1.6; }
.privacy-lock { font-size: 18px; vertical-align: middle; margin-right: 2px; }

/* Feature cards grid */
.features-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;
  max-width: 700px; width: 100%;
}
@media (max-width: 700px) { .features-grid { grid-template-columns: repeat(2, 1fr); } }
.feature-card {
  background: var(--bg-light); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; text-align: center; text-decoration: none; color: inherit; display: block; cursor: pointer;
}
.feature-card:hover { border-color: var(--primary); }
.feature-icon { font-size: 28px; display: block; margin-bottom: 6px; }
.feature-card h3 { font-size: 14px; margin-bottom: 4px; }
.feature-card p { font-size: 11px; color: var(--text-muted); margin: 0; }

/* Image overlays — must sit above both the pdfjs-text-layer and text-layer */
.image-overlay {
  position: absolute; cursor: move; z-index: 50;
  border: 2px solid transparent; border-radius: 2px;
  transition: border-color 0.15s;
  pointer-events: auto;
}
.image-overlay * { pointer-events: auto; }
.image-overlay:hover, .image-overlay:active { border-color: var(--primary); }
.img-delete {
  position: absolute; top: -12px; right: -12px;
  width: 24px; height: 24px; background: var(--danger); color: white;
  border-radius: 50%; font-size: 16px; line-height: 24px; text-align: center;
  cursor: pointer; z-index: 51; box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
.img-resize {
  position: absolute; bottom: -6px; right: -6px;
  width: 16px; height: 16px; background: var(--primary); border-radius: 3px;
  cursor: nwse-resize; z-index: 51; box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
.img-rotate {
  position: absolute; top: -12px; left: -12px;
  width: 24px; height: 24px; background: var(--surface); color: var(--text);
  border-radius: 50%; font-size: 14px; line-height: 24px; text-align: center;
  cursor: pointer; z-index: 51; box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  border: 1px solid var(--border);
}

/* Shape overlays */
.shape-overlay {
  position: absolute; z-index: 15; pointer-events: auto; cursor: move;
}
.shape-overlay:hover { outline: 2px dashed var(--primary); }
.shape-delete {
  position: absolute; top: -10px; right: -10px;
  width: 20px; height: 20px; background: var(--danger); color: white;
  border-radius: 50%; font-size: 13px; line-height: 20px; text-align: center;
  cursor: pointer; z-index: 16; display: none;
}
.shape-overlay:hover .shape-delete { display: block; }

/* Cover & Replace drag selection */
.cover-drag-rect {
  position: fixed; border: 2px dashed var(--primary); background: rgba(233,69,96,0.1);
  z-index: 300; pointer-events: none;
}

/* Replaceable image outlines */
.img-replace-outline {
  position: absolute; border: 3px dashed var(--primary); border-radius: 4px;
  cursor: pointer; z-index: 40; background: rgba(233,69,96,0.08);
  transition: background 0.15s;
}
.img-replace-outline:hover { background: rgba(233,69,96,0.2); }
.img-replace-label {
  position: absolute; bottom: 100%; left: 50%; transform: translate(-50%, -6px);
  background: var(--primary); color: white; padding: 4px 10px; border-radius: 6px;
  font-size: 11px; font-weight: 600; pointer-events: none; white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}

/* SEO content section */
.seo-content {
  max-width: 700px; width: 100%; text-align: left;
  font-size: 13px; color: var(--text-muted); line-height: 1.7;
}
.seo-content h2 { font-size: 16px; color: var(--text); margin: 20px 0 8px; }
.seo-content ol, .seo-content ul { padding-left: 20px; margin: 8px 0; }
.seo-content li { margin: 4px 0; }
.seo-content details { margin: 4px 0; cursor: pointer; }
.seo-content summary { font-weight: 600; color: var(--text); padding: 4px 0; }
.seo-content details p { margin: 4px 0 8px 0; }

/* House / sister-site banner slots.
   Single 5:1 aspect (e.g. 1200x240 source PNG) scales to every slot:
   - rating modal:    rendered ~400x80
   - landing page:    rendered up to ~728x146
   - SEO page top/bot: rendered up to ~600x120
   No third-party JS, no tracking cookies. The slot starts hidden;
   mountHouseBanner() unhides only if there's something to show. */
.house-banner-slot {
  display: flex; justify-content: center; align-items: center;
  margin: 18px auto; width: 100%;
}
.house-banner-slot.is-landing { max-width: 728px; margin-top: 24px; margin-bottom: 24px; }
.house-banner-slot.is-rating-top,
.house-banner-slot.is-rating-bot { max-width: 400px; margin: 12px auto; }
.house-banner-slot.is-seo-top,
.house-banner-slot.is-seo-bot { max-width: 600px; margin: 22px auto; }

.house-banner {
  display: block; max-width: 100%;
  border: 1px solid rgba(255,255,255,0.08); border-radius: 8px;
  overflow: hidden; line-height: 0;
  transition: border-color 0.15s ease, transform 0.08s ease;
}
.house-banner:hover { border-color: var(--primary, #5aa6ff); }
.house-banner:active { transform: translateY(1px); }
.house-banner img { display: block; max-width: 100%; height: auto; }

/* FTC disclosure for affiliate banners. Add data-sponsored="1" on the slot
   container to surface this tag in the corner of the rendered banner. */
.house-banner-slot[data-sponsored="1"] { position: relative; }
.house-banner-slot[data-sponsored="1"]::after {
  content: "Sponsored"; position: absolute; top: 4px; right: 6px;
  font-size: 9px; letter-spacing: 0.04em; text-transform: uppercase;
  background: rgba(0,0,0,0.55); color: #fff;
  padding: 1px 5px; border-radius: 3px;
  pointer-events: none;
}

/* Popular guides — bottom-of-page link list */
.popular-guides .guide-links {
  columns: 2;
  column-gap: 36px;
  list-style: none;
  padding: 0;
  margin-top: 8px;
}
.popular-guides .guide-links li {
  margin: 0 0 8px 0;
  break-inside: avoid;
}
.popular-guides .guide-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 15px;
  border-bottom: 1px dotted transparent;
  transition: color .15s, border-color .15s;
}
.popular-guides .guide-links a:hover {
  color: var(--text);
  border-bottom-color: var(--text-muted);
}
@media (max-width: 640px) {
  .popular-guides .guide-links { columns: 1; }
}

/* Modal overlay (used by rating modal) */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 500;
  display: flex; align-items: center; justify-content: center;
}
.modal-content {
  background: var(--bg-light); border-radius: 16px; padding: 32px;
  max-width: 400px; text-align: center; box-shadow: 0 16px 48px rgba(0,0,0,0.5);
  max-height: 92vh; overflow-y: auto;
}
.modal-content h2 { margin-bottom: 12px; }
.modal-content p { color: var(--text-muted); margin-bottom: 16px; }
/* Buttons */
.btn {
  padding: 8px 16px; border: none; border-radius: 6px;
  cursor: pointer; font-size: 14px; font-weight: 500;
  transition: background 0.2s, transform 0.1s;
  color: var(--text); background: var(--surface);
}
.btn:hover { background: var(--surface-hover); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.35; cursor: default; pointer-events: none; }
.btn-primary { background: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger); color: white; }
.btn-icon {
  width: 36px; height: 36px; padding: 0; font-size: 18px;
  display: flex; align-items: center; justify-content: center; border-radius: 8px;
}
.rotate-all-label {
  display: none; font-size: 7px; line-height: 1;
  text-transform: uppercase; letter-spacing: 0.5px; color: var(--primary);
  position: absolute; bottom: 1px; left: 50%; transform: translateX(-50%);
}
.shift-held .tp-btn .rotate-all-label { display: block; }
.shift-held .tp-btn .rotate-icon { font-size: 16px; }
.shift-held .tp-btn .tp-label { display: none; }
.btn-tool { font-size: 13px; padding: 8px 14px; }
.btn-tool[data-active="true"] { background: var(--primary); }
.btn-small { font-size: 11px; padding: 4px 8px; }
.btn-sm { font-size: 12px; padding: 6px 14px; }

.separator { width: 1px; height: 24px; background: var(--border); margin: 0 8px; }

/* ===== Top Bar ===== */
.topbar {
  height: 42px; background: var(--bg-light);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 10px; flex-shrink: 0;
  position: sticky; top: 0; left: 0; right: 0; z-index: 95;
}
.topbar-logo { font-family: -apple-system, 'Helvetica Neue', Arial, sans-serif; font-weight: 900; font-size: 16px; line-height: 1.05; color: #fff; margin-right: 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; user-select: none; letter-spacing: 0.5px; text-align: center; background: none; border: 0; padding: 4px 8px; border-radius: 6px; cursor: pointer; transition: background 0.15s ease, transform 0.08s ease; }
.topbar-logo:hover { background: rgba(255,255,255,0.08); }
.topbar-logo:active { transform: scale(0.97); }
.topbar-logo:focus-visible { outline: 2px solid var(--primary, #5aa6ff); outline-offset: 2px; }

/* Zoom preset dropdown in the topbar — match the icon-button visual style. */
#zoom-level {
  appearance: none; -webkit-appearance: none;
  background: transparent;
  color: var(--text, #fff);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  padding: 4px 22px 4px 8px;
  font-size: 12px;
  line-height: 1.2;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 12px) 52%, calc(100% - 8px) 52%;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
}
#zoom-level:hover { background-color: rgba(255,255,255,0.08); }
#zoom-level:focus-visible { outline: 2px solid var(--primary, #5aa6ff); outline-offset: 1px; }
#zoom-level option { background: var(--surface, #1a2538); color: var(--text, #fff); }
.topbar-left { display: flex; align-items: center; gap: 4px; }
.topbar-center {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 12px;
  overflow: hidden;
}
.topbar-right { display: flex; align-items: center; gap: 6px; }
.topbar-sep { width: 1px; height: 22px; background: var(--border); margin: 0 6px; }
.filename {
  font-weight: 600; font-size: 13px; max-width: 200px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.page-info { color: var(--text-muted); font-size: 12px; white-space: nowrap; }
#zoom-level { font-size: 12px; min-width: 38px; text-align: center; color: var(--text-muted); }

/* ===== Left Tool Panel ===== */
.tool-panel {
  width: 72px; background: var(--bg-light);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center;
  padding: 6px 0; overflow-y: auto; flex-shrink: 0; order: 1;
}
.tp-section { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 2px 0; }
.tp-divider { width: 36px; height: 1px; background: var(--border); margin: 4px 0; }
.tp-btn {
  width: 60px; height: 54px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; border: none; border-radius: 8px; cursor: pointer;
  background: transparent; color: var(--text); transition: background 0.15s;
  position: relative; padding: 4px 2px; text-decoration: none;
}
#help-btn .tp-icon { font-size: 22px; font-weight: 700; }
.tp-btn:hover { background: var(--surface-hover); }
.tp-btn.active, .tp-btn[data-active="true"] { background: var(--primary); }
/* "Dialog open" — lighter state so it doesn't compete visually with the
   actually-selected tool. Outline + subtle fill. */
.tp-btn[data-dialog-open="true"] {
  background: rgba(90, 166, 255, 0.12);
  box-shadow: inset 0 0 0 1.5px var(--primary, #5aa6ff);
}
.tp-icon { font-size: 20px; line-height: 1; }
.tp-label { font-size: 10px; line-height: 1; color: var(--text-muted); letter-spacing: 0.3px; font-weight: 600; }
.tp-btn.active .tp-label, .tp-btn[data-active="true"] .tp-label { color: var(--text); }

/* ===== Context Bar (shape/text options) ===== */
.context-bar {
  position: absolute; top: 0; left: 72px; right: 220px;
  background: var(--bg-light); border: 1px solid var(--border);
  border-radius: 0 0 8px 8px; padding: 6px 12px; z-index: 90;
  display: flex; align-items: center; gap: 8px;
}
.ctx-group { display: flex; align-items: center; gap: 6px; }

/* Text options in context bar */
.text-options { display: flex; align-items: center; gap: 6px; }
.toolbar-label { font-size: 12px; color: var(--text-muted); }
.btn-fmt {
  width: 30px; height: 30px; padding: 0; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px;
}
.btn-fmt.active { background: var(--primary); }
.btn-highlight { background: rgba(255,230,0,0.3); color: #000; font-weight: bold; }
.btn-highlight:hover { background: rgba(255,230,0,0.6); }
.btn-highlight.active { background: rgba(255,220,0,0.95) !important; color: #000; box-shadow: 0 0 0 2px rgba(255,200,0,0.6); }
.btn-ul { text-decoration: underline; }
.btn-strike { text-decoration: line-through; }
#text-color {
  width: 26px; height: 26px; border: 2px solid var(--border);
  border-radius: 4px; cursor: pointer; background: none; padding: 0;
}
#font-size, #font-face {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 4px 6px; font-size: 12px; cursor: pointer;
}

/* ===== Editor Body ===== */
.editor-body { display: flex; flex: 1; overflow: hidden; position: relative; min-width: 0; min-height: 0; }
#editor-screen { flex-direction: column; overflow: hidden; }

/* ===== Right Sidebar (page thumbnails) ===== */
.sidebar {
  width: var(--sidebar-width); background: var(--bg-light);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
  order: 3;
}
.sidebar-header {
  padding: 12px; display: flex; justify-content: space-between; align-items: center;
  font-weight: 600; font-size: 13px; border-bottom: 1px solid var(--border);
}
.sidebar-hint {
  padding: 6px 12px; font-size: 11px; color: var(--text-muted);
  background: rgba(233,69,96,0.08); border-bottom: 1px solid var(--border);
}

.delete-input-group {
  display: flex; gap: 4px; padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.delete-input-group input {
  flex: 1; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 4px 8px; font-size: 12px; outline: none;
}
.delete-input-group input:focus { border-color: var(--primary); }
.delete-input-group input::placeholder { color: var(--text-muted); }
.btn-danger-solid {
  background: var(--danger); color: white; border: none;
  font-size: 11px; padding: 4px 10px;
}
.btn-danger-solid:hover { background: var(--primary-hover); }
.thumbnails {
  flex: 1; overflow-y: auto; padding: 8px;
  display: flex; flex-direction: column; gap: 6px;
}

.thumbnail {
  position: relative; cursor: pointer; border: 2px solid transparent;
  border-radius: 6px; overflow: visible; transition: border-color 0.2s; flex-shrink: 0;
}
.thumbnail:hover { border-color: var(--surface-hover); }
.thumbnail.active { border-color: var(--primary); }
.thumbnail.selected { border-color: var(--danger); background: rgba(233,69,96,0.15); }

.thumbnail canvas { width: 100%; display: block; border-radius: 4px; }

.thumbnail-label {
  position: absolute; bottom: 4px; left: 50%; transform: translateX(-50%);
  font-size: 11px; background: rgba(0,0,0,0.7); padding: 2px 8px; border-radius: 10px;
}

.thumbnail-check {
  position: absolute; top: 4px; right: 4px;
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.7); background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: bold;
  transition: all 0.2s; cursor: pointer; z-index: 5; color: transparent;
}
.thumbnail-check:hover {
  border-color: var(--danger); background: rgba(233,69,96,0.4); color: white;
}
.thumbnail.selected .thumbnail-check {
  background: var(--danger); border-color: var(--danger); color: white;
}
/* Drag to reorder */
.thumbnail.dragging { opacity: 0.4; }
.thumbnail.drop-above { border-top: 3px solid var(--primary); margin-top: -2px; }
.thumbnail.drop-below { border-bottom: 3px solid var(--primary); margin-bottom: -2px; }
.thumbnail[draggable] { cursor: grab; }
.thumbnail[draggable]:active { cursor: grabbing; }

/* Canvas area — continuous scroll */
.canvas-area {
  flex: 1; overflow: auto; background: var(--bg);
  padding: 24px; order: 2; min-width: 0;
}
/* Use min-width: max-content so wide (zoomed) pages stay centered when they
   fit, but the container expands horizontally for the canvas-area to scroll. */
.pages-container {
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  min-width: max-content;
}
.page-wrapper {
  position: relative; box-shadow: 0 4px 24px rgba(0,0,0,0.4); line-height: 0;
  background: #888; /* placeholder color while loading */
  pointer-events: auto;
}
.page-wrapper canvas { display: block; }
.page-wrapper .pdfjs-text-layer {
  position: absolute; top: 0; left: 0; z-index: 5;
}
.page-wrapper .text-layer {
  position: absolute; top: 0; left: 0; z-index: 10;
}

/* ===== PDF.js Text Selection Layer ===== */
.pdfjs-text-layer {
  position: absolute;
  top: 0; left: 0;
  overflow: hidden;
  z-index: 5;
  line-height: 1.0;
  text-size-adjust: none;
  forced-color-adjust: none;
}

/* PDF.js TextLayer renders spans absolutely with percentage left/top
   and font-size using calc(var(--scale-factor) * Npx).
   We make them transparent so they overlay the canvas invisibly. */
.pdfjs-text-layer > span {
  position: absolute;
  color: transparent;
  white-space: pre;
  pointer-events: all;
  cursor: text;
  transform-origin: 0% 0%;
}

.pdfjs-text-layer > span::selection {
  background: rgba(0, 80, 255, 0.3);
  color: transparent;
}

.pdfjs-text-layer > span::-moz-selection {
  background: rgba(0, 80, 255, 0.3);
  color: transparent;
}

.pdfjs-text-layer > br {
  content: ' ';
  display: block;
  height: 0;
  user-select: all;
}

.pdfjs-text-layer.hidden {
  pointer-events: none !important;
  visibility: hidden !important;
}

/* ===== Text Overlay Layer (user-added text) ===== */
.text-layer {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none; z-index: 8;
}
.text-layer.edit-mode { pointer-events: auto; cursor: crosshair; }

.text-overlay {
  position: absolute;
  background: rgba(255, 255, 255, 0.92);
  border: 1px dashed var(--primary);
  padding: 6px 10px;
  min-width: 40px; min-height: 20px;
  cursor: move; pointer-events: auto;
  outline: none; word-break: break-word; z-index: 10;
}
.text-overlay:focus-within {
  border-style: solid;
  box-shadow: 0 0 0 2px rgba(233,69,96,0.3);
}

.overlay-edit {
  outline: none;
  min-height: 1em;
  line-height: 1.3;
  /* Text styling set via inline styles from JS */
}

.text-overlay-controls {
  position: absolute; top: -12px; right: -12px;
  display: none; gap: 2px; pointer-events: auto; z-index: 20;
}
.text-overlay:hover .text-overlay-controls,
.text-overlay:focus-within .text-overlay-controls {
  display: flex;
}
.text-overlay .delete-handle {
  width: 20px; height: 20px; background: var(--danger); color: white;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 14px; cursor: pointer; line-height: 1;
}
.text-overlay .link-handle {
  width: 20px; height: 20px; background: #444; color: white;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 11px; cursor: pointer; line-height: 1;
}
.text-overlay .link-handle.has-link { background: #1f6feb; }
.text-overlay .resize-handle {
  position: absolute; bottom: -4px; right: -4px;
  width: 10px; height: 10px; background: var(--primary);
  cursor: nwse-resize; border-radius: 2px;
}

/* Post-download rating modal */
.rating-content {
  max-width: 440px;
  text-align: center;
}
.rating-content p {
  text-align: left;
  line-height: 1.5;
  color: var(--text);
  margin-bottom: 20px;
}
.rating-content p a { color: var(--primary, #5aa6ff); }
.rating-stars {
  display: flex; justify-content: center; gap: 6px;
  margin: 18px 0 20px;
}
.rating-star {
  background: none; border: 0; padding: 0;
  font-size: 40px; line-height: 1;
  color: #f5c542;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.12s ease;
  filter: drop-shadow(0 0 0 transparent);
}
.rating-star.is-off {
  color: rgba(255,255,255,0.15);
}
.rating-star:hover { transform: scale(1.15); }
.rating-star:focus-visible {
  outline: 2px solid #f5c542; outline-offset: 2px; border-radius: 4px;
}
.rating-star.is-glow { filter: drop-shadow(0 0 6px rgba(245, 197, 66, 0.55)); }
.rating-comment {
  display: block; width: 100%; box-sizing: border-box; margin-top: 12px;
  padding: 8px 10px; font: inherit; font-size: 13px; resize: vertical;
  background: rgba(255,255,255,0.04); color: var(--text, #e8e8e8);
  border: 1px solid rgba(255,255,255,0.12); border-radius: 6px;
}
.rating-comment:focus { outline: 2px solid var(--primary, #5aa6ff); outline-offset: 1px; }
.rating-actions {
  display: flex; justify-content: center; gap: 10px; margin-top: 8px;
}
.rating-status {
  min-height: 18px; margin-top: 10px; font-size: 13px;
  color: var(--text-muted);
}
.rating-status.is-error { color: var(--danger); }
.rating-status.is-ok { color: var(--success); }

/* Toast — slides out from the left edge like a drawer so it's hard to miss */
#toast-container {
  position: fixed; bottom: 24px; left: 0; z-index: 1000;
  display: flex; flex-direction: column; gap: 10px;
  pointer-events: none;
}
.toast {
  padding: 12px 20px 12px 24px;
  border-radius: 0 10px 10px 0;
  font-size: 14px;
  font-weight: 500;
  max-width: 420px;
  pointer-events: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35), 0 0 0 1px rgba(0,0,0,0.15);
  /* Generous overshoot with a touch of bounce so the motion is obvious. */
  animation: toastDrawerIn 0.45s cubic-bezier(0.34, 1.2, 0.5, 1) both;
  border-left: 4px solid rgba(0,0,0,0.25);
  will-change: transform, opacity;
}
.toast.toast-leaving {
  animation: toastDrawerOut 0.28s cubic-bezier(0.4, 0, 0.6, 1) forwards;
}
.toast-success { background: var(--success); color: #000; }
.toast-warning { background: #f5c542; color: #1a1300; }
.toast-error   { background: var(--danger); color: #fff; }
.toast-info    { background: var(--surface); color: var(--text); border-top: 1px solid var(--border); border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }

@keyframes toastDrawerIn {
  0%   { transform: translateX(-110%); opacity: 0; }
  60%  { transform: translateX(8px);   opacity: 1; }
  100% { transform: translateX(0);     opacity: 1; }
}
@keyframes toastDrawerOut {
  0%   { transform: translateX(0);     opacity: 1; }
  100% { transform: translateX(-110%); opacity: 0; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: rgba(255,255,255,0.05); border-radius: 5px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.25); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.4); }

/* Persistent selection indicator */
.selection-indicator {
  position: fixed;
  background: rgba(0, 100, 255, 0.25);
  border: 1px solid rgba(0, 100, 255, 0.5);
  pointer-events: none;
  z-index: 150;
  border-radius: 2px;
}

/* Unified edit popup */
.edit-popup {
  position: fixed; z-index: 200;
  background: var(--bg-light); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  width: 480px;
  display: flex; flex-direction: column; gap: 8px;
}
.ep-header {
  display: flex; justify-content: space-between; align-items: center;
}
.ep-font-info {
  font-size: 11px; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;
}
.ep-close { width: 24px; height: 24px; font-size: 16px; padding: 0; }
.ep-row {
  display: flex; align-items: center; gap: 4px;
}
.ep-row select {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 4px 5px; font-size: 12px; cursor: pointer;
}
#ep-font { flex: 1; min-width: 140px; max-width: 220px; }
#ep-size {
  width: 60px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 4px 6px; font-size: 12px;
}
#ep-size::-webkit-inner-spin-button { opacity: 1; }
.ep-text {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 8px 10px; font-size: 14px; outline: none; width: 100%;
}
.ep-text:focus { border-color: var(--primary); }
.ep-checkbox {
  font-size: 12px; color: var(--text-muted);
  display: flex; align-items: center; gap: 6px; cursor: pointer;
}
.ep-checkbox input { cursor: pointer; }
.ep-buttons { display: flex; gap: 6px; justify-content: flex-end; }

/* Find & Replace panel */
.find-replace-panel {
  position: fixed; top: 60px; right: 20px;
  width: 320px; background: var(--bg-light);
  border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  z-index: 100;
}
.fr-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 14px;
}
.fr-close { width: 28px; height: 28px; font-size: 18px; }
.fr-body {
  padding: 14px; display: flex; flex-direction: column; gap: 8px;
}
.fr-body label { font-size: 12px; color: var(--text-muted); }
.fr-body input {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 8px 10px; font-size: 14px; outline: none;
}
.fr-body input:focus { border-color: var(--primary); }
.fr-nav {
  display: flex; align-items: center; gap: 6px;
}
.fr-count { font-size: 12px; color: var(--text-muted); flex: 1; }
.fr-checkbox {
  font-size: 12px; color: var(--text); display: flex; align-items: center; gap: 6px; cursor: pointer;
}
.fr-checkbox input { cursor: pointer; }
.fr-info { font-size: 11px; color: var(--text-muted); line-height: 1.4; }
.fr-buttons { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }

/* Highlight for found text — precise overlay boxes positioned over just
   the matched substring within the PDF.js text layer. */
.fr-highlight-box {
  position: absolute;
  background: rgba(255, 200, 0, 0.4);
  border-radius: 2px;
  pointer-events: none;
  z-index: 7;
}
.fr-highlight-box.fr-current-box {
  background: rgba(255, 120, 0, 0.55);
}
/* Legacy whole-span highlight classes — left in for any code path we miss,
   but the new overlay boxes are preferred. */
.pdfjs-text-layer > span.fr-highlight {
  background: rgba(255, 200, 0, 0.4) !important;
  border-radius: 2px;
}
.pdfjs-text-layer > span.fr-current {
  background: rgba(255, 120, 0, 0.5) !important;
  border-radius: 2px;
}

/* Loading */
.loading-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 999;
  gap: 14px;
}
.spinner {
  width: 48px; height: 48px;
  border: 4px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
.loading-msg {
  color: #e8e8f0; font-size: 14px; text-align: center;
  background: rgba(0,0,0,0.5); padding: 6px 14px; border-radius: 6px;
  min-width: 200px; max-width: 500px;
}
.loading-msg:empty { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Keyboard shortcuts dialog */
.shortcuts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 24px; padding: 4px 0; }
.shortcuts-section h4 { font-size: 12px; color: var(--primary); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; font-weight: 700; }
.shortcut { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.shortcut span { flex: 1; }
.shortcut kbd {
  display: inline-block; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px;
  padding: 2px 6px; font-size: 11px; font-family: -apple-system, sans-serif;
  font-weight: 600; min-width: 18px; text-align: center;
}

/* Static content pages (Privacy, Terms) */
.static-page { max-width: 720px; margin: 0 auto; padding: 24px; text-align: left; }
.static-header { margin-bottom: 16px; }
.static-home-link { color: var(--primary); text-decoration: none; font-size: 14px; }
.static-home-link:hover { text-decoration: underline; }
.static-page h1 { font-size: 32px; margin-bottom: 4px; color: var(--text); }
.static-updated { font-size: 12px; color: var(--text-muted); margin-bottom: 24px; }
.static-body h2 { font-size: 20px; margin-top: 24px; margin-bottom: 8px; color: var(--text); }
.static-body p { font-size: 14px; line-height: 1.6; color: var(--text); margin-bottom: 12px; }
.static-body ul { margin: 8px 0 16px 20px; }
.static-body li { font-size: 14px; line-height: 1.6; color: var(--text); margin-bottom: 6px; }
.static-body a { color: var(--primary); }
.static-body strong { color: var(--text); }
.static-body table { font-size: 13px; }
.static-body th { color: var(--text); font-size: 13px; font-weight: 700; }
.static-body td { color: var(--text); font-size: 13px; vertical-align: top; }
.static-footer { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-muted); }
.static-footer a { color: var(--text-muted); margin: 0 4px; text-decoration: none; }
.static-footer a:hover { color: var(--primary); text-decoration: underline; }

/* ===== Mobile Layout (<768px) ===== */
@media (max-width: 768px) {
  .topbar { height: 38px; padding: 0 6px; }
  .topbar-center { display: none; }
  .topbar .btn-icon { width: 32px; height: 32px; font-size: 16px; }

  /* Move tool panel to bottom */
  .tool-panel {
    width: 100%; height: 56px; flex-direction: row;
    overflow-x: auto; overflow-y: hidden;
    border-right: none; border-top: 1px solid var(--border);
    order: 4; padding: 4px 6px; gap: 2px;
  }
  .tp-section { flex-direction: row; gap: 2px; padding: 0; }
  .tp-divider { width: 1px; height: 32px; margin: 0 4px; }
  .tp-btn { width: 44px; height: 44px; }
  .tp-icon { font-size: 16px; }
  .tp-label { font-size: 8px; }

  .editor-body { flex-direction: column; }

  /* Hide right sidebar on mobile — toggle with a button */
  .sidebar { display: none; width: 100%; height: 160px; border-left: none; border-top: 1px solid var(--border); order: 2; }
  .sidebar.mobile-open { display: flex; }

  .canvas-area { order: 1; }

  /* Context bar full width on mobile */
  .context-bar { left: 0; right: 0; top: 38px; border-radius: 0; }

  /* Dialogs smaller */
  .edit-popup { width: 90vw; max-width: 400px; left: 5vw !important; }
  .find-replace-panel { width: 90vw; max-width: 320px; right: 5vw; }
}

/* Landing-page aggregate rating display */
.rating-display {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 18px auto 0;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 14px;
  color: var(--text);
}
.rating-display-num { font-weight: 700; font-size: 16px; }
.rating-display-stars {
  position: relative;
  display: inline-block;
  font-size: 18px;
  line-height: 1;
  letter-spacing: 2px;
  color: #555;
}
.rating-display-stars::before { content: "\2605\2605\2605\2605\2605"; }
.rating-display-fill {
  position: absolute;
  left: 0; top: 0;
  overflow: hidden;
  white-space: nowrap;
  width: 0;
  color: #f5c518;
}
.rating-display-fill::before { content: "\2605\2605\2605\2605\2605"; }
.rating-display-count { color: var(--text-muted); font-size: 13px; }
