/* ============================================
   Phonics Playground — styles.css
   Joyful, toy-like design system for kids
   ============================================ */

/* --- Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;500;600;700&family=Nunito:wght@500;600;700;800&display=swap');

/* --- Design Tokens --- */
:root {
  /* Canvas */
  --bg-canvas: #F0E6D8;
  --bg-card: #FFFFFF;
  --bg-card-inner: #FFF5EE;

  /* Accent Palette */
  --pink: #FF6B9D;
  --pink-light: #FFE0EB;
  --yellow: #FFD93D;
  --yellow-light: #FFF5CC;
  --green: #6BCB77;
  --green-light: #E0F5E4;
  --purple: #9B5DE5;
  --purple-light: #EDE0FA;
  --coral: #FF8A5C;
  --coral-light: #FFE4D6;
  --blue: #45B7D1;
  --blue-light: #DDF2F7;

  /* Chunk Colors */
  --chunk-1: #FF6B9D;
  --chunk-2: #FFD93D;
  --chunk-3: #6BCB77;
  --chunk-4: #9B5DE5;
  --chunk-5: #FF8A5C;
  --chunk-6: #45B7D1;

  /* Text */
  --text-dark: #2D2D3F;
  --text-mid: #6B6B80;
  --text-light: #A0A0B4;

  /* Radius */
  --r-card: 28px;
  --r-inner: 18px;
  --r-pill: 100px;

  /* Shadows */
  --shadow-card: 0 4px 24px rgba(255, 107, 157, 0.10), 0 1px 4px rgba(0, 0, 0, 0.04);
  --shadow-card-hover: 0 8px 32px rgba(255, 107, 157, 0.16), 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-btn: 0 4px 16px rgba(255, 107, 157, 0.25);
  --shadow-btn-hover: 0 6px 20px rgba(255, 107, 157, 0.35);

  /* Easing */
  --bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --smooth: cubic-bezier(0.25, 1, 0.5, 1);

  /* Fonts */
  --font-display: 'Fredoka', sans-serif;
  --font-body: 'Nunito', sans-serif;
}

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

/* --- Background --- */
body {
  font-family: var(--font-body);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(16px, 4vw, 40px);
  padding-top: max(clamp(16px, 4vw, 40px), env(safe-area-inset-top));
  padding-bottom: max(clamp(16px, 4vw, 40px), env(safe-area-inset-bottom));
  padding-left: max(clamp(16px, 4vw, 40px), env(safe-area-inset-left));
  padding-right: max(clamp(16px, 4vw, 40px), env(safe-area-inset-right));
  background-color: var(--bg-canvas);
  background-image:
    /* Soft colored blobs */
    radial-gradient(ellipse at 15% 30%, rgba(255, 107, 157, 0.15) 0%, transparent 50%),
    radial-gradient(ellipse at 85% 20%, rgba(155, 93, 229, 0.12) 0%, transparent 45%),
    radial-gradient(ellipse at 50% 90%, rgba(107, 203, 119, 0.12) 0%, transparent 50%),
    radial-gradient(ellipse at 75% 70%, rgba(255, 217, 61, 0.10) 0%, transparent 40%),
    /* Playful dot pattern */
    radial-gradient(circle, rgba(0, 0, 0, 0.04) 1px, transparent 1px),
    /* Larger accent dots */
    radial-gradient(circle, rgba(255, 107, 157, 0.06) 1.5px, transparent 1.5px);
  background-size:
    100% 100%,
    100% 100%,
    100% 100%,
    100% 100%,
    24px 24px,
    48px 48px;
  background-position:
    0 0,
    0 0,
    0 0,
    0 0,
    0 0,
    12px 12px;
  background-attachment: fixed;
  color: var(--text-dark);
  -webkit-font-smoothing: antialiased;
  position: relative;
  overflow-x: hidden;
}

/* --- Scene --- */
.scene {
  width: 100%;
  max-width: 720px;
  position: relative;
  z-index: 1;
  animation: scene-enter 700ms var(--bounce) both;
}

@keyframes scene-enter {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.95);
  }
}

/* --- Card (ticket aesthetic) --- */
.card {
  background: var(--bg-card);
  border-radius: 32px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
  position: relative;
  border: 2px solid rgba(0, 0, 0, 0.04);
}

/* Subtle dot pattern on card */
.card::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle, rgba(0, 0, 0, 0.025) 1px, transparent 1px);
  background-size: 20px 20px;
  pointer-events: none;
  border-radius: var(--r-card);
}

/* --- Card Header --- */
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 36px 0;
  position: relative;
  z-index: 1;
}

.header-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-dark);
  display: flex;
  align-items: center;
  gap: 10px;
}



/* --- Card Body --- */
.card-body {
  padding: 16px 36px 12px;
  min-height: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
}

/* --- Meta --- */
.meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 20px;
}

.category-badge {
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 6px 14px;
  border-radius: var(--r-pill);
  line-height: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: transform 200ms var(--bounce);
}

.category-badge:hover {
  transform: scale(1.05);
}

/* Category-specific colors */
.category-badge[data-cat="animals"] { background: var(--yellow-light); color: #B8860B; }
.category-badge[data-cat="nature"] { background: var(--green-light); color: #2E7D32; }
.category-badge[data-cat="space"] { background: var(--purple-light); color: #6A1B9A; }
.category-badge[data-cat="food"] { background: var(--coral-light); color: #BF360C; }
.category-badge[data-cat="body"] { background: var(--blue-light); color: #00695C; }
.category-badge[data-cat="adventure"] { background: var(--pink-light); color: #AD1457; }
.category-badge[data-cat="science"] { background: var(--blue-light); color: #01579B; }
.category-badge[data-cat="people"] { background: var(--coral-light); color: #4E342E; }
.category-badge[data-cat="home"] { background: var(--yellow-light); color: #795548; }
.category-badge[data-cat="feelings"] { background: var(--pink-light); color: #880E4F; }
.category-badge[data-cat="school"] { background: var(--purple-light); color: #4527A0; }
.category-badge[data-cat="transport"] { background: var(--blue-light); color: #0277BD; }
.category-badge[data-cat="music"] { background: var(--coral-light); color: #BF360C; }
.category-badge[data-cat="shapes"] { background: var(--green-light); color: #1B5E20; }
.category-badge[data-cat="everyday"] { background: var(--yellow-light); color: #6D4C00; }

.category-icon {
  font-size: 0.9rem;
  line-height: 1;
}

.header-icon {
  font-size: 1.1rem;
  color: var(--pink);
}

.level-badge {
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 6px 12px;
  border-radius: var(--r-pill);
  line-height: 1;
  background: var(--bg-card-inner);
  color: var(--text-mid);
}

.level-badge[data-level="1"] { background: var(--green-light); color: #2E7D32; }
.level-badge[data-level="2"] { background: var(--yellow-light); color: #B8860B; }
.level-badge[data-level="3"] { background: var(--coral-light); color: #BF360C; }

/* --- No Speech Notice --- */
.notice {
  background: var(--yellow-light);
  color: #B8860B;
  padding: 10px 18px;
  border-radius: var(--r-inner);
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 16px;
  font-family: var(--font-body);
}

/* --- Word Display --- */
.word-display {
  text-align: center;
  width: 100%;
}

.chunks {
  display: flex;
  justify-content: center;
  gap: clamp(6px, 1.5vw, 14px);
  flex-wrap: nowrap;
  min-height: 90px;
  align-items: center;
  margin-bottom: 8px;
}

.chunk {
  white-space: nowrap;
}

.chunk {
  font-family: var(--font-display);
  font-size: clamp(28px, 8vw, 64px);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.01em;
  animation: chunk-bounce 500ms var(--bounce) calc(var(--i, 0) * 80ms) both;
  cursor: default;
  transition: transform 200ms var(--bounce), filter 200ms ease;
}

.chunk:hover {
  transform: scale(1.08) rotate(-2deg);
}

.chunk.color-1 { color: var(--chunk-1); }
.chunk.color-2 { color: var(--chunk-2); text-shadow: 0 0 0 transparent; -webkit-text-stroke: 0.5px rgba(0,0,0,0.05); }
.chunk.color-3 { color: var(--chunk-3); }
.chunk.color-4 { color: var(--chunk-4); }
.chunk.color-5 { color: var(--chunk-5); }
.chunk.color-6 { color: var(--chunk-6); }

.chunk.highlight {
  transform: scale(1.18) rotate(-3deg);
  filter: brightness(1.15) drop-shadow(0 4px 8px rgba(0, 0, 0, 0.1));
  transition: transform 180ms var(--bounce), filter 180ms ease;
}

@keyframes chunk-bounce {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.6);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.full-word {
  font-family: var(--font-body);
  font-size: clamp(16px, 3.5vw, 22px);
  color: var(--text-mid);
  font-weight: 600;
  margin-bottom: 8px;
  min-height: 1.5em;
  letter-spacing: 0.02em;
}

/* --- Card Tear (ticket perforation) --- */
.card-tear {
  border: none;
  position: relative;
  z-index: 1;
  margin: 16px 0;
  height: 2px;
  background: repeating-linear-gradient(
    90deg,
    rgba(0, 0, 0, 0.08) 0px,
    rgba(0, 0, 0, 0.08) 8px,
    transparent 8px,
    transparent 16px
  );
}

/* Ticket notches on the sides */
.card-tear::before,
.card-tear::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 20px;
  height: 20px;
  background: var(--bg-canvas);
  border-radius: 50%;
  transform: translateY(-50%);
}

.card-tear::before {
  left: -12px;
}

.card-tear::after {
  right: -12px;
}

/* --- Discovery Fold --- */
.discovery-fold {
  padding: 8px 36px 12px;
  position: relative;
  z-index: 1;
}

.discovery-layout {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  background: var(--bg-card-inner);
  border-radius: 20px;
  padding: 24px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 500ms var(--smooth), transform 500ms var(--smooth);
}

.discovery-layout.visible {
  opacity: 1;
  transform: translateY(0);
}

.word-image {
  width: 160px;
  height: 160px;
  border-radius: 18px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.7);
  flex-shrink: 0;
  display: none;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.08);
}

.word-image.has-image {
  display: block;
}

.word-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.discovery-text {
  flex: 1;
  text-align: left;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 120px;
}

.meaning {
  font-size: clamp(15px, 2.5vw, 18px);
  color: var(--text-mid);
  font-style: italic;
  line-height: 1.6;
  margin: 0 0 12px;
  font-family: var(--font-body);
}

.sentence {
  font-size: clamp(16px, 2.8vw, 20px);
  color: var(--text-dark);
  line-height: 1.7;
  margin: 0;
  font-family: var(--font-body);
  font-weight: 700;
}

.sentence mark {
  background: transparent;
  color: var(--purple);
  font-weight: 800;
  padding: 0;
  text-decoration: underline;
  text-decoration-color: rgba(155, 93, 229, 0.3);
  text-underline-offset: 3px;
  text-decoration-thickness: 2.5px;
}

/* --- Card Footer --- */
.card-footer {
  display: flex;
  gap: 16px;
  padding: 20px 36px 32px;
  justify-content: center;
  position: relative;
  z-index: 1;
}

/* --- Buttons --- */
.btn {
  font-family: var(--font-body);
  font-size: clamp(15px, 2.8vw, 18px);
  font-weight: 700;
  padding: 16px 36px;
  border: none;
  border-radius: var(--r-pill);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  transition:
    transform 150ms var(--bounce),
    box-shadow 200ms ease,
    background 200ms ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  position: relative;
  overflow: hidden;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.2) 0%, transparent 50%);
  border-radius: var(--r-pill);
  pointer-events: none;
}

.btn:active {
  transform: scale(0.93);
}

.btn-icon {
  font-size: 1.15em;
  line-height: 1;
}

.btn-primary {
  background: linear-gradient(135deg, var(--pink), var(--coral));
  color: #FFFFFF;
  box-shadow: var(--shadow-btn);
}

.btn-primary:hover {
  box-shadow: var(--shadow-btn-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-card-inner);
  color: var(--text-mid);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.btn-secondary:hover {
  background: #FFEDE2;
  transform: translateY(-1px);
}

/* --- Confetti --- */
.confetti-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 100;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  border-radius: 3px;
  opacity: 0;
  animation: confetti-fall 1.6s var(--smooth) forwards;
}

@keyframes confetti-fall {
  0% {
    opacity: 1;
    transform: translateY(0) rotate(0deg) scale(1);
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(70vh) rotate(var(--rot, 720deg)) scale(0.3);
  }
}


/* --- iPad landscape: fill the space --- */
@media (min-width: 1024px) {
  .scene { max-width: 800px; }
  .card-body { min-height: 380px; padding: 20px 48px 16px; }
  .card-header { padding: 28px 48px 0; }
  .card-footer { padding: 24px 48px 36px; }
  .discovery-fold { padding: 12px 48px 16px; }
  .discovery-layout { padding: 28px; gap: 28px; }
  .word-image { width: 180px; height: 180px; }
  .meaning { font-size: 19px; }
  .sentence { font-size: 21px; }
  .chunk { font-size: clamp(36px, 8vw, 72px); }
  .btn { padding: 18px 44px; min-height: 60px; font-size: 18px; }
}

/* --- Responsive: small phones --- */
@media (max-width: 480px) {
  .card-header { padding: 16px 16px 0; }
  .card-body { padding: 8px 16px 4px; min-height: 260px; }
  .card-footer { padding: 12px 16px 20px; }
  .btn { padding: 12px 20px; min-height: 48px; }
  .discovery-fold { padding: 8px 12px 4px; }
  .discovery-layout { padding: 14px; gap: 14px; }
  .word-image { width: 100px; height: 100px; }
  .card-tear { margin: 12px 0; }
  .card-tear::before { left: -10px; width: 16px; height: 16px; }
  .card-tear::after { right: -10px; width: 16px; height: 16px; }
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .scene { animation: none; }
  .chunk { opacity: 1 !important; transform: none !important; animation: none !important; }
  .discovery-layout { opacity: 1; transform: none; }
  .level-up-toast.visible { transform: translate(-50%, -50%) scale(1); }
}
