:root {
  --night: #0b0806;
  --cream: #f2e4c6;
  --paper-ink: #2a1d16;
  --accent: #d8642a;
  --f-display: "Caveat Brush", cursive;
  --f-hand: "Caveat", cursive;
  --hint-y: 36vh;
  --lyr-y: 34vh;
  --blow: 0;
  --ink: none;
  --ink-hot: none;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: var(--night); color: var(--cream);
  font-family: var(--f-hand); -webkit-tap-highlight-color: transparent;
}
body { overflow: hidden; }
#grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 50;
  background-size: 256px 256px; mix-blend-mode: soft-light; opacity: 0.55;
}

/* ---------------- stage ---------------- */
#stage {
  position: fixed; inset: 0; overflow: hidden; touch-action: none;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
#stage.nocursor { cursor: none; }
#scene { position: absolute; left: 0; top: 0; display: block; }

.painted, #hint .h-main, #lyrics .w, #wish .w-main {
  background-image: var(--ink); background-size: 360px 180px;
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
/* background-clip:text only paints inside the box; give descenders, ascenders and
   slanted brush letters room to breathe, then cancel the extra space with margins */
.painted, #hint .h-main, #lyrics .w, #wish .w-main {
  padding: .14em .1em .26em; margin: -.14em -.1em -.26em;
}
@supports not ((-webkit-background-clip: text) or (background-clip: text)) {
  .painted, #hint .h-main, #lyrics .w, #wish .w-main { color: var(--cream); background: none; }
}

/* hint */
#hint {
  position: absolute; left: 50%; top: var(--hint-y); transform: translate(-50%, -50%);
  text-align: center; pointer-events: none; z-index: 10; width: min(92vw, 720px);
  opacity: 0; transition: opacity .35s ease;
  filter: drop-shadow(0 3px 0 rgba(10, 6, 4, .55)) drop-shadow(0 0 18px rgba(10, 6, 4, .45));
}
#hint.on { opacity: 1; }
#hint.on .h-main { animation: painton .6s cubic-bezier(.2, .9, .3, 1.3) both; }
#hint .h-main {
  font-family: var(--f-display); font-size: clamp(40px, 9vw, 88px); line-height: .95;
  display: inline-block; white-space: pre-line;
  transform: scale(calc(1 + var(--blow) * .18)) rotate(calc(-2deg + var(--blow) * 4deg));
}
#hint.small .h-main { font-size: clamp(30px, 6.5vw, 52px); }
#hint.side { transform: translate(0, -50%) rotate(-3deg); text-align: left; }
#hint .h-sub { font-family: var(--f-hand); font-weight: 700; font-size: clamp(18px, 4vw, 26px); color: var(--cream); opacity: .85; margin-top: 6px; }
@keyframes painton {
  0% { clip-path: inset(-30% 100% -40% -10%); transform: translateY(8px) rotate(-6deg); }
  100% { clip-path: inset(-30% -10% -40% -10%); transform: none; }
}

/* tip near the matchbox */
#tip {
  position: absolute; transform: translate(-30%, -100%) rotate(-4deg); z-index: 10; pointer-events: none;
  font-family: var(--f-display); font-size: clamp(22px, 5vw, 34px); color: var(--cream); white-space: nowrap;
  opacity: 0; transition: opacity .4s; text-shadow: 0 2px 0 rgba(0, 0, 0, .5), 0 0 12px rgba(0, 0, 0, .5);
}
#tip.on { opacity: 1; }

/* lyrics */
#lyrics {
  position: absolute; left: 50%; top: var(--lyr-top, 30vh); transform: translateX(-50%);
  width: min(94vw, 900px); text-align: center; pointer-events: none; z-index: 9;
  filter: drop-shadow(0 4px 0 rgba(10, 6, 4, .6)) drop-shadow(0 0 22px rgba(10, 6, 4, .5));
  transition: opacity 1s;
}
#lyrics.fade { opacity: 0; }
#lyrics .line {
  position: absolute; left: 0; right: 0; top: 0;
  font-family: var(--f-display); font-size: clamp(44px, 10.5vw, 112px); line-height: .95;
  opacity: 0; transition: opacity .35s, transform .5s;
}
#lyrics .line.cur { opacity: 1; }
#lyrics .line.past { opacity: 0; transform: translateY(-40%) scale(.9); }
#lyrics .w {
  display: inline-block; opacity: 0; transform: translateY(.35em) rotate(-6deg) scale(.7);
  transition: opacity .18s, transform .45s cubic-bezier(.2, .9, .3, 1.5);
}
#lyrics .w.on { opacity: 1; transform: none; }
#lyrics .w.nm { background-image: var(--ink-hot); font-size: 1.35em; }
#lyrics .w.nm.on { animation: wobble 1.6s ease-in-out infinite 0.5s; }
@keyframes wobble { 0%, 100% { transform: rotate(-3deg) scale(1); } 50% { transform: rotate(3deg) scale(1.06); } }

/* gift tag */
.tag {
  position: absolute; left: 50%; top: 46%; z-index: 20;
  width: min(80vw, 360px); min-height: 220px; padding: 34px 26px 26px 84px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  background-size: 100% 100%; background-repeat: no-repeat; color: var(--paper-ink);
  transform: translate(-50%, -50%) rotate(-4deg); transform-origin: 12% 50%;
  animation: swing 4.5s ease-in-out infinite; cursor: pointer;
  filter: drop-shadow(0 14px 22px rgba(0, 0, 0, .55));
  transition: opacity .7s, transform .9s cubic-bezier(.5, -0.3, .7, 1);
}
.tag.gone { animation: none; opacity: 0; transform: translate(-50%, -160%) rotate(-24deg); pointer-events: none; }
.tag .t-for { font-family: var(--f-hand); font-size: 22px; font-weight: 700; opacity: .7; }
.tag .t-name { font-family: var(--f-display); font-size: clamp(46px, 12vw, 68px); line-height: .9; color: #8f2a22; word-break: break-word; }
.tag .t-from { font-family: var(--f-hand); font-size: 22px; font-weight: 700; margin-top: 4px; }
.tag .t-cta { font-family: var(--f-display); font-size: 30px; margin-top: 14px; color: #b4471f; }
.tag .t-sound { font-family: var(--f-hand); font-size: 17px; font-weight: 700; opacity: .65; }
.tag.loading .t-cta { animation: breathe 1.2s ease-in-out infinite; color: var(--paper-ink); font-size: 24px; }
.tag:not(.loading) .t-cta { animation: breathe 2.2s ease-in-out infinite; }
@keyframes swing { 0%, 100% { transform: translate(-50%, -50%) rotate(-4deg); } 50% { transform: translate(-50%, -50%) rotate(2deg); } }
@keyframes breathe { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

/* wish */
#wish {
  position: absolute; left: 50%; bottom: var(--wish-bottom, 50vh); transform: translateX(-50%); z-index: 12;
  text-align: center; width: min(90vw, 560px); opacity: 0; transition: opacity 1.2s;
}
#wish.on { opacity: 1; }
#wish .w-main {
  font-family: var(--f-display); font-size: clamp(40px, 9vw, 80px); line-height: .95; margin: 0 0 22px; white-space: pre-line;
  filter: drop-shadow(0 3px 0 rgba(10, 6, 4, .6));
}
#wish .w-sub { font-family: var(--f-hand); font-weight: 700; font-size: 19px; opacity: .8; margin: 14px 0 0; }

/* painted buttons */
.pbtn {
  font-family: var(--f-display); font-size: 26px; line-height: 1; color: var(--cream);
  padding: 16px 30px 18px; border: 0; background: transparent no-repeat center / 100% 100%;
  cursor: pointer; text-decoration: none; display: inline-block; transition: transform .15s;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .3);
}
.pbtn.alt { color: var(--paper-ink); text-shadow: none; }
.pbtn:hover { transform: rotate(-2deg) scale(1.04); }
.pbtn:active { transform: scale(.96); }
.pbtn:focus-visible { outline: 2px dashed var(--cream); outline-offset: 4px; }

/* note */
#note {
  position: absolute; left: 50%; top: 50%; z-index: 30; width: min(90vw, 470px);
  transform: translate(-50%, -46%) scale(.2) rotate(-14deg); opacity: 0;
  transition: transform .8s cubic-bezier(.2, 1.2, .3, 1), opacity .4s;
  max-height: 94vh; overflow-y: auto;
}
#note.on { transform: translate(-50%, -50%) scale(1) rotate(-1.5deg); opacity: 1; }
.n-paper {
  position: relative; padding: 40px 34px 30px; color: var(--paper-ink);
  background-size: 100% 100%; background-repeat: no-repeat;
  filter: drop-shadow(0 18px 30px rgba(0, 0, 0, .55)); min-height: 200px;
}
.n-text { font-family: var(--f-hand); font-weight: 500; font-size: clamp(23px, 5.6vw, 29px); line-height: 1.22; margin: 0; white-space: pre-wrap; min-height: 2.4em; }
.n-sign { font-family: var(--f-display); font-size: 32px; text-align: right; margin: 14px 0 0; color: #8f2a22; opacity: 0; transition: opacity .6s .2s; }
.n-stamp {
  display: inline-flex; flex-direction: column; margin-top: 16px; padding: 8px 14px; border: 2.5px solid #a3302a; border-radius: 6px;
  color: #a3302a; transform: rotate(-5deg) scale(1.4); opacity: 0; transition: opacity .3s .5s, transform .4s cubic-bezier(.3, 1.6, .5, 1) .5s;
  font-family: var(--f-hand); font-weight: 700; line-height: 1.05; mix-blend-mode: multiply;
}
.n-stamp .s1 { font-size: 20px; }
.n-stamp .s2 { font-family: var(--f-display); font-size: 24px; text-transform: lowercase; }
#note.done .n-sign { opacity: 1; }
#note.done .n-stamp { opacity: .85; transform: rotate(-5deg) scale(1); }
.n-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 18px; opacity: 0; transition: opacity .6s 1s; }
#note.done .n-actions { opacity: 1; }

#mute {
  position: absolute; top: max(12px, env(safe-area-inset-top)); right: 12px; z-index: 40;
  width: 44px; height: 44px; border-radius: 50%; border: 2px solid rgba(242, 228, 198, .5);
  background: rgba(11, 8, 6, .35); color: var(--cream); font-size: 20px; cursor: pointer;
}
#mute.off { opacity: .45; text-decoration: line-through; }
#debug { position: absolute; left: 6px; bottom: 6px; z-index: 60; font: 11px/1.3 monospace; color: #fff; background: rgba(0, 0, 0, .6); padding: 4px 6px; }

/* ---------------- builder ---------------- */
#builder {
  position: fixed; inset: 0; overflow-y: auto; padding: 28px 14px 60px;
  background: radial-gradient(ellipse at 50% 30%, #2f4c3a 0%, #1c3024 60%, #0f1a13 100%);
}
.b-card {
  position: relative; width: min(100%, 560px); margin: 0 auto; padding: 34px 30px 30px;
  background-size: 100% 100%; background-repeat: no-repeat; color: var(--paper-ink);
  filter: drop-shadow(0 20px 40px rgba(0, 0, 0, .5));
}
#b-title { display: block; margin: 0 auto 4px; max-width: 100%; filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .25)); }
#b-title { background: #2a3f31; border-radius: 6px; }
.b-sub { font-family: var(--f-hand); font-weight: 700; font-size: 22px; text-align: center; margin: 10px 0 18px; }
.b-err, .b-warn { font-family: var(--f-hand); font-weight: 700; font-size: 18px; color: #a3302a; text-align: center; }
#b-form { display: flex; flex-direction: column; gap: 14px; }
#b-form label { display: flex; flex-direction: column; gap: 4px; font-family: var(--f-display); font-size: 24px; position: relative; }
#b-form label small { font-family: var(--f-hand); font-weight: 700; font-size: 15px; opacity: .65; }
#b-form .row, #b-out .row { display: flex; gap: 12px; }
#b-form .row label { flex: 1; }
#b-form input:not([type=checkbox]):not([type=radio]), #b-form textarea, #b-link {
  font-family: var(--f-hand); font-weight: 700; font-size: 22px; color: var(--paper-ink);
  background: rgba(255, 250, 238, .55); border: 0; border-bottom: 2.5px solid rgba(42, 29, 22, .45);
  border-radius: 4px 4px 0 0; padding: 6px 10px; width: 100%; outline: none;
}
#b-form input:focus, #b-form textarea:focus { border-bottom-color: #a3302a; background: rgba(255, 250, 238, .85); }
#b-form textarea { resize: vertical; line-height: 1.2; }
.count { position: absolute; right: 6px; bottom: 6px; font-family: var(--f-hand); font-size: 14px; opacity: .55; }
.themes { display: flex; gap: 10px; flex-wrap: wrap; }
.chip { flex-direction: row !important; align-items: center; cursor: pointer; }
.chip input { position: absolute; opacity: 0; }
.chip span { padding: 6px 16px 8px; border: 2.5px solid var(--paper-ink); border-radius: 999px 900px 999px 950px; font-size: 22px; }
.chip input:checked + span { background: var(--paper-ink); color: var(--cream); }
.chip.soon { opacity: .4; cursor: default; }
.check { flex-direction: row !important; align-items: center; gap: 10px !important; flex-wrap: wrap; }
.check input { width: 22px; height: 22px; accent-color: #a3302a; }
.pbtn.big { font-size: 32px; padding: 18px 34px 20px; align-self: center; margin-top: 8px; }
#b-out { margin-top: 22px; display: flex; flex-direction: column; gap: 12px; align-items: center; }
#b-out .row { flex-wrap: wrap; justify-content: center; }
#b-link { font-size: 16px; }
.b-fine { font-family: var(--f-hand); font-weight: 700; font-size: 16px; opacity: .65; margin: 0; }
.b-demo { text-align: center; margin: 18px 0 0; }
.b-demo a { font-family: var(--f-display); font-size: 22px; color: #8f2a22; }

@media (prefers-reduced-motion: reduce) {
  .tag { animation: none; }
  #lyrics .w.nm.on { animation: none; }
}
