/* ==========================================================================
   crop.css — crop selector overlay for the settings screen preview
   ========================================================================== */

/* The stage fills the preview frame; the image letterboxes inside it with
   object-fit, and JS positions the overlay onto the rendered image box.
   (Wrapping the <img> makes its `max-height: 100%` resolve against an
   auto-height parent, i.e. to `none` — which is what squashed portraits
   into a square before.) */
.crop-stage {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  line-height: 0;
  touch-action: none;
}

.settings-screen .img-background .crop-stage .img-presentation {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
}

.crop-overlay {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  display: none;
  cursor: crosshair;
}
.crop-overlay.is-active { display: block; }

/* Dimmed area outside the selection — four panels around the box */
.crop-shade {
  position: absolute;
  background: rgba(15, 23, 42, 0.55);
  pointer-events: none;
}

/* Feedback while dragging */
.crop-box:active,
.crop-overlay.is-dragging .crop-box {
  border-color: #38bdf8;
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.7);
}
.crop-handle:active { background: #38bdf8; }

.crop-box {
  position: absolute;
  border: 1px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.45);
  cursor: move;
  box-sizing: border-box;
}

/* Rule-of-thirds guides */
.crop-box::before,
.crop-box::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.45;
}
.crop-box::before {
  background:
    linear-gradient(to right, transparent 33.33%, #fff 33.33%, #fff calc(33.33% + 1px), transparent calc(33.33% + 1px)),
    linear-gradient(to right, transparent 66.66%, #fff 66.66%, #fff calc(66.66% + 1px), transparent calc(66.66% + 1px));
}
.crop-box::after {
  background:
    linear-gradient(to bottom, transparent 33.33%, #fff 33.33%, #fff calc(33.33% + 1px), transparent calc(33.33% + 1px)),
    linear-gradient(to bottom, transparent 66.66%, #fff 66.66%, #fff calc(66.66% + 1px), transparent calc(66.66% + 1px));
}

.crop-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  background: #ffffff;
  border: 1px solid #0f172a;
  border-radius: 3px;
  box-sizing: border-box;
  z-index: 2;
}

.crop-handle[data-handle="nw"] { top: -7px;  left: -7px;  cursor: nwse-resize; }
.crop-handle[data-handle="n"]  { top: -7px;  left: 50%; margin-left: -7px; cursor: ns-resize; }
.crop-handle[data-handle="ne"] { top: -7px;  right: -7px; cursor: nesw-resize; }
.crop-handle[data-handle="e"]  { top: 50%; margin-top: -7px; right: -7px; cursor: ew-resize; }
.crop-handle[data-handle="se"] { bottom: -7px; right: -7px; cursor: nwse-resize; }
.crop-handle[data-handle="s"]  { bottom: -7px; left: 50%; margin-left: -7px; cursor: ns-resize; }
.crop-handle[data-handle="sw"] { bottom: -7px; left: -7px;  cursor: nesw-resize; }
.crop-handle[data-handle="w"]  { top: 50%; margin-top: -7px; left: -7px; cursor: ew-resize; }

/* Readout + reset under the preview */
.crop-toolbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}
.crop-toolbar.is-active { display: flex; }

.crop-readout { font-variant-numeric: tabular-nums; }

.crop-reset {
  border: 1px solid var(--border-light);
  background: #ffffff;
  color: var(--text-main);
  border-radius: var(--radius-pill);
  padding: 6px 14px;
  font-weight: 600;
  font-size: 0.78rem;
  cursor: pointer;
}
.crop-reset:hover { background: var(--bg-subtle); }

/* Fingers need bigger grab targets than a mouse pointer */
@media (max-width: 820px), (pointer: coarse) {
  .crop-handle {
    width: 22px;
    height: 22px;
    border-radius: 4px;
  }
  .crop-handle[data-handle="nw"] { top: -11px; left: -11px; }
  .crop-handle[data-handle="n"]  { top: -11px; margin-left: -11px; }
  .crop-handle[data-handle="ne"] { top: -11px; right: -11px; }
  .crop-handle[data-handle="e"]  { margin-top: -11px; right: -11px; }
  .crop-handle[data-handle="se"] { bottom: -11px; right: -11px; }
  .crop-handle[data-handle="s"]  { bottom: -11px; margin-left: -11px; }
  .crop-handle[data-handle="sw"] { bottom: -11px; left: -11px; }
  .crop-handle[data-handle="w"]  { margin-top: -11px; left: -11px; }

  .crop-toolbar { font-size: 0.75rem; }
  .crop-reset { min-height: 38px; }
}

/* ==========================================================================
   Conversion progress ring (under the Convert button)
   ========================================================================== */

.convert-loader {
  display: none;
  align-items: center;
  gap: 14px;
  margin-top: 14px;
}
.convert-loader.is-active { display: flex; }

.convert-loader-ring {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  transform: rotate(-90deg);   /* start the sweep at 12 o'clock */
}
.convert-loader-track {
  fill: none;
  stroke: var(--border-light);
  stroke-width: 6;
}
.convert-loader-bar {
  fill: none;
  stroke: var(--text-main);
  stroke-width: 6;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.12s linear;
}

.convert-loader-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.convert-loader-pct {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
}
.convert-loader-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

@media (prefers-reduced-motion: reduce) {
  .convert-loader-bar { transition: none; }
}
