/* =============================================
   Alphabet Flashcard Webapp — Main Stylesheet
   Single-Page Card Design (no flip)
   ============================================= */

@import url('https://fonts.googleapis.com/css2?family=Fredoka+One&family=Nunito:wght@400;600;700;800;900&display=swap');

/* ── CSS Variables ───────────────────────────────────────────────────── */
:root {
  --pink: #ff6b9d;
  --pink-light: #ffe0ed;
  --pink-dark: #d94f82;
  --teal: #06d6a0;
  --teal-light: #d0faf0;
  --teal-dark: #04a07a;
  --bg: #fdf4ff;
  --white: #ffffff;
  --text-dark: #2d2d2d;
  --text-mid: #666;
  --text-light: #aaa;
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 14px;
  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.07);
  --shadow-md: 0 8px 28px rgba(0, 0, 0, 0.11);
  --shadow-pink: 0 6px 24px rgba(255, 107, 157, 0.28);
  --shadow-teal: 0 6px 24px rgba(6, 214, 160, 0.28);
  --font: 'Nunito', sans-serif;
  --font-display: 'Fredoka One', cursive;
}

/* ── Reset ───────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-dark);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

/* =============================================
   LEVEL SCREEN
   ============================================= */
.level-page {
  min-height: 100vh;
  background: linear-gradient(160deg, #fff0fa 0%, #f0f7ff 100%);
  padding-bottom: 40px;
}

.level-header {
  text-align: center;
  padding: 36px 24px 24px;
  background: linear-gradient(135deg, #ff6b9d 0%, #fa4d94 100%);
  color: #fff;
  box-shadow: 0 6px 24px rgba(255, 107, 157, 0.35);
  position: relative;
  overflow: hidden;
}

.level-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 20% 50%, rgba(255, 255, 255, 0.12) 0%, transparent 60%),
    radial-gradient(circle at 80% 20%, rgba(255, 255, 255, 0.08) 0%, transparent 50%);
  pointer-events: none;
}

.level-header h1 {
  font-family: var(--font-display);
  font-size: clamp(2rem, 6vw, 3.2rem);
  letter-spacing: 1px;
  position: relative;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.level-header p {
  font-size: clamp(0.85rem, 3vw, 1rem);
  opacity: 0.9;
  margin-top: 8px;
  position: relative;
  font-weight: 600;
}

.letters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 14px;
  padding: 28px 20px;
  max-width: 680px;
  margin: 0 auto;
}

.letter-tile {
  aspect-ratio: 1;
  border-radius: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
  color: white;
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 5vw, 2.4rem);
  box-shadow: var(--shadow-md);
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.18s;
  position: relative;
  overflow: hidden;
  user-select: none;
}

.letter-tile span.tile-label {
  font-family: var(--font);
  font-size: clamp(0.58rem, 2vw, 0.72rem);
  font-weight: 800;
  opacity: 0.85;
  margin-top: 1px;
  letter-spacing: 0.5px;
}

.letter-tile:hover {
  transform: scale(1.10) translateY(-4px);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.18);
}

.letter-tile:active {
  transform: scale(0.97);
}

.letter-tile::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.22), transparent 60%);
  opacity: 0;
  transition: opacity 0.2s;
}

.letter-tile:hover::after {
  opacity: 1;
}

.letter-tile:nth-child(6n+1) {
  background: linear-gradient(150deg, #ff6b9d, #fa4d94);
}

.letter-tile:nth-child(6n+2) {
  background: linear-gradient(150deg, #f97316, #ea6009);
}

.letter-tile:nth-child(6n+3) {
  background: linear-gradient(150deg, #f59e0b, #d97706);
}

.letter-tile:nth-child(6n+4) {
  background: linear-gradient(150deg, #22c55e, #16a34a);
}

.letter-tile:nth-child(6n+5) {
  background: linear-gradient(150deg, #06b6d4, #0891b2);
}

.letter-tile:nth-child(6n+6) {
  background: linear-gradient(150deg, #8b5cf6, #7c3aed);
}

/* Staggered entrance */
.letter-tile {
  animation: tileIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.letter-tile:nth-child(1) {
  animation-delay: 0.02s;
}

.letter-tile:nth-child(2) {
  animation-delay: 0.04s;
}

.letter-tile:nth-child(3) {
  animation-delay: 0.06s;
}

.letter-tile:nth-child(4) {
  animation-delay: 0.08s;
}

.letter-tile:nth-child(5) {
  animation-delay: 0.10s;
}

.letter-tile:nth-child(6) {
  animation-delay: 0.12s;
}

.letter-tile:nth-child(7) {
  animation-delay: 0.14s;
}

.letter-tile:nth-child(8) {
  animation-delay: 0.16s;
}

.letter-tile:nth-child(9) {
  animation-delay: 0.18s;
}

.letter-tile:nth-child(10) {
  animation-delay: 0.20s;
}

.letter-tile:nth-child(11) {
  animation-delay: 0.22s;
}

.letter-tile:nth-child(12) {
  animation-delay: 0.24s;
}

.letter-tile:nth-child(13) {
  animation-delay: 0.26s;
}

.letter-tile:nth-child(14) {
  animation-delay: 0.28s;
}

.letter-tile:nth-child(15) {
  animation-delay: 0.30s;
}

.letter-tile:nth-child(16) {
  animation-delay: 0.32s;
}

.letter-tile:nth-child(17) {
  animation-delay: 0.34s;
}

.letter-tile:nth-child(18) {
  animation-delay: 0.36s;
}

.letter-tile:nth-child(19) {
  animation-delay: 0.38s;
}

.letter-tile:nth-child(20) {
  animation-delay: 0.40s;
}

.letter-tile:nth-child(21) {
  animation-delay: 0.42s;
}

.letter-tile:nth-child(22) {
  animation-delay: 0.44s;
}

.letter-tile:nth-child(23) {
  animation-delay: 0.46s;
}

.letter-tile:nth-child(24) {
  animation-delay: 0.48s;
}

.letter-tile:nth-child(25) {
  animation-delay: 0.50s;
}

.letter-tile:nth-child(26) {
  animation-delay: 0.52s;
}

@keyframes tileIn {
  from {
    opacity: 0;
    transform: scale(0.5) translateY(16px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.level-footer {
  text-align: center;
  padding: 16px 24px;
  font-size: 0.82rem;
  color: var(--text-light);
  font-weight: 600;
}

/* =============================================
   CARD PAGE — SINGLE PAGE LAYOUT
   ============================================= */
.card-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(160deg, #fff0fa 0%, #f0f7ff 100%);
}

/* ── Nav Bar ─────────────────────────────────────────────────────────── */
.card-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.07);
  flex-shrink: 0;
  z-index: 10;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 14px;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  font-family: var(--font);
  font-weight: 800;
  font-size: 0.85rem;
  text-decoration: none;
  transition: all 0.18s ease;
}

.nav-btn.home {
  background: var(--pink-light);
  color: var(--pink-dark);
}

.nav-btn.home:hover {
  background: #ffc8dd;
}

.nav-letter-indicator {
  font-family: var(--font-display);
  font-size: 1.6rem;
  color: var(--pink);
  letter-spacing: 2px;
  line-height: 1;
}

.nav-arrows {
  display: flex;
  gap: 8px;
}

.arrow-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid #e8e8f0;
  background: white;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.18s;
  color: var(--text-mid);
  font-weight: 700;
}

.arrow-btn:hover {
  background: #f0f4ff;
  border-color: #3b82f6;
  color: #3b82f6;
  transform: scale(1.08);
}

.arrow-btn:active {
  transform: scale(0.95);
}

.arrow-btn:disabled {
  opacity: 0.25;
  cursor: not-allowed;
  transform: none;
}

/* ── Main Content ────────────────────────────────────────────────────── */
.card-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 14px 14px 20px;
  gap: 12px;
  overflow-y: auto;
  animation: pageIn 0.4s ease both;
}

@keyframes pageIn {
  from {
    opacity: 0;
    transform: translateY(16px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Top Section: Lip + Letter ───────────────────────────────────────── */
.card-top {
  display: flex;
  gap: 12px;
  flex-shrink: 0;
}

/* Lip/mouth tap area */
.lip-area {
  flex: 1.05;
  cursor: pointer;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: white;
  border: 2.5px solid #ffd6ea;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.15s, border-color 0.15s;
  user-select: none;
  display: flex;
  flex-direction: column;
}

.lip-area:hover {
  box-shadow: var(--shadow-pink);
  border-color: var(--pink);
}

.lip-area:active {
  transform: scale(0.96);
}

/* Lip pop animation — plays on every phonics tap */
.lip-area.lip-pop img {
  animation: lipPop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes lipPop {
  0% {
    transform: scale(1);
  }

  30% {
    transform: scale(1.07);
  }

  65% {
    transform: scale(0.96);
  }

  100% {
    transform: scale(1);
  }
}

/* Letter display — clickable for letter name sound */
.letter-display {
  cursor: pointer;
}

.letter-display:hover {
  border-color: #f59e0b;
  box-shadow: 0 6px 20px rgba(245, 158, 11, 0.22);
}

.letter-display:active {
  transform: scale(0.97);
}

.letter-display.letter-playing {
  border-color: #f59e0b;
  background: linear-gradient(160deg, #fff9e5, #fef3c7);
  box-shadow: 0 6px 20px rgba(245, 158, 11, 0.28);
}

.letter-display.letter-bounce {
  animation: letterBounce 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes letterBounce {
  0% {
    transform: scale(1);
  }

  35% {
    transform: scale(1.08);
  }

  70% {
    transform: scale(0.96);
  }

  100% {
    transform: scale(1);
  }
}

.lip-area img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  display: block;
}

.lip-footer {
  padding: 6px 8px 7px;
  background: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.tap-label {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--pink);
  letter-spacing: 0.3px;
}

.say-label {
  font-size: 0.66rem;
  font-weight: 700;
  color: var(--text-light);
}

/* Sound wave */
.sound-wave {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 2.5px;
  height: 14px;
}

.sound-wave span {
  display: inline-block;
  width: 3px;
  border-radius: 4px;
  background: var(--pink);
  height: 3px;
}

.sound-wave.playing span:nth-child(1) {
  animation: wavePulse 0.55s 0.00s infinite ease-in-out alternate;
}

.sound-wave.playing span:nth-child(2) {
  animation: wavePulse 0.55s 0.10s infinite ease-in-out alternate;
}

.sound-wave.playing span:nth-child(3) {
  animation: wavePulse 0.55s 0.20s infinite ease-in-out alternate;
}

.sound-wave.playing span:nth-child(4) {
  animation: wavePulse 0.55s 0.10s infinite ease-in-out alternate;
}

.sound-wave.playing span:nth-child(5) {
  animation: wavePulse 0.55s 0.00s infinite ease-in-out alternate;
}

@keyframes wavePulse {
  from {
    height: 3px;
  }

  to {
    height: 12px;
  }
}

/* Letter display box */
.letter-display {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #fffde8, #fef9c3);
  border-radius: var(--radius-md);
  border: 2.5px solid #fde68a;
  padding: 10px 8px 8px;
  box-shadow: var(--shadow-sm);
}

.letter-lines-wrap {
  width: 100%;
  position: relative;
  padding: 8px 2px;
  border-top: 2.5px solid #93c5fd;
  border-bottom: 2.5px solid #fca5a5;
}

.letter-lines-wrap::before {
  content: '';
  position: absolute;
  left: 4px;
  right: 4px;
  top: 50%;
  border-top: 1.5px dashed #d1d5db;
}

.letter-img-placeholder {
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 9vw, 4.5rem);
  color: var(--text-dark);
  text-align: center;
  line-height: 1;
  position: relative;
  z-index: 1;
}

.letter-sublabel {
  font-size: 0.62rem;
  color: #bbb;
  margin-top: 6px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* ── Objects Header ──────────────────────────────────────────────────── */
.objects-header {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #06d6a0, #04c794);
  border-radius: 50px;
  padding: 7px 18px;
  flex-shrink: 0;
}

.objects-header span {
  color: white;
  font-weight: 800;
  font-size: clamp(0.75rem, 3vw, 0.88rem);
  letter-spacing: 0.3px;
}

/* ── Objects 2×3 Grid ────────────────────────────────────────────────── */
.objects-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  flex: 1;
}

.obj-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: white;
  border-radius: var(--radius-md);
  border: 2.5px solid #d1fae5;
  padding: 10px 6px 8px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.15s, border-color 0.15s;
  user-select: none;
  position: relative;
  overflow: hidden;
}

.obj-card:hover {
  border-color: var(--teal);
  box-shadow: var(--shadow-teal);
  transform: translateY(-2px);
}

.obj-card:active {
  transform: scale(0.96);
}

.obj-card.playing {
  border-color: var(--teal);
  background: #f0fdf9;
  box-shadow: var(--shadow-teal);
}

.obj-card img {
  width: 72%;
  aspect-ratio: 1;
  object-fit: contain;
  display: block;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.obj-card.playing img {
  transform: scale(1.1);
}

.obj-name {
  font-weight: 800;
  font-size: clamp(0.64rem, 2.4vw, 0.8rem);
  color: var(--text-dark);
  margin-top: 6px;
  text-align: center;
}

.obj-wave {
  height: 12px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;
  margin-top: 4px;
}

.obj-wave span {
  width: 3px;
  border-radius: 3px;
  background: var(--teal);
  height: 3px;
}

.obj-card.playing .obj-wave span:nth-child(1) {
  animation: wavePulse 0.5s 0.00s infinite ease-in-out alternate;
}

.obj-card.playing .obj-wave span:nth-child(2) {
  animation: wavePulse 0.5s 0.10s infinite ease-in-out alternate;
}

.obj-card.playing .obj-wave span:nth-child(3) {
  animation: wavePulse 0.5s 0.20s infinite ease-in-out alternate;
}

.obj-card.playing .obj-wave span:nth-child(4) {
  animation: wavePulse 0.5s 0.10s infinite ease-in-out alternate;
}

.obj-card.playing .obj-wave span:nth-child(5) {
  animation: wavePulse 0.5s 0.00s infinite ease-in-out alternate;
}

/* Bounce on tap */
.obj-card.bounce {
  animation: objBounce 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes objBounce {
  0% {
    transform: scale(1);
  }

  35% {
    transform: scale(1.14) rotate(-2deg);
  }

  70% {
    transform: scale(0.95) rotate(1deg);
  }

  100% {
    transform: scale(1);
  }
}

/* Ripple */
.ripple {
  position: absolute;
  border-radius: 50%;
  width: 60px;
  height: 60px;
  background: rgba(6, 214, 160, 0.25);
  transform: scale(0);
  animation: rippleAnim 0.65s ease-out;
  pointer-events: none;
}

@keyframes rippleAnim {
  to {
    transform: scale(5);
    opacity: 0;
  }
}

/* =============================================
   RESPONSIVE
   ============================================= */

/* Portrait — default */
@media (orientation: portrait) {
  .card-top {
    height: clamp(155px, 28vh, 220px);
  }

  .objects-grid {
    gap: 10px;
  }
}

/* Landscape on small phone */
@media (orientation: landscape) and (max-height: 520px) {
  .card-main {
    flex-direction: row;
    flex-wrap: wrap;
    padding: 8px 12px;
    gap: 8px;
  }

  .card-top {
    flex: 0 0 200px;
    flex-direction: column;
    height: auto;
  }

  .objects-header {
    flex: 0 0 100%;
    order: -1;
    padding: 5px 14px;
  }

  .objects-grid {
    flex: 1;
    gap: 6px;
    grid-template-columns: repeat(3, 1fr);
  }

  .obj-card img {
    width: 60%;
  }

  .obj-name {
    font-size: 0.6rem;
  }
}

/* Tablet portrait */
@media (min-width: 600px) and (orientation: portrait) {
  .card-main {
    max-width: 480px;
    margin: 0 auto;
  }

  .letters-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  }
}

/* Small phones */
@media (max-width: 360px) {
  .card-main {
    padding: 10px 10px 16px;
    gap: 9px;
  }

  .objects-grid {
    gap: 8px;
  }

  .obj-card {
    border-radius: 14px;
    padding: 8px 4px 6px;
  }

  .obj-card img {
    width: 68%;
  }

  .letters-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    padding: 16px 12px;
  }
}