:root {
  --bg: #faf6f0; --card: #fff; --ink: #221d1a; --muted: #6f655d; --line: #e7dfd4;
  --accent: #d9482b; --accent-ink: #fff; --accent-soft: #fbe6df; --ok: #1f7a4d; --ok-soft: #dff3e8;
  --hold: #8a5a00; --hold-soft: #fdefc8; --shadow: 0 1px 2px rgb(40 25 10 / .06), 0 8px 24px rgb(40 25 10 / .06);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171412; --card: #221e1b; --ink: #f3ece4; --muted: #a89d92; --line: #36302b;
    --accent: #ff7a5c; --accent-ink: #1b0d08; --accent-soft: #43201a; --ok: #6fd6a0; --ok-soft: #173326;
    --hold: #f1c765; --hold-soft: #3b2f10; --shadow: 0 1px 2px rgb(0 0 0 / .4);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 8rem; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.top { display: flex; align-items: center; gap: 1rem; padding: 1rem clamp(1rem, 4vw, 2.5rem) .25rem; max-width: 1500px; margin: auto; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 800; font-size: 1.35rem; letter-spacing: -.02em; text-decoration: none; }
.brand svg { color: var(--accent); }
.tagline { margin: 0; color: var(--muted); font-size: .95rem; flex: 1; }
.top-actions { display: flex; gap: .5rem; margin-left: auto; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: .4rem .85rem; white-space: nowrap; }
.ghost:hover { border-color: var(--muted); }
.ghost[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.pill { display: inline-block; min-width: 1.4em; padding: 0 .4em; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: .75rem; font-weight: 700; text-align: center; }
.pill:empty { display: none; }

.controls { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); padding: .75rem clamp(1rem, 4vw, 2.5rem); }
.controls > * { max-width: calc(1500px - 5rem); margin-inline: auto; }
.row { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.seg { display: inline-flex; max-width: 100%; overflow-x: auto; scrollbar-width: none; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg button { flex: none; white-space: nowrap; border: 0; background: transparent; border-radius: 999px; padding: .45rem 1.1rem; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.seg.small button { padding: .25rem .8rem; font-size: .875rem; }
.search { flex: 1; min-width: 180px; display: flex; align-items: center; gap: .5rem; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 0 1rem; color: var(--muted); }
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; border: 0; background: transparent; padding: .6rem 0; outline: 0; color: var(--ink); min-width: 0; }
.filters-btn { display: none; }
.near-btn { display: inline-flex; align-items: center; gap: .35rem; font-weight: 600; }
.near-btn:disabled { opacity: .6; cursor: progress; }
.geo-msg { margin: .6rem auto 0; font-size: .875rem; color: var(--hold); }

.facets { display: flex; flex-wrap: wrap; gap: .5rem 1.75rem; margin-top: .75rem; }
fieldset { border: 0; padding: 0; margin: 0; display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
legend { float: left; margin-right: .4rem; font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 0; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: .25rem .75rem; font-size: .875rem; }
.chip:hover { border-color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip small { opacity: .65; margin-left: .25em; }

.meta { margin-top: .75rem; font-size: .9rem; }
#count { margin: 0; color: var(--muted); }
#count b { color: var(--ink); }
.link { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; }
.alert-btn { margin-left: auto; padding: .25rem .8rem; font-weight: 600; }
.alert-btn:hover { border-color: var(--accent); color: var(--accent); }
.sort { color: var(--muted); display: flex; gap: .4rem; align-items: center; }
.sort select { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: .25rem .6rem; }

.hero { margin: 0 0 1.25rem; }
.hero h1 { margin: 0; font-size: clamp(1.4rem, 3.5vw, 2rem); letter-spacing: -.02em; line-height: 1.15; }
.hero p { margin: .35rem 0 0; color: var(--muted); max-width: 70ch; }
main { max-width: 1500px; margin: auto; padding: 1.25rem clamp(1rem, 4vw, 2.5rem) 3rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1.25rem; }
.card { position: relative; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; content-visibility: auto; contain-intrinsic-size: 220px 360px; transition: transform .15s; }
.card:hover { transform: translateY(-3px); }
.card a { display: block; text-decoration: none; }
.card a::after { content: ""; position: absolute; inset: 0; }
.photo { aspect-ratio: 4 / 5; background: var(--line); display: block; width: 100%; object-fit: cover; }
.photo.ph { display: grid; place-items: center; color: var(--muted); font-size: 3rem; }
.card.adopted .photo { filter: grayscale(.7); opacity: .8; }
.body { padding: .7rem .9rem .9rem; }
.name { margin: 0; font-size: 1.1rem; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.facts { margin: .1rem 0 0; color: var(--muted); font-size: .875rem; }
.where { margin: .35rem 0 0; font-size: .8rem; color: var(--muted); display: flex; gap: .3rem; align-items: center; }
.where::before { content: ""; width: .5rem; height: .5rem; border-radius: 50%; background: var(--dot, var(--muted)); flex: none; }
[data-src="spca"] { --dot: #e2572b; } [data-src="proanima"] { --dot: #2b8fb5; } [data-src="bergerblanc"] { --dot: #7b61c9; }
[data-src="roussillon"] { --dot: #d19a1c; } [data-src="animatch"] { --dot: #c2417c; } [data-src="gerdys"] { --dot: #4f7f3a; }
.badges { position: absolute; top: .6rem; left: .6rem; display: flex; gap: .3rem; z-index: 1; pointer-events: none; }
.badge { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: .2rem .55rem; border-radius: 999px; background: var(--accent); color: var(--accent-ink); }
.badge.adopted { background: var(--ok-soft); color: var(--ok); }
.badge.hold { background: var(--hold-soft); color: var(--hold); }
.fav { position: absolute; top: .45rem; right: .45rem; z-index: 2; width: 2.25rem; height: 2.25rem; border-radius: 50%; border: 0; background: rgb(255 255 255 / .88); color: #8a7f76; font-size: 1.1rem; line-height: 1; display: grid; place-items: center; }
.fav:hover { transform: scale(1.1); }
.fav[aria-pressed="true"] { color: #e0245e; }

.empty { text-align: center; color: var(--muted); padding: 4rem 1rem; font-size: 1.05rem; }
.skeleton { aspect-ratio: 4 / 6.5; border-radius: var(--radius); background: linear-gradient(100deg, var(--line) 30%, var(--card) 50%, var(--line) 70%) 0 0 / 300% 100%; animation: sh 1.2s infinite linear; }
@keyframes sh { to { background-position: -150% 0; } }

footer { max-width: 1500px; margin: auto; padding: 1.5rem clamp(1rem, 4vw, 2.5rem) 3rem; color: var(--muted); font-size: .85rem; border-top: 1px solid var(--line); }
footer nav { display: flex; flex-wrap: wrap; gap: .25rem 1rem; margin-bottom: .75rem; font-weight: 600; }
footer p { margin: .25rem 0; max-width: 75ch; }

dialog { border: 0; padding: 0; background: var(--card); color: var(--ink); border-radius: 20px; width: min(980px, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem); box-shadow: 0 30px 80px rgb(0 0 0 / .35); overflow: hidden; }
dialog#detail[open] { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
dialog::backdrop { background: rgb(20 12 8 / .6); backdrop-filter: blur(3px); }
.gallery { background: #000; position: relative; display: flex; flex-direction: column; min-height: 0; max-height: calc(100dvh - 2rem); }
.gallery .main { flex: 1; min-height: 0; width: 100%; object-fit: contain; background: #111; }
.gallery .ph { flex: 1; display: grid; place-items: center; font-size: 5rem; background: var(--line); min-height: 300px; }
.thumbs { display: flex; gap: 4px; padding: 4px; background: #000; overflow-x: auto; }
.thumbs button { border: 2px solid transparent; padding: 0; background: none; border-radius: 6px; overflow: hidden; flex: none; }
.thumbs button[aria-current="true"] { border-color: #fff; }
.thumbs img { display: block; width: 64px; height: 64px; object-fit: cover; }
.info { padding: 1.5rem 1.75rem 1.75rem; overflow-y: auto; max-height: calc(100dvh - 2rem); }
.info h2 { margin: 0 2.5rem .15rem 0; font-size: 1.9rem; letter-spacing: -.02em; line-height: 1.15; }
.info .sub { margin: 0 0 1rem; color: var(--muted); }
.info .tags { display: flex; gap: .35rem; flex-wrap: wrap; margin-bottom: 1rem; }
.info dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem 1rem; margin: 0 0 1.25rem; padding: 1rem; background: var(--bg); border-radius: 12px; }
.info dt { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.info dd { margin: 0; font-weight: 600; }
.desc { white-space: pre-line; margin: 0 0 1.25rem; }
.desc-note { font-size: .8rem; color: var(--muted); margin: -.75rem 0 1.25rem; font-style: italic; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.cta { display: inline-block; background: var(--accent); color: var(--accent-ink); font-weight: 700; text-decoration: none; padding: .7rem 1.2rem; border-radius: 999px; }
.cta:hover { filter: brightness(1.08); }
.close { position: absolute; top: .75rem; right: .75rem; z-index: 3; width: 2.4rem; height: 2.4rem; border-radius: 50%; border: 0; background: var(--bg); font-size: 1.3rem; line-height: 1; }
.nav { position: absolute; top: 45%; z-index: 2; width: 2.4rem; height: 2.4rem; border-radius: 50%; border: 0; background: rgb(255 255 255 / .85); color: #222; font-size: 1.2rem; }
.nav.prev { left: .6rem; } .nav.next { right: .6rem; }
.seen { font-size: .8rem; color: var(--muted); margin: 1rem 0 0; }

dialog.sheet { width: min(560px, calc(100vw - 2rem)); overflow-y: auto; }
.alert-body { padding: 1.5rem 1.75rem 1.75rem; }
.alert-body h2 { margin: 0 2.5rem .5rem 0; font-size: 1.4rem; letter-spacing: -.01em; }
.alert-body h3 { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1.5rem 0 .5rem; }
.alert-body ol { padding-left: 1.2rem; margin: 1rem 0 1.25rem; }
.alert-body li { margin: .5rem 0; }
.alert-body ul { list-style: none; padding: 0; margin: 0; }
.alert-body ul li { display: flex; justify-content: space-between; gap: 1rem; padding: .5rem 0; border-top: 1px solid var(--line); margin: 0; }
.alert-for { background: var(--bg); border-radius: 12px; padding: .75rem 1rem; margin: 1rem 0 0; display: grid; gap: .15rem; }
.alert-for span { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.topic-row { display: flex; gap: .4rem; margin-top: .5rem; }
.topic-row input { flex: 1; min-width: 0; font-family: ui-monospace, monospace; font-size: .9rem; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: .45rem .7rem; }
.muted { color: var(--muted); margin: 0; }
button.cta { border: 0; }
button.cta:disabled { opacity: .6; }
#alertMsg { font-size: .9rem; }

@media (max-width: 760px) {
  .controls { position: static; }
  .tagline { display: none; }
  .filters-btn { display: inline-block; }
  .facets { display: none; }
  .facets.open { display: flex; flex-direction: column; gap: .75rem; }
  .sort span { display: none; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
  .body { padding: .55rem .7rem .7rem; }
  .name { font-size: 1rem; }
  dialog { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; margin: 0; }
  dialog#detail[open], dialog.sheet[open] { display: block; overflow-y: auto; }
  .gallery { max-height: 60dvh; }
  .gallery .main { max-height: 52dvh; }
  .info { max-height: none; overflow: visible; padding: 1.1rem 1.1rem 2rem; }
  .close { position: fixed; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
