:root {
  color-scheme: light dark;
  --bg: #fafaf7;
  --surface: #ffffff;
  --text: #15171c;
  --muted: #626773;
  --line: #e4e4de;
  --tile: #ebebe6;
  --accent: #2447f9;
  --accent-ink: #ffffff;
  --radius: 10px;
  --row: 230px;
  --gap: 10px;
  --pad: clamp(16px, 3vw, 36px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101113;
    --surface: #18191d;
    --text: #f2f2ee;
    --muted: #9da2ad;
    --line: #2b2d33;
    --tile: #212329;
    --accent: #8598ff;
    --accent-ink: #0b0d14;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, "Segoe UI", "Arial Hebrew", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

a {
  color: inherit;
}

img {
  max-width: 100%;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Header */

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: clamp(12px, 3vw, 32px);
  padding: 12px var(--pad);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-weight: 800;
  font-size: 1.45rem;
  letter-spacing: -0.01em;
}

.brand__mark {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  background:
    linear-gradient(var(--accent), var(--accent)) 0 0 / 50% 50% no-repeat,
    linear-gradient(var(--text), var(--text)) 100% 100% / 50% 50% no-repeat;
}

.search {
  flex: 1;
  max-width: 560px;
}

.search input {
  width: 100%;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.search input::placeholder {
  color: var(--muted);
}

/* Gallery */

main {
  flex: 1;
  width: 100%;
  padding: 16px var(--pad) 48px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.filters__sep {
  width: 1px;
  margin: 4px 4px;
  background: var(--line);
}

.chip {
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.chip:hover {
  border-color: var(--muted);
}

.chip[aria-pressed="true"] {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}

.chip__count {
  margin-inline-start: 6px;
  color: var(--muted);
  font-size: 0.85em;
}

.chip[aria-pressed="true"] .chip__count {
  color: inherit;
  opacity: 0.7;
}

.status {
  min-height: 1.5em;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.95rem;
}

.status button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}

/*
 * Justified rows: every tile grows in proportion to its aspect ratio (--r),
 * so all tiles in a row end up the same height with no gaps and no layout shift.
 */
.grid {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--gap);
}

.grid::after {
  content: "";
  flex-grow: 1000000;
}

.tile {
  position: relative;
  flex: calc(var(--r) * 100) 1 calc(var(--r) * var(--row));
  aspect-ratio: var(--r);
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--tile);
}

.tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.25s ease;
}

.tile:hover img,
.tile:focus-visible img {
  transform: scale(1.03);
}

.tile__cap {
  position: absolute;
  inset: auto 0 0 0;
  padding: 28px 12px 10px;
  background: linear-gradient(transparent, rgb(0 0 0 / 0.62));
  color: #fff;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.tile:hover .tile__cap,
.tile:focus-visible .tile__cap {
  opacity: 1;
}

/* Transparent elements sit on a checkerboard so their shape is visible. */
.tile--element,
.detail__stage--element {
  background-color: #f4f4f1;
  background-image: repeating-conic-gradient(#e2e2dc 0% 25%, transparent 0% 50%);
  background-size: 20px 20px;
}

.tile--element img {
  object-fit: contain;
  padding: 8%;
}

/* Detail page */

.back {
  display: inline-block;
  margin-bottom: 14px;
  color: var(--muted);
  text-decoration: none;
}

.back:hover {
  color: var(--text);
}

.detail {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: clamp(20px, 3vw, 40px);
  align-items: start;
}

.detail__stage {
  display: flex;
  justify-content: center;
  border-radius: var(--radius);
  background: var(--tile);
  overflow: hidden;
}

.detail__stage img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 78vh;
}

.detail__side {
  position: sticky;
  top: 84px;
}

.detail__title {
  margin: 0 0 8px;
  font-size: 1.5rem;
  line-height: 1.25;
}

.detail__meta {
  margin: 0 0 20px;
  color: var(--muted);
}

.btn {
  display: block;
  padding: 14px 20px;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 1.05rem;
  text-align: center;
  text-decoration: none;
}

.btn:hover {
  filter: brightness(1.08);
}

.btn__sub {
  display: block;
  font-weight: 400;
  font-size: 0.85rem;
  opacity: 0.85;
}

.detail__label {
  margin: 24px 0 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 400;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.related {
  margin-top: 48px;
}

.related h2 {
  margin: 0 0 14px;
  font-size: 1.1rem;
}

.related .grid {
  --row: 170px;
}

.foot {
  padding: 20px var(--pad);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 820px) {
  :root {
    --row: 150px;
    --gap: 6px;
  }

  .detail {
    grid-template-columns: 1fr;
  }

  .detail__side {
    position: static;
  }

  .brand__name {
    font-size: 1.25rem;
  }
}

@media (hover: none) {
  .tile__cap {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile img,
  .tile__cap {
    transition: none;
  }
}
