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

body {
  background: #1a1a2e;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  overflow: hidden;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* ── Loading Screen ─────────────────────────────────────────── */
#loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: #1a1a2e;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  color: #fff;
  font-family: system-ui, -apple-system, sans-serif;
}

#loading-screen.hidden {
  display: none;
}

#loading-screen h1 {
  font-size: 2.5rem;
  margin-bottom: 1.5rem;
}

#loading-bar-container {
  width: 300px;
  height: 20px;
  background: #2a2a4e;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 1rem;
}

#loading-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #4facfe, #00f2fe);
  border-radius: 10px;
  transition: width 0.3s ease;
}

#loading-status {
  font-size: 1rem;
  opacity: 0.7;
}

/* ── Intro Overlay ──────────────────────────────────────────── */
#intro-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: #000;
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 9998;
  cursor: pointer;
}

/* Skip intro button — small play icon, bottom-right */
#skip-intro-btn {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.7);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  padding-left: 4px; /* optical center for ▶ */
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.15s ease;
  z-index: 9999;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
#skip-intro-btn:hover,
#skip-intro-btn:active {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.7);
  color: #fff;
  transform: scale(1.1);
}

#intro-overlay.active {
  display: flex;
}

#intro-photo {
  height: 400px;
  width: auto;
  max-width: 90vw;
  object-fit: contain;
  border-radius: 20px;
  pointer-events: none;
}

/* Pulsating glow to attract child's attention */
#intro-photo.pulsate {
  animation: introPulsate 1.8s ease-in-out infinite;
}

@keyframes introPulsate {
  0%   { filter: drop-shadow(0 0 8px rgba(79, 172, 254, 0.3)) brightness(0.85); transform: scale(1); }
  50%  { filter: drop-shadow(0 0 40px rgba(79, 172, 254, 0.9)) drop-shadow(0 0 80px rgba(0, 242, 254, 0.5)) brightness(1.1); transform: scale(1.04); }
  100% { filter: drop-shadow(0 0 8px rgba(79, 172, 254, 0.3)) brightness(0.85); transform: scale(1); }
}

/* Gentle side-to-side rocking while audio plays */
#intro-photo.rocking {
  animation: introRock 2.5s ease-in-out infinite;
  filter: brightness(1);
}

@keyframes introRock {
  0%   { transform: rotate(0deg); }
  25%  { transform: rotate(3deg); }
  50%  { transform: rotate(0deg); }
  75%  { transform: rotate(-3deg); }
  100% { transform: rotate(0deg); }
}

/* Static — no animation */
#intro-photo.static {
  animation: none;
  filter: brightness(1);
}

/* Intro home.png — warm golden glow to invite a tap */
#intro-photo.home-pulsate {
  height: 220px;
  animation: homePulsate 2s ease-in-out infinite;
  border-radius: 50%;
}

@keyframes homePulsate {
  0%   { filter: drop-shadow(0 0 10px rgba(255, 200, 50, 0.4)) brightness(0.9); transform: scale(1); }
  50%  { filter: drop-shadow(0 0 50px rgba(255, 200, 50, 1)) drop-shadow(0 0 100px rgba(255, 160, 0, 0.6)) brightness(1.2); transform: scale(1.08); }
  100% { filter: drop-shadow(0 0 10px rgba(255, 200, 50, 0.4)) brightness(0.9); transform: scale(1); }
}

/* ── Game Container ─────────────────────────────────────────── */
#game-container {
  position: relative;
  width: 1280px;
  height: 720px;
  overflow: hidden;
  display: none;
  background: #000;
}

#game-container.active {
  display: block;
}

#game-container img {
  display: block;
}

/* ── Background layer ───────────────────────────────────────── */
#bg-base {
  position: absolute;
  top: 0;
  left: 0;
  width: 1280px;
  height: 720px;
  object-fit: contain;
  z-index: 0;
}

/* ── BG overlay quarters ────────────────────────────────────── */
.bg-overlay {
  position: absolute;
  width: 640px;
  height: 360px;
  object-fit: fill;
  opacity: 1;
  pointer-events: none;
}

.bg-overlay.revealing {
  animation: bgReveal 5s ease forwards;
}

@keyframes bgReveal {
  0%   { opacity: 1; }
  30%  { opacity: 0; }
  70%  { opacity: 0; }
  100% { opacity: 0.8; }
}

.bg-overlay.completed {
  opacity: 0.8;
}

#bg1 { top: 0;     left: 0;    z-index: 1; }
#bg2 { top: 0;     left: 640px; z-index: 1; }
#bg3 { top: 360px; left: 640px; z-index: 1; }
#bg4 { top: 360px; left: 0;    z-index: 1; }

/* ── Draggable sprites (space objects) ──────────────────────── */
.sprite {
  position: absolute;
  cursor: grab;
  touch-action: none;
  transform: translate(-50%, -50%);
}

.sprite.dragging {
  cursor: grabbing;
  filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.5));
}

.sprite img {
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ── Family member photo ────────────────────────────────────── */
.family-member {
  position: absolute;
  cursor: grab;
  touch-action: none;
  transform: translate(-50%, -50%);
}

.family-member.dragging {
  cursor: grabbing;
  filter: drop-shadow(0 0 12px rgba(79, 172, 254, 0.8));
}

.family-member img {
  height: 100px;
  width: auto;
  max-width: none;
  pointer-events: none;
}

/* ── Home target ─────────────────────────────────────────────── */
#home-target {
  position: absolute;
  cursor: default;
  touch-action: none;
  transform: translate(-50%, -50%);
  z-index: 500;
  transition: transform 0.3s ease, filter 0.3s ease;
}

#home-target img {
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#home-target.glow {
  filter: drop-shadow(0 0 20px rgba(0, 242, 254, 0.9));
  transform: translate(-50%, -50%) scale(1.15);
}

#home-target.pulsate {
  animation: homePulsate 1.8s ease-in-out infinite;
}

@keyframes homePulsate {
  0%   { filter: drop-shadow(0 0 8px rgba(0, 242, 254, 0.3)); transform: translate(-50%, -50%) scale(1); }
  50%  { filter: drop-shadow(0 0 25px rgba(0, 242, 254, 0.8)); transform: translate(-50%, -50%) scale(1.1); }
  100% { filter: drop-shadow(0 0 8px rgba(0, 242, 254, 0.3)); transform: translate(-50%, -50%) scale(1); }
}

/* ── Post-Game Reveal ───────────────────────────────────────── */
#post-game-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 9999;
  display: none;
  font-family: system-ui, -apple-system, sans-serif;
  color: #fff;
  overflow: hidden;
}
#post-game-overlay.active {
  display: block;
}

/* Coloring page wrapper with narrow black border */
#pg-coloring-page-wrapper {
  position: absolute;
  top: 26px;
  left: 15px;
  width: 1000px;
  height: 667px;
  z-index: 1;
  border: 2px solid #000;
}

#pg-coloring-page {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* Canvas exactly overlays the coloring page */
#pg-draw-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 1000px;
  height: 667px;
  display: none;
  touch-action: none;
  cursor: crosshair;
  z-index: 10;
}
#pg-draw-canvas.active {
  display: block;
}

/* Grandparent photo container - positioned over coloring page */
#pg-photos {
  position: absolute;
  top: 26px;
  left: 15px;
  width: 1000px;
  height: 667px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
#pg-photos.hidden { display: none; }

.pg-photo {
  max-height: 400px;
  width: auto;
  border-radius: 16px;
  object-fit: contain;
  cursor: pointer;
  pointer-events: auto;
}
.pg-photo.pulsate {
  animation: introPulsate 1.8s ease-in-out infinite;
}
.pg-photo.rocking {
  animation: introRock 2.5s ease-in-out infinite;
  filter: brightness(1);
}

/* Drawing UI - crayons and send button */
#pg-drawing-ui {
  display: none;
}
#pg-drawing-ui.active {
  display: block;
}

.pg-crayon {
  position: absolute;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.pg-crayon:hover {
  opacity: 0.8;
}
.pg-crayon.pulsate {
  animation: introPulsate 1.8s ease-in-out infinite;
}
.pg-crayon.selected {
  opacity: 1;
  transform: scale(1.1);
}

#pg-crayon-red {
  top: 30px;
  left: 1040px;
  width: 200px;
  height: 51px;
  z-index: 11;
}

#pg-crayon-blue {
  top: 90px;
  left: 1040px;
  width: 200px;
  height: 51px;
  z-index: 11;
}

.pg-btn-send-drawing {
  position: absolute;
  top: 206px;
  left: 1073px;
  width: 149px;
  height: 294px;
  z-index: 12;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  opacity: 0.4;
  transition: opacity 0.3s ease;
}
.pg-btn-send-drawing img {
  width: 100%;
  height: 100%;
  display: block;
}
.pg-btn-send-drawing:disabled,
.pg-btn-send-drawing.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}
.pg-btn-send-drawing.active:not(:disabled):not(.disabled) {
  opacity: 1;
}
.pg-btn-send-drawing.pulsate {
  animation: introPulsate 1.8s ease-in-out infinite;
}
.pg-btn-send-drawing:active:not(:disabled):not(.disabled) {
  transform: scale(0.95);
}

/* Audio UI - record button */
#pg-audio-ui {
  display: none;
}
#pg-audio-ui.active {
  display: block;
}

/* Large red record button — positioned where crayons are in drawing scene */
.pg-btn-record {
  position: absolute;
  top: 25px;
  left: 1085px;
  width: 110px;
  height: 110px;
  z-index: 13;
  padding: 0;
  border: 4px solid #fff;
  border-radius: 50%;
  background: #cc0000;
  color: #fff;
  font-size: 3rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 20px rgba(204, 0, 0, 0.5);
}
.pg-btn-record.pulsate {
  animation: introPulsate 1.8s ease-in-out infinite;
}
.pg-btn-record.recording {
  animation: mic-pulse 1s ease-in-out infinite;
  background: #ff2222;
  box-shadow: 0 4px 30px rgba(255, 34, 34, 0.8);
}
.pg-btn-record:active {
  transform: scale(0.92);
}

/* Send audio button — same layout as drawing send button */
.pg-btn-send-audio {
  position: absolute;
  top: 206px;
  left: 1073px;
  width: 149px;
  height: 294px;
  z-index: 12;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  opacity: 0.4;
  transition: opacity 0.3s ease;
  display: none; /* hidden until recording is done */
}
.pg-btn-send-audio img {
  width: 100%;
  height: 100%;
  display: block;
}
.pg-btn-send-audio:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.pg-btn-send-audio.active:not(:disabled) {
  display: block;
  opacity: 1;
}
.pg-btn-send-audio.pulsate {
  animation: introPulsate 1.8s ease-in-out infinite;
}
.pg-btn-send-audio:active:not(:disabled) {
  transform: scale(0.95);
}

#pg-recording-status {
  position: absolute;
  top: 520px;
  left: 1040px;
  width: 200px;
  text-align: center;
  font-size: 1.2rem;
  font-weight: 600;
  color: #fff;
  z-index: 13;
}

@keyframes mic-pulse {
  0%, 100% { transform: scale(1); filter: brightness(1); }
  50% { transform: scale(1.05); filter: brightness(1.2); }
}

/* Print UI container */
#pg-print-ui {
  display: none;
}
#pg-print-ui.active {
  display: block;
}

/* Print icon - pulsates to attract attention */
#pg-print-icon {
  position: absolute;
  top: 200px;
  left: 1070px;
  width: 150px;
  height: 150px;
  z-index: 15;
  cursor: pointer;
  display: none;
  transition: transform 0.15s ease;
}
#pg-print-icon.visible {
  display: block;
}
#pg-print-icon.pulsate {
  display: block;
  animation: printPulsate 1.8s ease-in-out infinite;
}
#pg-print-icon:active {
  transform: scale(0.92);
}

@keyframes printPulsate {
  0%   { filter: drop-shadow(0 0 8px rgba(255, 200, 50, 0.3)) brightness(0.85); transform: scale(1); }
  50%  { filter: drop-shadow(0 0 40px rgba(255, 200, 50, 0.9)) drop-shadow(0 0 80px rgba(255, 160, 0, 0.5)) brightness(1.15); transform: scale(1.08); }
  100% { filter: drop-shadow(0 0 8px rgba(255, 200, 50, 0.3)) brightness(0.85); transform: scale(1); }
}

/* Subtle play-again button — doesn't draw attention */
#pg-play-again-btn {
  position: absolute;
  bottom: 20px;
  right: 15px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.4);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  padding-left: 4px;
  z-index: 16;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.15s ease;
}
#pg-play-again-btn.visible {
  display: flex;
}
#pg-play-again-btn:hover,
#pg-play-again-btn:active {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.5);
  color: rgba(255, 255, 255, 0.7);
  transform: scale(1.1);
}

/* Base button styles */
.pg-btn {
  font-size: 1.3rem;
  padding: 14px 28px;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  font-family: system-ui, -apple-system, sans-serif;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.pg-btn:active { transform: scale(0.95); }

/* ── Consent Modal ──────────────────────────────────────────── */
#consent-modal {
  position: fixed;
  top: 0; left: 0;
  width: 100vw; height: 100vh;
  background: rgba(0, 0, 0, 0.85);
  z-index: 99999;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: system-ui, -apple-system, sans-serif;
  color: #fff;
}
#consent-modal.active { display: flex; }

#consent-modal-box {
  background: #1e1e3a;
  border-radius: 20px;
  padding: 30px;
  max-width: 420px;
  width: 90vw;
  text-align: center;
}

#consent-modal-box h2 {
  font-size: 1.5rem;
  margin-bottom: 16px;
}

#consent-modal-box p {
  font-size: 1rem;
  margin-bottom: 20px;
  opacity: 0.85;
  line-height: 1.5;
}

#consent-modal-box label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.95rem;
  text-align: left;
  margin-bottom: 20px;
  cursor: pointer;
  line-height: 1.4;
}

#consent-modal-box input[type="checkbox"] {
  width: 22px;
  height: 22px;
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: #4facfe;
}

#consent-confirm-btn {
  font-size: 1.1rem;
  padding: 12px 30px;
  border: none;
  border-radius: 12px;
  background: #4facfe;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}
#consent-confirm-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#consent-cancel-btn {
  display: inline-block;
  margin-top: 14px;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.35);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
  font-family: system-ui, -apple-system, sans-serif;
}
#consent-cancel-btn:hover {
  color: rgba(255, 255, 255, 0.6);
}

/* ── Print-only stylesheet ─────────────────────────────────── */
@media print {
  body * { visibility: hidden !important; }
  #print-frame,
  #print-frame * { visibility: visible !important; }
  #print-frame {
    position: fixed !important;
    top: 0 !important; left: 0 !important;
    width: 100% !important; height: 100% !important;
    border: none !important;
    margin: 0 !important;
    padding: 0 !important;
  }
}

#install-screen {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: #1a1a2e;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

#install-box {
  background: #2d2d5e;
  border-radius: 20px;
  padding: 32px 28px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  color: #e0e0ff;
  font-family: system-ui, -apple-system, sans-serif;
}

#install-icon {
  font-size: 64px;
  margin-bottom: 12px;
}

#install-title {
  font-size: 24px;
  margin-bottom: 16px;
  color: #fff;
}

#install-body {
  font-size: 15px;
  line-height: 1.6;
  margin-bottom: 24px;
  text-align: left;
}

#install-body ol {
  margin: 12px 0 0 20px;
  padding: 0;
}

#install-body li {
  margin-bottom: 8px;
}

.ios-share-icon {
  display: inline-block;
  vertical-align: middle;
  font-size: 18px;
}

#install-btn {
  display: inline-block;
  background: #6c63ff;
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 14px 32px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 12px;
  transition: background 0.2s;
}

#install-btn:hover {
  background: #5a52d5;
}

#install-ios-steps {
  text-align: left;
  margin-bottom: 20px;
  font-size: 14px;
  line-height: 1.7;
  color: #c0c0e0;
}

#install-skip-btn {
  background: none;
  border: none;
  color: #8888bb;
  font-size: 14px;
  cursor: pointer;
  text-decoration: underline;
}

#install-skip-btn:hover {
  color: #aaaadd;
}