.crop-rotate-control {
  display: grid;
  gap: 9px;
  margin: 16px 0 18px;
}

.rotation-boundary-control {
  grid-column: 1 / -1;
  width: min(310px, 100%);
  margin-top: 3px;
}
.rotation-boundary-control[hidden] {
  display: none !important;
}

.rotation-boundary-control select {
  width: 100%;
  height: 42px;
  padding: 8px 34px 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
  font: 700 12px 'DM Mono', monospace;
}

.crop-editor .editor-boundary-toggle{position:relative;display:inline-grid;flex:0 0 40px;width:40px;height:40px;padding:0;place-items:center;border:1px solid var(--line);border-radius:10px;background:color-mix(in srgb,var(--panel) 86%,var(--paper));color:var(--muted);cursor:pointer}
.crop-editor .editor-boundary-toggle:hover,.crop-editor .editor-boundary-toggle:focus-visible{border-color:var(--accent);color:var(--accent);outline:none}
.crop-editor .editor-boundary-toggle.active{border-color:var(--accent);background:var(--accent-soft);color:var(--accent);box-shadow:inset 0 0 0 1px var(--accent)}
.boundary-toggle-icon{position:relative;display:block;width:23px;height:19px;border:1.5px dashed currentColor;border-radius:3px}
.boundary-toggle-icon i{position:absolute;left:50%;top:50%;display:block;width:13px;height:13px;border:1.5px solid currentColor;transform:translate(-50%,-50%) rotate(25deg);transition:width .16s ease,height .16s ease}
.editor-boundary-toggle[data-mode="free"] .boundary-toggle-icon i{width:25px;height:14px}

.ratio-presets .main-boundary-toggle{
  display:flex;
  min-width:0;
  min-height:64px;
  height:64px;
  align-items:center;
  justify-content:center;
  gap:7px;
  padding:7px 8px;
  border:1px solid var(--line);
  border-radius:8px;
  background:color-mix(in srgb,var(--panel) 88%,var(--paper));
  color:var(--muted);
  cursor:pointer;
}
.ratio-presets .main-boundary-toggle:hover,.ratio-presets .main-boundary-toggle:focus-visible{border-color:var(--accent);color:var(--accent);outline:none}
.ratio-presets .main-boundary-toggle.active{border-color:var(--accent);background:var(--accent-soft);color:var(--accent);box-shadow:inset 0 0 0 1px var(--accent)}
.ratio-presets .main-boundary-toggle[data-mode="free"] .boundary-toggle-icon i{width:25px;height:14px}
.ratio-presets .main-boundary-toggle .boundary-copy{display:grid;min-width:0;gap:3px;text-align:left}
.ratio-presets .main-boundary-toggle .boundary-copy b{overflow:hidden;font:700 9px/1.2 inherit;text-overflow:ellipsis;white-space:nowrap}
.ratio-presets .main-boundary-toggle .boundary-copy small{font:700 9px/1.2 'DM Mono',monospace}
.ratio-presets .main-boundary-toggle .boundary-toggle-icon{flex:0 0 auto}

.position-help-tooltip {
  position: relative;
  display: inline-flex;
  margin-left: 6px;
  vertical-align: middle;
}

.position-help-tooltip > button {
  display: inline-grid;
  width: 18px;
  height: 18px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel) 82%, var(--paper));
  color: var(--muted);
  font: 800 11px/1 'DM Mono', monospace;
  cursor: help;
}

.position-help-tooltip [role='tooltip'] {
  position: absolute;
  z-index: 40;
  right: -4px;
  bottom: calc(100% + 9px);
  width: min(300px, calc(100vw - 40px));
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 12px 30px rgba(0,0,0,.2);
  font: 500 11px/1.6 'Noto Sans Thai','Segoe UI',sans-serif;
  white-space: normal;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity .15s ease,transform .15s ease,visibility .15s;
}

.position-help-tooltip:hover [role='tooltip'],
.position-help-tooltip:focus-within [role='tooltip'],
.position-help-tooltip.open [role='tooltip'] {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.crop-rotate-control > strong {
  color: var(--muted);
  font: 700 12px/1.2 'DM Mono', monospace;
  letter-spacing: .06em;
}

.crop-rotate-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 62px;
  align-items: center;
  gap: 12px;
}

.crop-rotate-row > input[type='range'] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.crop-rotate-row > label {
  display: flex;
  align-items: center;
  min-height: 40px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.crop-rotate-row input[type='number'] {
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  text-align: center;
  font: 700 14px 'DM Mono', monospace;
  appearance: textfield;
}

.crop-rotate-row input[type='number']::-webkit-inner-spin-button,
.crop-rotate-row input[type='number']::-webkit-outer-spin-button { appearance: none; }

.crop-rotate-row label > span,
.crop-rotate-limits { color: var(--muted); }

.crop-rotate-limits {
  display: flex;
  justify-content: space-between;
  padding-right: 74px;
  font: 600 11px 'DM Mono', monospace;
}

.per-image-rotate {
  width: 100%;
  margin: 10px 0 2px;
  padding: 10px 11px 8px;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: color-mix(in srgb, var(--panel) 82%, var(--paper));
}

.file-info .per-image-rotate > strong {
  display: block;
  overflow: visible;
  color: var(--muted);
  text-overflow: clip;
  white-space: nowrap;
}

.per-image-rotate .crop-rotate-row {
  grid-template-columns: minmax(70px, 1fr) 58px;
  gap: 8px;
}

.per-image-rotate .crop-rotate-row > label {
  min-height: 34px;
  padding-inline: 7px;
}

.per-image-rotate .crop-rotate-limits {
  padding-right: 66px;
  font-size: 10px;
}

.crop-card .preview-wrap > img {
  will-change: transform;
}

/* Rotation now uses a draggable handle directly on the crop overlay. */
.crop-card .per-image-rotate {
  display: none !important;
}

.inline-rotate-handle {
  position: absolute;
  z-index: 12;
  top: 10px;
  left: 50%;
  display: grid;
  width: 30px;
  height: 30px;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(255,255,255,.72);
  border-radius: 999px;
  background: rgba(8,13,24,.84);
  color: #fff;
  box-shadow: 0 4px 13px rgba(0,0,0,.34);
  font: 700 20px/1 sans-serif;
  cursor: grab;
  transform: translateX(-50%) rotate(calc(var(--crop-angle, 0deg) * -1));
  touch-action: none;
  backdrop-filter: blur(7px);
}

.inline-crop > .crop-size-overlay {
  transform: rotate(calc(var(--crop-angle, 0deg) * -1));
  transform-origin: center;
}

.inline-rotate-handle:hover,
.inline-rotate-handle.dragging {
  border-color: #fff;
  background: var(--accent);
  cursor: grabbing;
}

.inline-rotate-handle::after {
  content: attr(data-angle);
  position: absolute;
  top: calc(100% + 5px);
  left: 50%;
  min-width: 42px;
  padding: 3px 6px;
  border-radius: 6px;
  background: rgba(8,13,24,.86);
  color: #fff;
  font: 700 10px/1.25 'DM Mono', monospace;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%);
  transition: opacity .15s ease;
}

.inline-rotate-handle:hover::after,
.inline-rotate-handle.dragging::after {
  opacity: 1;
}

.editor-rotate-handle {
  position: absolute;
  z-index: 12;
  top: 10px;
  left: 50%;
  display: grid;
  width: 34px;
  height: 34px;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(255,255,255,.75);
  border-radius: 999px;
  background: rgba(8,13,24,.86);
  color: #fff;
  box-shadow: 0 5px 16px rgba(0,0,0,.38);
  font: 700 22px/1 sans-serif;
  cursor: grab;
  transform: translateX(-50%) rotate(calc(var(--crop-angle, 0deg) * -1));
  touch-action: none;
  backdrop-filter: blur(7px);
}

.editor-rotate-handle:hover,
.editor-rotate-handle.dragging {
  border-color: #fff;
  background: var(--accent);
  cursor: grabbing;
}

.editor-rotate-handle::after {
  content: attr(data-angle);
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  min-width: 48px;
  padding: 4px 7px;
  border-radius: 6px;
  background: rgba(8,13,24,.88);
  color: #fff;
  font: 700 11px/1.2 'DM Mono', monospace;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%);
}

.editor-rotate-handle:hover::after,
.editor-rotate-handle.dragging::after {
  opacity: 1;
}

#crop-selection > .crop-size-overlay {
  transform: rotate(calc(var(--crop-angle, 0deg) * -1));
  transform-origin: center;
}

.crop-align-control {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.pixel-fields > .crop-align-control {
  grid-column: 1 / -1;
  margin-top: 4px;
}

.crop-align-control > strong {
  color: var(--muted);
  font: 700 12px/1.3 'DM Mono', monospace;
}

.crop-align-buttons {
  display: grid;
  grid-template-columns: repeat(6, 30px);
  align-items: center;
  justify-content: start;
  gap: 5px;
  width: max-content;
  max-width: 100%;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: color-mix(in srgb, var(--panel) 86%, var(--paper));
}

.crop-align-buttons button {
  display: grid;
  width: 30px;
  height: 30px;
  min-width: 30px;
  padding: 0;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
}

.crop-align-buttons button:hover,
.crop-align-buttons button:focus-visible {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 15%, transparent);
}

.align-divider {
  display: none;
}

/* Two-row alignment map: axes, corners, then one full-height center button. */
.crop-align-buttons [data-align='left'] { grid-column: 1; grid-row: 1; }
.crop-align-buttons [data-align='center-x'] { grid-column: 2; grid-row: 1; }
.crop-align-buttons [data-align='right'] { grid-column: 3; grid-row: 1; }
.crop-align-buttons [data-align='top-left'] { grid-column: 4; grid-row: 1; }
.crop-align-buttons [data-align='top-right'] { grid-column: 5; grid-row: 1; }
.crop-align-buttons [data-align='top'] { grid-column: 1; grid-row: 2; }
.crop-align-buttons [data-align='center-y'] { grid-column: 2; grid-row: 2; }
.crop-align-buttons [data-align='bottom'] { grid-column: 3; grid-row: 2; }
.crop-align-buttons [data-align='bottom-left'] { grid-column: 4; grid-row: 2; }
.crop-align-buttons [data-align='bottom-right'] { grid-column: 5; grid-row: 2; }
.crop-align-buttons [data-align='center'] {
  grid-column: 6;
  grid-row: 1 / 3;
  height: 65px;
}

.align-icon {
  position: relative;
  display: block;
  width: 18px;
  height: 17px;
  border: 1px solid currentColor;
  border-radius: 2px;
  opacity: .82;
}

.align-icon::before {
  content: '';
  position: absolute;
  background: currentColor;
  border-radius: 1px;
}

.align-left::before,
.align-center-x::before,
.align-right::before {
  top: 3px;
  width: 7px;
  height: 9px;
}

.align-left::before { left: 2px; }
.align-center-x::before { left: 50%; transform: translateX(-50%); }
.align-right::before { right: 2px; }

.align-top::before,
.align-center-y::before,
.align-bottom::before {
  left: 3px;
  width: 10px;
  height: 6px;
}

.align-top::before { top: 2px; }
.align-center-y::before { top: 50%; transform: translateY(-50%); }
.align-bottom::before { bottom: 2px; }

.align-center::before,
.align-top-left::before,
.align-top-right::before,
.align-bottom-left::before,
.align-bottom-right::before {
  width: 8px;
  height: 7px;
}

.align-center::before {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.align-top-left::before { left: 2px; top: 2px; }
.align-top-right::before { right: 2px; top: 2px; }
.align-bottom-left::before { left: 2px; bottom: 2px; }
.align-bottom-right::before { right: 2px; bottom: 2px; }

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

.editor-align-control {
  display: flex;
  grid-column: 1 / -1;
  grid-row: 3;
  order: 3;
  margin: 12px 0 0;
  padding: 10px 12px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
}

.crop-editor .editor-ratio-bar {
  grid-row: 5;
  order: 5;
}

.crop-editor .editor-panel > p {
  display: none;
}

.crop-editor .editor-actions {
  grid-column: 1 / -1;
  grid-row: 4;
  justify-content: flex-end;
}

.editor-align-control .crop-align-buttons {
  display: flex;
  flex-wrap: nowrap;
  width: max-content;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: thin;
}

.editor-align-control .crop-align-buttons [data-align] {
  width: 30px;
  height: 30px;
  min-width: 30px;
}

@media (max-width: 640px) {
  .editor-align-control {
    justify-content: flex-start;
  }
}

/* Make every point along the four crop edges draggable. */
.inline-crop b.n,
.inline-crop b.s {
  left: 0;
  width: 100%;
  height: 16px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  transform: none;
}

.inline-crop b.n { top: -8px; }
.inline-crop b.s { top: auto; bottom: -8px; }

.inline-crop b.e,
.inline-crop b.w {
  top: 0;
  width: 16px;
  height: 100%;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  transform: none;
}

.inline-crop b.e { right: -8px; left: auto; }
.inline-crop b.w { right: auto; left: -8px; }

.inline-crop b:is(.n,.s,.e,.w)::after,
#crop-selection .crop-handle:is(.n,.s,.e,.w)::after {
  content: '';
  position: absolute;
  border: 1px solid rgba(20,40,70,.55);
  border-radius: 2px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.4);
  pointer-events: none;
}

.inline-crop b:is(.n,.s)::after,
#crop-selection .crop-handle:is(.n,.s)::after {
  top: 50%;
  left: 50%;
  width: 20px;
  height: 5px;
  transform: translate(-50%,-50%);
}

.inline-crop b:is(.e,.w)::after,
#crop-selection .crop-handle:is(.e,.w)::after {
  top: 50%;
  left: 50%;
  width: 5px;
  height: 20px;
  transform: translate(-50%,-50%);
}

#crop-selection .crop-handle.n,
#crop-selection .crop-handle.s {
  left: 0;
  width: 100%;
  height: 18px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  transform: none;
}

#crop-selection .crop-handle.n { top: -9px; }
#crop-selection .crop-handle.s { top: auto; bottom: -9px; }

#crop-selection .crop-handle.e,
#crop-selection .crop-handle.w {
  top: 0;
  width: 18px;
  height: 100%;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  transform: none;
}

#crop-selection .crop-handle.e { right: -9px; left: auto; }
#crop-selection .crop-handle.w { right: auto; left: -9px; }

.inline-crop b:is(.nw,.ne,.se,.sw),
#crop-selection .crop-handle:is(.nw,.ne,.se,.sw) {
  z-index: 7;
}

/* Small grid: compact, full-width control under the file details. */
.results.grid-view:not(.medium-grid-view):not(.large-grid-view):not(.card-view)
  .per-image-rotate {
  padding: 8px 9px 7px;
}

.results.grid-view:not(.medium-grid-view):not(.large-grid-view):not(.card-view)
  .per-image-rotate > strong {
  font-size: 9px;
}

.results.grid-view:not(.medium-grid-view):not(.large-grid-view):not(.card-view)
  .per-image-rotate .crop-rotate-row {
  grid-template-columns: minmax(60px, 1fr) 54px;
  gap: 6px;
}

.results.grid-view:not(.medium-grid-view):not(.large-grid-view):not(.card-view)
  .per-image-rotate .crop-rotate-row > label {
  min-height: 31px;
}

/* Medium grid: balanced control aligned with the card width. */
.results.medium-grid-view:not(.card-view) .per-image-rotate {
  max-width: 360px;
  margin-inline: auto;
}

/* Large grid: wider slider with comfortable spacing. */
.results.large-grid-view:not(.card-view) .per-image-rotate {
  width: min(460px, 100%);
  margin-inline: auto;
  padding: 11px 13px 9px;
}

.results.large-grid-view:not(.card-view) .per-image-rotate .crop-rotate-row {
  grid-template-columns: minmax(140px, 1fr) 62px;
}

/* Row views: keep the control centered and proportional to the preview. */
.results.card-view .file-info {
  display: grid;
  justify-items: center;
  text-align: center;
}

.results.card-view .file-info > strong,
.results.card-view .file-info > span {
  max-width: min(680px, 100%);
}

.results.card-view .per-image-rotate {
  width: min(520px, 100%);
  margin: 12px auto 2px;
  text-align: left;
}

.results.card-small-view .per-image-rotate {
  width: min(380px, 100%);
  padding: 8px 10px 7px;
}

.results.card-medium-view .per-image-rotate {
  width: min(460px, 100%);
}

.results.card-view:not(.card-small-view):not(.card-medium-view)
  .per-image-rotate .crop-rotate-row {
  grid-template-columns: minmax(220px, 1fr) 64px;
  gap: 12px;
}

@media (max-width: 560px) {
  .per-image-rotate,
  .results.card-view .per-image-rotate {
    width: 100%;
    padding: 8px 9px 7px;
  }

  .results.card-view .file-info {
    justify-items: stretch;
    text-align: left;
  }

  .results.card-view .per-image-rotate .crop-rotate-row {
    grid-template-columns: minmax(70px, 1fr) 56px;
    gap: 7px;
  }
}

/* Organized CROP EDITOR layout. */
.crop-editor .editor-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto auto auto;
  column-gap: 14px;
}

.crop-editor .editor-head {
  grid-column: 1 / -1;
  grid-row: 1;
  order: 1;
  padding-bottom: 10px;
}

.crop-editor .editor-viewport {
  grid-column: 1 / -1;
  grid-row: 2;
  order: 2;
  min-height: clamp(360px, 55vh, 620px);
}

.crop-editor .editor-align-control {
  grid-column: 1;
  grid-row: 3;
  order: 3;
  min-width: 0;
  margin: 12px 0 0;
  padding: 8px 10px;
  justify-content: flex-start;
}

.crop-editor .editor-actions {
  grid-column: 2;
  grid-row: 3;
  order: 3;
  align-self: stretch;
  align-items: center;
  margin: 12px 0 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
}

.crop-editor .editor-ratio-bar {
  grid-column: 1 / -1;
  grid-row: 4;
  order: 4;
  margin: 14px 0 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
}

.crop-editor .editor-ratios button {
  min-height: 54px;
}

@media (max-width: 760px) {
  .crop-editor .editor-panel {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto auto auto;
  }

  .crop-editor .editor-align-control {
    grid-column: 1;
    grid-row: 3;
    overflow: hidden;
  }

  .crop-editor .editor-actions {
    grid-column: 1;
    grid-row: 4;
    justify-content: stretch;
  }

  .crop-editor .editor-actions button {
    flex: 1 1 0;
  }

  .crop-editor .editor-ratio-bar {
    grid-row: 5;
  }
}

/* Keep the editor action group anchored to the right edge. */
.crop-editor .editor-align-control > .editor-actions {
  margin-left: auto;
  justify-content: flex-end;
}

@media (max-width: 620px) {
  .crop-editor .editor-align-control > .editor-actions {
    margin-left: auto;
    justify-content: flex-end;
  }
}

/* Ratio presets must remain fully visible; never create their own vertical scroller. */
.crop-editor .editor-ratio-bar {
  max-height: none;
  overflow-x: visible;
  overflow-y: visible;
}

.crop-editor .editor-ratios {
  overflow: visible;
}

@media (min-width: 761px) {
  .crop-editor .editor-ratios {
    height: 100%;
    grid-template-rows: repeat(10, minmax(34px, 1fr));
  }

  .crop-editor .editor-ratios button {
    min-height: 34px;
    height: auto;
  }
}

@media (max-width: 760px) {
  .crop-editor .editor-ratio-bar {
    max-height: none;
    overflow: visible;
  }

  .crop-editor .editor-ratios {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    overflow: visible;
  }

  .crop-editor .editor-ratios button {
    width: 100%;
    min-width: 0;
    min-height: 46px;
  }
}

/* Use the available screen width and always fit the image inside its viewport. */
.crop-editor {
  padding: 8px;
}

.crop-editor .editor-panel {
  width: min(1480px, calc(100vw - 32px));
  max-width: 1480px;
  max-height: calc(100dvh - 24px);
  padding: 18px;
}

.crop-editor .editor-viewport {
  min-width: 0;
  overflow: hidden;
}

/* Responsive editor dimensions for desktop, laptop, tablet and phone screens. */
.crop-editor {
  padding: clamp(6px, 1.2vw, 18px);
}

.crop-editor .editor-panel {
  width: min(94vw, 1480px);
  height: min(94dvh, 920px);
  max-width: 1480px;
  max-height: 94dvh;
  padding: clamp(12px, 1.4vw, 20px);
  overflow: hidden;
  grid-template-rows: auto minmax(240px, 1fr) auto;
}

.crop-editor .editor-ratio-bar {
  height: 100%;
  max-height: none;
}

.crop-editor .editor-viewport {
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: clamp(8px, 1.2vw, 20px);
}

@media (max-width: 1100px) {
  .crop-editor .editor-panel {
    width: min(96vw, 1180px);
    height: min(96dvh, 860px);
    max-height: 96dvh;
  }

  .crop-editor .editor-align-control {
    gap: 7px;
  }

  .editor-quick-options .extra-ratio-control {
    flex-basis: 160px;
  }
}

@media (max-width: 760px) {
  .crop-editor {
    padding: 5px;
  }

  .crop-editor .editor-panel {
    width: calc(100vw - 10px);
    height: calc(100dvh - 10px);
    max-width: none;
    max-height: none;
    padding: 10px;
    overflow-x: hidden;
    overflow-y: auto;
    grid-template-rows: auto auto minmax(260px, 56dvh) auto;
  }

  .crop-editor .editor-ratio-bar {
    height: auto;
    max-height: 170px;
    overflow-y: auto;
  }

  .crop-editor .editor-viewport {
    min-height: 260px;
  }
}

@media (max-width: 480px) {
  .crop-editor .editor-panel {
    padding: 8px;
    grid-template-rows: auto auto minmax(220px, 48dvh) auto;
  }

  .crop-editor .editor-head h2 {
    font-size: 1.15rem;
  }

  .crop-editor .editor-ratio-bar {
    max-height: 145px;
  }

  .crop-editor .editor-viewport {
    min-height: 220px;
    padding: 6px;
  }
}

@media (max-height: 700px) and (min-width: 761px) {
  .crop-editor .editor-panel {
    height: calc(100dvh - 12px);
    max-height: calc(100dvh - 12px);
    padding-block: 10px;
  }

  .crop-editor .editor-head {
    padding-bottom: 5px;
  }

  .crop-editor .editor-align-control {
    margin-top: 7px;
    padding-block: 6px;
  }
}

/* CROP EDITOR: ratio presets beside the image, quick options before alignment. */
.crop-editor .editor-panel {
  grid-template-columns: 176px minmax(0, 1fr);
  grid-template-rows: auto auto auto;
}

.crop-editor .editor-head {
  grid-column: 1 / -1;
  grid-row: 1;
}

.crop-editor .editor-ratio-bar {
  grid-column: 1;
  grid-row: 2;
  order: 2;
  align-self: stretch;
  align-content: start;
  margin: 0 12px 0 0;
  padding: 10px;
  max-height: clamp(360px, 55vh, 620px);
  overflow-y: auto;
}

.crop-editor .editor-ratios {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.crop-editor .editor-ratios button {
  min-height: 52px;
  padding: 6px 4px;
}

.crop-editor .editor-viewport {
  grid-column: 2;
  grid-row: 2;
  order: 2;
}

.crop-editor .editor-align-control {
  grid-column: 2;
  grid-row: 3;
  order: 3;
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 12px;
}

.editor-quick-options {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex: 0 0 auto;
  min-width: 0;
}

.editor-quick-options .extra-ratio-control {
  flex: 0 0 180px;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.editor-quick-options .extra-ratio-control > span {
  display: none;
}

.editor-quick-options .extra-ratio-control select {
  margin: 0;
  min-height: 34px;
}

.editor-quick-options .aspect-lock-control {
  flex: 0 0 auto;
  width: auto;
  min-width: max-content;
  min-height: 34px;
  margin: 0;
  padding: 5px 7px;
  gap: 5px;
  white-space: nowrap;
}

.editor-quick-options .aspect-lock-control span {
  width: auto;
  white-space: nowrap;
  overflow-wrap: normal;
}

.crop-editor .editor-align-control > .crop-align-buttons {
  flex: 0 0 auto;
}

.crop-editor .editor-align-control > .editor-actions {
  display: flex;
  flex: 0 0 auto;
  grid-column: auto;
  grid-row: auto;
  order: initial;
  align-self: flex-end;
  margin: 0 0 0 auto;
  padding: 0;
  border: 0;
  background: transparent;
  justify-content: flex-end;
}

@media (max-width: 900px) {
  .crop-editor .editor-panel {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto auto;
  }

  .crop-editor .editor-ratio-bar {
    grid-column: 1;
    grid-row: 2;
    margin: 0 0 10px;
    max-height: none;
    overflow: visible;
  }

  .crop-editor .editor-ratios {
    grid-template-columns: repeat(5, minmax(58px, 1fr));
  }

  .crop-editor .editor-viewport {
    grid-column: 1;
    grid-row: 3;
  }

  .crop-editor .editor-align-control {
    grid-column: 1;
    grid-row: 4;
  }
}

/* Final ratio overflow policy: show every preset without an inner vertical scrollbar. */
.crop-editor .editor-ratio-bar {
  max-height: none;
  overflow-x: visible;
  overflow-y: visible;
}

.crop-editor .editor-ratios {
  overflow: visible;
}

@media (min-width: 761px) {
  .crop-editor .editor-ratios {
    height: 100%;
    grid-template-rows: repeat(10, minmax(34px, 1fr));
  }

  .crop-editor .editor-ratios button {
    min-height: 34px;
    height: auto;
  }
}

@media (max-width: 760px) {
  .crop-editor .editor-ratio-bar {
    max-height: none;
    overflow: visible;
  }

  .crop-editor .editor-ratios {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    overflow: visible;
  }

  .crop-editor .editor-ratios button {
    width: 100%;
    min-width: 0;
    min-height: 46px;
  }
}

@media (max-width: 620px) {
  .crop-editor .editor-ratios {
    grid-template-columns: repeat(3, minmax(58px, 1fr));
  }

  .editor-quick-options {
    flex-basis: 100%;
    flex-wrap: wrap;
  }

  .crop-editor .editor-align-control > .editor-actions {
    width: 100%;
    margin-left: auto;
    justify-content: flex-end;
  }
}

/* Keep all preset aspect-ratio buttons on one horizontal row. */
.crop-editor .editor-panel {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto auto auto;
}

.crop-editor .editor-ratio-bar {
  grid-column: 1;
  grid-row: 2;
  margin: 0 0 10px;
  max-height: none;
  overflow: hidden;
}

.crop-editor .editor-ratios {
  display: flex;
  flex-wrap: nowrap;
  width: 100%;
  gap: 7px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  padding-bottom: 3px;
}

.crop-editor .editor-ratios button {
  flex: 0 0 72px;
  width: 72px;
  min-width: 72px;
}

.crop-editor .editor-viewport {
  grid-column: 1;
  grid-row: 3;
}

.crop-editor .editor-align-control {
  grid-column: 1;
  grid-row: 4;
}

/* Desktop: one vertical ratio column on the left side of the image. */
.crop-editor .editor-panel {
  grid-template-columns: 104px minmax(0, 1fr);
  grid-template-rows: auto auto auto;
}

.crop-editor .editor-ratio-bar {
  grid-column: 1;
  grid-row: 2;
  align-self: stretch;
  margin: 0 12px 0 0;
  padding: 9px;
  max-height: none;
  overflow: visible;
}

.crop-editor .editor-ratios {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  width: 100%;
  gap: 6px;
  overflow: visible;
  padding: 0;
}

.crop-editor .editor-ratios button {
  width: 100%;
  min-width: 0;
  min-height: 52px;
}

.crop-editor .editor-viewport {
  grid-column: 2;
  grid-row: 2;
}

.crop-editor .editor-align-control {
  grid-column: 2;
  grid-row: 3;
}

@media (max-width: 760px) {
  .crop-editor .editor-panel {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto auto;
  }

  .crop-editor .editor-ratio-bar {
    grid-column: 1;
    grid-row: 2;
    margin: 0 0 10px;
    max-height: none;
    overflow: visible;
  }

  .crop-editor .editor-viewport {
    grid-column: 1;
    grid-row: 3;
  }

  .crop-editor .editor-align-control {
    grid-column: 1;
    grid-row: 4;
  }
}
