/* A contact sheet on a neutral grey light table: grey so photos are judged
   fairly, grease-pencil red only for the frames you've marked. */
:root {
  --table: #303134;      /* neutral mid-dark grey, like an editing app's backdrop */
  --sheet: #3a3b3f;      /* raised surfaces: bar, cards, inputs */
  --rule: #4c4d52;
  --ink: #ecebe8;
  --muted: #a7a6a1;
  --marker: #f0442c;     /* china-marker red, used only for selections */
  --dark: #1e1f21;       /* viewer backdrop */
  --radius: 3px;
  --pad: clamp(16px, 4vw, 48px);
  --cond: "Barlow Condensed", "Arial Narrow", sans-serif;
  --text: "Barlow", system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--table);
  color: var(--ink);
  font: 400 16px/1.5 var(--text);
  -webkit-font-smoothing: antialiased;
}
body.viewing { overflow: hidden; }
a { color: inherit; }
img { display: block; }
code { font-size: .9em; background: var(--sheet); padding: 1px 5px; border-radius: var(--radius); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
main:focus { outline: none; }

/* ---------------------------------------------------------------- header */
.site {
  display: flex; align-items: baseline; gap: 24px;
  padding: 22px var(--pad) 0;
}
.brand {
  font: 600 22px/1 var(--cond);
  letter-spacing: .01em;
  text-decoration: none;
}
.back { color: var(--muted); text-decoration: none; font-size: 15px; }
.back::before { content: "‹ "; }
.back:hover { color: var(--ink); }

.loading, .empty { padding: 48px var(--pad); color: var(--muted); }
.problem { padding: 48px var(--pad); max-width: 60ch; }

/* --------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px;
  font: 500 15px/1 var(--text); color: var(--ink);
  background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius);
  text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--ink); color: var(--table); border-color: var(--ink); font-weight: 600; }
.btn.primary:hover { background: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { border-color: var(--rule); }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--muted); font: inherit; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.link:hover { color: var(--ink); }

/* ------------------------------------------------------- collection list */
.collections { padding: 40px var(--pad) 96px; display: grid; gap: clamp(40px, 7vw, 88px); }
.col { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: clamp(20px, 4vw, 56px); align-items: end; }
.cover {
  display: block; aspect-ratio: var(--r, 1.5); max-height: 70vh; width: 100%;
  background: var(--sheet); overflow: hidden; border-radius: var(--radius);
}
.cover img { width: 100%; height: 100%; object-fit: cover; }
.cover.blank { display: grid; place-items: center; aspect-ratio: 3 / 2; color: var(--muted); font: 500 20px var(--cond); }
.col h2 {
  margin: 0 0 12px;
  font: 600 clamp(40px, 6vw, 84px)/.92 var(--cond);
  letter-spacing: -.01em;
  text-wrap: balance;
}
.col h2 a { text-decoration: none; }
.col h2 a:hover { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 6px; }
.desc { margin: 0 0 8px; max-width: 46ch; }
.facts { margin: 0; color: var(--muted); font-size: 15px; }
.slot { margin-top: 20px; }

.unlock { max-width: 380px; }
.unlock label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.unlock .row { display: flex; gap: 8px; }
.unlock input, .field input, .field select {
  flex: 1; min-width: 0; min-height: 40px; padding: 0 12px;
  font: 16px var(--text); color: var(--ink);
  background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius);
}
.unlock input:focus, .field input:focus, .field select:focus { outline: none; border-color: var(--ink); }
.err { min-height: 1.5em; margin: 6px 0 0; color: #ff9b8a; font-size: 14px; }

.gate { padding: 12vh var(--pad); }
.gate h1, .intro h1, .admin h1 {
  margin: 0 0 12px; font: 600 clamp(44px, 7vw, 96px)/.92 var(--cond); letter-spacing: -.01em; text-wrap: balance;
}
.gate p { color: var(--muted); margin: 0 0 24px; }

/* --------------------------------------------------------------- sheet */
.intro { padding: 36px var(--pad) 28px; }
.intro .facts { max-width: 70ch; }

.sheet {
  display: flex; flex-wrap: wrap; gap: 18px var(--gap, 10px);
  padding: 0 var(--pad) 140px;
}
.frame { position: relative; margin: 0; flex: none; }
.shot { display: block; position: relative; height: var(--h, 200px); background: var(--sheet); }
.shot img { width: 100%; height: 100%; object-fit: cover; }
.frame figcaption {
  display: flex; justify-content: space-between; gap: 8px;
  padding-top: 5px; height: 22px;
  font: 500 13px/1.2 var(--cond); letter-spacing: .04em; color: var(--muted);
  white-space: nowrap; overflow: hidden;
}
.frame .ext { opacity: .7; }

/* Video poster overlay: play badge + duration */
.vid {
  position: absolute; right: 6px; bottom: 6px; z-index: 1;
  display: flex; align-items: center; gap: 4px;
  padding: 2px 6px; border-radius: 3px;
  background: rgba(0, 0, 0, .55); color: #fff; font: 500 11px var(--cond); letter-spacing: .03em;
}
.vid .play { width: 13px; height: 13px; fill: #fff; }

/* Grease-pencil loop around marked frames */
.mark {
  position: absolute; inset: -7px; width: calc(100% + 14px); height: calc(100% + 14px);
  pointer-events: none; overflow: visible;
}
.mark path {
  fill: none; stroke: var(--marker); stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.mark { opacity: 0; transform: scale(1.04) rotate(.4deg); transition: opacity .16s, transform .22s cubic-bezier(.3, 0, .2, 1); }
.frame.on .mark { opacity: 1; transform: none; }
.frame.on figcaption { color: var(--marker); }
.frame.on figcaption .num::after { content: " ✓"; }

/* Corner tick for selecting */
.pick {
  position: absolute; z-index: 2; top: 6px; left: 6px;
  width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%;
  background: transparent; cursor: pointer;
  display: grid; place-items: center;
  opacity: 0; transition: opacity .12s;
}
.pick span {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid #fff; background: rgba(0, 0, 0, .28);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .25);
}
.frame:hover .pick, .pick:focus-visible, body.selecting .pick, .frame.on .pick { opacity: 1; }
.frame.on .pick span { background: var(--marker); border-color: var(--marker); }
.frame.on .pick span::after {
  content: ""; display: block; width: 6px; height: 11px; margin: 2px auto 0;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
@media (hover: none) { .pick { opacity: 1; } }
body.selecting .shot { cursor: copy; }

/* ----------------------------------------------------------------- bar */
.bar {
  position: fixed; z-index: 10; left: 50%; bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(920px, calc(100% - 32px));
  display: flex; align-items: center; gap: 16px;
  padding: 10px 10px 10px 18px;
  background: var(--sheet); border: 1px solid var(--rule); border-radius: 6px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
}
.bar.has-sel { border-color: var(--marker); }
.bar .count { display: flex; flex-direction: column; min-width: 0; }
.bar .count strong { font-weight: 600; white-space: nowrap; }
.bar .count .link { align-self: flex-start; font-size: 14px; }
.dlrow { display: flex; flex-wrap: wrap; gap: 8px; flex: 1; justify-content: flex-end; }
.btn.dl {
  flex-direction: column; align-items: flex-start; gap: 1px;
  min-width: 84px; padding: 6px 14px; min-height: 40px;
}
.btn.dl span { font-size: 12px; font-weight: 400; color: var(--muted); }
.btn.dl:disabled span { color: inherit; opacity: .8; }
.btn.save-photos { min-height: 40px; }

@media (max-width: 720px) {
  .col { grid-template-columns: 1fr; }
  .bar { flex-wrap: wrap; gap: 10px; padding: 10px; bottom: 8px; width: calc(100% - 16px); }
  .bar .count { flex-basis: 100%; }
  .dlrow { flex-basis: 100%; justify-content: flex-start; }
  .btn.dl { flex: 1; min-width: 0; }
  .sheet { padding-bottom: 200px; row-gap: 12px; }
  .frame figcaption { font-size: 11px; }
}

/* -------------------------------------------------------------- viewer */
.viewer {
  position: fixed; inset: 0; z-index: 50;
  display: grid; grid-template-rows: auto 1fr auto;
  background: var(--dark);
}
.viewer[hidden] { display: none; }
.v-top, .v-bottom { display: flex; align-items: center; gap: 16px; padding: 10px 16px; }
.v-name { font: 600 20px var(--cond); letter-spacing: .03em; }
.v-pos { color: var(--muted); font-size: 14px; flex: 1; }
.v-stage { position: relative; min-height: 0; overflow: hidden; }
.v-img {
  position: absolute; top: 0; bottom: 0; left: 64px; right: 64px;
  width: calc(100% - 128px); height: 100%; object-fit: contain;
  background: center / contain no-repeat;
}
.v-img.loading { filter: blur(6px); }
.v-badge {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  display: flex; align-items: center; gap: 8px; pointer-events: none;
  padding: 8px 14px; border-radius: 6px; background: rgba(0, 0, 0, .5); color: #fff;
  font: 500 15px var(--cond); letter-spacing: .03em;
}
.v-badge .play { width: 22px; height: 22px; fill: #fff; }
.v-exif { margin: 0; padding: 6px 16px 0; color: var(--muted); font-size: 13px; text-align: center; }
.v-exif[hidden], .v-badge[hidden] { display: none; }
.v-top .v-zoom[hidden] { display: none; }
.v-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 48px; height: 72px; border: 0; background: transparent; cursor: pointer; color: var(--ink);
  border-radius: var(--radius);
}
.v-nav:hover { background: rgba(255, 255, 255, .06); }
.v-nav svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2; }
.prev { left: 8px; } .next { right: 8px; }
.v-bottom { justify-content: space-between; flex-wrap: wrap; }
.v-pick[aria-pressed="true"] { color: var(--marker); border-color: var(--marker); }
.v-pick[aria-pressed="true"]::before { content: "✓"; }
.v-dl { display: flex; gap: 8px; flex-wrap: wrap; }
.v-dl .btn span { color: var(--muted); font-weight: 400; font-size: 13px; }
@media (max-width: 720px) {
  .v-img { left: 0; right: 0; width: 100%; }
  .v-nav { display: none; }
  .v-dl { width: 100%; }
  .v-dl .btn { flex: 1; flex-direction: column; gap: 0; min-height: 48px; }
}

/* --------------------------------------------------------------- toast */
#toast {
  position: fixed; z-index: 60; top: 16px; left: 50%; transform: translate(-50%, -12px);
  max-width: min(560px, calc(100% - 32px));
  padding: 10px 16px; border-radius: 6px;
  background: var(--ink); color: var(--table); font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------------------------------------------------- zip panels */
.zipprog, .zipparts {
  position: fixed; z-index: 55; left: 50%; bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(420px, calc(100% - 32px));
  padding: 14px 16px; background: var(--sheet); border: 1px solid var(--rule); border-radius: 6px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
}
.zp-row, .zp-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.zp-row strong, .zp-head strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.zp-bar { height: 6px; margin-top: 10px; background: var(--table); border-radius: 3px; overflow: hidden; }
.zp-fill { height: 100%; width: 0; background: var(--ink); transition: width .15s; }
.zp-txt { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.zp-list { display: grid; gap: 8px; margin-top: 10px; max-height: 50vh; overflow-y: auto; }
.zp-part { justify-content: space-between; }
.zp-part span { color: var(--muted); font-size: 13px; }
.zp-part.done { border-color: var(--marker); }
.zp-part.done::before { content: "✓ "; color: var(--marker); }

/* --------------------------------------------------------------- admin */
.admin { padding: 36px var(--pad) 96px; max-width: 1100px; }
.admin h2 { font: 600 24px var(--cond); margin: 40px 0 16px; }
.admin-actions { display: flex; gap: 20px; align-items: center; margin: 20px 0 32px; }
.admin-list { display: grid; gap: 24px; }
.acard {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 24px;
  padding: 24px; background: var(--sheet); border-radius: 6px;
}
.ahead, .afoot, .field.wide { grid-column: 1 / -1; }
.ahead h2 { margin: 0 0 4px; font: 600 30px/1 var(--cond); }
.ahead .facts { margin: 0; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.field input, .field select { background: var(--table); }
.switch { display: grid; grid-template-columns: auto 1fr; column-gap: 10px; align-items: center; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--ink); margin: 0; }
.switch span { font-weight: 600; }
.switch small { grid-column: 2; color: var(--muted); font-size: 13px; }
.switch.tight { grid-template-columns: auto auto; justify-content: start; column-gap: 8px; }
.switch.tight span { font-weight: 400; color: var(--muted); font-size: 14px; }
.afoot { display: flex; align-items: center; gap: 16px; }
.saved { color: var(--muted); font-size: 14px; }
@media (max-width: 720px) { .acard { grid-template-columns: 1fr; padding: 18px; } }

/* cover picker */
.coverwrap { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.coverpick-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px;
  width: 100%; max-height: 240px; overflow-y: auto; padding: 8px;
  background: var(--table); border-radius: var(--radius); color: var(--muted); font-size: 13px;
}
.coverthumb { padding: 0; border: 2px solid transparent; border-radius: 2px; background: none; cursor: pointer; aspect-ratio: 1; overflow: hidden; }
.coverthumb img { width: 100%; height: 100%; object-fit: cover; }
.coverthumb.on { border-color: var(--marker); }

/* store usage */
.stores-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.stores-table th, .stores-table td { padding: 8px 12px; border-bottom: 1px solid var(--rule); text-align: left; }
.stores-table th { color: var(--muted); font-weight: 500; }
.usebar { height: 6px; width: 140px; background: var(--table); border-radius: 3px; overflow: hidden; margin-bottom: 4px; }
.usebar-fill { height: 100%; background: var(--ink); }
.stores-table span { color: var(--muted); font-size: 12px; }

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