:root {
  --ship-photo-ratio: 16 / 9;
}

.ship-photo-crop {
  box-sizing: border-box;
  width: min(960px, calc(100% - 32px));
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid #69404c;
  background: #141115;
  color: var(--white, #f3f1ef);
  box-shadow: 0 28px 90px #000b;
}

.ship-photo-crop[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  animation: ship-photo-crop-enter 260ms cubic-bezier(.2, .75, .25, 1) both;
}

.ship-photo-crop::backdrop {
  background: #08060ac9;
  backdrop-filter: blur(5px);
}

@keyframes ship-photo-crop-enter {
  from { opacity: 0; transform: translateY(10px) scale(.987); }
  to { opacity: 1; transform: none; }
}

.ship-photo-crop-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px;
  border-bottom: 1px solid #362a31;
}

.ship-photo-crop-kicker {
  color: #e77586;
  font-size: 10px;
  font-weight: 650;
  letter-spacing: .16em;
}

.ship-photo-crop-header h2 {
  margin: 7px 0 0;
  font-size: clamp(22px, 3vw, 30px);
  line-height: 1.2;
}

.ship-photo-crop-ratio {
  padding: 7px 10px;
  border: 1px solid #68404b;
  background: #2b1a22;
  color: #f2bac4;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.ship-photo-crop-body {
  display: grid;
  grid-template-columns: minmax(0, 2.4fr) minmax(180px, 1fr);
  align-items: start;
  gap: 20px;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 22px 24px;
}

.ship-photo-crop-frame {
  position: relative;
  border: 1px solid #97616c;
  background: #111;
}

.ship-photo-crop-frame::after {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, transparent calc(100% - 1px), #fff5 0) 0 0 / calc(100% / 3) 100%,
    linear-gradient(transparent calc(100% - 1px), #fff5 0) 0 0 / 100% calc(100% / 3);
  pointer-events: none;
  content: "";
}

.ship-photo-crop canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: var(--ship-photo-ratio);
}

/* Preserve the uploaded composition in previews, thumbnails and ship details. */
.custom-photo-preview > img {
  display: block;
  width: min(100%, 480px);
  height: auto;
  max-height: none;
  aspect-ratio: var(--ship-photo-ratio);
  object-fit: contain;
  margin-inline: auto;
}

.dashboard-ship-art:has(> img[data-ship-image="upload"]),
.profile-ship-grid .fleet-image:has(> img[data-ship-image="upload"]),
.detail-cover:has(> img[data-ship-image="upload"]) {
  height: auto;
  aspect-ratio: var(--ship-photo-ratio);
}

.dashboard-ship-art:has(> img[data-ship-image="upload"]) {
  align-self: center;
}

.dashboard-ship-art > img[data-ship-image="upload"],
.profile-ship-grid .fleet-image > img[data-ship-image="upload"],
.detail-cover > img[data-ship-image="upload"] {
  object-fit: contain;
}

.profile-ship-grid .fleet-card:hover .fleet-image > img[data-ship-image="upload"] {
  transform: none;
}

#ship-photo-crop-stage {
  touch-action: none;
  cursor: grab;
}

#ship-photo-crop-stage.is-dragging {
  cursor: grabbing;
}

.ship-photo-crop :is(canvas, input, button):focus-visible {
  outline: 2px solid #f47789;
  outline-offset: 3px;
}

.ship-photo-crop p {
  margin: 10px 0 0;
  color: #bfb0b7;
  font-size: 12px;
  line-height: 1.65;
}

.ship-photo-crop-scale {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 4ch;
  align-items: center;
  gap: 12px;
  margin-top: 13px;
  font-size: 13px;
}

.ship-photo-crop-scale input {
  width: 100%;
  min-width: 0;
  min-height: 38px;
  margin: 0;
  accent-color: #eb5269;
  cursor: pointer;
}

.ship-photo-crop-scale output {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.ship-photo-crop-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 9px;
}

.ship-photo-crop-tools button,
.ship-photo-crop-footer button {
  min-height: 42px;
  padding: 9px 13px;
  font-size: 12px;
  white-space: nowrap;
}

.ship-photo-crop button:disabled {
  opacity: .55;
  cursor: wait;
}

.ship-photo-crop-result {
  min-width: 0;
  padding: 12px;
  border: 1px solid #3f3038;
  background: #100e11;
}

.ship-photo-crop-result-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 9px;
  color: #d9c8cf;
  font-size: 12px;
}

#ship-photo-crop-size {
  color: #aa99a3;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ship-photo-crop-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: end;
  gap: 9px;
  padding: 13px 24px;
  border-top: 1px solid #362a31;
  background: #181319;
}

#ship-photo-crop-status {
  flex: 1 1 180px;
  margin: 0;
  color: #f3b5bf;
}

#ship-photo-crop-status:empty {
  display: none;
}

@media (max-width: 680px) {
  .ship-photo-crop {
    width: calc(100% - 20px);
    max-height: calc(100dvh - 20px);
  }

  .ship-photo-crop-body {
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
  }

  .ship-photo-crop-header,
  .ship-photo-crop-body,
  .ship-photo-crop-footer {
    padding: 14px;
  }

  .ship-photo-crop-result {
    width: min(100%, 360px);
  }

  .ship-photo-crop-tools button,
  .ship-photo-crop-footer button {
    min-height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ship-photo-crop[open] { animation: none; }
}

.motion-off .ship-photo-crop[open] {
  animation: none;
}
