/* Ocean Labs Gallery — follows the ocean-labs.net tool suite look:
   light grid canvas, Inter + JetBrains Mono, hairline borders, black accents. */

:root {
  --bg: #f6f7f8;
  --fg: #0a0a0a;
  --muted: #888888;
  --line: #e8e8e8;
  --card: #ffffff;
  --radius: 14px;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --row-h: 240px;
  --gap: 14px;
}

body[data-density="s"] { --row-h: 170px; }
body[data-density="l"] { --row-h: 340px; }

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(0, 0, 0, 0.065) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 0, 0, 0.065) 1px, transparent 1px);
  background-size: 32px 32px;
  color: var(--fg);
  font-family: "Inter", system-ui, sans-serif;
  font-weight: 300;
  -webkit-font-smoothing: antialiased;
}

body.is-locked {
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
}

.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Topbar ─────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
  padding: 16px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.topbar-logo {
  height: 38px;
  width: auto;
  display: block;
}

.topbar-divider {
  width: 1px;
  height: 30px;
  background: var(--line);
}

.topbar-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.2;
}

.topbar-meta {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-family: var(--mono);
  white-space: nowrap;
}

.density {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 3px;
  gap: 2px;
}

.density button {
  border: 0;
  background: transparent;
  border-radius: 7px;
  width: 32px;
  height: 28px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}

.density button:hover {
  color: var(--fg);
}

.density button[aria-pressed="true"] {
  background: var(--fg);
  color: #fff;
}

/* ── Justified grid ─────────────────────────────────── */

.grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
  padding: 24px;
}

/* Keeps the last row from stretching. */
.grid::after {
  content: "";
  flex-grow: 1e6;
}

.card {
  /* --ar = width / height of the photo */
  flex: calc(var(--ar) * 100) 1 calc(var(--ar) * var(--row-h));
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.card:hover,
.card:focus-within {
  border-color: var(--fg);
  transform: translateY(-2px);
}

.card-open {
  display: block;
  padding: 0;
  border: 0;
  border-radius: 8px;
  overflow: hidden;
  cursor: zoom-in;
  aspect-ratio: var(--ar);
  background: var(--ph, #ddd);
}

.card-open:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

.card-open img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.4s ease, transform 0.6s ease;
}

.card-open img.is-loaded {
  opacity: 1;
}

.card:hover .card-open img {
  transform: scale(1.025);
}

.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 2px 0 4px;
  min-height: 32px;
}

.card-name {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-download {
  flex: none;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--fg);
  background: #fff;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.card-download:hover,
.card-download:focus-visible {
  background: var(--fg);
  border-color: var(--fg);
  color: #fff;
  outline: none;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.grid-message {
  width: 100%;
  padding: 80px 0;
  text-align: center;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
}

/* ── Footer ─────────────────────────────────────────── */

.footer {
  margin-top: auto;
  border-top: 1px solid var(--line);
  background: #fff;
  padding: 14px 22px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
}

/* ── Lightbox ───────────────────────────────────────── */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  background: #080809;
  color: #fff;
  animation: lb-in 0.2s ease;
}

.lightbox[hidden] {
  display: none;
}

@keyframes lb-in {
  from { opacity: 0; }
}

.lb-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.lb-info {
  display: flex;
  align-items: baseline;
  gap: 14px;
  min-width: 0;
  font-family: var(--mono);
  font-size: 13px;
}

.lb-counter {
  color: #fff;
  white-space: nowrap;
}

.lb-name {
  color: #afafb4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lb-download {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 14px;
  border-radius: 10px;
  background: #fff;
  color: var(--fg);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.lb-download:hover,
.lb-download:focus-visible {
  background: #e8e8e8;
  outline: none;
}

.lb-size {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
}

.lb-icon,
.lb-nav {
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.04);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.lb-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
}

.lb-icon:hover,
.lb-nav:hover,
.lb-icon:focus-visible,
.lb-nav:focus-visible {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.5);
  outline: none;
}

.lb-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 84px;
  touch-action: pan-y;
}

.lb-figure {
  margin: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lb-figure img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
  user-select: none;
  -webkit-user-drag: none;
  transition: opacity 0.2s ease, filter 0.3s ease;
}

.lb-figure img.is-low {
  filter: blur(6px);
}

.lb-figure img.is-swapping {
  opacity: 0;
}

.lb-nav {
  position: absolute;
  top: 50%;
  translate: 0 -50%;
  width: 48px;
  height: 48px;
  border-radius: 50%;
}

.lb-nav svg {
  width: 22px;
  height: 22px;
}

.lb-prev { left: 20px; }
.lb-next { right: 20px; }

/* ── Small screens ──────────────────────────────────── */

@media (max-width: 720px) {
  :root {
    --row-h: 150px;
    --gap: 10px;
  }
  body[data-density="s"] { --row-h: 110px; }
  body[data-density="l"] { --row-h: 230px; }

  .topbar { padding: 12px 16px; }
  .topbar-left { gap: 10px; }
  .topbar-logo { height: 28px; }
  .topbar-divider { height: 26px; }
  .topbar-title { font-size: 15px; }
  .topbar-meta { font-size: 11px; }
  .meta-subtitle { display: none; }
  .density button { width: 26px; height: 26px; }
  .grid { padding: 16px; }
  .card { padding: 6px; border-radius: 12px; }
  .footer { flex-direction: column; padding: 14px 16px; }

  .lb-bar { padding: 10px 12px; }
  .lb-name { display: none; }
  .lb-size { display: none; }
  .lb-stage { padding: 12px 0; }
  .lb-nav {
    top: auto;
    bottom: 16px;
    translate: none;
    background: rgba(0, 0, 0, 0.45);
  }
  .lb-prev { left: 16px; }
  .lb-next { right: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}
