@font-face {
  font-family: 'ChoretBubble';
  src: url('https://raw.githubusercontent.com/kynahpics4-ship-it/tff/c2817acfdf63b0b1957b32fc89ebcaa162391091/ChoretFudyngBubbleRegular-3zYPG.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

body {
  font-family: 'Baloo 2', sans-serif;
  margin: 0;
  padding: 0;
  color: #28303d;
  overflow-x: hidden;
  background: #f7f8ff;
}

/* Realistic notebook paper background */
#balloon-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    /* Main paper texture */
    radial-gradient(ellipse farthest-corner at 20% 80%, rgba(255,255,255,0.92) 0%, rgba(248,248,252,0.88) 50%, rgba(240,242,248,0.85) 100%),
    
    /* Faint paper grain */
    radial-gradient(circle at 30% 40%, rgba(255,255,255,0.15) 0%, transparent 50%),
    radial-gradient(circle at 70% 70%, rgba(255,255,255,0.12) 0%, transparent 50%),
    radial-gradient(circle at 10% 20%, rgba(255,255,255,0.08) 0%, transparent 50%),
    
    /* Notebook blue lines */
    repeating-linear-gradient(
      to bottom,
      transparent 0px,
      transparent 24px,
      rgba(135, 152, 186, 0.35) 24px,
      rgba(135, 152, 186, 0.35) 25px
    ),
    
    /* Vertical margin line */
    repeating-linear-gradient(
      to right,
      transparent 0px,
      transparent 32px,
      rgba(135, 152, 186, 0.4) 32px,
      rgba(135, 152, 186, 0.4) 33px
    ),
    
    /* Subtle paper fold shadows */
    linear-gradient(to bottom, rgba(0,0,0,0.02) 0%, transparent 10%, transparent 90%, rgba(0,0,0,0.03) 100%),
    
    /* Paper color base */
    #f9f9fb;
  backdrop-filter: blur(0.8px) saturate(1.02);
}

/* Pencil handwriting font + writing animation */
.doodle {
  position: absolute;
  font-family: "Reenie+Beanie", "Caveat", "ChoretBubble", cursive;
  font-size: clamp(1.4rem, 4vw, 2.2rem);
  font-weight: 400;
  color: #5a6a7a;
  white-space: nowrap;
  opacity: 0;
  overflow: hidden;
  border-right: 2px solid transparent;
  pointer-events: none;
  /* Writing animation */
  animation: handwriting 4s cubic-bezier(0.25, 0.46, 0.45, 0.94) infinite;
  /* Multiple path movement */
  animation-timing-function: cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.doodle::before {
  content: attr(data-text);
  position: absolute;
  width: 0;
  overflow: hidden;
  border-right: 2px solid #6b8a9c;
  animation: writeText 4s cubic-bezier(0.25, 0.46, 0.45, 0.94) infinite;
}

@keyframes handwriting {
  0% {
    opacity: 0;
    transform: translateY(15px) translateX(10px) rotate(-2deg) scale(0.9);
  }
  12% {
    opacity: 1;
    transform: translateY(-2px) translateX(0) rotate(0deg) scale(1.02);
  }
  45%, 55% {
    transform: translateY(-1px) rotate(1deg) scale(1);
  }
  88% {
    opacity: 1;
    transform: translateY(0) rotate(0deg) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-8px) translateX(-5px) rotate(1deg) scale(0.95);
  }
}

@keyframes writeText {
  0% { width: 0; }
  70% { width: 100%; }
  100% { width: 100%; }
}

/* Individual doodle positions - staggered to avoid overlap */
.doodle-1 {
  top: 12%;
  left: 5%;
  --text-delay: 0s;
  font-size: clamp(1.3rem, 3.5vw, 1.9rem);
  transform: rotate(-8deg);
  animation-delay: 0s;
}

.doodle-2 {
  top: 28%;
  right: 6%;
  --text-delay: 1s;
  font-size: clamp(1.5rem, 3.8vw, 2rem);
  transform: rotate(5deg);
  animation-delay: 2.5s;
}

.doodle-3 {
  top: 52%;
  left: 12%;
  --text-delay: 0.8s;
  color: #4a7a5e;
  transform: rotate(-5deg);
  animation-delay: 5s;
}

.doodle-4 {
  bottom: 22%;
  right: 10%;
  --text-delay: 1.2s;
  color: #8a5a3a;
  transform: rotate(6deg);
  animation-delay: 1s;
}

.doodle-5 {
  bottom: 12%;
  left: 4%;
  --text-delay: 0.9s;
  color: #6a5a9a;
  font-size: clamp(1.6rem, 4.2vw, 2.1rem);
  transform: rotate(-7deg);
  animation-delay: 3.8s;
}

.doodle-6 {
  top: 6%;
  right: 15%;
  --text-delay: 1.1s;
  color: #9a5a6a;
  transform: rotate(9deg);
  animation-delay: 7s;
}

/* Responsive doodle adjustments */
@media (max-width: 480px) {
  .doodle-1 { left: 2%; top: 10%; }
  .doodle-2 { right: 2%; top: 26%; }
  .doodle-5 { left: 2%; bottom: 10%; }
  .doodle-6 { right: 8%; top: 4%; }
}

/* Layout containers */
.pagedemo {
  min-height: 100vh;
  width: 100vw;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: transparent;
  animation: fadeInPage 0.9s;
  position: relative;
  z-index: 1;
}

@keyframes fadeInPage {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Headings */
.balloon-heading {
  font-family: 'ChoretBubble';
  font-size: clamp(2.4rem, 12vw, 6.4rem);
  color: #3a8f7b;
  letter-spacing: 0.03em;
  text-align: center;
  margin: 0 0 0.13em 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  user-select: none;
  line-height: 1.05;
  max-width: 98vw;
  flex-shrink: 1;
  word-break: break-word;
  animation: breathe-bubble 2.9s infinite cubic-bezier(.75,0,.25,1);
  will-change: transform;
  font-weight: normal;
}

@keyframes breathe-bubble {
  0%,100% { transform: scale(1); }
  35% { transform: scale(1.09); }
  65% { transform: scale(1.04); }
}

.layout-page h1,
#layout-frames-page h1,
#layout-frames-page-4stacked h1,
#layout-frames-page-4grid h1 {
  color: #3a8f7b;
}

/* Emoji buttons */
.emoji-btn {
  background: none;
  border: none;
  font-size: 2.2rem;
  cursor: pointer;
  padding: 0 12px;
  color: #ffb347;
  transition: transform 0.1s, color 0.2s;
  margin: 0 2px;
  border-radius: 50%;
  outline: none;
  z-index: 2;
}

.emoji-btn:hover,
.emoji-btn:focus {
  color: #ff7da5;
  transform: scale(1.21);
}

/* Layout selection buttons */
.layout-selection {
  display: flex;
  gap: 18px;
  margin-bottom: 22px;
  flex-wrap: wrap;
  justify-content: center;
}

.layout-option {
  border: 3px solid #3a8f7b;
  border-radius: 16px;
  font-size: 1.35rem;
  padding: 10px 7px;
  background: #ffffff;
  color: #28303d;
  margin: 0 2px;
  transition: box-shadow 0.2s, border 0.2s, background 0.21s;
  box-shadow: 0 2px 8px rgba(58,143,123,0.18);
  display: flex;
  align-items: center;
  justify-content: center;
}

.layout-option:focus,
.layout-option:hover {
  background: #f0fff6;
  box-shadow: 0 0 0 5px rgba(152,231,196,0.32);
  outline: none;
  border-color: #66c2a3;
}

.layout-option.selected {
  box-shadow: 0 0 0 4px rgba(102,194,163,0.6);
}

/* Frame selection grid */
.frame-selection {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 14px;
  justify-content: center;
}

.frame,
.frame-4stacked,
.frame-4grid {
  cursor: pointer;
  border: 3px solid #3a8f7b;
  border-radius: 16px;
  background: #fff;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: 10px;
  margin-right: 6px;
  box-shadow: 0 2px 8px rgba(20,255,255,0.06);
  transition: box-shadow 0.18s, border 0.18s, background 0.18s, transform 0.15s;
  min-width: clamp(100px, 22vw, 180px);
  min-height: clamp(80px, 18vw, 168px);
}

.frame.selected,
.frame-4stacked.selected,
.frame-4grid.selected {
  transform: scale(1.07);
  border: 3.5px solid #66c2a3;
  box-shadow: 0 4px 16px rgba(58,143,123,0.4);
}

.frame img,
.frame-4stacked img,
.frame-4grid img {
  width: clamp(110px, 21vw, 180px);
  height: auto;
  display: block;
  border-radius: 13px;
}

/* 4-grid adjustments */
#layout-frames-page-4grid,
#layout-frames-page-4grid .frame-selection {
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  background: transparent !important;
}

#layout-frames-page-4grid .frame-4grid img {
  width: clamp(210px, 42vw, 320px);
  height: auto;
  border-radius: 14px;
  box-shadow: 0 2px 14px rgba(140,252,227,0.53), 0 0 0 rgba(0,0,0,0.18);
}

#layout-frames-page-4grid .frame-4grid {
  min-width: 210px;
  min-height: 128px;
  max-width: 320px;
  max-height: 240px;
  margin-bottom: 9px;
  margin-top: 0;
  background: #fff;
}

#layout-frames-page-4grid .frame-selection {
  gap: 24px !important;
}

/* Single row back buttons */
.controls-single {
  display: flex;
  justify-content: center;
  margin-top: 10px;
}

/* Camera preview container */
.video-container {
  position: relative;
  display: block;
  width: 95vw;
  max-width: 425px;
  aspect-ratio: 16 / 9;
  margin: 0 auto 10px;
  overflow: hidden;
  border-radius: 13px;
  background: #ffffff;
  box-shadow: 0 10px 30px rgba(40, 48, 61, 0.18);
}

video,
#video-4stacked,
#video-4grid {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scaleX(-1);
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Camera guide box */
#camera-guide .center-box,
#camera-guide-4stacked .center-box,
#camera-guide-4grid .center-box {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 76%;
  aspect-ratio: 16/9;
  border: 2.5px dashed rgba(255,255,255,0.75);
  border-radius: 13px;
  box-sizing: border-box;
  box-shadow: 0 0 14px 2px #7adfd8, 0 0 32px 4px #b3ffec2a;
  animation: guideGlow 1.2s infinite alternate;
  pointer-events: none;
}

@keyframes guideGlow {
  0% {
    box-shadow:0 0 7px 2px #7adfd8, 0 0 32px 0px #b3ffec00;
  }
  100% {
    box-shadow:0 0 14px 2px #7adfd8, 0 0 32px 4px #b3ffec2a;
  }
}

/* Countdown overlay */
#countdown-overlay,
#countdown-overlay-4stacked,
#countdown-overlay-4grid {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 62px;
  color: #ffe243;
  font-weight: bold;
  pointer-events: none;
  text-shadow: 2px 2px 8px rgba(0,0,0,0.7);
  display: none;
  z-index: 9;
}

/* Flash overlay over video */
.flash-overlay {
  position: absolute;
  inset: 0;
  background: white;
  opacity: 0;
  pointer-events: none;
  z-index: 8;
  transition: opacity 0.2s ease-out;
}

.flash-overlay.active {
  opacity: 0.9;
}

/* Instructions text */
.instructions {
  font-size: 1.1em;
  text-align: center;
  color: #40526b;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 12px;
  border: 1px dashed #c4d7ff;
  margin-bottom: 10px;
  width: 100%;
  max-width: 420px;
  margin-left: auto;
  margin-right: auto;
  padding: 5px 13px;
  display: block;
}

/* Photostrip images */
.strip img,
.strip-4stacked img,
.strip-4grid img {
  width: 34vw;
  max-width: 195px;
  min-width: 82px;
  height: auto;
  display: block;
  margin: 10px auto;
  border-radius: 14px;
  background: #fffdf7;
  box-shadow:
    0 12px 22px rgba(40, 48, 61, 0.25),
    0 0 0 1px rgba(212, 214, 222, 0.7);
}

@media (max-width: 500px) {
  .strip img,
  .strip-4stacked img {
    width: 70vw;
    max-width: 165px;
    min-width: 70px;
    margin: 5px auto;
  }
}

/* 4-grid photostrip larger */
.strip-4grid img {
  width: 76vw;
  max-width: 680px;
  min-width: 220px;
  height: auto;
  display: block;
  margin: 18px auto;
  border-radius: 13px;
}

@media (max-width: 700px) {
  .strip-4grid img {
    width: 99vw;
    max-width: 400px;
    min-width: 100px;
    margin: 7px auto;
  }
}

/* Controls */
.controls {
  display: flex;
  gap: 13px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 16px 0;
}

/* Progress bars */
#progress-bar,
#progress-bar-4,
#progress-bar-4grid {
  height: 19px;
  width: 81%;
  background: #232d3c;
  border-radius: 11px;
  overflow: hidden;
  margin-bottom: 13px;
  display: block;
  box-shadow: 0 0 5px #39345f;
}

#progress-fill,
#progress-fill-4,
#progress-fill-4grid {
  background: linear-gradient(90deg, #64ffe4, #41b8f9);
  width: 0;
  height: 100%;
  transition: width 0.4s;
  border-radius: 13px;
}

/* QR box */
#qr-box,
#qr-box-4,
#qr-box-4grid {
  margin: 16px 0;
  display: flex;
  justify-content: center;
}

/* Basic button size in controls */
.controls button,
.controls-single button {
  font-size: 1.9rem;
}

/* Small responsiveness tweaks */
@media (max-width: 420px) {
  .layout-option {
    font-size: 1.15rem;
  }
}
