:root {
  --bg: #1a1a1a;
  --panel: #222;
  --border: #383838;
  --border-inner: #2a2a2a;
  --text: #d4d4d4;
  --muted: #8a8a8a;
  --accent: #b388ff;
  --accent-2: #80cbc4;
  --button-bg: #2c2040;
  --button-border: #4a2e7a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: "MS PGothic", "MS UI Gothic", sans-serif;
  font-size: 13px;
  line-height: 1.6;
  min-height: 100%;
}

* {
  scrollbar-width: thin;
  scrollbar-color: #3a2a55 #1a1a1a;
}
*::-webkit-scrollbar { width: 4px; height: 4px; }
*::-webkit-scrollbar-track { background: #1a1a1a; }
*::-webkit-scrollbar-thumb { background: #3a2a55; border-radius: 2px; }

/* ── Topbar ───────────────────────────────────────────────────────────── */
#topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #202020;
  border-bottom: 1px solid #3a3a3a;
  padding: 5px 12px;
  font-size: 12px;
  color: #666;
  display: flex;
  align-items: center;
  gap: 4px;
}
#topbar a { color: var(--accent); text-decoration: none; }
#topbar a:hover { text-decoration: underline; }
#topbar .sep { color: #444; }
#topbar .current { color: #aaa; }

/* ── Site title ───────────────────────────────────────────────────────── */
a.site-title {
  display: block;
  text-decoration: none;
  font-size: 18px;
  color: var(--accent);
  font-weight: bold;
  letter-spacing: 1px;
  margin-top: -8px;
  margin-bottom: 14px;
  padding: 8px 0 6px;
  border-bottom: 1px solid #333;
  position: sticky;
  top: 28px;
  z-index: 9;
  background: var(--bg);
}
a.site-title:hover { text-decoration: none; }
.site-title .seg { display: inline-block; position: relative; transform-origin: center bottom; }

/* ── Outer wrapper ────────────────────────────────────────────────────── */
#outer {
  width: min(1100px, 100% - 24px);
  margin: 20px auto 60px;
}

/* ── Gallery header / filter bar ─────────────────────────────────────── */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 12px 14px;
  margin-bottom: 10px;
}

.tag {
  display: inline-block;
  background: var(--button-bg);
  color: var(--accent);
  border: 1px solid var(--button-border);
  font-size: 10px;
  padding: 1px 6px;
  letter-spacing: 0.04em;
}

.gallery-header-top {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 6px;
}

.gallery-count-label {
  font-size: 10px;
  color: #666;
  letter-spacing: 0.03em;
}

.gallery-desc {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
}

#filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: flex-start;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-group-search {
  flex: 1;
  min-width: 160px;
}

.filter-label {
  font-size: 10px;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  white-space: nowrap;
  flex-shrink: 0;
}

.filter-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.filter-btn {
  background: #1e1a28;
  border: 1px solid #3a2e55;
  color: #8878b0;
  font: inherit;
  font-size: 11px;
  padding: 2px 8px;
  cursor: pointer;
  transition: border-color 120ms ease, color 120ms ease, background 120ms ease;
  line-height: 1.5;
}
.filter-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.filter-btn.active {
  background: var(--button-bg);
  border-color: var(--accent);
  color: var(--accent);
}
/* category-specific accent for active state */
.filter-btn[data-cat].active {
  border-color: var(--cat-accent, var(--accent));
  color: var(--cat-accent, var(--accent));
  background: color-mix(in srgb, var(--cat-accent, var(--accent)) 12%, #1a1a1a);
}

.search-input {
  flex: 1;
  min-width: 120px;
  background: #161616;
  border: 1px solid #333;
  color: var(--text);
  padding: 3px 7px;
  font: inherit;
  font-size: 12px;
  line-height: 1.5;
}
.search-input:focus {
  outline: none;
  border-color: #6a4aaa;
}
.search-input::placeholder { color: #484848; }

/* ── Category headers ────────────────────────────────────────────────── */
.gallery-cat-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 6px 0 5px;
  border-bottom: 1px solid color-mix(in srgb, var(--cat-color, var(--accent)) 35%, transparent);
  margin-bottom: 2px;
}
.gallery-cat-header:not(:first-child) {
  margin-top: 14px;
}
.gallery-cat-label {
  font-size: 11px;
  color: var(--cat-color, var(--accent));
  text-transform: lowercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
  flex-shrink: 0;
}
.gallery-cat-desc {
  font-size: 10px;
  color: #555;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Gallery grid ─────────────────────────────────────────────────────── */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 6px;
}

.gallery-tile {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 0;
  border: 1px solid #3a2a55;
  background: #171717;
  cursor: pointer;
  overflow: hidden;
  position: relative;
  transition: border-color 130ms ease, box-shadow 130ms ease;
}
.gallery-tile:hover,
.gallery-tile:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(179, 136, 255, 0.25) inset;
  outline: none;
}
.gallery-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 200ms ease;
}
.gallery-tile:hover img,
.gallery-tile:focus-visible img {
  transform: scale(1.07);
}

.tile-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 6px 7px;
  background: linear-gradient(to top, rgba(0,0,0,0.72) 0%, rgba(0,0,0,0.18) 55%, transparent 100%);
  opacity: 0;
  transition: opacity 160ms ease;
  pointer-events: none;
}
.gallery-tile:hover .tile-overlay,
.gallery-tile:focus-visible .tile-overlay { opacity: 1; }

.tile-date {
  font-size: 9px;
  color: rgba(255,255,255,0.65);
  letter-spacing: 0.03em;
  line-height: 1.3;
}
.tile-title {
  font-size: 10px;
  color: rgba(255,255,255,0.88);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Empty / error states ─────────────────────────────────────────────── */
.gallery-empty {
  text-align: center;
  color: #555;
  font-size: 12px;
  padding: 36px 0;
}
.gallery-load-error {
  color: #7a5555;
  font-size: 12px;
  padding: 20px 0;
  text-align: center;
}

/* ── Lightbox ─────────────────────────────────────────────────────────── */
body.lb-active { overflow: hidden; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(8, 6, 14, 0.94);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.lb-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  color: #777;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
  z-index: 10;
  transition: color 120ms ease;
  font-family: inherit;
}
.lb-close:hover { color: var(--accent); }

.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(20, 15, 30, 0.7);
  border: 1px solid #3a2a55;
  color: #a090cc;
  font-size: 18px;
  line-height: 1;
  width: 36px;
  height: 54px;
  cursor: pointer;
  z-index: 10;
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lb-nav:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(44, 32, 64, 0.85);
}
.lb-prev { left: 8px; }
.lb-next { right: 8px; }

.lb-stage {
  flex: 1;
  width: 100%;
  max-width: min(900px, 100% - 100px);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.lb-focus {
  overflow: hidden;
  border: 1px solid #4a2e7a;
  background: #0f0f0f;
  max-height: calc(100vh - 130px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.lb-focus img {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 130px);
  object-fit: contain;
  transform-origin: 50% 50%;
  transform: scale(1);
  cursor: zoom-in;
  transition: transform 140ms ease;
  user-select: none;
  -webkit-user-drag: none;
}
.lb-focus.is-zoom-pan img {
  transform: scale(2.4);
  cursor: zoom-out;
}

.lb-info {
  width: 100%;
  max-width: min(900px, 100% - 100px);
  margin-top: 8px;
  padding: 0 2px;
  flex-shrink: 0;
}

.lb-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 3px;
}

.lb-title {
  font-size: 12px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-counter {
  font-size: 10px;
  color: #555;
  flex-shrink: 0;
  letter-spacing: 0.04em;
}

.lb-caption {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
  min-height: 14px;
}

.lb-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}

.lb-tag {
  display: inline-block;
  background: #1e1a28;
  border: 1px solid #3a2a55;
  color: #887aaa;
  font-size: 10px;
  padding: 1px 6px;
  letter-spacing: 0.03em;
}

.lb-tag-cat {
  color: var(--tag-color, var(--accent));
  border-color: color-mix(in srgb, var(--tag-color, var(--accent)) 45%, #1a1a1a);
  background: color-mix(in srgb, var(--tag-color, var(--accent)) 10%, #1a1a1a);
}

/* ── Footer ───────────────────────────────────────────────────────────── */
footer {
  text-align: center;
  color: #444;
  font-size: 11px;
  margin-top: 32px;
  padding-bottom: 24px;
}

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  #outer { width: calc(100% - 16px); margin: 12px auto 32px; }

  a.site-title {
    font-size: 15px;
    margin-bottom: 12px;
    position: static;
    top: auto;
  }

  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 4px;
  }

  #filter-bar {
    flex-direction: column;
    gap: 7px;
  }

  .filter-group-search {
    width: 100%;
  }

  .lb-stage {
    max-width: 100%;
  }
  .lb-info {
    max-width: 100%;
  }
  .lb-nav {
    width: 30px;
    height: 44px;
    font-size: 15px;
  }
  .lb-prev { left: 3px; }
  .lb-next { right: 3px; }
  .tile-overlay { opacity: 1; }
}

@media (min-width: 900px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  }
}
