/* The community theme gallery (mars-dawn-website #145, plan-website-104 W4). Cards and filter
   buttons are built at build time by scripts/build_pages.py from public/themes/v1/index.json;
   scripts/theme-gallery.js only toggles the [hidden] attribute and aria-pressed -- no inline
   style anywhere, since the site's CSP has no 'unsafe-inline' for style-src. */

/* Both the filter and the cards are --w-media wide and centred on the page the way the hero window
   and the loop drawing are: an auto margin would leave a block wider than the 44rem text column
   against its left edge. */
.theme-gallery-filter {
  --gallery-width: var(--w-media);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: var(--gallery-width);
  margin: 20px calc((100% - var(--gallery-width)) / 2) 0;
}

.theme-filter-btn {
  font: inherit;
  padding: 6px 14px;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}

.theme-filter-btn[aria-pressed="true"] {
  background: var(--ember);
  border-color: var(--ember);
  color: var(--paper);
}

.theme-gallery-cards {
  --gallery-width: var(--w-media);
  width: var(--gallery-width);
  margin: 20px calc((100% - var(--gallery-width)) / 2) 28px;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 20px;
}

.theme-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 14px;
  background: var(--sand);
  border-radius: var(--r-plate, 12px);
}

/* [hidden] already means display:none in every browser; stated again because a flex/grid
   container is exactly the case where a forgotten override has bitten this site before
   (mars-dawn-website#147 round 2, on a different property). */
.theme-card[hidden] { display: none; }

/* The light and dark previews: side by side from 760px, where each is about 450px wide on a full
   card (they used to stack, each at half the card's width, about 215px), stacked below that. A
   preview is a link to the full-size file; theme-gallery.js opens it in a dialog instead. */
.theme-previews {
  display: grid;
  gap: 12px;
  margin-bottom: 6px;
}

@media (min-width: 760px) {
  .theme-previews { grid-template-columns: 1fr 1fr; }
}

.theme-preview {
  display: block;
  border-radius: 8px;
  box-shadow: 0 1px 2px color-mix(in srgb, #000 12%, transparent),
              0 8px 20px -12px color-mix(in srgb, #000 30%, transparent);
}

[data-lightbox] .theme-preview { cursor: zoom-in; }

.theme-preview img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
}

.theme-preview:focus-visible { border-radius: 8px; }

.theme-card .theme-name { font-size: 1rem; }

.theme-card .theme-version,
.theme-card .theme-author {
  display: block;
  color: var(--dust);
  font-size: 0.9rem;
}

.theme-card .theme-summary { display: block; }

.theme-card .theme-scenarios { display: block; }

.theme-card .theme-scenario {
  display: inline-block;
  font-size: 0.8rem;
  padding: 2px 8px;
  margin: 2px 4px 0 0;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  color: var(--dust);
}

/* Report / Report-by-email are real <button>s, not <a>s (see the comment in build_pages.py above
   COMMUNITY_GALLERY_MARK and in theme-gallery.js): reset the button chrome so each still reads as
   a plain link, underlined, in the site's link colour, on its own line. */
.theme-card .theme-report,
.theme-card .theme-report-mail {
  display: block;
  width: fit-content;
  margin-top: 4px;
  font: inherit;
  color: var(--link);
  background: none;
  border: none;
  padding: 0;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  cursor: pointer;
}
.theme-card .theme-report:hover,
.theme-card .theme-report-mail:hover {
  text-decoration-thickness: 2px;
}
.theme-card .theme-report:focus-visible,
.theme-card .theme-report-mail:focus-visible {
  outline: 2px solid var(--ember);
  outline-offset: 3px;
  border-radius: 3px;
}

.theme-gallery-empty {
  width: var(--w-text);
  max-width: calc(100vw - 32px);
  margin: 20px auto;
  color: var(--dust);
}

/* The enlarged preview: a modal <dialog> over the whole viewport (see theme-gallery.js). The image
   is shown at its natural size, so one wider or taller than the window scrolls inside the dialog;
   the browser supplies Esc, the focus trap and the dimmed top layer. No display is set on the
   dialog itself, so it stays hidden until showModal(). */
.theme-lightbox {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  background: color-mix(in srgb, #000 86%, transparent);
  color: #fff;
}

.theme-lightbox-scroll {
  position: absolute;
  inset: 0;
  display: flex;
  overflow: auto;
  overscroll-behavior: contain;
}

/* margin:auto centres a small image and, unlike place-items, never makes the top-left of a
   larger one unreachable. */
.theme-lightbox-scroll:focus-visible {
  outline: 3px solid #fff;
  outline-offset: -3px;
}

.theme-lightbox-img {
  display: block;
  flex: none;
  max-width: none;
  width: auto;
  height: auto;
  margin: auto;
}

.theme-lightbox-close {
  position: absolute;
  z-index: 1;
  top: 12px;
  right: 24px;
  min-height: 44px;
  padding: 0 18px;
  font: inherit;
  color: #fff;
  background: #1d1b1a;
  border: 1px solid color-mix(in srgb, #fff 70%, transparent);
  border-radius: 999px;
  cursor: pointer;
}

.theme-lightbox-close:hover { background: #3a3735; }

.theme-lightbox-close:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

@media (prefers-reduced-motion: no-preference) {
  .theme-lightbox[open] { animation: theme-lightbox-in 140ms ease-out; }
  @keyframes theme-lightbox-in { from { opacity: 0; } to { opacity: 1; } }
}
