:root {
  --ground: #0f0e0c;
  --ground-2: #171512;
  --ground-3: #221f1a;
  --line: #2e2a23;
  --ink: #efe8dc;
  --ink-2: #a79e8f;
  --ink-3: #6f675b;
  --safelight: #ffb547;
  --safelight-dim: #ffb54726;
  --danger: #ff6b57;
  --display: "Instrument Serif", "Iowan Old Style", Georgia, serif;
  --body: "Schibsted Grotesk", "Helvetica Neue", sans-serif;
  --mono: "Martian Mono", ui-monospace, monospace;
  --gap: 6px;
  --radius: 3px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

html { background: var(--ground); color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  font: 15px/1.45 var(--body);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 85% -200px, #ffb54712, transparent 70%),
    radial-gradient(900px 400px at -10% -100px, #ff6b570c, transparent 70%),
    var(--ground);
}

/* A faint film grain keeps the black from reading as a flat void. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--safelight); outline-offset: 2px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%);
}

/* ---- top bar ---------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 28px;
  align-items: center;
  padding: 14px 22px;
  background: color-mix(in srgb, var(--ground) 86%, transparent);
  backdrop-filter: blur(14px) saturate(1.3);
  border-bottom: 1px solid var(--line);
}

.wordmark {
  font: italic 34px/1 var(--display);
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
}
.wordmark span { color: var(--safelight); }

.search {
  position: relative;
  display: flex;
  align-items: center;
  max-width: 720px;
  width: 100%;
  justify-self: center;
  background: var(--ground-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search:focus-within { border-color: #5a4a30; box-shadow: 0 0 0 4px var(--safelight-dim); }
.search-icon {
  width: 18px; height: 18px; margin-left: 16px; flex: none;
  fill: none; stroke: var(--ink-3); stroke-width: 2; stroke-linecap: round;
}
.search input {
  flex: 1;
  min-width: 0;
  padding: 11px 12px;
  background: none;
  border: 0;
  outline: none;
}
.search input::placeholder { color: var(--ink-3); }
.upload {
  display: grid; place-items: center;
  width: 38px; height: 38px; margin-right: 3px;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.2s;
}
.upload:hover { background: var(--ground-3); }
.upload[hidden], .ghost[hidden] { display: none; }
.upload svg { width: 19px; height: 19px; fill: none; stroke: var(--ink-2); stroke-width: 1.7; }

.collections { display: flex; gap: 2px; padding: 3px; background: var(--ground-2); border: 1px solid var(--line); border-radius: 999px; }
.collections button {
  padding: 6px 14px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--ink-2);
  font-size: 13.5px;
  white-space: nowrap;
}
.collections button[aria-pressed="true"] { background: var(--ink); color: var(--ground); }
.collections .count { font: 300 10.5px var(--mono); opacity: 0.6; margin-left: 5px; }

/* ---- lens bar --------------------------------------------------------- */

.lensbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 22px;
  align-items: center;
  padding: 14px 22px 12px;
}

.lens-chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--ground-2);
  color: var(--ink-2);
  font-size: 13.5px;
  transition: border-color 0.2s, color 0.2s, background 0.2s, transform 0.2s var(--ease-out);
}
.chip:hover { color: var(--ink); border-color: #4a4336; }
.chip:active { transform: scale(0.97); }
.chip .ring {
  width: 14px; height: 14px; border-radius: 50%;
  border: 1.5px solid currentColor;
  position: relative;
  transition: border-color 0.2s;
}
.chip .ring::after {
  content: ""; position: absolute; inset: 3px; border-radius: 50%;
  background: currentColor; transform: scale(0); transition: transform 0.25s var(--ease-out);
}
.chip[aria-checked="true"] { color: var(--ink); border-color: var(--safelight); background: var(--safelight-dim); }
.chip[aria-checked="true"] .ring { border-color: var(--safelight); }
.chip[aria-checked="true"] .ring::after { background: var(--safelight); transform: scale(1); }
.chip.custom { border-style: dashed; }

.optics {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
  animation: rise 0.35s var(--ease-out);
}
.optics[hidden] { display: none; }

.k-control { display: flex; align-items: center; gap: 12px; font: 400 12px var(--mono); color: var(--ink-2); }
.k-label output { color: var(--safelight); display: inline-block; min-width: 2.2ch; }
.k-control input[type="range"] { width: 150px; accent-color: var(--safelight); }
.variance { display: inline-flex; align-items: center; gap: 8px; }
.variance-bar { width: 64px; height: 4px; border-radius: 2px; background: var(--ground-3); overflow: hidden; }
.variance-bar span { display: block; height: 100%; background: linear-gradient(90deg, #a86b1c, var(--safelight)); transition: width 0.25s var(--ease-out); }
#variance-text { min-width: 9ch; }

.methods, .views { display: flex; border: 1px solid var(--line); border-radius: 999px; padding: 2px; }
.methods button, .views button {
  padding: 5px 12px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--ink-3);
  font: 400 11px var(--mono);
  white-space: nowrap;
}
.methods button[aria-pressed="true"], .views button[aria-pressed="true"] { background: var(--ground-3); color: var(--ink); }

.ghost {
  padding: 6px 12px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: none;
  color: var(--ink-2);
  font-size: 13px;
  text-decoration: underline;
  text-decoration-color: var(--ink-3);
  text-underline-offset: 3px;
}
.ghost:hover { color: var(--ink); text-decoration-color: var(--safelight); }

/* ---- query panel ------------------------------------------------------ */

.query-panel {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  margin: 0 22px 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: linear-gradient(100deg, var(--ground-2), transparent 80%);
  animation: rise 0.4s var(--ease-out);
}
.query-panel[hidden] { display: none; }
.query-subject img {
  display: block;
  height: 96px;
  max-width: 180px;
  object-fit: cover;
  border-radius: var(--radius);
  outline: 2px solid var(--safelight);
  outline-offset: 3px;
}
.query-subject .text-query {
  font: italic 40px/1 var(--display);
  padding: 0 8px;
  max-width: 50vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.query-subject .text-query::before { content: "“"; color: var(--safelight); }
.query-subject .text-query::after { content: "”"; color: var(--safelight); }
.eyebrow { margin: 0 0 6px; font: 400 10.5px var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }
.reading { margin: 0; display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--ink-2); font-size: 14px; }
.reading b { color: var(--ink); font-weight: 500; }
.reading .p { font: 300 11px var(--mono); color: var(--safelight); margin-left: 4px; }
.reading .hint { color: var(--ink-3); }

/* ---- grid ------------------------------------------------------------- */

main { padding: 0 var(--gap) 80px; }

.grid { display: flex; gap: var(--gap); align-items: flex-start; }
.column { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--gap); }

.tile {
  position: relative;
  margin: 0;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--ground-3);
  cursor: zoom-in;
  animation: develop 0.6s var(--ease-out) both;
}
.tile img { display: block; width: 100%; height: auto; transition: transform 0.5s var(--ease-out), filter 0.3s; }
.tile:hover img { transform: scale(1.025); }
.tile figcaption {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 8px;
  padding: 28px 9px 8px;
  background: linear-gradient(transparent, #000c);
  font: 400 10.5px var(--mono);
  color: var(--ink);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.2s, transform 0.25s var(--ease-out);
  pointer-events: none;
}
.tile:hover figcaption, .tile:focus-visible figcaption { opacity: 1; transform: none; }
.tile .label { font: 500 12px var(--body); color: var(--safelight); text-align: right; }
.tile .open {
  position: absolute;
  top: 7px; right: 7px;
  width: 30px; height: 30px;
  border: 0;
  border-radius: 50%;
  background: #000a;
  color: var(--ink);
  font-size: 15px;
  opacity: 0;
  transition: opacity 0.2s;
}
.tile:hover .open, .tile .open:focus-visible { opacity: 1; }

/* Tiles "develop" in like a print in the tray. */
@keyframes develop {
  from { opacity: 0; filter: brightness(1.8) sepia(0.6); transform: translateY(8px); }
  to { opacity: 1; filter: none; transform: none; }
}
@keyframes rise { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.sentinel { height: 1px; }
.status { text-align: center; color: var(--ink-3); font: 400 12px var(--mono); min-height: 2em; }

/* ---- compare view ----------------------------------------------------- */

.compare { display: flex; flex-direction: column; gap: 26px; padding: 4px 16px 0; }
.compare[hidden] { display: none; }
.compare-row h3 { margin: 0 0 8px; display: flex; align-items: baseline; gap: 12px; font: italic 26px/1 var(--display); font-weight: 400; }
.compare-row h3 small { font: 400 10.5px var(--mono); color: var(--ink-3); font-style: normal; }
.compare-row h3 .top { font: 500 13px var(--body); color: var(--safelight); font-style: normal; }
.compare-strip { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(150px, 1fr); gap: var(--gap); overflow-x: auto; padding-bottom: 6px; }
.compare-strip .tile { aspect-ratio: 4 / 5; }
.compare-strip .tile img { height: 100%; object-fit: cover; object-position: top; }

/* ---- dialogs ---------------------------------------------------------- */

dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ground-2);
  color: var(--ink);
  padding: 0;
  max-width: min(1100px, 94vw);
  max-height: 92vh;
}
dialog::backdrop { background: #000b; backdrop-filter: blur(6px); }
dialog[open] { animation: pop 0.3s var(--ease-out); }
@keyframes pop { from { opacity: 0; transform: scale(0.97); } }

.close {
  position: absolute; top: 8px; right: 10px; z-index: 2;
  width: 34px; height: 34px; border: 0; border-radius: 50%;
  background: var(--ground-3); font-size: 20px; line-height: 1;
}
.detail-body { display: grid; grid-template-columns: minmax(0, 1fr) 280px; max-height: 92vh; }
.detail-image { overflow: auto; background: #000; display: grid; place-items: start center; }
.detail-image img { max-width: 100%; display: block; }
.detail-side { padding: 48px 22px 22px; display: flex; flex-direction: column; gap: 8px; overflow: auto; }
.detail-actions { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.detail-actions button {
  text-align: left; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--ground);
  transition: border-color 0.2s, background 0.2s;
}
.detail-actions button:hover { border-color: var(--safelight); background: var(--safelight-dim); }
.detail-actions button small { display: block; color: var(--ink-3); font-size: 12px; }
.detail-title { color: var(--ink-2); font-size: 13px; margin: 0; overflow-wrap: anywhere; }
.detail-source { color: var(--safelight); font: 400 11px var(--mono); }

.editor { width: min(720px, 94vw); }
.editor form { padding: 26px; display: flex; flex-direction: column; gap: 14px; }
.editor h2 { font: italic 36px/1 var(--display); font-weight: 400; margin: 0 0 8px; }
.editor header p { color: var(--ink-2); margin: 0; }
.editor code { color: var(--safelight); font: 400 12px var(--mono); }
.group { border: 1px solid var(--line); border-radius: 6px; padding: 14px; margin: 0 0 10px; display: grid; gap: 10px; }
.group label { display: grid; gap: 6px; font: 400 10.5px var(--mono); letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-3); }
.group input, .group textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 4px;
  background: var(--ground); font: 400 14px var(--body); text-transform: none; letter-spacing: 0; resize: vertical;
}
.group .remove-group { justify-self: end; }
.editor-error { color: var(--danger); margin: 0; min-height: 1.2em; font-size: 13px; }
.editor footer { display: flex; justify-content: flex-end; gap: 10px; }
.primary {
  padding: 10px 18px; border: 0; border-radius: 999px;
  background: var(--safelight); color: #1a1206; font-weight: 600;
}
.primary:disabled { opacity: 0.6; cursor: progress; }

.drop-veil {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: #0f0e0cdd; border: 3px dashed var(--safelight);
  font: italic 44px var(--display); color: var(--safelight);
}
.drop-veil[hidden] { display: none; }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 60;
  max-width: 80vw; padding: 10px 16px; border-radius: 6px;
  background: var(--ground-3); border: 1px solid var(--danger); color: var(--ink);
  animation: rise 0.3s var(--ease-out);
}
.toast[hidden] { display: none; }

@media (max-width: 820px) {
  .topbar { grid-template-columns: 1fr auto; gap: 12px; }
  .search { grid-column: 1 / -1; grid-row: 2; }
  .query-panel { grid-template-columns: auto 1fr; }
  .views { grid-column: 1 / -1; justify-self: start; }
  .detail-body { grid-template-columns: 1fr; }
}

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