:root {
  --bg: #f5f1ea;
  --surface: #fffdf9;
  --surface-2: #ece6dc;
  --ink: #1f1b16;
  --muted: #6d655a;
  --line: #dcd3c5;
  --accent: #b4532a;
  --accent-ink: #fffaf4;
  --accent-soft: #f3dfd2;
  --danger: #b42a2a;
  --ok: #2f7a4b;
  --shadow: 0 10px 30px rgba(40, 28, 15, 0.12);
  --radius: 14px;
  --serif: ui-serif, "New York", "Iowan Old Style", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141210;
    --surface: #1d1a17;
    --surface-2: #2a2622;
    --ink: #f2ede5;
    --muted: #a69d90;
    --line: #3a342d;
    --accent: #e0875a;
    --accent-ink: #1a0f08;
    --accent-soft: #3b261b;
    --danger: #ef6b6b;
    --ok: #6cc08e;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
svg.i { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: 16px; text-decoration: none; white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 15px; border-radius: 10px; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.icon-btn {
  width: 44px; height: 44px; display: inline-grid; place-items: center;
  border: 0; background: transparent; border-radius: 12px; color: inherit;
}
.icon-btn:hover { background: var(--surface-2); }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 14px; font-weight: 600; color: var(--muted); }
.input {
  width: 100%; min-height: 46px; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  font-size: 16px;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea.input { min-height: 80px; resize: vertical; }
.hint { font-size: 14px; color: var(--muted); margin: 4px 0 12px; }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; text-align: center; }
.login-card img { width: 72px; height: 72px; border-radius: 18px; margin-bottom: 12px; }
.login-card h1 { font: 600 30px/1.15 var(--serif); margin: 0 0 6px; }
.login-card p { color: var(--muted); margin: 0 0 24px; }
.login-card form { text-align: left; }
.login-card .btn { width: 100%; margin-top: 6px; }
.error { color: var(--danger); font-size: 15px; min-height: 22px; margin: 4px 0; }

/* ---------- Header ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
  border-bottom: 1px solid transparent;
}
.top.scrolled { border-bottom-color: var(--line); }
.top-row { display: flex; align-items: center; gap: 8px; max-width: 1400px; margin: 0 auto; }
.brand { font: 600 24px/1.1 var(--serif); margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand a { color: inherit; text-decoration: none; }
.search {
  display: flex; align-items: center; gap: 8px; margin: 10px auto 0; max-width: 1400px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 0 6px 0 12px;
}
.search input { flex: 1; min-width: 0; border: 0; background: transparent; height: 44px; font-size: 16px; outline: none; }
.search .icon-btn { width: 40px; height: 40px; }
.filter-count {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700;
}

.wrap { max-width: 1400px; margin: 0 auto; padding: 0 16px; }

/* ---------- People strip ---------- */
.people-strip {
  display: flex; gap: 14px; overflow-x: auto; padding: 12px 16px 6px; margin: 0 -16px;
  scrollbar-width: none; scroll-snap-type: x proximity; scroll-padding-inline: 16px;
}
.people-strip::-webkit-scrollbar { display: none; }
.person {
  flex: none; width: 72px; display: grid; justify-items: center; gap: 6px;
  border: 0; background: none; padding: 0; scroll-snap-align: start;
}
.avatar {
  width: 64px; height: 64px; border-radius: 50%; background: var(--surface-2) center/cover no-repeat;
  display: grid; place-items: center; font: 600 22px var(--serif); color: var(--muted);
  border: 3px solid transparent; outline: 1px solid var(--line); outline-offset: -1px;
  transition: border-color .15s, transform .15s;
}
.person.on .avatar { border-color: var(--accent); outline-color: transparent; transform: scale(1.04); }
.person .nm { font-size: 13px; font-weight: 600; line-height: 1.15; max-width: 72px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person.on .nm { color: var(--accent); }
.person .ct { font-size: 11px; color: var(--muted); margin-top: -5px; }

/* ---------- Segmented control ---------- */
.seg {
  display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; overflow-x: auto; scrollbar-width: none;
}
.seg button {
  flex: 1 0 auto; border: 0; background: transparent; border-radius: 9px; min-height: 38px; padding: 0 12px;
  font-size: 15px; font-weight: 600; color: var(--muted); white-space: nowrap;
}
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.controls { display: grid; gap: 10px; padding: 6px 0 4px; }
.match-row { display: grid; gap: 6px; }
.match-row .lbl { font-size: 14px; color: var(--muted); }

/* ---------- Chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  font-size: 15px; font-weight: 500;
}
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }
.chip .x { font-size: 18px; line-height: 1; color: var(--muted); }
.chip small { color: var(--muted); font-size: 12px; }

/* ---------- Result bar & grid ---------- */
.result-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 0 4px; }
.result-bar .count { font-weight: 600; }
.group-h {
  grid-column: 1 / -1; font: 600 19px/1.2 var(--serif); padding: 18px 2px 4px; position: sticky; top: var(--top-h, 120px);
}
.grid {
  display: grid; gap: 3px; grid-template-columns: repeat(3, 1fr);
  margin: 0 -13px; padding-bottom: 120px;
}
@media (min-width: 600px) { .grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px; margin: 0; } }
.tile {
  position: relative; aspect-ratio: 1; border: 0; padding: 0; background: var(--surface-2); overflow: hidden;
  display: block; width: 100%;
}
@media (min-width: 600px) { .tile { border-radius: 8px; } }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .25s; }
.tile img.ld { opacity: 1; }
.tile .check {
  position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid #fff; background: rgba(0,0,0,.25); display: none; place-items: center; color: #fff;
}
.selecting .tile .check { display: grid; }
.tile.sel .check { background: var(--accent); border-color: var(--accent); }
.tile.sel img { transform: scale(0.9); border-radius: 6px; }
.tile.sel { background: var(--accent-soft); }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty h2 { font: 600 22px var(--serif); color: var(--ink); margin: 0 0 6px; }
.sentinel { height: 1px; }
.loading-more { text-align: center; color: var(--muted); padding: 20px; grid-column: 1/-1; }

/* ---------- Selection bar ---------- */
.selbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px);
  background: var(--surface); border-top: 1px solid var(--line); box-shadow: var(--shadow);
  display: grid; gap: 8px;
}
.selbar .sb-row { display: flex; gap: 8px; align-items: center; max-width: 760px; width: 100%; margin: 0 auto; }
.selbar .sb-row .btn { flex: 1; }
.selbar .n { font-weight: 700; padding: 0 6px; white-space: nowrap; flex: 1; }
.selbar .sb-row .btn.fit { flex: none; }

/* ---------- Sheets ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(15, 10, 5, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease-out;
}
@media (min-width: 700px) { .overlay { align-items: center; } }
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg); border-radius: 20px 20px 0 0; box-shadow: var(--shadow);
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 20px);
  animation: up .2s ease-out;
}
@media (min-width: 700px) { .sheet { border-radius: 20px; } }
.sheet-h { display: flex; align-items: center; gap: 8px; position: sticky; top: -8px; background: var(--bg); padding: 8px 0; z-index: 1; }
.sheet-h h2 { flex: 1; margin: 0; font: 600 22px var(--serif); }
.sheet h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 20px 0 8px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 20px; }
.sheet-actions .btn { flex: 1; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }

/* ---------- Lightbox ---------- */
.lb {
  position: fixed; inset: 0; z-index: 40; background: #000; color: #fff;
  display: grid; grid-template-rows: auto 1fr auto; touch-action: pan-y;
}
.lb-top, .lb-bottom { padding: 8px 10px; display: flex; align-items: center; gap: 6px; }
.lb-top { padding-top: calc(env(safe-area-inset-top) + 6px); }
.lb-bottom { padding-bottom: calc(env(safe-area-inset-bottom) + 10px); flex-direction: column; align-items: stretch; gap: 10px; }
.lb .icon-btn:hover { background: rgba(255,255,255,.12); }
.lb-count { flex: 1; text-align: center; font-size: 15px; color: #cfc8bf; }
.lb-stage { position: relative; overflow: hidden; display: grid; place-items: center; min-height: 0; }
.lb-stage img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; transition: transform .2s ease-out; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 64px; border: 0; background: rgba(0,0,0,.35); color: #fff; border-radius: 10px; display: none; place-items: center; }
.lb-nav.prev { left: 12px; } .lb-nav.next { right: 12px; }
@media (hover: hover) and (min-width: 700px) { .lb-nav { display: grid; } }
.lb-meta { text-align: center; }
.lb-meta .d { font: 600 18px var(--serif); }
.lb-meta .w { font-size: 15px; color: #cfc8bf; }
.lb-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.lb-actions .btn { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.15); color: #fff; }
.lb-actions .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.lb-spinner { position: absolute; color: #aaa; font-size: 14px; }

.info-grid { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 16px; }
.info-grid dt { color: var(--muted); }
.info-grid dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- Pages ---------- */
.page { max-width: 760px; margin: 0 auto; padding: 8px 16px 80px; }
.page h2 { font: 600 26px var(--serif); margin: 10px 0 6px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 14px 0; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .avatar { width: 48px; height: 48px; font-size: 18px; }
.list-item .t { font-weight: 600; }
.list-item .s { font-size: 14px; color: var(--muted); }
.badge { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.badge.admin { background: var(--accent-soft); color: var(--accent); }

.drop {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 28px 16px; text-align: center;
  background: var(--surface); display: grid; gap: 8px; justify-items: center;
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.queue { display: grid; gap: 8px; margin-top: 12px; }
.q-item { display: grid; grid-template-columns: 52px 1fr auto; gap: 12px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
.q-item img { width: 52px; height: 52px; object-fit: cover; border-radius: 8px; background: var(--surface-2); }
.q-item .nm { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-item .st { font-size: 13px; color: var(--muted); }
.q-item .st.err { color: var(--danger); }
.q-item .st.ok { color: var(--ok); }
.bar { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.banner {
  display: flex; gap: 10px; align-items: flex-start; background: var(--accent-soft); border-radius: 12px; padding: 12px 14px; margin: 10px 0; font-size: 15px;
}
.banner .grow { flex: 1; }

#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 90px); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 600; font-size: 15px;
  opacity: 0; pointer-events: none; transition: all .2s; z-index: 100; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.menu {
  position: absolute; right: 12px; top: calc(env(safe-area-inset-top) + 56px); z-index: 60;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  min-width: 220px; padding: 6px;
}
.menu button, .menu a { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; border: 0; background: none; padding: 12px; border-radius: 10px; font-size: 16px; color: var(--ink); text-decoration: none; }
.menu button:hover, .menu a:hover { background: var(--surface-2); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
