:root {
  --red: #cf2f3a;
  --red-deep: #9e1c27;
  --accent: #22201f; /* soft black: lettering + buttons on cream */
  --accent-deep: #0f0e0e;
  --cream: #fdf8e6;
  --ink: #4b2a26;
  --hand: "Caveat", cursive;
  --type: "Special Elite", "Courier New", monospace;
  --type-ink: #2a2321;
  --paper-noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.45 0 0 0 0 0.36 0 0 0 0 0.3 0 0 0 0.16 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: var(--cream); color: var(--ink); font: 500 20px/1.3 var(--hand); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.paper, .paper-bg { background-color: var(--cream); background-image: var(--paper-noise); background-blend-mode: multiply; }

/* ---- full-screen stage ---- */
#stage, #ui { position: fixed; inset: 0; width: 100vw; height: 100vh; object-fit: cover; display: block; }
#ui { pointer-events: none; z-index: 4; }

.hand-note { margin: 8px 0 0; font: 500 21px/1.2 var(--hand); color: var(--accent); opacity: .85; }

/* ---- buttons (handwritten labels) ---- */
.btn-red, .btn-line, .btn-text {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  font: 700 26px/1 var(--hand);
  border-radius: 999px; padding: 12px 30px 14px;
  transition: transform .12s, background .15s;
}
.btn-red { background: var(--accent); color: var(--cream); border: 0; box-shadow: 0 8px 22px -8px rgba(34, 32, 31, .55); }
.btn-red:hover { background: var(--accent-deep); transform: translateY(-1px) rotate(-1deg); }
.btn-red.small, .btn-line, .btn-text { font-size: 23px; padding: 8px 20px 10px; }
.btn-line { background: transparent; color: var(--accent); border: 1.5px solid var(--accent); }
.btn-line:hover { background: rgba(34, 32, 31, .07); transform: rotate(1deg); }
.btn-text { background: transparent; border: 0; color: var(--accent); text-decoration: underline wavy; text-underline-offset: 6px; text-decoration-thickness: 1px; }
button:disabled { opacity: .45; cursor: default; }

/* ---- start screen ---- */
#startScreen { position: fixed; inset: 0; z-index: 20; }
body.running #startScreen { display: none; }
#startArt { position: absolute; inset: 0; width: 100%; height: 100%; }
.has-landing-art #startScreen { background-image: url("/assets/watercolor-paper-wide.jpg"), var(--paper-noise); background-size: cover, auto; }
.landing-art { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; display: none; }
.has-landing-art .landing-art.wide:not(.still) { display: block; }
.has-landing-art.no-alpha-video .landing-art.wide:not(.still), .has-landing-art.landing-still .landing-art.wide:not(.still) { display: none; }
.has-landing-art.no-alpha-video .landing-art.wide.still, .has-landing-art.landing-still .landing-art.wide.still { display: block; }
@media (max-aspect-ratio: 1/1) {
  .has-landing-art .landing-art.wide { display: none !important; }
  .has-landing-art .landing-art.tall:not(.still) { display: block; }
  .has-landing-art.no-alpha-video .landing-art.tall:not(.still), .has-landing-art.landing-still .landing-art.tall:not(.still) { display: none; }
  .has-landing-art.no-alpha-video .landing-art.tall.still, .has-landing-art.landing-still .landing-art.tall.still { display: block; }
}
.typed-sub { position: absolute; left: 50%; top: 50%; transform: translateX(-50%); margin: 0; width: min(760px, 90vw); text-align: center; font: 400 clamp(17px, 1.7vw, 23px)/1.4 var(--type); color: var(--type-ink); letter-spacing: .02em; }
.typed-sub::after { content: "▍"; opacity: .7; animation: blink 1s steps(1) infinite; }
.typed-sub.done::after { content: ""; }
.start-controls { position: absolute; left: 50%; top: 58%; transform: translateX(-50%); width: min(560px, 90vw); display: grid; justify-items: center; text-align: center; animation: appear .6s ease 4.2s both; }
@keyframes appear { from { opacity: 0; translate: 0 8px; } }
.to-line {
  display: flex; align-items: baseline; justify-content: center; gap: 12px;
  width: min(300px, 78vw); border-bottom: 1.5px solid var(--red);
  font: 400 22px var(--type); color: var(--type-ink);
  border-bottom-color: var(--type-ink);
}
.to-line input { border: 0; outline: 0; background: transparent; width: 100%; min-width: 0; font: 400 22px var(--type); color: var(--type-ink); padding: 0 0 4px; }
.to-line input::placeholder { color: rgba(42, 35, 33, .35); }
.start-controls .btn-red { margin-top: 22px; }
.start-controls .hand-note { font: 400 14px var(--type); color: var(--type-ink); opacity: .65; margin-top: 12px; }
/* phones: the stickers come close, so the small print sits on a strip of paper */
@media (max-width: 520px) { .start-controls .hand-note { font-size: 12px; opacity: 1; color: rgba(34, 32, 31, .7); background: rgba(251, 246, 236, .92); border-radius: 999px; padding: 3px 12px; display: inline-block; } }

/* ---- camera overlay chrome ---- */
.chrome { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.chrome .dock, .chrome .dock *, .chrome .names, .chrome .names * { pointer-events: auto; }
body.clean .chrome .dock, body.clean .chrome .hints, body.clean .chrome .names { opacity: 0; }
body.clean .chrome .dock *, body.clean .chrome .names * { pointer-events: none; }
body:not(.running) .chrome { display: none; }

/* to / from: small cream paper tags, top-right */
.names { position: absolute; top: 18px; right: 18px; display: flex; gap: 8px; }
.tag {
  display: inline-flex; align-items: baseline; gap: 8px;
  padding: 4px 14px 6px; border-radius: 999px;
  background: rgba(253, 248, 230, 0.9);
  box-shadow: 0 4px 16px rgba(60, 20, 20, 0.16);
  font: 400 16px var(--type); color: var(--type-ink);
}
.tag input { border: 0; outline: 0; background: transparent; width: 104px; font: 400 16px var(--type); color: var(--type-ink); }
.tag input::placeholder { color: rgba(42, 35, 33, .4); }

.rec { position: absolute; top: 74px; right: 22px; display: none; align-items: center; gap: 8px; color: #fffdf6; font: 700 22px var(--hand); text-shadow: 0 1px 5px rgba(0,0,0,.55); }
.rec i { width: 10px; height: 10px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 2px #fffdf6; animation: blink 1s infinite; }
body[data-state="recording"] .rec { display: inline-flex; }
body[data-state="booth"] .hints { visibility: hidden; } /* the photo thumbnails use that space */
@keyframes blink { 50% { opacity: .2; } }

#flash { position: absolute; inset: 0; background: #fffdf6; opacity: 0; }
#flash.go { animation: flash .5s ease-out; }
@keyframes flash { from { opacity: .95; } to { opacity: 0; } }

#toast { position: absolute; left: 50%; bottom: 90px; transform: translate(-50%, 8px); opacity: 0; transition: .25s; color: #fffdf6; font: 700 28px var(--hand); text-shadow: 0 1px 6px rgba(0,0,0,.6); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* live mini photo strip while the booth runs */
#thumbs { position: absolute; left: 50%; bottom: 76px; transform: translateX(-50%) rotate(-1deg); display: flex; gap: 5px; padding: 6px; background: #fffdf7; box-shadow: 0 6px 18px rgba(0,0,0,.28); }
#thumbs:empty { display: none; }
#thumbs .thumb { width: 92px; aspect-ratio: 16/9; background: #e9e1d4; display: grid; place-items: center; overflow: hidden; color: rgba(34, 32, 31, .5); font: 700 20px var(--hand); }
#thumbs .thumb.filled { animation: develop 1.2s ease-out; }
#thumbs img { width: 100%; height: 100%; object-fit: cover; display: block; }
@keyframes develop { from { filter: brightness(2.2) saturate(0); } }

/* bottom controls: just handwriting, no boxes */
/* controls on the bottom row; the hints sit to their right, or wrap above them when there isn't room */
.bottombar { position: absolute; left: 22px; right: 22px; bottom: 14px; display: flex; flex-wrap: wrap-reverse; align-items: flex-start; /* (wrap-reverse: start = bottom) */ justify-content: space-between; gap: 10px 32px; }
.dock { display: flex; gap: 6px 22px; align-items: baseline; flex-wrap: wrap; }
.ghost {
  background: none; border: 0; padding: 4px 0; cursor: pointer;
  color: #fffdf6; font: 700 27px var(--hand);
  text-shadow: 0 1px 6px rgba(0, 0, 0, .55);
  text-decoration: none;
}
button.ghost:hover:not(:disabled) { text-decoration: underline wavy rgba(255, 253, 246, .8); text-underline-offset: 6px; }
.ghost.select { cursor: default; }
.ghost select { background: none; border: 0; outline: 0; color: #fffdf6; font: 700 27px var(--hand); text-shadow: 0 1px 6px rgba(0,0,0,.55); cursor: pointer; appearance: none; -webkit-appearance: none; padding: 0; field-sizing: content; }
.ghost.select::after { content: '▾'; margin-left: 2px; font-size: .7em; } /* keep the arrow next to the words */
.ghost select option { color: var(--ink); text-shadow: none; }
.ghost.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.ghost.check input { accent-color: #cf2f3a; width: 18px; height: 18px; }

.hints {
  margin-left: auto; max-width: 560px;
  text-align: right; color: #fffdf6;
  font: 500 18px/1.25 var(--hand);
  text-shadow: 0 1px 5px rgba(0, 0, 0, .55);
}
.hints p { margin: 0; }
.hints-more { display: none; border: 0; background: none; padding: 0 0 0 4px; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; }
@media (hover: none) { .hints .keys { display: none; } } /* no keyboard on phones and tablets */
/* phones: one line of hints until you ask for more */
@media (max-width: 520px) {
  .hints-more { display: inline; }
  .hints:not(.open) p:not(:first-child):not(#modelNote) { display: none; }
}
.inapp-note { margin: 0 0 4px; max-width: 320px; font: 400 13px/1.4 var(--type); color: var(--type-ink); background: rgba(251, 246, 236, .94); border-radius: 12px; padding: 8px 12px; }
.inapp-note .btn-text { font: inherit; text-decoration: underline; padding: 0; }
.hints b { font: 600 13px system-ui, sans-serif; border: 1px solid rgba(255, 253, 246, .8); border-radius: 4px; padding: 0 4px; }

/* ---- result ---- */
#cardStage {
  position: fixed; inset: 0; z-index: 30;
  display: grid; grid-template-rows: 1fr auto; justify-items: center; align-items: center;
  padding: 28px 20px 26px;
  background: rgba(253, 250, 244, 0.86);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
}
.card-scene { perspective: 1800px; width: 100%; height: 100%; display: grid; place-items: center; min-height: 0; }
.card {
  --rx: 0deg; --ry: 0deg;
  position: relative;
  width: min(44vw, 640px, calc((100vh - 200px) * 1.25));
  aspect-ratio: 5 / 4;
  transform-style: preserve-3d;
  transform: translateX(0) rotateX(var(--rx)) rotateY(var(--ry));
  transition: transform .9s cubic-bezier(.3, .7, .2, 1);
}
.card.open { transform: translateX(50%) rotateX(var(--rx)) rotateY(var(--ry)); }
.card .paper { background-image: url("/assets/watercolor-paper.jpg"), var(--paper-noise); background-size: cover, auto; }
/* watercolor art layers (clip + still), behind the canvas that writes titles and notes */
.art-paint { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
/* the clips play out of sight and get painted into a canvas in their place (src/cardart.js) */
video.art-paint, video.landing-art { display: none !important; }
img.art-paint { display: none; }
img.art-paint:not([src]), img.art-paint[src=""] { display: none !important; }
img.art-paint.always, .no-alpha-video img.art-paint { display: block; }
.no-alpha-video .art-canvas { display: none; }
.card .paper { border-radius: 3px; box-shadow: 0 34px 60px -24px rgba(90, 40, 30, .45), 0 2px 6px rgba(90, 40, 30, .14); }
.page { position: absolute; inset: 0; }
.art { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.cover { position: absolute; inset: 0; transform-origin: left center; transform-style: preserve-3d; transition: transform 1s cubic-bezier(.3, .7, .2, 1); cursor: pointer; }
.card.open .cover { transform: rotateY(-178deg); }
.face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; overflow: hidden; }
.face.back { transform: rotateY(180deg); }
.cover-media { position: absolute; left: 14%; right: 14%; top: 10%; aspect-ratio: 16 / 9; }
.cover-media .media-title { position: absolute; inset: 7px; width: calc(100% - 14px); height: calc(100% - 14px); pointer-events: none; transform: rotate(-1.2deg); }
.cover-media video {
  width: 100%; height: 100%; object-fit: cover; display: block;
  border: 7px solid #fffdf7; box-shadow: 0 6px 16px rgba(90, 40, 30, .22);
  transform: rotate(-1.2deg);
}

/* the photo strip as a physical object */
.strip-view { --rx: 0deg; --ry: 0deg; width: auto; transform: rotate(-1.5deg) rotateX(var(--rx)) rotateY(var(--ry)); transform-style: preserve-3d; transition: transform .2s ease-out; animation: slidein .9s cubic-bezier(.2, .8, .2, 1); }
.strip-view { position: relative; }
.strip-view video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.strip-view img { width: auto; max-width: 92vw; max-height: calc(100vh - 150px); display: block; box-shadow: 0 30px 50px -20px rgba(90, 40, 30, .5), 0 2px 6px rgba(90, 40, 30, .15); }
@keyframes slidein { from { translate: 0 60vh; rotate: 8deg; } }

.card-bar { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; align-items: center; margin-top: 18px; }

.note-panel, .note-panel { left: 50%; bottom: 96px; transform: translateX(-50%); width: min(460px, calc(100vw - 40px)); display: grid; gap: 10px; }
.note-panel textarea { width: 100%; resize: none; border: 0; border-bottom: 1.5px solid rgba(34, 32, 31, .4); background: transparent; font: 600 26px/1.3 var(--hand); color: var(--ink); outline: none; }
.panel-h { margin: 0; font: 700 34px var(--hand); color: var(--accent); }
.row { display: flex; gap: 10px; }
.mini { display: grid; gap: 3px; font: 600 18px var(--hand); }
.mini input { width: 110px; padding: 4px 10px; border-radius: 8px; border: 1.5px solid rgba(34, 32, 31, .3); background: #fffdf6; font: 600 20px var(--hand); }
progress { width: 100%; height: 8px; accent-color: var(--accent); }

#mailRoom { position: fixed; inset: 0; z-index: 40; display: grid; grid-template-rows: 1fr auto auto; justify-items: center; align-items: center; padding: 20px 20px 26px; background: rgba(250, 244, 234, 0.94); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); }
.mail-frame { width: 100%; height: 100%; position: relative; overflow: hidden; }
#envFrame { position: absolute; left: 50%; top: 50%; width: 1920px; height: 1080px; border: 0; background: transparent; transform-origin: 0 0; }

.share-panel { display: grid; justify-items: center; gap: 6px; margin-top: 6px; }
.share-status { margin: 0; font: 400 16px var(--type); color: var(--type-ink); }
.share-links { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.share-links li { display: flex; align-items: center; gap: 12px; padding: 6px 12px; border-radius: 10px; background: rgba(255, 253, 246, .8); box-shadow: 0 4px 14px rgba(90, 40, 30, .1); }
.share-links .for { font: 700 24px var(--hand); color: var(--accent); min-width: 90px; }
.share-links a { font: 400 14px var(--type); color: var(--type-ink); }
.share-links .btn-line.small { font-size: 18px; padding: 3px 14px 5px; }

@media (max-width: 860px) {
  .bottombar { left: 16px; right: 16px; bottom: 10px; }
  .dock { gap: 4px 16px; }
  .ghost, .ghost select { font-size: 23px; }
  .hints { margin-left: 0; text-align: left; font-size: 15px; max-width: none; }
  .card { width: min(80vw, calc((100vh - 260px) * 1.25)); }
  .card.open { transform: translateX(0) rotateX(var(--rx)) rotateY(var(--ry)); }
  }
