:root {
  --red: #b3202a;
  --red-dark: #8c1820;
  --green: #165b33;
  --green-dark: #0f4024;
  --gold: #f2c14e;
  --snow: #fffaf5;
  --ink: #2b1d1a;
  --muted: #6b5b57;
  --card: #ffffff;
  --line: #eadfd8;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(60, 20, 10, .07);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--snow);
  line-height: 1.45;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--green); }
h1, h2, h3 { line-height: 1.2; }
h1 { font-size: 1.6rem; margin: .4rem 0; }
h2 { font-size: 1.15rem; color: var(--green); margin: 1.4rem 0 .7rem; }
h3 { font-size: 1rem; margin: .9rem 0 .45rem; }
.festive { font-family: "Mountains of Christmas", Georgia, serif; color: var(--red); font-size: 2.1rem; letter-spacing: .5px; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.mt { margin-top: .9rem; }
.center { text-align: center; }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .65rem 1rem;
  padding-top: max(.65rem, env(safe-area-inset-top));
  background: linear-gradient(135deg, var(--red), var(--red-dark));
  color: #fff;
  overflow: hidden;
}
.topbar::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .55;
  background-image:
    radial-gradient(2px 2px at 20px 15px, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 80px 40px, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 140px 25px, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 190px 5px, #fff 50%, transparent 51%);
  background-size: 210px 60px;
  animation: snow 9s linear infinite;
}
@keyframes snow { from { background-position: 0 0; } to { background-position: 30px 60px; } }
@media (prefers-reduced-motion: reduce) { .topbar::before { animation: none; } }
.brand {
  position: relative; color: #fff; text-decoration: none;
  font-family: "Mountains of Christmas", Georgia, serif; font-weight: 700; font-size: 1.45rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.userbox { position: relative; display: flex; align-items: center; gap: .5rem; margin: 0; flex-shrink: 0; }
.who { font-size: .9rem; opacity: .9; max-width: 8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill {
  background: transparent; border: 1px solid rgba(255,255,255,.6); color: #fff;
  border-radius: 999px; padding: .35rem .8rem; font: inherit; font-size: .85rem; cursor: pointer; min-height: 36px;
}
.garland {
  height: 7px;
  background: repeating-linear-gradient(90deg,
    var(--green) 0 20px, var(--gold) 20px 26px, var(--green) 26px 46px, var(--red) 46px 52px);
}
@media (max-width: 420px) { .who { display: none; } .brand { font-size: 1.25rem; } }

.container { width: 100%; max-width: 960px; margin: 0 auto; padding: 1rem; flex: 1; }
footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 1.5rem 1rem calc(1.5rem + env(safe-area-inset-bottom)); }

/* ---------- building blocks ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin: 1rem 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  min-height: 44px; padding: .55rem 1.1rem;
  border-radius: 999px; border: 2px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  transition: transform .05s, background .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .6; cursor: progress; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dark); }
.btn-red { background: var(--red); color: #fff; }
.btn-red:hover { background: var(--red-dark); }
.btn-ghost { background: transparent; color: var(--green); border-color: var(--green); }
.btn-ghost.danger { color: var(--red); border-color: var(--red); }
.btn-small { min-height: 40px; padding: .3rem .85rem; font-size: .9rem; }
.btn-block { width: 100%; }
.btn-google { background: #fff; color: #3c4043; border: 1px solid #dadce0; }
.btn-google:hover { background: #f8f9fa; }

input, textarea {
  width: 100%; font: inherit; font-size: 16px; /* 16px stops iOS zooming */
  padding: .6rem .75rem; border: 1px solid #d8ccc5; border-radius: 10px;
  background: #fff; color: var(--ink);
}
input[type=file] { padding: .5rem; background: #fffdfb; }
input:focus, textarea:focus { outline: 2px solid var(--gold); border-color: var(--gold); }
textarea { resize: vertical; }
label { display: block; font-weight: 600; margin: .75rem 0 .3rem; font-size: .95rem; }
label input, label textarea { margin-top: .3rem; font-weight: 400; }

.alert { background: #fde8e8; border: 1px solid #f3b4b4; color: var(--red-dark); padding: .65rem .9rem; border-radius: 10px; margin: .75rem 0; }
.notice { background: #eef7f0; border: 1px solid #b9dcc4; color: var(--green-dark); padding: .5rem .8rem; border-radius: 10px; }
.empty { color: var(--muted); text-align: center; padding: 1.2rem; border: 2px dashed var(--line); border-radius: var(--radius); margin: .5rem 0; }

summary { cursor: pointer; font-weight: 700; color: var(--green); min-height: 40px; display: flex; align-items: center; list-style: none; }
summary::-webkit-details-marker { display: none; }
summary::after { content: "▾"; margin-left: auto; transition: transform .2s; }
details[open] > summary::after { transform: rotate(180deg); }

.form-actions { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-top: .9rem; }
.htmx-indicator { display: none; }
.htmx-request.htmx-indicator, .htmx-request .htmx-indicator { display: inline; }

/* ---------- auth ---------- */
.auth-wrap { display: flex; justify-content: center; padding-top: .5rem; }
.auth-card { width: 100%; max-width: 420px; }
.divider { display: flex; align-items: center; gap: .6rem; color: var(--muted); margin: 1rem 0 .25rem; font-size: .85rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
details.signup { margin-top: 1.1rem; border-top: 1px solid var(--line); padding-top: .6rem; }

/* ---------- home ---------- */
.hero { margin: .25rem 0 .5rem; }
.cards { display: grid; grid-template-columns: 1fr; gap: .75rem; }
@media (min-width: 600px) { .cards { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) { .cards { grid-template-columns: repeat(3, 1fr); } }
.list-card {
  display: block; background: #fff; border: 1px solid var(--line); border-left: 6px solid var(--red);
  border-radius: var(--radius); padding: .9rem 1rem; text-decoration: none; color: var(--ink); box-shadow: var(--shadow);
  transition: transform .1s, box-shadow .1s;
}
.list-card:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(60,20,10,.12); }
.list-card.mine { border-left-color: var(--green); }
.lc-title { font-weight: 700; font-size: 1.05rem; }
.lc-meta { color: var(--muted); font-size: .88rem; margin-top: .2rem; }
.avail { color: var(--green); font-weight: 700; }
.progress { height: 6px; background: #f1e6df; border-radius: 999px; margin-top: .6rem; overflow: hidden; }
.progress span { display: block; height: 100%; background: linear-gradient(90deg, var(--red), var(--gold)); }
.owner-group h3 { color: var(--red); }
.create-form { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .5rem; }
.create-form input { flex: 1 1 220px; }
.create-card h2 { margin-top: .2rem; }

/* ---------- list page ---------- */
.crumbs a { text-decoration: none; font-weight: 600; display: inline-block; padding: .3rem 0; }
.list-head .festive { margin-bottom: .1rem; }
.list-head p { margin-top: .2rem; }
.add-card summary, .settings summary, .create-card summary { font-size: 1.05rem; }
.items-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.count { display: inline-block; background: var(--gold); color: var(--ink); border-radius: 999px; padding: 0 .55rem; font-size: .85rem; vertical-align: middle; }
summary .count { margin-left: .4rem; }
.live { font-size: .8rem; color: var(--green); display: inline-flex; align-items: center; gap: .3rem; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #2ea44f; animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

.item-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .6rem; }
.item {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem .9rem; box-shadow: var(--shadow);
}
.item-main { flex: 1 1 160px; min-width: 0; }
.item-name { font-weight: 600; font-size: 1.05rem; overflow-wrap: anywhere; }
.item-name a { color: var(--ink); text-decoration-color: var(--gold); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.item-meta { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .3rem; align-items: center; }
.chip { font-size: .78rem; background: #f4efe9; border-radius: 999px; padding: .12rem .55rem; color: var(--muted); text-decoration: none; }
.notes { font-size: .88rem; color: var(--muted); }
.item-actions { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.item.taken { opacity: .6; background: #f7f3ef; box-shadow: none; }
.item.taken .item-name { text-decoration: line-through; text-decoration-color: rgba(0,0,0,.35); }
.item.mine { border: 2px solid var(--gold); background: #fffbea; }
.badge { font-size: .85rem; padding: .3rem .7rem; border-radius: 999px; background: #ede6df; color: var(--muted); }
.badge-gold { background: var(--gold); color: var(--ink); font-weight: 600; }
@media (max-width: 520px) {
  .item-actions { width: 100%; }
  .item-actions .btn-primary { flex: 1; }
}

.edit-form, .input-row { display: grid; grid-template-columns: 1fr; gap: .45rem; width: 100%; }
.input-row { border: 1px solid var(--line); border-radius: 10px; padding: .6rem; margin: 0 0 .5rem; background: #fffdfb; }
.btn-x { border: none; background: #f8e3e3; color: var(--red); border-radius: 8px; min-height: 40px; min-width: 44px; cursor: pointer; font-size: 1rem; }
@media (min-width: 760px) {
  .input-row { grid-template-columns: 2fr 2fr 1.5fr .8fr auto; align-items: center; }
  .edit-form { grid-template-columns: 2fr 2fr 1.5fr .8fr; }
  .edit-form .row-actions { grid-column: 1 / -1; }
}
.row-actions { display: flex; gap: .4rem; }
.review h3 { margin-top: 0; color: var(--red); }

/* ---------- product pictures ---------- */
.thumb {
  flex: 0 0 64px; width: 64px; height: 64px; border-radius: 12px; overflow: hidden;
  background: #fff; border: 1px solid var(--line); display: grid; place-items: center;
}
.thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.thumb.noimg { background: repeating-linear-gradient(45deg, #fdf3e7 0 8px, #fbeadb 8px 16px); }
.thumb.noimg::after { content: "🎁"; font-size: 1.6rem; }
.item.taken .thumb { filter: grayscale(.8); }
.input-row .thumb { width: 48px; height: 48px; flex-basis: 48px; }
.pic-field { display: flex; align-items: center; gap: .6rem; }
.pic-field .thumb { width: 44px; height: 44px; flex-basis: 44px; }
@media (min-width: 760px) {
  .input-row { grid-template-columns: 48px 1.6fr 1.6fr 1.2fr .7fr 1.2fr auto; }
  .edit-form .pic-field { grid-column: 1 / -1; }
}

/* ---------- Santa's workshop loader ---------- */
.elf-loader {
  position: relative; overflow: hidden; margin-top: 1rem; padding: 1rem 1rem 1.1rem;
  border-radius: var(--radius); color: #fff;
  background: radial-gradient(ellipse at top, #1f7a45, var(--green-dark) 70%);
  box-shadow: inset 0 -26px 0 -10px rgba(255,255,255,.9), var(--shadow); /* snowbank */
}
.elf-loader::before { /* falling snow */
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .7;
  background-image:
    radial-gradient(2px 2px at 10% 20%, #fff 50%, transparent 51%),
    radial-gradient(2.5px 2.5px at 30% 60%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 55% 30%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 75% 70%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 90% 15%, #fff 50%, transparent 51%);
  background-size: 180px 140px;
  animation: loaderSnow 7s linear infinite;
}
@keyframes loaderSnow { from { background-position: 0 0; } to { background-position: 40px 140px; } }

.lights { display: flex; justify-content: space-between; margin: -.2rem -.2rem .5rem; position: relative; }
.lights::before { /* the wire */
  content: ""; position: absolute; left: 0; right: 0; top: 2px; height: 2px;
  background: rgba(0,0,0,.35); border-radius: 2px;
}
.lights span {
  position: relative; width: 12px; height: 16px; margin-top: 2px; border-radius: 50% 50% 50% 50% / 40% 40% 60% 60%;
  background: var(--red); box-shadow: 0 0 10px 2px var(--red); animation: twinkle 1.2s ease-in-out infinite;
}
.lights span:nth-child(3n+2) { background: var(--gold); box-shadow: 0 0 10px 2px var(--gold); animation-delay: .4s; }
.lights span:nth-child(3n) { background: #4fd1ff; box-shadow: 0 0 10px 2px #4fd1ff; animation-delay: .8s; }
@keyframes twinkle { 0%, 100% { opacity: 1; } 50% { opacity: .3; box-shadow: none; } }

.sleigh-track { height: 2.2rem; position: relative; }
.sleigh {
  position: absolute; top: 0; left: -6rem; font-size: 1.7rem; white-space: nowrap;
  transform: scaleX(-1); /* face right */
  animation: dash 3.8s linear infinite;
}
@keyframes dash {
  0% { left: -6rem; top: .6rem; }
  25% { top: 0; }
  50% { top: .5rem; }
  75% { top: 0; }
  100% { left: 105%; top: .4rem; }
}
.elf-loader.finished .sleigh { animation-play-state: paused; }

.elf-title { margin: .3rem 0 .6rem; font-family: "Mountains of Christmas", Georgia, serif; font-size: 1.6rem; color: var(--gold); position: relative; }
.elf-steps { list-style: none; margin: 0; padding: 0; position: relative; display: grid; gap: .35rem; }
.elf-steps li {
  background: rgba(255,255,255,.12); border-radius: 10px; padding: .45rem .7rem .45rem 2.1rem;
  position: relative; animation: popIn .3s ease-out; overflow-wrap: anywhere;
}
.elf-steps li::before { position: absolute; left: .65rem; top: .45rem; }
.elf-steps li.active::before { content: "❄"; display: inline-block; animation: spin 1.6s linear infinite; }
.elf-steps li.done { opacity: .8; }
.elf-steps li.done::before { content: "✓"; color: var(--gold); font-weight: 700; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes popIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.elf-quip { position: relative; margin: .8rem 0 0; font-style: italic; color: #fdf5e6; opacity: .9; font-size: .92rem; min-height: 1.3em; }
.elf-quip.fade { animation: popIn .4s ease-out; }
@media (prefers-reduced-motion: reduce) {
  .elf-loader::before, .lights span, .sleigh, .elf-steps li.active::before { animation: none; }
  .sleigh { left: 1rem; }
}

/* ---------- linked (auto-syncing) lists ---------- */
.sources-card summary { font-size: 1.05rem; }
.source-list { list-style: none; margin: .6rem 0; padding: 0; display: grid; gap: .5rem; }
.source {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem;
  border: 1px solid var(--line); border-left: 5px solid var(--gold); border-radius: 12px; padding: .6rem .8rem; background: #fffdf8;
}
.source-main { flex: 1 1 220px; min-width: 0; }
.source-title { font-weight: 700; overflow-wrap: anywhere; }
.source-title a { color: var(--ink); }
.source-error { color: var(--red-dark); margin-top: .2rem; }
.source-actions { display: flex; gap: .4rem; align-items: flex-start; flex-wrap: wrap; }
.source-actions form { margin: 0; }
.unlink { position: relative; }
.unlink > summary { list-style: none; }
.unlink > summary::after { content: none; }
.unlink-menu {
  position: absolute; right: 0; top: calc(100% + .3rem); z-index: 5; display: grid; gap: .35rem; min-width: 15rem;
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: .5rem; box-shadow: 0 6px 20px rgba(0,0,0,.12);
}
.link-form { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .6rem; }
.link-form input { flex: 1 1 260px; }
.chip-synced { background: #fff4d6; color: #7a5a00; }
.notice { margin: .6rem 0; }

/* ---------- family chat ---------- */
.chat-link {
  position: relative; margin-left: auto; flex-shrink: 0;
  display: inline-flex; align-items: center; text-decoration: none;
}
.chat { display: flex; flex-direction: column; padding-bottom: .75rem; }
.chat-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.chat-head h1 { margin: 0; }
.chat-warning { margin: .3rem 0 .6rem; }
.chat-messages {
  display: flex; flex-direction: column; gap: .5rem;
  height: calc(100dvh - 330px); min-height: 260px; overflow-y: auto; overscroll-behavior: contain;
  padding: .6rem; border-radius: 12px; background: var(--snow); border: 1px solid var(--line);
}
.chat-empty { margin: auto; text-align: center; }
.chat-messages:has(.chat-msg) .chat-empty { display: none; }
.chat-msg {
  max-width: min(85%, 560px); align-self: flex-start;
  background: #fff; border: 1px solid var(--line); border-radius: 14px 14px 14px 4px;
  padding: .45rem .7rem; box-shadow: var(--shadow);
}
.chat-msg.mine {
  align-self: flex-end; background: #e9f4ec; border-color: #cfe5d6; border-radius: 14px 14px 4px 14px;
}
.chat-msg.fresh { animation: msg-in .35s ease-out; }
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) { .chat-msg.fresh { animation: none; } }
.chat-meta { display: flex; align-items: baseline; gap: .45rem; font-size: .78rem; color: var(--muted); }
.chat-who { color: var(--red); font-size: .85rem; }
.chat-msg.mine .chat-who { color: var(--green); }
.chat-delete { margin: 0 0 0 auto; }
.linkish {
  background: none; border: 0; padding: 0 .2rem; color: var(--muted); cursor: pointer; font: inherit;
  min-width: 24px; min-height: 24px;
}
.linkish:hover { color: var(--red); }
.chat-body { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: .1rem; }
.chat-form { display: flex; gap: .5rem; align-items: flex-end; margin-top: .6rem; }
.chat-form textarea {
  flex: 1; resize: none; min-height: 44px; max-height: 140px; margin: 0; line-height: 1.35;
}
.chat-form .btn { flex-shrink: 0; }
