:root {
  --paper: #EDF1F5;
  --surface: #F9FBFC;
  --raised: #FFFFFF;
  --ink: #15202B;
  --muted: #5A6774;
  --line: #CDD5DD;
  --mark: #F5A300;
  --danger: #C2362B;
  --ok: #1D7A4E;
  --checker: #DCE3EA;
  --shadow: 0 1px 2px rgba(21, 32, 43, .06), 0 8px 24px -12px rgba(21, 32, 43, .18);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #10161C;
    --surface: #161E26;
    --raised: #1B242E;
    --ink: #E4EAF0;
    --muted: #8C99A6;
    --line: #2A3540;
    --mark: #FFB81F;
    --danger: #FF6B5E;
    --ok: #4CC38A;
    --checker: #222C36;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px -14px rgba(0, 0, 0, .7);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  min-height: 100vh; display: flex; flex-direction: column;
  background: var(--paper); color: var(--ink);
  font: 16px/1.5 "Schibsted Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
main { flex: 1; width: 100%; max-width: 1320px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 40px) 64px; }
a { color: inherit; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Header & footer */
.top {
  width: 100%; max-width: 1320px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px clamp(16px, 4vw, 40px);
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -0.02em; text-decoration: none; font-size: 1.05rem; }
.brand .mark { width: 22px; height: 22px; color: var(--mark); }
.brand:focus-visible { outline: 3px solid var(--mark); outline-offset: 4px; border-radius: 2px; }
.top-nav { display: flex; align-items: center; gap: 8px; }
.top-nav form { margin: 0; }
.foot { max-width: 1320px; width: 100%; margin: 0 auto; padding: 0 clamp(16px, 4vw, 40px) 28px; color: var(--muted); font-size: .85rem; }
.foot p { margin: 0; padding-top: 18px; border-top: 1px solid var(--line); }

/* Buttons & fields */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: .92rem; line-height: 1.2; white-space: nowrap;
  padding: .66em 1.05em; border-radius: 7px; cursor: pointer; text-decoration: none;
  border: 1.5px solid var(--line); background: var(--raised); color: var(--ink);
  transition: background-color .12s, border-color .12s;
}
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.btn.primary:hover { background: color-mix(in srgb, var(--ink) 86%, var(--paper)); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.btn.danger:hover { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, var(--raised)); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { border-color: var(--line); }
.btn.sm { font-size: .8rem; padding: .42em .72em; border-width: 1px; border-radius: 6px; }
.btn.lg { font-size: 1rem; padding: .8em 1.3em; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible, .field:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--mark); outline-offset: 2px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.field {
  font: inherit; font-size: .95rem; color: var(--ink);
  padding: .62em .85em; border: 1.5px solid var(--line); border-radius: 7px; background: var(--raised); min-width: 0;
}
.field.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8rem; }
.lbl { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 6px; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: .92rem; }
.facts { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
kbd {
  font: inherit; font-size: .8rem; font-weight: 600;
  padding: .1em .45em; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; background: var(--raised);
}

/* Drop zone = selection marquee */
.zone {
  position: relative;
  min-height: min(62vh, 560px);
  display: grid; place-items: center;
  padding: 64px 24px 76px; text-align: center;
  background:
    linear-gradient(90deg, var(--mark) 50%, transparent 0) 0 0 / 16px 2px repeat-x,
    linear-gradient(90deg, var(--mark) 50%, transparent 0) 0 100% / 16px 2px repeat-x,
    linear-gradient(0deg, var(--mark) 50%, transparent 0) 0 0 / 2px 16px repeat-y,
    linear-gradient(0deg, var(--mark) 50%, transparent 0) 100% 0 / 2px 16px repeat-y,
    var(--surface);
}
.zone.drag { animation: ants .6s linear infinite; background-color: color-mix(in srgb, var(--mark) 10%, var(--surface)); }
.zone.busy { cursor: progress; }
.zone.busy .zone-body { opacity: .4; pointer-events: none; }
@keyframes ants { to { background-position: 16px 0, -16px 100%, 0 -16px, 100% 16px, 0 0; } }
.hd { position: absolute; width: 12px; height: 12px; background: var(--surface); border: 2px solid var(--mark); z-index: 1; }
.hd.tl { top: -5px; left: -5px; } .hd.tr { top: -5px; right: -5px; }
.hd.bl { bottom: -5px; left: -5px; } .hd.br { bottom: -5px; right: -5px; }
.zone h1 {
  margin: 0 auto .35em; max-width: 12ch;
  font-size: clamp(2.4rem, 7vw, 5.2rem); font-weight: 800; line-height: 1; letter-spacing: -0.04em;
}
.lede { margin: 0 auto 30px; color: var(--muted); font-size: clamp(1rem, 1.6vw, 1.15rem); max-width: 42ch; }
.zone .actions { justify-content: center; }
.keys { margin: 22px 0 0; color: var(--muted); font-size: .9rem; }
.readout {
  position: absolute; right: 14px; bottom: 14px;
  font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums;
  background: var(--paper); padding: 4px 9px; border-radius: 4px; max-width: calc(100% - 28px); text-align: right;
}
.readout.err { color: var(--danger); font-weight: 600; }
.readout.ok { color: var(--ok); font-weight: 600; }
.progress { position: absolute; left: 2px; right: 2px; bottom: 2px; height: 4px; background: color-mix(in srgb, var(--mark) 18%, transparent); }
.progress span { display: block; height: 100%; width: 0; background: var(--mark); transition: width .15s linear; }

/* History & grids */
.history-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 56px 0 18px; }
.history h2, .admin h1 { font-size: 1.25rem; letter-spacing: -0.015em; margin: 0; }
.empty { color: var(--muted); max-width: 60ch; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.shot { position: relative; margin: 0; background: var(--raised); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.shot > a { display: block; }
.shot > a:focus-visible { outline: 3px solid var(--mark); outline-offset: -3px; }
.shot img {
  display: block; width: 100%; aspect-ratio: 16 / 10; object-fit: cover; object-position: top center;
  background: repeating-conic-gradient(var(--checker) 0 25%, transparent 0 50%) 0 0 / 14px 14px;
}
.shot figcaption { display: grid; gap: 6px; padding: 9px 10px 10px; border-top: 1px solid var(--line); }
.shot .row { display: flex; align-items: center; justify-content: space-between; gap: 6px 8px; min-width: 0; flex-wrap: wrap; }
.shot .row.facts { font-size: .76rem; }
.shot .row > .facts { white-space: nowrap; }
.shot .row.nowrap { flex-wrap: nowrap; }
.shot .row.nowrap .sid { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shot .row.nowrap .actions { flex: none; gap: 4px; }
.shot .row.nowrap .btn.sm { padding: .36em .6em; font-size: .76rem; }
.shot .actions { gap: 4px; flex-wrap: nowrap; }
.sid { font-weight: 700; font-size: .85rem; text-decoration: none; font-variant-numeric: tabular-nums; }
.sid:hover { text-decoration: underline; }
.tag { font-size: .75rem; color: var(--muted); text-decoration: none; padding: 2px 6px; border: 1px solid var(--line); border-radius: 4px; }
.tag:hover { color: var(--ink); border-color: var(--ink); }

/* View page */
.view { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.frame {
  display: grid; place-items: center; overflow: auto; min-height: 240px;
  padding: clamp(10px, 2vw, 28px);
  border: 1px solid var(--line); border-radius: 8px;
  background: repeating-conic-gradient(var(--checker) 0 25%, var(--surface) 0 50%) 0 0 / 18px 18px;
}
.frame img { display: block; width: auto; height: auto; max-width: 100%; max-height: 80vh; object-fit: contain; cursor: zoom-in; box-shadow: var(--shadow); }
.frame img.zoom { max-width: none; max-height: none; cursor: zoom-out; }
.frame.small img { max-height: 40vh; cursor: default; }
.panel {
  position: sticky; top: 16px; display: grid; gap: 18px;
  background: var(--raised); border: 1px solid var(--line); border-radius: 8px; padding: 18px; box-shadow: var(--shadow);
}
.linkrow { display: flex; gap: 8px; min-width: 0; }
.linkrow input, .linkrow .field { flex: 1; min-width: 0; }
.linkrow input:not(.field) {
  font: inherit; font-size: .9rem; padding: .62em .8em; color: var(--ink);
  border: 1.5px solid var(--line); border-radius: 7px; background: var(--surface);
}
.stack { display: grid; gap: 8px; }
.details { margin: 0; display: grid; gap: 10px; padding-top: 16px; border-top: 1px solid var(--line); }
.details div { display: flex; justify-content: space-between; gap: 12px; font-size: .88rem; }
.details dt { color: var(--muted); }
.details dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }

/* Notices & login */
.notice { max-width: 640px; padding-top: 8vh; }
.notice h1 { font-size: clamp(2rem, 5vw, 3.2rem); letter-spacing: -0.035em; line-height: 1.05; margin: 0 0 .4em; }
.notice p { color: var(--muted); }
.notice .frame { margin: 24px 0; }
.login { display: grid; place-items: center; padding-top: 10vh; }
.login-card {
  width: min(400px, 100%); display: grid; gap: 4px;
  background: var(--raised); border: 1px solid var(--line); border-radius: 10px; padding: 28px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 0; font-size: 1.5rem; letter-spacing: -0.02em; }
.login-card .sub { margin-bottom: 18px; }
.login-card .field { width: 100%; margin-bottom: 14px; }
.form-error { margin: -6px 0 12px; color: var(--danger); font-size: .88rem; font-weight: 600; }

/* Admin */
.admin-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin: 12px 0 22px; }
.admin h1 { font-size: clamp(1.6rem, 3vw, 2.2rem); letter-spacing: -0.03em; }
.stats { margin: 0; display: flex; gap: clamp(16px, 3vw, 40px); flex-wrap: wrap; }
.stats div { display: grid; gap: 2px; }
.stats dt { color: var(--muted); font-size: .8rem; }
.stats dd { margin: 0; font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.filters input[type=search] { flex: 1 1 280px; }
.bulkbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 0; margin-bottom: 10px; background: var(--paper); border-bottom: 1px solid var(--line);
}
.bulkbar #bulk-delete { margin-left: auto; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: .88rem; cursor: pointer; }
.check input, .pick input { width: 16px; height: 16px; accent-color: var(--mark); }
.pick {
  position: absolute; top: 8px; left: 8px; z-index: 2;
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: 6px;
  background: color-mix(in srgb, var(--raised) 90%, transparent); border: 1px solid var(--line); cursor: pointer;
}
.shot:has(.pick input:checked) { border-color: var(--mark); box-shadow: 0 0 0 2px var(--mark); }
.flash { padding: 10px 14px; border-radius: 7px; background: color-mix(in srgb, var(--ok) 14%, var(--raised)); color: var(--ok); font-weight: 600; font-size: .92rem; }
.hint { display: grid; gap: 12px; padding: 16px; margin-bottom: 18px; border-radius: 8px; border: 1px solid var(--mark); background: color-mix(in srgb, var(--mark) 9%, var(--raised)); font-size: .92rem; }
.hint p, .hint form { margin: 0; }
.pager { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; margin-top: 26px; }
.pager > :last-child { justify-self: end; }

/* Capture overlay */
.cap {
  position: fixed; inset: 0; z-index: 50; background: #000;
  display: grid; place-items: center; cursor: crosshair; touch-action: none; user-select: none;
}
.cap-stage { position: relative; line-height: 0; }
.cap-stage canvas { display: block; }
.cap-stage.dim::after { content: ""; position: absolute; inset: 0; background: rgba(0, 0, 0, .45); }
.sel { position: absolute; outline: 2px dashed #FFB81F; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45); pointer-events: none; }
.sel-size {
  position: absolute; right: 0; bottom: -26px;
  font: 600 12px/1.3 "Schibsted Grotesk", system-ui, sans-serif; font-variant-numeric: tabular-nums;
  color: #1A1200; background: #FFB81F; padding: 3px 6px; border-radius: 3px; white-space: nowrap;
}
.cap-hint {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 51;
  color: #fff; background: rgba(0, 0, 0, .75); padding: 7px 12px; border-radius: 5px;
  font-size: .85rem; line-height: 1.4; pointer-events: none; white-space: nowrap;
}

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 60;
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 7px; font-weight: 600; font-size: .92rem;
  box-shadow: var(--shadow); transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  .zone.drag { animation: none; }
  .toast, .progress span, .btn { transition: none; }
}
@media (max-width: 900px) {
  .view { grid-template-columns: 1fr; }
  .panel { position: static; }
}
@media (max-width: 560px) {
  .zone { min-height: 68vh; padding-top: 48px; }
  .cap-hint { white-space: normal; width: calc(100% - 28px); text-align: center; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .shot .row:last-child { flex-wrap: wrap; }
}
