/* ---------- fonts (self-hosted, SIL Open Font License: see fonts/OFL-*.txt) ---------- */
@font-face { font-family: "Fraunces"; src: url("../fonts/fraunces.woff2") format("woff2"); font-weight: 300 700; font-style: normal; font-display: swap; }
@font-face { font-family: "Fraunces"; src: url("../fonts/fraunces-italic.woff2") format("woff2"); font-weight: 300 700; font-style: italic; font-display: swap; }
@font-face { font-family: "Caveat"; src: url("../fonts/caveat.woff2") format("woff2"); font-weight: 400 700; font-style: normal; font-display: swap; }

:root {
  --sky: #0B1426; --sky-2: #16233F; --sky-3: #1C2B4D;
  --cream: #F4EBDD; --muted: #AEB6C8; --gold: #E8B65A; --gold-2: #F6CF7F; --berry: #C8323C;
  --paper: #FBF8F2; --ink: #2A3049;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --script: "Caveat", "Segoe Script", cursive;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { overflow: hidden; font-family: var(--sans); color: var(--cream); -webkit-user-select: none; user-select: none;
  background: radial-gradient(60vmax 40vmax at 85% 0%, rgba(120,150,220,.16), transparent 60%), linear-gradient(180deg, var(--sky) 0%, var(--sky-2) 65%, var(--sky-3) 100%) fixed; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, canvas:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; }
[hidden] { display: none !important; }

/* ---------- the night: snow and fairy lights ---------- */
#snow { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }
#lights { position: fixed; left: 0; right: 0; top: 0; height: 90px; z-index: 2; pointer-events: none; }
#lights svg { position: absolute; left: 0; top: 0; overflow: visible; }
.bulb { position: absolute; width: 9px; height: 15px; margin-left: -4.5px; transform-origin: 50% 0; border-radius: 45% 45% 50% 50% / 35% 35% 65% 65%;
  background: radial-gradient(circle at 40% 60%, #fff 0 12%, var(--c) 45%);
  box-shadow: 0 0 8px 2px color-mix(in srgb, var(--c) 75%, transparent), 0 0 24px 8px color-mix(in srgb, var(--c) 30%, transparent);
  animation: twinkle var(--t, 3s) ease-in-out var(--d, 0s) infinite alternate; }
.bulb::before { content: ""; position: absolute; left: 1.5px; top: -4px; width: 6px; height: 5px; border-radius: 1.5px; background: #3A4360; }
@keyframes twinkle { 0% { opacity: 1; filter: brightness(1.1); } 60% { opacity: .85; } 100% { opacity: .4; filter: brightness(.7); } }
#lights.fast .bulb { animation-duration: .55s; }
#lights.flash .bulb { animation: flashb .5s ease-out; }
@keyframes flashb { 0% { opacity: 1; filter: brightness(2.2); } 100% { opacity: 1; filter: brightness(1); } }

/* ---------- page: intro | hanging strip | lyric ---------- */
#page { position: relative; z-index: 1; overflow-x: clip; height: 100vh; height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  justify-content: center; align-items: center; gap: clamp(24px, 4vw, 70px); padding: 70px clamp(20px, 4vw, 64px) 20px; transition: opacity .5s; }
.intro { display: flex; flex-direction: column; gap: 16px; justify-self: end; width: min(100%, 350px); }
.brand { display: flex; align-items: center; gap: 7px; font-size: 13px; letter-spacing: .08em; text-transform: lowercase; color: var(--muted); }
.flake { width: 15px; height: 15px; color: var(--muted); flex: none; }
.flake.gold { color: var(--gold); }
h1 { margin: 0; font-family: var(--serif); font-style: italic; font-weight: 400; font-size: clamp(40px, 4.4vw, 66px); line-height: .98; letter-spacing: -.015em; font-variation-settings: "opsz" 144; }
h1 .l { display: block; }
h1.long { font-size: clamp(34px, 3.7vw, 56px); }
.script { margin: -6px 0 0; font-family: var(--script); font-size: 26px; line-height: 1.1; color: var(--gold); }
.script:empty { display: none; }
.sub { margin: 0; font-size: 15px; line-height: 1.55; color: var(--muted); max-width: 33ch; }
.sub:empty { display: none; }
.controls { display: flex; align-items: center; gap: 10px 12px; flex-wrap: wrap; margin-top: 4px; }
.btn { border: 0; border-radius: 999px; padding: 12px 24px; font-weight: 650; font-size: 16px; letter-spacing: .01em;
  background: var(--gold); color: var(--sky); display: inline-flex; align-items: center; gap: .4em; transition: box-shadow .25s, background .25s; }
.btn:hover { background: var(--gold-2); box-shadow: 0 0 26px rgba(232,182,90,.45); }
.btn:active { transform: translateY(2px); }
.btn[disabled] { opacity: .4; cursor: default; box-shadow: none; }
.btn.ghost { background: transparent; color: var(--cream); box-shadow: inset 0 0 0 1.5px rgba(244,235,221,.7); }
.btn.ghost:hover { box-shadow: inset 0 0 0 1.5px var(--cream), 0 0 20px rgba(244,235,221,.15); }
.btn.link { background: transparent; color: var(--cream); text-decoration: underline; text-underline-offset: 4px; padding-left: 6px; padding-right: 6px; }
.btn.link:hover { box-shadow: none; color: var(--gold-2); }
.hg { display: inline-block; height: .85em; width: auto; fill: var(--berry); }
#hint { font-family: var(--script); font-size: 21px; color: var(--muted); min-height: 24px; }
#linkTxt { margin: 0; font-size: 12px; line-height: 1.4; color: var(--muted); word-break: break-all; -webkit-user-select: text; user-select: text; max-width: 40ch;
  padding: 9px 12px; border-radius: 10px; background: rgba(255,255,255,.06); box-shadow: inset 0 0 0 1px rgba(244,235,221,.15); }

/* ---------- the strip: torn photo paper ---------- */
.booth { position: relative; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: center; min-height: 0; }
.hang { position: relative; filter: drop-shadow(0 14px 26px rgba(0,0,0,.45)) drop-shadow(0 1px 1px rgba(0,0,0,.3)); }
/* the clip-path for the torn edge is set by tearStrip() in scene.js; height is about 1.98 x width */
.bstrip { --sw: min(calc((100vh - 110px) / 1.98), 44vw); --sw: min(calc((100dvh - 110px) / 1.98), 44vw);
  width: var(--sw); padding: calc(var(--sw) * .063); display: flex; flex-direction: column; gap: calc(var(--sw) * .034);
  background-color: #F3F1EC;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .42 0 0 0 0 .38 0 0 0 0 .33 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
  box-shadow: inset 0 0 calc(var(--sw) * .03) rgba(120,110,95,.18); }
.slot { position: relative; aspect-ratio: 2 / 1; background: #141210; box-shadow: 0 0 0 1px rgba(20,18,16,.35); overflow: hidden; }
.slot > canvas { position: absolute; inset: 0; width: 100%; height: 100%; transition: filter 1.6s ease-out; }
.slot > canvas.fresh { filter: brightness(2.4) contrast(.25); transition: none; }
.frame { position: absolute; inset: 0; z-index: 1; background: #141210; overflow: hidden; }
.half { position: absolute; top: 0; bottom: 0; width: 50%; overflow: hidden; }
.half.l { left: 0; } .half.r { right: 0; }
.half video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1);
  filter: sepia(.18) saturate(.92) contrast(1.05) brightness(.97); opacity: 0; transition: opacity .6s; }
.half.live video { opacity: 1; }
.half .still { position: absolute; inset: 0; width: 100%; height: 100%; display: none; }
.half.has-still .still { display: block; }
.half.has-still video { opacity: 0; }
.empty { position: absolute; inset: calc(var(--sw) * .03); border: 1px dashed rgba(255,255,255,.3);
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: calc(var(--sw) * .1); text-align: center;
  font-family: var(--sans); font-weight: 500; letter-spacing: -.01em; font-size: clamp(12px, calc(var(--sw) * .038), 18px); color: rgba(255,255,255,.85); }
.half.live .empty, .half.has-still .empty { display: none; }
.waiting .half.r .empty { animation: breathe 2.4s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .4; } }
.seam { position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; margin-left: -.5px; background: rgba(243,241,236,.45); z-index: 2; pointer-events: none; }
#grain { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .1; mix-blend-mode: overlay; pointer-events: none; z-index: 3; }
.vig { position: absolute; inset: 0; pointer-events: none; z-index: 3; background: radial-gradient(80% 75% at 50% 45%, rgba(0,0,0,0) 62%, rgba(5,10,30,.3) 100%); }
#count { position: absolute; right: 8px; top: 4px; z-index: 5; font-family: var(--script); font-weight: 700; font-size: clamp(14px, calc(var(--sw) * .07), 24px); color: rgba(255,255,255,.9); opacity: 0; transition: opacity .3s; }
.live #count { opacity: 1; }
#bar { position: absolute; left: 0; bottom: 0; z-index: 5; height: 3px; width: 0; background: var(--gold); opacity: 0; }
.live #bar { opacity: .95; }
#big { position: absolute; inset: 0; z-index: 6; display: grid; place-items: center; font-family: var(--serif); font-style: italic; font-size: calc(var(--sw) * .36); color: #fff; opacity: 0; pointer-events: none; text-shadow: 0 6px 30px rgba(0,0,0,.5); }
#big.pop { animation: pop .78s ease-out; }
@keyframes pop { 0% { opacity: 0; transform: scale(1.25); } 22% { opacity: 1; transform: scale(1); } 78% { opacity: 1; } 100% { opacity: 0; } }
#sflash { position: absolute; inset: 0; z-index: 7; background: #fff; opacity: 0; pointer-events: none; }
#sflash.go { animation: fl .45s ease-out; }
@keyframes fl { 0% { opacity: 0; } 10% { opacity: 1; } 100% { opacity: 0; } }
#flash { position: fixed; inset: 0; z-index: 30; background: #FFF6E6; opacity: 0; pointer-events: none; }
#flash.go { animation: fl2 .5s ease-out; }
@keyframes fl2 { 0% { opacity: 0; } 10% { opacity: .45; } 100% { opacity: 0; } }

/* the paper heart that folds across the middle */
#heartWrap, #heartGuide { position: absolute; left: 50%; top: calc(var(--hy, .6) * 100%); height: calc(var(--hs, .3) * 100%); aspect-ratio: 1; translate: -50% -50%; pointer-events: none; }
#heartGuide { top: calc(var(--gy, .6) * 100%); height: calc(var(--gs, .3) * 100%); z-index: 5; opacity: 0; transition: opacity .25s; filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); }
#heartGuide.on { opacity: 1; }
#heartGuide svg { width: 100%; height: 100%; overflow: visible; }
#heartWrap { z-index: 6; opacity: 0; transition: opacity .3s; }
#heartWrap.on { opacity: 1; }
#heartC { position: absolute; inset: 0; width: 100%; height: 100%; display: none; filter: drop-shadow(0 6px 8px rgba(0,0,0,.3)); }
#heartWrap.vid #heartC { display: block; }
#heartWrap.vid .ph { display: none; }
.ph { position: absolute; inset: 0; perspective: 700px; filter: drop-shadow(0 6px 8px rgba(0,0,0,.35)); }
.ph svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.ph .hr { transform-origin: 50% 50%; }
#heartWrap.on .ph .hr { animation: fold 1.25s cubic-bezier(.65,0,.3,1) .3s forwards; }
@keyframes fold { 0% { transform: rotateY(0); filter: brightness(1); } 50% { filter: brightness(.7); } 100% { transform: rotateY(-180deg); filter: brightness(1.1); } }

/* ---------- lyric cue ---------- */
.side { justify-self: start; width: min(100%, 330px); }
.track { display: flex; flex-direction: column; align-items: flex-start; gap: 14px; width: 100%; }
.track.hide { display: none; }
.tl { font-family: var(--script); font-weight: 600; font-size: clamp(32px, 3vw, 48px); line-height: 1.05; color: var(--cream); max-width: 100%; overflow-wrap: anywhere; text-shadow: 0 2px 18px rgba(0,0,0,.35); }
.segs { display: flex; gap: 6px; width: min(100%, 240px); }
.segs i { flex: 1; height: 6px; border-radius: 3px; background: rgba(244,235,221,.16); overflow: hidden; }
.segs i b { display: block; height: 100%; width: 0; background: var(--gold); box-shadow: 0 0 10px rgba(232,182,90,.6); }

/* ---------- results: the clothesline ---------- */
.peg { position: absolute; z-index: 4; width: 11px; height: 34px; border-radius: 4px; background: linear-gradient(90deg, #B98653, #E3B887 50%, #A87442);
  box-shadow: 0 3px 6px rgba(0,0,0,.4); }
.peg::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; margin-left: -.5px; background: rgba(90,55,25,.4); }
.peg::after { content: ""; position: absolute; left: -2px; right: -2px; top: 13px; height: 3px; border-radius: 1px; background: #9AA1AE; }
#results { position: fixed; inset: 0; z-index: 20; display: grid; grid-template-columns: minmax(260px, 1fr) minmax(0, 1.3fr); align-items: center; gap: clamp(24px, 4vw, 70px);
  padding: 70px clamp(20px, 4vw, 64px) 24px; opacity: 0; transition: opacity .6s; color: var(--cream); }
body.done #page { opacity: 0; pointer-events: none; }
#results.show { opacity: 1; }
.rl { display: flex; flex-direction: column; gap: 16px; justify-self: end; width: min(100%, 380px); }
.rl h2 { margin: 0; font-family: var(--serif); font-style: italic; font-weight: 400; font-size: clamp(48px, 5.4vw, 80px); line-height: .95; }
.rl h2 .l { display: block; }
.acts { display: flex; flex-direction: column; gap: 12px; transition: opacity .6s; }
#results:not(.printed) .acts { opacity: 0; pointer-events: none; }
.pick { display: flex; align-items: center; gap: 12px; }
.pl { width: 52px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); flex: none; }
.acts button { border: 0; border-radius: 999px; padding: 11px 20px; font-weight: 650; font-size: 15px; }
.acts .solid { background: var(--gold); color: var(--sky); }
.acts .solid:hover { background: var(--gold-2); box-shadow: 0 0 24px rgba(232,182,90,.4); }
.acts .outline { background: transparent; box-shadow: inset 0 0 0 1.5px rgba(244,235,221,.7); }
.acts .plain { background: transparent; text-decoration: underline; text-underline-offset: 4px; padding-left: 6px; padding-right: 6px; }
.acts .row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.seg { display: inline-flex; padding: 3px; border-radius: 999px; box-shadow: inset 0 0 0 1.5px rgba(244,235,221,.35); max-width: 100%; }
.seg button { padding: 8px 14px; font-size: 13px; background: transparent; color: var(--cream); }
.seg button[aria-pressed="true"] { background: var(--cream); color: var(--sky); }
.fmtsize { font-size: 12px; color: var(--muted); margin: -2px 0 0 64px; }
#shareNote { font-family: var(--script); font-size: 20px; color: var(--muted); min-height: 22px; }
.pnote { margin: 0; font-family: var(--script); font-size: 22px; line-height: 1.2; color: var(--gold); min-height: 26px; }

.lineScene { position: relative; align-self: stretch; min-height: 0; cursor: default; }
.line { position: absolute; left: -10%; width: 120%; top: 2%; height: 34px; color: rgba(244,235,221,.5); overflow: visible; }
.feed { position: absolute; left: 50%; top: calc(2% + 16px); translate: -50% 0; }
.feed canvas { display: block; height: min(76vh, calc(100dvh - 150px)); width: auto; transform-origin: 50% 0; visibility: hidden; cursor: wait;
  filter: drop-shadow(0 18px 30px rgba(0,0,0,.45)); }
.feed canvas + canvas { position: absolute; left: 0; top: 0; }
.feed canvas.landed { cursor: zoom-in; }
.feed .peg { top: -12px; visibility: hidden; } .feed .peg.l { left: 22%; rotate: -4deg; } .feed .peg.r { right: 22%; rotate: 5deg; }

/* lightbox */
#light { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; gap: 28px; padding: 24px; background: rgba(8,14,28,.94); opacity: 0; transition: opacity .3s; }
#light.show { opacity: 1; }
#lightC { height: calc(100dvh - 48px); width: auto; max-width: 80vw; object-fit: contain; filter: drop-shadow(0 20px 30px rgba(0,0,0,.5)); cursor: zoom-out; }
#lightC.wide { height: auto; width: min(80vw, 1400px); max-height: calc(100dvh - 48px); }
.lacts { display: flex; flex-direction: column; gap: 10px; }
.lacts button { border: 0; border-radius: 999px; padding: 11px 20px; font-weight: 650; font-size: 15px; white-space: nowrap; }
#lightSave { background: var(--gold); color: var(--sky); }
#lightClose { background: transparent; color: var(--cream); box-shadow: inset 0 0 0 1.5px rgba(244,235,221,.7); }

#offlineBadge { position: fixed; left: 12px; bottom: 10px; z-index: 50; font-size: 12px; color: var(--muted); background: rgba(11,20,38,.85); padding: 6px 10px; border-radius: 999px; box-shadow: inset 0 0 0 1px rgba(244,235,221,.2); }

/* ---------- phones and portrait screens ---------- */
@media (max-width: 860px), (max-aspect-ratio: 1/1) {
  body { overflow: auto; }
  #lights { height: 60px; }
  #page { grid-template-columns: 1fr; grid-template-rows: auto auto auto; gap: 14px; padding: 54px 16px 16px; align-content: start; align-items: stretch; }
  .intro { gap: 8px; justify-self: stretch; width: auto; }
  .brand { display: none; }
  h1, h1.long { font-size: 30px; }
  h1 .l { display: inline; margin-right: .25em; }
  .script { font-size: 21px; margin: 0; }
  .sub { font-size: 13px; max-width: none; }
  .btn { padding: 11px 20px; font-size: 15px; }
  .bstrip { --sw: min(calc((100dvh - 280px) / 1.98), 84vw); }
  .booth { justify-content: flex-start; }
  .side { justify-self: stretch; width: auto; }
  .track { align-items: center; }
  .tl { text-align: center; font-size: 28px; }
  #results { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto; gap: 18px; padding: 54px 16px 24px; align-items: start; overflow: hidden auto; }
  .rl { gap: 10px; justify-self: stretch; width: auto; }
  .rl h2 { font-size: 36px; }
  .rl h2 .l { display: inline; margin-right: .25em; }
  .lineScene { height: min(118vw, 76dvh); order: -1; }   /* the strip arrives first, the controls follow below */
  .feed canvas { height: min(108vw, 70dvh); }
  #light { flex-direction: column; gap: 14px; }
  #lightC { height: calc(100dvh - 130px); max-width: 92vw; }
  #lightC.wide { width: 92vw; height: auto; }
  .lacts { flex-direction: row; }
}
@media (max-height: 560px) and (min-aspect-ratio: 1/1) { .sub, .brand { display: none; } h1 { font-size: 40px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; } }
