/* ============================================================
   styles/gallery.css
   ============================================================ */

/*
 * WHAT: Responsive presentation of the MandArt discovery catalog.
 * WHY: Let existing artwork dominate the discovery experience.
 *
 * REQ: Preserve original artwork colors and aspect ratios.
 * REQ: Support desktop, tablet, and mobile screens.
 * REQ: Preserve existing catalog identifiers and event wiring.
 *
 * OBS: The existing catalog is presented as a modal.
 *      These styles also establish the foundation for
 *      a permanent Discover workspace.
 */

@media screen {
  /* ==========================================================
     DISCOVERY GALLERY
     ========================================================== */

  #catalogModal {
    position: fixed;

    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);

    width: min(96vw, 1400px);
    max-width: none;

    max-height: 90vh;
    max-height: 90dvh;

    padding: var(--ui-space-xl);

    background: var(--ui-background);
    color: var(--ui-text);

    border: 1px solid var(--ui-border-strong);
    border-radius: var(--ui-radius-md);

    box-shadow: 0 12px 64px rgb(0 0 0 / 60%);
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  #catalogModal .modal-content {
    padding-top: var(--ui-space-md);
  }

  #catalogModal h2 {
    margin: 0 44px var(--ui-space-xl);

    font-size: clamp(1.25rem, 3vw, 2rem);
    font-weight: 500;
    text-align: center;
  }

  #catalogCloseBtn {
    top: 0;
    right: 0;

    width: 44px;
    height: 44px;

    background: var(--ui-surface-raised);
    color: var(--ui-text);

    border-radius: var(--ui-radius-sm);
  }

  #catalogCloseBtn:hover {
    background: var(--ui-border);
    color: var(--ui-accent);
  }

  /* ==========================================================
     RESPONSIVE ARTWORK GRID
     ========================================================== */

  #mandartList {
    display: grid;

    grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr));

    align-items: start;
    gap: var(--ui-space-lg);
    padding: 0;
  }

  .mandart-item {
    display: flex;
    flex-direction: column;

    width: 100%;
    max-width: none;
    min-width: 0;

    padding: var(--ui-space-xs);

    background: var(--ui-surface);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-sm);

    box-shadow: none;
    cursor: pointer;
    overflow: hidden;
  }

  .mandart-item:hover {
    transform: none;
    border-color: var(--ui-accent);
    box-shadow: none;
  }

  /*
   * REQ: Never crop or recolor original discovery thumbnails.
   */

  .mandart-item img {
    display: block;

    width: 100%;
    max-width: none;
    height: auto;

    aspect-ratio: 1;
    object-fit: contain;

    background: var(--ui-canvas-background);
    border-radius: 0;
  }

  .mandart-item span {
    margin: 0;
    padding: var(--ui-space-sm);

    background: transparent;
    color: var(--ui-text-secondary);

    font-size: 0.875rem;
    text-align: left;
    overflow-wrap: anywhere;
  }

  .catalog-loading,
  .catalog-error {
    grid-column: 1 / -1;

    padding: var(--ui-space-xl);
    color: var(--ui-text-secondary);
    text-align: center;
  }

  /* ==========================================================
     TABLET AND PHONE
     ========================================================== */

  @media (max-width: 900px) {
    #mandartList {
      grid-template-columns: repeat(auto-fill, minmax(min(180px, 100%), 1fr));
    }
  }

  @media (max-width: 600px) {
    #catalogModal {
      width: calc(100vw - 16px);
      padding: var(--ui-space-md);
    }

    #catalogModal h2 {
      font-size: 1.25rem;
    }

    #mandartList {
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: var(--ui-space-sm);
    }

    .mandart-item span {
      font-size: 0.75rem;
    }
  }
}

/* ============================================================
   DISCOVERY GALLERY TOOLBAR
   ============================================================ */

/*
 * WHAT: Search, classification filters, and discovery actions.
 * WHY: Provide multiple ways to discover artwork while keeping
 *      the artwork itself visually dominant.
 *
 * REQ: Use existing neutral surfaces and accent colors.
 * REQ: Support keyboard, pointer, and touch interactions.
 * REQ: Keep controls compact on desktop and usable on mobile.
 */

@media screen {
  .gallery-toolbar {
    display: flex;
    flex-direction: column;

    gap: var(--ui-space-md);
    margin-bottom: var(--ui-space-xl);
  }

  .gallery-toolbar p {
    margin: 0;
    color: var(--ui-text-secondary);
    font-size: 0.9375rem;
    text-align: left;
  }

  /* === INTRODUCTION AND SURPRISE ACTION === */

  .gallery-intro {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;

    gap: var(--ui-space-md);
  }

  .gallery-intro p {
    flex: 1;
    min-width: min(240px, 100%);
  }

  #gallerySurpriseBtn {
    min-height: var(--ui-target-size);
    padding: var(--ui-space-sm) var(--ui-space-xl);

    background: var(--ui-accent);
    color: var(--ui-accent-text);

    border-radius: var(--ui-radius-sm);
    font-weight: 600;
  }

  #gallerySurpriseBtn:hover:not(:disabled) {
    background: var(--ui-accent-hover);
  }

  /* === SEARCH AND RESET === */

  .gallery-search-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;

    gap: var(--ui-space-sm);
  }

  #gallerySearchInput,
  .gallery-filter select {
    box-sizing: border-box;

    width: 100%;
    min-width: 0;
    min-height: var(--ui-target-size);

    margin: 0;
    padding: var(--ui-space-sm) var(--ui-space-md);

    background: var(--ui-surface);
    color: var(--ui-text);

    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-sm);

    font-family: inherit;
    font-size: 0.9375rem;
  }

  #gallerySearchInput::placeholder {
    color: var(--ui-text-secondary);
  }

  /*
   * WHY: Clearing active filters restores the full discovery
   *      experience and should be easy to find.
   */

  #galleryClearFiltersBtn {
    min-height: var(--ui-target-size);

    padding: var(--ui-space-sm) var(--ui-space-md);

    background: var(--ui-accent);
    color: var(--ui-accent-text);

    border: 1px solid transparent;
    border-radius: var(--ui-radius-sm);

    font-weight: 600;
    white-space: nowrap;
  }

  #galleryClearFiltersBtn:hover:not(:disabled) {
    background: var(--ui-accent-hover);
  }

  #galleryClearFiltersBtn:disabled {
    background: var(--ui-surface);
    color: var(--ui-text-secondary);
    border-color: var(--ui-border);
  }

  /* === CLASSIFICATION FILTERS === */

  .gallery-filters {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));

    gap: var(--ui-space-md);
  }

  .gallery-filter {
    display: flex;
    flex-direction: column;

    min-width: 0;
    gap: var(--ui-space-xs);
  }

  .gallery-filter > span {
    color: var(--ui-text-secondary);
    font-size: 0.8125rem;
    font-weight: 500;
  }

  /* WHY: Use the accent only for an active filter. */

  .gallery-filter select.is-active,
  #gallerySearchInput.is-active {
    border-color: var(--ui-accent);
  }

  /* === KEYBOARD ACCESSIBILITY === */

  .gallery-toolbar input:focus-visible,
  .gallery-toolbar select:focus-visible,
  .gallery-toolbar button:focus-visible,
  .mandart-item:focus-visible {
    outline: 2px solid var(--ui-accent);
    outline-offset: 2px;
  }

  .gallery-toolbar button:disabled,
  .gallery-toolbar select:disabled,
  .gallery-toolbar input:disabled {
    opacity: 0.45;
    cursor: default;
  }

  /* === RESULTS === */

  .gallery-results-row {
    display: flex;
    align-items: center;
    justify-content: space-between;

    min-height: 24px;
  }

  .gallery-results-row p {
    font-size: 0.8125rem;
  }

  .gallery-empty {
    grid-column: 1 / -1;

    padding: var(--ui-space-xl);
    color: var(--ui-text-secondary);
    text-align: center;
  }

  /* === TABLET AND PHONE === */

  @media (max-width: 900px) {
    .gallery-filters {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
  }

  @media (max-width: 600px) {
    .gallery-toolbar {
      gap: var(--ui-space-sm);
    }

    .gallery-filters {
      gap: var(--ui-space-sm);
    }

    .gallery-intro p {
      flex-basis: 100%;
    }

    #gallerySurpriseBtn {
      width: 100%;
    }

    #gallerySearchInput,
    .gallery-filter select {
      font-size: 1rem;
    }

    #galleryClearFiltersBtn {
      font-size: 0.8125rem;
    }
  }
}

/* ============================================================
   DISCOVERY GALLERY ARTWORK CAPTIONS
   ============================================================ */

/*
 * WHAT: Artwork names, contributor attribution, and placeholders.
 * WHY: Preserve artistic identity without competing visually
 *      with the artwork itself.
 */

@media screen {
  .mandart-item .gallery-card-caption {
    display: flex;
    flex-direction: column;

    width: 100%;
    box-sizing: border-box;

    gap: var(--ui-space-xs);
    padding: var(--ui-space-sm);
  }

  .mandart-item .gallery-card-name {
    padding: 0;

    color: var(--ui-text);
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.4;
  }

  .mandart-item .gallery-card-contributor {
    padding: 0;

    color: var(--ui-text-secondary);
    font-size: 0.75rem;
    font-weight: 400;
    line-height: 1.4;
  }

  /* WHY: Missing previews retain the same space as artwork. */

  .mandart-item .gallery-preview-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;

    width: 100%;
    box-sizing: border-box;
    aspect-ratio: 1;

    background: var(--ui-canvas-background);
    color: var(--ui-text-secondary);

    font-size: 0.8125rem;
    text-align: center;
  }

  .mandart-item .gallery-preview-placeholder[hidden] {
    display: none;
  }

  /* WHY: Indicate the currently selected artwork. */

  .mandart-item[aria-pressed="true"] {
    border-color: var(--ui-accent);
  }

  @media (max-width: 600px) {
    .mandart-item .gallery-card-name {
      font-size: 0.8125rem;
    }

    .mandart-item .gallery-card-contributor {
      font-size: 0.6875rem;
    }
  }
}

/* ============================================================
   DISCOVERY GALLERY MAP SECTION
   ============================================================ */

/*
 * WHAT: Optional mathematical map within the Gallery.
 * WHY: Keep location-based discovery available without
 *      requiring visitors to navigate the mathematical map.
 */

@media screen {
  .gallery-map-section {
    min-width: 0;

    background: var(--ui-surface);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-sm);
  }

  .gallery-map-section > summary {
    min-height: var(--ui-target-size);
    box-sizing: border-box;

    padding: var(--ui-space-md);

    color: var(--ui-text);
    font-size: 0.9375rem;
    font-weight: 500;

    cursor: pointer;
  }

  .gallery-map-section > summary:hover,
  .gallery-map-section[open] > summary {
    color: var(--ui-accent);
  }

  .gallery-map-section > summary:focus-visible {
    outline: 2px solid var(--ui-accent);
    outline-offset: 2px;
  }

  #galleryMapContainer {
    max-width: 800px;

    margin-inline: auto;
    padding: var(--ui-space-sm);
  }

  #galleryMapContainer .mandart-map {
    padding: 0;

    background: transparent;
    border: 0;
  }
}
