/* Crop & straighten modal (crop.js). Reuses the theme tokens from styles.css. */

.crop-overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overscroll-behavior: contain;
  animation: crop-fade-in 0.2s var(--ease);
}

.crop-overlay:focus {
  outline: none;
}

.crop-overlay [hidden] {
  display: none !important;
}

@keyframes crop-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.crop-header {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 8px 4px 16px;
}

.crop-titles {
  flex: 1;
  min-width: 0;
  padding-top: 6px;
}

.crop-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.25rem;
  line-height: 1.3;
}

.crop-hint {
  margin: 2px 0 0;
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--text-dim);
}

.crop-close {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--touch);
  height: var(--touch);
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 999px;
  color: var(--text-dim);
  cursor: pointer;
}

.crop-close:hover {
  color: var(--gold);
}

/* ---------- Stage ---------- */

.crop-stage {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Room for the corner handles to overhang the photo edge. */
  padding: 24px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.crop-frame {
  position: relative;
  flex: none;
}

.crop-image {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 2px;
}

.crop-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  overflow: visible;
  pointer-events: none;
}

.crop-mask {
  fill: rgba(10, 8, 5, 0.62);
}

.crop-outline {
  fill: none;
  stroke: var(--gold);
  stroke-width: 2;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.crop-grid {
  fill: none;
  stroke: var(--gold-line);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.crop-handle {
  position: absolute;
  width: var(--touch);
  height: var(--touch);
  margin: calc(var(--touch) / -2) 0 0 calc(var(--touch) / -2);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 999px;
  cursor: grab;
  touch-action: none;
}

.crop-handle.is-dragging {
  cursor: grabbing;
}

.crop-handle:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 0;
  border-radius: 999px;
}

.crop-handle-dot {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--bg);
  border: 2px solid var(--gold);
  box-shadow: 0 0 0 3px rgba(10, 8, 5, 0.45);
  transition: transform 0.12s var(--ease), background 0.12s var(--ease);
}

.crop-handle:hover .crop-handle-dot,
.crop-handle:focus-visible .crop-handle-dot,
.crop-handle.is-dragging .crop-handle-dot {
  background: var(--gold);
  transform: scale(1.15);
}

/* Magnifier shown near the active corner. Size must match LOUPE_SIZE. */
.crop-loupe {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  width: 96px;
  height: 96px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg-elevated);
  border: 2px solid var(--gold);
  box-shadow: 0 6px 18px rgba(10, 8, 5, 0.6);
  pointer-events: none;
}

.crop-loupe canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.crop-loupe::before,
.crop-loupe::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  background: var(--focus);
}

.crop-loupe::before {
  width: 14px;
  height: 1px;
  margin: 0 0 0 -7px;
}

.crop-loupe::after {
  width: 1px;
  height: 14px;
  margin: -7px 0 0 0;
}

/* ---------- Controls ---------- */

.crop-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 4px 16px 16px;
}

.crop-toolbar,
.crop-actions {
  display: flex;
  gap: 10px;
}

.crop-toolbar {
  justify-content: center;
}

.crop-btn {
  flex: 1 1 0;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--touch);
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease);
}

.crop-btn svg {
  flex: none;
}

.crop-btn-tool {
  flex: 0 1 auto;
  min-width: 112px;
  border-color: var(--card-border);
  color: var(--text-dim);
  font-size: 0.92rem;
  font-weight: 500;
}

.crop-btn-tool:hover {
  color: var(--gold);
  border-color: var(--gold-line);
}

.crop-btn-secondary {
  border-color: var(--gold-line);
  color: var(--gold);
}

.crop-btn-secondary:hover {
  background: var(--gold-soft);
}

.crop-btn-primary {
  flex-grow: 1.6;
  background: var(--gold);
  color: var(--bg);
}

.crop-btn-primary:hover {
  filter: brightness(1.06);
}

.crop-btn[aria-disabled="true"] {
  opacity: 0.6;
  cursor: progress;
}

.crop-error {
  margin: 0;
  padding: 8px 12px;
  border-radius: var(--radius-s);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.88rem;
  text-align: center;
}

/* Live region for screen-reader announcements only. */
.crop-status {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (min-width: 640px) {
  .crop-header {
    padding-top: 20px;
  }
  .crop-stage {
    padding: 32px;
  }
  .crop-controls {
    padding-bottom: 24px;
  }
}

@media (max-width: 360px) {
  .crop-btn {
    padding: 10px 10px;
  }
  .crop-btn-tool {
    min-width: 0;
    flex: 1 1 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .crop-overlay {
    animation: none;
  }
  .crop-overlay *,
  .crop-overlay *::before,
  .crop-overlay *::after {
    transition: none !important;
    animation: none !important;
  }
}
