:root {
  --pink-50: #fff4f8;
  --pink-100: #fde3ec;
  --pink-200: #f8c6d7;
  --pink-300: #f2a2bd;
  --pink-500: #e35d8c;
  --pink-600: #d4467a;
  --pink-700: #b8335f;
  --ink: #4a2a35;
  --ink-soft: #8a5d6c;
  --paper: #fffaf6;
  --line: #f1dbe3;
  --red: #e0435f;
  --shadow: 0 10px 30px rgba(184, 51, 95, .18);
  --font: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  --script: "Playwrite VN", cursive;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 20%, #ffe3ee 0, transparent 40%),
    radial-gradient(circle at 85% 80%, #f7cfe0 0, transparent 45%),
    #fbe6ee;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }

.stage {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.card {
  position: relative;
  width: min(420px, 100%);
  height: min(860px, calc(100dvh - 48px));
  border-radius: 32px;
  overflow: hidden;
  background: linear-gradient(170deg, #f9d3e0 0%, #f3b6cb 55%, #eea7c0 100%);
  box-shadow: 0 30px 80px rgba(160, 50, 90, .25), inset 0 0 0 1px rgba(255, 255, 255, .5);
}

@media (max-width: 480px) {
  .stage { padding: 0; }
  .card { width: 100%; height: 100dvh; border-radius: 0; }
}

/* Lấp lánh nền */
.sparkles span {
  position: absolute;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: #fff;
  opacity: 0;
  animation: twinkle 3.5s infinite ease-in-out;
}
@keyframes twinkle { 50% { opacity: .9; transform: scale(1.4); } }

/* Nút nhạc */
.music-toggle {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: 14px;
  z-index: 15;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, .75);
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 12px rgba(184, 51, 95, .2);
  opacity: 0; pointer-events: none;
  transition: opacity .4s, transform .2s;
}
.music-toggle.show { opacity: 1; pointer-events: auto; }
.music-toggle:active { transform: scale(.92); }
.music-toggle svg { width: 18px; height: 18px; fill: none; stroke: var(--pink-600); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.music-toggle.playing svg { animation: sway 1.6s ease-in-out infinite; }
.music-toggle.playing .slash { display: none; }
@keyframes sway { 50% { transform: rotate(-10deg) scale(1.06); } }

/* Màn hình */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: max(28px, env(safe-area-inset-top)) 22px max(28px, env(safe-area-inset-bottom));
  opacity: 0;
  visibility: hidden;
  transform: translateY(18px) scale(.98);
  transition: opacity .5s ease, transform .5s ease, visibility 0s linear .5s;
  overflow-y: auto;
}
.screen.active {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity .5s ease .1s, transform .5s ease .1s, visibility 0s;
}

.eyebrow, .hint {
  margin: 0;
  font-size: 11px;
  letter-spacing: .3em;
  text-transform: uppercase;
  color: var(--pink-700);
  opacity: .75;
}
.hint { font-family: var(--script); font-size: 16px; letter-spacing: 0; text-transform: none; animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.script { font-family: var(--script); font-size: 15px; line-height: 1.7; color: var(--ink-soft); margin: 0; }

.qbox {
  width: 100%;
  background: var(--paper);
  border-radius: 22px;
  padding: 18px 20px;
  text-align: center;
  box-shadow: var(--shadow);
}
.qbox h2 { margin: 6px 0; font-size: 19px; line-height: 1.4; font-weight: 700; }

/* Nút */
.btn {
  min-width: 150px;
  padding: 15px 30px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 16px;
  transition: transform .3s cubic-bezier(.3, 1.6, .5, 1), opacity .3s, box-shadow .2s;
}
.btn.primary {
  color: #fff;
  background: linear-gradient(180deg, #ef7aa3, var(--pink-600));
  box-shadow: 0 8px 20px rgba(212, 70, 122, .4), inset 0 1px 0 rgba(255, 255, 255, .4);
}
.btn.primary:hover:not(:disabled) { box-shadow: 0 10px 26px rgba(212, 70, 122, .5), inset 0 1px 0 rgba(255, 255, 255, .4); }
.btn.primary:active:not(:disabled) { transform: scale(.96); }
.btn.primary:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.btn.ghost { color: var(--pink-700); background: rgba(255, 255, 255, .85); min-width: 0; padding: 12px 24px; font-size: 14px; }
.btn.block { width: 100%; }

/* 1. Phong bì */
.envelope {
  position: relative;
  width: min(330px, 86vw);
  aspect-ratio: 1.5;
  border-radius: 10px;
  background: linear-gradient(160deg, #fffdf9, #f5ece6);
  box-shadow: 0 20px 40px rgba(150, 50, 80, .25);
  perspective: 800px;
  transition: transform .6s ease;
  animation: float 3.2s ease-in-out infinite;
}
.envelope:hover { transform: rotate(-2deg) scale(1.02); }
@keyframes float { 50% { translate: 0 -8px; } }
.env-flap {
  position: absolute;
  inset: 0 0 auto 0;
  height: 58%;
  background: linear-gradient(180deg, #fbf5f0, #efe3da);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top;
  transition: transform .7s ease;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .08));
  z-index: 2;
}
.env-label {
  position: absolute; top: 10px; left: 0; right: 0;
  font-size: 8px; letter-spacing: .35em; text-transform: uppercase; color: #8a7a74;
  z-index: 3;
}
.env-to { position: absolute; left: 22px; bottom: 22px; text-align: left; line-height: 1; }
.env-to small { display: block; font-size: 8px; letter-spacing: .2em; text-transform: uppercase; color: #9a8a84; margin-bottom: 10px; }
.env-to b { font-family: var(--script); font-size: 24px; font-weight: 400; color: #5b3a40; }
.env-seal {
  position: absolute; left: 50%; top: 58%;
  translate: -50% -50%;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: #fff; font-size: 18px;
  background: radial-gradient(circle at 35% 30%, #f06a8a, #c3284d 70%);
  box-shadow: 0 3px 6px rgba(120, 20, 40, .35), inset 0 0 0 4px rgba(255, 255, 255, .15);
  z-index: 4;
  transition: transform .4s, opacity .4s;
}
.env-stamp {
  position: absolute; right: 22px; bottom: 26px;
  width: 38px; height: 46px;
  display: grid; place-items: center;
  color: var(--red); font-size: 16px;
  background: #fde8ee;
  outline: 2px dotted #e8b8c6; outline-offset: -4px;
}
.env-postmark {
  position: absolute; right: 50px; bottom: 34px;
  width: 54px; height: 24px;
  background: repeating-radial-gradient(ellipse at 0 50%, transparent 0 4px, #b9a8a2 4px 5px);
  opacity: .5;
  border-radius: 40%;
}
.envelope.open { animation: none; }
.envelope.open .env-flap { transform: rotateX(180deg); }
.envelope.open .env-seal { transform: scale(0); opacity: 0; }

/* Mèo */
.cat { width: 200px; flex-shrink: 0; }
.cat svg { width: 100%; height: auto; display: block; animation: bob 3s ease-in-out infinite; overflow: visible; }
.cat.small { width: 150px; }
@keyframes bob { 50% { transform: translateY(-6px); } }
.cat .floaty { animation: floaty 2.4s ease-in-out infinite; transform-box: fill-box; }
.cat .floaty:nth-of-type(2) { animation-delay: .8s; }
@keyframes floaty { 0% { opacity: 0; transform: translateY(8px); } 50% { opacity: 1; } 100% { opacity: 0; transform: translateY(-14px); } }

/* 2. Thẻ cào */
.scratch-wrap { position: relative; width: 100%; }
.scratch-wrap .qbox { min-height: 130px; display: flex; flex-direction: column; justify-content: center; }
#scratch {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  border-radius: 22px;
  touch-action: none;
  cursor: grab;
  transition: opacity .6s;
}
#scratch.done { opacity: 0; pointer-events: none; }

.choices {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  min-height: 64px;
  opacity: 0; pointer-events: none;
  transition: opacity .5s;
}
.choices.show { opacity: 1; pointer-events: auto; }
#yesBtn { transform: scale(var(--yes, 1)); }
#noBtn { transform: translate(var(--nx, 0), var(--ny, 0)) scale(var(--no, 1)); }
#noBtn.gone { opacity: 0; pointer-events: none; width: 0; padding: 0; margin-left: -14px; }

.tip {
  position: absolute; top: -10px; left: 50%;
  translate: -50% -100%;
  padding: 7px 14px;
  border-radius: 999px;
  background: #fff;
  font-size: 13px; font-weight: 600; white-space: nowrap;
  color: var(--pink-700);
  box-shadow: 0 6px 16px rgba(184, 51, 95, .2);
  opacity: 0;
  transform: translateX(var(--tx, 0)) scale(.8);
  transition: opacity .25s, transform .25s;
  z-index: 5;
  pointer-events: none;
}
.tip.show { opacity: 1; transform: translateX(var(--tx, 0)) scale(1); }

/* 4. Form ngày giờ */
.form {
  width: 100%;
  background: rgba(255, 255, 255, .7);
  border-radius: 22px;
  padding: 16px;
  display: flex; flex-direction: column; gap: 6px;
  box-shadow: var(--shadow);
}
.field-label { font-size: 10px; font-weight: 700; letter-spacing: .15em; text-transform: uppercase; color: var(--ink-soft); margin-left: 4px; }
.field-label + .field { margin-bottom: 8px; }
.field {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%;
  padding: 13px 14px;
  border-radius: 14px;
  background: #fff;
  border: 1.5px solid var(--line);
  font-size: 15px; font-weight: 500; text-align: left;
  transition: border-color .2s;
}
.field:hover, .field:focus-visible { border-color: var(--pink-300); outline: none; }
.field .placeholder { color: #b9a0a8; font-weight: 400; }
.field svg { width: 20px; height: 20px; fill: none; stroke: var(--pink-500); stroke-width: 1.7; stroke-linecap: round; }

.popup {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  padding: 22px;
  background: rgba(120, 40, 70, .22);
  backdrop-filter: blur(4px);
  opacity: 0; visibility: hidden;
  transition: opacity .25s, visibility 0s linear .25s;
  z-index: 10;
}
.popup.open { opacity: 1; visibility: visible; transition: opacity .25s; }
.pop-card {
  width: 100%; max-width: 330px;
  background: #fff;
  border-radius: 22px;
  padding: 16px;
  box-shadow: 0 20px 50px rgba(120, 40, 70, .3);
  transform: translateY(12px) scale(.96);
  transition: transform .3s cubic-bezier(.3, 1.4, .5, 1);
}
.popup.open .pop-card { transform: none; }
.pop-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.pop-close { width: 28px; height: 28px; border-radius: 50%; background: var(--pink-50); color: var(--pink-600); font-size: 18px; line-height: 1; }

.cal-nav { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-weight: 700; font-size: 14px; }
.cal-nav button { width: 32px; height: 32px; border-radius: 50%; font-size: 20px; color: var(--pink-600); }
.cal-nav button:hover:not(:disabled) { background: var(--pink-50); }
.cal-nav button:disabled { opacity: .25; cursor: default; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.cal-week span { font-size: 10px; font-weight: 700; color: var(--ink-soft); padding: 4px 0; }
.cal-grid button { aspect-ratio: 1; border-radius: 50%; font-size: 13px; font-weight: 500; }
.cal-grid button:hover:not(:disabled) { background: var(--pink-100); }
.cal-grid button:disabled { color: #d8c8cd; cursor: default; }
.cal-grid button.today { box-shadow: inset 0 0 0 1.5px var(--pink-300); }
.cal-grid button.sel { background: var(--pink-600); color: #fff; }

.wheel { position: relative; display: flex; justify-content: center; align-items: center; gap: 6px; height: 180px; margin-bottom: 14px; }
.wheel-band { position: absolute; left: 0; right: 0; top: 72px; height: 36px; border-radius: 12px; background: var(--pink-50); }
.wheel-col {
  position: relative;
  list-style: none; margin: 0; padding: 72px 0;
  height: 180px; width: 70px;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  mask-image: linear-gradient(transparent, #000 30%, #000 70%, transparent);
}
.wheel-col::-webkit-scrollbar { display: none; }
.wheel-col li {
  height: 36px; line-height: 36px;
  text-align: center;
  scroll-snap-align: center;
  font-size: 17px; color: #b9a0a8;
  cursor: pointer;
  transition: color .15s, font-size .15s;
}
.wheel-col li.sel { color: var(--pink-700); font-weight: 700; font-size: 20px; }
.wheel-colon { position: relative; font-weight: 700; color: var(--pink-700); font-size: 20px; }

/* 5. Hoạt động */
.activities { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; }
.activity {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: 14px 8px 12px;
  border-radius: 20px;
  background: #fff;
  border: 2px solid transparent;
  box-shadow: 0 6px 16px rgba(184, 51, 95, .12);
  transition: transform .2s, border-color .2s, box-shadow .2s;
}
.activity:hover { transform: translateY(-2px); }
.activity .emoji { font-size: clamp(38px, 7dvh, 52px); line-height: 1.1; transition: transform .3s cubic-bezier(.3, 1.8, .5, 1); }
.activity .label { font-size: 13px; font-weight: 600; }
.activity.sel { border-color: var(--pink-500); box-shadow: 0 8px 20px rgba(212, 70, 122, .28); }
.activity.sel .emoji { transform: scale(1.12) rotate(-4deg); }
.activity::after {
  content: "✓";
  position: absolute; top: 8px; right: 8px;
  width: 22px; height: 22px;
  display: grid; place-items: center;
  border-radius: 50%;
  font-size: 12px; font-weight: 800; color: #fff;
  background: var(--pink-600);
  transform: scale(0);
  transition: transform .25s cubic-bezier(.3, 1.8, .5, 1);
}
.activity.sel::after { transform: scale(1); }

/* 6. Vé */
#s-ticket { justify-content: flex-start; padding-top: max(56px, env(safe-area-inset-top)); }
.printer { position: relative; width: 100%; display: flex; flex-direction: column; align-items: center; }
.slot {
  width: 100%; height: 16px;
  border-radius: 999px;
  background: linear-gradient(180deg, #2b1a20, #4a2c36);
  box-shadow: 0 3px 0 rgba(255, 255, 255, .5), inset 0 3px 6px rgba(0, 0, 0, .6);
  position: relative; z-index: 2;
}
.paper { width: calc(90% + 28px); margin-top: -8px; overflow: hidden; padding: 0 14px 34px; }
.ticket {
  position: relative;
  background:
    radial-gradient(circle at 0 0, rgba(255, 220, 230, .5), transparent 40%),
    var(--paper);
  border-radius: 0 0 14px 14px;
  padding: 18px 18px 14px;
  box-shadow: 0 12px 26px rgba(120, 40, 70, .25);
  transform: translateY(-105%);
  font-size: 10px;
  color: #5b3a40;
}
.ticket.print { animation: print 3s cubic-bezier(.4, 0, .3, 1) forwards; }
@keyframes print {
  0% { transform: translateY(-105%); }
  20% { transform: translateY(-80%); }
  25% { transform: translateY(-78%); }
  50% { transform: translateY(-42%); }
  55% { transform: translateY(-40%); }
  100% { transform: translateY(0); }
}
.t-row { display: flex; justify-content: space-between; }
.t-top { flex-direction: column; align-items: center; gap: 4px; text-align: center; font-size: 9px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-soft); }
.t-top span:last-child { font-size: 8px; opacity: .8; }
.t-top b { color: var(--red); }
.t-kicker { text-align: center; margin: 12px 0 0; font-size: 9px; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-soft); }
.t-title { text-align: center; margin: 2px 0 0; font-size: 30px; font-weight: 800; letter-spacing: -.01em; }
.t-title em { font-family: var(--script); font-style: normal; color: var(--red); font-size: 28px; font-weight: 400; }
.t-admit { text-align: center; margin: 0 0 12px; font-size: 8px; letter-spacing: .3em; text-transform: uppercase; color: var(--ink-soft); }
.t-info { border-top: 1.5px dashed var(--line); border-bottom: 1.5px dashed var(--line); padding: 10px 6px; }
.t-info div:last-child { text-align: right; }
.t-info small, .t-plan-label { display: block; font-size: 8px; letter-spacing: .2em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 3px; }
.t-info b { font-size: 15px; }
.t-plan-label { text-align: center; margin: 10px 0 6px; }
.t-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.t-chips span { padding: 4px 10px; border-radius: 999px; background: #fde8ee; font-size: 11px; font-weight: 600; color: var(--pink-700); }
.t-fine { text-align: center; margin: 10px 0; font-size: 7.5px; letter-spacing: .12em; text-transform: uppercase; color: #b9a0a8; }
.t-stub { display: flex; align-items: center; gap: 10px; border-top: 2px dotted var(--pink-200); padding-top: 12px; }
.barcode { flex: 1; height: 40px; display: flex; align-items: stretch; gap: 1.5px; }
.barcode i { background: #3a2329; }
.t-heart {
  width: 34px; height: 34px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 50%;
  color: #fff; font-size: 15px;
  background: radial-gradient(circle at 35% 30%, #f06a8a, #c3284d 70%);
}

.final { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; opacity: 0; transform: translateY(10px); transition: opacity .8s, transform .8s; }
.final.show { opacity: 1; transform: none; }
.final h2 { font-size: 19px; margin: 0; color: var(--pink-700); }
.final .btn { margin-top: 10px; }
.share-fallback { width: 100%; margin-top: 8px; font-size: 13px; color: var(--ink-soft); }
.share-fallback p { margin: 0 0 6px; }
.share-fallback textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1.5px solid var(--pink-200);
  background: #fff;
  font: 500 14px/1.5 var(--font);
  color: var(--ink);
  resize: none;
  user-select: text;
  -webkit-user-select: text;
}

/* Tim bay */
.float-heart {
  position: absolute; bottom: -30px;
  pointer-events: none;
  color: var(--red);
  animation: rise linear forwards;
  z-index: 20;
}
@keyframes rise { to { transform: translateY(calc(-100dvh - 60px)) rotate(var(--r)); opacity: 0; } }

/* Màn hình thấp */
@media (max-height: 700px) {
  .cat { width: 150px; }
  .cat.small { width: 110px; }
  .screen { gap: 12px; }
  .qbox { padding: 14px 16px; }
  .qbox h2 { font-size: 17px; }
  .activity { padding: 10px 6px 8px; }
}

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