/* ---------------------------------------------------------------
   King's Seeds media library — "the contact sheet on the light table"

   The vocabulary is the editing bench: contact sheets, chinagraph
   pencil select marks, film rebate edge markings. Photos read on a
   warm near-black (a darkroom, not a blue-black dashboard). The one
   accent is #E31E24 — King's Seeds' brand red, and the colour of a
   grease pencil. Everything else stays quiet so the mark carries.
   --------------------------------------------------------------- */

:root {
  --ink:    #141110;   /* darkroom base, warm-shifted */
  --panel:  #1C1917;   /* raised surfaces */
  --rule:   #2E2825;   /* hairlines between frames */
  --paper:  #ECE6DE;   /* photographic paper base — primary type */
  --muted:  #948A80;   /* captions, data */
  --mark:   #E31E24;   /* chinagraph red / brand red */

  --tile: 210px;       /* contact-sheet density, set by the toolbar */

  --sans: "Plus Jakarta Sans", system-ui, -apple-system, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

/* Must outrank the display rules below. A class selector like `.gate`
   beats the user agent's `[hidden] { display: none }`, which left the
   sign-in screen rendered after login with the gallery stacked beneath it. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--ink);
  color: var(--paper);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--paper); text-decoration-color: var(--rule); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--mark); }

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

/* ---------- sign-in ---------------------------------------------------- */

.gate {
  min-height: 100dvh;
  display: grid;
  place-content: center;
  padding: 32px;
  max-width: 460px;
  margin: 0 auto;
}
.gate .eyebrow {
  font: 500 11px/1 var(--mono);
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--mark);
  margin: 0 0 18px;
}
.gate h1 {
  font: 800 34px/1.05 var(--sans);
  letter-spacing: -.025em;
  margin: 0 0 10px;
}
.gate p.lede { color: var(--muted); margin: 0 0 22px; }
.gate .field { display: flex; gap: 8px; margin: 0 0 12px; }
.gate input { flex: 1 1 auto; min-width: 0; }
.gate .or {
  font: 500 11px/1 var(--mono);
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 18px 0;
}
.gate .foot { margin-top: 28px; font-size: 13px; color: var(--muted); }

/* ---------- controls --------------------------------------------------- */

button, input {
  font: inherit;
  color: var(--paper);
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 0;
  padding: 10px 14px;
}
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: default; }

button.primary {
  background: var(--mark);
  border-color: var(--mark);
  color: #fff;
  font-weight: 700;
}
button.primary:hover:not(:disabled) { filter: brightness(1.12); }

input::placeholder { color: var(--muted); }

/* ---------- masthead --------------------------------------------------- */

.masthead {
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--rule);
}
.masthead h1 {
  font: 800 19px/1 var(--sans);
  letter-spacing: -.02em;
  margin: 0;
}
.masthead .set {
  font: 500 11px/1 var(--mono);
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--mark);
}
.masthead .who { margin-left: auto; font-size: 13px; color: var(--muted); }
.masthead .who a { color: var(--muted); }

/* ---------- toolbar ---------------------------------------------------- */

.toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 22px;
  background: var(--ink);
  border-bottom: 1px solid var(--rule);
}
.toolbar .group { display: flex; }
.toolbar .group button {
  border-right-width: 0;
  padding: 8px 14px;
  font-size: 13px;
  white-space: nowrap;
}
.toolbar .group button:last-child { border-right-width: 1px; }
.toolbar .group button[aria-pressed="true"] {
  background: var(--panel);
  box-shadow: inset 0 -2px 0 var(--mark);
}
.toolbar .tally {
  font: 500 12px/1 var(--mono);
  color: var(--muted);
  letter-spacing: .04em;
}
.toolbar .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }

/* ---------- the sheet -------------------------------------------------- */

.sheet {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tile), 1fr));
  gap: 1px;
  background: var(--rule);   /* the 1px gaps become the sheet's rules */
  border-bottom: 1px solid var(--rule);
}

.frame {
  position: relative;
  background: var(--ink);
  overflow: hidden;
}
.frame img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  opacity: 0;
  transition: opacity .35s ease;
  background: var(--panel);
}
.frame img.in { opacity: 1; }
.frame:hover img.in { opacity: .84; }

/* film rebate: frame number along the bottom edge */
.frame .rebate {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 7px;
  font: 500 10px/1 var(--mono);
  letter-spacing: .1em;
  color: var(--paper);
  background: linear-gradient(transparent, rgba(0,0,0,.8));
  opacity: 0;
  transition: opacity .18s ease;
  pointer-events: none;
  z-index: 5;
}
.frame:hover .rebate,
.frame:focus-within .rebate { opacity: 1; }

/* editor's pick — a printed corner tick, distinct from your own mark */
.frame.pick::before {
  content: "";
  position: absolute;
  top: 0; right: 0;
  border: 11px solid transparent;
  border-top-color: var(--mark);
  border-right-color: var(--mark);
  z-index: 6;
}

/* open = view large; mark = select. Two targets, no ambiguity. */
.frame .open,
.frame .selector {
  position: absolute;
  border: 0;
  background: transparent;
  padding: 0;
  z-index: 4;
}
.frame .open { inset: 0; cursor: zoom-in; }
.frame .open:hover { border: 0; }

.frame .selector {
  left: 6px; top: 6px;
  width: 26px; height: 26px;
  border: 1px solid rgba(236,230,222,.55);
  background: rgba(20,17,16,.55);
  cursor: pointer;
  z-index: 7;
  opacity: 0;
  transition: opacity .15s ease;
}
.frame:hover .selector,
.frame:focus-within .selector,
.frame.marked .selector { opacity: 1; }
.frame.marked .selector { background: var(--mark); border-color: var(--mark); }

/* ---------- the signature: the chinagraph select mark ------------------ */

.frame .chinagraph {
  position: absolute;
  inset: 5%;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
}
.frame .chinagraph path {
  fill: none;
  stroke: var(--mark);
  stroke-width: 4.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 640;
  stroke-dashoffset: 640;
}
.frame.marked .chinagraph { opacity: 1; }
.frame.marked .chinagraph path { animation: draw .34s ease-out forwards; }
.frame.marked img.in { opacity: 1; }
.frame.marked { box-shadow: inset 0 0 0 2px var(--mark); }

@keyframes draw { to { stroke-dashoffset: 0; } }

@media (prefers-reduced-motion: reduce) {
  .frame img { transition: none; }
  .frame .chinagraph path { animation: none; stroke-dashoffset: 0; }
}

/* ---------- lightbox --------------------------------------------------- */

dialog {
  border: 1px solid var(--rule);
  border-radius: 0;
  padding: 0;
  background: var(--panel);
  color: var(--paper);
  max-width: 96vw;
  max-height: 96vh;
}
dialog::backdrop { background: rgba(10, 8, 8, .9); }
dialog img { display: block; max-width: 92vw; max-height: 76vh; }
dialog .bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px;
  border-top: 1px solid var(--rule);
}
dialog .bar .id {
  font: 500 11px/1 var(--mono);
  letter-spacing: .08em;
  color: var(--muted);
}
dialog .bar .spacer { margin-left: auto; }

/* ---------- utility ---------------------------------------------------- */

.msg { font-size: 13px; color: var(--muted); }
.msg.error { color: var(--mark); }
.empty { padding: 60px 22px; color: var(--muted); }

@media (max-width: 640px) {
  :root { --tile: 148px; }
  .masthead .who { margin-left: 0; width: 100%; }
  .toolbar { padding: 10px 14px; }
  .toolbar .right { margin-left: 0; width: 100%; }
}
