:root {
  --paper: #FDF3F5;
  --ink: #3A1B36;
  --ink-soft: #6E4D69;
  --rose: #D94F70;
  --rose-deep: #B83A5B;
  --marigold: #F4A62A;
  --lavender: #C9B8E8;
  --white: #FFFFFF;
  --display: "Young Serif", Georgia, serif;
  --body: "Mukta", system-ui, sans-serif;
  --step--1: .875rem;
  --step-0: 1.0625rem;
  --step-1: 1.3125rem;
  --step-2: 1.625rem;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100svh; background: var(--paper); color: var(--ink);
  font: 400 var(--step-0)/1.55 var(--body);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
:focus-visible { outline: 3px solid var(--marigold); outline-offset: 3px; border-radius: 6px; }
button, input, textarea { font: inherit; color: inherit; }

/* ---------- gate ---------- */
.gate { max-width: 26rem; margin: 0 auto; padding: 14vh 1.5rem 3rem; }
.gate-beads { display: flex; gap: .5rem; margin-bottom: 2.5rem; position: relative; }
.gate-beads::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1.5px; background: var(--lavender); }
.gate-beads span { position: relative; width: 1.1rem; height: 1.1rem; border-radius: 50%; background: var(--paper); border: 1.5px solid var(--lavender); }
.gate-beads span:nth-child(-n+3) { background: var(--rose); border-color: var(--rose); }
.gate-beads span:nth-child(4) { border: 2.5px solid var(--marigold); }
.gate-title { font: 400 2.25rem/1.15 var(--display); margin: 0 0 .6rem; letter-spacing: -.01em; }
.gate-lead { margin: 0 0 2rem; color: var(--ink-soft); }
.gate-form label { display: block; font-weight: 500; margin-bottom: .4rem; }
.gate-form input {
  width: 100%; font-size: 1.5rem; letter-spacing: .35em; padding: .7rem .9rem; border-radius: 14px;
  border: 1.5px solid var(--lavender); background: var(--white);
}
.gate-form input:focus { border-color: var(--rose); outline: none; box-shadow: 0 0 0 4px rgba(217, 79, 112, .18); }
.hint { margin: .5rem 0 0; font-size: var(--step--1); color: var(--ink-soft); }
.error { margin: .75rem 0 0; color: var(--rose-deep); font-weight: 500; }
.gate-form button, .btn {
  margin-top: 1.5rem; width: 100%; padding: .85rem 1rem; border: 0; border-radius: 999px;
  background: var(--rose); color: var(--white); font-weight: 700; font-size: var(--step-0); cursor: pointer;
}
.gate-form button:hover, .btn:hover { background: var(--rose-deep); }
.btn[disabled] { opacity: .55; cursor: wait; }

/* ---------- app: one screen, no page scroll ---------- */
body.is-app { height: 100svh; overflow: hidden; padding: 0; }
.app {
  height: 100svh; max-width: 30rem; margin: 0 auto;
  display: grid; grid-template-rows: auto 1fr auto;
  padding: calc(env(safe-area-inset-top) + 14px) 18px 0;
}

/* countdown */
.top { padding-bottom: 10px; }
.count { display: flex; align-items: center; gap: 14px; }
.count-days {
  font: 400 clamp(3.8rem, 21vw, 5.25rem)/.9 var(--display); color: var(--rose);
  letter-spacing: -.04em; font-variant-numeric: lining-nums;
}
.count-side { display: flex; flex-direction: column; gap: 2px; }
.count-unit { font: 400 1.3rem/1.1 var(--display); }
.count-clock { font-size: .95rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.count-clock b { color: var(--ink); font-weight: 700; }
.progress { margin: 8px 0 0; font-size: .95rem; color: var(--ink-soft); }
.progress b { color: var(--rose-deep); font-weight: 700; }
.is-birthday .count-days { font-size: clamp(2.4rem, 12vw, 3.2rem); letter-spacing: -.02em; }

/* the middle: today's card; only this area scrolls, and only when it must */
.stage {
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  margin: 0 -18px; padding: 4px 18px 18px; scrollbar-width: none;
}
.stage::-webkit-scrollbar { display: none; }

.day-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.day-date { margin: 0; font-weight: 500; }
.day-date small { display: block; font-weight: 400; color: var(--ink-soft); font-size: .85rem; }
.nav { display: flex; gap: 4px; }
.nav button {
  width: 44px; height: 44px; border-radius: 50%; border: 1.5px solid var(--lavender); background: var(--white);
  font-size: 1.25rem; line-height: 1; cursor: pointer; color: var(--ink);
}
.nav button:disabled { opacity: .35; cursor: default; }

/* the envelope */
.envelope {
  position: relative; display: block; width: 100%; aspect-ratio: 5 / 3.6; max-height: 46svh;
  border: 1.5px solid #F2D4DC; border-radius: 18px; background: var(--white); padding: 0; cursor: pointer;
  perspective: 900px; overflow: hidden;
}
.envelope::after { /* lower folds */
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(to top right, #FBE3EA 49.6%, transparent 50%) left bottom / 50% 62% no-repeat,
              linear-gradient(to top left, #FBE3EA 49.6%, transparent 50%) right bottom / 50% 62% no-repeat;
}
.flap {
  position: absolute; inset: 0 0 auto 0; height: 58%; transform-origin: top center; z-index: 2;
  background: #F7D3DE; clip-path: polygon(0 0, 100% 0, 50% 100%); transition: transform .55s cubic-bezier(.3, .7, .2, 1);
}
.seal {
  position: absolute; left: 50%; top: 58%; transform: translate(-50%, -50%); z-index: 3;
  width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #F4A9BB, var(--rose) 55%, var(--rose-deep));
  color: #FFF4F6; font: 400 1.6rem/1 var(--display); box-shadow: 0 3px 0 rgba(122, 30, 58, .25);
  transition: opacity .3s;
}
.envelope-tap {
  position: absolute; left: 0; right: 0; bottom: 14px; z-index: 3; font-weight: 500; color: var(--rose-deep);
}
.envelope.opening .flap { transform: rotateX(178deg); }
.envelope.opening .seal { opacity: 0; }
.envelope-wrap p.hint-below { text-align: center; margin: 10px 0 0; color: var(--ink-soft); font-size: .9rem; }

/* opened day */
.opened { animation: rise .45s ease-out both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.day-note { font: 400 1.4rem/1.38 var(--display); margin: 0 0 18px; text-wrap: pretty; }
.challenge { background: var(--white); border-radius: 18px; padding: 16px; border: 1.5px solid #EEE3F7; }
.challenge h2, .reward h2 { font: 700 1.05rem/1.3 var(--body); margin: 0 0 4px; }
.challenge h2 { color: #6B4FA8; }
.challenge-text { margin: 0 0 12px; }
.challenge textarea, .challenge input {
  width: 100%; padding: 12px 14px; border-radius: 14px; border: 1.5px solid var(--lavender); background: #FCFAFF;
  font-size: 1.0625rem; resize: none;
}
.challenge textarea { min-height: 5.5rem; }
.challenge textarea:focus, .challenge input:focus { border-color: var(--rose); outline: none; box-shadow: 0 0 0 4px rgba(217, 79, 112, .18); }
.challenge .btn { margin-top: 12px; }
.your-reply { margin: 0; padding: 10px 14px; background: #FCFAFF; border-radius: 12px; white-space: pre-wrap; }
.err-inline { color: var(--rose-deep); font-weight: 500; margin: 10px 0 0; }
.err-inline:empty { display: none; }

/* the reward: a scratch card */
.reward { margin-top: 18px; }
.scratch { position: relative; border-radius: 18px; overflow: hidden; }
.note-paper { position: relative; background: var(--white); border: 1.5px solid #F2D4DC; border-radius: 18px; padding: 20px 18px; min-height: 9rem; }
.note-kind { margin: 0 0 6px; font-size: .875rem; color: var(--rose-deep); font-weight: 500; }
.note-text { margin: 0; font-size: 1.25rem; line-height: 1.65; white-space: pre-line; }
.note-text.is-shayari { font-size: 1.35rem; line-height: 1.85; }
.scratch canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; transition: opacity .5s; }
.scratch canvas.done { opacity: 0; pointer-events: none; }
.scratch-help { margin: 8px 0 0; text-align: center; color: var(--ink-soft); font-size: .9rem; }

/* birthday letter, shown above the card on the day */
.letter { background: var(--white); border-radius: 18px; padding: 20px 18px; margin-bottom: 18px; border: 1.5px solid #F2D4DC; }
.letter p { font: 400 1.15rem/1.6 var(--display); margin: 0 0 12px; text-wrap: pretty; }
.letter p:first-child { font-size: 1.5rem; color: var(--rose); }
.letter .sign { font-family: var(--body); font-size: 1rem; color: var(--ink-soft); margin: 0; }

.foot { margin: 22px 0 0; text-align: center; font-size: .85rem; color: var(--ink-soft); }
.foot a { color: inherit; padding: 8px; }

/* bottom: the bead strip, swipe sideways */
.strip {
  margin: 0 -18px; padding: 8px 0 calc(env(safe-area-inset-bottom) + 8px);
  border-top: 1.5px solid #F2D4DC; background: var(--paper);
  overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.strip::-webkit-scrollbar { display: none; }
.beads {
  list-style: none; margin: 0; padding: 0 calc(50% - 22px); display: flex; width: max-content;
  background: linear-gradient(var(--lavender), var(--lavender)) 0 22px / 100% 1.5px no-repeat;
}
.beads li { scroll-snap-align: center; }
.bead {
  position: relative; width: 46px; height: 62px; border: 0; padding: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; color: var(--ink-soft);
}
.bead::before { /* the bead itself */
  content: ""; margin-top: 9px; width: 26px; height: 26px; border-radius: 50%; box-sizing: border-box;
  background: var(--paper); border: 1.5px solid var(--ink-soft); transition: transform .15s;
}
.bead[data-s="future"] { cursor: default; }
.bead[data-s="future"]::before { border-color: var(--lavender); }
.bead[data-s="open"]::before { background: radial-gradient(circle at 35% 30%, #F4A9BB, var(--rose) 60%); border-color: var(--rose); }
.bead.is-today::before { box-shadow: 0 0 0 3px var(--paper), 0 0 0 5.5px var(--marigold); }
.bead[aria-current="true"]::before { transform: scale(1.25); }
.bead[aria-current="true"] { color: var(--ink); font-weight: 700; }
.bead span { margin-top: 6px; font-size: .78rem; line-height: 1; font-variant-numeric: tabular-nums; }
.bead[data-s="birthday"]::before { border-color: var(--marigold); background: #FFF3DC; }

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

/* very short screens (small phones, landscape): shrink the countdown */
@media (max-height: 640px) {
  .count-days { font-size: 3.2rem; }
  .progress { display: none; }
  .envelope { max-height: 40svh; }
}
@media (prefers-reduced-motion: reduce) {
  .flap, .seal, .bead::before, .scratch canvas { transition: none; }
  .opened { animation: none; }
}
