/* Media Manager - 04-modal.css */

/* ---------- Modal ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  animation: overlayIn .18s var(--ease) both;
  z-index: 60;
}

@keyframes overlayIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.modal {
  width: min(980px, 100%);
  background: rgba(26, 26, 26, .86);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: relative;
  animation: modalIn .22s var(--ease) both;
}

.modal--wide {
  width: min(1080px, 100%);
}

@keyframes modalIn {
  from {
    transform: translateY(10px) scale(.99);
    opacity: 0;
  }

  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.modal__close {
  position: absolute;
  right: 10px;
  top: 10px;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-card);
  color: var(--text);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  transition: transform .15s var(--ease), border-color .15s var(--ease), box-shadow .15s var(--ease);
}

.modal__close:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(0, 0, 0, .40);
}

.modal__content {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 14px;
  padding: 14px;
}

.modal__image {
  width: 100%;
  aspect-ratio: 2 / 3;
  height: auto;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #0f0f0f;
}

#modalOverlay[data-kind="music"] .modal__image {
  aspect-ratio: 1 / 1;
  object-fit: contain;
}

.modal__details {
  padding: 4px 4px 10px;
  overflow: auto;
  max-height: min(78vh, 820px);
}

/* Badge row */
.modal__badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 8px 0 6px;
}

.badge {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface-card);
  border: 1px solid var(--border);
  color: rgba(255, 255, 255, .82);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

/* DL rows */
.dl {
  margin: 14px 0 0;
}

.dl__row {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--border-subtle);
}

.dl__row dt {
  color: var(--muted);
}

.dl__row dd {
  margin: 0;
}

/* Blocks below dl */
.modal__block {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
}

#modalOverview {
  white-space: pre-wrap;
}

/* Details disclosure */
details summary {
  cursor: pointer;
  list-style: none;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

details summary::-webkit-details-marker {
  display: none;
}

details summary::after {
  content: "▸";
  display: inline-block;
  transform: translateY(-1px);
  opacity: .85;
}

details[open] summary::after {
  content: "▾";
}

/* Debug */
.debug {
  margin-top: 14px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, .25);
  color: #cfcfcf;
  overflow: auto;
  max-height: 200px;
}

@media (max-width: 860px) {
  .modal__content {
    grid-template-columns: 1fr;
  }

  .modal__image {
    max-height: 420px;
  }

  .header__inner {
    align-items: flex-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  body::before {
    animation: none;
  }

  body::after {
    animation: none;
  }

  html::before {
    display: none;
  }

  .fab-home {
    transition: none;
  }

  .card,
  .card * {
    transition: none !important;
  }
}

/* ===========================
   Item Modal — Image Handling
   =========================== */

/* Default: show full artwork without cropping */
.modal__image {
  width: 100%;
  height: auto;
  max-height: 60vh;
  object-fit: contain;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 16px;
}

/* ===========================
   Item Modal — Mobile Layout
   =========================== */
@media (max-width: 720px) {
  /* Let the modal use the viewport and keep the close button reachable */
  .overlay {
    padding: 10px;
    align-items: stretch;
  }

  .modal {
    width: 100%;
    max-height: calc(100vh - 20px);
    overflow: hidden;
    border-radius: 16px;
  }

  /* Stack image above details */
  .modal__content {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px;
  }

  /* Image should not dominate the screen */
  .modal__image {
    max-height: 34vh;
    object-fit: contain;
    padding: 8px;
    background: rgba(0, 0, 0, 0.35);
    border-radius: 14px;
  }

  /* Make details scrollable so the close button stays accessible */
  .modal__details {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 18px;
    scrollbar-gutter: stable both-edges;
  }

  /* Always keep close button in a reachable place */
  .modal__close {
    position: fixed;
    top: 14px;
    z-index: 80;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }

  /* Tighten typography + spacing */
  #modalTitle.h2, #modalTitle {
    font-size: 18px;
    line-height: 1.2;
    margin-right: 52px; /* breathing room for the close button */
  }

  .modal__block {
    margin-top: 12px;
    padding-top: 12px;
  }

  /* Facts: two-column grid for better density */
  .dl {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 14px;
    margin-top: 12px;
  }

  .dl__row {
    display: block;
    border-top: 0;
    padding: 10px 0;
  }

  .dl__row dt {
    font-size: 12px;
    letter-spacing: .02em;
    margin: 0 0 4px;
    color: var(--muted);
  }

  .dl__row dd {
    margin: 0;
  }
}

/* Extra-small phones: fall back to 1 column to avoid cramped cells */
@media (max-width: 360px) {
  .dl {
    grid-template-columns: 1fr;
  }
}

/* ===========================
   Modal Close Button — Scrollbar Safe
   =========================== */

/* Offset close button from scrollbar (uses reserved gutter where supported) */
.modal__close {
  right: 28px; /* safe default */
}

@supports (scrollbar-gutter: stable) {
  .modal__details {
    scrollbar-gutter: stable both-edges;
  }
}
