:root {
  --bg: #f8f4ee;
  --surface: #ffffff;
  --ink: #2a2320;
  --muted: #776b63;
  --line: #e7ddd2;
  --accent: #b3412e;
  --accent-ink: #ffffff;
  --accent-soft: #f6e3dd;
  --ok: #2f6b47;
  --ok-soft: #e1efe5;
  --danger: #a32a1f;
  --danger-soft: #fbe5e2;
  --bought-bg: #efebe6;
  --radius: 14px;
  --tap: 48px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1715;
    --surface: #26211e;
    --ink: #f1e9e2;
    --muted: #a99c92;
    --line: #3a332e;
    --accent: #e0705a;
    --accent-ink: #1b1715;
    --accent-soft: #3d2620;
    --ok: #7cc49a;
    --ok-soft: #1f3328;
    --danger: #f08a7c;
    --danger-soft: #3d2220;
    --bought-bg: #211d1a;
    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 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); }

.icon {
  width: 1.15em; height: 1.15em; vertical-align: -0.2em;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  flex: none;
}

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* ---------- header ---------- */

.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  min-height: 56px;
  padding: env(safe-area-inset-top) 12px 0;
  background: var(--accent); color: var(--accent-ink);
}
.top-title { flex: 1; margin: 0; font-size: 1.1rem; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-logo { display: grid; place-items: center; width: 32px; }
.top-logo .icon { width: 24px; height: 24px; }
.top-back {
  display: grid; place-items: center;
  width: var(--tap); height: var(--tap); margin-left: -8px;
  color: inherit;
}
.top-back .icon { width: 26px; height: 26px; }
.top-nav { display: flex; align-items: center; gap: 4px; }
.top-nav a, .top-nav .linkish {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 10px;
  color: inherit; text-decoration: none; font-size: 0.95rem; border-radius: 8px;
}
.top-nav a:active, .top-nav .linkish:active { background: rgb(0 0 0 / 0.12); }
.top-nav form { margin: 0; }

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(40px + env(safe-area-inset-bottom));
}

.lead { font-size: 1.15rem; margin: 4px 0 16px; }
.hint { color: var(--muted); font-size: 0.92rem; margin: 12px 0 16px; }
.summary { font-weight: 600; margin: 0 0 10px; }
.empty { text-align: center; color: var(--muted); padding: 32px 8px; }
.section-title { font-size: 1.05rem; margin: 28px 0 10px; display: flex; align-items: center; gap: 8px; }

/* ---------- flash ---------- */

.flash { padding: 12px 14px; border-radius: 10px; margin: 0 0 16px; font-weight: 500; overflow-wrap: anywhere; }
.flash-ok { background: var(--ok-soft); color: var(--ok); }
.flash-error { background: var(--danger-soft); color: var(--danger); }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px;
  border: 1.5px solid transparent; border-radius: 12px;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.6; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-danger { background: transparent; color: var(--danger); border-color: currentColor; }

.linkish {
  background: none; border: 0; padding: 0; font: inherit; color: var(--muted);
  text-decoration: underline; cursor: pointer;
}

/* ---------- cards & lists ---------- */

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.card-link {
  display: flex; align-items: center; gap: 12px;
  min-height: 68px;
  color: inherit; text-decoration: none;
}
.card-link:active { background: var(--accent-soft); }
.card-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.card-main strong { font-size: 1.05rem; }
.card-main .muted { font-size: 0.92rem; }
.chevron { color: var(--muted); }
.card-me { border-color: var(--accent); border-width: 1.5px; }

.avatar {
  display: grid; place-items: center; flex: none;
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: 1.1rem;
}

/* ---------- gifts ---------- */

.gift { display: flex; flex-direction: column; gap: 6px; }
.gift-head { display: flex; align-items: baseline; gap: 12px; }
.gift-name { flex: 1; margin: 0; font-size: 1.08rem; font-weight: 650; overflow-wrap: anywhere; }
.gift-price { font-weight: 650; white-space: nowrap; }
.gift-info { margin: 2px 0 0; white-space: pre-line; overflow-wrap: anywhere; color: var(--ink); }
.gift-link {
  align-self: flex-start;
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; font-weight: 600; text-decoration: none;
}
.gift-actions { display: flex; gap: 8px; margin: 6px 0 0; }
.gift-actions .btn { flex: 1; }

.prio { display: inline-flex; align-items: center; gap: 6px; font-size: 0.88rem; color: var(--muted); }
.prio-dots { letter-spacing: 1px; font-size: 0.7rem; color: var(--accent); }
.prio-dots .off { color: var(--line); }
.prio-3 { color: var(--accent); font-weight: 600; }

/* Bought by someone: visibly out of play. */
.gift-bought { background: var(--bought-bg); border-style: dashed; }
.gift-bought > :not(.bought-tag):not(.gift-actions) { opacity: 0.5; }
.gift-bought .gift-name { text-decoration: line-through; text-decoration-thickness: 1.5px; }
.bought-tag {
  align-self: flex-start;
  display: inline-flex; align-items: center; gap: 6px;
  margin: 0 0 2px; padding: 3px 10px; border-radius: 999px;
  background: var(--line); color: var(--muted); font-size: 0.85rem; font-weight: 600;
}
.bought-mine { background: var(--ok-soft); color: var(--ok); }

.removed { margin-top: 28px; }
.removed > summary {
  min-height: var(--tap); display: flex; align-items: center;
  cursor: pointer; color: var(--muted); font-weight: 600;
}
.removed .list { margin-top: 8px; }
.gift-removed { background: var(--bought-bg); }
.gift-removed > .gift-top, .gift-removed > .gift-info, .gift-removed > .gift-link { opacity: 0.6; }
.removed-reason { margin: 2px 0 0; font-size: 0.92rem; font-style: italic; color: var(--muted); }

/* ---------- forms ---------- */

.stack { display: grid; gap: 16px; }
.login { margin-top: 12vh; }

.field { display: grid; gap: 6px; margin: 0; padding: 0; border: 0; min-width: 0; }
.field > span:first-child, .field legend { font-weight: 600; padding: 0; }
.field small { font-weight: 400; }

input:not([type=checkbox]):not([type=radio]), textarea, select {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1.5px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink);
  font: inherit; font-size: 17px; /* ≥16px avoids iOS zoom on focus */
}
textarea { resize: vertical; line-height: 1.4; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.input-row { display: flex; gap: 8px; }
.input-row .btn { flex: none; }
.input-suffix { position: relative; display: block; }
.input-suffix input { padding-right: 36px; }
.input-suffix span { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }

.check { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; }
.segmented span {
  display: grid; place-items: center; text-align: center;
  min-height: var(--tap); padding: 4px 6px;
  border: 1.5px solid var(--line); border-radius: 10px;
  background: var(--surface); font-size: 0.92rem; font-weight: 600; line-height: 1.2;
}
.segmented input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.segmented input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }

.danger-zone { margin-top: 36px; padding-top: 4px; border-top: 1px solid var(--line); }
.danger-zone .section-title { margin-top: 20px; margin-bottom: 0; }
.danger-zone .hint { margin: 0; }

/* ---------- discussion ---------- */

.discussion { margin-top: 32px; padding-top: 4px; border-top: 1px solid var(--line); scroll-margin-top: 64px; }
.discussion .hint { margin-top: 0; }
.messages { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 8px; }
.msg {
  max-width: 88%;
  padding: 10px 12px; border-radius: 14px 14px 14px 4px;
  background: var(--surface); border: 1px solid var(--line);
}
.msg-mine { margin-left: auto; border-radius: 14px 14px 4px 14px; background: var(--accent-soft); border-color: transparent; }
.msg-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.msg-body { margin: 2px 0 0; white-space: pre-line; overflow-wrap: anywhere; }
.msg form { margin: 4px 0 0; text-align: right; }
.msg-form { gap: 8px; }

.gift { scroll-margin-top: 72px; }

/* ---------- admin ---------- */

.admin-add > summary, .user-summary {
  display: flex; align-items: center; gap: 12px;
  min-height: var(--tap); cursor: pointer; list-style: none;
}
.admin-add > summary::-webkit-details-marker, .user-summary::-webkit-details-marker { display: none; }
.admin-add[open] > summary { margin-bottom: 12px; }
details[open] > .user-summary { margin-bottom: 16px; }
.user-summary .chevron { transform: rotate(90deg); transition: transform 0.15s; }
details[open] > .user-summary .chevron { transform: rotate(-90deg); }
.card details > form + form { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }

@media (min-width: 700px) {
  main { padding-top: 28px; }
}

.removed > summary { gap: 8px; list-style: none; }
.removed > summary::-webkit-details-marker { display: none; }
.removed > summary .chevron { transform: rotate(90deg); transition: transform 0.15s; }
.removed[open] > summary .chevron { transform: rotate(-90deg); }

select {
  appearance: none;
  padding-right: 40px !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23776b63' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 18px;
}

/* ---------- imported lists waiting for an owner ---------- */

.pending { display: grid; gap: 10px; }
.pending-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.pending-head strong { font-size: 1.05rem; }
.pending-teaser { margin: -6px 0 0; color: var(--muted); font-size: 0.92rem; }
.pending-gifts > summary {
  display: inline-flex; align-items: center; gap: 4px; min-height: 36px;
  cursor: pointer; list-style: none; color: var(--accent); font-weight: 600; font-size: 0.92rem;
}
.pending-gifts > summary::-webkit-details-marker { display: none; }
.pending-gifts > summary .chevron { color: inherit; transform: rotate(90deg); transition: transform 0.15s; }
.pending-gifts[open] > summary .chevron { transform: rotate(-90deg); }
.pending-gifts ul { margin: 4px 0 0; padding-left: 18px; font-size: 0.92rem; display: grid; gap: 4px; }
.pending-attach { display: flex; gap: 8px; }
.pending-attach select { flex: 1; min-width: 0; }
.pending-attach .btn { flex: none; }
.pending form:last-child { margin: 0; }

/* ---------- gift pictures ---------- */

.gift-top { display: flex; gap: 12px; align-items: flex-start; }
.gift-top-text { flex: 1; min-width: 0; display: grid; gap: 6px; }
.gift-thumb-link { flex: none; display: block; }
.gift-thumb {
  flex: none; display: block;
  width: 76px; height: 76px; object-fit: contain;
  padding: 4px; border-radius: 10px;
  background: #fff; border: 1px solid var(--line);
}
.gift-bought .gift-thumb, .gift-removed .gift-thumb { filter: grayscale(1); }

.photo-field { gap: 8px; }
.photo-row { display: flex; gap: 12px; align-items: center; }
.photo-pick { position: relative; flex: 1; }
.photo-pick:focus-within { box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- sort ---------- */

.sort-bar { display: flex; align-items: center; gap: 6px; margin: 0 0 12px; }
.sort-bar .muted { margin-right: 2px; white-space: nowrap; }
.sort-bar a {
  flex: 1; justify-content: center; white-space: nowrap;
  display: inline-flex; align-items: center; min-height: 38px; padding: 0 8px;
  border: 1.5px solid var(--line); border-radius: 999px; background: var(--surface);
  color: var(--ink); text-decoration: none; font-size: 0.92rem; font-weight: 600;
}
.sort-bar a[aria-current] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
