/* PIXEL VAULT — asset library showcase
   Aesthetic: Aseprite-workshop theme from the library's own palette.
   v2: dual theme, density control, skeletons, mobile drawer, motion respect. */
:root {
  --px: 3px;
  --card-min: 158px;
  --card-h: 118px;
  --topbar-h: 63px; /* JS keeps this in sync with the real topbar height */
}
html[data-theme="dark"] {
  --bg: #1a1c2c; --bg2: #20243a; --panel: #292d44; --panel2: #31365273;
  --line: #3a4066; --ink: #f4f4f4; --muted: #8b9bb4; --dim: #5a6988;
  --green: #63c74d; --green-d: #3e8948; --gold: #fee761; --red: #e43b44;
  --cyan: #2ce8f5; --shadow: #00000066; --focus: #63c74d;
  color-scheme: dark;
}
html[data-theme="light"] {
  --bg: #eceef4; --bg2: #f4f5fa; --panel: #ffffff; --panel2: #e3e6f0;
  --line: #c3c9dd; --ink: #232637; --muted: #5f6b85; --dim: #8b95ad;
  --green: #3e8948; --green-d: #2d6b36; --gold: #b8860b; --red: #d0333c;
  --cyan: #0f8fa3; --shadow: #9aa2bd66; --focus: #3e8948;
  color-scheme: light;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html { scrollbar-color: var(--line) var(--bg); }
body {
  background: var(--bg); color: var(--ink);
  font-family: "IBM Plex Mono", "Courier New", monospace;
  font-size: 14px; min-height: 100vh;
  transition: background .25s, color .25s;
}
::selection { background: var(--green); color: #10240b; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
img { user-select: none; -webkit-user-drag: none; }

.scanlines {
  pointer-events: none; position: fixed; inset: 0; z-index: 90;
  background: repeating-linear-gradient(0deg, #0000 0 2px, #00000014 2px 4px);
}
html[data-theme="light"] .scanlines { display: none; }
body::after {
  content: ""; pointer-events: none; position: fixed; inset: 0; z-index: 89;
  background: radial-gradient(120% 90% at 50% 0%, #0000 60%, #00000055 100%);
}
html[data-theme="light"] body::after { background: none; }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 28px; border-bottom: var(--px) solid var(--line);
  background: var(--bg2); position: sticky; top: 0; z-index: 50;
}
.navtoggle {
  display: none; background: var(--panel); color: var(--ink);
  border: var(--px) solid var(--line); padding: 9px 12px; cursor: pointer; line-height: 0;
}
.navtoggle .bars { display: inline-block; width: 16px; }
.navtoggle .bars i {
  display: block; height: 2px; margin: 3px 0; background: var(--ink);
}
.brand { display: flex; align-items: baseline; gap: 12px; text-decoration: none; color: var(--ink); }
.brand-heart { width: 22px; height: 22px; image-rendering: pixelated; transform: translateY(4px); }
.brand-name {
  font-family: "Silkscreen", monospace; font-weight: 700; font-size: 20px;
  letter-spacing: 2px; color: var(--gold); text-shadow: 0 3px 0 var(--shadow);
}
.brand-name em { font-style: normal; color: var(--green); }
.brand-sub { font-size: 12px; color: var(--muted); letter-spacing: 4px; }
.topbar-right { display: flex; gap: 10px; margin-left: auto; align-items: center; }
.pill {
  font-family: "Silkscreen", monospace; font-size: 10px; letter-spacing: 1px;
  padding: 7px 12px; text-decoration: none; color: var(--ink); cursor: pointer;
  border: var(--px) solid var(--line); background: var(--panel);
  box-shadow: 0 3px 0 var(--shadow);
}
.pill-mit { color: var(--green); border-color: var(--green-d); }
.pill-gh:hover, .pill-theme:hover { color: var(--gold); border-color: var(--gold); }

/* ---------- hero ---------- */
.hero {
  position: relative; overflow: hidden; border-bottom: var(--px) solid var(--line);
  background:
    radial-gradient(80% 140% at 15% 0%, #63c74d14, transparent 50%),
    radial-gradient(70% 120% at 90% 20%, #fee76112, transparent 55%),
    var(--bg2);
}
.hero-inner { padding: 44px 28px 36px; max-width: 860px; }
.hero-title {
  font-family: "Silkscreen", monospace;
  font-size: clamp(26px, 4.6vw, 44px); letter-spacing: 4px; line-height: 1.1;
  text-shadow: 0 4px 0 var(--shadow);
}
.hero-title::after {
  content: "▮"; color: var(--green); margin-left: 8px;
  animation: blink 1.1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.hero-line { margin-top: 14px; color: var(--muted); font-size: 13px; letter-spacing: 1px; }
.stats { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 24px; }
.stat {
  border: var(--px) solid var(--line); background: var(--panel);
  padding: 10px 16px; min-width: 110px; box-shadow: 0 4px 0 var(--shadow);
}
.stat b { display: block; font-family: "Silkscreen", monospace; font-size: 20px; color: var(--gold); }
.stat span { font-size: 11px; color: var(--muted); letter-spacing: 2px; }
.hero-deco {
  position: absolute; right: 26px; bottom: -4px; display: flex; gap: 18px; align-items: flex-end; opacity: .9;
}
.hero-deco img {
  width: 64px; height: 64px; image-rendering: pixelated;
  filter: drop-shadow(0 6px 0 var(--shadow));
  animation: bob 3.2s ease-in-out infinite;
}
.hero-deco img:nth-child(2n) { animation-delay: -1.1s; width: 52px; height: 52px; }
.hero-deco img:nth-child(3n) { animation-delay: -2.2s; }
@keyframes bob { 50% { transform: translateY(-8px); } }

/* ---------- layout ---------- */
/* footer stays inside .layout (full-width wrap row) so the sticky sidebar's
   containing block ends at the page bottom and never tucks under the topbar */
.layout { display: flex; flex-wrap: wrap; min-height: 70vh; }
.sidebar {
  width: 252px; flex: 0 0 auto; border-right: var(--px) solid var(--line);
  padding: 18px 14px; background: var(--bg2);
  position: sticky; top: var(--topbar-h); align-self: flex-start;
  max-height: calc(100vh - var(--topbar-h));
  max-height: calc(100dvh - var(--topbar-h));
  overflow-y: auto; scrollbar-gutter: stable;
}
.searchbox input {
  width: 100%; padding: 10px 12px; background: var(--bg); color: var(--ink);
  border: var(--px) solid var(--line); outline: none; font: inherit; font-size: 13px;
}
.searchbox input:focus { border-color: var(--green); box-shadow: 0 0 0 2px #63c74d33; }
.filters { display: flex; gap: 6px; margin: 12px 0; }
.fbtn {
  flex: 1; padding: 7px 0; cursor: pointer; font-family: "Silkscreen", monospace;
  font-size: 9px; letter-spacing: 1px; color: var(--muted);
  background: var(--panel); border: var(--px) solid var(--line);
}
.fbtn.active { color: #10240b; background: var(--green); border-color: var(--green); }
html[data-theme="light"] .fbtn.active { color: #fff; }
.viewrow { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
.viewlabel { font-size: 11px; color: var(--muted); flex: 0 0 auto; }
.sortsel {
  flex: 1; font: inherit; font-size: 12px; padding: 6px 8px;
  background: var(--panel); color: var(--ink); border: var(--px) solid var(--line);
}
.density { display: flex; flex: 1; gap: 6px; }
.density button {
  flex: 1; padding: 10px 0; cursor: pointer; color: var(--muted); font-size: 12px;
  background: var(--panel); border: var(--px) solid var(--line); letter-spacing: 0;
}
.density button.active { color: #10240b; background: var(--green); border-color: var(--green); }
html[data-theme="light"] .density button.active { color: #fff; }
.tree { display: flex; flex-direction: column; gap: 2px; }
.tcat {
  margin-top: 12px; padding: 6px 8px; font-family: "Silkscreen", monospace;
  font-size: 10px; letter-spacing: 1px; color: var(--gold); border-bottom: 2px solid var(--line);
}
.tsub {
  display: flex; justify-content: space-between; align-items: center; gap: 6px;
  padding: 6px 8px 6px 14px; cursor: pointer; font-size: 12px; color: var(--ink);
  border-left: 3px solid transparent; background: none; border-top: 0; border-right: 0; border-bottom: 0;
  font-family: inherit; width: 100%; text-align: left;
}
.tsub:hover { background: var(--panel2); }
.tsub.active { background: var(--panel); border-left-color: var(--green); color: var(--green); }
.tsub .n { color: var(--muted); font-size: 11px; }
.sidebar-tip { margin-top: 18px; font-size: 11px; color: var(--muted); opacity: .7; }
.scrim { display: none; }

.main { flex: 1; padding: 22px 26px 60px; min-width: 0; }
.cat-head { margin-bottom: 18px; }
.cat-head h2 { font-family: "Silkscreen", monospace; font-size: 15px; letter-spacing: 2px; }
.cat-head p { color: var(--muted); font-size: 12px; margin-top: 6px; }

/* ---------- grid ---------- */
.grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(var(--card-min), 1fr));
}
html[data-density="s"] { --card-min: 118px; --card-h: 84px; }
html[data-density="m"] { --card-min: 158px; --card-h: 118px; }
html[data-density="l"] { --card-min: 220px; --card-h: 170px; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.card {
  border: var(--px) solid var(--line); background: var(--panel);
  cursor: pointer; overflow: hidden; box-shadow: 0 4px 0 var(--shadow);
  transition: transform .08s steps(2), border-color .12s;
  animation: pop .25s steps(3) backwards;
  /* skip layout/paint of off-screen cards (559 items render at once);
     intrinsic size = preview height + bar/border, measured 39px in all densities */
  content-visibility: auto;
  contain-intrinsic-size: auto calc(var(--card-h) + 39px);
}
.card:hover { transform: translateY(-3px); border-color: var(--green); }
.card:active { transform: translateY(0); }
.card .prev {
  height: var(--card-h); display: flex; align-items: center; justify-content: center;
  background: var(--dim); padding: 10px; position: relative; overflow: hidden;
}
.card:hover .prev img { transform: scale(1.08); }
.card .prev img {
  max-width: 100%; max-height: 100%; image-rendering: pixelated;
  transition: transform .15s steps(3);
}
.card .prev img[data-svg], .lb-stage img[data-svg] { image-rendering: auto; }
.checker {
  background:
    conic-gradient(#cfcfcf 0 25%, #a9a9a9 0 50%, #cfcfcf 0 75%, #a9a9a9 0) 0 0/16px 16px;
}
.card .bar {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 8px 10px; border-top: var(--px) solid var(--line); background: var(--bg);
}
.card .nm { font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .dm { font-size: 10px; color: var(--muted); flex: 0 0 auto; }
.card .src-badge {
  flex: 0 0 auto; width: 10px; height: 10px; background: var(--cyan); box-shadow: 0 0 6px var(--cyan);
}
.card .quick-dl {
  position: absolute; right: 6px; bottom: 6px; display: none;
  background: var(--panel); border: 2px solid var(--line); color: var(--ink);
  font: inherit; font-size: 11px; padding: 3px 8px; cursor: pointer; text-decoration: none;
}
.card:hover .quick-dl { display: block; }
.quick-dl:hover { border-color: var(--green); color: var(--green); }
.empty { color: var(--muted); padding: 40px 0; text-align: center; }
/* visually hidden live region: announces result counts without re-reading the grid */
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* skeleton shimmer */
@keyframes shimmer { 0% { background-position: -300px 0; } 100% { background-position: 300px 0; } }
.skeleton .sk {
  height: calc(var(--card-h) + 37px); border: var(--px) solid var(--line);
  background: linear-gradient(90deg, var(--panel) 25%, var(--panel2) 50%, var(--panel) 75%);
  background-size: 600px 100%; animation: shimmer 1.1s linear infinite;
}

/* ---------- footer ---------- */
.footer {
  flex: 0 0 100%;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 22px; border-top: var(--px) solid var(--line);
  color: var(--muted); font-size: 12px; letter-spacing: 1px; background: var(--bg2);
}
.foot-ico { width: 16px; height: 16px; image-rendering: pixelated; }

/* ---------- lightbox ---------- */
.lightbox { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.lightbox[hidden] { display: none; }
.lb-backdrop { position: absolute; inset: 0; background: #0b0c14e6; backdrop-filter: blur(3px); }
.lb-panel {
  position: relative; width: min(880px, 94vw);
  border: var(--px) solid var(--line); background: var(--bg2);
  box-shadow: 0 10px 0 #000000aa; animation: lbpop .18s steps(3);
}
@keyframes lbpop { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
.lb-close {
  position: absolute; top: -14px; right: -14px; z-index: 2;
  width: 34px; height: 34px; cursor: pointer; font-size: 18px; line-height: 1;
  color: #fff; background: var(--red); border: var(--px) solid var(--bg);
}
.lb-stage {
  height: min(56vh, 480px); display: flex; align-items: center; justify-content: center;
  padding: 26px; border-bottom: var(--px) solid var(--line);
  overflow: auto; position: relative; touch-action: pan-y;
}
.lb-stage img { max-width: 100%; max-height: 100%; image-rendering: pixelated; cursor: zoom-in; transition: transform .12s steps(2); }
.lb-stage img.zoomed { cursor: zoom-out; transform: scale(2.2); }
.lb-arrow {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2;
  width: 40px; height: 44px; cursor: pointer; color: var(--ink); font-size: 13px;
  background: var(--panel); border: var(--px) solid var(--line);
}
.lb-arrow:hover { color: var(--gold); border-color: var(--gold); }
.lb-prev { left: 10px; } .lb-next { right: 10px; }
.lb-meta { padding: 16px 20px 20px; }
.lb-name-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.lb-name-row h2 { font-family: "Silkscreen", monospace; font-size: 16px; letter-spacing: 1px; }
.lb-badge { font-size: 10px; color: #10240b; background: var(--green); padding: 3px 8px; letter-spacing: 1px; }
.lb-counter { margin-left: auto; font-family: "Silkscreen", monospace; font-size: 11px; color: var(--muted); }
.lb-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.tag {
  font-size: 11px; color: var(--muted); background: var(--bg);
  border: 1px solid var(--line); padding: 4px 8px; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lb-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.abtn {
  font-family: "Silkscreen", monospace; font-size: 10px; letter-spacing: 1px;
  color: var(--ink); text-decoration: none; text-align: center;
  background: var(--panel); border: var(--px) solid var(--line);
  padding: 9px 14px; cursor: pointer; box-shadow: 0 3px 0 var(--shadow);
}
.abtn:hover { border-color: var(--green); color: var(--green); }
.abtn:active { transform: translateY(2px); box-shadow: none; }
.abtn-src { color: var(--cyan); border-color: var(--cyan); }
.lb-hint { margin-top: 14px; font-size: 11px; color: var(--dim); }

/* ---------- responsive ---------- */
@media (max-width: 1280px) { .hero-deco { display: none; } }
@media (max-width: 860px) {
  .navtoggle { display: block; }
  .brand-sub { display: none; }
  .topbar {
    flex-wrap: wrap; row-gap: 8px;
    padding: 12px 16px; padding-left: max(12px, env(safe-area-inset-left));
  }
  .layout { flex-direction: column; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 80; width: min(300px, 86vw);
    transform: translateX(-102%); transition: transform .18s steps(4);
    overflow-y: auto; padding-top: 20px; max-height: none; align-self: auto;
  }
  .sidebar.open { transform: none; box-shadow: 12px 0 0 #00000040; }
  .scrim {
    display: block; position: fixed; inset: 0; z-index: 70;
    background: #0b0c14b0; border: 0;
  }
  .scrim[hidden] { display: none; }
  .main { padding: 16px 14px calc(60px + env(safe-area-inset-bottom)); }
  .grid { gap: 10px; grid-template-columns: repeat(auto-fill, minmax(min(var(--card-min), 44vw), 1fr)); }
  .lb-stage { height: 52dvh; padding: 12px; }
  .lb-close { top: 10px; right: 10px; width: 44px; height: 44px; font-size: 20px; }
  .lb-panel { width: 100vw; height: 100dvh; border: 0; display: flex; flex-direction: column; justify-content: center; }
  .lb-meta { padding: 12px 14px calc(16px + env(safe-area-inset-bottom)); }
  .lb-hint { display: none; }
  .footer { font-size: 10px; text-align: center; padding: 16px; }
}
@media (max-width: 480px) {
  .topbar { gap: 8px; }
  .brand { gap: 8px; }
  .brand-heart { width: 18px; height: 18px; }
  .brand-name { font-size: 16px; letter-spacing: 1px; }
  .pill { padding: 6px 10px; }
  .pill-mit { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
