:root {
  --bg: #f5f0e6;
  --surface: #fffdf8;
  --ink: #221d17;
  --muted: #6d6456;
  --line: #ddd3c2;
  --accent: #8b2e1f;
  --accent-ink: #fff;
  --chip: #ece4d4;
  --shadow: 0 1px 2px rgb(40 30 20 / 0.08), 0 4px 16px rgb(40 30 20 / 0.06);
  --serif: "Libre Caslon Text", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15120e; --surface: #1f1b16; --ink: #ece4d4; --muted: #a39884;
    --line: #3a332a; --accent: #e0826d; --accent-ink: #1a0f0b; --chip: #2d2720;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15120e; --surface: #1f1b16; --ink: #ece4d4; --muted: #a39884;
  --line: #3a332a; --accent: #e0826d; --accent-ink: #1a0f0b; --chip: #2d2720;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4); color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--sans); }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--serif); font-weight: 400; margin: 0; }

input[type="text"], input[type="search"], input[type="number"], input[type="date"], select, textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 10px; width: 100%; min-width: 0;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 6px;
  padding: 7px 14px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: default; }

.chip {
  display: inline-flex; align-items: center; gap: 4px; border: 1px solid transparent;
  background: var(--chip); border-radius: 999px; padding: 3px 11px; font-size: 13px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- public ---------- */
.site-head { padding: 40px 16px 20px; max-width: 1400px; margin: 0 auto; }
.site-head h1 { font-size: clamp(28px, 4vw, 44px); line-height: 1.1; }
.site-head p { margin: 8px 0 0; max-width: 60ch; }

.filters {
  position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(6px); border-bottom: 1px solid var(--line);
}
.filters-inner {
  max-width: 1400px; margin: 0 auto; padding: 12px 16px; display: grid; gap: 10px;
  grid-template-columns: minmax(140px, 1.2fr) repeat(4, minmax(0, 1fr)) 300px auto;
  align-items: center;
}
.years { display: flex; gap: 6px; align-items: center; }
.years input { padding-inline: 8px; }
@media (min-width: 801px) and (max-width: 1150px) {
  .filters-inner { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .filters-inner > :first-child { grid-column: 1 / -1; }
  .years { grid-column: span 3; }
}
.tag-row { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }
@media (max-width: 800px) {
  .filters { position: static; }
  .filters-inner { grid-template-columns: 1fr 1fr; }
  .filters-inner > :first-child, .years { grid-column: 1 / -1; }
}

.count { max-width: 1400px; margin: 0 auto; padding: 14px 16px 0; }
.grid { max-width: 1400px; margin: 0 auto; padding: 12px 16px 60px; columns: 5 160px; column-gap: 14px; }
.card {
  break-inside: avoid; margin: 0 0 14px; background: var(--surface); border-radius: 6px;
  box-shadow: var(--shadow); overflow: hidden; cursor: pointer; display: block; width: 100%;
  border: 0; padding: 0; text-align: left;
}
.card img { display: block; width: 100%; height: auto; max-height: 520px; object-fit: cover; object-position: top; background: var(--chip); }
.card .cap { padding: 8px 10px 10px; font-size: 13px; }
.card .cap b { font-weight: 600; display: block; }
.empty { text-align: center; padding: 80px 16px; }

.viewer {
  position: fixed; inset: 0; z-index: 20; background: var(--bg); display: none;
  grid-template-columns: minmax(0, 1fr) 360px;
}
.viewer.open { display: grid; }
.viewer .stage { overflow: auto; padding: 20px; display: flex; justify-content: center; align-items: flex-start; }
/* Fit the whole ad in the window; click to zoom to full size and scroll. */
.viewer .stage img { display: block; width: auto; height: auto; max-width: 100%; max-height: 100%; cursor: zoom-in; box-shadow: var(--shadow); background: #fff; }
.viewer .stage.zoom { display: block; }
.viewer .stage.zoom img { max-width: none; max-height: none; margin: 0 auto; cursor: zoom-out; }
.viewer aside { border-left: 1px solid var(--line); background: var(--surface); padding: 20px; overflow: auto; }
.viewer .nav { display: flex; gap: 8px; margin-bottom: 18px; }
.viewer .nav .btn:last-child { margin-left: auto; }
dl.meta { display: grid; grid-template-columns: 100px 1fr; gap: 8px 12px; margin: 16px 0; }
dl.meta dt { color: var(--muted); font-size: 13px; }
dl.meta dd { margin: 0; }
@media (max-width: 800px) {
  .viewer { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .viewer .stage { padding: 10px; }
  .viewer aside { border-left: 0; border-top: 1px solid var(--line); max-height: 45vh; }
}

/* ---------- admin ---------- */
.admin { display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100vh; }
.admin-bar {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 10px 16px;
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.admin-bar h1 { font-size: 20px; margin-right: 8px; }
.admin-bar .grow { flex: 1; }
.progress { width: 160px; height: 6px; background: var(--chip); border-radius: 3px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); }
.admin-main { display: grid; grid-template-columns: 300px minmax(0, 1fr) 380px; min-height: 0; }
.list { overflow: auto; border-right: 1px solid var(--line); }
.list-filters { padding: 10px; display: grid; gap: 8px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 1; }
.row {
  display: grid; grid-template-columns: 48px 1fr; gap: 10px; padding: 8px 10px; width: 100%;
  border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; cursor: pointer;
}
.row img { width: 48px; height: 64px; object-fit: cover; object-position: top; border-radius: 3px; background: var(--chip); }
.row[aria-current="true"] { background: var(--chip); box-shadow: inset 3px 0 var(--accent); }
.row .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--line); margin-right: 5px; }
.row .dot.done { background: #3f8f5a; }
.row .dot.hidden { background: var(--muted); }
/* Fit the whole ad in view (width and height); click to zoom to full size and scroll. */
.editor-stage { overflow: auto; padding: 16px; background: var(--bg); display: flex; justify-content: center; align-items: flex-start; }
.editor-stage img { display: block; width: auto; height: auto; max-width: 100%; max-height: 100%; cursor: zoom-in; background: #fff; box-shadow: var(--shadow); }
.editor-stage.zoom { display: block; }
.editor-stage.zoom img { max-width: none; max-height: none; margin: 0 auto; cursor: zoom-out; }
.form { overflow: auto; padding: 16px; border-left: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; gap: 14px; }
.form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.form label > * { color: var(--ink); font-size: 15px; }
.form .fixed { font-size: 15px; color: var(--ink); }
.form .tags { display: flex; flex-wrap: wrap; gap: 6px; }
.form .actions { display: flex; gap: 8px; position: sticky; bottom: -16px; background: var(--surface); padding: 12px 0 16px; margin-top: auto; }
.status { font-size: 13px; min-height: 1.5em; }
.status.err { color: #c0392b; }
.tag-manage { display: flex; gap: 6px; }
.chip .x { border: 0; background: none; padding: 0 0 0 2px; cursor: pointer; color: inherit; opacity: 0.6; }
.chip .x:hover { opacity: 1; }
@media (max-width: 1100px) {
  .admin { height: auto; }
  .admin-main { grid-template-columns: 1fr; }
  .list { max-height: 40vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .form { border-left: 0; }
  .editor-stage img { max-height: 80vh; }
}

/* suggestion dropdowns (admin) */
.combo { position: relative; }
.combo-list {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 10; margin: 2px 0 0; padding: 4px 0;
  list-style: none; max-height: 240px; overflow: auto; background: var(--surface);
  border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow);
}
.combo-list li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 10px; cursor: pointer; color: var(--ink); font-size: 15px; }
.combo-list li:hover, .combo-list li[aria-selected="true"] { background: var(--chip); }
.btn.danger { color: #b3261e; border-color: color-mix(in srgb, #b3261e 40%, var(--line)); align-self: flex-start; }
.btn.danger:hover { background: #b3261e; color: #fff; border-color: #b3261e; }

/* multi-select filter dropdowns (public) */
.ms { position: relative; min-width: 0; }
.ms-btn {
  width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 28px 7px 10px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: relative;
}
.ms-btn::after { content: "▾"; position: absolute; right: 10px; color: var(--muted); }
.ms-btn.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.ms-pop {
  position: absolute; z-index: 15; top: calc(100% + 4px); left: 0; min-width: 100%; width: max-content; max-width: min(360px, 90vw);
  max-height: 320px; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); padding: 6px;
}
.ms-opt { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 4px; cursor: pointer; }
.ms-opt:hover { background: var(--chip); }
.ms-opt input { accent-color: var(--accent); margin: 0; }
.ms-clear { display: block; margin: 4px 0 2px auto; border: 0; background: none; color: var(--accent); cursor: pointer; padding: 4px 8px; }
@media (max-width: 800px) {
  .ms-pop { max-width: calc(100vw - 32px); }
  .ms:nth-of-type(even) .ms-pop { left: auto; right: 0; }
}
dl.meta .meta-link { color: inherit; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; }
dl.meta .meta-link:hover { color: var(--accent); text-decoration-color: currentColor; }
.ms-opt.zero { opacity: 0.45; }
.home-link { color: inherit; text-decoration: none; }
.home-link:hover { color: var(--accent); }
