.murph-cover-crop {
  position: fixed;
  inset: 0;
  z-index: 4000;
  display: grid;
  place-items: center;
  box-sizing: border-box;
  padding: max(0.5rem, env(safe-area-inset-top, 0px))
    max(0.5rem, env(safe-area-inset-right, 0px))
    max(0.5rem, env(safe-area-inset-bottom, 0px))
    max(0.5rem, env(safe-area-inset-left, 0px));
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

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

body.murph-cover-crop-open {
  overflow: hidden;
}

.murph-cover-crop-backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: rgba(15, 23, 42, 0.75);
}

.murph-cover-crop-panel {
  --murph-crop-chrome: 12.75rem;
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(100%, 34rem);
  max-height: calc(100vh - 1.25rem);
  max-height: calc(100dvh - 1.25rem);
  box-sizing: border-box;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: 1rem;
  background: var(--color-surface);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  padding: 1rem 1rem 0.85rem;
}

.murph-cover-crop-title {
  flex: 0 0 auto;
  margin: 0 0 0.3rem;
  font-size: 1.05rem;
  color: var(--color-text);
}

.murph-cover-crop-intro {
  flex: 0 0 auto;
  margin: 0 0 0.65rem;
  font-size: 0.84rem;
  line-height: 1.4;
  color: var(--color-text-muted);
}

.murph-cover-crop-viewport {
  position: relative;
  flex: 0 1 auto;
  /* Šířka i výška se vejdou do zbývajícího místa + poměr stran (JS nastaví --murph-crop-aspect) */
  --murph-crop-aspect: 2.35;
  width: min(100%, calc((100vh - var(--murph-crop-chrome)) * var(--murph-crop-aspect)));
  width: min(100%, calc((100dvh - var(--murph-crop-chrome)) * var(--murph-crop-aspect)));
  max-height: calc(100vh - var(--murph-crop-chrome));
  max-height: calc(100dvh - var(--murph-crop-chrome));
  aspect-ratio: var(--murph-crop-aspect);
  height: auto;
  margin: 0 auto 0.65rem;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-subtle, #f1f5f9);
}

/* Stejné „sklo“ jako karty ve feedu / panely — prázdné okraje při zmenšení fotky. */
.murph-cover-crop-viewport--panel-match {
  background: rgb(255 255 255 / calc(var(--glass-panel-pct, 40) * 1%));
}

.murph-cover-crop-viewport.is-dragging {
  cursor: grabbing;
}

.murph-cover-crop-image {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
  max-width: none;
}

.murph-cover-crop-frame {
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.45);
  pointer-events: none;
}

.murph-cover-crop-zoom {
  flex: 0 0 auto;
  display: grid;
  gap: 0.3rem;
  margin-bottom: 0.75rem;
}

.murph-cover-crop-zoom label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.murph-cover-crop-zoom input[type="range"] {
  width: 100%;
  accent-color: var(--color-primary);
}

.murph-cover-crop-actions {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
}

.murph-cover-crop-actions button {
  appearance: none;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 0.55rem 1rem;
  cursor: pointer;
  max-width: 100%;
}

.murph-cover-crop-actions button[data-murph-cover-crop-apply] {
  background: var(--color-primary);
  border-color: transparent;
  color: #fff;
}

.murph-cover-crop-actions button:hover,
.murph-cover-crop-actions button:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

@media (max-height: 720px) {
  .murph-cover-crop-panel {
    --murph-crop-chrome: 11.5rem;
    padding: 0.85rem 0.85rem 0.7rem;
  }

  .murph-cover-crop-intro {
    font-size: 0.8rem;
    margin-bottom: 0.45rem;
  }
}

@media (max-height: 600px) {
  .murph-cover-crop-panel {
    --murph-crop-chrome: 9.25rem;
  }

  .murph-cover-crop-intro {
    display: none;
  }

  .murph-cover-crop-title {
    font-size: 1rem;
    margin-bottom: 0.35rem;
  }

  .murph-cover-crop-zoom {
    margin-bottom: 0.5rem;
  }

  .murph-cover-crop-actions button {
    padding: 0.45rem 0.85rem;
    font-size: 0.88rem;
  }
}

@media (max-width: 480px) {
  .murph-cover-crop-panel {
    --murph-crop-chrome: 12.25rem;
    width: 100%;
    border-radius: 0.85rem;
  }

  .murph-cover-crop-actions {
    flex-direction: column-reverse;
  }

  .murph-cover-crop-actions button {
    width: 100%;
  }
}

@media (max-width: 480px) and (max-height: 700px) {
  .murph-cover-crop-panel {
    --murph-crop-chrome: 13.5rem;
  }

  .murph-cover-crop-intro {
    display: none;
  }
}

.cover-crop-preview {
  margin: 0.75rem 0 0;
}

.cover-crop-preview.hidden {
  display: none !important;
}

.cover-crop-preview-frame {
  aspect-ratio: 2.35 / 1;
  width: min(100%, calc(var(--post-feed-cover-h, 10rem) * 2.35));
  max-height: var(--post-feed-cover-h, 10rem);
  overflow: hidden;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: rgb(15 23 42 / 4%);
}

.cover-crop-preview-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
}

.cover-crop-preview--cropped .cover-crop-preview-frame img {
  object-fit: cover;
}

.cover-crop-preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
