/* Editor-specific styles (theme utilities are in tailwind/application.css) */

/* ===== Busy Cursor (non-blocking loading indicator) ===== */
html.busy-cursor,
html.busy-cursor *,
html.busy-cursor canvas {
  cursor: progress !important;
}

/* ===== Global Selection Highlight ===== */
::selection {
  background: color-mix(in srgb, var(--color-accent, #7c3aed) 25%, transparent);
  color: inherit;
}

/* ===== Global Thin Scrollbars ===== */
* {
  scrollbar-width: thin !important;
  scrollbar-color: color-mix(in srgb, var(--color-text-muted) 30%, transparent) transparent !important;
}
*::-webkit-scrollbar {
  width: 6px !important;
  height: 6px !important;
}
*::-webkit-scrollbar-track {
  background: transparent !important;
}
*::-webkit-scrollbar-thumb {
  background-color: color-mix(in srgb, var(--color-text-muted) 30%, transparent) !important;
  border-radius: 3px !important;
}
*::-webkit-scrollbar-thumb:hover {
  background-color: var(--color-text-muted) !important;
}

/* Search input placeholder hiding on focus */
.search-input:focus::placeholder {
  color: transparent;
}

/* ===== Stitch Chart Styles ===== */

.stitch-chart {
  margin: 0.5rem 0;
  border-radius: 0.5rem;
  overflow: hidden;
  page-break-after: avoid;
}

.stitch-chart__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}

.stitch-chart__content {
  overflow-x: auto;
}

.stitch-chart--collapsed .stitch-chart__content {
  display: none;
}

/* Chart grid */
.chart-grid {
  border-collapse: collapse;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.chart-grid td,
.chart-grid th {
  text-align: center;
  vertical-align: middle;
  border: 1px solid var(--color-border);
  padding: 0;
  box-sizing: border-box;
}

.chart-grid:not(.painting) td[data-row]:hover {
  box-shadow: inset 0 0 0 2px var(--color-accent);
  cursor: pointer;
}

.chart-grid td.selected {
  box-shadow: inset 0 0 0 2px var(--color-accent);
}

/* Row and stitch numbers */
.chart-row-number,
.chart-stitch-number {
  font-weight: normal;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  border: none !important;
  background: transparent !important;
}

.chart-row-number {
  width: 24px;
  min-width: 24px;
  padding: 0 2px !important;
}

/* Stitch chart cell backgrounds */
.chart-cell--stitch {
  background-color: #ffffff;
  color: #1f2937;
}

.chart-cell--clear {
  background-color: var(--color-surface, #ffffff);
}

.chart-cell--no-stitch {
  background-color: #f5f5f4;
}

/* Overlay dimension inputs */
.chart-overlay-input:focus {
  outline: none;
  border-color: var(--color-accent);
}

/* Chart legend */
.chart-legend {
  margin-top: 0.5rem;
  padding-top: 0;
  border-top: none;
}

.chart-legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.5rem;
  border-radius: 0.375rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: border-color 0.1s;
}

.chart-legend-item--row {
  justify-content: flex-start;
  white-space: nowrap;
}

.chart-legend-item--active {
  border-color: var(--color-accent);
}

/* Chart overlay select dropdowns */
.chart-overlay-select {
  font-size: 0.75rem;
  padding: 0.2rem 1.4rem 0.2rem 0.4rem;
  border: 1px solid var(--color-border);
  border-radius: 0.25rem;
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
  outline: none;
  width: 110px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23a8a29e' stroke-width='1.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.4rem center;
}

.chart-overlay-select:focus {
  border-color: var(--color-accent);
}

/* Chart instructions checkbox */
.chart-instructions-checkbox {
  accent-color: var(--color-accent);
  width: 0.75rem;
  height: 0.75rem;
  cursor: pointer;
}

.chart-legend-symbol {
  width: 1.5rem;
  height: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border);
  background: #ffffff;
  color: #1f2937;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.875rem;
}

/* Color picker input: fill the swatch to the full element size */
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 3px; }
input[type="color"]::-moz-color-swatch { border: none; border-radius: 3px; }

/* Chart symbol colors for colorwork */
.chart-cell--mc { background-color: #ffffff; }
.chart-cell--cc1 { background-color: #374151; color: #ffffff; }
.chart-cell--cc2 { background-color: #dc2626; color: #ffffff; }
.chart-cell--cc3 { background-color: #2563eb; color: #ffffff; }
.chart-cell--cc4 { background-color: #059669; color: #ffffff; }

/* Colorwork palette swatches: no border, rounded */
.chart-legend-symbol[class*="chart-cell--cc"],
.chart-legend-symbol.chart-cell--mc {
  border: none;
  border-radius: 0.375rem;
}
.chart-legend-symbol.chart-cell--mc {
  border: 1px solid rgba(0, 0, 0, 0.1);
}

/* Repeat section highlighting */
.chart-cell--repeat-start {
  border-left: 3px solid var(--color-accent) !important;
}

.chart-cell--repeat-end {
  border-right: 3px solid var(--color-accent) !important;
}

.chart-cell--repeat {
  background-color: color-mix(in srgb, var(--color-accent) 10%, transparent);
}

/* Chart grid wrapper */
.chart-grid-wrapper {
  display: inline-block;
}

/* Stitch Chart - Clean Grid Design */
.stitch-chart-clean {
  border: none !important;
  border-radius: 0 !important;
  background: transparent !important;
  overflow: visible !important;
  position: relative;
}

.stitch-chart-clean .stitch-chart__header {
  display: none;
}

.stitch-chart-clean.show-header .stitch-chart__header {
  display: flex;
  background: transparent;
  border: none;
  padding: 0.5rem 0;
  margin-bottom: 0.5rem;
}

.stitch-chart-clean .stitch-chart__header .chart-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
}

.stitch-chart-clean .stitch-chart__content {
  background: transparent !important;
  padding: 0 !important;
}

.stitch-chart-clean .chart-grid td,
.stitch-chart-clean .chart-cell {
  border: 1px solid var(--color-border, #d1d5db);
  background-color: var(--color-surface, white);
}

.stitch-chart-clean .chart-grid td:hover,
.stitch-chart-clean .chart-cell:hover {
  background-color: color-mix(in srgb, var(--color-accent) 10%, transparent);
}

.stitch-chart-clean .chart-row-number,
.stitch-chart-clean .chart-stitch-number {
  color: var(--color-text-muted, #6b7280);
  font-size: 0.75rem;
  font-weight: normal;
  background: transparent !important;
  border: none !important;
}

.stitch-chart-clean .stitch-chart-edit-btn {
  position: absolute;
  top: -0.5rem;
  right: -0.5rem;
  opacity: 0;
  transition: opacity 0.2s ease;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0.25rem;
  color: var(--color-text);
  cursor: pointer;
  z-index: 10;
}

.stitch-chart-clean:hover .stitch-chart-edit-btn {
  opacity: 1;
}

.stitch-chart-clean .stitch-chart-edit-btn:hover {
  background-color: var(--color-bg);
}

.stitch-chart-clean .chart-legend {
  margin-top: 0.5rem;
  padding-top: 0;
  border-top: none;
}

.stitch-chart-clean .chart-legend-symbol {
  border-color: var(--color-border, #d1d5db);
}

/* ===== Chart Document Output Styles ===== */

.chart-document {
  color: var(--color-text, #1a1a1a);
  font-family: inherit;
  max-width: 100%;
  page-break-inside: avoid;
  margin: 1rem 0;
}

.chart-document h3 {
  font-size: 1.1em;
  font-weight: 600;
  margin: 0 0 0.5em 0;
  color: var(--color-text, #1a1a1a);
}

.chart-document h4 {
  font-size: 0.95em;
  font-weight: 600;
  margin: 0.75em 0 0.25em 0;
  color: var(--color-text, #1a1a1a);
}

.chart-document p {
  margin: 0 0 0.5em 0;
  font-size: 0.9em;
  line-height: 1.4;
  color: var(--color-text, #333);
}

.chart-document table {
  border-collapse: collapse;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  margin: 0;
}

.chart-document td {
  padding: 0;
  text-align: center;
  vertical-align: middle;
}

/* ===== Google Docs-Style Page Dimensions ===== */

/* Page Canvas - wrapper that holds CSS custom properties */
.page-canvas {
  --page-width: 816px;
  --page-height: 1056px;
  --margin-top: 72px;
  --margin-bottom: 72px;
  --margin-left: 72px;
  --margin-right: 72px;
  --ruler-size: 18px;
  --ruler-gutter: 26px;
  height: 100%;
  overflow: hidden;
}

.page-canvas.page-a4 {
  --page-width: 794px;
  --page-height: 1123px;
}

/* Scrollable container for entire canvas */
.canvas-scroll-container {
  height: 100%;
  overflow: auto;
}

/* Content wrapper */
.canvas-content-wrapper {
  display: inline-flex;
  flex-direction: column;
  min-width: 100%;
  min-height: 100%;
}

/* Sticky horizontal ruler row */
.ruler-row-sticky {
  display: flex;
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--color-bg, #f8f9fa);
}

/* Canvas ruler wrapper - provides CSS custom properties for ruler sizing */
.canvas-ruler-wrapper {
  --ruler-size: 18px;
  --ruler-gutter: 26px;
}

/* Horizontal ruler row for canvas-based editor */
.ruler-row-canvas {
  display: flex;
  z-index: 20;
  background: var(--color-canvas-bg, #e5e5e5);
  padding-top: 3px;
  padding-bottom: 10px;
}

/* Corner spacer */
.ruler-corner {
  width: var(--ruler-gutter, 26px);
  height: var(--ruler-size, 18px);
  flex-shrink: 0;
  background: var(--color-canvas-bg, #e5e5e5);
}

/* Horizontal Ruler Wrapper */
.page-ruler-wrapper-horizontal {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding-bottom: 4px;
  padding-left: 2rem;
  padding-right: 2rem;
}

/* Document row */
.document-row {
  display: flex;
  flex: 1;
}

/* Vertical Ruler Wrapper */
.page-ruler-wrapper-vertical {
  position: sticky;
  left: 0;
  width: var(--ruler-gutter);
  flex-shrink: 0;
  display: flex;
  justify-content: flex-end;
  align-items: flex-start;
  padding-right: 4px;
  background: var(--color-canvas-bg, var(--color-bg, #f8f9fa));
  z-index: 15;
  overflow: hidden;
}

/* Document area */
.document-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem;
  gap: 0;
}

/* Ruler base styles */
.page-ruler {
  background: color-mix(in srgb, var(--color-surface) 50%, var(--color-canvas-bg));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--color-border) 30%, transparent);
  position: relative;
  border-radius: 3px;
  overflow: visible;
  user-select: none;
}

.page-ruler-horizontal {
  height: var(--ruler-size, 18px);
  width: var(--page-width, 612px);
}

.page-ruler-vertical {
  width: var(--ruler-size, 18px);
  height: var(--page-height, 792px);
}

/* Margin zones on ruler */
.ruler-margin-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  background: color-mix(in srgb, var(--color-border) 12%, transparent);
  z-index: 1;
}

.ruler-margin-left {
  left: 0;
  width: var(--margin-left);
  border-radius: 2px 0 0 2px;
}

.ruler-margin-right {
  right: 0;
  width: var(--margin-right);
  border-radius: 0 2px 2px 0;
}

.ruler-margin-zone-vertical {
  position: absolute;
  left: 0;
  right: 0;
  background: color-mix(in srgb, var(--color-border) 12%, transparent);
  z-index: 1;
}

.ruler-margin-top {
  top: 0;
  height: var(--margin-top);
  border-radius: 2px 2px 0 0;
}

.ruler-margin-bottom {
  bottom: 0;
  height: var(--margin-bottom);
  border-radius: 0 0 2px 2px;
}

/* Ruler tick marks */
.ruler-tick {
  position: absolute;
  bottom: 0;
  width: 1px;
  background: color-mix(in srgb, var(--color-border) 60%, transparent);
  z-index: 2;
}

.ruler-tick-major {
  height: 10px;
  background: color-mix(in srgb, var(--color-text-muted) 50%, transparent);
}

.ruler-tick-half {
  height: 7px;
}

.ruler-tick-quarter {
  height: 5px;
}

.ruler-tick-minor {
  height: 3px;
}

.ruler-label {
  position: absolute;
  top: 2px;
  font-size: 9px;
  color: color-mix(in srgb, var(--color-text-muted) 50%, transparent);
  transform: translateX(-50%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  z-index: 2;
  pointer-events: none;
}

/* Vertical ruler tick marks */
.ruler-tick-vertical {
  position: absolute;
  right: 0;
  height: 1px;
  background: color-mix(in srgb, var(--color-border) 60%, transparent);
  z-index: 2;
}

.ruler-tick-vertical.ruler-tick-major {
  width: 10px;
  background: color-mix(in srgb, var(--color-text-muted) 50%, transparent);
}

.ruler-tick-vertical.ruler-tick-half {
  width: 7px;
}

.ruler-tick-vertical.ruler-tick-quarter {
  width: 5px;
}

.ruler-tick-vertical.ruler-tick-minor {
  width: 3px;
}

.ruler-label-vertical {
  position: absolute;
  left: 2px;
  font-size: 9px;
  color: color-mix(in srgb, var(--color-text-muted) 50%, transparent);
  transform: translateY(-50%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  z-index: 2;
  pointer-events: none;
}

/* Horizontal ruler wrapper — use clip-path instead of overflow:hidden
   because CSS forces overflow-y to 'auto' when overflow-x is 'hidden',
   which clips the triangle handles that extend below the ruler. */
.ruler-wrapper-horizontal {
  clip-path: inset(0 0 -14px 0);
}

/* Margin handles — horizontal (left/right) */
.ruler-handle {
  position: absolute;
  width: 0;
  height: 0;
  top: 100%;
  cursor: ew-resize;
  z-index: 10;
  transition: opacity 0.15s ease;
}

/* Invisible expanded click target */
.ruler-handle::before {
  content: '';
  position: absolute;
  top: -8px;
  left: -10px;
  right: -10px;
  bottom: -6px;
}

.ruler-handle-left {
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 8px solid var(--color-accent);
  transform: translateX(-6px);
  opacity: 0.65;
}

.ruler-handle-right {
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 8px solid var(--color-accent);
  transform: translateX(6px);
  opacity: 0.65;
}

.ruler-handle:hover {
  opacity: 1;
}

.ruler-handle.dragging {
  opacity: 1;
}

/* Margin handles — vertical (top/bottom) */
.ruler-handle-vertical {
  position: absolute;
  width: 0;
  height: 0;
  left: 100%;
  cursor: ns-resize;
  z-index: 10;
  transition: opacity 0.15s ease;
}

/* Invisible expanded click target */
.ruler-handle-vertical::before {
  content: '';
  position: absolute;
  left: -8px;
  top: -10px;
  bottom: -10px;
  right: -6px;
}

.ruler-handle-top {
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 8px solid var(--color-accent);
  transform: translateY(-6px);
  opacity: 0.65;
}

.ruler-handle-bottom {
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 8px solid var(--color-accent);
  transform: translateY(6px);
  opacity: 0.65;
}

.ruler-handle-vertical:hover {
  opacity: 1;
}

.ruler-handle-vertical.dragging {
  opacity: 1;
}

/* Drag guide lines */
.ruler-handle.dragging::after {
  content: '';
  position: fixed;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--color-accent);
  opacity: 0.5;
  pointer-events: none;
}

.ruler-handle-vertical.dragging::after {
  content: '';
  position: fixed;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--color-accent);
  opacity: 0.5;
  pointer-events: none;
}

/* Document Page */
.document-page {
  width: var(--page-width);
  height: var(--page-height);
  background: var(--color-surface, #fff);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  position: relative;
  border: 1px solid color-mix(in srgb, var(--color-border, #e0e0e0) 60%, transparent);
  border-radius: 8px;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
  overflow: hidden;
  background-color: #ffffff !important;
  color: #1f2937 !important;
}

.document-page.page-active {
  border-color: color-mix(in srgb, var(--color-accent, #4285f4) 50%, transparent);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.document-page + .document-page {
  margin-top: 24px;
}

/* Page number indicator */
.page-number-indicator {
  position: absolute;
  bottom: calc(var(--margin-bottom, 72px) / 2);
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: var(--color-text-muted, #666);
  user-select: none;
  pointer-events: none;
}

/* Margin Indicators */
.margin-indicator {
  position: absolute;
  pointer-events: none;
  z-index: 5;
}

.margin-indicator-top {
  top: var(--margin-top);
  left: var(--margin-left);
  right: var(--margin-right);
  height: 0;
  border-top: 1px dashed color-mix(in srgb, var(--color-accent, #4285f4) 40%, transparent);
}

.margin-indicator-bottom {
  bottom: var(--margin-bottom);
  left: var(--margin-left);
  right: var(--margin-right);
  height: 0;
  border-top: 1px dashed color-mix(in srgb, var(--color-accent, #4285f4) 40%, transparent);
}

.margin-indicator-left {
  left: var(--margin-left);
  top: var(--margin-top);
  bottom: var(--margin-bottom);
  width: 0;
  border-left: 1px dashed color-mix(in srgb, var(--color-accent, #4285f4) 40%, transparent);
}

.margin-indicator-right {
  right: var(--margin-right);
  top: var(--margin-top);
  bottom: var(--margin-bottom);
  width: 0;
  border-left: 1px dashed color-mix(in srgb, var(--color-accent, #4285f4) 40%, transparent);
}

/* Header/Footer Zones */
.page-header-zone,
.page-footer-zone {
  position: absolute;
  left: var(--margin-left);
  right: var(--margin-right);
  display: none;
  align-items: center;
  font-size: 10px;
  color: #6b7280;
  overflow: hidden;
  pointer-events: none;
  z-index: 4;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.page-header-zone {
  top: calc(var(--margin-top) - var(--header-height, 20px) - 4px);
  height: var(--header-height, 20px);
}

.page-footer-zone {
  bottom: calc(var(--margin-bottom) - var(--footer-height, 20px) - 4px);
  height: var(--footer-height, 20px);
}

.page-header-zone.enabled,
.page-footer-zone.enabled {
  display: flex;
}

.page-header-zone[data-align="left"],
.page-footer-zone[data-align="left"] {
  justify-content: flex-start;
}

.page-header-zone[data-align="center"],
.page-footer-zone[data-align="center"] {
  justify-content: center;
}

.page-header-zone[data-align="right"],
.page-footer-zone[data-align="right"] {
  justify-content: flex-end;
}

.page-header-content,
.page-footer-content {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Document End Zone */
.document-end-zone {
  position: absolute;
  left: var(--margin-left);
  right: var(--margin-right);
  bottom: calc(var(--margin-bottom) + var(--footer-height, 0px) + 24px);
  display: none;
  flex-direction: column;
  font-size: 9px;
  color: #6b7280;
  pointer-events: none;
  z-index: 4;
}

.document-end-divider {
  width: 100%;
  height: 1px;
  background-color: #d1d5db;
  margin-bottom: 8px;
}

.document-end-text {
  text-align: left;
  line-height: 1.4;
  margin-bottom: 6px;
}

.document-end-copyright {
  text-align: left;
  font-weight: 600;
}

.document-end-content {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Content Area */
.document-content {
  box-sizing: border-box;
  padding-top: var(--margin-top);
  padding-bottom: var(--margin-bottom);
  padding-left: var(--margin-left);
  padding-right: var(--margin-right);
  min-height: var(--page-height);
  max-height: var(--page-height);
  overflow: hidden;
  color: #1f2937;
}

.document-page .document-content h1,
.document-page .document-content h2,
.document-page .document-content h3,
.document-page .document-content h4,
.document-page .document-content h5,
.document-page .document-content h6 {
  color: #111827;
}

.document-page .document-content a {
  color: #4f46e5;
}

/* Page settings bar */
.page-settings-bar {
  background-color: var(--color-bg, #f8f9fa);
  border-color: var(--color-border, #e0e0e0);
}

.page-settings-bar select,
.page-settings-bar button {
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  border: 1px solid var(--color-border, #ccc);
  background-color: var(--color-surface, #fff);
  color: var(--color-text, #333);
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.page-settings-bar button:hover {
  background-color: var(--color-bg, #f0f0f0);
}

.page-settings-bar button.active {
  background-color: color-mix(in srgb, var(--color-accent, #4285f4) 15%, transparent);
  border-color: var(--color-accent, #4285f4);
  color: var(--color-accent, #4285f4);
}

/* Ruler tooltip */
.ruler-tooltip {
  position: fixed;
  z-index: 9999;
  padding: 4px 8px;
  background: var(--color-surface, #fff);
  border: 1px solid var(--color-border, #ccc);
  border-radius: 4px;
  font-size: 11px;
  color: var(--color-text, #333);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  pointer-events: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ===== Skeleton Loading Animation ===== */
.skeleton-shimmer {
  background: linear-gradient(
    90deg,
    var(--color-bg, #f3f4f6) 0%,
    var(--color-surface, #ffffff) 50%,
    var(--color-bg, #f3f4f6) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* ===== Editor Toolbar ===== */
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  margin-bottom: 1rem;
}

.editor-toolbar button {
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.875rem;
  color: var(--color-muted);
  transition: all 0.15s ease;
}

.editor-toolbar button:hover {
  color: var(--color-text);
  background: var(--color-bg);
}

/* ===== Scrollable Pages Container ===== */
.pages-scroll-container {
  position: relative;
  height: calc(100vh - 220px);
  overflow-y: auto;
  overflow-x: hidden;
  background: #d4d4d4;
  border-radius: 0.5rem;
}

.pages-stack {
  position: absolute;
  top: 40px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 1;
}

.page-background {
  width: var(--page-width);
  height: var(--page-height);
  background: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  margin-bottom: var(--page-gap);
  position: relative;
}

.page-background .page-label {
  position: absolute;
  top: -24px;
  left: 0;
  font-size: 12px;
  color: #666;
}

.page-gap-overlay {
  position: absolute;
  width: var(--page-width);
  background: #d4d4d4;
  z-index: 10;
  pointer-events: none;
}

.editing-surface {
  position: relative;
  width: var(--page-width);
  margin: 40px auto;
  padding: var(--page-margin);
  background: transparent;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 16px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  outline: none;
  min-height: var(--page-height);
  z-index: 2;
  color: #000;
}

.editing-surface:focus {
  outline: none;
}

.page-break-spacer {
  display: block;
  position: relative;
  pointer-events: none;
  user-select: none;
  background: transparent;
  font-size: 0;
  line-height: 0;
  min-width: 100%;
}

.page-content {
  display: block;
  position: relative;
}

/* Dark mode adjustments */
[data-mode="dark"] .pages-scroll-container {
  background: #404040;
}

[data-mode="dark"] .page-background .page-label {
  color: #999;
}

[data-mode="dark"] .chart-cell--clear {
  background-color: #9E9890;
}

[data-mode="dark"] .chart-cell--no-stitch {
  background-color: #7A7570;
}

[data-mode="dark"] .chart-cell--stitch {
  background-color: #B8B1A9;
  color: #1f2937;
}

[data-mode="dark"] .chart-cell--mc {
  background-color: #B8B1A9;
}

[data-mode="dark"] .chart-legend-symbol:not([class*="chart-cell--cc"]):not(.chart-cell--mc) {
  background-color: #B8B1A9;
  color: #1f2937;
}

[data-mode="dark"] .chart-legend-symbol.chart-cell--mc {
  background-color: #B8B1A9;
}

/* ===== Print Styles ===== */

.print-pages { display: none; }

@media print {
  body > *:not(.print-pages) { display: none !important; }
  .print-pages { display: block !important; }
  .print-page {
    width: 100%;
    height: auto;
    display: block;
    page-break-after: always;
  }
  .print-page:last-child { page-break-after: avoid; }
  @page { margin: 0; }
}

/* Screen-reader only class */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ===== Ease Slider ===== */

.ease-slider {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: var(--color-border);
  outline: none;
}

.ease-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-accent);
  cursor: pointer;
  border: 2px solid var(--color-surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.ease-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-accent);
  cursor: pointer;
  border: 2px solid var(--color-surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.ease-slider::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: var(--color-border);
}

/* ===== Image Overlay ===== */

.image-overlay {
  position: absolute;
  z-index: 50;
  pointer-events: none;
}

.image-overlay__border {
  position: absolute;
  inset: 0;
  border: 1px solid color-mix(in srgb, var(--color-accent) 40%, transparent);
  border-radius: 2px;
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
}

.image-overlay:hover .image-overlay__border,
.image-overlay--active .image-overlay__border {
  opacity: 1;
}

.image-overlay__menu-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: auto;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  font-size: 16px;
  color: var(--color-text);
}

.image-overlay:hover .image-overlay__menu-btn,
.image-overlay--active .image-overlay__menu-btn {
  opacity: 1;
}

.image-overlay__menu-btn:hover {
  background: var(--color-bg);
}

.image-overlay__dropdown {
  position: absolute;
  top: 36px;
  right: 4px;
  min-width: 160px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: 4px 0;
  pointer-events: auto;
  z-index: 61;
}

.image-overlay__dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 12px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 13px;
  color: var(--color-text);
  text-align: left;
}

.image-overlay__dropdown-item:hover {
  background: var(--color-bg);
}

.image-overlay__dropdown-item--active {
  color: var(--color-accent);
  font-weight: 500;
}

.image-overlay__dropdown-separator {
  height: 1px;
  margin: 4px 0;
  background: var(--color-border);
}

.image-overlay__handle {
  position: absolute;
  width: 8px;
  height: 8px;
  background: transparent;
  border: 2px solid var(--color-accent);
  border-radius: 20%;
  pointer-events: auto;
  opacity: 0;
  transition: opacity 0.15s ease;
  box-shadow: 0 0 0 1px var(--color-surface);
}

.image-overlay:hover .image-overlay__handle,
.image-overlay--active .image-overlay__handle {
  opacity: 1;
}

.image-overlay__handle--nw { top: -4px; left: -4px; cursor: nwse-resize; }
.image-overlay__handle--ne { top: -4px; right: -4px; cursor: nesw-resize; }
.image-overlay__handle--sw { bottom: -4px; left: -4px; cursor: nesw-resize; }
.image-overlay__handle--se { bottom: -4px; right: -4px; cursor: nwse-resize; }

/* ===== Computed Token Pill ===== */
/* Canvas-rendered pills use these same values via text_renderer.js.
   This class mirrors them for any DOM-based token overlays. */
.computed-token-pill {
  display: inline;
  padding: 0 3px;
  border: 1px solid color-mix(in srgb, var(--color-accent) 25%, transparent);
  background: color-mix(in srgb, var(--color-accent) 6%, transparent);
  border-radius: 3px;
  cursor: default;
}

/* Applied during cascade animation — subtle opacity pulse while random numbers cycle */
.token-animating {
  opacity: 0.85;
  transition: opacity 80ms ease-in-out;
}
