:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --ink: #161513;
  --muted: #77726a;
  --line: #dcd8d0;
  --accent: #161513;
  --on-accent: #f4f2ee;
  --ph: #e4e0d8;
  --gap: 6px;
  --gutter: clamp(14px, 3vw, 36px);
  --sans: "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
}
:root[data-theme="dark"] {
  --bg: #0f0f0e;
  --surface: #181816;
  --ink: #eceae5;
  --muted: #8f8a80;
  --line: #2a2926;
  --accent: #eceae5;
  --on-accent: #0f0f0e;
  --ph: #1c1c1a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0f0e; --surface: #181816; --ink: #eceae5; --muted: #8f8a80;
    --line: #2a2926; --accent: #eceae5; --on-accent: #0f0f0e; --ph: #1c1c1a;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--sans); min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; padding: 0 var(--gutter) 64px; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
svg { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* ---------- header ---------- */
.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-bottom: 1px solid var(--line); }
.top-inner { display: flex; align-items: center; gap: 20px; padding: 12px var(--gutter); }
.brand { font-size: 12px; letter-spacing: .14em; text-transform: uppercase; text-decoration: none; white-space: nowrap; font-weight: 500; }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tab { background: none; border: 0; padding: 7px 12px; border-radius: 99px; color: var(--muted); white-space: nowrap; }
.tab:hover { color: var(--ink); }
.tab[aria-current="true"] { background: var(--ink); color: var(--bg); }
.icon-btn { background: none; border: 0; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); flex: none; }
.icon-btn:hover { color: var(--ink); background: var(--line); }
.icon-btn svg { width: 18px; height: 18px; }

.search { position: relative; flex: 1 1 420px; max-width: 640px; display: flex; align-items: center; }
.search > svg { position: absolute; left: 13px; width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.search input { width: 100%; padding: 10px 38px 10px 38px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); outline: none; text-overflow: ellipsis; -webkit-appearance: none; }
.search input::-webkit-search-cancel-button { display: none; }
.search input:focus { border-color: var(--ink); }
.search input::placeholder { color: var(--muted); }
#clear { position: absolute; right: 4px; }
.suggest { position: absolute; top: calc(100% + 6px); left: 0; right: 0; list-style: none; margin: 0; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.suggest li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.suggest li[aria-selected="true"], .suggest li:hover { background: var(--line); }
.suggest .kind { color: var(--muted); font-size: 12px; }
.suggest .n { color: var(--muted); font-variant-numeric: tabular-nums; }

.filters { padding: 0 var(--gutter) 12px; display: grid; gap: 10px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.filter-row.small { gap: 14px; }
.chip { border: 1px solid var(--line); background: none; padding: 5px 12px; border-radius: 99px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.chip:hover { color: var(--ink); border-color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip .n { opacity: .6; margin-left: 5px; font-variant-numeric: tabular-nums; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 99px; padding: 2px; }
.seg button { border: 0; background: none; padding: 3px 11px; border-radius: 99px; color: var(--muted); font-size: 13px; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.sel { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 99px; padding: 5px 12px; font-size: 13px; max-width: 100%; }
.check { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); font-size: 13px; cursor: pointer; }
.link-btn { background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; font-size: 13px; }
.link-btn:hover { color: var(--ink); }

/* ---------- admin ---------- */
.admin-only { display: none !important; }
body.admin .admin-btns { display: flex !important; gap: 6px; margin-left: auto; }
body.admin .admin-btns + .tabs { margin-left: 0; }
body.admin .admin-only:not(.admin-btns) { display: inline-flex !important; }
body.admin button.admin-only { display: inline-block !important; }
.pill { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 99px; padding: 6px 14px; font-size: 13px; white-space: nowrap; }
.pill:hover { border-color: var(--muted); }
.pill[aria-pressed="true"], .pill.solid { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.pill.danger { color: #c0392b; border-color: color-mix(in srgb, #c0392b 45%, var(--line)); background: none; }
.pill.danger:hover { background: #c0392b; color: #fff; border-color: #c0392b; }
.drop-ov { position: fixed; inset: 0; z-index: 90; background: rgba(0,0,0,.6); display: grid; place-items: center; pointer-events: none; }
.drop-ov > div { border: 2px dashed #fff; border-radius: 18px; padding: 48px 64px; color: #fff; font-size: 22px; }
.modal { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 16px; }
.modal-box { width: min(480px, 100%); max-height: 90vh; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 22px; display: grid; gap: 14px; }
.modal-box h2 { font-size: 18px; font-weight: 500; }
.modal-box label, .lb-edit label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }
.modal-box input, .modal-box select, .lb-edit input:not([type=checkbox]), .lb-edit select,

.selbar select { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; width: 100%; }
.modal-btns { display: flex; gap: 8px; justify-content: flex-end; }
.bar { height: 6px; border-radius: 9px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--ink); transition: width .2s; }
.uplist { list-style: none; margin: 0; padding: 0; max-height: 180px; overflow: auto; font-size: 12px; color: var(--muted); display: grid; gap: 3px; }
.uplist .bad { color: #c0392b; }
.selbar { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 30; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; justify-content: center; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 10px 16px; box-shadow: 0 10px 40px rgba(0,0,0,.3); max-width: calc(100vw - 24px); }
.selbar select { width: auto; }
body.selecting .tile { cursor: pointer; }
body.selecting .tile::after { content: ""; position: absolute; top: 8px; left: 8px; width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; background: rgba(0,0,0,.35); }
body.selecting .tile.sel::after { background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='m5 10.5 3.2 3.2L15 6.8' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/16px no-repeat; }
body.selecting .tile.sel img { opacity: .6; }
.lb-edit { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px 12px; margin-bottom: 12px; }
.lb-edit .wide, .lb-edit .check, .lb-edit-btns { grid-column: 1 / -1; }
.lb-edit label { color: #9d988e; }
.lb-edit input:not([type=checkbox]), .lb-edit select { background: #151513; border-color: #34332f; color: #eceae5; }
.lb-edit .pill { background: none; border-color: #34332f; color: #eceae5; }
.lb-edit .pill.solid { background: #eceae5; color: #0a0a09; }
.lb-edit .pill.danger { margin-left: auto; color: #e66; }
.lb-edit-btns { display: flex; gap: 8px; }
@media (max-width: 760px) { .lb-edit { grid-template-columns: 1fr; } .admin-btns { width: 100%; order: 3; } .admin-btns + .tabs { order: 3; } }

.modal-box.wide { width: min(720px, 100%); }
.mg-head { display: flex; align-items: center; gap: 14px; }
.mg-head h2 { margin-right: auto; }
.mg-sec { display: grid; gap: 6px; }
.mg-sec h3 { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; font-weight: 500; color: var(--muted); margin-top: 10px; }
.mg-row { display: grid; grid-template-columns: minmax(0, 1fr) 120px 34px auto; gap: 8px; align-items: center; padding: 4px 0; border-bottom: 1px solid var(--line); }
.mg-row.genre { grid-template-columns: minmax(0, 1fr) 34px auto; }
.mg-row input, .mg-row select { padding: 6px 9px !important; }
.mg-row .n { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; }
.mg-row.add { border: 0; padding-top: 12px; }
.mg-confirm { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; padding: 4px 0 8px; }
.mg-confirm select { width: auto !important; }
.pill.small { padding: 4px 11px; font-size: 12px; }
@media (max-width: 760px) { .mg-row { grid-template-columns: minmax(0, 1fr) 100px auto; } .mg-row .n, .mg-row.add > span { display: none; } }

/* ---------- collections ---------- */
.group { margin-top: 44px; }
.group > h2 { font-size: 12px; letter-spacing: .14em; text-transform: uppercase; font-weight: 500; margin-bottom: 4px; }
.group > p { color: var(--muted); margin-bottom: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 14px; }
.card { position: relative; display: block; aspect-ratio: 4 / 5; overflow: hidden; border-radius: 4px; background: var(--ph); text-decoration: none; color: #fff; isolation: isolate; }
.card img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transition: transform .6s cubic-bezier(.2,.7,.2,1); z-index: -2; }
.card::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to top, rgba(0,0,0,.7), rgba(0,0,0,0) 55%); z-index: -1; }
.card:hover img { transform: scale(1.04); }
.card .label { position: absolute; left: 14px; right: 14px; bottom: 12px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card .name { font-size: 16px; font-weight: 500; }
.card .count { font-size: 12px; opacity: .8; font-variant-numeric: tabular-nums; }

/* ---------- results ---------- */
.results-head { padding: 28px 0 14px; display: flex; flex-wrap: wrap; gap: 4px 18px; align-items: baseline; }
.results-head h1 { font-size: 22px; font-weight: 400; letter-spacing: -.01em; }
.cloud { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.grid { position: relative; }
.row { display: flex; gap: var(--gap); margin-bottom: var(--gap); }
.tile { position: relative; display: block; flex: none; background: var(--ph); overflow: hidden; border-radius: 2px; cursor: zoom-in; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .35s; }
.tile img.in { opacity: 1; }
.tile .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 22px 10px 8px; color: #fff; font-size: 12px; background: linear-gradient(to top, rgba(0,0,0,.65), transparent); opacity: 0; transition: opacity .2s; pointer-events: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile:hover .cap, .tile:focus-visible .cap { opacity: 1; }
.empty { padding: 60px 0; text-align: center; }
.empty .cloud { justify-content: center; margin-top: 12px; }
.foot { padding: 20px var(--gutter) 28px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); }

/* ---------- lightbox ---------- */
.lb { position: fixed; inset: 0; z-index: 50; background: #0a0a09; color: #eceae5; display: flex; flex-direction: column; }
.lb-stage { position: relative; flex: 1; min-height: 0; touch-action: pan-y; }
/* the image is pinned to the stage and letterboxed with object-fit, so any shape stays centred and never overflows */
.lb-stage img { position: absolute; inset: 56px 64px 8px; width: calc(100% - 128px); height: calc(100% - 64px); object-fit: contain; user-select: none; -webkit-user-drag: none; }
.lb-stage img.loading { filter: blur(6px); }
.lb-btn { position: absolute; background: none; border: 0; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; color: #eceae5; opacity: .75; }
.lb-btn:hover { opacity: 1; background: rgba(255,255,255,.1); }
.lb-btn svg { width: 22px; height: 22px; }
.lb-close { top: 8px; right: 10px; }
.lb-prev { left: 8px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 8px; top: 50%; transform: translateY(-50%); }
.lb-info { flex: none; padding: 10px var(--gutter) 18px; max-width: 980px; width: 100%; margin: 0 auto; }
.lb-info.collapsed .cloud { display: none; }
.lb-meta { display: flex; justify-content: space-between; gap: 20px; align-items: flex-end; margin-bottom: 10px; }
.lb-meta h2 { font-size: 17px; font-weight: 400; }
.lb-meta .muted, .lb .link-btn { color: #9d988e; }
.lb .link-btn:hover { color: #fff; }
.lb-actions { display: flex; gap: 16px; flex: none; }
.lb .chip { color: #aaa59b; border-color: #34332f; font-size: 12px; padding: 3px 10px; }
.lb .chip:hover { color: #fff; border-color: #77726a; }
.lb .cloud { margin-bottom: 0; }

@media (max-width: 760px) {
  .top { position: static; }
  .filters { gap: 8px; padding-bottom: 10px; }
  .filter-row, .filter-row.small, #resultsView .cloud { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-inline: calc(var(--gutter) * -1); padding-inline: var(--gutter); }
  .filter-row::-webkit-scrollbar, #resultsView .cloud::-webkit-scrollbar { display: none; }
  .filter-row > *, #resultsView .cloud > * { flex: none; }
  #resultsView .cloud { margin-bottom: 12px; }
  .results-head { padding-top: 18px; }
  .top-inner { flex-wrap: wrap; gap: 10px 8px; }
  .brand { flex: 1; }
  .tabs { order: 3; margin-left: 0; width: 100%; }
  .search { order: 4; flex-basis: 100%; max-width: none; }
  .tab { flex: 1; text-align: center; background: none; border: 1px solid var(--line); }
  .tab[aria-current="true"] { border-color: var(--ink); }
  .lb-stage img { inset: 52px 0 4px; width: 100%; height: calc(100% - 56px); }
  .lb-prev, .lb-next { display: none; }
  .lb-meta { flex-direction: column; align-items: flex-start; gap: 6px; }
  :root { --gap: 4px; }
  .card { aspect-ratio: 1 / 1; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

@media (max-height: 700px) {
  .lb-info .cloud { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .lb-info .cloud > * { flex: none; }
}

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 120; background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 99px; font-size: 13px; box-shadow: 0 8px 30px rgba(0,0,0,.35); }

.lb-file { font-size: 12px; color: #9d988e; margin: 2px 0 4px; font-variant-numeric: tabular-nums; user-select: all; overflow-wrap: anywhere; }

/* ---------- my folder / downloads ---------- */
.user-btns { display: flex; gap: 6px; flex: none; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 99px; background: var(--ink); color: var(--bg); font-size: 11px; line-height: 18px; text-align: center; font-variant-numeric: tabular-nums; }
.pill:disabled { opacity: .5; cursor: default; }
.fv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.fv-item { position: relative; aspect-ratio: 1 / 1; border-radius: 6px; overflow: hidden; background: var(--ph); }
.fv-item img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.fv-item button { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; line-height: 1; font-size: 14px; }
.fv-item button:hover { background: #c0392b; }
.fv-empty { grid-column: 1 / -1; padding: 28px 0; text-align: center; color: var(--muted); }
.lb-actions { flex-wrap: wrap; justify-content: flex-end; }
.lb-actions .link-btn[disabled] { opacity: .5; }
@media (max-width: 760px) { .user-btns { order: 2; } .tabs { order: 3; } }
