@font-face { font-family: 'Fredoka'; src: url(/fonts/fredoka.woff2) format('woff2'); font-weight: 300 700; font-display: swap; }
@font-face { font-family: 'Mountains of Christmas'; src: url(/fonts/christmas.woff2) format('woff2'); font-weight: 700; font-display: swap; }

:root {
  --night: #0d2620;
  --night-2: #0a1a2b;
  --paper: #fff8ec;
  --paper-2: #f6ead3;
  --ink: #2b1d14;
  --ink-soft: #6b5546;
  --red: #d7263d;
  --red-d: #9e1529;
  --green: #1f7a4d;
  --green-d: #135437;
  --gold: #f4b93a;
  --gold-d: #c98a12;
  --snow: #ffffff;
  --display: 'Mountains of Christmas', 'Fredoka', cursive;
  --body: 'Fredoka', ui-rounded, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --radius: 22px;
  --shadow: 0 6px 0 rgba(0, 0, 0, .18), 0 14px 30px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--night); }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--body);
  font-size: 17px;
  color: var(--paper);
  background:
    radial-gradient(ellipse 120% 60% at 50% 0%, #1d4d3c 0%, transparent 60%),
    linear-gradient(180deg, var(--night) 0%, var(--night-2) 100%) fixed;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }

#snow { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 100; }

.wrap { position: relative; z-index: 1; max-width: 560px; margin: 0 auto; padding: 0 16px calc(110px + env(safe-area-inset-bottom, 0px)); }

/* ---------- header */
.topbar {
  position: sticky; top: 0; z-index: 5;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: linear-gradient(180deg, rgba(13, 38, 32, .96), rgba(13, 38, 32, .82));
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.topbar::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -6px; height: 6px;
  background: repeating-linear-gradient(-45deg, var(--red) 0 10px, var(--snow) 10px 20px);
}
.brand { font-family: var(--display); font-size: 26px; line-height: 1; letter-spacing: .5px; color: var(--gold); text-shadow: 0 2px 0 var(--red-d); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who {
  display: flex; align-items: center; gap: 6px; flex-shrink: 0;
  padding: 6px 12px; border-radius: 999px; background: rgba(255, 255, 255, .1);
  font-weight: 600; font-size: 15px;
}

h1, h2, .display { font-family: var(--display); font-weight: 700; letter-spacing: .3px; }
h1 { font-size: clamp(38px, 11vw, 56px); line-height: 1; margin: 0; color: var(--gold); text-shadow: 0 3px 0 var(--red-d), 0 8px 24px rgba(0, 0, 0, .35); }
h2 { font-size: 32px; line-height: 1.05; margin: 0 0 6px; color: var(--paper); }
.lede { color: rgba(255, 248, 236, .78); margin: 6px 0 0; line-height: 1.4; }
.muted { color: var(--ink-soft); }
.small { font-size: 14px; }

/* ---------- cards */
.card {
  background: var(--paper); color: var(--ink);
  border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow);
  position: relative;
}
.card + .card { margin-top: 16px; }
.section { margin-top: 26px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 0 4px 10px; }
.section-title h2 { margin: 0; }
.section-title .count { color: var(--gold); font-weight: 600; font-size: 15px; }

/* ---------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 22px; border-radius: 999px;
  font-weight: 600; font-size: 18px; letter-spacing: .2px;
  background: var(--red); color: var(--snow);
  box-shadow: 0 5px 0 var(--red-d), 0 10px 18px rgba(0, 0, 0, .25);
  transition: transform .08s ease, box-shadow .08s ease, filter .15s;
  user-select: none; -webkit-user-select: none;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--red-d), 0 4px 10px rgba(0, 0, 0, .2); }
.btn:disabled { filter: grayscale(.7) opacity(.6); pointer-events: none; }
.btn.green { background: var(--green); box-shadow: 0 5px 0 var(--green-d), 0 10px 18px rgba(0, 0, 0, .25); }
.btn.green:active { box-shadow: 0 1px 0 var(--green-d); }
.btn.gold { background: var(--gold); color: var(--ink); box-shadow: 0 5px 0 var(--gold-d), 0 10px 18px rgba(0, 0, 0, .25); }
.btn.gold:active { box-shadow: 0 1px 0 var(--gold-d); }
.btn.ghost { background: rgba(255, 255, 255, .1); color: var(--paper); box-shadow: none; }
.btn.ghost:active { transform: scale(.97); }
.btn.paper { background: var(--paper-2); color: var(--ink); box-shadow: 0 4px 0 #d9c7a5; }
.btn.small { min-height: 40px; padding: 0 16px; font-size: 15px; }
.btn.block { width: 100%; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--paper-2); color: var(--ink); font-size: 18px; flex-shrink: 0; }
.icon-btn:active { transform: scale(.92); }

.field {
  width: 100%; min-height: 54px; padding: 0 18px; border-radius: 16px;
  border: 3px solid transparent; background: var(--paper-2); color: var(--ink);
  font-size: 18px; outline: none; transition: border-color .15s;
}
.field:focus { border-color: var(--gold); }
.field::placeholder { color: #a8927e; }
label.lbl { display: block; font-weight: 600; font-size: 14px; color: var(--ink-soft); margin: 12px 4px 6px; }

/* ---------- crisp thumbnail */
.packet {
  aspect-ratio: 1; border-radius: 16px; overflow: hidden; background: #fff;
  display: grid; place-items: center; flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06);
}
.packet img { width: 100%; height: 100%; object-fit: contain; }
.packet.none { background: repeating-linear-gradient(45deg, #fbe7c4 0 12px, #f8dcae 12px 24px); font-size: 42%; }
.packet.none span { font-size: 2.2em; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .15)); }

/* ---------- crisp rows */
.crisp-row { display: flex; align-items: center; gap: 14px; padding: 10px 0; }
.crisp-row + .crisp-row { border-top: 2px dashed #ecdcbf; }
.crisp-row .packet { width: 64px; }
.crisp-row .meta { flex: 1; min-width: 0; }
.crisp-row .name { font-weight: 600; line-height: 1.2; }
.crisp-row .sub { font-size: 14px; color: var(--ink-soft); margin-top: 2px; }

/* ---------- toast */
#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 24px); z-index: 200;
  transform: translate(-50%, 140%); transition: transform .3s cubic-bezier(.2, 1.4, .4, 1);
  padding: 12px 20px; border-radius: 999px; background: var(--ink); color: var(--paper);
  font-weight: 600; box-shadow: var(--shadow); max-width: calc(100vw - 32px); text-align: center;
}
#toast.show { transform: translate(-50%, 0); }
#toast.bad { background: var(--red-d); }

/* ---------- bottom sheet */
.sheet-back { position: fixed; inset: 0; z-index: 50; background: rgba(5, 15, 12, .6); opacity: 0; transition: opacity .25s; }
.sheet-back.open { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  max-height: 92dvh; display: flex; flex-direction: column;
  background: var(--paper); color: var(--ink);
  border-radius: 28px 28px 0 0; box-shadow: 0 -10px 40px rgba(0, 0, 0, .35);
  transform: translateY(105%); transition: transform .32s cubic-bezier(.2, 1, .3, 1);
  max-width: 640px; margin: 0 auto;
}
.sheet.open { transform: translateY(0); }
.sheet-head { padding: 10px 18px 8px; display: flex; align-items: center; gap: 10px; }
.sheet-head::before { content: ''; position: absolute; top: 8px; left: 50%; width: 44px; height: 5px; margin-left: -22px; border-radius: 9px; background: #e2cfac; }
.sheet-head h2 { color: var(--red); flex: 1; margin: 12px 0 0; font-size: 30px; }
.sheet-body { overflow-y: auto; padding: 4px 18px calc(env(safe-area-inset-bottom, 0px) + 22px); -webkit-overflow-scrolling: touch; }

.results-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
.result {
  text-align: left; background: #fff; border-radius: 18px; padding: 10px; color: var(--ink);
  box-shadow: 0 3px 0 #ead9b8; transition: transform .1s;
}
.result:active { transform: scale(.96); }
.result .packet { width: 100%; margin-bottom: 8px; }
.result .name { font-weight: 600; font-size: 15px; line-height: 1.2; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.result .sub { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }
.empty-note { text-align: center; color: var(--ink-soft); padding: 22px 8px 6px; line-height: 1.4; }
.spinner { width: 36px; height: 36px; margin: 26px auto; border-radius: 50%; border: 5px solid #ead9b8; border-top-color: var(--red); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- animations */
.pop-in { animation: popIn .45s cubic-bezier(.2, 1.5, .4, 1) both; animation-delay: var(--d, 0s); }
@keyframes popIn { from { opacity: 0; transform: translateY(16px) scale(.94); } to { opacity: 1; transform: none; } }
.wiggle { animation: wiggle 2.4s ease-in-out infinite; display: inline-block; }
@keyframes wiggle { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(6deg); } }
.bob { animation: bob 3s ease-in-out infinite; display: inline-block; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
