/* =========================================================
   Magic Mirror Words — Toddler-Friendly Magical Styles
   ========================================================= */

:root {
  --font-display: 'Fredoka', 'Comic Sans MS', 'Chalkboard SE', ui-rounded, sans-serif;
  --font-body: 'Nunito', system-ui, -apple-system, sans-serif;

  /* Default (Mix) Theme Tokens */
  --accent-1: #ff5fa2;
  --accent-2: #60c5ff;
  --accent-3: #ffd447;
  --ring-color: #ff5fa2;
  --frame-glow: rgba(255, 110, 199, 0.45);
  --bg-grad: radial-gradient(circle at 20% 20%, #ffd6f0 0%, #c8e7ff 50%, #f3d5ff 100%);
  --card-bg: rgba(255, 255, 255, 0.92);
  --card-border: #ffffff;
  --text-dark: #2c2147;
}

/* Kitty House (Dollhouse inspired) */
#app[data-theme="dollhouse"] {
  --accent-1: #ff4fa3;
  --accent-2: #2ad4c5;
  --accent-3: #ffcf40;
  --ring-color: #ff4fa3;
  --frame-glow: rgba(255, 79, 163, 0.5);
  --bg-grad: radial-gradient(circle at 25% 20%, #ffd3ec 0%, #c8f7f2 52%, #ead7ff 100%);
}

/* Ice Magic (Frozen inspired) */
#app[data-theme="frozen"] {
  --accent-1: #34b3ff;
  --accent-2: #a580ff;
  --accent-3: #9ef0ff;
  --ring-color: #34d2ff;
  --frame-glow: rgba(70, 200, 255, 0.55);
  --bg-grad: radial-gradient(circle at 50% 15%, #dff8ff 0%, #8cd4ff 50%, #6b7be6 100%);
}

/* Toy Room (Toy Story inspired) */
#app[data-theme="toystory"] {
  --accent-1: #ff5544;
  --accent-2: #2f9bff;
  --accent-3: #ffd426;
  --ring-color: #ffcb1f;
  --frame-glow: rgba(47, 155, 255, 0.5);
  --bg-grad: linear-gradient(180deg, #5ec4ff 0%, #a5e0ff 65%, #fff0a8 100%);
}

/* Sparkle Salon (Makeup & Dress-up inspired) */
#app[data-theme="makeup"] {
  --accent-1: #ff4593;
  --accent-2: #c966ff;
  --accent-3: #ffbf47;
  --ring-color: #ff4593;
  --frame-glow: rgba(255, 102, 196, 0.55);
  --bg-grad: radial-gradient(circle at 30% 15%, #ffe0f0 0%, #ffc2e2 48%, #e4b8ff 100%);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-display);
  color: var(--text-dark);
  background: #1b1530;
}

#app, #stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-grad);
  transition: background 0.6s ease;
}

#video {
  display: none;
}

#camera-canvas,
#fx-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#camera-canvas {
  z-index: 1;
}

#fx-canvas {
  z-index: 15;
  pointer-events: none;
}

#theme-frame {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  box-shadow: inset 0 0 55px 12px var(--frame-glow);
  border: 6px solid rgba(255, 255, 255, 0.45);
  transition: box-shadow 0.5s ease;
}

.hidden {
  display: none !important;
}

/* ================= HUD ================= */

#hud {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

#top-bar {
  position: absolute;
  top: 14px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 30;
  pointer-events: auto;
}

.top-left,
.top-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-pill {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 6px 16px rgba(32, 16, 64, 0.2);
  font-size: 24px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.18s ease, background 0.2s ease;
}

.icon-pill:hover {
  transform: scale(1.08);
  background: #ffffff;
}

.icon-pill:active {
  transform: scale(0.94);
}

.theme-pill {
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  border: 3px solid #fff;
  box-shadow: 0 6px 16px rgba(32, 16, 64, 0.18);
  font-size: 18px;
  font-weight: 700;
  color: var(--text-dark);
}

/* Star Jar */
#star-jar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  border: 3px solid #fff;
  box-shadow: 0 8px 20px rgba(32, 16, 64, 0.22);
}

.star-slots {
  display: flex;
  gap: 6px;
}

.star-slot {
  font-size: 26px;
  filter: grayscale(1) opacity(0.32);
  transform: scale(0.9);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.3s ease;
}

.star-slot.filled {
  filter: drop-shadow(0 2px 6px rgba(255, 188, 0, 0.7));
  transform: scale(1.18);
  animation: starPop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes starPop {
  0% { transform: scale(0.4) rotate(-25deg); }
  65% { transform: scale(1.4) rotate(10deg); }
  100% { transform: scale(1.18) rotate(0deg); }
}

.star-count {
  font-size: 18px;
  font-weight: 700;
  background: var(--accent-3);
  color: #5b3b00;
  padding: 2px 10px;
  border-radius: 999px;
  min-width: 32px;
  text-align: center;
}

/* ================= PROMPT PICTURE CARD ================= */

#prompt-card {
  position: absolute;
  left: 50%;
  top: 78px;
  transform: translateX(-50%);
  width: clamp(190px, 24vw, 280px);
  padding: 14px 18px 12px;
  border-radius: 34px;
  background: var(--card-bg);
  border: 6px solid #fff;
  box-shadow: 0 14px 36px rgba(25, 14, 58, 0.28), 0 0 0 5px var(--accent-1);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  z-index: 12;
  pointer-events: auto;
  cursor: pointer;
  transition: top 0.4s ease, bottom 0.4s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* In 3-choice mode, move picture card to bottom-center so top-center is free for reaching high! */
#app[data-choices="3"] #prompt-card {
  top: auto;
  bottom: 24px;
  width: clamp(165px, 20vw, 235px);
  padding: 10px 14px;
}

#prompt-card.bounce {
  animation: promptCelebrate 0.75s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes promptCelebrate {
  0% { transform: translateX(-50%) scale(1); }
  35% { transform: translateX(-50%) scale(1.18) rotate(-4deg); }
  65% { transform: translateX(-50%) scale(1.15) rotate(4deg); }
  100% { transform: translateX(-50%) scale(1); }
}

#prompt-art {
  width: clamp(120px, 15vw, 185px);
  height: clamp(120px, 15vw, 185px);
  display: grid;
  place-items: center;
  animation: gentleFloat 3.2s ease-in-out infinite;
}

#app[data-choices="3"] #prompt-art {
  width: clamp(100px, 12vw, 148px);
  height: clamp(100px, 12vw, 148px);
}

#prompt-art svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.14));
}

@keyframes gentleFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

#prompt-label {
  font-size: clamp(17px, 2vw, 22px);
  font-weight: 700;
  color: var(--accent-1);
  letter-spacing: 0.04em;
  text-align: center;
  min-height: 26px;
}

.prompt-sparkle {
  position: absolute;
  color: var(--accent-3);
  font-size: 26px;
  text-shadow: 0 2px 6px rgba(255, 165, 0, 0.5);
  animation: twinkle 1.8s ease-in-out infinite;
}

.prompt-sparkle.s1 { top: -12px; left: 16px; }
.prompt-sparkle.s2 { bottom: -10px; right: 18px; animation-delay: 0.9s; }

@keyframes twinkle {
  0%, 100% { opacity: 0.6; transform: scale(0.85) rotate(0deg); }
  50% { opacity: 1; transform: scale(1.25) rotate(20deg); }
}

/* ================= WORD TARGET BUBBLES ================= */

#targets-layer {
  position: absolute;
  inset: 0;
  z-index: 12;
  pointer-events: none;
}

.word-target {
  position: absolute;
  pointer-events: auto;
  cursor: pointer;
  border: none;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.35s ease;
}

/* 2-Choice Mode: Huge Left & Right Bubbles at Toddler Reach Height */
.word-target.slot-2-0 {
  left: 3.5%;
  top: 56%;
  transform: translateY(-50%);
  width: clamp(200px, 27vw, 330px);
  height: clamp(200px, 27vw, 330px);
}

.word-target.slot-2-1 {
  right: 3.5%;
  top: 56%;
  transform: translateY(-50%);
  width: clamp(200px, 27vw, 330px);
  height: clamp(200px, 27vw, 330px);
}

/* 3-Choice Mode: Left, Top-Center (Reach Up!), Right */
.word-target.slot-3-0 {
  left: 3%;
  top: 54%;
  transform: translateY(-50%);
  width: clamp(175px, 22vw, 270px);
  height: clamp(175px, 22vw, 270px);
}

.word-target.slot-3-1 {
  left: 50%;
  top: 78px;
  transform: translateX(-50%);
  width: clamp(175px, 22vw, 260px);
  height: clamp(175px, 22vw, 260px);
}

.word-target.slot-3-2 {
  right: 3%;
  top: 54%;
  transform: translateY(-50%);
  width: clamp(175px, 22vw, 270px);
  height: clamp(175px, 22vw, 270px);
}

.target-inner {
  position: relative;
  width: 88%;
  height: 88%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 7px solid #ffffff;
  box-shadow: 0 14px 34px rgba(28, 12, 60, 0.28), inset 0 -10px 22px rgba(255, 180, 230, 0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: transform 0.15s ease, background 0.25s ease, box-shadow 0.25s ease;
}

.word-target:hover .target-inner {
  transform: scale(1.05);
}

.word-target.charging .target-inner {
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 0 36px 8px var(--ring-color), 0 14px 34px rgba(28, 12, 60, 0.3);
}

.word-target.correct .target-inner {
  background: linear-gradient(135deg, #fff6b8 0%, #b9ffcf 100%);
  border-color: #ffe347;
  box-shadow: 0 0 48px 14px rgba(255, 224, 71, 0.9);
  transform: scale(1.14);
}

.word-target.wrong-nudge {
  animation: gentleWiggle 0.55s ease;
}

.word-target.wrong-dimmed {
  opacity: 0.52;
}

@keyframes gentleWiggle {
  0%, 100% { margin-left: 0; }
  20% { margin-left: -12px; }
  45% { margin-left: 12px; }
  70% { margin-left: -8px; }
  85% { margin-left: 6px; }
}

.target-word {
  font-family: var(--font-display);
  font-size: clamp(40px, 5.6vw, 76px);
  font-weight: 700;
  color: var(--text-dark);
  letter-spacing: 0.06em;
  line-height: 1;
  text-shadow: 0 3px 0 rgba(255, 255, 255, 0.9);
}

.word-target.slot-3-0 .target-word,
.word-target.slot-3-1 .target-word,
.word-target.slot-3-2 .target-word {
  font-size: clamp(34px, 4.6vw, 62px);
}

.target-hint-icon {
  font-size: 20px;
  opacity: 0.65;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.word-target.charging .target-hint-icon {
  opacity: 1;
  transform: scale(1.25);
}

/* Circular SVG Charge Ring */
.charge-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
  pointer-events: none;
}

.charge-ring-bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.45);
  stroke-width: 10;
}

.charge-ring-progress {
  fill: none;
  stroke: var(--ring-color);
  stroke-width: 12;
  stroke-linecap: round;
  transition: stroke 0.2s ease;
  filter: drop-shadow(0 0 6px var(--ring-color));
}

.word-target.slot-color-0 .charge-ring-progress { stroke: var(--accent-1); }
.word-target.slot-color-1 .charge-ring-progress { stroke: var(--accent-2); }
.word-target.slot-color-2 .charge-ring-progress { stroke: var(--accent-3); }

/* ================= CELEBRATION BANNER & DANCE TIMER ================= */

#celebration-banner {
  position: absolute;
  left: 50%;
  top: 52%;
  transform: translate(-50%, -50%);
  z-index: 25;
  background: rgba(255, 255, 255, 0.95);
  border: 6px solid var(--accent-3);
  border-radius: 36px;
  padding: 20px 40px;
  text-align: center;
  box-shadow: 0 20px 55px rgba(32, 10, 72, 0.35);
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}

#celebration-text {
  font-size: clamp(34px, 5vw, 60px);
  font-weight: 700;
  color: var(--accent-1);
  line-height: 1.1;
}

#celebration-sub {
  font-size: clamp(20px, 2.5vw, 30px);
  font-weight: 700;
  color: var(--text-dark);
  margin-top: 6px;
}

@keyframes popIn {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

#dance-timer-wrap {
  position: absolute;
  top: 84px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 24;
  background: rgba(255, 255, 255, 0.92);
  border: 4px solid #fff;
  border-radius: 28px;
  padding: 12px 26px;
  box-shadow: 0 12px 30px rgba(25, 10, 60, 0.25);
  text-align: center;
  min-width: min(88vw, 460px);
}

.dance-label {
  font-size: clamp(18px, 2.3vw, 24px);
  font-weight: 700;
  color: var(--accent-1);
  margin-bottom: 8px;
}

.dance-bar-track {
  width: 100%;
  height: 16px;
  border-radius: 999px;
  background: rgba(44, 33, 71, 0.14);
  overflow: hidden;
}

#dance-bar-fill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-1), var(--accent-3), var(--accent-2));
  transition: width 0.1s linear;
}

#mode-hint {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  font-size: 16px;
  font-weight: 700;
  color: var(--text-dark);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.14);
  z-index: 11;
}

#app[data-choices="3"] #mode-hint {
  display: none;
}

/* ================= START SCREEN ================= */

#start-screen {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg-grad);
  overflow-y: auto;
}

.start-card {
  width: min(94vw, 720px);
  background: rgba(255, 255, 255, 0.93);
  border: 6px solid #ffffff;
  border-radius: 40px;
  padding: 32px 30px 26px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(45, 20, 88, 0.22);
}

.logo-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 10px;
}

.logo-badge {
  font-size: clamp(28px, 4vw, 40px);
  animation: twinkle 2s ease-in-out infinite;
}

.start-card h1 {
  font-size: clamp(30px, 5vw, 48px);
  font-weight: 700;
  background: linear-gradient(90deg, #ff4593, #965cff, #24a8ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.start-subtitle {
  font-family: var(--font-body);
  font-size: clamp(16px, 2vw, 19px);
  color: #4b3d6b;
  margin-bottom: 22px;
  line-height: 1.45;
}

.world-picker-label {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 12px;
}

.world-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}

.world-card {
  border: 4px solid transparent;
  background: #f6f2ff;
  border-radius: 22px;
  padding: 12px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.world-card:hover {
  transform: translateY(-3px);
  background: #ffffff;
}

.world-card.active {
  border-color: var(--accent-1);
  background: #fff0f8;
  box-shadow: 0 8px 18px rgba(255, 79, 163, 0.25);
  transform: translateY(-3px) scale(1.03);
}

.world-emoji {
  font-size: 32px;
}

.world-name {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  color: var(--text-dark);
}

.start-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  margin-bottom: 16px;
}

.primary-btn {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  padding: 16px 32px;
  border-radius: 999px;
  border: 4px solid #fff;
  color: #fff;
  background: linear-gradient(135deg, #ff4fa3 0%, #ff7d54 100%);
  box-shadow: 0 10px 24px rgba(255, 79, 163, 0.38);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.primary-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 14px 28px rgba(255, 79, 163, 0.45);
}

.primary-btn:active {
  transform: scale(0.96);
}

.secondary-btn {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  padding: 15px 24px;
  border-radius: 999px;
  border: 3px solid #d9cff2;
  color: var(--text-dark);
  background: #ffffff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.18s ease, border-color 0.2s ease;
}

.secondary-btn:hover {
  transform: scale(1.03);
  border-color: var(--accent-2);
}

.error-box {
  background: #fff1f1;
  border: 2px solid #ff9aa2;
  color: #9e2236;
  border-radius: 16px;
  padding: 12px 16px;
  font-family: var(--font-body);
  font-size: 14px;
  margin-bottom: 14px;
  line-height: 1.4;
}

.privacy-note {
  font-family: var(--font-body);
  font-size: 13px;
  color: #6b5d8a;
}

/* ================= PARENT SETTINGS DRAWER ================= */

#settings-drawer {
  position: absolute;
  inset: 0;
  z-index: 60;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 12, 42, 0.45);
  backdrop-filter: blur(3px);
}

.drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(92vw, 390px);
  height: 100%;
  background: #ffffff;
  box-shadow: -12px 0 40px rgba(20, 10, 48, 0.28);
  display: flex;
  flex-direction: column;
  font-family: var(--font-body);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 2px solid #f0ebf8;
}

.drawer-header h2 {
  font-family: var(--font-display);
  font-size: 22px;
  color: var(--text-dark);
}

.close-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: #f2edf9;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  color: var(--text-dark);
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.setting-group label,
.setting-row label {
  font-weight: 800;
  font-size: 15px;
  color: var(--text-dark);
}

.setting-group select {
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 700;
  padding: 10px 12px;
  border-radius: 12px;
  border: 2px solid #dfd6f2;
  background: #faf8ff;
  color: var(--text-dark);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.segmented button {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 800;
  padding: 10px 8px;
  border-radius: 12px;
  border: 2px solid #e2daf4;
  background: #f7f4fc;
  color: #554875;
  cursor: pointer;
  transition: all 0.15s ease;
}

.segmented button.active {
  border-color: var(--accent-1);
  background: #fff0f7;
  color: var(--accent-1);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.setting-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--accent-1);
  cursor: pointer;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 800;
  font-size: 14px;
}

.slider-header span {
  color: var(--accent-1);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent-1);
  cursor: pointer;
}

.setting-hint {
  font-size: 12.5px;
  color: #746794;
  line-height: 1.35;
}

.drawer-body hr {
  border: none;
  border-top: 2px solid #f2edf9;
  margin: 2px 0;
}

.drawer-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.fun-btn {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  padding: 13px 16px;
  border-radius: 14px;
  border: none;
  color: #fff;
  background: linear-gradient(135deg, #ff4fa3, #8f5cff);
  cursor: pointer;
}

.outline-btn {
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 800;
  padding: 12px 16px;
  border-radius: 14px;
  border: 2px solid #d9cff2;
  background: #ffffff;
  color: var(--text-dark);
  cursor: pointer;
}

/* Responsive adjustments for smaller screens */
@media (max-width: 720px) {
  .world-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .theme-pill {
    display: none;
  }
  .star-slot {
    font-size: 20px;
  }
}
