:root {
  --bg: #faf6f0;
  --surface: #ffffff;
  --ink: #2a2420;
  --muted: #7a6f66;
  --line: #eadfd3;
  --accent: #b8402c;
  --accent-ink: #ffffff;
  --accent-soft: #f8e3dd;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 8px 24px rgba(60, 40, 20, .06);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1613; --surface: #241f1b; --ink: #f3ece4; --muted: #a39a90; --line: #3a322b;
    --accent: #e0735e; --accent-ink: #1a1613; --accent-soft: #3a2520; --danger: #f08a80; --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { line-height: 1.2; margin: 0; }
.muted { color: var(--muted); }

/* banners */
.banner {
  display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between;
  padding: 10px 16px; font-size: 14px; background: var(--accent-soft); border-bottom: 1px solid var(--line);
}
.banner.owner { background: var(--ink); color: var(--bg); border: 0; }
.banner-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.banner.owner .btn.ghost { color: var(--bg); border-color: color-mix(in srgb, var(--bg) 40%, transparent); }

/* hero */
.hero { max-width: 760px; margin: 0 auto; padding: 56px 16px 24px; text-align: center; }
.hero h1 { font: 600 clamp(2rem, 6vw, 3rem)/1.1 ui-serif, Georgia, "Times New Roman", serif; letter-spacing: -.01em; }
.hero p { color: var(--muted); margin: 14px auto 0; max-width: 56ch; }

main { max-width: 1080px; margin: 0 auto; padding: 8px 16px 48px; }
.status { text-align: center; color: var(--muted); margin: 16px 0; min-height: 1.5em; }


/* grid + cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 18px; }
.card {
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; overflow: hidden; box-shadow: var(--shadow);
}
.thumb {
  position: relative; aspect-ratio: 4 / 3; display: grid; place-items: center; overflow: hidden;
  background: var(--accent-soft); color: var(--accent);
}
/* With a picture: show all of it (contain), on a blurred copy of itself so any shape looks intentional. */
.thumb.has-img .gift { display: none; }
.thumb.has-img::before {
  content: ""; position: absolute; inset: -24px; background: var(--bg) center / cover;
  filter: blur(20px) saturate(1.2); opacity: .6;
}
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; padding: 10px; }
.body { padding: 14px 16px 6px; flex: 1; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; min-height: 0; }
.meta:empty { display: none; }
.badge, .tag { font-size: 12px; padding: 2px 9px; border-radius: 999px; }
.badge { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.tag { background: var(--accent-soft); color: var(--accent); }
.card h3 { font-size: 1.05rem; font-weight: 600; }
.price { margin: 4px 0 0; font-weight: 600; }
.note { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.actions { display: flex; align-items: center; gap: 8px; padding: 12px 16px 16px; flex-wrap: wrap; }
.spacer { flex: 1; }

.mine { margin-top: 48px; padding-top: 28px; border-top: 1px dashed var(--line); }
.mine h2 { font: 600 1.4rem ui-serif, Georgia, serif; }
.mine .muted { margin: 4px 0 18px; font-size: 14px; }

/* buttons */
.btn {
  font: inherit; font-weight: 600; font-size: 15px; padding: 10px 18px; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent; text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
}
.btn.small { padding: 6px 12px; font-size: 14px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.danger-text { color: var(--danger); }
.btn:disabled { opacity: .6; cursor: default; }
.btn:focus-visible, .link:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.link { background: none; border: 0; color: var(--muted); font: inherit; font-size: 13px; text-decoration: underline; cursor: pointer; }
footer { text-align: center; padding: 24px 16px 40px; }

/* dialogs */
dialog {
  width: min(480px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto;
  border: 1px solid var(--line); border-radius: 18px; padding: 24px; background: var(--surface); color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(20, 12, 8, .5); }
dialog h2 { font: 600 1.35rem ui-serif, Georgia, serif; margin-bottom: 14px; }
dialog p.muted { margin: 0 0 8px; }
label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.opt { font-weight: 400; color: var(--muted); }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; font: inherit; font-weight: 400; color: var(--ink);
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}
textarea { resize: vertical; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .two { grid-template-columns: 1fr; } }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.error { color: var(--danger); font-size: 14px; margin: 0; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 10;
  max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 12px; font-size: 15px;
  background: var(--ink); color: var(--bg); box-shadow: 0 8px 30px rgba(0, 0, 0, .25);
}
.toast.bad { background: var(--danger); color: #fff; }

.muted.small { font-size: 13px; }
.reveal-list { max-height: 55vh; overflow: auto; }
.reveal-person { padding: 10px 0; border-bottom: 1px solid var(--line); }
.reveal-person:last-child { border-bottom: 0; }
.reveal-person h3 { font-size: 1rem; }
.reveal-person ul { margin: 4px 0 0; padding-left: 20px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 4px; }
.chip {
  font: inherit; font-size: 14px; padding: 6px 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.chip:hover { background: var(--accent-soft); }
.chip.warn { color: var(--danger); border-style: dashed; }
.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sortbar { display: flex; justify-content: center; align-items: center; gap: 8px; margin: 4px 0 18px; }
.sortbar label { margin: 0; font-weight: 400; color: var(--muted); }
.sortbar select { width: auto; margin: 0; padding: 6px 10px; }

.lock { max-width: 420px; margin: 24px auto; padding: 24px; text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.lock h2 { font: 600 1.35rem ui-serif, Georgia, serif; margin-bottom: 6px; }
.lock form { display: flex; gap: 8px; margin: 16px 0 8px; }
.lock input { margin: 0; flex: 1; min-width: 0; }
.lock .error { margin-top: 8px; }
.share-row { display: flex; flex-wrap: wrap; gap: 8px; }
#share-link-box { margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--line); }
#share-link-box label { margin-bottom: 8px; }

/* Small screens: pin popups to the top of the visible area (not the middle), sized to what the on-screen
   keyboard leaves free. --vvh / --vvtop are kept up to date by app.js. */
@media (max-width: 640px) {
  dialog {
    inset: auto 0 auto 0;
    top: calc(var(--vvtop, 0px) + 12px);
    margin: 0 auto;
    max-height: calc(var(--vvh, 100dvh) - 24px);
    padding: 20px;
  }
}

/* personal invite links */
#share-dialog h3 { font-size: 1.05rem; margin: 14px 0 4px; }
.invite-form { display: flex; gap: 8px; margin: 10px 0 4px; }
.invite-form input { margin: 0; flex: 1; min-width: 0; }
.invite-list { list-style: none; margin: 10px 0 4px; padding: 0; }
.invite-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.invite-list li:last-child { border-bottom: 0; }
.invite-name { flex: 1; min-width: 7rem; font-weight: 600; overflow-wrap: anywhere; }
.invite-name .badge { font-weight: 400; margin-left: 6px; background: var(--danger); color: #fff; }
.invite-list li.off .invite-name { color: var(--muted); text-decoration: line-through; }
.family-code { margin-top: 14px; padding-top: 10px; border-top: 1px dashed var(--line); }
.family-code summary { cursor: pointer; font-weight: 600; font-size: 14px; margin-bottom: 10px; }
.claim-as strong { color: var(--ink); }
