:root {
  --bg: #f8f1e6;
  --paper: #fffdf8;
  --ink: #2b1d14;
  --muted: #7a6858;
  --line: #eadfce;
  --red: #a3222b;
  --red-dark: #7e1820;
  --pine: #1f4d3a;
  --gold: #c99a2e;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(43, 29, 20, .06), 0 8px 24px rgba(43, 29, 20, .08);
  --serif: "Fraunces", Georgia, serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --tabs-h: 64px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--red); }

/* soft falling snow in the background */
.snow {
  position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: .5;
  background-image:
    radial-gradient(2px 2px at 20px 30px, #fff, transparent),
    radial-gradient(2px 2px at 120px 80px, #fff, transparent),
    radial-gradient(3px 3px at 200px 150px, #fff, transparent),
    radial-gradient(2px 2px at 300px 40px, #fff, transparent),
    radial-gradient(2px 2px at 60px 200px, #fff, transparent);
  background-size: 340px 240px;
  animation: snow 18s linear infinite;
}
@keyframes snow { to { background-position: 60px 240px; } }
@media (prefers-reduced-motion: reduce) { .snow { animation: none; } }

/* header */
.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--red);
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 14px;
  box-shadow: 0 2px 12px rgba(126, 24, 32, .25);
}
.top-inner { max-width: 560px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.logo { font-size: 28px; }
.top-title { font-family: var(--serif); font-weight: 700; font-size: 20px; line-height: 1.1; }
.top-sub { font-size: 13px; opacity: .85; margin-top: 2px; }

/* main */
.app {
  position: relative; z-index: 1;
  max-width: 560px; margin: 0 auto;
  padding: 18px 16px calc(var(--tabs-h) + env(safe-area-inset-bottom) + 28px);
}
.center-msg { min-height: 50vh; display: grid; place-items: center; text-align: center; color: var(--muted); }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--red);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

h2 { font-family: var(--serif); font-size: 24px; margin: 6px 0 4px; }
.lead { color: var(--muted); margin: 0 0 18px; line-height: 1.45; }

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}

/* buttons */
.btn {
  appearance: none; border: 0; cursor: pointer;
  background: var(--red); color: #fff;
  font-weight: 600; font-size: 16px;
  padding: 13px 20px; border-radius: 999px;
  min-height: 48px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .6; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--red); border: 1.5px solid var(--red); }
.btn.green { background: var(--pine); }
.btn.small { min-height: 38px; padding: 8px 14px; font-size: 14px; }
.linkbtn { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; padding: 8px; font-size: 14px; }

/* scratch card */
.ticket {
  position: relative;
  border-radius: 22px;
  overflow: hidden;
  background:
    repeating-linear-gradient(135deg, rgba(255,255,255,.08) 0 12px, transparent 12px 24px),
    linear-gradient(160deg, var(--pine), #163a2b);
  color: #fff;
  box-shadow: var(--shadow);
  aspect-ratio: 16 / 10;
  min-height: 200px;
  user-select: none; -webkit-user-select: none;
}
.ticket-under {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 20px;
}
.ticket-label { font-size: 13px; letter-spacing: .14em; text-transform: uppercase; opacity: .8; }
.ticket-name {
  font-family: var(--serif); font-weight: 700;
  font-size: clamp(32px, 11vw, 54px); line-height: 1.05;
  margin-top: 8px; color: #ffe9b0; word-break: break-word;
}
.ticket canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  touch-action: none; cursor: grab;
  transition: opacity .6s ease;
}
.ticket canvas.gone { opacity: 0; pointer-events: none; }
.scratch-hint { text-align: center; color: var(--muted); font-size: 14px; margin: 10px 0 0; }

/* wish list items */
.items { display: grid; gap: 10px; }
.item {
  background: var(--paper); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: start;
}
.item-name { font-weight: 600; font-size: 16px; line-height: 1.3; word-break: break-word; }
.item-price { font-weight: 700; color: var(--pine); white-space: nowrap; }
.item-notes { grid-column: 1 / -1; color: var(--muted); font-size: 14px; line-height: 1.4; white-space: pre-wrap; word-break: break-word; }
.item-actions { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.chip-link {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 14px; font-weight: 600; text-decoration: none;
  padding: 6px 12px; border-radius: 999px; background: #f3e7d6; color: var(--red-dark);
  border: 0; cursor: pointer;
}
.chip-link.danger { background: #fbe4e4; color: #9b1c1c; }
.empty { text-align: center; color: var(--muted); padding: 22px 10px; line-height: 1.5; }

/* progress */
.progress-row { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.bar { height: 10px; background: #efe4d3; border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--pine)); border-radius: 99px; transition: width .4s ease; }
.badge { display: inline-block; background: #f3e7d6; color: var(--red-dark); font-weight: 700; font-size: 13px; padding: 4px 10px; border-radius: 99px; }

/* people picker */
.people { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; margin: 0 -2px 6px; scrollbar-width: none; }
.people::-webkit-scrollbar { display: none; }
.person {
  flex: 0 0 auto; border: 1.5px solid var(--line); background: var(--paper);
  padding: 9px 16px; border-radius: 999px; font-weight: 600; cursor: pointer; min-height: 42px;
}
.person[aria-pressed="true"] { background: var(--red); border-color: var(--red); color: #fff; }
.person small { font-weight: 500; opacity: .75; }

/* event */
.detail { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.detail:last-child { border-bottom: 0; }
.detail .di { font-size: 22px; width: 28px; text-align: center; }
.detail .dl { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.detail .dv { font-weight: 600; margin-top: 2px; line-height: 1.4; white-space: pre-wrap; }
.code-pill { font-family: ui-monospace, Menlo, monospace; font-size: 18px; letter-spacing: 3px; font-weight: 700; }

/* forms */
label.f { display: block; font-weight: 600; font-size: 14px; margin: 14px 0 6px; }
label.f .opt { font-weight: 400; color: var(--muted); }
.input {
  width: 100%; border: 1.5px solid var(--line); background: #fff;
  border-radius: 12px; padding: 12px 14px; font-size: 16px; /* 16px stops iPhone zoom */
  outline: none;
}
.input:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(163, 34, 43, .12); }
textarea.input { min-height: 80px; resize: vertical; }
.price-wrap { position: relative; }
.price-wrap span { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.price-wrap .input { padding-left: 28px; }
.help { font-size: 13px; color: var(--muted); margin-top: 6px; }
.form-err { color: #9b1c1c; font-size: 14px; margin-top: 12px; min-height: 1em; }
.code-input { text-align: center; font-family: ui-monospace, Menlo, monospace; font-size: 26px; letter-spacing: 8px; text-transform: uppercase; }

/* bottom sheet */
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(43, 29, 20, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet-panel {
  width: 100%; max-width: 560px; background: var(--paper);
  border-radius: 22px 22px 0 0; padding: 10px 18px calc(env(safe-area-inset-bottom) + 18px);
  max-height: 92vh; overflow-y: auto; animation: up .22s ease;
}
.sheet-grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 10px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }
.sheet-actions .btn { flex: 1; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }

/* tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: rgba(255, 253, 248, .96);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  background: none; border: 0; cursor: pointer; height: var(--tabs-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; font-weight: 600; color: var(--muted);
}
.tabs .ti { font-size: 21px; filter: grayscale(1); opacity: .7; transition: .15s; }
.tabs button[aria-current="page"] { color: var(--red); }
.tabs button[aria-current="page"] .ti { filter: none; opacity: 1; transform: translateY(-1px); }

/* install banner */
.install {
  display: flex; gap: 12px; align-items: center;
  background: #fff7e3; border: 1px solid #f0dca8; border-radius: 14px;
  padding: 12px 14px; margin-bottom: 14px; font-size: 14px; line-height: 1.4;
}
.install .x { margin-left: auto; background: none; border: 0; font-size: 20px; color: var(--muted); cursor: pointer; padding: 4px 6px; }

/* toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 14px);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 999px;
  font-size: 14px; z-index: 30; max-width: calc(100% - 32px); text-align: center;
  box-shadow: 0 6px 20px rgba(0,0,0,.2);
}
.toast.err { background: #9b1c1c; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 22px 0 10px; }
.section-head h3 { font-family: var(--serif); font-size: 19px; margin: 0; }
