/* One Wish Willow, web edition. Colours match the iOS app's Branding.swift. */
:root {
  --red: #ed1c24;
  --red-shade: #b3121a;
  --red-deep: #820a12;
  --red-hi: #ff8c8f;
  --cream: #f5e4cc;
  --carton: #f3e1c3;
  --peach: #f2bca6;
  --ink: #171615;
  --void: #070404;
  --blood: #3d0509;
  --ember: #6b0a0f;
  --rounded: "Nunito", ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
  --serif: "Fraunces", ui-serif, Georgia, serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--void);
  color: var(--cream);
  font-family: var(--serif);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none;
  user-select: none;
}

/* ---------- backdrop ---------- */
.backdrop { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.backdrop .glow {
  position: absolute; inset: -20%;
  background: radial-gradient(closest-side at 50% 42%, rgba(107,10,15,.85), rgba(61,5,9,.55) 55%, transparent 100%);
  animation: breathe 4.5s ease-in-out infinite alternate;
}
.backdrop .vignette {
  position: absolute; inset: 0;
  background: radial-gradient(farthest-corner at 50% 50%, transparent 45%, rgba(0,0,0,.78) 100%);
}
.backdrop .grain {
  position: absolute; inset: 0; opacity: .09; mix-blend-mode: screen;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 1.6 -.55'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}
@keyframes breathe { from { opacity: .7; } to { opacity: 1; } }

/* ---------- scenes ---------- */
.scene {
  position: fixed; inset: 0; z-index: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(16px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right))
           calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  opacity: 0; visibility: hidden; transition: opacity .45s ease, visibility 0s linear .45s;
}
.scene.scroll { justify-content: flex-start; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.phase-box #sceneBox,
.phase-wishing #sceneWish,
.phase-snapping #sceneSnap,
.phase-locked #sceneLocked { opacity: 1; visibility: visible; transition: opacity .45s ease, visibility 0s; }

.instruction {
  font-family: var(--serif); font-weight: 900; font-size: 22px; line-height: 1.12;
  letter-spacing: .3px; text-align: center; color: var(--cream); margin: 18px 0 6px;
  font-variation-settings: "opsz" 144;
}
.alt { font-family: var(--serif); font-weight: 700; font-size: 15px; color: var(--peach); text-align: center; }
.fineprint { font-family: var(--serif); font-weight: 700; font-size: 11px; color: rgba(242,188,166,.55); text-align: center; margin: 18px 0 0; }

/* ---------- the carton (CSS 3D) ---------- */
.box-stage { display: flex; justify-content: center; align-items: center; }
.box-stage--big { flex: 0 1 auto; height: min(62vh, 360px); width: 100%; }
.boxmount { position: relative; width: var(--w); height: var(--h); perspective: 1100px; }
.box3d {
  position: absolute; inset: 0; transform-style: preserve-3d;
  transform: rotateX(-11deg) rotateY(-26deg);
}
.box-stage--big .box3d { animation: bob 5s ease-in-out infinite; }
@keyframes bob {
  0%, 100% { transform: rotateX(-11deg) rotateY(-26deg) translateY(0); }
  50% { transform: rotateX(-9deg) rotateY(-20deg) translateY(-6px); }
}
.face { position: absolute; backface-visibility: hidden; -webkit-backface-visibility: hidden; overflow: hidden; }
.face svg { display: block; width: 100%; height: 100%; }
.face.front { left: 0; top: 0; width: var(--w); height: var(--h); transform: translateZ(calc(var(--d) / 2)); box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); }
.face.side  { left: calc((var(--w) - var(--d)) / 2); top: 0; width: var(--d); height: var(--h);
  transform: rotateY(90deg) translateZ(calc(var(--w) / 2)); filter: brightness(.78); }
.face.left  { left: calc((var(--w) - var(--d)) / 2); top: 0; width: var(--d); height: var(--h);
  transform: rotateY(-90deg) translateZ(calc(var(--w) / 2)); background: var(--red-deep); }
.face.back  { left: 0; top: 0; width: var(--w); height: var(--h); transform: rotateY(180deg) translateZ(calc(var(--d) / 2)); background: var(--red-deep); }
.face.hole  { left: 0; top: calc(-1 * var(--d) / 2); width: var(--w); height: var(--d);
  transform: rotateX(90deg); background: radial-gradient(ellipse at 50% 60%, #1a0204, #4a060b 80%); backface-visibility: visible; }
.face.bottom { left: 0; top: calc(var(--h) - var(--d) / 2); width: var(--w); height: var(--d);
  transform: rotateX(-90deg); background: #2a0306; }
/* lid: hinged on the back top edge; closed lies flat over the top */
.lid {
  position: absolute; left: 0; top: calc(-1 * var(--d)); width: var(--w); height: var(--d);
  transform-origin: 50% 100%; transform-style: preserve-3d;
  transform: translateZ(calc(-1 * var(--d) / 2)) rotateX(-90deg);
  transition: transform .55s cubic-bezier(.3,1.5,.5,1);
}
.lid .lid-face { position: absolute; inset: 0; background: var(--red); backface-visibility: visible; overflow: hidden; }
.lid .lid-face svg { width: 100%; height: 100%; display: block; }
.lid .tuck {
  position: absolute; left: 4%; right: 4%; top: 100%; height: 34%;
  background: var(--carton); border-radius: 0 0 40% 40% / 0 0 100% 100%;
  transform-origin: 50% 0; transform: rotateX(-90deg);
}
.open-lid .lid { transform: translateZ(calc(-1 * var(--d) / 2)) rotateX(24deg); }
.box-shadow {
  position: absolute; left: -20%; right: -20%; bottom: calc(-1 * var(--h) * .08); height: calc(var(--h) * .12);
  background: radial-gradient(closest-side, rgba(0,0,0,.65), transparent); transform: translateX(10%);
}

/* ---------- wish screen ---------- */
.wish-wrap { width: 100%; max-width: 520px; margin: 0 auto; display: flex; flex-direction: column; align-items: center; padding-bottom: 24px; }
.wordmark-block { position: relative; width: 100%; text-align: center; padding: 6px 0 4px; }
.kicker { font-family: var(--serif); font-weight: 700; font-size: 11px; letter-spacing: 1.4px; color: rgba(245,228,204,.85); }
.wordmark { width: min(100%, 360px); height: auto; display: block; margin: -6px auto -10px; overflow: visible;
  filter: drop-shadow(0 0 14px rgba(237,28,36,.45)); }
.wordmark .wm { font-family: var(--rounded); font-weight: 900; font-size: 52px; fill: var(--red); letter-spacing: 1px; }
.tagline { font-family: var(--serif); font-weight: 700; font-size: 15px; color: var(--peach); }
.doodles { position: absolute; inset: 0; pointer-events: none; }
.doodles svg { position: absolute; overflow: visible; }

.stick-slot { width: 100%; max-width: 560px; touch-action: none; }
.stick-slot .stick { width: 100%; height: auto; display: block; overflow: visible; }
.stick-slot--big { max-width: 520px; }
.stick-slot--small { max-width: 360px; margin-top: 8px; }

.prompt { font-family: var(--serif); font-weight: 900; font-size: 26px; line-height: 1.05; text-align: center; color: var(--cream); margin: 4px 0 12px; display: block; font-variation-settings: "opsz" 144; }
.wish-card { width: 100%; background: var(--cream); border-radius: 8px; padding: 4px; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.wish-card textarea {
  display: block; width: 100%; border: 2px solid var(--red); border-radius: 5px; background: transparent;
  font-family: var(--serif); font-style: italic; font-weight: 600; font-size: 20px; line-height: 1.3; color: var(--ink);
  padding: 12px 14px; resize: none; outline: none; caret-color: var(--red);
  -webkit-user-select: text; user-select: text;
}
.wish-card textarea::placeholder { color: rgba(23,22,21,.4); }
.wish-card.nudge { animation: nudge .45s ease; }
@keyframes nudge { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* ---------- emerge (box opening) ---------- */
.emerge { position: fixed; inset: 0; z-index: 5; display: none; align-items: center; justify-content: center; pointer-events: none; }
.emerging .emerge { display: flex; }
.emerging .wish-wrap { opacity: 0; }
.emerge-out .wish-wrap { opacity: 1; transition: opacity .6s ease .1s; }
.emerge-stage { position: relative; width: var(--w); height: var(--h); margin-top: calc(var(--h) * .55); }
.boxmount--lid, .boxmount--body { position: absolute; inset: 0; width: auto; height: auto; transition: transform .6s cubic-bezier(.5,0,.8,.4), opacity .5s ease; }
.boxmount--lid { z-index: 1; }
.boxmount--body { z-index: 3; }
.emerge-stick {
  position: absolute; z-index: 2; left: 50%; top: 50%; width: calc(var(--h) * .95);
  transform: translate(-50%, -50%) rotate(-90deg) translateX(0);
  transition: transform .9s cubic-bezier(.2,.8,.2,1);
}
.emerge-stick .stick { width: 100%; height: auto; display: block; overflow: visible; }
.emerge-rise .emerge-stick { transform: translate(-50%, -50%) translateY(calc(var(--h) * -.82)) rotate(-90deg); }
.emerge-out .emerge-stick { transform: translate(-50%, -50%) translateY(calc(var(--h) * -1.05)) rotate(0deg) scale(1.15); opacity: 0;
  transition: transform .7s cubic-bezier(.2,.8,.2,1), opacity .35s ease .45s; }
.emerge-out .boxmount--lid, .emerge-out .boxmount--body { transform: translateY(60vh) rotate(8deg); opacity: 0; }

/* ---------- snap ---------- */
#sceneSnap { gap: 6px; }
.wish-quote { font-family: var(--serif); font-style: italic; font-weight: 600; font-size: 21px; text-align: center; color: var(--cream); margin: 4px 16px 0; max-width: 520px; }
.crack-word { font-family: var(--rounded); font-weight: 900; font-size: 40px; color: var(--red); text-shadow: 0 0 14px rgba(237,28,36,.6); opacity: 0; transform: scale(.6); }
.phase-snapping .crack-word { animation: pop .9s ease forwards; }
@keyframes pop { 0% { opacity: 0; transform: scale(.6); } 20% { opacity: 1; transform: scale(1.15); } 70% { opacity: 1; transform: scale(1); } 100% { opacity: .9; transform: scale(1); } }
.flash { position: fixed; inset: 0; background: var(--red); mix-blend-mode: screen; opacity: 0; pointer-events: none; }
.phase-snapping .flash { animation: flash .7s ease-out; }
@keyframes flash { 0% { opacity: .55; } 100% { opacity: 0; } }
.phase-snapping #sceneSnap .stick-slot { animation: shake .5s ease-out; }
@keyframes shake { 10% { transform: translateX(-9px); } 25% { transform: translateX(8px); } 40% { transform: translateX(-6px); } 55% { transform: translateX(4px); } 70% { transform: translateX(-2px); } 100% { transform: none; } }

/* ---------- ribbon + tag ---------- */
.ribbon-mount svg { display: block; width: 230px; height: auto; overflow: visible; margin: 0 auto; }
.ribbon-mount text { font-family: var(--serif); font-weight: 900; font-size: 19px; letter-spacing: 3.5px; fill: var(--cream); }
.locked-wrap { justify-content: center; min-height: 100%; }
.locked-head { position: relative; width: 100%; text-align: center; padding: 10px 0 14px; }
.locked-title { font-family: var(--serif); font-weight: 900; font-size: 32px; color: var(--cream); font-variation-settings: "opsz" 144; }
.locked-sub { font-family: var(--serif); font-weight: 700; font-size: 15px; color: var(--peach); margin-top: 6px; }
.tag-wrap { width: 100%; display: flex; flex-direction: column; align-items: center; }
.tag-wrap .ribbon-mount { position: relative; z-index: 2; margin-bottom: -16px; }
.tag-card { width: 100%; background: var(--cream); border-radius: 8px; padding: 30px 22px 18px; text-align: center; color: var(--ink);
  box-shadow: 0 12px 30px rgba(0,0,0,.5), inset 0 0 0 4px var(--cream), inset 0 0 0 6px var(--red); }
.tag-wish { font-family: var(--serif); font-style: italic; font-weight: 600; font-size: 22px; margin: 0 0 10px; word-break: break-word; -webkit-user-select: text; user-select: text; }
.tag-date { font-family: var(--serif); font-weight: 700; font-size: 12px; color: var(--red); margin: 0; }
.linkish { font: inherit; font-family: var(--serif); font-weight: 700; font-size: 16px; color: var(--peach); background: none; border: 0; padding: 14px; margin-top: 6px; cursor: pointer; }

/* outer (closed) screen is small: tighten type */
@media (max-width: 420px) {
  .instruction { font-size: 20px; }
  .locked-title { font-size: 27px; }
  .prompt { font-size: 23px; }
}

/* ---------- debug ---------- */
.debug { position: fixed; z-index: 50; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); background: rgba(0,0,0,.75);
  border: 1px solid rgba(245,228,204,.2); border-radius: 10px; padding: 6px; font: 11px/1.3 ui-monospace, Menlo, monospace; color: var(--cream); max-width: 70vw; }
.debug button { font: inherit; margin: 4px 4px 0 0; padding: 4px 8px; background: var(--red); color: var(--cream); border: 0; border-radius: 6px; }

@media (prefers-reduced-motion: reduce) {
  .box-stage--big .box3d, .backdrop .glow { animation: none; }
}
