:root {
  --bg: #faf9f7;
  --surface: #ffffff;
  --surface-2: #f2f0ec;
  --border: #e3e0d9;
  --border-strong: #cfcbc1;
  --text: #191817;
  --text-2: #56534d;
  --muted: #857f76;
  --accent: #1f6f4a;
  --accent-soft: #e8f2ec;
  --accent-text: #ffffff;
  --danger: #a1372a;
  --shadow-sm: 0 1px 2px rgba(24,22,20,.06);
  --shadow: 0 2px 4px rgba(24,22,20,.05), 0 12px 32px rgba(24,22,20,.07);
  --radius: 12px;
  --radius-lg: 18px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131415;
    --surface: #1c1e1f;
    --surface-2: #242628;
    --border: #303335;
    --border-strong: #43474a;
    --text: #f0efec;
    --text-2: #b4b1ab;
    --muted: #8e8b85;
    --accent: #5cbf8d;
    --accent-soft: #172a20;
    --accent-text: #0d2318;
    --danger: #e08e7f;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.35);
    --shadow: 0 2px 4px rgba(0,0,0,.3), 0 12px 32px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { letter-spacing: -.021em; line-height: 1.2; margin: 0; }
h1 { font-size: clamp(1.75rem, 4vw, 2.5rem); font-weight: 640; }
h2 { font-size: 1.3rem; font-weight: 620; }

.hint { color: var(--muted); font-size: .9rem; margin: .3rem 0 0; max-width: 60ch; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88em; }

/* --------------------------------------------------------------- brand */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1.25rem;
  padding: .8rem clamp(1rem, 4vw, 2rem);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex; align-items: baseline; gap: .5rem;
  text-decoration: none; color: var(--text);
}
.brand-mark {
  font-size: 1.12rem; font-weight: 680; letter-spacing: -.035em;
}
.brand-tld { color: var(--accent); font-weight: 620; }

.tabs { display: flex; gap: .15rem; flex: 1; }

.tab {
  border: 0; background: none; color: var(--muted);
  padding: .42rem .8rem; border-radius: 8px;
  font: inherit; font-size: .92rem; font-weight: 500; cursor: pointer;
  transition: background .13s ease, color .13s ease;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); font-weight: 570; }

/* -------------------------------------------------------------- buttons */

.btn {
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  padding: .48rem .95rem; border-radius: 9px;
  font: inherit; font-size: .92rem; font-weight: 520; cursor: pointer;
  white-space: nowrap;
  transition: filter .13s ease, transform .08s ease;
}
.btn:hover { filter: brightness(.975); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 570; }
.btn-quiet { background: none; border-color: transparent; color: var(--muted); }
.btn-quiet:hover { background: var(--surface-2); color: var(--text); }
.btn-lg { padding: .7rem 1.6rem; font-size: 1rem; border-radius: 11px; }

main { max-width: 1080px; margin: 0 auto; padding: clamp(1.5rem, 4vw, 3rem) clamp(1rem, 4vw, 2rem) 6rem; }

.view { display: none; }
.view.is-active { display: block; }

.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1.5rem; margin-bottom: 1.5rem; }
.back { margin-bottom: 1rem; padding-left: 0; }

/* ----------------------------------------------------------- progress */

.progress {
  position: sticky; top: 57px; z-index: 15;
  padding: .65rem clamp(1rem, 4vw, 2rem);
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.progress-bar { height: 3px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .35s ease; }
.progress-text { font-size: .82rem; color: var(--muted); margin-top: .4rem; }

/* --------------------------------------------------------------- hero */

.hero { text-align: center; max-width: 34rem; margin: clamp(1rem, 4vw, 2.5rem) auto 2rem; }
.lede { color: var(--text-2); font-size: 1.05rem; margin: .8rem 0 0; }

/* ----------------------------------------------------------- dropzone */

.dropzone {
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius-lg);
  padding: clamp(1.75rem, 5vw, 3rem) 1.5rem; text-align: center; cursor: pointer;
  background: var(--surface); max-width: 34rem; margin: 0 auto;
  transition: border-color .15s ease, background .15s ease;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); }
.dz-icon { width: 30px; height: 30px; color: var(--muted); margin-bottom: .65rem; }
.dropzone strong { display: block; font-weight: 570; }
.dropzone span { color: var(--muted); font-size: .88rem; }

.ref-previews { display: flex; gap: .55rem; justify-content: center; flex-wrap: wrap; }
.ref-previews:not(:empty) { margin-top: .3rem; }
.ref-previews img {
  width: 78px; height: 78px; object-fit: cover;
  border-radius: 10px; box-shadow: var(--shadow-sm);
}

.search-actions { text-align: center; margin-top: 1.5rem; }
.advanced { margin-top: 1.5rem; }
.advanced summary { cursor: pointer; color: var(--muted); font-size: .88rem; list-style-position: inside; }
.advanced .hint { margin: .7rem auto 0; text-align: left; max-width: 34rem; }
.slider-row { display: flex; align-items: center; justify-content: center; gap: .85rem; margin-top: .9rem; }
.slider-row input { flex: 1; max-width: 22rem; accent-color: var(--accent); }
.slider-row output { font-family: ui-monospace, Menlo, monospace; font-size: .9rem; min-width: 2.6rem; }

.result-group { margin-top: 2.5rem; }
.result-group h3 { font-size: 1.05rem; margin: 0; }
.result-group .hint { margin-bottom: 1rem; }

/* ------------------------------------------------------------- people */

.people-grid { display: grid; gap: 1.5rem 1.25rem; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); }

.person { text-align: center; }
.person-avatar {
  width: 100%; aspect-ratio: 1; border-radius: 50%;
  object-fit: cover; background: var(--surface-2);
  cursor: pointer; border: 2px solid transparent; box-shadow: var(--shadow-sm);
  transition: border-color .14s ease, transform .14s ease;
}
.person-avatar:hover { border-color: var(--accent); transform: translateY(-3px); }
.person-name {
  display: block; width: 100%; margin-top: .6rem;
  border: 0; background: none; color: var(--text);
  font: inherit; font-size: .9rem; font-weight: 560; text-align: center;
  border-radius: 6px; padding: .18rem; cursor: text;
}
.person-name:hover:not([readonly]) { background: var(--surface-2); }
.person-name[readonly] { cursor: default; }
.person-name.unnamed { color: var(--muted); font-weight: 400; }
.person-count { font-size: .8rem; color: var(--muted); }

/* ------------------------------------------------------------- photos */

.photo-grid { display: grid; gap: .7rem; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); }

.photo {
  position: relative; aspect-ratio: 1;
  border-radius: var(--radius); overflow: hidden;
  background: var(--surface-2); cursor: zoom-in; box-shadow: var(--shadow-sm);
}
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .3s ease; }
.photo:hover img { transform: scale(1.04); }
.photo .badge {
  position: absolute; left: .45rem; bottom: .45rem;
  padding: .12rem .45rem; border-radius: 6px;
  font-size: .73rem; font-weight: 600;
  background: rgba(0,0,0,.7); color: #fff; backdrop-filter: blur(4px);
}
.photo .del {
  position: absolute; top: .4rem; right: .4rem;
  width: 25px; height: 25px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.65); color: #fff;
  font-size: 15px; line-height: 1; cursor: pointer;
  opacity: 0; transition: opacity .14s ease;
}
.photo:hover .del { opacity: 1; }
.photo.is-pending, .photo.is-error {
  display: grid; place-items: center; font-size: .78rem; padding: .6rem; text-align: center;
}
.photo.is-pending { color: var(--muted); }
.photo.is-error { color: var(--danger); }

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

.lightbox {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(12,11,10,.94);
  display: grid; place-items: center; padding: 2.5rem 1.5rem 5rem;
}
.lightbox-stage { position: relative; line-height: 0; max-width: 100%; max-height: 100%; }
.lightbox img { display: block; max-width: 100%; max-height: calc(100vh - 9rem); border-radius: 8px; }

/* Drawn over the matched face. The dark outer ring keeps it visible against
   sky and pale skin, where a bare green line disappears. */
.face-box {
  position: absolute;
  border: 3px solid #22c55e; border-radius: 5px;
  box-shadow: 0 0 0 1.5px rgba(0,0,0,.6), inset 0 0 0 1.5px rgba(0,0,0,.4);
  pointer-events: none;
}
/* Two cycles then stop — enough to catch the eye, not enough to nag. */
.face-box.pulse { animation: face-pulse .75s ease-out 2; }
@keyframes face-pulse {
  0%   { box-shadow: 0 0 0 1.5px rgba(0,0,0,.6), 0 0 0 0 rgba(34,197,94,.85); }
  100% { box-shadow: 0 0 0 1.5px rgba(0,0,0,.6), 0 0 0 24px rgba(34,197,94,0); }
}
@media (prefers-reduced-motion: reduce) { .face-box.pulse { animation: none; } }

.lightbox-close {
  position: absolute; top: 1rem; right: 1.25rem;
  border: 0; background: none; color: rgba(255,255,255,.8);
  font-size: 2rem; line-height: 1; cursor: pointer;
}
.lightbox-close:hover { color: #fff; }
.lightbox-bar {
  position: absolute; bottom: 1.25rem; left: 0; right: 0;
  display: flex; align-items: center; justify-content: center; gap: 1.25rem;
  flex-wrap: wrap; color: rgba(255,255,255,.72); font-size: .85rem;
}
.lightbox-bar .btn { text-decoration: none; }

/* ------------------------------------------------------ empty, toast */

.empty {
  border: 1px dashed var(--border); border-radius: var(--radius-lg);
  padding: 3rem 1.5rem; text-align: center; color: var(--muted);
  background: var(--surface);
}
.empty strong { display: block; color: var(--text); margin-bottom: .35rem; font-weight: 570; }

.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  z-index: 60; padding: .65rem 1.1rem; border-radius: 10px;
  background: var(--text); color: var(--bg);
  font-size: .9rem; font-weight: 500; box-shadow: var(--shadow);
  max-width: calc(100vw - 2rem);
}

.footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem; text-align: center;
  color: var(--muted); font-size: .82rem;
}

/* Hiding these is a courtesy, not a control — the server rejects the request
   regardless of what the page chooses to render. */
.admin-only { display: none !important; }
body.is-admin .admin-only { display: revert !important; }
body.is-admin .photo .del { display: block !important; }

[hidden] { display: none !important; }
