:root {
  --bg: #0b0c10;
  --surface: #14161c;
  --line: #262a33;
  --text: #e8e9ec;
  --muted: #8a8f9a;
  --accent: #e8b04a;
  --row-h: 220px;
  --gap: 4px;
  color-scheme: dark;
}
@media (max-width: 700px) {
  :root { --row-h: 120px; --gap: 2px; }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
h1 { font-size: 20px; margin: 0; font-weight: 600; }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 12px; }
.grow { flex: 1; }
[hidden] { display: none !important; }

button, select, input {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; min-height: 34px;
}
button { cursor: pointer; white-space: nowrap; }
button:hover { border-color: #3a3f4a; }
button.primary { background: var(--accent); color: #111; border-color: var(--accent); font-weight: 600; }
button.on { background: var(--text); color: #111; border-color: var(--text); }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* header */
.top { position: sticky; top: 0; z-index: 5; background: rgba(11, 12, 16, .94); backdrop-filter: blur(8px);
  padding: 12px 16px 8px; padding-top: max(12px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); }
.top-row { display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.actions { display: flex; gap: 6px; }
.filters { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.filters input[type=search] { flex: 1; min-width: 160px; }
.seg { display: inline-flex; }
.seg button { border-radius: 0; margin-left: -1px; }
.seg button:first-child { border-radius: 8px 0 0 8px; margin-left: 0; }
.seg button:last-child { border-radius: 0 8px 8px 0; }

.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin-top: 8px; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chips:empty { display: none; }
.chip { border-radius: 999px; padding: 4px 12px; min-height: 30px; font-size: 14px; }
.chip .n { color: var(--muted); margin-left: 6px; font-size: 12px; }
.chip.on .n { color: #444; }
.chip .x { margin-left: 8px; color: var(--muted); }

/* grid: justified rows, each tile as wide as its picture's ratio */
main { padding: var(--gap); padding-bottom: 90px; }
.grid { display: flex; flex-wrap: wrap; gap: var(--gap); }
.grid::after { content: ""; flex-grow: 999999; }
.tile { position: relative; flex-grow: var(--r); width: calc(var(--r) * var(--row-h)); height: var(--row-h);
  background: var(--surface); overflow: hidden; cursor: pointer; border: 0; padding: 0; border-radius: 2px; min-height: 0; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .dur { position: absolute; right: 6px; bottom: 6px; background: rgba(0,0,0,.65); color: #fff;
  font-size: 12px; padding: 1px 6px; border-radius: 4px; font-variant-numeric: tabular-nums; }
.tile .noimg { display: grid; place-items: center; height: 100%; color: var(--muted); font-size: 12px; padding: 6px; word-break: break-all; }
.tile.sel { outline: 3px solid var(--accent); outline-offset: -3px; }
.tile.sel img { opacity: .7; }
.selecting .tile:not(.sel) img { opacity: .9; }
.empty { text-align: center; padding: 60px 20px; }
#sentinel { height: 1px; }

/* selection bar */
.selbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; gap: 8px; align-items: center;
  padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom)); background: var(--surface);
  border-top: 1px solid var(--line); flex-wrap: wrap; }
.selbar input { flex: 1; min-width: 120px; }

/* viewer */
.viewer { position: fixed; inset: 0; z-index: 10; background: #000; display: flex; flex-direction: column; }
.v-top { display: flex; gap: 8px; align-items: center; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
.v-top button { background: rgba(255,255,255,.08); border-color: transparent; }
.v-top button.primary { background: var(--accent); }
.v-top button.on { background: var(--text); color: #111; }
.v-stage { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.v-media { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; touch-action: pan-y pinch-zoom; }
.v-media img, .v-media video { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.v-zone { position: absolute; top: 0; bottom: 0; width: 18%; background: transparent; border: 0; border-radius: 0; z-index: 1; }
.v-zone:hover { background: linear-gradient(90deg, rgba(255,255,255,.05), transparent); }
.v-next:hover { background: linear-gradient(270deg, rgba(255,255,255,.05), transparent); }
.v-prev { left: 0; }
.v-next { right: 0; }
.v-stage.is-video .v-zone { top: 0; bottom: 70px; }
.v-info { display: flex; gap: 16px; padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: #0b0c10; border-top: 1px solid var(--line); flex-wrap: wrap; align-items: flex-start; }
.v-meta { display: flex; flex-direction: column; gap: 2px; min-width: 180px; }
.v-meta a { color: var(--muted); }
.v-tags { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 220px; }
.v-tags .chips { margin-top: 0; }
.v-tagform input { width: 100%; max-width: 320px; }

@media (max-width: 700px) {
  .top { padding: 10px 10px 6px; }
  .actions button { padding: 6px 10px; }
  #slideBtn { display: none; }
  .v-top { gap: 4px; padding-left: 6px; padding-right: 6px; }
  .v-top button { padding: 6px 8px; font-size: 14px; }
  #vPos { white-space: nowrap; font-size: 13px; }
  #count { display: block; font-size: 12px; }
  .filters select { flex: 1; }
  .v-zone { width: 25%; }
  .v-info { max-height: 38vh; overflow-y: auto; }
}

/* upload sheet: centred on a computer, from the bottom on a phone */
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; }
.sheet-box { width: min(520px, 100%); max-height: 100%; overflow-y: auto; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.sheet-head h2 { font-size: 17px; margin: 0; font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.field input, .field select { color: var(--text); background: var(--bg); }
.filepick { position: relative; display: block; border: 1px dashed #3a3f4a; border-radius: 10px; padding: 18px; text-align: center; cursor: pointer; }
.filepick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.filepick:hover { border-color: var(--accent); }
.uplist { display: flex; flex-direction: column; gap: 4px; max-height: 32vh; overflow-y: auto; font-size: 13px; }
.uplist:empty { display: none; }
.uprow { display: flex; gap: 8px; justify-content: space-between; }
.uprow .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uprow .st { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.uprow.done .st { color: #7bd88f; }
.uprow.err .st { color: #ff7a6b; }
.upbar { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; }
#upBar { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
#upStart:disabled { opacity: .5; cursor: default; }
@media (max-width: 700px) {
  .sheet { align-items: flex-end; }
  .sheet-box { border-radius: 14px 14px 0 0; padding-bottom: max(16px, env(safe-area-inset-bottom)); max-height: 92vh; }
}

button.linkish { background: none; border: 0; padding: 0; min-height: 0; color: var(--muted); text-align: left;
  text-decoration: underline dotted; text-underline-offset: 3px; }
button.linkish:hover { color: var(--text); }
.picks { display: flex; gap: 8px; }
.picks .filepick { flex: 1; }
#upPickText { margin: -4px 0 0; }
#upPickText:empty { display: none; }
button.danger { color: #ff7a6b; }
.v-top button.danger { color: #ff9b8f; }
#tagBox { margin-top: 8px; }
#tagBox .chips { margin-top: 0; }
.small-btn { margin-top: 8px; font-size: 13px; min-height: 28px; padding: 3px 10px; }
.tagedit { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 999px; padding: 2px 4px 2px 12px; font-size: 14px; }
.tagedit .n { color: var(--muted); font-size: 12px; margin-right: 4px; }
.tagedit button { min-height: 26px; padding: 2px 8px; font-size: 12px; border-radius: 999px; }

/* login */
.login-body { min-height: 100vh; display: grid; place-items: center; }
.login { display: flex; flex-direction: column; gap: 12px; width: min(320px, 90vw); }
.login .error { color: #ff7a6b; margin: 0; }
