/* ==========================================================================
   Pixelpost – styles (pixel look: hard edges, hard shadows, pixel fonts)
   ========================================================================== */
:root {
  --ink: #1b1330;
  --paper: #fffaf0;
  --mint: #7ee0c3;
  --sky: #8fd3ff;
  --sun: #ffd23f;
  --pink: #ff5d8f;
  --lilac: #c9b6ff;
  --bgA: #e9fbff;
  --bgB: #fff3f8;
  --px: 4px;
  --shadow: 6px 6px 0 var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Pixelify Sans', system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 10%, #fff 0 2px, transparent 3px) 0 0 / 28px 28px,
    linear-gradient(160deg, var(--bgA), var(--bgB) 60%, #fffbe6);
  min-height: 100vh;
}
body.rcvOpen { overflow: hidden; }
canvas { image-rendering: -moz-crisp-edges; image-rendering: crisp-edges; image-rendering: -webkit-optimize-contrast; image-rendering: pixelated; }
button, a, .tile, .chip, .sw { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-user-select: none; user-select: none; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
:focus-visible { outline: 3px dashed var(--pink); outline-offset: 3px; }
[hidden] { display: none !important; }

/* ---------------- buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  border: 0; padding: .7em 1.1em; font-weight: 700; font-size: 1rem; text-decoration: none;
  background: var(--sky); color: var(--ink);
  box-shadow: 0 0 0 3px var(--ink), 4px 4px 0 3px var(--ink);
  transition: transform .08s, box-shadow .08s;
}
@media (hover: hover) { .btn:hover { transform: translate(-1px, -1px); box-shadow: 0 0 0 3px var(--ink), 6px 6px 0 3px var(--ink); } }
.btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 3px var(--ink), 1px 1px 0 3px var(--ink); }
.btn:disabled { opacity: .4; pointer-events: none; }
.btn.pink { background: var(--pink); color: #fff; }
.btn.ghost { background: #fff; }
.btn.big { font-size: 1.15rem; padding: .9em 1.2em; }
.btn.small { font-size: .85rem; padding: .4em .8em; }
.linkbtn { background: none; border: 0; text-decoration: underline; padding: 0; }

/* ---------------- topbar & stepper ---------------- */
.topbar {
  padding-top: max(14px, env(safe-area-inset-top)) !important;
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 14px 24px; background: #fff; border-bottom: 4px solid var(--ink);
  position: sticky; top: 0; z-index: 5;
}
.logo { display: flex; align-items: center; gap: 10px; font-family: 'Press Start 2P'; font-size: 16px; letter-spacing: 1px; }
.logo canvas { width: 32px; height: 32px; }
.stepper { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; justify-content: flex-end; }
.stepDot {
  display: flex; align-items: center; gap: 6px; border: 0; background: #f2f0f7; padding: 6px 10px 6px 6px;
  box-shadow: 0 0 0 2px var(--ink); font-size: .9rem;
}
.stepDot b { display: grid; place-items: center; width: 24px; height: 24px; background: #fff; box-shadow: 0 0 0 2px var(--ink); font-family: 'Press Start 2P'; font-size: 10px; }
.stepDot.done b { background: var(--mint); }
.stepDot.on { background: var(--sun); transform: translateY(-2px); box-shadow: 0 0 0 2px var(--ink), 3px 3px 0 2px var(--ink); }
.stepDot.on b { background: var(--pink); color: #fff; }

/* ---------------- editor layout ---------------- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 460px; gap: 28px; padding: 28px 24px; max-width: 1400px; margin: 0 auto; align-items: start; }
.panel { background: #fff; box-shadow: 0 0 0 4px var(--ink), 10px 10px 0 4px rgba(27, 19, 48, .18); padding: 24px; }
.steps { min-height: 520px; display: flex; flex-direction: column; }
#stepBody { flex: 1; }
.stepWrap h2 { font-family: 'Press Start 2P'; font-size: 18px; margin: 0 0 10px; line-height: 1.4; }
.lead { margin: 0 0 18px; font-size: 1.05rem; opacity: .85; }
.lbl { margin: 22px 0 10px; font-size: 1rem; text-transform: uppercase; letter-spacing: 1px; }
.stepnav { display: flex; justify-content: space-between; margin-top: 24px; padding-top: 18px; border-top: 3px dashed #e3def0; }
.previewPanel { position: sticky; top: 100px; display: flex; flex-direction: column; gap: 16px; align-items: stretch; background: linear-gradient(180deg, #fff, #fbf8ff); }
.previewHead { display: flex; align-items: center; justify-content: space-between; }
.previewHead h3 { margin: 0; font-family: 'Press Start 2P'; font-size: 14px; }
.seg { display: flex; box-shadow: 0 0 0 3px var(--ink); }
.segBtn { border: 0; background: #fff; padding: 6px 12px; font-weight: 600; }
.segBtn.on { background: var(--ink); color: #fff; }
.previewStage {
  --cw: min(190px, 40vw);
  display: grid; place-items: center; min-height: calc(var(--cw) * 4 / 3 + 40px); padding: 20px 0;
  background: repeating-conic-gradient(#f4f1fa 0 25%, #fff 0 50%) 0 0 / 24px 24px;
  box-shadow: inset 0 0 0 3px #e3def0;
}
.appfoot { display: flex; justify-content: center; gap: 18px; padding: 18px 0 max(30px, env(safe-area-inset-bottom)); font-size: .9rem; opacity: .8; }

/* ---------------- tiles & pickers ---------------- */
.tabs { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.tab { border: 0; background: #fff; padding: 10px 14px; box-shadow: 0 0 0 3px var(--ink); font-weight: 700; display: flex; align-items: center; gap: 8px; }
.tab .ico { font-size: 1.1em; }
.tab em { font-style: normal; font-size: .7rem; background: var(--pink); color: #fff; padding: 2px 6px; }
.tab.on.t0 { background: #cfe3ff; } .tab.on.t1 { background: #ffd1e0; } .tab.on.t2 { background: #fff0a8; }
.tab.on { transform: translateY(-2px); box-shadow: 0 0 0 3px var(--ink), 4px 4px 0 3px var(--ink); }
.grid { display: grid; gap: 14px; }
.g5 { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.tile {
  border: 0; background: #fff; padding: 8px; display: flex; flex-direction: column; align-items: center; gap: 6px;
  box-shadow: 0 0 0 3px var(--ink); transition: transform .12s cubic-bezier(.3, 1.6, .5, 1);
}
.tile span, .tile small { font-size: .85rem; font-weight: 600; text-align: center; }
@media (hover: hover) { .tile:hover { transform: translateY(-3px) rotate(-1deg); } }
.tile.sel { background: var(--sun); box-shadow: 0 0 0 3px var(--ink), 5px 5px 0 3px var(--pink); transform: translateY(-3px); }
.animTile canvas { width: 100%; aspect-ratio: 3 / 4; box-shadow: 0 0 0 2px var(--ink); }
.patTile i { display: block; width: 100%; aspect-ratio: 1; box-shadow: 0 0 0 2px var(--ink); image-rendering: pixelated; }
.stampTile canvas { width: 72px; height: 85px; filter: drop-shadow(3px 3px 0 rgba(27, 19, 48, .3)); }
@media (hover: hover) { .stampTile:hover canvas { animation: wiggle .4s steps(4) infinite; } }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-5deg); } 75% { transform: rotate(5deg); } }
.fontTile { padding: 16px 8px; min-height: 92px; justify-content: center; }
.fontTile .sample { line-height: 1.1; word-break: break-word; }
.inpRow { display: flex; align-items: center; gap: 12px; margin-top: 4px; }
.inpRow input, .linkInp {
  flex: 1; font: inherit; font-size: 1.25rem; padding: 12px 14px; border: 0; background: #fffdf5;
  box-shadow: inset 0 0 0 3px var(--ink); min-width: 0;
}
.inpRow input:focus { background: #fff; box-shadow: inset 0 0 0 3px var(--pink); outline: none; }
.counter { font-family: 'Press Start 2P'; font-size: 10px; opacity: .7; white-space: nowrap; }
.counter.full { color: var(--pink); opacity: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.chip { border: 0; background: #fff; padding: 9px 12px; box-shadow: 0 0 0 3px var(--ink); font-weight: 600; transition: transform .12s; }
@media (hover: hover) { .chip:hover { transform: translateY(-2px); } }
.chip.sel { background: var(--pink); color: #fff; }
.chip.own { background: #f2f0f7; }
.chip.own.sel { background: var(--pink); }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.sw { width: 40px; height: 40px; border: 0; background: var(--c); box-shadow: 0 0 0 3px var(--ink); }
.swatches.small .sw { width: 32px; height: 32px; }
.sw.sel { box-shadow: 0 0 0 3px var(--ink), 0 0 0 7px #fff, 0 0 0 10px var(--ink); transform: scale(1.05); }
.pick { position: relative; display: grid; place-items: center; width: 32px; height: 32px; box-shadow: 0 0 0 3px var(--ink); background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); cursor: pointer; font-size: 14px; }
.pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt { border: 0; background: #fff; padding: 7px 11px; box-shadow: 0 0 0 3px var(--ink); font-weight: 600; }
.opt.sel { background: var(--mint); }
.check { display: flex; align-items: center; gap: 8px; margin-top: 18px; font-weight: 600; }
.check input { width: 20px; height: 20px; accent-color: var(--pink); }

/* ---------------- share ---------------- */
.share { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 26px; }
.qrBox { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.qrCanvas { width: 100%; max-width: 340px; height: auto; align-self: center; box-shadow: 0 0 0 3px var(--ink), 8px 8px 0 3px rgba(27, 19, 48, .18); background: #fff; }
.qrBtns { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 8px; }
.linkInp { flex: none; font-size: 16px; padding: 8px 10px; }
.tiny { font-size: .8rem; opacity: .7; margin: 0; }
.warn { background: #fff4c2; padding: 10px 12px; box-shadow: 0 0 0 2px var(--ink); margin: 0; font-size: .9rem; }
.qrOpts .lbl:first-child { margin-top: 0; }

/* ---------------- the card ---------------- */
.cardWrap { perspective: 1600px; }
.card3d {
  position: relative; width: var(--cw); height: calc(var(--cw) * 4 / 3);
  transform-style: preserve-3d; transition: transform 1s cubic-bezier(.4, .1, .3, 1);
}
.previewStage .card3d { transform-style: preserve-3d; }
.previewStage { perspective: 1400px; }
.card3d.open { transform: translateX(50%); }
.cardInside, .cardCover { position: absolute; inset: 0; }
.cardInside {
  background: var(--pat) 0 0 / var(--pats) repeat; image-rendering: pixelated;
  padding: calc(var(--cw) * .06); box-shadow: 0 0 0 4px var(--ink), 8px 8px 0 4px rgba(27, 19, 48, .25);
}
.paper {
  position: relative; height: 100%; background: var(--paper);
  box-shadow: 0 0 0 3px var(--ink), inset 0 0 0 4px #f1e6cf;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  padding: 16% 9% 20%; overflow: hidden;
}
.fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.miniStamp { position: absolute; top: 5%; right: 6%; width: 17%; transform: rotate(7deg); filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, .2)); }
.msg { position: relative; font-size: calc(var(--cw) * .12 * var(--fs, 1)); line-height: 1.05; font-weight: 700; text-shadow: 2px 2px 0 rgba(27, 19, 48, .14); overflow-wrap: anywhere; }
.msg .word { display: inline-block; white-space: nowrap; }
.msg .ch { display: inline-block; }
.msg.anim .ch { animation: pop .55s cubic-bezier(.3, 1.7, .5, 1) both, bob 2.6s ease-in-out infinite; animation-delay: calc(var(--i) * 60ms), calc(var(--i) * 60ms + .7s); }
@keyframes pop { from { transform: translateY(-140%) scale(.2) rotate(-30deg); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8%); } }
.sig { position: absolute; bottom: 7%; left: 0; right: 0; font-size: calc(var(--cw) * .075); opacity: .9; }
.sig span { font-size: 1.25em; }
.cardCover { transform-origin: left center; transition: transform 1.1s cubic-bezier(.5, .05, .25, 1); transform-style: preserve-3d; z-index: 2; }
.card3d.open .cardCover { transform: rotateY(-180deg); }
.coverFront, .coverBack { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; box-shadow: 0 0 0 4px var(--ink), 8px 8px 0 4px rgba(27, 19, 48, .25); }
.coverFront canvas { display: block; width: 100%; height: 100%; }
.coverBack { transform: rotateY(180deg); background: var(--pat) 0 0 / var(--pats) repeat; image-rendering: pixelated; display: grid; place-items: center; }
.cbInner { background: var(--paper); box-shadow: 0 0 0 3px var(--ink); padding: 10% 12%; display: flex; flex-direction: column; align-items: center; gap: 6px; transform: rotate(-4deg); font-size: calc(var(--cw) * .08); font-weight: 700; }
.cbInner b { color: #ff3355; font-size: 1.4em; }
.cbStamp { width: calc(var(--cw) * .26); }

/* ---------------- start page ---------------- */
.start {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; overflow: hidden;
  background: linear-gradient(135deg, rgba(126, 232, 250, .78), rgba(255, 186, 214, .74) 50%, rgba(255, 233, 140, .78));
  backdrop-filter: blur(5px) saturate(1.2); -webkit-backdrop-filter: blur(5px) saturate(1.2);
  clip-path: circle(150% at 50% 62%);
  transition: clip-path .9s cubic-bezier(.7, 0, .3, 1);
}
.start.leaving { clip-path: circle(0% at 50% 62%); }
.start.leaving .startInner { transform: scale(1.3); opacity: 0; }
.startInner { position: relative; text-align: center; display: flex; flex-direction: column; align-items: center; transition: transform .6s, opacity .5s; padding: 20px; }
.startStamp canvas { width: 96px; height: 114px; transform: rotate(8deg); filter: drop-shadow(5px 5px 0 rgba(27, 19, 48, .3)); animation: floatS 3s ease-in-out infinite; }
@keyframes floatS { 50% { transform: rotate(-4deg) translateY(-8px); } }
.title { font-family: 'Press Start 2P'; font-size: clamp(34px, 9vw, 96px); margin: 18px 0 8px; line-height: 1; color: #fff; display: flex; flex-wrap: wrap; justify-content: center; }
.title span {
  text-shadow: 4px 0 var(--ink), -4px 0 var(--ink), 0 4px var(--ink), 0 -4px var(--ink), 4px 4px var(--ink), -4px -4px var(--ink), 4px -4px var(--ink), -4px 4px var(--ink),
    8px 8px 0 var(--pink), 12px 12px 0 var(--ink);
  animation: titleIn .9s cubic-bezier(.3, 1.6, .5, 1) both;
}
.title span:nth-child(2) { color: var(--sun); animation-delay: .15s; }
@keyframes titleIn { from { transform: translateY(-60px) scale(.6); opacity: 0; } }
.subtitle { font-size: clamp(17px, 2.6vw, 24px); font-weight: 600; margin: 18px 0 30px; text-shadow: 2px 2px 0 rgba(255, 255, 255, .7); }
.playBtn {
  width: 108px; height: 108px; border: 0; background: var(--pink); color: #fff; display: grid; place-items: center;
  box-shadow: 0 0 0 5px var(--ink), 8px 8px 0 5px var(--ink); animation: pulse 1.6s ease-in-out infinite;
  clip-path: polygon(8px 0, calc(100% - 8px) 0, calc(100% - 8px) 4px, calc(100% - 4px) 4px, calc(100% - 4px) 8px, 100% 8px, 100% calc(100% - 8px), calc(100% - 4px) calc(100% - 8px), calc(100% - 4px) calc(100% - 4px), calc(100% - 8px) calc(100% - 4px), calc(100% - 8px) 100%, 8px 100%, 8px calc(100% - 4px), 4px calc(100% - 4px), 4px calc(100% - 8px), 0 calc(100% - 8px), 0 8px, 4px 8px, 4px 4px, 8px 4px);
  outline: 5px solid var(--ink); outline-offset: -5px;
}
.playBtn svg { width: 46px; height: 46px; margin-left: 8px; }
.playBtn:hover { background: #ff3f7a; }
.playBtn:active { transform: translate(4px, 4px); }
@keyframes pulse { 50% { transform: scale(1.08); } }
.hint { font-family: 'Press Start 2P'; font-size: 11px; margin-top: 22px; animation: blink 1.2s steps(2) infinite; }
@keyframes blink { 50% { opacity: .2; } }
.floaties { position: absolute; inset: 0; pointer-events: none; }
.floaty { position: absolute; bottom: -60px; width: var(--s); height: var(--s); animation: rise var(--d) linear infinite; animation-delay: var(--dl); opacity: .9; filter: drop-shadow(3px 3px 0 rgba(27, 19, 48, .2)); }
@keyframes rise { from { transform: translateY(0) rotate(0); } to { transform: translateY(-120vh) rotate(var(--r)); } }

/* ---------------- receiver ---------------- */
.receiver { position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column; overflow: hidden; --cw: min(300px, 45vw, calc((100vh - 220px) * .75)); --ew: min(440px, 88vw, calc((100vh - 200px) * 1.4)); }
@supports (height: 100dvh) { .receiver { --cw: min(300px, 45vw, calc((100dvh - 220px) * .75)); --ew: min(440px, 88vw, calc((100dvh - 200px) * 1.4)); } }
.receiver { padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left); -webkit-user-select: none; user-select: none; }
.rcvBg { position: absolute; inset: 0; image-rendering: pixelated; animation: drift 40s linear infinite; }
@keyframes drift { to { background-position: 240px 240px; } }
.receiver::before { content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 1; }
.theme0::before { background: radial-gradient(ellipse at center, rgba(20, 35, 77, .25), rgba(13, 16, 51, .8)); }
.theme1::before { background: radial-gradient(ellipse at center, rgba(255, 209, 230, .2), rgba(160, 30, 80, .7)); }
.theme2::before { background: radial-gradient(ellipse at center, rgba(255, 240, 168, .2), rgba(15, 120, 140, .7)); }
.rcvStage { position: relative; z-index: 2; flex: 1; display: grid; place-items: center; padding: 20px; perspective: 1600px; }
.rcvStage > * { grid-area: 1 / 1; }
.rcvControls { position: relative; z-index: 2; display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; min-height: 56px; padding: 0 12px; }
.rcvControls .btn { animation: pop .5s cubic-bezier(.3, 1.6, .5, 1) both; }
.rcvFoot { position: relative; z-index: 2; display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 10px; padding: 14px 18px max(14px, env(safe-area-inset-bottom)); }
.makeOwn { justify-self: start; color: #fff; background: var(--ink); text-decoration: none; padding: 8px 12px; font-weight: 700; box-shadow: 3px 3px 0 var(--pink); }
.makeOwn:hover { background: var(--pink); box-shadow: 3px 3px 0 var(--ink); }
.madeBy { font-size: .78rem; color: #fff; text-shadow: 1px 1px 0 var(--ink); background: rgba(27, 19, 48, .45); padding: 3px 8px; }
.privBtn { justify-self: end; border: 0; background: #fff; padding: 7px 12px; box-shadow: 0 0 0 2px var(--ink), 3px 3px 0 2px var(--ink); font-size: .85rem; font-weight: 600; }
.rcvClose { position: absolute; top: 14px; right: 14px; z-index: 3; width: 44px; height: 44px; border: 0; background: #fff; box-shadow: 0 0 0 3px var(--ink), 4px 4px 0 3px var(--ink); font-size: 18px; font-weight: 700; }

/* envelope */
.envScene { display: flex; flex-direction: column; align-items: center; gap: 22px; }
.envWrap { position: relative; width: var(--ew); height: calc(var(--ew) * .62); perspective: 1400px; }
.env { position: absolute; inset: 0; transform-style: preserve-3d; cursor: pointer; }
.envFace { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.envFront {
  background: #f8ecd2; box-shadow: 0 0 0 5px var(--ink), 10px 10px 0 5px rgba(0, 0, 0, .3);
  overflow: hidden;
}
.airmail { position: absolute; inset: 0; background: repeating-linear-gradient(-45deg, #e0303f 0 16px, #f8ecd2 16px 24px, #2b6fd6 24px 40px, #f8ecd2 40px 48px); }
.paperIn { position: absolute; inset: 12px; background: #f8ecd2; box-shadow: 0 0 0 3px var(--ink); }
.eStamp { position: absolute; top: 8%; right: 6%; width: 18%; transform: rotate(4deg); filter: drop-shadow(3px 3px 0 rgba(0, 0, 0, .2)); }
.postmark { position: absolute; top: 9%; right: 13%; width: 34%; opacity: 0; transform: rotate(-14deg); mix-blend-mode: multiply; }
.addr { position: absolute; left: 10%; bottom: 14%; right: 10%; font-size: calc(var(--ew) * .05); }
.fromLbl { font-family: 'Press Start 2P'; font-size: .45em; opacity: .7; margin-bottom: 4px; }
.fromName { display: block; min-height: 1.2em; font-size: 1.9em; line-height: 1.1; border-bottom: 3px dashed rgba(27, 19, 48, .35); padding-bottom: 4px; }
.fromName:not(.done)::after { content: '▌'; animation: blink .6s steps(2) infinite; }
.toLbl { margin-top: 10px; font-weight: 700; }
.envBack { transform: rotateY(180deg); background: #f2dfb8; box-shadow: 0 0 0 5px var(--ink), -10px 10px 0 5px rgba(0, 0, 0, .3); perspective: 900px; }
.envInside { position: absolute; inset: 0; background: repeating-linear-gradient(90deg, #d84f6a 0 10px, #e86a82 10px 20px); }
.envCard { position: absolute; left: 50%; top: 10%; width: 36%; aspect-ratio: 3 / 4; margin-left: -18%; z-index: 2; box-shadow: 0 0 0 3px var(--ink); background: #fff; }
.envCard canvas { width: 100%; height: 100%; display: block; }
.envPocket { position: absolute; inset: 0; z-index: 3; background: #f2dfb8; }
.envPocket::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 60%, rgba(0, 0, 0, .06)); }
.flapWrap { position: absolute; inset: 0; z-index: 4; transform-style: preserve-3d; }
.flapWrap.behind { z-index: 1; }
.envFlap { position: absolute; inset: 0 0 auto 0; height: 100%; background: #e8d0a0; transform-origin: top center; filter: drop-shadow(0 3px 0 var(--ink)); }
.envFlap::after { content: ''; position: absolute; left: 50%; top: 50%; width: 9%; aspect-ratio: 1; margin: -4.5% 0 0 -4.5%; background: #e0303f; box-shadow: 0 0 0 3px #a01828; border-radius: 30%; }
.stampTool { position: absolute; top: -6%; right: 6%; width: 20%; opacity: 0; transform-origin: bottom center; z-index: 5; filter: drop-shadow(4px 6px 0 rgba(0, 0, 0, .25)); }
.puff { position: absolute; top: 4%; right: 2%; width: 30%; aspect-ratio: 1; z-index: 6; pointer-events: none;
  background: radial-gradient(circle, #fff 0 6px, transparent 7px) 0 0 / 22px 22px; animation: puff .6s ease-out forwards; }
@keyframes puff { from { transform: scale(.4); opacity: 1; } to { transform: scale(1.5); opacity: 0; } }
.tapHint { border: 0; background: var(--sun); padding: 10px 18px; font-weight: 700; font-size: 1.05rem; box-shadow: 0 0 0 3px var(--ink), 4px 4px 0 3px var(--ink); animation: pulse 1s ease-in-out infinite; }

/* big card */
.cardScene { display: flex; flex-direction: column; align-items: center; gap: 22px; }
.card3d.big { --cw: inherit; }
.prog { display: flex; align-items: center; gap: 14px; transition: opacity .4s; width: var(--cw); }
.prog.gone { opacity: 0; pointer-events: none; }
.progBar { flex: 1; height: 16px; background: #fff; box-shadow: 0 0 0 3px var(--ink); padding: 3px; }
.progBar i { display: block; height: 100%; width: 0; background: repeating-linear-gradient(90deg, var(--pink) 0 8px, #ff9ec0 8px 12px); }
.broken { text-align: center; max-width: 420px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.broken h2 { font-family: 'Press Start 2P'; font-size: 16px; line-height: 1.5; }
.sadFace { width: 96px; height: 96px; }

/* ---------------- modal & toast ---------------- */
.modal { position: fixed; inset: 0; z-index: 90; background: rgba(27, 19, 48, .6); display: grid; place-items: center; padding: 20px; }
.modalBox { position: relative; background: #fff; max-width: 560px; max-height: 86vh; overflow: auto; padding: 26px 28px; box-shadow: 0 0 0 4px var(--ink), 10px 10px 0 4px var(--pink); animation: pop .4s cubic-bezier(.3, 1.5, .5, 1); }
.modalBox h2 { font-family: 'Press Start 2P'; font-size: 16px; margin-top: 0; }
.modalBox li { margin-bottom: 8px; }
.modalBox .small { font-size: .85rem; opacity: .7; }
.modalX { position: absolute; top: 10px; right: 10px; border: 0; background: var(--sun); width: 36px; height: 36px; box-shadow: 0 0 0 3px var(--ink); font-weight: 700; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 99; background: var(--ink); color: #fff; padding: 12px 18px; font-weight: 700; box-shadow: 4px 4px 0 var(--pink); }
.toast.show { animation: toastIn .35s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes toastIn { from { transform: translate(-50%, 30px); opacity: 0; } }

/* ---------------- responsive ---------------- */
@media (max-width: 1000px) {
  .editor { grid-template-columns: 1fr; }
  .previewPanel { position: relative; top: 0; order: -1; }
  .share { grid-template-columns: 1fr; }
  .stepDot span { display: none; }
  .stepDot.on span { display: inline; }
}
@media (max-width: 560px) {
  .topbar { padding: 10px 14px; gap: 10px; }
  .logo { font-size: 12px; }
  .editor { padding: 18px 12px; }
  .panel { padding: 16px; }
  .stepWrap h2 { font-size: 14px; }
  .g5 { grid-template-columns: repeat(3, 1fr); }
  .g3 { grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
  .rcvFoot { grid-template-columns: 1fr 1fr; }
  .madeBy { grid-column: 1 / -1; grid-row: 2; justify-self: center; }
}
@media (prefers-reduced-motion: reduce) {
  .floaty, .rcvBg, .playBtn, .hint, .msg.anim .ch { animation: none !important; }
}

/* ---------------- install / PWA ---------------- */
.installBtn { white-space: nowrap; background: var(--mint); }
.installLink { margin-top: 16px; border: 0; background: rgba(255, 255, 255, .85); padding: 8px 14px; font-weight: 700; box-shadow: 0 0 0 3px var(--ink), 3px 3px 0 3px var(--ink); }
.kbd { display: inline-flex; align-items: center; gap: 4px; padding: 1px 6px; background: #eef3ff; box-shadow: 0 0 0 2px var(--ink); font-weight: 700; color: #1f5fbf; }
#installSteps ol { padding-left: 1.3em; } #installSteps li { margin-bottom: 10px; line-height: 1.5; }
body.standalone .appfoot { padding-bottom: max(20px, env(safe-area-inset-bottom)); }
@media (max-width: 1000px) { .topbar { justify-content: space-between; } .stepper { order: 3; flex-basis: 100%; justify-content: center; } }
@media (max-width: 560px) { .installBtn { font-size: .75rem; padding: .35em .6em; } .stepDot { padding: 4px; } .stepDot.on { padding-right: 8px; } }
@media (max-width: 700px) {
  .previewPanel { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "stage head" "stage play"; gap: 12px; padding: 12px; align-items: center; }
  .previewHead { grid-area: head; flex-direction: column; align-items: stretch; gap: 8px; }
  .previewHead h3 { font-size: 11px; text-align: center; }
  .seg { flex-direction: column; }
  .previewStage { grid-area: stage; --cw: min(118px, 30vw); min-height: calc(var(--cw) * 4 / 3 + 24px); padding: 12px 0; }
  #playFull { grid-area: play; font-size: .85rem; padding: .6em .7em; }
}
