:root {
  --bg: #f6f1e7;
  --surface: #fffcf6;
  --text: #2f2a22;
  --muted: #7a6e5d;
  --border: #e7dcc8;
  --accent: #8b6b45;
  --accent-text: #ffffff;
  --bar: #dccbab;
  --bar-text: #2f2a22;
  --danger: #a8432f;
  --placeholder: #efe6d6;
  --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1a15;
    --surface: #27231c;
    --text: #f0e8da;
    --muted: #b4a68f;
    --border: #3b352b;
    --accent: #d6b98c;
    --accent-text: #1d1a15;
    --bar: #3a3226;
    --bar-text: #f0e8da;
    --danger: #e0806a;
    --placeholder: #322c23;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 4px;
  padding: calc(env(safe-area-inset-top) + 8px) 8px 8px;
  background: var(--bar); color: var(--bar-text);
}
.topbar h1 { flex: 1; margin: 0 8px; font-size: 1.15rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  border: 0; border-radius: 50%; background: transparent; color: inherit;
  font-size: 1.4rem; text-decoration: none; cursor: pointer;
}
#back { font-size: 2rem; line-height: 1; }
.topbar .icon-btn:active { background: rgba(0,0,0,.08); }

main { max-width: 720px; margin: 0 auto; padding: 12px 16px calc(96px + env(safe-area-inset-bottom)); }
h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 20px 4px 8px; }

.search input, .form input, .form select, .form textarea {
  width: 100%; padding: 12px 14px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.search input { font-size: 1.05rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; color: inherit; text-decoration: none; }
.row + .row { border-top: 1px solid var(--border); }
.row:active { background: var(--placeholder); }
.thumb { width: 48px; height: 48px; flex: none; border-radius: 8px; object-fit: cover; background: var(--placeholder); }
.thumb.placeholder { display: grid; place-items: center; font-size: 1.4rem; }
.row-text { flex: 1; min-width: 0; }
.row-title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { color: var(--muted); font-size: .875rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qty { color: var(--muted); font-weight: 400; }
.chev { color: var(--muted); font-size: 1.4rem; }

.crumbs { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: .9rem; margin: 4px 4px 8px; }
.crumbs span:not(.sep) { color: var(--muted); }
.crumbs .sep { color: var(--muted); }
.loc-head .kind { color: var(--muted); margin: 4px; }
.hero { width: 100%; max-height: 260px; object-fit: cover; border-radius: var(--radius); background: var(--placeholder); }
.notes { white-space: pre-wrap; margin: 4px; }
.empty { color: var(--muted); margin: 12px 4px; }

.gallery { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; margin: 0 -16px 12px; padding: 0 16px; }
.gallery img { height: 280px; max-width: 90%; flex: none; object-fit: cover; border-radius: var(--radius); scroll-snap-align: center; background: var(--placeholder); }
.gallery img:only-child { width: 100%; max-width: 100%; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.where-label { font-size: .8rem; color: var(--muted); margin: 0 4px; }
.card .crumbs { font-size: 1.05rem; margin-bottom: 2px; }
.facts { margin: 16px 4px; }
.facts dt { font-size: .8rem; color: var(--muted); margin-top: 12px; }
.facts dd { margin: 2px 0 0; }
.tag { display: inline-block; padding: 2px 10px; border-radius: 99px; background: var(--placeholder); font-size: .875rem; }

.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px); border-top: 1px solid var(--border);
}
.bottom-bar .btn { flex: 1; max-width: 340px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px; font: inherit; font-weight: 550;
  color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); margin-right: auto; }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: .875rem; }

.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 6px; font-weight: 550; font-size: .9rem; }
.form label.btn { display: inline-flex; font-size: 1rem; }
.form small { font-weight: 400; color: var(--muted); }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.form-actions.left { justify-content: flex-start; }

.photo-field { display: grid; gap: 8px; }
.photo-buttons { display: flex; gap: 8px; }
.photo-buttons .btn { flex: 1; }
.photo-strip { display: flex; gap: 8px; flex-wrap: wrap; }
.photo-strip:empty { display: none; }
.photo-tile { position: relative; }
.photo-tile img { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; display: block; background: var(--placeholder); }
.photo-tile .x {
  position: absolute; top: -6px; right: -6px; width: 26px; height: 26px; border-radius: 50%;
  border: 0; background: var(--text); color: var(--bg); font-size: 1rem; line-height: 1; cursor: pointer;
}

dialog { border: 0; border-radius: var(--radius); background: var(--surface); color: var(--text); width: min(92vw, 480px); padding: 20px; }
dialog::backdrop { background: rgba(0,0,0,.4); }

#toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 99px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 20; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.muted { color: var(--muted); }
p.small { font-size: .8rem; }
.invite-link { word-break: break-all; font-family: ui-monospace, monospace; font-size: .85rem; background: var(--placeholder); padding: 8px 10px; border-radius: 8px; }
.card + .form, .card + #members, #members + .form { margin-top: 12px; }
.card p { margin: 4px 0 8px; }
.row .btn.small { flex: none; }
