/* Game reels: scratch (.rx-), memory (.rm-), quiz (.rq-).
   Each fills the dark reel stage and keeps its interactive card clear of gram's caption (bottom ~120px)
   and like-rail (right ~64px). */

/* ======================================================================
   SCRATCH  .rx-
   ====================================================================== */
.rx {
  position: absolute; inset: 0; overflow: hidden;
  display: grid; place-items: center;
  padding: var(--g-safe-top, calc(64px + env(safe-area-inset-top)))
           calc(var(--g-safe-right, 64px) + env(safe-area-inset-right))
           max(var(--g-safe-bottom, 0px), calc(112px + env(safe-area-inset-bottom)))
           calc(20px + env(safe-area-inset-left));
  background:
    radial-gradient(60% 45% at 50% 42%, rgba(246, 211, 101, 0.22), rgba(246, 211, 101, 0) 70%),
    radial-gradient(120% 80% at 50% 110%, #3a1d4f 0%, rgba(58, 29, 79, 0) 60%),
    linear-gradient(180deg, #120a1c, #1d1029 60%, #120a1c);
  color: #fff;
  container-type: size;
}
.rx-col { display: flex; flex-direction: column; align-items: center; gap: 14px; width: 100%; }

.rx-card {
  position: relative;
  width: min(100cqw, (100cqh - 92px) * 0.75, 420px);
  aspect-ratio: 3 / 4;
  border-radius: 22px; overflow: hidden;
  background: #2a1d33;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08), 0 18px 50px -10px rgba(0, 0, 0, 0.7), 0 0 60px -10px rgba(246, 211, 101, 0.35);
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
.rx-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.rx-noimg .rx-img { display: none; }
.rx-noimg::before { content: "🎁"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 72px; }

.rx-cover {
  position: absolute; inset: 0; width: 100%; height: 100%;
  touch-action: none; cursor: grab;
  transition: opacity 650ms var(--ease-out), transform 650ms var(--ease-out), filter 650ms;
}
.rx-card.is-scratching .rx-cover { cursor: grabbing; }
.rx-card.is-revealed .rx-cover { opacity: 0; transform: scale(1.12); filter: blur(6px); pointer-events: none; }
.rx-dust { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.rx-hint {
  position: absolute; left: 50%; bottom: 14%; transform: translateX(-50%);
  padding: 9px 16px; border-radius: var(--radius-pill);
  background: rgba(40, 24, 6, 0.72); color: #fff6d8;
  font: 700 15px/1 var(--font-sans); white-space: nowrap; pointer-events: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  transition: opacity 300ms, transform 300ms;
}
.rx-hint-hand { display: inline-block; animation: rx-rub 1.4s ease-in-out infinite; }
@keyframes rx-rub { 0%, 100% { transform: translateX(-4px) rotate(-10deg); } 50% { transform: translateX(5px) rotate(8deg); } }
.rx-card.is-scratching .rx-hint, .rx-card.is-revealed .rx-hint { opacity: 0; transform: translateX(-50%) translateY(8px); }

/* a light sweep across the photo when it's revealed */
.rx-shine {
  position: absolute; inset: -20%; pointer-events: none; opacity: 0;
  background: linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.55) 50%, transparent 60%);
  transform: translateX(-60%);
}
.rx-card.is-revealed .rx-shine { animation: rx-shine 1.1s 350ms var(--ease-out) both; }
@keyframes rx-shine { 0% { opacity: 1; transform: translateX(-60%); } 100% { opacity: 1; transform: translateX(60%); } }
.rx-card.is-revealed { animation: rx-pop 600ms var(--ease-spring); }
@keyframes rx-pop { 0% { transform: scale(1); } 40% { transform: scale(1.04); } 100% { transform: scale(1); } }

.rx-foot { position: relative; height: 78px; width: 100%; display: grid; justify-items: center; align-content: start; }
.rx-meter {
  width: min(60%, 180px); height: 6px; margin-top: 4px; border-radius: 3px; overflow: hidden;
  background: rgba(255, 255, 255, 0.14); transition: opacity 300ms;
}
.rx-meter i {
  display: block; height: 100%; border-radius: inherit;
  background: linear-gradient(90deg, #f6d365, #fda085);
  transform-origin: left; transform: scaleX(0); transition: transform 200ms var(--ease-out);
}
.rx-msg {
  position: absolute; top: 0; left: 0; right: 0; margin: 0; text-align: center;
  font: 800 clamp(18px, 5.4vw, 22px)/1.25 var(--font-sans); text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  opacity: 0; transform: translateY(10px) scale(0.92); pointer-events: none;
  transition: opacity 400ms var(--ease-out), transform 500ms var(--ease-spring);
}
.rx-again {
  position: absolute; bottom: 0; left: 50%;
  min-height: 36px; padding: 0 16px; border-radius: var(--radius-pill);
  border: 1px solid rgba(255, 255, 255, 0.35); background: rgba(255, 255, 255, 0.12); color: #fff;
  font: 700 14px/1 var(--font-sans);
  opacity: 0; visibility: hidden; transform: translateX(-50%) translateY(6px);
  transition: opacity 300ms 500ms, transform 300ms 500ms, visibility 0s 800ms, background var(--dur);
}
.rx-again:hover { background: rgba(255, 255, 255, 0.22); }
.rx-again:active { transform: translateX(-50%) scale(0.95); }
.rx.is-done .rx-meter { opacity: 0; }
.rx.is-done .rx-msg { opacity: 1; transform: none; transition-delay: 250ms; }
.rx.is-done .rx-again { opacity: 1; visibility: visible; transform: translateX(-50%); transition-delay: 700ms, 700ms, 0s, 0s; }

/* ======================================================================
   MEMORY  .rm-
   ====================================================================== */
.rm {
  position: absolute; inset: 0; overflow: hidden;
  padding: var(--g-safe-top, calc(64px + env(safe-area-inset-top)))
           calc(var(--g-safe-right, 64px) + env(safe-area-inset-right))
           max(var(--g-safe-bottom, 0px), calc(112px + env(safe-area-inset-bottom)))
           calc(20px + env(safe-area-inset-left));
  background:
    radial-gradient(70% 50% at 50% 45%, rgba(120, 90, 255, 0.28), rgba(120, 90, 255, 0) 70%),
    radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.06) 1px, transparent 1.5px) 0 0 / 22px 22px,
    linear-gradient(180deg, #0c0f24, #17123a 55%, #0c0f24);
  color: #fff;
}
.rm-col { height: 100%; display: flex; flex-direction: column; align-items: center; gap: 12px; }

.rm-head { flex: none; width: 100%; max-width: 460px; display: grid; justify-items: center; gap: 8px; }
.rm-hint { margin: 0; font: 700 15px/1.3 var(--font-sans); text-align: center; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4); }
.rm-stats { display: flex; gap: 8px; }
.rm-stat {
  padding: 4px 11px; border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.14);
  font: 600 12.5px/1.2 var(--font-sans); font-variant-numeric: tabular-nums; color: rgba(255, 255, 255, 0.85);
}

.rm-board { flex: 1 1 auto; min-height: 0; width: 100%; display: grid; place-items: center; }
.rm-grid {
  --cols: 3; --cw: 80px;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
  width: calc(var(--cols) * var(--cw) + (var(--cols) - 1) * 8px); /* incomplete last row is centred */
}
.rm-empty { margin: 0; color: rgba(255, 255, 255, 0.7); text-align: center; }

.rm-card {
  position: relative; width: var(--cw); aspect-ratio: 3 / 4; padding: 0; border: 0; background: none;
  perspective: 700px; border-radius: 12px;
  -webkit-user-select: none; user-select: none; touch-action: manipulation;
}
.rm-card:focus-visible { outline: 3px solid #ffd166; outline-offset: 3px; }
.rm-inner {
  position: absolute; inset: 0; display: block;
  transform-style: preserve-3d; -webkit-transform-style: preserve-3d;
  transition: transform 420ms var(--ease-out);
}
.rm-card.is-up .rm-inner { transform: rotateY(180deg); }
.rm-card:not(.is-up):active .rm-inner { transform: scale(0.94); }

.rm-face {
  position: absolute; inset: 0; display: block; overflow: hidden; border-radius: 12px;
  -webkit-backface-visibility: hidden; backface-visibility: hidden;
  box-shadow: 0 6px 16px -6px rgba(0, 0, 0, 0.6);
}
.rm-back {
  display: grid; place-items: center;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.22) 0 26%, transparent 27%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.09) 0 6px, transparent 6px 12px),
    linear-gradient(140deg, #ff6fa5, #a66bff 60%, #6a7bff);
  border: 2px solid rgba(255, 255, 255, 0.55);
}
.rm-back-mark { font-size: calc(var(--cw) * 0.3); line-height: 1; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.25)); }
.rm-front { transform: rotateY(180deg); background: #222; border: 2px solid #fff; }
.rm-img { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }

.rm-card.is-matched .rm-front { border-color: #7ef0a8; box-shadow: 0 0 0 3px rgba(126, 240, 168, 0.35), 0 8px 22px -6px rgba(126, 240, 168, 0.6); }
.rm-card.is-matched { animation: rm-pop 520ms var(--ease-spring); }
@keyframes rm-pop { 0% { transform: scale(1); } 45% { transform: scale(1.12); } 100% { transform: scale(1); } }
.rm-card.is-wrong { animation: rm-shake 420ms ease-in-out; }
.rm-card.is-wrong .rm-front { border-color: #ff6b7d; }
@keyframes rm-shake { 0%, 100% { transform: none; } 20% { transform: translateX(-6px) rotate(-2deg); } 40% { transform: translateX(5px) rotate(2deg); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }
.rm.is-won .rm-card { animation: rm-wave 900ms calc(var(--i) * 45ms) var(--ease-spring) both; }
@keyframes rm-wave { 0%, 100% { transform: none; } 40% { transform: translateY(-12px) rotate(-3deg); } }

.rm-foot { flex: none; height: 92px; width: 100%; display: grid; justify-items: center; align-content: start; gap: 4px; }
.rm-win {
  margin: 0; text-align: center; font: 800 clamp(17px, 5vw, 21px)/1.25 var(--font-sans);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}
.rm-win-sub { margin: 0; font: 500 13px/1.3 var(--font-sans); color: rgba(255, 255, 255, 0.7); }
.rm-again {
  margin-top: 6px; min-height: 36px; padding: 0 16px; border-radius: var(--radius-pill);
  border: 1px solid rgba(255, 255, 255, 0.35); background: rgba(255, 255, 255, 0.12); color: #fff;
  font: 700 14px/1 var(--font-sans); transition: background var(--dur), transform var(--dur) var(--ease-out);
}
.rm-again:hover { background: rgba(255, 255, 255, 0.22); }
.rm-again:active { transform: scale(0.95); }
.rm-foot > * { opacity: 0; visibility: hidden; transform: translateY(8px); transition: opacity 400ms, transform 500ms var(--ease-spring), visibility 0s 500ms; }
.rm.is-won .rm-foot > * { opacity: 1; visibility: visible; transform: none; transition: opacity 400ms, transform 500ms var(--ease-spring), visibility 0s; }
.rm.is-won .rm-win-sub { transition-delay: 150ms; }
.rm.is-won .rm-again { transition-delay: 450ms; }

/* ======================================================================
   QUIZ  .rq-
   ====================================================================== */
.rq {
  position: absolute; inset: 0; overflow: hidden;
  display: grid; place-items: center;
  padding: var(--g-safe-top, calc(64px + env(safe-area-inset-top)))
           calc(var(--g-safe-right, 64px) + env(safe-area-inset-right))
           max(var(--g-safe-bottom, 0px), calc(112px + env(safe-area-inset-bottom)))
           calc(20px + env(safe-area-inset-left));
  background:
    radial-gradient(70% 40% at 20% 10%, rgba(255, 93, 143, 0.35), rgba(255, 93, 143, 0) 70%),
    radial-gradient(70% 40% at 90% 90%, rgba(98, 40, 215, 0.45), rgba(98, 40, 215, 0) 70%),
    linear-gradient(180deg, #1a0d24, #120a22);
  color: #fff;
}
.rq-card {
  position: relative; width: min(100%, 420px); max-height: 100%; overflow: auto; overscroll-behavior: contain;
  padding: 18px 18px 20px; border-radius: 22px;
  background: rgba(255, 255, 255, 0.96); color: #23182b;
  box-shadow: 0 24px 60px -16px rgba(0, 0, 0, 0.7);
  scrollbar-width: none;
}
.rq-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.rq-dots { display: flex; gap: 6px; flex-wrap: wrap; }
.rq-dots i {
  display: block; width: 8px; height: 8px; border-radius: 4px; background: #e4dcea;
  transition: width 300ms var(--ease-out), background 300ms;
}
.rq-dots i.is-current { width: 22px; background: #b07cff; }
.rq-dots i.is-right { background: #2fbf71; }
.rq-dots i.is-wrong { background: #ff5470; }
.rq-count { font: 700 12px/1 var(--font-sans); color: #8a7b96; font-variant-numeric: tabular-nums; }

.rq-body.is-in { animation: rq-in 420ms var(--ease-out) both; }
@keyframes rq-in { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }

.rq-hint { margin: 0 0 6px; font: 700 12px/1.2 var(--font-sans); letter-spacing: 0.06em; text-transform: uppercase; color: #a35bd8; }
.rq-q { margin: 0 0 14px; font: 800 clamp(19px, 5.6vw, 23px)/1.25 var(--font-sans); overflow-wrap: anywhere; }

.rq-opts { display: grid; gap: 8px; }
.rq-opt {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 48px; padding: 8px 12px;
  border: 2px solid #ece5f1; border-radius: 14px; background: #fff; color: inherit; text-align: left;
  font: 600 16px/1.3 var(--font-sans);
  transition: transform 160ms var(--ease-out), border-color 200ms, background 200ms, opacity 300ms;
  animation: rq-in 380ms calc(80ms + var(--i) * 50ms) var(--ease-out) both;
}
.rq-opt:not(:disabled):hover { border-color: #cdb5ef; background: #faf6ff; }
.rq-opt:not(:disabled):active { transform: scale(0.97); }
.rq-opt:disabled { cursor: default; }
.rq-letter {
  flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 9px;
  background: #f1eaf7; color: #7d4bb5; font: 800 13px/1 var(--font-sans);
  transition: background 200ms, color 200ms;
}
.rq-text { overflow-wrap: anywhere; }
.rq-opt.is-right { border-color: #2fbf71; background: #e9f9f0; animation: rq-yay 450ms var(--ease-spring); }
.rq-opt.is-right .rq-letter { background: #2fbf71; color: transparent; position: relative; }
.rq-opt.is-right .rq-letter::after { content: "✓"; position: absolute; color: #fff; }
.rq-opt.is-wrong { border-color: #ff5470; background: #fff0f2; animation: rq-shake 420ms ease-in-out; }
.rq-opt.is-wrong .rq-letter { background: #ff5470; color: transparent; position: relative; }
.rq-opt.is-wrong .rq-letter::after { content: "✕"; position: absolute; color: #fff; }
.rq-opt.is-dim { opacity: 0.45; }
@keyframes rq-yay { 0% { transform: scale(1); } 40% { transform: scale(1.04); } 100% { transform: scale(1); } }
@keyframes rq-shake { 0%, 100% { transform: none; } 20% { transform: translateX(-7px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }

.rq-after { display: none; }
.rq-card.is-answered .rq-after { display: grid; gap: 12px; margin-top: 14px; animation: rq-up 380ms var(--ease-out) both; }
@keyframes rq-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.rq-feedback { margin: 0; padding: 10px 12px; border-radius: 12px; font: 600 15px/1.35 var(--font-sans); overflow-wrap: anywhere; }
.rq-feedback.is-right { background: #e9f9f0; color: #1b7a48; }
.rq-feedback.is-wrong { background: #fff0f2; color: #b02a43; }

.rq-next {
  justify-self: stretch; min-height: 46px; border: 0; border-radius: 14px;
  background: linear-gradient(135deg, #ff5d8f, #a35bd8); color: #fff;
  font: 800 16px/1 var(--font-sans); box-shadow: 0 8px 18px -8px rgba(163, 91, 216, 0.8);
  transition: transform 160ms var(--ease-out), filter 200ms;
}
.rq-next:hover { filter: brightness(1.06); }
.rq-next:active { transform: scale(0.97); }

/* end screen */
.rq-card.is-end .rq-body { display: grid; justify-items: center; text-align: center; gap: 10px; padding-top: 4px; }
.rq-ring {
  --p: 0;
  position: relative; width: 120px; height: 120px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(#2fbf71 calc(var(--p) * 360deg), #efe8f4 0);
  animation: rq-pop 600ms var(--ease-spring) both;
}
.rq-ring::before { content: ""; position: absolute; inset: 11px; border-radius: 50%; background: #fff; }
.rq-score { position: relative; font: 900 30px/1 var(--font-sans); font-variant-numeric: tabular-nums; }
@keyframes rq-pop { from { opacity: 0; transform: scale(0.5); } to { opacity: 1; transform: none; } }
.rq-end-msg { margin: 6px 0 0; font: 800 clamp(19px, 5.6vw, 23px)/1.25 var(--font-sans); overflow-wrap: anywhere; }
.rq-end-sub { margin: 0 0 6px; font: 500 14px/1.3 var(--font-sans); color: #7b6b88; }
.rq-again { width: 100%; }
