*,
*::before,
*::after {
  box-sizing: border-box;
}

/* ---------- Theme tokens ----------
   Dark only, borrowed from FRIFT: same plate red, same Barlow pair. Gold is the ribbon. */

:root {
  --plate: #e5322d;
  --plate-deep: #ba241f;
  --gold: #f5c542;
  --gold-deep: #c99a1f;
  --mint: #7be0a8;

  --display: 'Barlow Condensed', 'Arial Narrow', Arial, sans-serif;
  --text-font: 'Barlow', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  --radius-panel: 14px;
  --radius-control: 10px;

  --page: #0d0f12;
  --panel: #16191e;
  --panel-border: #262b33;
  --raised: #232830;
  --text: #eceef0;
  --text-2: #a3aab3;
  --text-3: #6b737d;
  --rule: #2a2f37;
  --focus: #7db1ff;

  color-scheme: dark;
}

html {
  -webkit-text-size-adjust: 100%;
  background: var(--page);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% -10%, rgba(229, 50, 45, 0.22), transparent 55%),
    var(--page);
  color: var(--text);
  font-family: var(--text-font);
  font-size: 16px;
  line-height: 1.4;
  overflow-x: hidden;
}

button {
  font: inherit;
  color: inherit;
}

h1,
h2,
h3,
p,
ol {
  margin: 0;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

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

.page {
  display: grid;
  gap: 18px;
  max-width: 480px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
}

/* ---------- Header ---------- */

.head {
  text-align: center;
}

.wordmark {
  display: grid;
  font-family: var(--display);
  font-style: italic;
  font-weight: 800;
  font-size: clamp(3rem, 15vw, 4.2rem);
  line-height: 0.82;
  letter-spacing: -0.01em;
  text-transform: uppercase;
  color: var(--plate);
}

.wordmark em {
  font-style: italic;
  padding-right: 0.08em; /* italic overhang */
}

.wordmark em:last-child {
  color: var(--text);
}

.wordmark.has-name em:first-child {
  font-size: 0.62em;
  margin-bottom: 0.08em;
}

.tagline {
  margin-top: 8px;
  color: var(--text-2);
  font-size: 0.95rem;
}

/* ---------- Hero: the present itself ---------- */

.hero {
  display: grid;
  justify-items: center;
  gap: 4px;
  text-align: center;
}

.greeting {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.7rem;
  line-height: 1.05;
  letter-spacing: 0.01em;
}

.gift {
  position: relative;
  width: min(240px, 64vw);
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.gift svg {
  width: 100%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(0 18px 24px rgba(0, 0, 0, 0.55));
}

.box {
  fill: var(--plate);
}
.lid {
  fill: var(--plate-deep);
}
.box-shadow {
  fill: rgba(0, 0, 0, 0.18);
}
.ribbon,
.bow {
  fill: var(--gold);
}
.bow-knot {
  fill: var(--gold-deep);
}
.ticket {
  fill: var(--gold);
  stroke: var(--gold-deep);
  stroke-width: 3;
  stroke-dasharray: 6 5;
}
.ticket-text {
  font-family: var(--display);
  font-weight: 800;
  font-style: italic;
  font-size: 34px;
  fill: #1a1408;
}

.gift-lid,
.gift-inside {
  transform-box: view-box;
  transition: transform 700ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.gift-lid {
  transform-origin: 30px 80px;
}
.gift-inside {
  transform: translateY(40px);
}

/* Waiting: a nervous little wiggle every few seconds. */
.status-waiting .gift svg,
.status-before .gift svg {
  animation: wiggle 4s ease-in-out infinite;
  transform-origin: 50% 90%;
}

.gift.is-shaking svg {
  animation: shake 600ms ease-in-out;
}

/* Delivered: the lid flips off and the voucher pops out. */
.status-delivered .gift-lid {
  transform: translate(-30px, -14px) rotate(-20deg);
}
.status-delivered .gift-inside {
  transform: translateY(-20px);
}
.status-delivered .gift svg {
  animation: bob 2.6s ease-in-out infinite;
}

/* Run out: the present goes grey and sad. */
.status-zero .gift svg {
  filter: grayscale(1) brightness(0.6) drop-shadow(0 18px 24px rgba(0, 0, 0, 0.55));
  transform: rotate(-6deg) translateY(8px);
}

.gift-hint {
  position: absolute;
  right: -6px;
  top: 14%;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--gold);
  color: #1a1408;
  font-family: var(--display);
  font-weight: 700;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transform: rotate(10deg);
  animation: pulse 1.8s ease-in-out infinite;
}

.toast {
  min-height: 1.5em;
  color: var(--gold);
  font-weight: 600;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 200ms, transform 200ms;
}
.toast.is-on {
  opacity: 1;
  transform: none;
}

/* ---------- Voucher ---------- */

.voucher {
  --notch: 14px;
  position: relative;
  padding: 18px 20px 16px;
  border-radius: var(--radius-panel);
  background:
    radial-gradient(circle at 0 58%, var(--page) var(--notch), transparent calc(var(--notch) + 0.5px)),
    radial-gradient(circle at 100% 58%, var(--page) var(--notch), transparent calc(var(--notch) + 0.5px)),
    linear-gradient(135deg, #2a1312, #1b0d0c 60%, #241a08);
  border: 1px solid #4a1e1b;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.voucher::after {
  /* the perforation line between the notches */
  content: '';
  position: absolute;
  left: calc(var(--notch) + 6px);
  right: calc(var(--notch) + 6px);
  top: 58%;
  border-top: 2px dashed rgba(245, 197, 66, 0.25);
}

.voucher-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.voucher-label {
  font-family: var(--display);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.95rem;
  color: var(--gold);
}

.voucher-stamp {
  padding: 2px 8px;
  border: 2px solid currentColor;
  border-radius: 6px;
  font-family: var(--display);
  font-weight: 800;
  font-style: italic;
  text-transform: uppercase;
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  color: var(--plate);
  transform: rotate(-6deg);
}
.status-delivered .voucher-stamp {
  color: var(--mint);
}
.status-zero .voucher-stamp {
  color: var(--text-3);
}

.voucher-value {
  font-family: var(--display);
  font-style: italic;
  font-weight: 800;
  font-size: clamp(5.5rem, 30vw, 7.5rem);
  line-height: 0.9;
  padding: 6px 0 22px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.voucher-value .pound {
  font-size: 0.55em;
  vertical-align: 0.6em;
  margin-right: 0.04em;
  color: var(--gold);
}

.voucher-value.is-dropping {
  animation: thud 140ms ease-out;
}

.status-delivered .voucher-value {
  color: var(--mint);
}
.status-zero .voucher-value {
  color: var(--text-3);
  text-decoration: line-through;
  text-decoration-color: var(--plate);
  text-decoration-thickness: 6px;
}

.meter {
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--plate), var(--gold));
  transition: width 140ms linear;
}

.voucher-next {
  margin-top: 10px;
  color: var(--text-2);
  font-size: 0.95rem;
}

.voucher-next strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.countdown {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: 0.03em;
  color: var(--plate) !important;
}

/* ---------- Quip and stats ---------- */

.quip {
  padding: 12px 14px;
  background: var(--raised);
  border-left: 3px solid var(--plate);
  border-radius: var(--radius-control);
  font-size: 1.02rem;
  font-weight: 500;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.stat {
  display: grid;
  justify-items: center;
  padding: 12px 6px 10px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-control);
  text-align: center;
}

.stat-num {
  font-family: var(--display);
  font-weight: 800;
  font-style: italic;
  font-size: 2.1rem;
  line-height: 1;
}

.stat-num.lost {
  color: var(--plate);
}

.stat-label {
  margin-top: 4px;
  color: var(--text-2);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.primary {
  width: 100%;
  min-height: 52px;
  padding: 12px 16px;
  border: 0;
  border-radius: var(--radius-control);
  background: var(--plate);
  color: #fff;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--plate-deep);
  transition: transform 80ms, box-shadow 80ms;
}

.primary:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--plate-deep);
}

/* ---------- Timeline ---------- */

.timeline-wrap {
  padding: 16px 14px 8px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-panel);
}

.section-title {
  margin-bottom: 12px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.4rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.timeline {
  list-style: none;
  padding: 0;
  position: relative;
}

.timeline::before {
  /* the rail */
  content: '';
  position: absolute;
  left: 11px;
  top: 12px;
  bottom: 12px;
  width: 2px;
  background: var(--rule);
}

.tl {
  position: relative;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 7px 0;
}

.tl-dot {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--panel);
  border: 2px solid var(--rule);
  font-size: 0.75rem;
}

.tl-date {
  display: grid;
  line-height: 1.15;
}

.tl-day {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.1rem;
}

.tl-note {
  color: var(--text-2);
  font-size: 0.82rem;
}

.tl-value {
  font-family: var(--display);
  font-weight: 800;
  font-style: italic;
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums;
}

.tl.lost .tl-dot {
  border-color: var(--plate);
  background: var(--plate);
}
.tl.lost .tl-value {
  color: var(--text-3);
  text-decoration: line-through;
  text-decoration-color: var(--plate);
  text-decoration-thickness: 2px;
}
.tl.lost .tl-day {
  color: var(--text-2);
}

.tl.today {
  margin: 4px -8px;
  padding: 10px 8px;
  border-radius: var(--radius-control);
  background: rgba(229, 50, 45, 0.14);
  box-shadow: inset 0 0 0 1px rgba(229, 50, 45, 0.5);
}
.tl.today .tl-dot {
  border-color: var(--gold);
  background: var(--gold);
  animation: ping 1.6s ease-out infinite;
}
.tl.today .tl-value {
  color: var(--gold);
  font-size: 1.9rem;
}
.tl.today .tl-note {
  color: var(--gold);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.tl.future .tl-day,
.tl.future .tl-value {
  color: var(--text-2);
}

.tl.handed {
  margin: 4px -8px;
  padding: 10px 8px;
  border-radius: var(--radius-control);
  background: rgba(123, 224, 168, 0.12);
  box-shadow: inset 0 0 0 1px rgba(123, 224, 168, 0.45);
}
.tl.handed .tl-dot {
  border-color: var(--mint);
  background: var(--mint);
}
.tl.handed .tl-value,
.tl.handed .tl-note {
  color: var(--mint);
}

.tl.saved {
  opacity: 0.45;
}
.tl.saved .tl-dot {
  border-color: var(--mint);
}

.tl.zero:not(.saved) .tl-value {
  color: var(--plate);
}

.foot {
  color: var(--text-3);
  font-size: 0.85rem;
  text-align: center;
}

/* ---------- Motion ---------- */

@keyframes wiggle {
  0%, 82%, 100% { transform: rotate(0); }
  85% { transform: rotate(-5deg); }
  88% { transform: rotate(5deg); }
  91% { transform: rotate(-3deg); }
  94% { transform: rotate(2deg); }
}

@keyframes shake {
  0%, 100% { transform: translate(0, 0) rotate(0); }
  15% { transform: translate(-8px, -4px) rotate(-8deg); }
  30% { transform: translate(8px, -8px) rotate(8deg); }
  45% { transform: translate(-6px, -2px) rotate(-6deg); }
  60% { transform: translate(6px, -4px) rotate(5deg); }
  75% { transform: translate(-3px, 0) rotate(-2deg); }
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes pulse {
  0%, 100% { transform: rotate(10deg) scale(1); }
  50% { transform: rotate(10deg) scale(1.1); }
}

@keyframes thud {
  0% { transform: translateY(-3px) scale(1.03); }
  100% { transform: none; }
}

@keyframes ping {
  0% { box-shadow: 0 0 0 0 rgba(245, 197, 66, 0.7); }
  100% { box-shadow: 0 0 0 12px rgba(245, 197, 66, 0); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* Room for the flipped-open lid so the bow doesn't sit on the greeting. */
.status-delivered .gift {
  margin-top: 34px;
}
