:root {
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-padding-top: 88px;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.08), transparent 32%),
    linear-gradient(180deg, #0f0f10 0%, #0a0a0b 100%);
  color: #f5f5f5;
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  display: block;
  max-width: 100%;
}

button,
input,
textarea,
select {
  color: inherit;
  font: inherit;
}

button {
  cursor: pointer;
}

textarea {
  resize: vertical;
}

.glass {
  background: rgba(12, 12, 13, 0.72);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.gallery-thumb {
  transition:
    transform 400ms ease,
    opacity 250ms ease;
}

.gallery-card:hover .gallery-thumb {
  transform: scale(1.03);
}

.gallery-overlay {
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, 0.58),
    rgba(0, 0, 0, 0.08) 55%,
    rgba(0, 0, 0, 0)
  );
  opacity: 0;
  transition: opacity 240ms ease;
}

.gallery-card:hover .gallery-overlay,
.gallery-card:focus-within .gallery-overlay {
  opacity: 1;
}

.modal-shell {
  display: none;
  z-index: 70;
}

.modal-shell.is-open {
  display: flex;
}

.modal-base {
  align-items: center;
  justify-content: center;
}

.modal-top {
  align-items: center;
  justify-content: center;
}

.detail-modal-panel {
  background: linear-gradient(
    180deg,
    rgba(20, 20, 21, 0.98) 0%,
    rgba(13, 13, 14, 0.98) 100%
  );
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
  max-height: 92dvh;
  overflow: hidden;
}

.detail-modal-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(340px, 420px);
  min-height: 0;
}

.detail-media {
  min-height: 320px;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.detail-media #detailPicture,
.detail-media #detailImage {
  width: 100%;
  height: 100%;
}

.detail-media #detailPicture {
  display: flex;
  align-items: center;
  justify-content: center;
}

.detail-media #detailImage {
  max-height: 92dvh;
  object-fit: contain;
  object-position: center;
}

.detail-sidebar {
  min-height: 0;
  overflow-y: auto;
}

/* Cropper Styles - Updated */
#uploadPreviewStage,
#editPreviewStage {
  position: relative;
  overflow: hidden;
  border-radius: 1.25rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.32);
  min-height: 260px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#uploadPreviewImage,
#editPreviewImage {
  display: block;
  max-width: 100%;
  max-height: 60dvh;
  width: auto;
  height: auto;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

#uploadCropBox,
#editCropBox {
  position: absolute;
  display: none;
  border: 2px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
  cursor: move;
  z-index: 10;
  pointer-events: auto;
}

.crop-handle {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: white;
  border: 2px solid black;
  z-index: 12;
  pointer-events: auto;
}

.crop-handle.nw {
  top: -8px;
  left: -8px;
  cursor: nwse-resize;
}

.crop-handle.ne {
  top: -8px;
  right: -8px;
  cursor: nesw-resize;
}

.crop-handle.sw {
  bottom: -8px;
  left: -8px;
  cursor: nesw-resize;
}

.crop-handle.se {
  bottom: -8px;
  right: -8px;
  cursor: nwse-resize;
}

.crop-overlay {
  position: absolute;
  inset: 0;
  cursor: move;
  z-index: 11;
}

.secret-reveal {
  animation: fadePop 320ms ease;
}

@keyframes fadePop {
  0% {
    opacity: 0;
    transform: translateY(8px) scale(0.96);
  }

  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 1023px) {
  .gallery-overlay {
    opacity: 1;
    background: linear-gradient(
      to top,
      rgba(0, 0, 0, 0.66),
      rgba(0, 0, 0, 0.16) 55%,
      rgba(0, 0, 0, 0)
    );
  }

  .detail-modal-layout {
    grid-template-columns: 1fr;
  }

  .detail-sidebar {
    border-left: 0;
  }
}

@media (max-width: 767px) {
  html {
    scroll-padding-top: 78px;
  }

  body {
    overflow-x: hidden;
  }

  .modal-base,
  .modal-top {
    align-items: center;
    justify-content: center;
  }

  .modal-shell {
    padding: max(24px, env(safe-area-inset-top)) 20px
      max(24px, env(safe-area-inset-bottom)) 20px;
  }

  .modal-shell > .relative {
    width: 100%;
    margin: 0;
  }

  .detail-modal-panel {
    width: 100%;
    max-width: 100%;
    height: calc(
      100dvh - 48px - env(safe-area-inset-top) - env(safe-area-inset-bottom)
    );
    max-height: calc(
      100dvh - 48px - env(safe-area-inset-top) - env(safe-area-inset-bottom)
    );
    border-radius: 1.5rem;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
  }

  .detail-modal-layout {
    display: flex;
    flex-direction: column;
    min-height: max-content;
  }

  .detail-media {
    display: block;
    min-height: auto;
    height: auto;
    background: #000;
    flex: 0 0 auto;
    overflow: hidden;
    border-top-left-radius: 1.5rem;
    border-top-right-radius: 1.5rem;
  }

  .detail-media #detailPicture {
    display: block;
    width: 100%;
    height: auto;
  }

  .detail-media #detailImage {
    display: block;
    width: 100%;
    height: auto;
    max-height: 40dvh;
    object-fit: contain;
    object-position: center top;
    margin: 0 auto;
    background: #000;
  }

  .detail-sidebar {
    overflow: visible;
    flex: 0 0 auto;
    min-height: auto;
    padding: 1rem 1rem calc(1.5rem + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    background: linear-gradient(
      180deg,
      rgba(24, 24, 25, 0.98) 0%,
      rgba(17, 17, 18, 0.99) 100%
    );
  }

  .detail-sidebar::before {
    content: "";
    width: 3rem;
    height: 0.34rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.22);
    display: block;
    margin: 0 auto 1rem;
  }

  #detailTitle {
    font-size: 1.6rem;
    line-height: 1.08;
  }

  #detailDescription {
    font-size: 1rem;
    line-height: 1.8;
    overflow-wrap: anywhere;
  }

  #detailCreators {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  #closeDetailModal,
  #detailOpenFull,
  #detailEditButton {
    min-height: 44px;
  }

  #uploadPreviewImage,
  #editPreviewImage {
    max-height: 42dvh;
  }

  .gallery-card {
    border-radius: 1.1rem;
  }
}

@media (max-width: 480px) {
  .modal-shell {
    padding: max(28px, env(safe-area-inset-top)) 22px
      max(28px, env(safe-area-inset-bottom)) 22px;
  }

  .detail-modal-panel {
    height: calc(
      100dvh - 56px - env(safe-area-inset-top) - env(safe-area-inset-bottom)
    );
    max-height: calc(
      100dvh - 56px - env(safe-area-inset-top) - env(safe-area-inset-bottom)
    );
    border-radius: 1.4rem;
  }

  .detail-media {
    border-top-left-radius: 1.4rem;
    border-top-right-radius: 1.4rem;
  }

  .detail-media #detailImage {
    max-height: 38dvh;
  }

  .detail-sidebar {
    padding-inline: 1rem;
  }

  #detailTitle {
    font-size: 1.45rem;
  }

  #detailDescription {
    line-height: 1.72;
  }
}
