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

:root {
  --paper: #f3efe4;
  --paper-deep: #e8e2d4;
  --ink: #1c1915;
  --ink-soft: #3f3a33;
  --muted: #6e675c;
  --rule: #cfc6b4;
  --red: #9d1c1c;
  --sidebar-w: 220px;
  --header-h: 76px;
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, "Times New Roman", serif;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--serif);
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
}

/* Nameplate */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  padding-bottom: 4px;
  border-bottom: 1px solid var(--ink);
  background: var(--paper);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  height: calc(var(--header-h) - 8px);
  padding: 0 18px;
  border-bottom: 3px solid var(--ink);
}

.brand {
  color: var(--ink);
  text-decoration: none;
  flex-shrink: 0;
  line-height: 0.9;
}

.brand-name {
  font-weight: 700;
  font-size: 1.85rem;
  letter-spacing: -0.03em;
}

.brand:hover .brand-name { color: var(--red); }

.brand-count {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
  padding-top: 8px;
}

.search-wrap {
  flex: 1;
  min-width: 140px;
  max-width: 480px;
}

#search {
  width: 100%;
  padding: 6px 2px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--ink);
  border-radius: 0;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.95rem;
  font-style: italic;
  outline: none;
}

#search:focus { border-bottom-color: var(--red); }
#search::placeholder { color: var(--muted); }

.btn-refresh {
  margin-left: auto;
  padding: 5px 10px;
  background: transparent;
  border: 1px solid var(--ink);
  border-radius: 0;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  flex-shrink: 0;
}

.btn-refresh:hover { color: var(--red); border-color: var(--red); }
.btn-refresh:disabled { opacity: 0.45; cursor: wait; }

/* Layout */
.layout {
  display: flex;
  min-height: calc(100vh - var(--header-h));
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  padding: 16px 12px 18px;
  border-right: 1px solid var(--ink);
  background: var(--paper);
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-label {
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 8px 10px;
}

.sidebar-nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.sidebar-footer {
  flex-shrink: 0;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-footer a {
  font-size: 0.82rem;
  font-style: italic;
  color: var(--muted);
  text-decoration: none;
  padding: 4px 8px;
}

.sidebar-footer a:hover { color: var(--red); }

.cat-btn {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  width: 100%;
  padding: 5px 8px;
  margin-bottom: 1px;
  background: none;
  border: none;
  border-left: 3px solid transparent;
  border-radius: 0;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.92rem;
  cursor: pointer;
  text-align: left;
}

.cat-btn:hover { color: var(--red); }

.cat-btn.active {
  border-left-color: var(--red);
  color: var(--red);
  font-weight: 700;
}

.cat-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cat-count {
  font-size: 0.72rem;
  font-style: italic;
  color: var(--muted);
  margin-left: 8px;
  flex-shrink: 0;
}

.cat-btn.active .cat-count { color: var(--red); }

.sidebar-divider {
  height: 1px;
  background: var(--rule);
  margin: 8px 8px;
}

.main {
  flex: 1;
  padding: 18px 22px 48px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--header-h));
}

.toolbar {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--ink);
}

#view-title {
  font-size: 1.65rem;
  font-weight: 700;
  font-style: italic;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.view-count {
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Section covers */
.catalog {
  columns: 260px 4;
  column-gap: 16px;
}

.board-tile {
  display: block;
  width: 100%;
  margin-bottom: 16px;
  padding: 0;
  break-inside: avoid;
  overflow: hidden;
  background: #fffdf8;
  border: 1px solid var(--ink);
  border-radius: 0;
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-align: left;
  appearance: none;
}

.board-tile:hover { border-color: var(--red); }
.board-tile:hover .board-tile-name { color: var(--red); }

.board-frame {
  background: #1c1915;
}

.board-tile img,
.board-tile video,
.card img,
.card video {
  width: 100%;
  height: auto;
  display: block;
  vertical-align: top;
}

.board-tile-label,
.card-caption {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px 9px;
  background: var(--paper);
  border-top: 1px solid var(--rule);
}

.board-tile-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-tile-count {
  font-size: 0.75rem;
  font-style: italic;
  color: var(--muted);
  flex-shrink: 0;
}

/* Picture grid */
.grid {
  columns: 220px 5;
  column-gap: 14px;
}

.card {
  display: block;
  width: 100%;
  margin-bottom: 14px;
  break-inside: avoid;
  border-radius: 0;
  overflow: hidden;
  background: #fffdf8;
  border: 1px solid var(--rule);
  cursor: pointer;
}

.card:hover { border-color: var(--ink); }

.card-frame {
  position: relative;
  background: #1c1915;
}

.card video,
.board-tile video {
  min-height: 80px;
  background: #1c1915;
}

.card-name {
  font-size: 0.78rem;
  font-style: italic;
  line-height: 1.3;
  color: var(--ink-soft);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.card-dl,
.btn-download {
  flex-shrink: 0;
  color: var(--red);
  font-family: inherit;
  font-size: 0.68rem;
  font-style: normal;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
  border-bottom: 1px solid var(--red);
  background: none;
}

.card-dl:hover,
.btn-download:hover { color: var(--ink); border-bottom-color: var(--ink); }

.video-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--ink);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 1px 5px;
  pointer-events: none;
}

.loading, .empty {
  text-align: left;
  padding: 36px 2px;
  color: var(--muted);
  font-size: 1rem;
  font-style: italic;
}

.loading .error-detail {
  margin-top: 10px;
  color: var(--red);
  font-size: 0.9rem;
  font-style: normal;
}

.loading .error-hint {
  margin-top: 8px;
  font-size: 0.85rem;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--rule);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-bottom: 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(28, 25, 21, 0.82);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.lightbox-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: var(--paper);
  border: 1px solid var(--ink);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 6px 10px;
  cursor: pointer;
  z-index: 10;
}

.lightbox-close:hover { color: var(--red); border-color: var(--red); }

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: var(--paper);
  border: 1px solid var(--ink);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 10px 8px;
  cursor: pointer;
  z-index: 10;
}

.lightbox-nav:hover { color: var(--red); border-color: var(--red); }
.lightbox-nav.prev { left: 16px; }
.lightbox-nav.next { right: 16px; }

.lightbox-content {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: max-content;
  max-width: 90vw;
  background: var(--paper);
}

.lightbox-content img,
.lightbox-content video {
  max-width: 90vw;
  max-height: 78vh;
  object-fit: contain;
  background: #1c1915;
}

.lightbox-footer {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  max-width: 90vw;
  padding: 8px 12px 10px;
  background: var(--paper);
  border-top: 1px solid var(--rule);
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-style: italic;
}

#lightbox-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 768px) {
  :root { --header-h: 64px; }

  .header-inner { gap: 8px; padding: 0 12px; }
  .brand-name { font-size: 1.4rem; }
  .brand-count { display: none; }

  .layout { flex-direction: column; }

  .sidebar {
    width: 100%;
    position: static;
    height: auto;
    overflow: visible;
    padding: 10px 12px 12px;
    border-right: none;
    border-bottom: 1px solid var(--ink);
  }

  .sidebar-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    overflow: visible;
  }

  .sidebar-divider { display: none; }

  .cat-btn {
    width: auto;
    flex: 0 0 auto;
    padding: 4px 8px;
    margin: 0;
    border: 1px solid var(--rule);
    border-left-width: 1px;
    background: transparent;
    white-space: nowrap;
  }

  .cat-btn.active {
    border-color: var(--red);
    background: transparent;
  }

  #category-list { display: contents; }

  .main { padding: 14px 12px 32px; }

  #view-title { font-size: 1.35rem; }

  .catalog {
    columns: 160px 2;
    column-gap: 10px;
  }

  .grid {
    columns: 150px 2;
    column-gap: 10px;
  }

  .card, .board-tile { margin-bottom: 10px; }

  .lightbox-nav { display: none; }

  .lightbox-footer { max-width: 92vw; }
}

/* ===== Theme: dark / underground (replaces newsprint colours and type) ===== */
:root {
  --paper: #0a0a0a; --ink: #e9e9e2; --ink-soft: #c9c9c0; --muted: #8a8a80; --rule: #222;
  --red: #b6ff00; --acid: #b6ff00; --pink: #a066ff; /* violet (was hot pink) */
  --disp: "Rubik Glitch", "Bungee", Impact, sans-serif; --mono: "Space Mono", ui-monospace, Menlo, monospace;
  --noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --tape: repeating-linear-gradient(-45deg, var(--acid) 0 12px, #0a0a0a 12px 24px);
}
body { font-family: var(--mono); background: #0a0a0a var(--noise); color: var(--ink); }
.header { background: #050505 var(--noise); border-bottom: none; padding-bottom: 0; }
.header::after { content: ""; position: absolute; left: 0; right: 0; bottom: -8px; height: 8px; background: var(--tape); }
.header-inner { border-bottom: none; }
.brand-name { font-family: var(--disp); font-weight: 400; font-size: 2.4rem; text-transform: uppercase; color: var(--acid); text-shadow: 2px 0 var(--pink), -2px 0 #00e5ff; }
.brand:hover .brand-name { color: var(--pink); animation: glitch .25s steps(2) infinite; }
.brand-count { font-family: var(--mono); color: var(--pink); transform: rotate(-3deg); }
#search { font-family: var(--mono); font-style: normal; color: var(--acid); background: #111; border: 2px dashed #444; padding: 7px 10px; }
#search:focus { border: 2px solid var(--pink); }
#search::placeholder { color: #666; }
.btn-refresh { font-family: var(--disp); font-size: .9rem; background: var(--pink); color: #000; border: none; padding: 6px 12px; transform: rotate(2deg); }
.btn-refresh:hover { background: var(--acid); transform: rotate(-3deg) scale(1.08); }
.layout { margin-top: 8px; }
.sidebar { background: transparent; border-right: 2px dashed #2a2a2a; }
.sidebar-label { font-family: var(--disp); color: var(--pink); font-size: 1rem; letter-spacing: .05em; }
.cat-btn { font-family: var(--mono); text-transform: lowercase; color: var(--ink-soft); font-size: .88rem; border-left: 3px solid transparent; }
.cat-btn:hover { color: #000; background: var(--acid); }
.cat-btn:hover .cat-count { color: #000; }
.cat-btn.active { background: var(--pink); color: #000; border-left-color: var(--acid); font-weight: 700; transform: rotate(-1.5deg); }
.cat-btn.active .cat-count { color: #000; }
.cat-count { font-style: normal; color: #666; }
.sidebar-divider { background: var(--tape); height: 4px; opacity: .6; }
.sidebar-footer { border-top: 2px dashed #2a2a2a; }
.sidebar-footer a { font-style: normal; color: #777; }
.sidebar-footer a:hover { color: var(--acid); }
.toolbar { border-bottom: none; }
#view-title { font-family: var(--disp); font-weight: 400; font-style: normal; text-transform: uppercase; font-size: 2.6rem; color: var(--ink); text-shadow: 3px 0 var(--pink), -3px 0 #00e5ff; }
.view-count { font-family: var(--mono); color: #000; background: var(--acid); padding: 2px 8px; transform: rotate(-2deg); }
.board-tile, .card { background: #111; border: 2px solid #1e1e1e; transition: transform .12s, border-color .12s; }
.board-tile:nth-child(3n+1), .card:nth-child(3n+1) { transform: rotate(-.8deg); }
.board-tile:nth-child(3n+2), .card:nth-child(3n+2) { transform: rotate(.7deg); }
.board-tile:hover, .card:hover { transform: rotate(0) scale(1.02); border-color: var(--acid); box-shadow: 5px 5px 0 var(--pink), -3px -3px 0 #00e5ff; z-index: 2; position: relative; }
.board-frame, .card-frame { background: #000; }
.board-tile-label, .card-caption { background: #111; border-top: none; }
.board-tile-name { font-family: var(--disp); font-weight: 400; text-transform: uppercase; font-size: 1.15rem; color: #000; background: var(--acid); padding: 2px 8px; transform: rotate(-2deg); box-shadow: 2px 2px 0 #000; }
.board-tile:hover .board-tile-name { background: var(--pink); animation: glitch .2s steps(2) infinite; }
.board-tile-count { color: var(--pink); font-style: normal; font-weight: 700; }
.card-name { font-style: normal; color: var(--ink-soft); font-size: .74rem; }
.card-dl, .btn-download { font-family: var(--mono); color: var(--pink); border-bottom: 2px solid var(--pink); font-weight: 700; }
.card-dl:hover, .btn-download:hover { color: #000; background: var(--acid); border-bottom-color: var(--acid); }
.video-badge { background: var(--tape); color: #000; border: none; font-weight: 700; text-shadow: 0 0 3px var(--acid); }
.loading, .empty { font-style: normal; color: var(--acid); }
.spinner { border-color: #333; border-top-color: var(--pink); }
.lightbox { background: rgba(0,0,0,.94) var(--noise); }
.lightbox-close, .lightbox-nav { font-family: var(--disp); background: var(--acid); color: #000; border: none; }
.lightbox-close:hover, .lightbox-nav:hover { background: var(--pink); }
.lightbox-content { background: #111; outline: 3px solid var(--pink); }
.lightbox-footer { background: #111; border-top: 6px solid transparent; border-image: var(--tape) 6; font-style: normal; }
@keyframes glitch {
  0% { text-shadow: 3px 0 var(--pink), -3px 0 #00e5ff; transform: translate(0) rotate(-2deg); }
  50% { text-shadow: -3px 1px var(--pink), 3px -1px #00e5ff; transform: translate(1px,-1px) rotate(-2deg); }
  100% { text-shadow: 2px -1px var(--pink), -2px 1px #00e5ff; transform: translate(-1px,1px) rotate(-2deg); }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }
@media (max-width: 768px) {
  .brand-name { font-size: 1.7rem; }
  #view-title { font-size: 1.8rem; }
  .sidebar { border-right: none; border-bottom: 2px dashed #2a2a2a; }
  .cat-btn { border: 1px solid #333; }
  .cat-btn.active { border-color: var(--acid); }
  .board-tile-name { font-family: var(--mono); font-weight: 700; font-size: .8rem; }
}

/* Sidebar: fit the section list at ~800px tall viewports; hide the scroll bar (still scrollable on short screens) */
@media (min-width: 769px) {
  .sidebar { padding: 10px 10px 12px; }
  .sidebar-label { padding-bottom: 6px; }
  .cat-btn { padding: 3px 8px; font-size: .84rem; line-height: 1.25; }
  .sidebar-divider { margin: 5px 8px; }
  .sidebar-footer { margin-top: 6px; padding-top: 6px; flex-direction: row; flex-wrap: wrap; gap: 0 4px; }
  .sidebar-footer a { padding: 2px 8px; }
}
.sidebar-nav { scrollbar-width: none; -ms-overflow-style: none; }
.sidebar-nav::-webkit-scrollbar { display: none; }

/* Captions without file names: actions only */
.card-caption { justify-content: flex-end; gap: 12px; }
.lightbox-footer { justify-content: flex-end; }
.lightbox-actions { display: flex; gap: 14px; align-items: baseline; }
button.card-dl, button.btn-download { border-top: 0; border-left: 0; border-right: 0; padding: 0; cursor: pointer; line-height: inherit; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 28px; z-index: 300; transform: translateX(-50%) rotate(-1.5deg) translateY(20px);
  background: var(--acid); color: #000; font-family: var(--mono); font-weight: 700; font-size: .85rem;
  padding: 8px 14px; box-shadow: 4px 4px 0 var(--pink); opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%) rotate(-1.5deg) translateY(0); }
