/* All Wrapped. One stylesheet; a theme only swaps these colour variables. */

:root, [data-theme="santa"] {
  --bg: #fdf6f0; --surface: #fff; --ink: #3b1f1f; --muted: #7d5c58; --line: #efdcd4; --soft: #fbe9e6;
  --primary: #c8102e; --primary-ink: #fff; --head: #a50d24; --head-ink: #fff; --accent: #f5c542;
}
[data-theme="elf"] {
  --bg: #f1f7f0; --surface: #fff; --ink: #1d3324; --muted: #55705c; --line: #d5e6d6; --soft: #e1f0e2;
  --primary: #1f7a3a; --primary-ink: #fff; --head: #17612d; --head-ink: #fff; --accent: #d4202c;
}
[data-theme="snowman"] {
  --bg: #f3f6fa; --surface: #fff; --ink: #263241; --muted: #5f6f83; --line: #dbe3ec; --soft: #e8edf4;
  --primary: #50677f; --primary-ink: #fff; --head: #fff; --head-ink: #263241; --accent: #a9b6c6;
}
:root {
  --st-idea: #66758c; --st-to-buy: #a86200; --st-bought: #237a49; --st-received: #6047b0; --st-wrapped: #b3102a;
  --danger: #b3102a; --radius: 16px;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 2px 8px rgb(0 0 0 / .04);
}

* { box-sizing: border-box; }
[x-cloak] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
body.has-tabs { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; margin-top: 8px; }
a { color: var(--primary); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Shell */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 4px 12px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--head); color: var(--head-ink); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; font-weight: 800; font-size: 1.25rem; min-height: 44px; }
.brand img { border-radius: 8px; }
.countdown { margin: 0; font-weight: 600; font-size: .95rem; }
main, .years, .foot { max-width: 600px; margin: 0 auto; }
.years { padding: 12px 16px 0; }
.pad { padding: 16px; }
.foot { text-align: center; color: var(--muted); font-size: .85rem; padding: 24px 16px 32px; }

.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 20; display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; max-width: 200px; min-height: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--muted); text-decoration: none; font-size: .8rem; font-weight: 700;
}
.tabs a span { font-size: 1.4rem; line-height: 1; }
.tabs a[aria-current="page"] { color: var(--primary); }

/* Forms and buttons */
label, .label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .9rem; margin: 0; }
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--surface);
  border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; min-height: 48px; width: 100%;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 48px; padding: 0 20px;
  border-radius: 999px; border: 1.5px solid var(--primary); background: var(--surface); color: var(--primary);
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.ghost { border-color: var(--line); color: var(--ink); background: transparent; }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.small { min-height: 40px; padding: 0 14px; font-size: .9rem; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; padding: 4px 0; min-height: 40px; font: inherit; color: var(--primary); text-decoration: underline; cursor: pointer; }
.link:disabled { color: inherit; text-decoration: none; cursor: default; }
.icon {
  width: 44px; height: 44px; flex: none; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 1.1rem; cursor: pointer;
}
.icon.danger { color: var(--danger); }
.icon:disabled { opacity: .35; }
.fab {
  position: fixed; right: max(16px, calc(50vw - 284px)); bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 15;
  width: 64px; height: 64px; border-radius: 50%; border: 0; background: var(--primary); color: var(--primary-ink);
  font-size: 2.2rem; line-height: 1; cursor: pointer; box-shadow: 0 4px 14px rgb(0 0 0 / .25);
}
.has-tabs .fab { bottom: calc(84px + env(safe-area-inset-bottom)); }

/* Layout helpers */
.stack { display: flex; flex-direction: column; gap: 12px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin: 0 0 12px; }
.note { color: var(--muted); font-size: .9rem; margin: 8px 0; }
.error { color: var(--danger); background: #fde8ea; border-radius: 10px; padding: 8px 12px; margin: 0; }
.row-form { display: flex; gap: 8px; }
.hero { text-align: center; padding: 8px 0 16px; }
.hero p { color: var(--muted); margin: 6px 0 0; }
.hero .avatar, .empty .avatar { margin: 0 auto 10px; }
.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.empty p { margin: 0 0 16px; font-size: 1.05rem; }
.big { font-size: 1.8rem; font-weight: 800; margin: 6px 0 8px; }
.big small { font-size: 1rem; font-weight: 500; color: var(--muted); }

/* Lists and rows */
.list { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex; align-items: center; gap: 12px; min-height: 68px; padding: 10px 12px; margin-bottom: 8px;
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); color: inherit; text-decoration: none;
}
li.row[role="button"], a.row { cursor: pointer; }
.row b { display: block; overflow: hidden; text-overflow: ellipsis; }
.list.tight .row { min-height: 56px; padding: 6px 8px; box-shadow: none; border: 1px solid var(--line); }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; color: var(--muted); font-size: .85rem; margin: 2px 0 0; }
.amount { display: flex; flex-direction: column; align-items: flex-end; font-weight: 700; white-space: nowrap; font-size: .95rem; }
.tag { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--soft); color: var(--primary); font-size: .78rem; font-weight: 700; }
.flag { font-size: .78rem; font-weight: 600; color: var(--muted); }
.flag.over { color: var(--danger); }

.bar { display: block; height: 8px; border-radius: 999px; background: var(--soft); overflow: hidden; margin-top: 6px; }
.bar.lg { height: 14px; }
.bar i { display: block; height: 100%; background: var(--primary); border-radius: inherit; }
.bar i.over { background: repeating-linear-gradient(45deg, #b3102a 0 6px, #e8590c 6px 12px); }

/* Avatars */
.avatar {
  width: 52px; height: 52px; flex: none; display: grid; place-items: center; padding: 4px;
  border-radius: 50%; border: 0; background: var(--soft); cursor: inherit;
}
button.avatar { cursor: pointer; }
.avatar svg { width: 100%; height: 100%; }
.avatar.xl { width: 88px; height: 88px; }
.avatar-pick { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.avatar-pick .avatar { width: 100%; height: auto; aspect-ratio: 1; }
.avatar-pick .avatar.on { outline: 3px solid var(--primary); outline-offset: 2px; }

/* Person page */
.person-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 16px; }
.person-head .meta { font-size: .9rem; }
.editable { cursor: pointer; border-bottom: 2px dashed transparent; }
.editable:hover { border-bottom-color: var(--line); }
.pencil { font-size: 1rem; color: var(--muted); }
.btn.wide { width: 100%; margin: 8px 0 72px; }
.name-edit { display: flex; gap: 8px; align-items: center; }
.title-input { font-size: 1.2rem; font-weight: 700; min-width: 0; }
.tag-select {
  width: auto; min-height: 36px; margin-top: 6px; padding: 4px 12px; border: 0; border-radius: 999px;
  background: var(--soft); color: var(--primary); font-size: .85rem; font-weight: 700;
}
.inline-num { width: 120px; min-height: 40px; }
.seg { display: flex; gap: 4px; padding: 4px; margin-bottom: 14px; border-radius: 999px; background: var(--soft); }
.seg button { flex: 1; min-height: 44px; border: 0; border-radius: 999px; background: transparent; color: var(--muted); font: inherit; font-weight: 700; cursor: pointer; }
.seg button[aria-selected="true"] { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }

/* Status colours */
.st-idea { background: var(--st-idea); }
.st-to-buy { background: var(--st-to-buy); }
.st-bought { background: var(--st-bought); }
.st-received { background: var(--st-received); }
.st-wrapped { background: var(--st-wrapped); }
.chip {
  min-height: 40px; min-width: 84px; padding: 0 12px; border: 0; border-radius: 999px; color: #fff;
  font: inherit; font-size: .82rem; font-weight: 700; text-transform: capitalize; cursor: pointer;
}
.chip:disabled { cursor: default; }
.dot { width: 16px; height: 16px; border-radius: 50%; flex: none; }
.status-opt {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px; padding: 0 14px;
  border: 1.5px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink);
  font: inherit; text-transform: capitalize; cursor: pointer;
}
.status-opt.on { border-color: var(--primary); background: var(--soft); font-weight: 700; }

/* Bottom sheets, confirm and toast */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet-wrap.top-layer { z-index: 60; }
.backdrop { position: absolute; inset: 0; background: rgb(0 0 0 / .45); }
.sheet {
  position: relative; width: 100%; max-width: 600px; max-height: 90vh; overflow: auto;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); border-radius: 22px 22px 0 0;
  background: var(--surface); animation: up .2s ease-out;
}
.sheet p { margin: 0; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 70;
  width: max-content; max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 999px; background: var(--ink); color: var(--bg); font-weight: 600; text-align: center;
}

/* Budget */
.pie-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 20px; margin-top: 12px; }
.pie { width: 180px; height: 180px; border-radius: 50%; flex: none; margin: 0 auto; }
.legend { list-style: none; padding: 0; margin: 0; flex: 1; min-width: 160px; }
.legend li { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.legend i { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.legend b { margin-left: auto; }

/* Settings */
.themes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.theme {
  display: flex; flex-direction: column; align-items: center; gap: 6px; min-height: 80px; padding: 10px;
  border: 2px solid var(--line); border-radius: 14px; background: var(--bg); color: var(--ink); font: inherit; font-weight: 700; cursor: pointer;
}
.theme.on { border-color: var(--primary); }
.swatch { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg, var(--primary) 50%, var(--accent) 50%); border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line); }
.invite { background: var(--soft); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.invite .note { margin: 0; }

/* Print one person's list on one clean page */
#print { display: none; }
@media print {
  body { background: #fff; color: #000; padding: 0; font-size: 12pt; }
  body > :not(#print) { display: none !important; }
  #print { display: block; }
  #print h1 { font-size: 20pt; margin-bottom: 4pt; }
  #print h2 { font-size: 14pt; margin: 14pt 0 6pt; }
  #print table { width: 100%; border-collapse: collapse; }
  #print th, #print td { text-align: left; padding: 4pt 6pt; border-bottom: 1px solid #ccc; vertical-align: top; }
  #print td:nth-child(3) { text-transform: capitalize; }
  @page { margin: 15mm; }
}
