:root {
  --ws-navy: #2f3b52;
  --ws-orange: #e8703a;
  --ws-purple: #8a6ba8;
  --ws-green: #9ab08b;
  --ws-bg: #eef0f3;
  --page-bg: #ffffff;
  --ink: #2a2f3a;
  --muted: #8a8f9a;
  --ok: #6fa87a;
  --warn: #d9a441;
  --danger: #cf5b4e;
  --page-font-size: 14pt;
  --page-line-height: 1.4;
  --page-font-weight: 400;
  --page-zoom: 0.55;
  /* Multiplier tuned against a real ruler so 100% view zoom shows the page
     at true physical size on THIS monitor — CSS mm/pt assume a 96dpi
     reference that real screens rarely match exactly. */
  --calibration: 1;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ws-bg);
  color: var(--ink);
}

.access-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--ws-navy);
  display: flex;
  align-items: center;
  justify-content: center;
}
.access-gate[hidden] { display: none; }
.access-gate-form {
  background: white;
  padding: 32px 28px;
  border-radius: 10px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.3);
}
.access-gate-form h2 { margin: 0; color: var(--ws-navy); }
.access-gate-form p { margin: 0; font-size: 13px; color: var(--muted); }
.access-gate-form input {
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #c3c8d1;
  font-size: 14px;
}
.access-gate-form button {
  padding: 8px;
  border-radius: 6px;
  border: none;
  background: var(--ws-orange);
  color: white;
  font-weight: 700;
  cursor: pointer;
}
.access-gate-form button:hover { filter: brightness(1.08); }
.access-gate-error {
  color: var(--danger);
  font-size: 12px;
}

.current-user {
  font-size: 12px;
  color: white;
  opacity: 0.85;
}

.ai-prompt-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(47, 59, 82, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
}
.ai-prompt-modal[hidden] { display: none; }
.ai-prompt-form {
  background: white;
  padding: 24px;
  border-radius: 10px;
  width: 420px;
  max-width: 92vw;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.3);
}
.ai-prompt-form h3 { margin: 0; color: var(--ws-navy); }
.ai-prompt-context {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  background: #f4f0fa;
  border-left: 3px solid var(--ws-purple);
  padding: 6px 8px;
  border-radius: 4px;
}
.ai-prompt-form textarea {
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #c3c8d1;
  font-family: inherit;
  font-size: 13px;
  resize: vertical;
}
.ai-prompt-error {
  color: var(--danger);
  font-size: 12px;
}
.ai-prompt-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}
.ai-prompt-buttons .topbar-btn-dark,
.ai-prompt-buttons .topbar-btn-primary {
  padding: 7px 16px;
}
.ai-prompt-buttons .topbar-btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  animation: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 20px;
  background: var(--ws-navy);
  color: white;
}

.topbar h1 {
  font-size: 18px;
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.topbar .subtitle {
  font-size: 13px;
  font-weight: 400;
  opacity: 0.75;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  font-size: 13px;
}

.topbar-controls label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar select {
  padding: 4px 8px;
  border-radius: 6px;
  border: none;
  font-size: 13px;
}

.capacity-toggle input[type="range"] {
  width: 120px;
}

#capacity-value {
  min-width: 90px;
  opacity: 0.85;
}

.howto-coverage {
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 12px;
}
.howto-coverage.ok { background: var(--ok); color: white; }
.howto-coverage.warn { background: var(--warn); color: white; }

.edit-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}

.topbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.35);
  background: transparent;
  color: white;
  font-size: 12px;
  cursor: pointer;
}
.topbar-btn:hover { background: rgba(255,255,255,0.12); }
.topbar-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.topbar-btn:disabled:hover { background: transparent; }
.topbar-btn-danger:hover { background: var(--danger); border-color: var(--danger); }

/* The one action that actually makes edits durable (localStorage is just a
   per-browser scratch copy) — kept visually louder than the other buttons
   on purpose, and flips to an "unsaved" warning color the moment anything
   changes, so it's never ambiguous whether work has actually been saved. */
.topbar-btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px;
  border-radius: 6px;
  border: none;
  background: var(--ok);
  color: white;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.topbar-btn-primary:hover { filter: brightness(1.08); }
.topbar-btn-primary.dirty {
  background: var(--warn);
  animation: save-btn-pulse 1.6s ease-in-out infinite;
}
@keyframes save-btn-pulse {
  0%, 100% { box-shadow: 0 1px 3px rgba(0,0,0,0.25); }
  50% { box-shadow: 0 0 0 5px rgba(217, 164, 65, 0.35); }
}

.typebar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 8px 20px;
  background: #dfe3ea;
  color: var(--ink);
  font-size: 12.5px;
  border-bottom: 1px solid #cfd4dc;
}
.typebar-label {
  font-weight: 600;
  color: var(--ws-navy);
  margin-right: 4px;
}
.typebar-selection {
  font-style: italic;
  color: var(--muted);
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.typebar label {
  display: flex;
  align-items: center;
  gap: 5px;
}
.typebar input[type="number"] {
  width: 56px;
  padding: 2px 5px;
  border-radius: 5px;
  border: 1px solid #c3c8d1;
}
.typebar select {
  padding: 2px 5px;
  border-radius: 5px;
  border: 1px solid #c3c8d1;
}
.typebar input:disabled,
.typebar select:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.zoom-toggle input[type="range"] { width: 130px; }
#page-zoom-value { min-width: 34px; display: inline-block; }

.topbar-btn-dark {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--ws-navy);
  background: white;
  color: var(--ws-navy);
  font-size: 12px;
  cursor: pointer;
}
.topbar-btn-dark:hover { background: var(--ws-navy); color: white; }

.calibration-panel {
  background: #fffbe8;
  border-bottom: 2px solid var(--warn);
  padding: 12px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}
/* [hidden] alone loses to the class rule above (same-origin cascade, later
   rule wins) — this compound selector is more specific, so toggling the
   `hidden` attribute in JS actually hides the panel. */
.calibration-panel[hidden] { display: none; }

.sync-banner {
  background: var(--danger);
  color: white;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
}
.sync-banner[hidden] { display: none; }
.calibration-panel p {
  max-width: 640px;
  margin: 0;
  font-size: 13px;
  color: #6b5a1f;
}
.calibration-ruler-wrap {
  padding: 6px 0;
}
.calibration-ruler {
  height: 26px;
  width: calc(100mm * var(--calibration, 1));
  background-image: repeating-linear-gradient(
    to right,
    var(--ws-navy) 0,
    var(--ws-navy) 2px,
    transparent 2px,
    transparent calc(10mm * var(--calibration, 1))
  );
  background-position: left top;
  background-repeat: no-repeat;
  border-bottom: 3px solid var(--ws-navy);
  border-left: 2px solid var(--ws-navy);
  border-right: 2px solid var(--ws-navy);
}
.calibration-slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.calibration-slider-row input[type="range"] { width: 220px; }
#calibration-value { min-width: 44px; display: inline-block; font-weight: 600; }

main {
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.unit-progress {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  max-width: 1100px;
  width: 100%;
  justify-content: center;
}

.unit-progress .u {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: white;
  border: 1px solid #d7dbe2;
  color: var(--muted);
  cursor: pointer;
}

.unit-progress .u.active {
  border-color: var(--ws-navy);
  color: var(--ws-navy);
  font-weight: 600;
}

.unit-progress .u .dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 5px;
}

.spread-viewport {
  width: 100%;
  overflow: auto;
  display: flex;
  justify-content: center;
  padding: 4px 0 40px;
}

/* Sticker-pack insert — a per-unit sheet of 12 round 25mm stickers, sibling
   of .spread (not nested inside it), shown only next to spread 1. Same
   zoom/calibration scale as the pages so 25mm reads as 25mm on screen. */
.sticker-sheet {
  background: white;
  border-radius: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  padding: 14px;
  margin-right: 6px;
  align-self: flex-start;
  position: relative;
  z-index: 20;
  /* transform (translate drag offset + scale) is set inline from JS —
     dragging updates the translate() part live. */
  transform-origin: top right;
}
.sticker-sheet-label {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  margin-bottom: 8px;
  font-family: "Segoe UI", Arial, sans-serif;
  cursor: move;
  user-select: none;
  padding: 2px 4px;
  border-radius: 4px;
}
.sticker-sheet-label:hover { background: #f4f0fa; color: var(--ws-purple); }
.sticker-grid {
  display: grid;
  grid-template-columns: repeat(3, 25mm);
  gap: 4mm;
}
.sticker-slot {
  width: 25mm;
  height: 25mm;
  border-radius: 50%;
  border: 2px dashed var(--ws-purple);
  background: #f4f0fa;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.sticker-slot img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 50%;
  background: white;
}
.sticker-slot-num {
  font-size: 11px;
  color: var(--ws-purple);
  font-weight: 600;
}
.sticker-upload.upload-btn {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0);
  color: var(--ws-purple);
  font-size: 15px;
}
.edit-mode .sticker-upload.upload-btn { display: flex; }
.sticker-upload.upload-btn:hover { background: rgba(138, 107, 168, 0.18); }

.spread {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  background: #cfd4dc;
  padding: 6px;
  border-radius: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  transform: scale(calc(var(--page-zoom) * var(--calibration)));
  transform-origin: top center;
  flex: none;
  position: relative;
}

/* Real A4 sheet: 210×297mm at CSS-reference 96dpi, so proportions between page
   size and font size (set in pt below) are print-accurate regardless of
   --page-zoom, which only scales the on-screen view for comfort. */
.page {
  width: 210mm;
  height: 297mm;
  background: var(--page-bg);
  padding: 18mm 16mm;
  position: relative;
  /* Establishes its own stacking context so negative-z-index children (the
     full-bleed cover, "behind text" free images) paint above THIS box's own
     white background instead of escaping to an ancestor and disappearing
     behind it — without this, z-index:-1 descendants render invisible. */
  z-index: 0;
  font-family: "Outfit", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  flex-shrink: 0;
}

/* Inner (spine-side) margin: keeps text 10mm clear of the spread centre —
   3mm past the 7mm gutter danger zone marked by .spine-guide below. */
.page-left { padding-right: 10mm; }
.page-right { padding-left: 10mm; }

/* Print reference guides — gutter zone, text-fit boundary. Hidden by
   default: the page as shown is the real deliverable (full 210×297mm,
   entirely available for text and artwork), not narrowed down to whatever's
   inside these marks. Toggle "Показать технические границы" reveals them
   for margin/fit checks without changing anything about the actual page or
   what can be placed on it. */
.spine-guide,
.overflow-marker {
  display: none;
}
.show-guides .spine-guide,
.show-guides .overflow-marker {
  display: block;
}

/* Gutter / binding danger zone: ±7mm from the middle of the spread, where
   the book falls into the spine and artwork/text can get lost in the fold. */
.spine-guide {
  position: absolute;
  top: 0;
  height: 297mm;
  left: 50%;
  width: 14mm;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 5;
  background: repeating-linear-gradient(
    45deg,
    rgba(207, 91, 78, 0.08),
    rgba(207, 91, 78, 0.08) 4px,
    rgba(207, 91, 78, 0.14) 4px,
    rgba(207, 91, 78, 0.14) 8px
  );
}
.spine-guide::before,
.spine-guide::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 0;
  border-left: 2px dashed var(--danger);
}
.spine-guide::before { left: 0; }
.spine-guide::after { right: 0; }

/* Tool-only caption bar — lives in .page-wrap, ABOVE .page, not inside it.
   It used to sit inside .page with a sticky/negative-margin bleed hack,
   which also meant .page-content's height had to guess the caption's
   rendered height. Moving it out entirely removes that guesswork. */
.page-caption {
  width: 210mm;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 4px 2px 6px;
  font-size: 11px;
  color: var(--muted);
  font-family: "Segoe UI", Arial, sans-serif;
}

.howto-toggle {
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid #b7bcc6;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  cursor: default;
}
.edit-mode .howto-toggle { cursor: pointer; }
.edit-mode .howto-toggle:hover { border-color: var(--ws-orange); color: var(--ws-orange); }
.howto-toggle.active {
  background: var(--ws-orange);
  border-color: var(--ws-orange);
  color: white;
}

.copy-text-btn {
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid #b7bcc6;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.copy-text-btn:hover { border-color: var(--ws-navy); color: var(--ws-navy); }
.copy-text-btn:disabled { border-color: var(--ok); color: var(--ok); cursor: default; }

/* Fixed to the EXACT printable height: 297mm page minus its own 18mm top +
   18mm bottom padding = 261mm. No estimate involved — the caption above no
   longer lives inside .page, so there's nothing left to guess the size of.
   Content overflowing this height visibly spills past it (not clipped) —
   that's the "does this text actually fit" signal the tool exists for. */
.page-content {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: calc(297mm - 36mm);
  overflow: visible;
}

.overflow-marker {
  position: absolute;
  top: 100%;
  left: -16mm;
  right: -16mm;
  border-top: 2px dashed var(--danger);
  height: 0;
}
.page-left .overflow-marker { right: -10mm; }
.page-right .overflow-marker { left: -10mm; }
.overflow-marker::after {
  content: "печатная область — 261мм от начала страницы — ниже уходит в поле";
  position: absolute;
  right: 0;
  top: 3px;
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 10px;
  color: var(--danger);
  background: white;
  padding: 1px 5px;
  border-radius: 3px;
}
.page-overflowing .fill-badge { background: var(--danger) !important; }

.fill-badge {
  padding: 2px 9px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 11px;
  color: white;
}
.fill-ok { background: var(--ok); }
.fill-warn { background: var(--warn); }
.fill-over { background: var(--danger); }
.fill-empty { background: #b7bcc6; }

.block {
  font-size: var(--page-font-size);
  line-height: var(--page-line-height);
  font-weight: var(--page-font-weight);
}

.block-heading {
  font-weight: 700;
  font-size: calc(var(--page-font-size) + 2pt);
  color: var(--ws-navy);
  border-left: 4px solid var(--ws-orange);
  padding-left: 8px;
  margin-top: 4px;
  line-height: var(--page-line-height);
}

.block-instruction {
  font-style: italic;
  color: #555;
}

.block-paragraph {
  text-align: justify;
}

.block-list ol, .block-list ul {
  margin: 4px 0;
  padding-left: 20px;
}
.block-list li { margin-bottom: 4px; }

.block-wordbank {
  background: #f4f0fa;
  border: 1px dashed var(--ws-purple);
  border-radius: 6px;
  padding: 8px 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.block-wordbank .label {
  width: 100%;
  font-weight: 600;
  font-size: 11px;
  color: var(--ws-purple);
  text-transform: uppercase;
  margin-bottom: 2px;
}
.block-wordbank .chip {
  background: white;
  border: 1px solid #ddd0ee;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
}

.block-dialogue { display: flex; flex-direction: column; gap: 6px; }
.block-dialogue .line {
  background: #eef2fb;
  border-radius: 10px;
  padding: 6px 10px;
}
.block-dialogue .speaker {
  font-weight: 700;
  color: var(--ws-navy);
  margin-right: 4px;
}

.block-answerkey {
  background: #eef7ee;
  border: 1px solid #cfe6cf;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  color: #3d6b3d;
}
.block-answerkey .label {
  font-weight: 700;
  text-transform: uppercase;
  font-size: 10px;
  display: block;
  margin-bottom: 3px;
}

.block-note {
  color: var(--muted);
  font-size: 12px;
  background: #f6f2e4;
  border-left: 3px solid var(--warn);
  padding: 4px 8px;
}

/* Comment feed — deliberately lives OUTSIDE .page (below the printed
   210×297mm sheet), so it's unambiguous it's a tool-only discussion thread
   and never part of the book: nothing here is ever added to the printable
   content. */
.page-wrap {
  display: flex;
  flex-direction: column;
  flex: none;
}
.page-notes {
  width: 210mm;
  margin-top: 8px;
  background: #fffbe8;
  border: 1px dashed var(--warn);
  border-radius: 6px;
  padding: 6px 10px 8px;
  font-size: 11.5px;
  color: #6b5a1f;
}
.page-notes-label {
  font-weight: 700;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.02em;
  margin-bottom: 3px;
  opacity: 0.8;
}
.comment-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 6px;
}
.comment-item {
  background: rgba(255,255,255,0.6);
  border-radius: 5px;
  padding: 5px 8px;
}
.comment-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}
.comment-author {
  font-weight: 700;
  color: var(--ws-navy);
  font-size: 11px;
}
.comment-time {
  font-size: 10px;
  color: #a89a5c;
}
.comment-delete {
  margin-left: auto;
  border: none;
  background: transparent;
  color: #a89a5c;
  cursor: pointer;
  font-size: 11px;
  padding: 0 2px;
  border-radius: 3px;
}
.comment-delete:hover { color: var(--danger); background: rgba(207,91,78,0.12); }
.comment-text {
  white-space: pre-wrap;
  line-height: 1.4;
}
.comment-add-row {
  display: flex;
  gap: 6px;
  align-items: flex-end;
}
.comment-input {
  flex: 1;
  resize: vertical;
  font-family: inherit;
  font-size: 11.5px;
  padding: 5px 7px;
  border-radius: 5px;
  border: 1px solid #e0d4a0;
  background: rgba(255,255,255,0.7);
}
.comment-add-btn {
  padding: 5px 12px;
  border-radius: 5px;
  border: 1px solid var(--warn);
  background: white;
  color: #6b5a1f;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.comment-add-btn:hover { background: var(--warn); color: white; }

.page-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
  border: 2px dashed #dcdfe5;
  border-radius: 8px;
  min-height: 200px;
}

.wordcount {
  font-variant-numeric: tabular-nums;
}

/* --- Title / cover page ---
   The illustration is printed on the FULL physical 210×297mm sheet — it
   bleeds past the page's own padding, past the spine-safety margin, right
   into the gutter danger zone, exactly like a real book cover would. It's
   positioned directly on .page (not inside a padded wrapper) with inset:0,
   which — per CSS's containing-block rules for absolutely positioned
   elements — resolves against the padding box's outer edge, i.e. true
   edge-to-edge fill, ignoring .page's padding entirely.
   object-fit:cover so the artwork always fills all 210×297mm with no gaps —
   if the uploaded file's own aspect ratio isn't exactly A4, the excess is
   cropped (evenly, from the centre) rather than left as blank margin. */
.title-cover-bleed {
  position: absolute;
  inset: 0;
  z-index: -1;
  background: #cfd4dc;
  overflow: hidden;
}
.title-cover-bleed img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}
.title-cover-bleed .cover-placeholder {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: #565e6c;
  font-size: 12px;
  text-align: center;
  padding: 12px;
}
.title-cover-bleed .cover-placeholder .icon { font-size: 30px; }
.title-cover-bleed .cover-reupload {
  position: absolute;
  z-index: 1;
  bottom: 10mm;
  right: 10mm;
}

/* Normal-flow text band, painted on top of the (negative z-index) cover
   without any extra positioning — it inherits .page's own padding, so it
   automatically respects the spine-safety margin already set up there. */
.title-overlay-text {
  position: relative;
  padding: 6px 0 10px;
  background: linear-gradient(to bottom, rgba(255,255,255,0.5) 70%, rgba(255,255,255,0));
}

/* "+ Название юнита" — a constructor-addable block, preset to bold 40pt on
   creation (adjustable afterwards like any block via the typography panel);
   not auto-inserted anywhere, unlike the old fixed unit-name field. */
.block-unittitle {
  text-align: center;
  color: var(--ws-navy);
}

/* --- Free-position image blocks (drag to move, handle to resize) --- */
.free-image {
  position: absolute;
  border-radius: 4px;
  /* No overflow:hidden here on purpose — the size label / toolbar / close
     button below are deliberately positioned just outside the box edges
     (so they don't cover the image itself), and clipping would hide them. */
}

/* Prepress handoff — copy data-URL / download file — shown on hover over
   any uploaded illustration (free images, cover). Lives INSIDE the image's
   own bounds (bottom edge), unlike the edit-mode chrome which lives outside
   it, so the two never collide. */
.image-hover-actions {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 4px;
  background: rgba(0, 0, 0, 0.6);
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
  z-index: 2;
}
.free-image:hover .image-hover-actions,
.title-cover-bleed:hover .image-hover-actions {
  opacity: 1;
  pointer-events: auto;
}
.image-hover-actions button {
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.12);
  color: white;
  font-size: 10px;
  cursor: pointer;
  white-space: nowrap;
}
.image-hover-actions button:hover { background: rgba(255, 255, 255, 0.28); }
.free-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 4px;
  pointer-events: none;
}
.free-image-placeholder {
  width: 100%;
  height: 100%;
  border: 2px dashed var(--ws-green);
  background: #f4f8f2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-align: center;
  color: #4b6a45;
  font-size: 11px;
  padding: 6px;
}
.free-image-placeholder .icon { font-size: 20px; }

.free-image.editing {
  outline: 2px dashed var(--ws-orange);
  cursor: move;
}
.free-image-size {
  display: none;
  position: absolute;
  top: -20px;
  left: 0;
  background: var(--ws-navy);
  color: white;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
}
.free-image.editing .free-image-size { display: block; }

.free-image-toolbar {
  display: none;
  position: absolute;
  bottom: -26px;
  left: 0;
  gap: 4px;
}
.free-image.editing .free-image-toolbar { display: flex; }
.free-image-toolbar button,
.free-image-toolbar .upload-btn {
  font-size: 10px;
  padding: 2px 7px;
  white-space: nowrap;
}
.free-image-toolbar button {
  border-radius: 999px;
  border: 1px solid #d7dbe2;
  background: white;
  color: var(--muted);
  cursor: pointer;
}
.free-image-toolbar button:hover { color: var(--ink); border-color: var(--ws-navy); }

.free-image-resize-handle {
  display: none;
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 14px;
  height: 14px;
  line-height: 14px;
  font-size: 10px;
  text-align: center;
  background: var(--ws-orange);
  color: white;
  border-radius: 3px;
  cursor: nwse-resize;
}
.free-image.editing .free-image-resize-handle { display: block; }

/* Always inside the box bounds (not clipped, not dependent on overflow) so
   deleting an image block is always reachable regardless of drag position. */
.free-image-close {
  display: none;
  position: absolute;
  top: 3px;
  right: 3px;
  width: 18px;
  height: 18px;
  line-height: 16px;
  text-align: center;
  font-size: 13px;
  border-radius: 50%;
  border: none;
  background: rgba(207, 91, 78, 0.9);
  color: white;
  cursor: pointer;
}
.free-image-close:hover { background: var(--danger); }
.free-image.editing .free-image-close { display: block; }

.upload-btn {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--ws-green);
  background: white;
  color: #4b6a45;
  font-size: 12px;
  cursor: pointer;
}
.upload-btn:hover { background: #eaf3e6; }

.cover-reupload {
  position: absolute;
  bottom: 8px;
  right: 8px;
}

/* --- Edit mode --- */
.editable {
  outline: 1px dashed transparent;
  border-radius: 4px;
  padding: 1px 3px;
  margin: -1px -3px;
  /* Preserve exactly what was typed — multiple spaces, blank lines — instead
     of the browser collapsing runs of whitespace when rendering normally. */
  white-space: pre-wrap;
}
.edit-mode .editable {
  outline-color: #c9cede;
  cursor: text;
}
.edit-mode .editable:focus {
  outline: 1px solid var(--ws-orange);
  background: #fff8f2;
}
/* Stays highlighted after blur (e.g. while the author fiddles with the
   typography sliders, which steals focus away from the text itself) —
   cleared only when a different block is picked or the page re-renders. */
.edit-mode .editable.typography-selected {
  outline: 1px solid var(--ws-orange);
  background: #fff8f2;
}

.block-row {
  position: relative;
  display: flex;
  gap: 4px;
  align-items: flex-start;
}
.block-row > .block { flex: 1; min-width: 0; }

.block-controls {
  display: none;
  flex-direction: column;
  gap: 2px;
}
.edit-mode .block-controls { display: flex; }
.block-controls button {
  width: 20px;
  height: 20px;
  line-height: 1;
  font-size: 11px;
  border: 1px solid #d7dbe2;
  background: white;
  border-radius: 4px;
  cursor: pointer;
  color: var(--muted);
}
.block-controls button:hover { color: var(--ink); border-color: var(--ws-navy); }
.block-controls .btn-delete:hover { color: white; background: var(--danger); border-color: var(--danger); }

/* Constructor menu — lives in the technical margin below .page (between the
   printed sheet and the comment feed), same width/footprint as .page-notes,
   so it reads as tool chrome rather than something competing with page
   content for space. Only shown in edit mode. */
.add-block-bar {
  display: none;
  width: 210mm;
  margin-top: 8px;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  background: #eef1f6;
  border: 1px dashed var(--ws-navy);
  border-radius: 6px;
  padding: 8px 10px;
}
.edit-mode .add-block-bar { display: flex; }
.add-block-bar::before {
  content: "Добавить:";
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--ws-navy);
  opacity: 0.7;
  margin-right: 2px;
}
.add-block-bar button {
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px dashed var(--ws-navy);
  background: white;
  color: var(--ws-navy);
  font-size: 11px;
  cursor: pointer;
}
.add-block-bar button:hover { background: #dfe6f0; }
.add-block-bar select {
  padding: 3px 6px;
  border-radius: 999px;
  border: 1px solid var(--ws-navy);
  color: var(--ws-navy);
  font-size: 11px;
}

/* Word count for reading-passage text (paragraph blocks) specifically —
   distinct from the page's overall word-based fill badge, which also counts
   headings/instructions/lists and isn't a proxy for "how long is the text". */
.paragraph-wordcount {
  display: inline-block;
  margin-top: 3px;
  font-size: 10px;
  color: var(--muted);
  font-style: normal;
}
