*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --app-width: 100vw;
  --app-height: 100dvh;
  --keyboard-offset: 0px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --surface-gap: clamp(10px, 3vw, 18px);
  --chat-card-width: min(420px, calc(var(--app-width) - (var(--surface-gap) * 2) - var(--safe-left) - var(--safe-right)));
}

html, body {
  height: 100%;
  height: 100dvh;
  width: 100%;
  background: #000;
  color: #e0e0e0;
  font-family: system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}

.stage {
  position: fixed;
  inset: 0;
  width: var(--app-width);
  height: var(--app-height);
  display: none;
}

canvas {
  width: var(--app-width);
  height: var(--app-height);
  display: block;
  touch-action: none;
}

.video-screen {
  position: fixed;
  inset: 0;
  width: var(--app-width);
  height: var(--app-height);
  display: none;
  background: #000;
  align-items: center;
  justify-content: center;
}

.video-screen video {
  max-width: 1080px;
  max-height: 2400px;
  width: 100%;
  height: 100%;
  object-fit: contain;
  z-index: 1;
}

.video-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  pointer-events: none;
  user-select: none;
  opacity: var(--video-overlay-opacity, 0.78);
  z-index: 2;
  display: none;
}

.video-skip {
  position: absolute;
  top: max(16px, calc(var(--safe-top) + 12px));
  right: max(16px, calc(var(--safe-right) + 12px));
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 20px;
  color: #fff;
  font-size: 14px;
  padding: 8px 20px;
  cursor: pointer;
  z-index: 10;
  transition: background 0.2s;
}
.video-skip:hover { background: rgba(255,255,255,0.25); }

.chat-screen {
  position: fixed;
  inset: 0;
  width: var(--app-width);
  height: var(--app-height);
  display: none;
  background: #0a0f0b;
}

#chatCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.chat-thread { display: none; }

/* The recovered fragment is given by holding, not awarded automatically. */
.give-ritual {
  --give-progress: 0;
  position: absolute;
  inset: 0;
  z-index: 8;
  display: none;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  opacity: 1;
  transition: opacity 300ms ease;
}
.give-ritual.is-active { display: block; }
.give-ritual.is-exiting { opacity: 0; }
.give-ritual__shade {
  position: absolute;
  inset: 0;
  background: rgba(3, 5, 4, 0.48);
  pointer-events: none;
}
.give-ritual__thread {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2px;
  height: 29%;
  transform: translateX(-50%) scaleY(var(--give-progress));
  transform-origin: top;
  background: linear-gradient(to bottom, rgba(255, 193, 126, .5), rgba(218, 100, 48, .12));
  box-shadow: 0 0 10px rgba(231, 127, 69, .28);
  opacity: calc(var(--give-progress) * .72);
  pointer-events: none;
}
.give-ritual__heart {
  position: absolute;
  left: 50%;
  top: 47%;
  width: 116px;
  height: 132px;
  transform: translate(-50%, -50%);
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.give-ritual__glow {
  position: absolute;
  inset: 18px 10px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(244, 148, 84, calc(.18 + var(--give-progress) * .52)) 0%, rgba(159, 42, 20, calc(.12 + var(--give-progress) * .32)) 36%, transparent 72%);
  transform: scale(calc(.72 + var(--give-progress) * .38));
  filter: blur(calc(8px - var(--give-progress) * 3px));
  animation: give-heart-flicker 1.8s ease-in-out infinite;
}
.give-ritual__ember {
  position: absolute;
  left: 50%;
  top: 78%;
  width: 40px;
  height: 40px;
  margin: -20px;
  border-radius: 50%;
  background: radial-gradient(circle, #ffd19a 0 8%, #d7773f 28%, rgba(126, 36, 16, .32) 52%, transparent 72%);
  filter: blur(.2px) drop-shadow(0 0 12px rgba(218, 100, 48, .56));
  animation: give-ember-float 4.2s ease-in-out infinite;
  transform: translateY(calc(var(--give-progress) * -31vh)) scale(calc(1 - var(--give-progress) * .72));
  opacity: calc(1 - var(--give-progress) * .92);
  transition: transform 400ms ease, opacity 400ms ease;
  pointer-events: none;
}
.give-ritual.was-released .give-ritual__ember { transition-duration: 400ms; }
.give-ritual.is-complete .give-ritual__ember { opacity: 0; }
.give-ritual__whisper {
  position: absolute;
  left: 12%;
  right: 12%;
  bottom: max(13%, calc(24px + var(--safe-bottom)));
  color: rgba(235, 220, 197, .78);
  font-size: clamp(15px, 4vw, 20px);
  letter-spacing: .025em;
  text-align: center;
  opacity: 0;
  transition: opacity 700ms ease;
  pointer-events: none;
}
.give-ritual__whisper.is-visible { opacity: 1; }
.give-ritual.is-holding .give-ritual__whisper { opacity: 0; }
@keyframes give-ember-float { 0%,100% { margin-top: -17px; } 50% { margin-top: -25px; } }
@keyframes give-heart-flicker { 0%,100% { opacity: .62; } 45% { opacity: .86; } 52% { opacity: .68; } }
@media (prefers-reduced-motion: reduce) {
  .give-ritual__ember, .give-ritual__glow { animation: none; }
  .give-ritual__ember { transform: none; opacity: calc(1 - var(--give-progress)); }
}

/* ─── Memory Words ───────────────────────────────────────────────────────── */
.words-screen {
  position: fixed; inset: 0; width: var(--app-width); height: var(--app-height);
  display: none; flex-direction: column; align-items: center;
  padding: max(36px, calc(var(--safe-top) + 10px)) 18px max(20px, calc(var(--safe-bottom) + 12px));
  overflow: hidden; touch-action: none; user-select: none;
  background: radial-gradient(circle at 50% 70%, rgba(112,37,18,.2), transparent 34%), #070604;
}
.words-screen__caption {
  min-height: 30px; color:#C1A376; font: 22px/1.2 'Schoolbell',cursive; text-align:center;
  /* sits on top of Eli's faded lower half — shadow keeps it readable over the art */
  position: relative; z-index: 1;
  text-shadow: 0 2px 10px rgba(0,0,0,.9), 0 0 18px rgba(0,0,0,.7);
}

/* Eli watching over the word puzzle — caption overlaps his faded lower half
   so the grid and wheel get the vertical room back */
.words-eli {
  display: flex;
  justify-content: center;
  margin-bottom: clamp(-72px, -13vw, -44px);
}
.words-eli img,
.words-eli canvas {
  width: min(38vw, 220px, calc(var(--app-width) * .42), calc(var(--app-height) * .26));
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 50%;
  /* fade the portrait into the darkness, like he's emerging from it */
  -webkit-mask-image: radial-gradient(circle, #000 55%, transparent 72%);
  mask-image: radial-gradient(circle, #000 55%, transparent 72%);
  filter: brightness(0.85);
  transition: filter 0.6s ease, transform 0.6s ease;
}
.words-eli.is-speaking img,
.words-eli.is-speaking canvas {
  filter: brightness(1.1) drop-shadow(0 0 24px rgba(193,163,118,0.35));
  transform: scale(1.03);
}
.words-screen.has-new-word .words-eli img,
.words-screen.has-new-word .words-eli canvas {
  filter: brightness(1.05);
}
.words-memories {
  width: min(88%, 330px);
  height: min(31vh, 250px, calc(var(--app-height) * .26));
  display: grid;
  grid-template-columns: repeat(var(--words-cols, 6), minmax(0, 1fr));
  grid-template-rows: repeat(var(--words-rows, 6), minmax(0, 1fr));
  gap: 4px;
  margin-top: 14px;
  align-content: center;
  justify-content: center;
  /* keep the tiles painting above Eli's overlapping portrait */
  position: relative; z-index: 1;
}
.words-tile {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
  border: 1px solid rgba(193,163,118,.2);
  border-radius: 6px;
  background: rgba(28,20,15,.82);
  box-shadow: inset 0 0 12px rgba(112,37,18,.12), 0 3px 8px rgba(0,0,0,.34);
  color: transparent;
  font: 700 clamp(17px,5vw,26px)/1 'Schoolbell',cursive;
  transition: background .45s ease, color .45s ease, border-color .45s ease, transform .55s ease;
}
.words-tile--empty { visibility: hidden; }
.words-tile.is-revealed {
  color: #f0c58b;
  border-color: rgba(231,160,99,.62);
  background: linear-gradient(145deg,rgba(111,48,25,.82),rgba(57,30,20,.9));
  box-shadow: inset 0 0 15px rgba(231,127,69,.13),0 0 11px rgba(218,100,48,.18);
}
/* Only freshly-found letters pop in — earlier tiles stay put. Staggered via
   inline animation-delay so the word writes itself across the grid. */
.words-tile.is-new { animation: words-tile-pop .6s cubic-bezier(.34,1.56,.64,1) both; }
@keyframes words-tile-pop {
  0%   { opacity:0; transform:scale(.3) rotate(-8deg); }
  55%  { opacity:1; transform:scale(1.22) rotate(2deg);
         box-shadow: inset 0 0 18px rgba(255,200,140,.4), 0 0 26px rgba(240,170,100,.6);
         color:#ffe6c2; }
  100% { opacity:1; transform:scale(1) rotate(0); }
}
.words-memory { min-height:42px; padding:6px 12px; border-bottom:1px solid rgba(193,163,118,.13); text-align:center; transition:background .5s ease; }
.words-memory__word { display:block; color:rgba(193,163,118,.42); font:700 18px/1.1 'Schoolbell',cursive; letter-spacing:.18em; }
.words-memory__reveal { display:block; min-height:15px; margin-top:3px; color:rgba(222,205,177,.58); font-size:13px; }
.words-memory.is-found { background:rgba(133,57,25,.09); }
.words-memory.is-found .words-memory__word { color:#e0b980; text-shadow:0 0 12px rgba(218,100,48,.3); }
.words-current { height:38px; margin-top:8px; color:#f0c58b; font:700 28px/1.2 'Schoolbell',cursive; letter-spacing:.12em; transition:opacity .35s,filter .35s; }
.words-current.is-dissolving { opacity:0; filter:blur(5px); }
/* Correct word: swells gold, then releases toward the grid */
.words-current.is-committing { animation: words-word-commit .55s ease both; }
@keyframes words-word-commit {
  0%   { transform:scale(1); }
  40%  { transform:scale(1.28); color:#ffe0b8; text-shadow:0 0 20px rgba(240,180,110,.85); }
  100% { transform:scale(.85) translateY(-10px); opacity:0; }
}
.words-wheel { position:relative; flex:0 0 auto; width:min(70vw,270px,calc(var(--app-width) * .62),calc(var(--app-height) * .29)); aspect-ratio:1; margin-top:4px; border-radius:50%; background:radial-gradient(circle,rgba(44,29,20,.48),rgba(11,9,7,.18) 68%,transparent 70%); }
.words-wheel__lines,#wordsLetters { position:absolute; inset:0; width:100%; height:100%; }
.words-wheel__lines { pointer-events:none; overflow:visible; }
.words-wheel__lines polyline { fill:none; stroke:rgba(232,146,84,.8); stroke-width:2.2; stroke-linecap:round; stroke-linejoin:round; filter:drop-shadow(0 0 4px rgba(218,100,48,.55)); }
.words-letter { position:absolute; width:var(--words-letter-size,52px); height:var(--words-letter-size,52px); transform:translate(-50%,-50%); border:1px solid rgba(193,163,118,.28); border-radius:50%; background:#17120e; color:#d8bd91; font:700 var(--words-letter-font,25px) 'Schoolbell',cursive; box-shadow:0 4px 16px rgba(0,0,0,.42); transition:background .2s,border-color .2s,transform .2s; }
.words-letter.is-selected { background:#5c2b18; border-color:#edaa72; color:#ffe0b8; transform:translate(-50%,-50%) scale(1.08); }
.words-screen__memory { min-height:24px; max-width:86%; margin-top:8px; color:rgba(225,209,183,.62); font-size:15px; text-align:center; }
.words-recovered {
  position:absolute;
  left:50%;
  top:52%;
  width:min(76%,280px);
  min-height:210px;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:2px;
  opacity:0;
  transform:translate(-50%,-50%) scale(.94);
  transition:opacity .9s ease .25s,transform 1.2s cubic-bezier(.16,.8,.24,1) .25s;
  pointer-events:none;
  z-index:4;
}
.words-recovered__core {
  position:absolute;
  left:50%;
  top:50%;
  width:150%;
  aspect-ratio:1;
  border-radius:50%;
  background:radial-gradient(circle,rgba(137,5,10,.88) 0%,rgba(91,3,7,.68) 34%,rgba(44,5,7,.24) 62%,transparent 76%);
  filter:blur(12px);
  transform:translate(-50%,-50%);
  animation:words-victory-core 2.8s ease-in-out infinite alternate;
}
.words-recovered__word {
  position:relative;
  z-index:1;
  color:#c9a35e;
  font:400 clamp(34px,10vw,48px)/1.12 Georgia,'Times New Roman',serif;
  letter-spacing:-.035em;
  text-shadow:0 1px 0 rgba(255,226,157,.12),0 0 18px rgba(113,39,17,.24);
  opacity:0;
  filter:blur(5px);
  transform:translateY(10px);
}
.words-recovered.is-visible {
  opacity:1;
  transform:translate(-50%,-50%) scale(1);
}
.words-recovered.is-visible .words-recovered__word {
  animation:words-victory-word .9s cubic-bezier(.2,.72,.2,1) calc(.55s + var(--word-delay)) forwards;
}
.words-recovered.is-visible .words-recovered__word:last-child::after {
  content:'';
  display:inline-block;
  width:2px;
  height:.9em;
  margin-left:3px;
  background:#d2ad67;
  vertical-align:-.04em;
  opacity:0;
  animation:words-memory-caret .82s steps(1,end) 2.15s infinite;
}
.words-screen.is-recovered .words-wheel,
.words-screen.is-recovered .words-current,
.words-screen.is-recovered .words-memories {
  opacity:0;
  transform:scale(.88);
  filter:blur(5px);
  transition:opacity .75s,transform .9s,filter .8s;
}
.words-screen.is-recovered .words-screen__memory {
  color:rgba(255,224,190,.82);
  transform:translateY(18px);
  transition:color .6s ease .5s,transform .8s ease .4s;
}
.words-screen.is-recovered .words-screen__caption {
  color:rgba(202,169,110,.72);
  text-shadow:0 0 18px rgba(103,20,18,.28);
  transition:color .7s,text-shadow .7s;
}
.words-screen.is-recovered {
  background:
    radial-gradient(ellipse at 50% 52%,rgba(96,4,8,.5) 0%,rgba(47,4,6,.22) 36%,transparent 68%),
    #100d0b;
  transition:background 1.2s ease;
}
.words-screen.is-departing .words-recovered {
  animation:words-victory-depart .9s cubic-bezier(.55,.05,.8,.25) forwards;
}
.words-screen.is-departing .words-screen__caption,
.words-screen.is-departing .words-screen__memory,
.words-screen.is-departing .words-eli {
  opacity:0;
  transition:opacity .55s ease;
}
.words-screen.is-departing::before {
  content:'';
  position:absolute;
  inset:0;
  z-index:3;
  pointer-events:none;
  background:radial-gradient(circle at 50% 54%,rgba(123,8,13,.35),transparent 24%);
  animation:words-victory-wash .9s ease forwards;
}
@keyframes words-victory-core {
  from { opacity:.72; transform:translate(-50%,-50%) scale(.92); filter:blur(14px) brightness(.82); }
  to { opacity:1; transform:translate(-50%,-50%) scale(1.08); filter:blur(10px) brightness(1.08); }
}
@keyframes words-victory-word {
  0% { opacity:0; filter:blur(5px); transform:translateY(10px); }
  100% { opacity:1; filter:blur(0); transform:translateY(0); }
}
@keyframes words-memory-caret {
  0%,48% { opacity:.9; }
  49%,100% { opacity:0; }
}
@keyframes words-victory-depart {
  0% { opacity:1; transform:translate(-50%,-50%) scale(1); }
  34% { opacity:1; transform:translate(-50%,-50%) scale(1.035); filter:brightness(1.08); }
  100% { opacity:0; transform:translate(-50%,-78%) scale(.72); filter:blur(8px) brightness(.72); }
}
@keyframes words-victory-wash {
  0% { opacity:0; transform:scale(.7); }
  38% { opacity:.6; }
  100% { opacity:0; transform:scale(2); }
}
.words-screen.has-new-word .words-memories { animation:words-found-breathe .65s ease; }
@keyframes words-found-breathe { 50% { transform:scale(1.025); } }
/* Soft golden flash washing over the screen when a word lands */
.words-screen::after {
  content:''; position:absolute; inset:0; pointer-events:none; opacity:0;
  background: radial-gradient(circle at 50% 40%, rgba(240,170,100,.2), transparent 48%);
}
.words-screen.has-new-word::after { animation: words-flash .7s ease both; }
@keyframes words-flash { 0%{opacity:0} 30%{opacity:1} 100%{opacity:0} }
.words-screen.has-new-word .words-wheel { animation: words-wheel-pulse .65s ease; }
@keyframes words-wheel-pulse { 35% { transform:scale(1.04); filter:brightness(1.25); } }
@media(max-height:700px){.words-memories{margin-top:6px;height:min(27vh,190px)}.words-memory{min-height:34px}.words-wheel{width:min(55vw,205px)}.words-letter{width:44px;height:44px}.words-current{height:30px;margin-top:5px}}

/* ─── Memory Thread ───────────────────────────────────────────────────────── */
.thread-screen {
  position: fixed;
  inset: 0;
  width: var(--app-width);
  height: var(--app-height);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: max(58px, calc(var(--safe-top) + 42px)) 16px max(34px, calc(var(--safe-bottom) + 22px));
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 56%, rgba(112, 37, 18, .22), transparent 36%),
    #070604;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.thread-screen__caption {
  min-height: 32px;
  max-width: 88%;
  color: #C1A376;
  font-family: 'Schoolbell', cursive;
  font-size: clamp(18px, 5vw, 24px);
  line-height: 1.25;
  text-align: center;
  text-shadow: 0 0 18px rgba(193, 163, 118, .28);
  transition: opacity .6s ease, transform .8s ease;
}

.thread-field {
  position: relative;
  width: min(94%, 390px);
  height: min(64vh, 520px);
  min-height: 390px;
}

.thread-lines,
.thread-nodes {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.thread-lines { overflow: visible; pointer-events: none; }
.thread-lines polyline {
  fill: none;
  stroke: rgba(230, 145, 87, .82);
  stroke-width: .72;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 3px rgba(230, 112, 55, .58));
  opacity: .9;
  transition: opacity .5s ease, stroke-width .8s ease;
}
.thread-lines polyline.is-complete { stroke-width: 1.2; opacity: 1; }

.thread-node {
  position: absolute;
  width: clamp(82px, 24vw, 112px);
  min-height: 50px;
  transform: translate(-50%, -50%);
  padding: 9px 11px;
  border: 1px solid rgba(193, 163, 118, .2);
  border-radius: 999px;
  background: rgba(17, 13, 10, .86);
  color: rgba(214, 193, 157, .72);
  font-family: 'Schoolbell', cursive;
  font-size: clamp(15px, 4vw, 19px);
  line-height: 1.05;
  text-align: center;
  box-shadow: inset 0 0 18px rgba(125, 46, 22, .12), 0 0 14px rgba(0, 0, 0, .4);
  transition: color .35s ease, border-color .35s ease, box-shadow .35s ease, opacity .9s ease, transform .9s ease;
  -webkit-tap-highlight-color: transparent;
}

.thread-node::before {
  content: '';
  display: block;
  width: 7px;
  height: 7px;
  margin: 0 auto 5px;
  border-radius: 50%;
  background: rgba(180, 69, 30, .52);
  box-shadow: 0 0 9px rgba(180, 69, 30, .3);
}

.thread-node.is-threaded {
  color: #edd1a6;
  border-color: rgba(234, 157, 95, .72);
  box-shadow: inset 0 0 22px rgba(158, 55, 23, .2), 0 0 18px rgba(218, 100, 48, .24);
}
.thread-node.is-threaded::before { background: #f0ad72; box-shadow: 0 0 13px rgba(240, 133, 72, .8); }
.thread-node.is-uncertain { border-color: rgba(145, 160, 173, .46); color: rgba(190, 197, 201, .58); }
.thread-field.is-releasing .thread-lines polyline { opacity: 0; }

.thread-screen__whisper {
  min-height: 24px;
  max-width: 84%;
  color: rgba(219, 204, 180, .54);
  font-size: clamp(14px, 3.8vw, 18px);
  text-align: center;
  letter-spacing: .025em;
  transition: opacity .6s ease;
}

.thread-recovered {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin: -23px;
  border-radius: 50%;
  background: radial-gradient(circle, #ffe1b8 0 7%, #e58b50 25%, rgba(143, 48, 22, .38) 50%, transparent 72%);
  filter: drop-shadow(0 0 15px rgba(218, 100, 48, .66));
  opacity: 0;
  transform: scale(.35);
  pointer-events: none;
  transition: opacity .9s ease 1s, transform 1.1s ease 1s;
}
.thread-recovered.is-visible { opacity: 1; transform: scale(1); animation: recovered-ember-breathe 2.2s ease-in-out 2.1s infinite; }

.thread-screen.is-recovered .thread-node.is-left-behind {
  opacity: 0;
  transform: translate(-50%, -50%) scale(.68);
}
.thread-screen.is-recovered .thread-node.is-chosen {
  opacity: 0;
  transform: translate(-50%, -50%) scale(.82);
  transition-delay: .65s;
}
.thread-screen.is-recovered .thread-lines polyline { opacity: 0; transition-delay: .8s; }
.thread-screen.is-recovered .thread-screen__caption { transform: translateY(-8px); }

@media (max-height: 700px) {
  .thread-field { height: 58vh; min-height: 330px; }
  .thread-node { min-height: 44px; padding: 7px 9px; }
}

@media (prefers-reduced-motion: reduce) {
  .thread-node, .thread-recovered, .thread-lines polyline { transition-duration: .15s; animation: none; }
}

/* ─── Memory room prototype ───────────────────────────────────────────────── */
.memory-screen {
  position: fixed;
  inset: 0;
  width: var(--app-width);
  height: var(--app-height);
  display: none;
  overflow: hidden;
  background: #070604;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

.memory-room {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 48% 63%, rgba(118, 23, 8, 0.32), transparent 28%),
    #050403;
}

.memory-room__bg,
.memory-room__shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.memory-room__bg {
  background-position: center;
  background-size: cover;
  opacity: 0;
  transform: scale(1.035);
  filter: saturate(0.84) brightness(0.72);
  transition: opacity 2.8s ease, transform 8s ease, filter 1.2s ease;
}

.memory-screen.is-awake .memory-room__bg {
  opacity: 1;
  transform: scale(1);
}

.memory-room__shade {
  z-index: 1;
  background:
    linear-gradient(to bottom, rgba(0,0,0,0.90), rgba(0,0,0,0.36) 38%, rgba(0,0,0,0.18) 58%, rgba(0,0,0,0.90)),
    radial-gradient(ellipse at center, transparent 18%, rgba(0,0,0,0.28) 52%, rgba(0,0,0,0.82) 100%);
}

.memory-room__caption {
  position: absolute;
  z-index: 7;
  top: max(74px, calc(var(--safe-top) + 58px));
  left: 50%;
  width: min(82%, 360px);
  transform: translateX(-50%);
  color: #c1a376;
  font-family: 'Schoolbell', cursive;
  font-size: clamp(22px, calc(var(--app-width) * 0.07), 32px);
  line-height: 1.35;
  text-align: center;
  text-shadow: 0 3px 18px rgba(0,0,0,0.95);
  opacity: 0;
  transition: opacity 0.7s ease, transform 0.7s ease, filter 0.7s ease;
  pointer-events: none;
  white-space: pre-line;
}

.memory-room__caption.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.memory-room__objects {
  position: absolute;
  inset: 0;
  z-index: 5;
}

.memory-object {
  position: absolute;
  width: var(--object-size, 76px);
  height: var(--object-size, 76px);
  left: var(--object-x);
  top: var(--object-y);
  transform: translate(-50%, -50%);
  border: 0;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.memory-object::before,
.memory-object::after {
  content: '';
  position: absolute;
  inset: 18%;
  border-radius: inherit;
  pointer-events: none;
}

.memory-object::before {
  background: radial-gradient(circle, rgba(218, 168, 97, 0.36), rgba(176, 70, 28, 0.14) 46%, transparent 72%);
  filter: blur(5px);
  opacity: 0.65;
  animation: memory-object-breathe 3.6s ease-in-out infinite;
}

.memory-object::after {
  border: 1px solid rgba(220, 185, 126, 0.18);
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.memory-object:focus-visible::after,
.memory-object:hover::after {
  opacity: 1;
  transform: scale(1);
}

.memory-object.is-found {
  pointer-events: none;
}

.memory-object.is-found::before {
  background: radial-gradient(circle, rgba(215, 64, 34, 0.32), rgba(152, 28, 18, 0.12) 46%, transparent 72%);
  opacity: 0.34;
  animation: none;
}

.memory-room__whisper {
  position: absolute;
  z-index: 8;
  left: 50%;
  bottom: max(76px, calc(var(--safe-bottom) + 62px));
  width: min(86%, 380px);
  transform: translateX(-50%) translateY(10px);
  color: rgba(244, 228, 197, 0.92);
  font-family: 'Schoolbell', cursive;
  font-size: clamp(22px, calc(var(--app-width) * 0.065), 30px);
  line-height: 1.35;
  text-align: center;
  text-shadow: 0 2px 18px rgba(0,0,0,0.95);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.memory-room__whisper.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.memory-room__eli {
  position: absolute;
  z-index: 9;
  left: 50%;
  bottom: 13%;
  width: min(54vw, 230px);
  height: min(68vw, 292px);
  max-height: 42vh;
  transform: translateX(-50%) translateY(34px) scale(0.94);
  opacity: 0;
  pointer-events: none;
  transition: opacity 1.1s ease, transform 1.1s cubic-bezier(0.22, 1, 0.36, 1), filter 0.6s ease;
  filter: drop-shadow(0 16px 44px rgba(0,0,0,0.9));
}

.memory-room__eli::before {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 62%;
  height: 74%;
  transform: translateX(-50%);
  border-radius: 46% 46% 30% 30%;
  background:
    radial-gradient(circle at 50% 31%, rgba(124, 64, 36, 0.32), transparent 18%),
    linear-gradient(to bottom, rgba(35, 27, 22, 0.92), rgba(14, 11, 10, 0.98));
  box-shadow: inset 0 0 48px rgba(193, 91, 42, 0.08);
}

.memory-room__eli-face {
  position: absolute;
  left: 50%;
  top: 3%;
  width: 62%;
  height: 36%;
  transform: translateX(-50%);
  border-radius: 48% 48% 44% 44%;
  background:
    radial-gradient(circle at 35% 49%, rgba(236, 221, 188, 0.88) 0 6%, #16100e 7% 13%, transparent 14%),
    radial-gradient(circle at 65% 49%, rgba(236, 221, 188, 0.88) 0 6%, #16100e 7% 13%, transparent 14%),
    radial-gradient(circle at 50% 68%, rgba(158, 89, 52, 0.8), transparent 8%),
    linear-gradient(to bottom, rgba(153, 112, 71, 0.80), rgba(78, 54, 37, 0.72));
  box-shadow: inset 0 -22px 36px rgba(0,0,0,0.45), 0 0 34px rgba(193, 163, 118, 0.08);
}

.memory-room__eli-heart {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 102, 51, 0.98), rgba(185, 29, 13, 0.56) 32%, rgba(107, 11, 8, 0.18) 58%, transparent 73%);
  filter: blur(4px);
  animation: memory-heart-panic 0.7s ease-in-out infinite;
  cursor: pointer;
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.memory-room__hold-progress {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%) rotate(-90deg);
  border-radius: 50%;
  background: conic-gradient(rgba(238, 203, 143, 0.72) calc(var(--hold-progress, 0) * 1turn), transparent 0);
  opacity: 0;
  mask: radial-gradient(circle, transparent 54%, #000 56%);
  -webkit-mask: radial-gradient(circle, transparent 54%, #000 56%);
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.memory-room__eli.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
}

.memory-room__eli.is-holding .memory-room__hold-progress {
  opacity: 1;
}

.memory-screen.is-collapsing .memory-room__bg,
.memory-screen.is-collapsing .memory-room__shade {
  animation: memory-collapse 0.24s linear infinite;
}

.memory-screen.is-collapsing .memory-room__bg {
  filter: saturate(0.58) brightness(0.56) contrast(1.18);
}

.memory-screen.is-calm .memory-room__eli-heart {
  animation: memory-heart-calm 2.2s ease-in-out infinite;
  background: radial-gradient(circle, rgba(255, 124, 58, 0.82), rgba(193, 63, 21, 0.34) 34%, rgba(118, 26, 10, 0.10) 60%, transparent 74%);
}

@keyframes memory-object-breathe {
  0%, 100% { opacity: 0.35; transform: scale(0.82); }
  50% { opacity: 0.78; transform: scale(1.08); }
}

@keyframes memory-collapse {
  0% { transform: translate3d(0, 0, 0) scale(1); }
  25% { transform: translate3d(-1.5px, 1px, 0) scale(1.006); }
  50% { transform: translate3d(1px, -1.5px, 0) scale(1.002); }
  75% { transform: translate3d(1.5px, 1px, 0) scale(1.008); }
  100% { transform: translate3d(0, 0, 0) scale(1); }
}

@keyframes memory-heart-panic {
  0%, 100% { opacity: 0.62; transform: translate(-50%, -50%) scale(0.76); }
  28% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); }
  48% { opacity: 0.72; transform: translate(-50%, -50%) scale(0.86); }
  66% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
}

@keyframes memory-heart-calm {
  0%, 100% { opacity: 0.54; transform: translate(-50%, -50%) scale(0.86); }
  50% { opacity: 0.88; transform: translate(-50%, -50%) scale(1.04); }
}

/* ─── Chat card input ──────────────────────────────────────────────────────── */
.chat-card {
  position: absolute;
  bottom: calc(var(--keyboard-offset) + max(10px, var(--safe-bottom)));
  left: 50%;
  transform: translateX(-50%);
  width: var(--chat-card-width);
  max-width: var(--chat-card-width);
  padding: 14px 16px 12px;
  background: #f5f0e8;
  border-radius: 18px;
  z-index: 10;
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.36);
}

.chat-card__input {
  width: 100%;
  min-height: 24px;
  background: transparent;
  border: none;
  color: #1a1a1a;
  font-size: 16px;
  padding: 0 0 10px;
  outline: none;
}
.chat-card__input::placeholder {
  color: #999;
  font-size: 16px;
}

.chat-card__actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
}

.chat-card__right {
  display: flex;
  gap: 8px;
}

.chat-card__btn {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: background 0.15s;
}

.chat-card__btn--add {
  background: rgba(0,0,0,0.06);
  color: #666;
  font-size: 22px;
  font-weight: 300;
}
.chat-card__btn--add:hover { background: rgba(0,0,0,0.12); }

.chat-card__btn--mic {
  background: rgba(0,0,0,0.06);
  color: #333;
  position: relative;
}
.chat-card__btn--mic:hover { background: rgba(0,0,0,0.12); }
.chat-card__btn--mic.is-recording {
  background: rgba(255, 68, 68, 0.2);
}

.chat-card__btn--send {
  background: #1a1a1a;
  color: #fff;
}
.chat-card__btn--send:hover { background: #333; }

.chat-card__send-icon {
  font-size: 14px;
  margin-left: 2px;
}

/* ─── Eli thinking indicator (inside chat card) ────────────────────────── */
.eli-thinking {
  display: none;
  padding: 7px 0 4px;
}

.eli-thinking__dots {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 6px 8px;
  border-radius: 999px;
  background: rgba(7, 40, 22, 0.08);
}

.eli-thinking__dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #0f5f32;
  box-shadow: 0 0 0 1px rgba(15, 95, 50, 0.12), 0 4px 10px rgba(15, 95, 50, 0.22);
  opacity: 0.38;
  transform: translateY(1px) scale(0.82);
  animation: eli-dot 1.25s ease-in-out infinite;
}
.eli-thinking__dots span:nth-child(2) { animation-delay: 0.2s; }
.eli-thinking__dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes eli-dot {
  0%, 70%, 100% {
    opacity: 0.35;
    transform: translateY(1px) scale(0.82);
  }
  35% {
    opacity: 1;
    transform: translateY(-2px) scale(1);
  }
}

/* ─── Heart comfort prompt ──────────────────────────────────────────────── */
.heart-prompt {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.heart-prompt__ring {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 2px solid rgba(255, 80, 80, 0.4);
  animation: heart-ring 2s ease-in-out infinite;
}

.heart-prompt__text {
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
  letter-spacing: 0.05em;
  animation: heart-text 2s ease-in-out infinite;
}

@keyframes heart-ring {
  0%, 100% { transform: scale(1); border-color: rgba(255, 80, 80, 0.3); }
  50% { transform: scale(1.1); border-color: rgba(255, 80, 80, 0.6); }
}
@keyframes heart-text {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

.heart-prompt.is-touching .heart-prompt__ring {
  animation: none;
  border-color: rgba(83, 238, 134, 0.8);
  background: rgba(83, 238, 134, 0.1);
  transition: all 0.5s ease;
  transform: scale(1.2);
}

.voice-btn__icon { width: 18px; height: 18px; z-index: 1; }
.voice-btn__pulse {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(255, 68, 68, 0.5);
  opacity: 0;
}
.is-recording .voice-btn__pulse {
  animation: voice-pulse 1.2s ease-out infinite;
}
@keyframes voice-pulse {
  0% { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(1.5); opacity: 0; }
}

.segment-chat-overlay {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  z-index: 50;
  pointer-events: none;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.segment-chat-overlay.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.segment-chat__thread { display: none; }

.segment-chat__card {
  pointer-events: auto;
}

/* Same warm-gold pill language as the authored scene CTA (.scene-cta) */
.segment-chat__continue {
  position: fixed;
  bottom: calc(var(--keyboard-offset) + max(90px, calc(var(--safe-bottom) + 78px)));
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Schoolbell', cursive;
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: 0.02em;
  color: #e6d2a6;
  background: rgba(56, 48, 36, 0.62);
  border: 1px solid rgba(193, 163, 118, 0.22);
  border-radius: 999px;
  padding: 12px 28px;
  cursor: pointer;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.25s, border-color 0.25s, color 0.25s;
}
.segment-chat__continue:hover {
  background: rgba(66, 57, 43, 0.72);
  border-color: rgba(193, 163, 118, 0.4);
  color: #f2e2ba;
}
.segment-chat__continue:active {
  transform: translateX(-50%) translateY(1px) scale(0.985);
}

.text-overlay {
  position: fixed;
  bottom: max(15%, calc(var(--keyboard-offset) + var(--safe-bottom) + 118px));
  left: 50%;
  transform: translateX(-50%);
  width: 85%;
  max-width: 500px;
  max-height: min(56vh, 470px);
  overflow: hidden;
  text-align: center;
  font-family: 'Schoolbell', cursive;
  font-weight: 700;
  font-size: 24px;
  line-height: 1.5;
  color: #C1A376;
  text-shadow: 0 2px 12px rgba(0,0,0,0.8), 0 0 4px rgba(0,0,0,0.6);
  pointer-events: none;
  z-index: 90;
  opacity: 0;
  transition: opacity 0.4s ease;
  white-space: pre-line;
}
.text-overlay.is-visible { opacity: 1; }
.text-overlay[data-position="diary"] {
  text-align: center;
  line-height: 1.24 !important;
  letter-spacing: 0.01em;
  text-shadow: 0 1px 1px rgba(38, 13, 4, 0.45), 0 0 8px rgba(216, 183, 123, 0.08);
}
.text-overlay[data-position="diary"] .word {
  transition-duration: 0.85s;
}
.text-overlay .char {
  display: inline-block;
  opacity: 0;
  transform: translateY(6px);
  filter: blur(2px);
  transition: opacity 0.35s ease, transform 0.35s ease, filter 0.35s ease;
}
.text-overlay .char.is-typed {
  opacity: 1;
  transform: translateY(0);
  filter: blur(0);
}
.text-overlay .char.is-space { width: 0.3em; }
.text-overlay .word {
  display: inline-block;
  opacity: 0;
  transform: translateY(6px);
  filter: blur(2px);
  transition: opacity 0.35s ease, transform 0.35s ease, filter 0.35s ease;
}
.text-overlay .word.is-typed {
  opacity: 1;
  transform: translateY(0);
  filter: blur(0);
}

.message-overlay {
  position: fixed;
  bottom: calc(var(--keyboard-offset) + max(24px, calc(var(--safe-bottom) + 18px)));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.75);
  color: #c8e8d0;
  font-size: 14px;
  padding: 10px 20px;
  border-radius: 20px;
  max-width: calc(var(--app-width) - 32px - var(--safe-left) - var(--safe-right));
  text-align: center;
  pointer-events: none;
  display: none;
  z-index: 100;
}

.message-overlay[style*="pointer-events: auto"] {
  color: #C1A376;
  border: 1px solid rgba(193, 163, 118, 0.28);
  font-family: 'Schoolbell', cursive;
  font-size: 16px;
  letter-spacing: 0.02em;
  animation: playback-invite 2.2s ease-in-out infinite;
}

@keyframes playback-invite {
  0%, 100% { opacity: 0.72; }
  50% { opacity: 1; }
}

.message-overlay.is-error {
  color: #ff9999;
  background: rgba(40,0,0,0.85);
}

.fade-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.fade-overlay.is-visible { opacity: 1; }

/* ─── Mobile optimizations ─────────────────────────────────────────────────── */
@media (max-width: 600px) {
  :root {
    --surface-gap: clamp(8px, 3.25vw, 14px);
    --chat-card-width: min(430px, calc(var(--app-width) - (var(--surface-gap) * 2) - var(--safe-left) - var(--safe-right)));
  }

  html, body {
    position: fixed;
    inset: 0;
    width: 100%;
  }

  .text-overlay {
    font-size: clamp(17px, 4.8vw, 22px);
    width: calc(100% - 28px - var(--safe-left) - var(--safe-right));
    max-width: none;
    bottom: max(18%, calc(var(--keyboard-offset) + var(--safe-bottom) + 108px));
    line-height: 1.35;
    max-height: min(56vh, 470px);
  }

  .chat-card {
    padding: 11px 12px 9px;
    border-radius: 16px;
  }
  .chat-card__input {
    font-size: 16px;
    line-height: 1.25;
    padding: 0 0 7px;
  }
  .chat-card__input::placeholder { font-size: 15px; }
  .chat-card__right { gap: 7px; }
  .chat-card__btn {
    width: 38px;
    height: 38px;
    flex-basis: 38px;
  }

  .segment-chat__card {
    width: var(--chat-card-width);
    max-width: var(--chat-card-width);
  }

  .message-overlay {
    bottom: calc(var(--keyboard-offset) + max(18px, calc(var(--safe-bottom) + 12px)));
    font-size: 13px;
    padding: 8px 16px;
  }

  .video-skip {
    top: max(12px, calc(var(--safe-top) + 8px));
    right: max(12px, calc(var(--safe-right) + 8px));
    font-size: 13px;
    padding: 6px 16px;
  }

  .heart-prompt__ring {
    width: clamp(84px, 24vw, 108px);
    height: clamp(84px, 24vw, 108px);
  }
  .heart-prompt__text {
    font-size: 12px;
  }

  .segment-chat__continue {
    bottom: calc(var(--keyboard-offset) + max(76px, calc(var(--safe-bottom) + 66px)));
    font-size: 16px;
    padding: 10px 22px;
  }
}

@media (max-width: 380px), (max-height: 680px) {
  .chat-card {
    padding: 9px 10px 8px;
    border-radius: 14px;
  }
  .chat-card__actions { min-height: 36px; }
  .chat-card__btn {
    width: 36px;
    height: 36px;
    flex-basis: 36px;
  }
  .text-overlay {
    bottom: max(20%, calc(var(--keyboard-offset) + var(--safe-bottom) + 94px));
    font-size: clamp(16px, 4.6vw, 19px);
  }
}

/* Prevent iOS rubber banding */
@supports (-webkit-touch-callout: none) {
  html, body {
    height: -webkit-fill-available;
    overflow: hidden;
    touch-action: none;
  }
  .stage, .chat-screen, .video-screen, .memory-screen, .thread-screen, .words-screen, .pairs-screen, .jigsaw-screen {
    height: var(--app-height);
  }
}

/* ─── Phone shell — desktop presentation frame ──────────────────────────────
   On desktop (≥600px): game sits inside a centered phone mockup.
   position:fixed children are contained by .phone-screen's transform.
   On mobile (<600px): shell and screen become display:contents so the game
   fills the real viewport exactly as before.
   ?shell=0: strips the frame so the game fills any viewport (mobile testing). */

/* shell=0 via JS sets data-shell="none" on <html> — beats all media queries */
:root[data-shell="none"] .phone-shell,
:root[data-shell="none"] .phone-screen { display: contents !important; }
:root[data-shell="none"] .phone-btn,
:root[data-shell="none"] .phone-island,
:root[data-shell="none"] .phone-status,
:root[data-shell="none"] .phone-home-bar { display: none !important; }

@media (max-width: 599px) {
  .phone-shell,
  .phone-screen  { display: contents; }
  .phone-btn,
  .phone-island,
  .phone-status,
  .phone-home-bar { display: none; }
}

@media (min-width: 600px) {
  /* Desktop background */
  html, body {
    height: auto;
    min-height: 100dvh;
    overflow: auto;
    overflow-x: hidden;
    background: #161411;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 28px 0;
  }

  /* ── Outer phone body ─────────────────────────────────────────────────── */
  .phone-shell {
    position: relative;
    flex-shrink: 0;
    width: 420px;
    /* Bezel gradient — blends into page background at the base */
    background: linear-gradient(170deg, #2a2520 0%, #1e1a16 35%, #161411 70%, #1a1714 100%);
    border-radius: 56px;
    padding: 16px 15px 22px;
    box-shadow:
      0 0 0 1px rgba(255,255,255,0.11),    /* outer rim highlight */
      0 0 0 2px rgba(0,0,0,0.85),          /* dark separator */
      0 40px 100px rgba(0,0,0,0.95),       /* deep drop shadow */
      0 10px 28px rgba(0,0,0,0.7),
      inset 0 1px 0 rgba(255,255,255,0.07);
  }

  /* ── Side buttons ─────────────────────────────────────────────────────── */
  .phone-btn {
    position: absolute;
    background: linear-gradient(90deg, #1e1e1e, #282828);
    border-radius: 2px;
    box-shadow: -1px 0 1px rgba(255,255,255,0.05), 1px 0 1px rgba(0,0,0,0.6);
  }
  /* Left side: mute toggle */
  .phone-btn--mute     { left: -4px; top: 104px; width: 4px; height: 30px;
                          border-radius: 2px 0 0 2px; }
  /* Left side: volume up */
  .phone-btn--vol-up   { left: -4px; top: 152px; width: 4px; height: 56px;
                          border-radius: 2px 0 0 2px; }
  /* Left side: volume down */
  .phone-btn--vol-down { left: -4px; top: 222px; width: 4px; height: 56px;
                          border-radius: 2px 0 0 2px; }
  /* Right side: power */
  .phone-btn--power    { right: -4px; top: 162px; width: 4px; height: 76px;
                          border-radius: 0 2px 2px 0; }

  /* ── Game screen ──────────────────────────────────────────────────────── */
  .phone-screen {
    position: relative;
    width: 390px;
    /* Shrink height on short viewports so the phone always fits */
    height: min(844px, calc(100dvh - 90px));
    border-radius: 44px;
    overflow: hidden;
    background: #000;
    /* GPU compositing layer */
    transform: translateZ(0);
    /* Subtle inner rim */
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.05);
  }

  /*
    Browsers don't reliably clip position:fixed children with overflow:hidden
    even inside a transformed ancestor. Switching to position:absolute means
    every game element is properly contained and clipped by the phone-screen.
  */
  .phone-screen .stage,
  .phone-screen .video-screen,
  .phone-screen .chat-screen,
  .phone-screen .memory-screen,
  .phone-screen .thread-screen,
  .phone-screen .words-screen,
  .phone-screen .pairs-screen,
  .phone-screen .jigsaw-screen,
  .phone-screen .segment-chat-overlay,
  .phone-screen .text-overlay,
  .phone-screen .heart-prompt,
  .phone-screen .fade-overlay,
  .phone-screen .message-overlay {
    position: absolute;
  }

  /* Constrain text overlay width to phone-screen dimensions */
  .phone-screen .text-overlay {
    width: min(85%, calc(var(--app-width) - 48px));
    max-width: min(500px, calc(var(--app-width) - 40px));
    font-size: clamp(17px, calc(var(--app-width) * 0.055), 22px);
  }

  /* ── Dynamic Island ───────────────────────────────────────────────────── */
  .phone-island {
    position: absolute;
    top: 13px;
    left: 50%;
    transform: translateX(-50%);
    width: 120px;
    height: 34px;
    background: #000;
    border-radius: 20px;
    z-index: 99999;
    pointer-events: none;
  }

  /* ── Status bar ───────────────────────────────────────────────────────── */
  .phone-status {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 54px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    padding: 0 28px 8px;
    z-index: 99998;
    pointer-events: none;
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    font-family: -apple-system, 'SF Pro Text', system-ui, sans-serif;
    letter-spacing: 0.01em;
  }

  .phone-status__time { line-height: 1; }

  .phone-status__right {
    display: flex;
    align-items: center;
    gap: 7px;
  }

  /* Signal bars — 4 spans with ascending heights */
  .phone-status__signal {
    display: inline-flex;
    align-items: flex-end;
    gap: 2px;
  }
  .phone-status__signal span {
    display: block;
    width: 3px;
    background: #fff;
    border-radius: 1px;
  }
  .phone-status__signal span:nth-child(1) { height: 4px; }
  .phone-status__signal span:nth-child(2) { height: 7px; }
  .phone-status__signal span:nth-child(3) { height: 10px; }
  .phone-status__signal span:nth-child(4) { height: 13px; }

  /* Battery — CSS box with fill and nub */
  .phone-status__battery {
    position: relative;
    display: inline-block;
    width: 25px;
    height: 13px;
    border: 1.5px solid rgba(255,255,255,0.6);
    border-radius: 3px;
    vertical-align: middle;
  }
  .phone-status__battery::before {
    /* fill */
    content: '';
    position: absolute;
    inset: 2px;
    background: #fff;
    border-radius: 1px;
  }
  .phone-status__battery::after {
    /* terminal nub */
    content: '';
    position: absolute;
    top: 50%;
    right: -4px;
    transform: translateY(-50%);
    width: 2.5px;
    height: 7px;
    background: rgba(255,255,255,0.45);
    border-radius: 0 1px 1px 0;
  }

  /* ── Home indicator ───────────────────────────────────────────────────── */
  .phone-home-bar {
    position: absolute;
    bottom: 9px;
    left: 50%;
    transform: translateX(-50%);
    width: 134px;
    height: 5px;
    background: rgba(255,255,255,0.28);
    border-radius: 3px;
    z-index: 99999;
    pointer-events: none;
  }
}

/* ─── Mute button ─────────────────────────────────────────────────────────── */
.mute-btn {
  position: absolute;
  top: 52px;
  right: 14px;
  z-index: 60;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.35);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.mute-btn:hover, .mute-btn.is-muted { opacity: 0.95; }

/* ─── Scene-loading spinner (shown on the fade overlay) ──────────────────── */
.fade-overlay.is-loading.is-visible::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-top-color: rgba(255, 255, 255, 0.55);
  border-radius: 50%;
  animation: eli-spin 0.8s linear infinite;
}

@keyframes eli-spin { to { transform: rotate(360deg); } }

/* ── Press-and-hold support ──────────────────────────────────────────────── */
/* Rive hold interactions need the browser's own gestures out of the way:
   no scroll-steal, no long-press menu, no text selection. */
#canvas, #chatCanvas {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* Pull-to-refresh / overscroll can cancel a press-and-hold on Android */
html, body { overscroll-behavior: none; }

/* ── Loading glow: Eli's heart, beating while the next scene loads ────────── */
/* Overrides the generic spinner defined above (same selector, later rule). */
.fade-overlay.is-loading.is-visible::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 200px;
  height: 200px;
  margin: -100px 0 0 -100px;
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle,
    rgba(255, 92, 38, 0.95) 0%,
    rgba(232, 58, 16, 0.6)  22%,
    rgba(186, 42, 10, 0.28) 44%,
    rgba(110, 22, 5, 0.10)  62%,
    transparent 74%);
  filter: blur(7px);
  animation: eli-heart-glow 1.9s ease-in-out infinite;
}

/* lub-dub … rest — like a heartbeat, not a spinner */
@keyframes eli-heart-glow {
  0%   { transform: scale(0.80); opacity: 0.60; }
  16%  { transform: scale(1.06); opacity: 1;    }
  30%  { transform: scale(0.88); opacity: 0.78; }
  44%  { transform: scale(1.14); opacity: 1;    }
  62%  { transform: scale(0.84); opacity: 0.66; }
  100% { transform: scale(0.80); opacity: 0.60; }
}

/* ── Loading screen: plain background, no indicator ───────────────────────── */
.fade-overlay { background: #161411; }
.fade-overlay.is-loading.is-visible::after { content: none; animation: none; }

/* ─── Scene CTA button ────────────────────────────────────────────────────── */

/* Matte, understated pill that sits quietly in the scene — wide, warm,
   flat brown with a whisper of a border, single-line Schoolbell text. */
.scene-cta {
  position: absolute;
  left: 50%;
  bottom: max(34px, calc(var(--safe-bottom) + 26px));
  transform: translateX(-50%) translateY(12px);
  z-index: 12;
  width: min(76%, 420px);
  font-family: 'Schoolbell', cursive;
  font-size: 22px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.02em;
  color: #e6d2a6;
  background: rgba(56, 48, 36, 0.62);
  border: 1px solid rgba(193, 163, 118, 0.22);
  border-radius: 999px;
  padding: 18px 32px;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.8s ease, transform 0.8s cubic-bezier(0.22, 1, 0.36, 1), background 0.25s, border-color 0.25s;
  -webkit-tap-highlight-color: transparent;
}

.scene-cta.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.scene-cta:hover {
  background: rgba(66, 57, 43, 0.72);
  border-color: rgba(193, 163, 118, 0.4);
  color: #f2e2ba;
}

.scene-cta:active {
  transform: translateX(-50%) translateY(1px) scale(0.985);
  transition-duration: 0.08s;
}

/* Hold-to-commit: the pill fills with warm gold while held */
.scene-cta::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(193, 163, 118, 0.30);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.18s ease;
  pointer-events: none;
}

.scene-cta.is-holding::before {
  transform: scaleX(1);
  transition: transform 1.1s linear;
}

.scene-cta.is-holding {
  border-color: rgba(226, 199, 156, 0.6);
}

/* ─── Heart touch zone ────────────────────────────────────────────────────── */
/* Invisible; position/size come from scene config (% of the stage). */
.heart-zone {
  position: absolute;
  transform: translate(-50%, -50%);
  aspect-ratio: 1;
  border-radius: 50%;
  z-index: 11;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  isolation: isolate;
}

.heart-zone::before {
  content: '';
  position: absolute;
  inset: -48%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 95, 95, .38) 0%, rgba(235, 24, 46, .16) 44%, transparent 74%);
  opacity: 0;
  transform: scale(.28);
  pointer-events: none;
}

.heart-zone::after {
  content: '';
  position: absolute;
  inset: 7%;
  border: 2px solid rgba(226, 199, 156, 0);
  border-radius: 50%;
  transform: scale(.72);
  pointer-events: none;
}

.heart-zone.is-holding::after {
  border-color: rgba(255, 74, 88, .92);
  box-shadow: 0 0 24px rgba(255, 28, 55, .55), inset 0 0 22px rgba(255, 35, 58, .28);
  animation: heart-zone-hold var(--heart-hold-duration, 3s) linear forwards;
}

.heart-zone.is-holding::before {
  opacity: 1;
  animation: heart-zone-core-breathe 1.05s ease-in-out infinite alternate;
}

.heart-zone.is-touching::before {
  opacity: 1;
  animation: heart-touch-arrive .42s cubic-bezier(.16,.72,.2,1) both;
}

.heart-zone__core {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 22%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #ff5365;
  box-shadow: 0 0 15px rgba(255, 93, 105, .95), 0 0 38px rgba(255, 16, 48, .7);
  opacity: 0;
  transform: translate(-50%, -50%) scale(.35);
  pointer-events: none;
}

.heart-zone.is-holding .heart-zone__core {
  opacity: .78;
  animation: heart-zone-gather var(--heart-hold-duration, 3s) cubic-bezier(.2,.7,.2,1) forwards;
}

.heart-zone.is-touching .heart-zone__core {
  opacity: .82;
}

.heart-zone__mote {
  --mote-x: 0px;
  --mote-y: -42px;
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  margin: -4px;
  border-radius: 50%;
  background: #ff4058;
  box-shadow: 0 0 5px #ff6a78, 0 0 13px rgba(255, 12, 46, .95);
  opacity: 0;
  pointer-events: none;
}

.heart-zone__mote:nth-of-type(2) { --mote-x: 2px;  --mote-y: -72px; }
.heart-zone__mote:nth-of-type(3) { --mote-x: 63px; --mote-y: -35px; }
.heart-zone__mote:nth-of-type(4) { --mote-x: 61px; --mote-y: 40px; }
.heart-zone__mote:nth-of-type(5) { --mote-x: -3px; --mote-y: 73px; }
.heart-zone__mote:nth-of-type(6) { --mote-x: -64px; --mote-y: 37px; }
.heart-zone__mote:nth-of-type(7) { --mote-x: -63px; --mote-y: -39px; }

.heart-zone.is-holding .heart-zone__mote {
  animation: heart-mote-in 1.18s ease-in infinite;
}
.heart-zone.is-holding .heart-zone__mote:nth-of-type(3) { animation-delay: -.2s; }
.heart-zone.is-holding .heart-zone__mote:nth-of-type(4) { animation-delay: -.4s; }
.heart-zone.is-holding .heart-zone__mote:nth-of-type(5) { animation-delay: -.6s; }
.heart-zone.is-holding .heart-zone__mote:nth-of-type(6) { animation-delay: -.8s; }
.heart-zone.is-holding .heart-zone__mote:nth-of-type(7) { animation-delay: -1s; }

.heart-zone.is-received .heart-zone__core {
  animation: heart-zone-received .72s ease-out forwards;
}

@keyframes heart-zone-hold {
  from { opacity: .25; transform: scale(.72); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes heart-zone-core-breathe {
  from { transform: scale(.76); filter: brightness(.88); }
  to { transform: scale(1.16); filter: brightness(1.2); }
}

@keyframes heart-touch-arrive {
  0% { opacity: 0; transform: scale(.2); }
  55% { opacity: 1; transform: scale(1.12); }
  100% { opacity: .82; transform: scale(1); }
}

@keyframes heart-zone-gather {
  0% { opacity: .18; transform: translate(-50%, -50%) scale(.35); }
  72% { opacity: .72; transform: translate(-50%, -50%) scale(.82); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1.18); }
}

@keyframes heart-mote-in {
  0% { opacity: 0; transform: translate(var(--mote-x), var(--mote-y)) scale(.45); }
  22% { opacity: .9; }
  78% { opacity: .55; }
  100% { opacity: 0; transform: translate(0, 0) scale(1.35); }
}

@keyframes heart-zone-received {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  45% { opacity: 1; transform: translate(-50%, -50%) scale(1.8); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(.55); }
}

.heart-gift-burst {
  position: absolute;
  z-index: 12;
  aspect-ratio: 1;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.heart-gift-burst__core,
.heart-gift-burst__ring {
  position: absolute;
  inset: 38%;
  border-radius: 50%;
}

.heart-gift-burst__core {
  background: #ff5265;
  box-shadow: 0 0 22px rgba(255, 105, 118, 1), 0 0 62px rgba(255, 16, 48, .82);
  animation: heart-gift-core .92s ease-out forwards;
}

.heart-gift-burst__ring {
  border: 3px solid rgba(255, 66, 84, .96);
  box-shadow: 0 0 16px rgba(255, 20, 50, .5);
  animation: heart-gift-ring .95s cubic-bezier(.15,.65,.2,1) forwards;
}

.heart-gift-burst__spark {
  --spark-angle: 0deg;
  position: absolute;
  left: 50%;
  top: 50%;
  width: 7px;
  height: 7px;
  margin: -3.5px;
  border-radius: 50%;
  background: #ff4158;
  box-shadow: 0 0 6px #ff7b87, 0 0 13px rgba(255, 10, 44, .95);
  animation: heart-gift-spark .86s ease-out forwards;
}
.heart-gift-burst__spark:nth-of-type(3) { --spark-angle: 15deg; }
.heart-gift-burst__spark:nth-of-type(4) { --spark-angle: 75deg; }
.heart-gift-burst__spark:nth-of-type(5) { --spark-angle: 135deg; }
.heart-gift-burst__spark:nth-of-type(6) { --spark-angle: 195deg; }
.heart-gift-burst__spark:nth-of-type(7) { --spark-angle: 255deg; }
.heart-gift-burst__spark:nth-of-type(8) { --spark-angle: 315deg; }

@keyframes heart-gift-core {
  0% { opacity: 1; transform: scale(.45); }
  38% { opacity: 1; transform: scale(1.4); }
  100% { opacity: 0; transform: scale(.35); }
}

@keyframes heart-gift-ring {
  0% { opacity: .9; transform: scale(.35); }
  100% { opacity: 0; transform: scale(4.4); }
}

@keyframes heart-gift-spark {
  0% { opacity: 1; transform: rotate(var(--spark-angle)) translateX(9px) scale(1); }
  100% { opacity: 0; transform: rotate(var(--spark-angle)) translateX(58px) scale(.4); }
}

@media (prefers-reduced-motion: reduce) {
  .heart-zone.is-holding::after,
  .heart-zone.is-holding::before,
  .heart-zone.is-holding .heart-zone__core,
  .heart-zone.is-holding .heart-zone__mote,
  .heart-zone.is-received .heart-zone__core,
  .heart-gift-burst * { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

.heart-zone--debug {
  outline: 2px dashed rgba(255, 90, 90, 0.7);
  outline-offset: -2px;
  background: rgba(255, 90, 90, 0.08);
}

/* ─── Pairs (memory game) scene ───────────────────────────────────────────── */
.pairs-screen {
  position: fixed;
  inset: 0;
  width: var(--app-width);
  height: var(--app-height);
  display: none;                 /* flex when active */
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 64px 18px 40px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 68%, rgba(118, 23, 8, 0.22), transparent 34%),
    #070604;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.pairs-screen__caption {
  min-height: 28px;
  font-family: 'Schoolbell', cursive;
  font-size: 21px;
  color: #C1A376;
  text-align: center;
  text-shadow: 0 0 18px rgba(193, 163, 118, 0.35);
  opacity: 0;
  transition: opacity 0.6s ease;
}
.pairs-screen__caption.is-visible { opacity: 1; }

.pairs-board {
  display: grid;
  gap: 10px;
  width: min(92%, 360px);
}

.pairs-card {
  position: relative;
  aspect-ratio: 3 / 4;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  perspective: 600px;
  -webkit-tap-highlight-color: transparent;
}

.pairs-card__inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.3, 1.2, 0.4, 1);
}
.pairs-card.is-flipped .pairs-card__inner { transform: rotateY(180deg); }

.pairs-card__back,
.pairs-card__face {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.pairs-card__back {
  background: #14100c;
  border: 1px solid rgba(193, 163, 118, 0.22);
  box-shadow: inset 0 0 22px rgba(0, 0, 0, 0.55);
}
.pairs-card__back::after {
  content: '';
  position: absolute;
  inset: 30%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(150, 30, 12, 0.5), transparent 70%);
}

.pairs-card__face {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transform: rotateY(180deg);
  background: #1b1510;
  border: 1px solid rgba(193, 163, 118, 0.45);
}
.pairs-card__face img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}
.pairs-card__glyph {
  font-family: 'Schoolbell', cursive;
  font-size: clamp(26px, 8vw, 40px);
  color: #C1A376;
  text-shadow: 0 0 14px rgba(193, 163, 118, 0.45);
}

.pairs-card.is-matched { pointer-events: none; }
.pairs-card.is-matched .pairs-card__face {
  border-color: rgba(193, 163, 118, 0.9);
  box-shadow: 0 0 18px rgba(193, 163, 118, 0.35);
  animation: pairs-match-glow 1.2s ease;
}
@keyframes pairs-match-glow {
  0%   { box-shadow: 0 0 4px  rgba(193, 163, 118, 0.2); }
  40%  { box-shadow: 0 0 26px rgba(193, 163, 118, 0.7); }
  100% { box-shadow: 0 0 18px rgba(193, 163, 118, 0.35); }
}

.pairs-screen__found {
  min-height: 20px;
  font-family: 'Schoolbell', cursive;
  font-size: 15px;
  letter-spacing: 2px;
  color: rgba(193, 163, 118, 0.65);
  text-align: center;
  transition: opacity .7s ease, transform .9s ease;
}

.pairs-screen.is-recovered .pairs-board {
  pointer-events: none;
}

.pairs-screen.is-recovered .pairs-card {
  opacity: 0;
  transform: translateY(-8px) scale(.9);
  transition: opacity .9s ease, transform .9s ease;
}

.pairs-screen.is-recovered .pairs-screen__caption {
  transform: translateY(-12px);
  transition: opacity .6s ease, transform 1s ease;
}

.pairs-screen.is-recovered .pairs-screen__found {
  min-height: 80px;
  transform: translateY(-42px);
}

.pairs-recovered-ember {
  display: block;
  width: 44px;
  height: 44px;
  margin: 0 auto;
  border-radius: 50%;
  background: radial-gradient(circle, #ffe1b8 0 7%, #e58b50 25%, rgba(143, 48, 22, .38) 50%, transparent 72%);
  filter: drop-shadow(0 0 14px rgba(218, 100, 48, .62));
  animation: recovered-ember-breathe 2.2s ease-in-out infinite;
}

@keyframes recovered-ember-breathe {
  0%, 100% { opacity: .68; transform: translateY(3px) scale(.88); }
  50% { opacity: 1; transform: translateY(-3px) scale(1.06); }
}

/* ─── Jigsaw (photo restoration) scene ────────────────────────────────────── */
.jigsaw-screen {
  position: fixed;
  inset: 0;
  width: var(--app-width);
  height: var(--app-height);
  display: none;                 /* flex when active */
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 64px 18px 40px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 68%, rgba(118, 23, 8, 0.22), transparent 34%),
    #070604;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.jigsaw-screen__caption {
  min-height: 28px;
  font-family: 'Schoolbell', cursive;
  font-size: 21px;
  color: #C1A376;
  text-align: center;
  text-shadow: 0 0 18px rgba(193, 163, 118, 0.35);
  opacity: 0;
  transition: opacity 0.6s ease;
}
.jigsaw-screen__caption.is-visible { opacity: 1; }
.jigsaw-screen__caption.is-win {
  font-size: 26px;
  font-weight: 700;
  color: #d8b988;
  text-shadow: 0 0 24px rgba(216, 185, 136, 0.55);
  animation: jigsaw-wintext-in 1.2s ease both;
}
@keyframes jigsaw-wintext-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.jigsaw-board {
  display: grid;
  gap: 6px;
  width: min(92%, 340px);
  aspect-ratio: var(--jigsaw-aspect, 3 / 4);
  padding: 8px;
  border-radius: 12px;
  background: #14100c;
  border: 1px solid rgba(193, 163, 118, 0.22);
  box-shadow: inset 0 0 22px rgba(0, 0, 0, 0.55);
  transition: gap 0.9s ease, padding 0.9s ease;
}
.jigsaw-board.is-solved {
  gap: 0;
  animation: jigsaw-solve-glow 2.4s ease forwards;
}
@keyframes jigsaw-solve-glow {
  0%   { box-shadow: inset 0 0 22px rgba(0, 0, 0, 0.55), 0 0 4px  rgba(193, 163, 118, 0.2); }
  45%  { box-shadow: inset 0 0 0 rgba(0, 0, 0, 0),        0 0 34px rgba(193, 163, 118, 0.75); }
  100% { box-shadow: inset 0 0 0 rgba(0, 0, 0, 0),        0 0 20px rgba(193, 163, 118, 0.4); }
}

.jigsaw-tile {
  position: relative;
  padding: 0;
  border: 1px solid rgba(193, 163, 118, 0.28);
  border-radius: 6px;
  background-color: #1b1510;
  background-repeat: no-repeat;
  cursor: pointer;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.3s ease, border-radius 0.9s ease, box-shadow 0.3s ease;
}
.jigsaw-board.is-solved .jigsaw-tile {
  border-color: transparent;
  border-radius: 0;
  pointer-events: none;
}

.jigsaw-tile.is-selected {
  border-color: rgba(193, 163, 118, 0.95);
  box-shadow: 0 0 14px rgba(193, 163, 118, 0.55), inset 0 0 10px rgba(193, 163, 118, 0.25);
  animation: jigsaw-selected-pulse 1.2s ease-in-out infinite;
}
@keyframes jigsaw-selected-pulse {
  0%, 100% { box-shadow: 0 0 8px  rgba(193, 163, 118, 0.35), inset 0 0 8px  rgba(193, 163, 118, 0.15); }
  50%      { box-shadow: 0 0 18px rgba(193, 163, 118, 0.7),  inset 0 0 12px rgba(193, 163, 118, 0.3); }
}

.jigsaw-tile.is-swapped { animation: jigsaw-swap-pop 0.35s ease; }
@keyframes jigsaw-swap-pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(0.92); }
  100% { transform: scale(1); }
}

.jigsaw-tile.is-placed:not(.is-selected) { border-color: rgba(193, 163, 118, 0.55); }

/* ── Jigsaw win sequence — cascade, bloom, shine, sparks, Ken Burns ────────── */
.jigsaw-board { position: relative; }

/* 1 · Golden pulse ripples outward from the center tile */
.jigsaw-board.is-winwave .jigsaw-tile {
  animation: jigsaw-winwave 0.6s ease both;
  animation-delay: var(--wave-delay, 0ms);
}
@keyframes jigsaw-winwave {
  0%   { filter: brightness(1);                  transform: scale(1); }
  45%  { filter: brightness(2.1) saturate(1.25); transform: scale(1.07);
         box-shadow: 0 0 20px rgba(255, 226, 168, 0.85); z-index: 2; }
  100% { filter: brightness(1.06);               transform: scale(1); }
}

/* 2 · Bloom flash on the impact beat */
.jigsaw-board::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle at 50% 42%,
    rgba(255, 242, 214, 0.95), rgba(255, 214, 150, 0.35) 45%, transparent 75%);
  opacity: 0;
  pointer-events: none;
  z-index: 3;
}
.jigsaw-board.is-bloom::after { animation: jigsaw-bloom 1.15s ease-out forwards; }
@keyframes jigsaw-bloom {
  0%   { opacity: 0; }
  16%  { opacity: 0.92; }
  100% { opacity: 0; }
}

/* 3 · Light sweep across the restored photo (the match-3 "polish" shine) */
.jigsaw-board::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(115deg,
    transparent 42%, rgba(255, 246, 224, 0.5) 50%, transparent 58%);
  background-size: 260% 100%;
  background-position: 130% 0;
  opacity: 0;
  pointer-events: none;
  z-index: 4;
}
.jigsaw-board.is-bloom::before {
  opacity: 1;
  animation: jigsaw-shine 1.4s ease-in-out 0.5s forwards;
}
@keyframes jigsaw-shine {
  from { background-position: 130% 0; }
  to   { background-position: -30% 0; opacity: 0; }
}

/* 4 · Golden dust motes rise off the photo */
.jigsaw-spark {
  position: absolute;
  width: var(--spark-size, 3px);
  height: var(--spark-size, 3px);
  border-radius: 50%;
  background: #ffe2a8;
  box-shadow: 0 0 8px 2px rgba(255, 214, 150, 0.75);
  opacity: 0;
  pointer-events: none;
  z-index: 5;
  animation: jigsaw-spark-rise 3s ease-out var(--spark-delay, 0s) forwards;
}
@keyframes jigsaw-spark-rise {
  0%   { opacity: 0;   transform: translate(0, 0)                          scale(0.6); }
  12%  { opacity: 0.95; }
  100% { opacity: 0;   transform: translate(var(--spark-drift, 0px), -110px) scale(1.15); }
}

/* 5 · The memory comes alive — slow breathe-in zoom (transition, so the
      solve-glow animation keeps running untouched) */
.jigsaw-board.is-alive {
  transform: scale(1.05);
  transition: transform 8s ease-out;
}

.jigsaw-screen__placed {
  min-height: 20px;
  font-family: 'Schoolbell', cursive;
  font-size: 15px;
  letter-spacing: 2px;
  color: rgba(193, 163, 118, 0.65);
}
