:root {
  --pine-950: #08160f;
  --pine-900: #0c1f17;
  --pine-800: #12301f;
  --pine-700: #1b4430;
  --pine-600: #2a5d43;
  --paper: #fbf6ec;
  --paper-2: #f3eadb;
  --cream: #f7f0e3;
  --ink: #2a1d15;
  --muted: #7d6b5a;
  --line: #e6dac6;
  --cranberry: #b8243c;
  --cranberry-dark: #8e1a2d;
  --gold: #d6a548;
  --gold-soft: #f1dfb2;
  --idea: #6b7f99;
  --bought: #2f7d55;
  --wrapped: #b8243c;
  --given: #a77a1f;
  --radius: 18px;
  --display: 'Fraunces', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--sans);
  color: var(--cream);
  background:
    radial-gradient(1200px 600px at 50% -200px, #1f5a3d 0%, transparent 70%),
    radial-gradient(900px 500px at 110% 110%, #3a0f19 0%, transparent 60%),
    var(--pine-900);
  background-attachment: fixed;
}
#snow { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }
#app { position: relative; z-index: 1; max-width: 760px; margin: 0 auto; padding: 0 16px calc(170px + var(--safe-b)); }

button { font: inherit; cursor: pointer; color: inherit; }
input, textarea, select { font: inherit; color: var(--ink); }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- header ---------- */
.top {
  padding: calc(env(safe-area-inset-top, 0px) + 22px) 4px 10px;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
}
.brand { font-family: var(--display); font-weight: 800; font-size: clamp(28px, 7vw, 38px); line-height: 1; letter-spacing: -0.02em; margin: 0; }
.brand .star { color: var(--gold); }
.sub { color: #b9cbbd; font-size: 14px; margin-top: 6px; }
.sub b { color: var(--gold-soft); font-weight: 600; }
.who { text-align: right; font-size: 13px; color: #b9cbbd; }
.who button { background: none; border: 0; color: var(--gold-soft); text-decoration: underline; padding: 4px 0; }

.garland { height: 18px; margin: 4px -16px 14px; background:
  radial-gradient(circle at 10px 6px, var(--cranberry) 4px, transparent 5px) 0 0/60px 18px,
  radial-gradient(circle at 30px 9px, var(--gold) 4px, transparent 5px) 0 0/60px 18px,
  radial-gradient(circle at 50px 6px, #3fa06c 4px, transparent 5px) 0 0/60px 18px;
  -webkit-mask: linear-gradient(90deg, transparent, #000 10%, #000 90%, transparent);
          mask: linear-gradient(90deg, transparent, #000 10%, #000 90%, transparent);
  opacity: .9;
}

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.stat { background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.09); border-radius: 14px; padding: 10px 12px; }
.stat .n { font-family: var(--display); font-weight: 700; font-size: 22px; color: var(--paper); }
.stat .l { font-size: 12px; color: #a9bfb0; text-transform: uppercase; letter-spacing: .06em; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 6px; background: rgba(0,0,0,.25); padding: 5px; border-radius: 999px; margin-bottom: 18px; }
.tabs button { flex: 1; border: 0; background: transparent; color: #cfe0d4; padding: 10px 8px; border-radius: 999px; font-weight: 600; font-size: 14px; }
.tabs button[aria-selected="true"] { background: var(--paper); color: var(--pine-900); box-shadow: 0 2px 8px rgba(0,0,0,.25); }

.section-title { font-family: var(--display); font-size: 20px; font-weight: 700; margin: 26px 4px 12px; display: flex; align-items: center; gap: 10px; }
.section-title::after { content: ''; flex: 1; height: 1px; background: linear-gradient(90deg, rgba(214,165,72,.6), transparent); }

/* ---------- gift tag cards ---------- */
.tags { display: grid; gap: 16px; }
@media (min-width: 640px) { .tags { grid-template-columns: 1fr 1fr; } }

.tag {
  position: relative;
  background: linear-gradient(180deg, var(--paper), var(--paper-2));
  color: var(--ink);
  border-radius: var(--radius);
  padding: 18px 16px 12px 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,.35), inset 0 0 0 1px rgba(255,255,255,.6);
  overflow: hidden;
}
.tag::before { /* candy-cane trim */
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 6px;
  background: repeating-linear-gradient(-45deg, var(--cranberry) 0 10px, #fff 10px 18px);
  opacity: .85;
}
.tag-head { display: flex; align-items: center; gap: 10px; position: relative; }
.hole { width: 14px; height: 14px; border-radius: 50%; background: var(--pine-900); box-shadow: inset 0 1px 2px rgba(0,0,0,.6), 0 0 0 3px var(--gold-soft); flex: none; }
.tag-name { font-family: var(--display); font-weight: 800; font-size: 24px; margin: 0; letter-spacing: -0.01em; flex: 1; min-width: 0; }
.tag-name small { display: block; font-family: var(--sans); font-weight: 500; font-size: 12px; color: var(--muted); letter-spacing: 0; margin-top: 2px; }
.icon-btn { border: 0; background: rgba(42,29,21,.06); width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: var(--ink); flex: none; }
.icon-btn:hover { background: rgba(42,29,21,.12); }
.shared-with { font-size: 12px; color: var(--muted); margin: 6px 0 0 24px; }
.shared-with .lock { color: var(--cranberry); font-weight: 600; }

.meter { margin: 12px 0 4px; }
.meter-bar { height: 10px; border-radius: 99px; background: #e9dcc7; overflow: hidden; }
.meter-fill { height: 100%; border-radius: 99px;
  background: repeating-linear-gradient(-45deg, var(--cranberry) 0 8px, #fff 8px 14px);
  transition: width .5s ease; }
.meter-fill.over { background: repeating-linear-gradient(-45deg, #e0592a 0 8px, #ffe5d6 8px 14px); }
.meter-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 5px; }

.items { list-style: none; margin: 10px 0 0; padding: 0; }
.item { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px dashed var(--line); }
.item:first-child { border-top: 0; }
.item-main { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 2px 0; color: var(--ink); }
.item-title { font-weight: 600; font-size: 15px; line-height: 1.3; }
.item.given .item-title { text-decoration: line-through; text-decoration-color: rgba(167,122,31,.6); color: var(--muted); }
.item-meta { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; }
.item-meta a { color: var(--pine-600); }
.item-body { flex: 1; min-width: 0; }
.item-notes { font-size: 12.5px; color: #5c4b3c; margin-top: 4px; line-height: 1.4; white-space: pre-line;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.item-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.item-links a { font-size: 12px; font-weight: 600; color: var(--pine-700); background: #e8f0ea; border-radius: 99px;
  padding: 4px 9px; text-decoration: none; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-links a:hover { background: #d6e6da; }
.link-row { display: grid; grid-template-columns: 1fr 36px; gap: 6px; margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px dashed var(--line); }
.link-row input { border: 1.5px solid var(--line); border-radius: 10px; padding: 9px 10px; background: #fff; font-size: 15px; width: 100%; }
.link-row .l-url { grid-column: 1; }
.link-row .icon-btn { grid-column: 2; grid-row: 1 / span 2; align-self: center; }
.secret-badge { color: var(--cranberry); font-weight: 600; }
.chip {
  flex: none; border: 0; border-radius: 99px; padding: 6px 10px; font-size: 12px; font-weight: 700;
  color: #fff; min-width: 84px; text-align: center; letter-spacing: .01em;
}
.chip.idea { background: var(--idea); }
.chip.bought { background: var(--bought); }
.chip.wrapped { background: var(--wrapped); }
.chip.given { background: var(--given); }
button.chip:active { transform: scale(.96); }
.empty { color: var(--muted); font-size: 14px; padding: 10px 0 6px; font-style: italic; }
.add-line { width: 100%; margin-top: 6px; border: 1.5px dashed #d6c6ab; background: transparent; color: var(--muted); border-radius: 12px; padding: 9px; font-weight: 600; font-size: 14px; }
.add-line:hover { color: var(--ink); border-color: var(--muted); }

.new-person { width: 100%; margin-top: 16px; border: 1.5px dashed rgba(241,223,178,.4); background: rgba(255,255,255,.03); color: var(--gold-soft); border-radius: var(--radius); padding: 14px; font-weight: 600; }

/* ---------- quick add dock ---------- */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  padding: 10px 12px calc(12px + var(--safe-b));
  background: linear-gradient(180deg, rgba(8,22,15,0) 0%, rgba(8,22,15,.92) 30%, var(--pine-950) 100%);
}
.dock-inner { max-width: 760px; margin: 0 auto; }
.preview { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; max-height: 32vh; overflow: auto; }
.pv { background: var(--paper); color: var(--ink); border-radius: 12px; padding: 8px 10px; font-size: 13px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; box-shadow: 0 4px 14px rgba(0,0,0,.3); }
.pv b { font-weight: 700; }
.pv .pill { background: var(--paper-2); border-radius: 99px; padding: 2px 8px; font-size: 12px; }
.pv .pill.who { background: var(--pine-700); color: #fff; }
.pv .pill.warn { background: #ffe1d6; color: #8e1a2d; }
.pv select { font-size: 12px; padding: 2px 4px; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.compose { display: flex; gap: 8px; align-items: flex-end; background: var(--paper); border-radius: 22px; padding: 6px 6px 6px 14px; box-shadow: 0 8px 30px rgba(0,0,0,.45), 0 0 0 2px rgba(214,165,72,.35); }
.compose textarea { flex: 1; border: 0; background: transparent; resize: none; padding: 9px 0; font-size: 16px; line-height: 1.35; max-height: 140px; outline: none; }
.compose textarea::placeholder { color: #a8957f; }
.send { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--cranberry); color: #fff; display: grid; place-items: center; }
.send:disabled { background: #cdbca3; }
.hint { font-size: 11.5px; color: #9fb6a6; text-align: center; margin-top: 7px; }

/* ---------- sheet (modal) ---------- */
.scrim { position: fixed; inset: 0; background: rgba(4,12,8,.6); backdrop-filter: blur(3px); z-index: 20; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease; }
@media (min-width: 640px) { .scrim { align-items: center; } }
.sheet { background: var(--paper); color: var(--ink); width: 100%; max-width: 520px; border-radius: 24px 24px 0 0; padding: 20px 18px calc(20px + var(--safe-b)); max-height: 92dvh; overflow: auto; animation: rise .2s ease; }
@media (min-width: 640px) { .sheet { border-radius: 24px; } }
.sheet h2 { font-family: var(--display); font-size: 24px; margin: 0 0 14px; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .05em; }
.field input, .field textarea, .field select { width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 12px; background: #fff; font-size: 16px; }
.field textarea { min-height: 70px; resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seg button { border: 1.5px solid var(--line); background: #fff; border-radius: 12px; padding: 9px 4px; font-size: 13px; font-weight: 600; color: var(--ink); }
.seg button[aria-pressed="true"] { color: #fff; border-color: transparent; }
.seg button[data-s="idea"][aria-pressed="true"] { background: var(--idea); }
.seg button[data-s="bought"][aria-pressed="true"] { background: var(--bought); }
.seg button[data-s="wrapped"][aria-pressed="true"] { background: var(--wrapped); }
.seg button[data-s="given"][aria-pressed="true"] { background: var(--given); }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; background: #fff; border: 1.5px solid var(--line); border-radius: 12px; margin-bottom: 12px; font-size: 14px; }
.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--cranberry); flex: none; }
.check small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.actions { display: flex; gap: 10px; margin-top: 8px; }
.btn { border: 0; border-radius: 14px; padding: 13px 16px; font-weight: 700; font-size: 15px; }
.btn.primary { background: var(--cranberry); color: #fff; flex: 1; }
.btn.primary:hover { background: var(--cranberry-dark); }
.btn.ghost { background: var(--paper-2); color: var(--ink); }
.btn.danger { background: transparent; color: var(--cranberry); border: 1.5px solid #ecc6cd; }
.btn.gold { background: var(--gold); color: var(--pine-950); }
.btn:disabled { opacity: .55; }

/* ---------- panels (elf, settings) ---------- */
.panel { background: linear-gradient(180deg, var(--paper), var(--paper-2)); color: var(--ink); border-radius: var(--radius); padding: 18px 16px; box-shadow: 0 10px 30px rgba(0,0,0,.35); margin-bottom: 16px; }
.panel h3 { font-family: var(--display); font-size: 20px; margin: 0 0 6px; }
.panel p { margin: 0 0 12px; color: #5c4b3c; font-size: 14px; line-height: 1.5; }
.panel code { background: var(--paper-2); padding: 1px 6px; border-radius: 6px; font-size: 13px; }
.status-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; background: #c9b9a0; }
.status-dot.on { background: #2f9d63; box-shadow: 0 0 0 3px rgba(47,157,99,.2); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.chips button { border: 1.5px solid var(--line); background: #fff; border-radius: 99px; padding: 7px 12px; font-size: 13px; font-weight: 600; color: var(--ink); }
.chips button:hover { border-color: var(--gold); }
.answer { background: #fff; border: 1.5px solid var(--line); border-radius: 14px; padding: 12px 14px; font-size: 14.5px; line-height: 1.55; margin-top: 12px; white-space: normal; }
.answer ul { padding-left: 20px; margin: 6px 0; }
.answer p { color: var(--ink); margin: 6px 0; }
.loading { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); font-size: 14px; }
.loading i { width: 8px; height: 8px; border-radius: 50%; background: var(--cranberry); animation: bounce 1s infinite; }
.loading i:nth-child(2) { background: var(--gold); animation-delay: .15s; }
.loading i:nth-child(3) { background: var(--bought); animation-delay: .3s; }

/* access matrix */
.matrix-wrap { overflow-x: auto; margin: 0 -4px; }
.matrix { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 14px; }
.matrix th, .matrix td { padding: 8px 6px; text-align: center; border-bottom: 1px dashed var(--line); }
.matrix th:first-child, .matrix td:first-child { text-align: left; position: sticky; left: 0; background: var(--paper); font-weight: 700; }
.matrix thead th { font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.matrix input { width: 22px; height: 22px; accent-color: var(--bought); }
.matrix .self { font-size: 16px; }
.users { list-style: none; padding: 0; margin: 0 0 12px; }
.users li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.users li .nm { flex: 1; font-weight: 600; }
.users li .nm small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.users li button { border: 1.5px solid var(--line); background: #fff; border-radius: 10px; padding: 6px 10px; font-size: 13px; font-weight: 600; color: var(--ink); }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 0; }
.login-card { width: 100%; max-width: 380px; text-align: center; }
.login-card .tree { font-size: 64px; line-height: 1; filter: drop-shadow(0 6px 18px rgba(214,165,72,.35)); }
.login-card h1 { font-family: var(--display); font-size: 40px; font-weight: 800; margin: 10px 0 4px; letter-spacing: -0.02em; }
.login-card p { color: #b9cbbd; margin: 0 0 22px; }
.login-card form { background: var(--paper); border-radius: 22px; padding: 18px; box-shadow: 0 20px 50px rgba(0,0,0,.45); }
.login-card input { width: 100%; border: 1.5px solid var(--line); border-radius: 14px; padding: 14px; font-size: 18px; text-align: center; letter-spacing: .12em; margin-bottom: 12px; }
.login-card .btn { width: 100%; }
.err { color: var(--cranberry); font-size: 14px; margin: 0 0 10px; min-height: 1em; }

.viewer-note { background: rgba(214,165,72,.12); border: 1px solid rgba(214,165,72,.35); color: var(--gold-soft); border-radius: 14px; padding: 10px 14px; font-size: 14px; margin-bottom: 16px; }

#toast { position: fixed; left: 50%; bottom: calc(150px + var(--safe-b)); transform: translateX(-50%) translateY(20px); background: var(--pine-700); color: #fff; padding: 10px 16px; border-radius: 99px; font-weight: 600; font-size: 14px; opacity: 0; transition: .25s; z-index: 40; pointer-events: none; box-shadow: 0 8px 24px rgba(0,0,0,.4); white-space: nowrap; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@keyframes rise { from { transform: translateY(30px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
