:root {
  --gallery-radius: 10px;
}

/* Basic reset/context */
html, body {
  height: 100%;
}

body.gallery-body {
  margin: 0;
  background: var(--color-bg, #f5f5f5);
  color: var(--color-text, #222);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, "Helvetica Neue", Arial, sans-serif;
}

/* Accessibility helper */
.visually-hidden {
  position: absolute !important;
  clip: rect(1px, 1px, 1px, 1px) !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  border: 0 !important;
}

/* Main layout: full-width main area under header */
.gallery-main {
  width: 100%;
  max-width: none;              /* full window width */
  margin: 0;
  padding: var(--gap, 16px);
  box-sizing: border-box;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: var(--gap, 16px);
  min-height: calc(100vh - 64px); /* rough header height */
}

/* Top controls panel (placeholder) */
.gallery-controls {
  border-radius: var(--gallery-radius);
  border: 1px solid var(--color-border-soft, #ddd);
  background: var(--color-surface, #fafafa);
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}
/* Top panel wrapper (optional) */
.gallery-top-panel {
  margin-bottom: 1rem;
}

/* Radio sort bar */
.gallery-sort {
  display: grid;
  grid-auto-flow: column;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
}

.gallery-sort-label {
  font-weight: 600;
}

/* Radio labels */
.gallery-sort label {
  display: inline-grid;
  grid-auto-flow: column;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

/* Make radio buttons slightly more visible */
.gallery-sort input[type="radio"] {
  cursor: pointer;
}

/* Mobile: stack vertically */
@media (max-width: 600px) {
  .gallery-sort {
    grid-auto-flow: row;
    justify-items: flex-start;
    gap: 0.5rem;
  }

  .gallery-sort-label {
    margin-bottom: 0.25rem;
  }
}

.gallery-controls .controls-inner {
  display: grid;
  align-items: center;
  grid-auto-flow: column;
  justify-content: space-between;
  gap: 0.75rem;
}

.gallery-controls .controls-label {
  opacity: 0.75;
}

/* Dark mode adjustments */
[data-theme="dark"] .gallery-controls {
  background: #151515;
  border-color: #333;
  color: #f2f2f2;
}

/* Grid: 12 columns; rows determined automatically */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--gap, 16px);
  min-height: 0; /* prevent overflow issues in grid layout */
}

/* Individual cells */
.gallery-cell {
  position: relative;
  border-radius: var(--gallery-radius);
  border: 1px solid var(--color-border-soft, #ddd);
  background: var(--color-surface, #fff);
  overflow: hidden;

  /* You found this works nicely on your screen */
  aspect-ratio: 1 / 1.4;
}

/* "message" cell */
.gallery-cell--loading {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  color: #666;
}

/* Anchor fills the whole cell, acts as inner 1-column / 2-row grid
   - Top row: image (takes remaining height)
   - Bottom row: fixed-height title band */
.gallery-link {
  display: grid;
  grid-template-rows: minmax(0, 1fr) 3.2em; /* bottom row fixed ~2 lines */
  width: 100%;
  height: 100%;
  text-decoration: none;
  color: inherit;
}

/* Image wrapper in top grid row */
.gallery-thumb-wrap {
  position: relative;
  overflow: hidden;
}

/* Thumbnail: fill, crop nicely */
.gallery-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Title wrapper: bottom grid row, vertically centers text
   inside its fixed-height band */

.gallery-title-wrap {
  display: flex;
  align-items: center;          /* vertical centering */
  padding: 0.35rem 0.6rem 0.45rem;
  overflow: hidden;             /* enforce fixed band height */
  border-top: 1px solid var(--color-border-soft, #ddd);
}

/* Title itself: clamp visually to 2 lines */
.gallery-title {
  margin: 0;
  font-size: 1rem;
  line-height: 1.3;
  font-weight: 600;
  text-align: left;
  color: inherit;

  /* multi-line clamp where supported */
  display: -webkit-box !important;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;        /* show at most 2 lines */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
}

/* Hover state */
.gallery-link:hover .gallery-title {
  text-decoration: underline;
}

/* Dark mode cell tweaks */
[data-theme="dark"] .gallery-cell {
  background: #111;
  border-color: #333;
}

/* Responsive: reduce columns as the viewport shrinks */
@media (max-width: 1800px) {
  .gallery-grid {
    grid-template-columns: repeat(10, minmax(0, 1fr));
    grid-auto-rows: minmax(150px, 1fr);
  }
}

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

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

@media (max-width: 900px) {
  .gallery-main {
    padding: 10px;
  }

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

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