/* ==========================================================================
   THE PARCHMENT — HANDWRITING COPYWORK STYLESHEET (css/handwriting.css)
   Centered Workspace, Drag-Select Popover Grid, Safe Margins, Exact 1:1 Print
   ========================================================================== */

/* ==========================================================================
   1. POPOVER VERSE GRID & RANGE SELECTION STYLING (Matches fill-in-the-blank.css)
   ========================================================================== */
.verse-grid {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.verse-grid-cell.in-range {
  background: rgba(184, 124, 36, 0.22) !important;
  color: var(--ui-accent-strong, #8c531b) !important;
  border-color: var(--ui-accent, #b87c24) !important;
}

.verse-grid-cell.range-bound {
  background: var(--ui-accent) !important;
  color: #ffffff !important;
  font-weight: 700;
  box-shadow: 0 0 6px rgba(184, 124, 36, 0.45);
}

.verse-grid-action-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--ui-line);
}

.grid-selection-preview {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.grid-selection-preview .preview-label {
  font-family: var(--font-ui, sans-serif);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ui-muted);
}

.grid-selection-preview .preview-ref {
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ui-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.grid-open-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 14px;
  font-family: var(--font-ui, sans-serif);
  font-size: 0.78rem;
  font-weight: 700;
  border-radius: 9999px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 130ms ease;
  touch-action: manipulation;
  background: var(--ui-accent, #b87c24);
  color: #ffffff;
  border: 1px solid var(--ui-accent-strong, #8c531b);
}

.grid-open-btn:hover {
  background: var(--ui-accent-strong, #8c531b);
}

/* ==========================================================================
   2. CENTERED WORKSPACE LAYOUT (Desk + Wider Sidebar)
   ========================================================================== */
.handwriting-workspace-layout {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 24px;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
  padding: 0 16px 2.5rem 16px;
}

.handwriting-preview-desk {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
  box-sizing: border-box;
}

/* Wider Sidebar Deck: 350px width for spacious controls */
.handwriting-sidebar-deck {
  flex: 0 0 350px;
  width: 350px;
  position: sticky;
  top: 16px;
  box-sizing: border-box;
}

.sidebar-deck-card {
  background: var(--ui-surface) !important;
  border: 1px solid var(--ui-line) !important;
  border-radius: 1.25rem !important;
  padding: 16px 20px !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05) !important;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sidebar-action-header {
  width: 100%;
  border-bottom: 1px solid var(--ui-line);
  padding-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-controls-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-control-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.label-with-val {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.control-label {
  font-family: var(--font-ui, sans-serif);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ui-muted);
}

.slider-val-indicator {
  font-family: var(--font-ui, sans-serif);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ui-accent-strong);
}

/* Segmented Buttons */
.seg-controls {
  display: inline-flex;
  align-items: center;
  background: var(--ui-surface-2);
  padding: 3px;
  border-radius: 9999px;
  border: 1px solid var(--ui-line);
  gap: 2px;
  width: 100%;
  box-sizing: border-box;
}

.seg-btn {
  flex: 1 1 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 5px 8px;
  font-family: var(--font-ui, sans-serif);
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--ui-muted);
  border-radius: 9999px;
  border: none;
  background: transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: all 130ms ease;
  touch-action: manipulation;
}

.seg-btn:hover { color: var(--ui-ink); }
.seg-btn.active {
  background: var(--ui-surface);
  color: var(--ui-ink);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.ruling-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-school { background: linear-gradient(135deg, #2563eb 50%, #dc2626 50%); }
.dot-bw { background: #111827; }

/* Sliders & Controls */
.slider-control-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--ui-surface-2);
  padding: 4px 12px;
  border-radius: 9999px;
  border: 1px solid var(--ui-line);
  width: 100%;
  box-sizing: border-box;
}

/* Tracing Tone Pill: Solid fits comfortably inside */
.trace-shade-wrap {
  padding: 3px 6px;
  gap: 6px;
}

.slider-caption {
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ui-muted);
}
.slider-caption.lg { font-size: 1.15rem; }

.hw-range-slider {
  -webkit-appearance: none;
  appearance: none;
  flex: 1 1 auto;
  min-width: 0;
  height: 4px;
  background: var(--ui-line);
  border-radius: 9999px;
  outline: none;
  cursor: pointer;
}
.hw-range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--ui-accent);
  cursor: pointer;
  transition: transform 120ms ease;
}
.hw-range-slider::-webkit-slider-thumb:hover { transform: scale(1.2); }

.btn-micro-tone {
  background: transparent;
  border: none;
  font-family: var(--font-ui, sans-serif);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ui-muted);
  cursor: pointer;
  padding: 3px 8px;
  border-radius: 9999px;
  transition: all 120ms ease;
  flex-shrink: 0;
  white-space: nowrap;
  line-height: 1.2;
}
.btn-micro-tone:hover { color: var(--ui-ink); }
.btn-micro-tone.active {
  background: var(--ui-surface);
  color: var(--ui-accent-strong);
  font-weight: 800;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.binding-toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-ui, sans-serif);
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--ui-ink);
  cursor: pointer;
  user-select: none;
  padding: 2px 0;
}
.hw-checkbox {
  accent-color: var(--ui-accent);
  cursor: pointer;
  width: 15px;
  height: 15px;
}

/* Primary Gilded Print Button */
.hw-print-btn {
  appearance: none;
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(135deg, #b87c24 0%, #8c531b 100%);
  color: #ffffff !important;
  border: 1px solid #784511;
  border-radius: 9999px;
  padding: 9px 18px;
  font-family: var(--font-ui, sans-serif);
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 140ms ease;
  box-shadow: 0 2px 8px rgba(184, 124, 36, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  white-space: nowrap;
  touch-action: manipulation;
}
.hw-print-btn:hover {
  background: linear-gradient(135deg, #c98829 0%, #9e601f 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(184, 124, 36, 0.4);
}
.hw-print-btn:active { transform: translateY(0); }
.hw-print-btn svg { flex-shrink: 0; stroke: #ffffff; }

/* Clear Verses Secondary Button */
.hw-clear-btn {
  appearance: none;
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--ui-surface);
  border: 1px solid var(--ui-line);
  border-radius: 9999px;
  padding: 7px 14px;
  font-family: var(--font-ui, sans-serif);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 130ms ease;
  color: #b92b27;
  box-sizing: border-box;
}
.hw-clear-btn:hover {
  background: rgba(185, 43, 39, 0.08);
  border-color: #b92b27;
  transform: translateY(-1px);
}
.hw-clear-btn svg { flex-shrink: 0; stroke: currentColor; }

/* ==========================================================================
   3. PAPER SHEETS & SCREEN VIEW
   ========================================================================== */
.handwriting-sheet-paper {
  background: #ffffff !important;
  color: #111827 !important;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12), 0 1px 3px rgba(0, 0, 0, 0.05);
  border: 1px solid #e5e7eb;
  border-radius: 2px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  position: relative;
  padding: 0.5in !important;
  transition: width 0.2s ease, padding 0.2s ease;
}

.handwriting-sheet-paper[data-orientation="portrait"] {
  width: 8.5in;
  height: 11in;
  min-height: 11in;
}

.handwriting-sheet-paper[data-orientation="landscape"] {
  width: 11in;
  height: 8.5in;
  min-height: 8.5in;
}

/* Orientation-Aware 0.75" Binding Margin */
.handwriting-sheet-paper[data-orientation="portrait"].has-binding-margin {
  padding-left: 0.75in !important;
  padding-top: 0.5in !important;
}

.handwriting-sheet-paper[data-orientation="landscape"].has-binding-margin {
  padding-top: 0.75in !important;
  padding-left: 0.5in !important;
}

/* Screen-Only Dashed Binding Guide Line */
.handwriting-sheet-paper[data-orientation="portrait"].has-binding-margin::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0.75in;
  width: 1px;
  border-left: 1px dashed #cbd5e1;
  pointer-events: none;
}

.handwriting-sheet-paper[data-orientation="landscape"].has-binding-margin::before {
  content: "";
  position: absolute;
  top: 0.75in;
  left: 0;
  right: 0;
  height: 1px;
  border-top: 1px dashed #cbd5e1;
  pointer-events: none;
}

/* Screen-Only 3-Hole Punch Markers */
.handwriting-sheet-paper .hole-punch-guide {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1.5px dashed #94a3b8;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.handwriting-sheet-paper[data-orientation="portrait"].has-binding-margin .hole-punch-guide {
  left: 0.36in;
}
.handwriting-sheet-paper[data-orientation="portrait"] .hole-punch-top { top: 1.25in; }
.handwriting-sheet-paper[data-orientation="portrait"] .hole-punch-mid { top: 5.5in; }
.handwriting-sheet-paper[data-orientation="portrait"] .hole-punch-bot { top: 9.75in; }

.handwriting-sheet-paper[data-orientation="landscape"].has-binding-margin .hole-punch-guide {
  top: 0.36in;
}
.handwriting-sheet-paper[data-orientation="landscape"] .hole-punch-top { left: 1.5in; }
.handwriting-sheet-paper[data-orientation="landscape"] .hole-punch-mid { left: 5.5in; }
.handwriting-sheet-paper[data-orientation="landscape"] .hole-punch-bot { left: 9.5in; }

/* Clean Model Card (Quote with Inline Reference) */
.verse-model-card {
  flex: 0 0 auto;
  border: none !important;
  box-shadow: none !important;
  background: transparent !important;
  padding: 4px 0 14px 0 !important;
  margin: 0 0 6px 0 !important;
  text-align: center;
}

.model-verse-text {
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 1.35rem;
  line-height: 1.5;
  color: #111827;
  margin: 0;
}

.model-verse-cite {
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 1.15rem;
  font-style: normal;
  font-weight: 700;
  color: #374151;
  white-space: nowrap;
  margin-left: 8px;
}

/* SVG Line Canvas */
.sheet-lines-canvas {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  width: 100%;
}

.hw-svg-row {
  width: 100%;
  height: auto !important;
  display: block;
  overflow: visible;
}

/* Guidelines */
.hw-svg-row.ruling-school .guide-headline {
  stroke: #2563eb;
  stroke-width: 1.25;
}
.hw-svg-row.ruling-school .guide-midline {
  stroke: #60a5fa;
  stroke-width: 1.25;
  stroke-dasharray: 6, 5;
}
.hw-svg-row.ruling-school .guide-baseline {
  stroke: #dc2626;
  stroke-width: 1.75;
}

.hw-svg-row.ruling-bw .guide-headline {
  stroke: #4b5563;
  stroke-width: 1;
}
.hw-svg-row.ruling-bw .guide-midline {
  stroke: #9ca3af;
  stroke-width: 1.2;
  stroke-dasharray: 6, 5;
}
.hw-svg-row.ruling-bw .guide-baseline {
  stroke: #111827;
  stroke-width: 1.6;
}

/* Ruled Single-Line Styling */
.hw-svg-row.style-ruled.ruling-school .guide-baseline {
  stroke: #2563eb;
  stroke-width: 1.5;
}
.hw-svg-row.style-ruled.ruling-bw .guide-baseline {
  stroke: #111827;
  stroke-width: 1.5;
}

/* ==========================================================================
   4. RESPONSIVE BREAKPOINTS (Wider sidebar wrapping)
   ========================================================================== */
@media (max-width: 1220px) {
  .handwriting-workspace-layout {
    flex-direction: column;
    align-items: center;
  }

  .handwriting-sidebar-deck {
    width: 100%;
    max-width: 600px;
    position: static;
    order: -1;
  }

  .sidebar-controls-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 10px;
  }
}

@media (max-width: 768px) {
  .sidebar-controls-list {
    grid-template-columns: 1fr;
  }

  .handwriting-sheet-paper[data-orientation="portrait"],
  .handwriting-sheet-paper[data-orientation="landscape"] {
    width: 100% !important;
    max-width: 100% !important;
    min-height: unset !important;
    height: auto !important;
    padding: 14px 10px !important;
  }

  .handwriting-sheet-paper.has-binding-margin {
    padding-left: 18px !important;
  }
}

/* ==========================================================================
   5. STRICT 1:1 PRINT ENGINE (Identical to Screen, Zero Offsets)
   ========================================================================== */
@media print {
  @page {
    size: letter portrait;
    margin: 0;
  }

  /* 1. Completely remove all non-worksheet chrome from flow */
  .no-print,
  header,
  footer,
  .site-header,
  .site-footer,
  .passage-header-strip,
  .handwriting-sidebar-deck,
  #toastHost,
  .cookie-banner,
  #cookieConsent {
    display: none !important;
  }

  /* 2. Reset html, body, and all wrappers so printable container starts at (0, 0) */
  html, body {
    width: 100% !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    overflow: visible !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  main,
  .editorial-main,
  .scribe-main,
  .workspace-column,
  .handwriting-workspace-layout {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    width: 100% !important;
    max-width: none !important;
    min-height: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
    position: static !important;
    transform: none !important;
  }

  #worksheetPagesContainer {
    display: block !important;
    position: static !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    box-shadow: none !important;
    gap: 0 !important;
  }

  /* 3. Paper layout: exact 1:1 match with screen dimensions */
  .handwriting-sheet-paper {
    box-sizing: border-box !important;
    position: relative !important;
    margin: 0 !important;
    border: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    background: #ffffff !important;
    overflow: hidden !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  .handwriting-sheet-paper[data-orientation="portrait"] {
    width: 8.5in !important;
    height: 11in !important;
    max-height: 11in !important;
    padding: 0.5in !important;
  }

  .handwriting-sheet-paper[data-orientation="landscape"] {
    width: 11in !important;
    height: 8.5in !important;
    max-height: 8.5in !important;
    padding: 0.5in !important;
  }

  .handwriting-sheet-paper[data-orientation="portrait"].has-binding-margin {
    padding-left: 0.75in !important;
    padding-top: 0.5in !important;
  }

  .handwriting-sheet-paper[data-orientation="landscape"].has-binding-margin {
    padding-top: 0.75in !important;
    padding-left: 0.5in !important;
  }

  /* Page breaks only between legitimate multi-page sheets */
  .handwriting-sheet-paper:not(:last-child) {
    page-break-after: always !important;
    break-after: page !important;
  }

  .handwriting-sheet-paper:last-child {
    page-break-after: auto !important;
    break-after: auto !important;
  }

  /* Suppress screen-only margin guidelines and hole punches on the physical print */
  .handwriting-sheet-paper::before,
  .handwriting-sheet-paper::after,
  .hole-punch-guide {
    display: none !important;
    content: none !important;
    border: none !important;
  }
}