:root {
  --bg: #f2f3f5;
  --panel: #ffffff;
  --ink: #17191c;
  --muted: #697079;
  --line: #dcdfe4;
  --accent: #2b59ff;
  --accent-ink: #ffffff;
  --tile: #e4e6ea;
  --gap: 12px;
  --radius: 6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111315;
    --panel: #181b1e;
    --ink: #eceef0;
    --muted: #8d949c;
    --line: #2a2e33;
    --accent: #7c9bff;
    --accent-ink: #0d1020;
    --tile: #20242a;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body.lb-open { overflow: hidden; }

.muted { color: var(--muted); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: 100vh;
}

.side {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
  padding: 20px 14px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.brand {
  margin: 0 8px 16px;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.tree { display: flex; flex-direction: column; gap: 1px; }

.tree a {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  padding-left: calc(8px + var(--depth, 0) * 14px);
  border-radius: var(--radius);
  color: inherit;
  text-decoration: none;
}

.tree a:hover { background: var(--bg); }

.tree a[aria-current="page"] {
  background: var(--accent);
  color: var(--accent-ink);
}

.tree .n { color: var(--muted); font-variant-numeric: tabular-nums; }
.tree a[aria-current="page"] .n { color: inherit; opacity: .8; }

.main { padding: 20px 24px 48px; min-width: 0; }

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 12px 24px;
  margin-bottom: 18px;
}

.heading h2 { margin: 0; font-size: 1.5rem; letter-spacing: -0.01em; }
.heading p { margin: 2px 0 0; }

.controls { display: flex; gap: 8px; }

.controls input,
.controls select {
  font: inherit;
  color: inherit;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 10px;
}

.controls input { width: 220px; }

.status {
  margin: 48px 0;
  text-align: center;
  color: var(--muted);
}

/* Masonry: columns are created by app.js, each tile goes to the shortest one */
.grid {
  display: flex;
  align-items: flex-start;
  gap: var(--gap);
}

.col {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.tile {
  display: block;
  background: var(--tile);
  border-radius: var(--radius);
  overflow: hidden;
}

.tile img {
  display: block;
  width: 100%;
  height: auto;
  transition: opacity .15s;
}

.tile:hover img { opacity: .88; }

.sentinel { height: 1px; }

/* Lightbox */
.lb {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: rgba(8, 9, 11, .94);
  color: #eceef0;
}

.lb[hidden] { display: none; }

.lb-fig {
  margin: 0;
  max-width: 100vw;
  display: grid;
  justify-items: center;
  gap: 10px;
}

.lb-fig img {
  max-width: 100vw;
  max-height: calc(100vh - 70px);
  object-fit: contain;
}

.lb-cap {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  justify-content: center;
  padding: 0 64px;
  font-size: 14px;
}

.lb-cap a { color: #9db4ff; }
.lb-cap .muted { color: #9aa1a9; }

.lb-btn {
  position: absolute;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .1);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

.lb-btn:hover { background: rgba(255, 255, 255, .2); }
.lb-close { top: 14px; right: 14px; }
.lb-prev  { left: 14px; top: 50%; transform: translateY(-50%); }
.lb-next  { right: 14px; top: 50%; transform: translateY(-50%); }

/* Narrow screens: folders move above the grid */
@media (max-width: 760px) {
  .layout { grid-template-columns: minmax(0, 1fr); }

  .side {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 14px;
  }

  .brand { margin-bottom: 8px; }

  .tree { flex-direction: row; flex-wrap: wrap; gap: 6px; }

  .tree a {
    padding: 5px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
  }

  .tree a[aria-current="page"] { border-color: var(--accent); }

  .main { padding: 16px 14px 40px; }
  .grid, .col { gap: 8px; }
  .controls { width: 100%; }
  .controls input { flex: 1; width: auto; min-width: 0; }
  .lb-prev, .lb-next { top: auto; bottom: 14px; transform: none; }
  .lb-cap { padding: 0 16px 56px; }
}

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