body {
  font-family: Arial, sans-serif;
  margin: 0;
  padding: 0;
  background: #f5f5f5;
}

/* ============================================
   Utility Classes
   ============================================ */

.hidden {
  display: none !important;
}

/* ============================================
   Global Controls (fixed position top-right)
   ============================================ */

#global-controls {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Override absolute positioning for buttons in global controls */
#global-controls .icon-btn {
  position: relative;
  background: #fff;
  border: 1px solid #e0e0e0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

#global-controls .icon-btn:hover {
  background: #f0f0f0;
}

/* Settings flyout positioning */
.settings-flyout {
  position: absolute;
  top: 56px;
  right: 56px;
}

/* Help overlay already inherits from modal-overlay */
.help-overlay .modal {
  max-height: 80vh;
  overflow-y: auto;
}

#app {
  max-width: 900px;
  margin: 40px auto;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  padding: 24px;
  position: relative;
  /* Allow content to overflow horizontally when page is
     scaled, needed for page controls on the left side. */
  overflow-x: visible;
}

.page-controls, .photo-controls {
  margin-bottom: 16px;
}

.app-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 4px;
}

.app-subtitle {
  font-size: 13px;
  color: #555;
}

.app-description {
  font-size: 13px;
  color: #555;
  margin-top: 4px;
}

.page-controls {
  text-align: center;
  margin-bottom: 40px;
}

.collage-page {
  border: 1px solid #ccc;
  background: #fafafa;
  min-height: 800px;
  position: relative;
  /* Allow handles and controls around photos to remain
     visible even when they extend slightly beyond the
     page border; JS still constrains photo containers
     themselves to the page bounds. */
  overflow: visible;
  /* Stack pages vertically and centre them in the
     workspace, with some breathing room between. */
  margin: 0 auto 24px auto;
  /* Prevent browser touch gestures (pan, zoom) so pointer
     events work reliably for drag/resize on touch devices. */
  touch-action: none;
  /* Transform origin for responsive scaling */
  transform-origin: top center;
}

/* Highlight the active page with the same blue outline
   used for the selected photo container. */
.collage-page.active-page {
  outline: 2px solid #0078d4;
  outline-offset: 2px;
}


/* The actual <img> elements; the container carries the border/frame. */
.photo {
  cursor: move;
  /* Prevent browser touch gestures on photos */
  touch-action: none;
}

/* Unrotated photo container; only selected ones get a blue frame. */
.photo-container {
  position: absolute;
  border-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

/* Use outline so selection doesn’t change layout/size. */
.photo-container.selected {
  outline: 2px solid #0078d4;
  /* Ensure the selected photo and its controls (including
     size readout) sit above other photos. */
  z-index: 20;
}

/* Active crop target sits above the dimming overlay */
.photo-container.cropping-active {
  /* Crop mode should sit even higher than a normal
     selection to keep its frame and handles clear. */
  z-index: 30;
}
/* Inner mask used for cropping; clips only the image. */
.photo-mask {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

/* Photo image inside the mask; JS sets left/top/width/height dynamically. */
.photo-mask .photo {
  position: absolute;
}

/* ============================================
   Resize Handles
   ============================================ */

.resize-handle {
  position: absolute;
  width: 32px;
  height: 32px;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
  z-index: 10;
  pointer-events: auto;
  /* Prevent browser touch gestures on handles */
  touch-action: none;
}

.resize-handle--round {
  border-radius: 50%;
}

.resize-handle--square {
  border-radius: 0;
}

/* Icon centered inside a resize handle */
.resize-handle__icon {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 20px;
  height: 20px;
  pointer-events: none;
}

/* Visual frame for the full underlying image while cropping. */
.image-frame {
  position: absolute;
  border: 1px dashed rgba(0,0,0,0.5);
  pointer-events: none;
}

.image-resize-handle {
  pointer-events: auto;
  border: 1px solid #0078d4;
  background: #ffffff;
}

.photo-container.cropping-active .crop-ratio-active {
  border-width: 2px;
  background-color: #4daaec;
}

/* Photo dimension info readout (top-right of selected photo) */
.photo-size-info {
  position: absolute;
  font-size: 11px;
  line-height: 1.2;
  color: #333;
  background: rgba(255, 255, 255, 0.9);
  padding: 2px 4px;
  border-radius: 3px;
  white-space: nowrap;
  pointer-events: none;
}

/* Dimension line (width/height row) */
.photo-size-info__line {
  display: flex;
  align-items: center;
}

/* Dimension icon styling */
.photo-size-info__icon {
  width: 14px;
  height: 14px;
  margin-right: 4px;
  pointer-events: none;
}

/* ============================================
   Page Actions (Add/Delete page buttons below page)
   ============================================ */

.page-actions {
  position: relative;
  margin: 8px auto 24px auto;
}

/* When a photo is in crop mode, make the crop toggle
   button stand out with a thicker blue border. */
.photo-container.cropping-active .crop-toggle {
  border-width: 2px;
  background-color: #4daaec;
}

/* Generic pressed/active feedback for all circular/square
   photo edit controls (resize, rotate, crop, delete, etc.). */
.resize-handle.image-resize-handle:active {
  background-color: #4daaec;
}

/* While dragging a resize button or crop handle, keep the
   same blue background applied via a JS-added class. */
.resize-handle.image-resize-handle.handle-active {
  background-color: #4daaec;
}

/* Global dim overlay when cropping a photo */
/* (Global crop overlay removed; crop mode no longer greys the whole page.) */

/* When capturing to PDF, suppress outlines and handles. */
body.printing-pdf .photo-container {
  border: none;
  box-shadow: none;
  outline: none;
}

body.printing-pdf .collage-page {
  outline: none;
}

body.printing-pdf .resize-handle {
  display: none !important;
}

body.printing-pdf .photo-size-info {
  display: none !important;
}

body.printing-pdf .help-overlay {
  display: none !important;
}

/* No special handling needed for a removed crop overlay in PDF mode. */

/* Wrapper for scaled collage page; reserves correct height
   after CSS transform:scale() is applied. */
.collage-page-wrapper {
  position: relative;
  /* JS sets the height and width based on scaled page dimensions */
  margin-left: auto;
  margin-right: auto;
}

/* ============================================
   Icon Buttons - Common circular button styles
   ============================================ */

/* Base icon button styles */
.icon-btn {
  position: absolute;
  cursor: pointer;
}

/* Large icon button: 40px with 20px icon */
.icon-btn--lg {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

/* Medium icon button: 32px with 20px icon */
.icon-btn--md {
  width: 32px;
  height: 32px;
  border-radius: 50%;
}

/* Small icon button: 28px with 18px icon */
.icon-btn--sm {
  width: 28px;
  height: 28px;
  border-radius: 50%;
}

/* Centered icon inside button */
.icon-btn__icon {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.icon-btn__icon--lg {
  width: 20px;
  height: 20px;
}

.icon-btn__icon--md {
  width: 20px;
  height: 20px;
}

.icon-btn__icon--sm {
  width: 18px;
  height: 18px;
}

/* ============================================
   Flyout Menu
   ============================================ */

.flyout {
  position: absolute;
  min-width: 160px;
  background: #ffffff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  border-radius: 6px;
  padding: 8px 0;
  z-index: 20;
}

.flyout__title {
  font-size: 11px;
  font-weight: 600;
  color: #888;
  padding: 4px 12px;
  text-transform: uppercase;
}

.flyout__row {
  display: flex;
  align-items: center;
  padding: 6px 12px;
  cursor: pointer;
}

.flyout__row:hover {
  background-color: #f5f5f5;
}

.flyout__radio {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #0078d4;
  margin-right: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.flyout__radio--selected::after {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #0078d4;
}

.flyout__label {
  font-size: 14px;
}

/* ============================================
   Modal Overlay & Dialog
   ============================================ */

.modal-overlay {
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
}

.modal {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 420px;
  max-width: 90%;
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  padding: 16px 20px 20px 20px;
  color: #333;
}

.modal__title {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 8px;
}

.modal__content {
  font-size: 13px;
  line-height: 1.5;
}

.modal__separator {
  height: 8px;
}

.modal__row {
  display: flex;
  align-items: center;
  margin-bottom: 6px;
}

.modal__row-icon {
  position: relative;
  margin-right: 8px;
}

@media (max-width: 600px) {
  #app {
    /* Minimal padding on mobile; leave room for side controls */
    padding: 8px;
    margin: 8px auto;
    border-radius: 0;
    box-shadow: none;
  }
  .page-controls {
    margin-bottom: 16px;
  }
  .app-title {
    font-size: 18px;
  }
  .app-subtitle,
  .app-description {
    font-size: 12px;
  }
  .collage-page {
    min-height: auto;
  }
}

/* Print: only show the collage page */
@media print {
  /* Hide everything by default */
  body * {
    visibility: hidden;
  }

  /* Show only the collage page and its contents */
  .collage-page, .collage-page * {
    visibility: visible;
  }

  /* Stack all collage pages vertically and put each
     on its own printed sheet, similar to a document
     editor. */
  .collage-page {
    position: static;
    margin: 0 auto;
    border: none;
    box-shadow: none;
    background: #ffffff;
    page-break-after: always;
  }

  .collage-page:last-of-type {
    page-break-after: auto;
  }

  /* Remove outer chrome */
  body {
    margin: 0;
    background: #ffffff;
  }
  #app {
    margin: 0;
    padding: 0;
    box-shadow: none;
    border-radius: 0;
    background: transparent;
  }

  /* Do not print selection outlines or resize handles */
  .photo-container {
    border: none;
    box-shadow: none;
    outline: none;
  }

  .collage-page {
    outline: none;
  }

  .resize-handle {
    display: none !important;
  }

  .photo-size-info {
    display: none !important;
  }

  .help-overlay {
    display: none !important;
  }

  /* No special handling needed for a removed crop overlay in print mode. */
}
