:root {
  --bg-1: #fff3cf;
  --bg-2: #b6f4ff;
  --bg-3: #ffe0d6;
  --ink: #2f275b;
  --card: rgba(255, 255, 255, 0.86);
  --accent: #ff7f45;
  --accent-2: #12b2c6;
  --success: #4fbf5c;
  --danger: #e74f73;
  --shadow: 0 14px 40px rgba(64, 39, 100, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Baloo 2', cursive;
  color: var(--ink);
  background: radial-gradient(circle at 15% 20%, #fff8e4 0, transparent 28%),
    radial-gradient(circle at 85% 15%, #d8f8ff 0, transparent 30%),
    radial-gradient(circle at 40% 80%, #ffe9e0 0, transparent 35%),
    linear-gradient(140deg, var(--bg-1) 0%, var(--bg-2) 50%, var(--bg-3) 100%);
  padding: 24px;
  overflow-x: hidden;
}

h1,
h2,
p {
  margin: 0;
}

.orb {
  position: fixed;
  border-radius: 999px;
  filter: blur(2px);
  z-index: -1;
  animation: drift 8s ease-in-out infinite;
}

.orb-a {
  width: 140px;
  height: 140px;
  top: 8%;
  left: -40px;
  background: rgba(255, 143, 89, 0.25);
}

.orb-b {
  width: 110px;
  height: 110px;
  top: 40%;
  right: -20px;
  background: rgba(18, 178, 198, 0.28);
  animation-delay: 1.6s;
}

.orb-c {
  width: 160px;
  height: 160px;
  bottom: -20px;
  left: 35%;
  background: rgba(96, 82, 201, 0.16);
  animation-delay: 2.3s;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0 auto 16px;
  max-width: 1180px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.kicker {
  font-size: 0.9rem;
  color: #705fbb;
  letter-spacing: 0.06em;
}

h1 {
  font-family: 'Fredoka', sans-serif;
  font-size: clamp(1.6rem, 3.4vw, 2.3rem);
}

.layout {
  max-width: 1180px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
}

.card {
  background: var(--card);
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 18px;
  backdrop-filter: blur(6px);
}

.hero-card {
  grid-column: span 6;
  display: grid;
  gap: 16px;
}

.hero-main {
  position: relative;
  text-align: center;
  background: linear-gradient(145deg, rgba(255, 242, 179, 0.6), rgba(195, 252, 255, 0.4));
  border-radius: 20px;
  padding: 20px;
}

.learned-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  margin: 0;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  color: #1f6b38;
  background: rgba(95, 221, 133, 0.28);
  border: 1px solid rgba(42, 148, 72, 0.35);
}

.label {
  font-size: 0.95rem;
  color: #6c6185;
}

.letter-display {
  font-family: 'Fredoka', sans-serif;
  font-size: clamp(5.6rem, 20vw, 9rem);
  line-height: 1;
  color: #3e2f93;
  text-shadow: 0 8px 0 rgba(255, 255, 255, 0.65);
}

.emoji-display {
  width: min(42vw, 146px);
  aspect-ratio: 1;
  margin: 8px auto 2px;
  border-radius: 24px;
  display: grid;
  place-items: center;
  font-size: clamp(3.6rem, 9vw, 5.4rem);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(218, 246, 255, 0.86));
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.9), 0 12px 20px rgba(70, 112, 175, 0.16);
}

.word-display {
  font-size: clamp(2.15rem, 3.6vw, 2.8rem);
  line-height: 1.06;
  letter-spacing: 0.01em;
  color: #ff7f45;
}

.hero-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.progress-card {
  grid-column: span 6;
  display: grid;
  gap: 10px;
  align-content: start;
}

.progress-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.meter-wrap {
  height: 18px;
  border-radius: 999px;
  background: rgba(45, 56, 109, 0.15);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #42d7ff, #4eca66, #ffc73d);
  transition: width 0.35s ease;
}

.reward-status {
  font-size: 1.08rem;
}

.star-strip {
  display: flex;
  gap: 8px;
  min-height: 34px;
  align-items: center;
  flex-wrap: wrap;
}

.star {
  font-size: 1.25rem;
  filter: drop-shadow(0 3px 0 rgba(255, 198, 52, 0.5));
}

.alphabet-card {
  grid-column: span 7;
  display: grid;
  gap: 12px;
  align-content: start;
}

.alphabet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
  gap: 8px;
}

.letter-chip {
  border: none;
  border-radius: 12px;
  padding: 10px 0;
  font-family: 'Fredoka', sans-serif;
  font-size: 1.2rem;
  background: rgba(255, 255, 255, 0.9);
  color: #4b4181;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.2s ease;
}

.letter-chip:hover {
  transform: translateY(-2px);
}

.letter-chip.current {
  background: #5b4cc7;
  color: #fff;
}

.letter-chip.learned {
  background: #57be63;
  color: #fff;
}

.quiz-card {
  grid-column: span 5;
  display: grid;
  gap: 12px;
  align-content: start;
}

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

.hint {
  color: #6a6286;
  font-size: 0.95rem;
}

.quiz-prompt {
  font-size: 1.25rem;
}

.quiz-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.quiz-option {
  border: none;
  border-radius: 14px;
  padding: 10px;
  font-size: 1.05rem;
  background: rgba(91, 76, 199, 0.12);
  color: #352b73;
  cursor: pointer;
}

.quiz-option.correct {
  background: rgba(79, 191, 92, 0.27);
}

.quiz-option.wrong {
  background: rgba(231, 79, 115, 0.22);
}

.quiz-result {
  min-height: 24px;
  font-size: 1.05rem;
}

.action-btn,
.pill-btn {
  border: none;
  border-radius: 14px;
  padding: 10px 14px;
  font-family: 'Baloo 2', cursive;
  font-size: 1rem;
  cursor: pointer;
  background: #ffffff;
  color: #3f3477;
  box-shadow: 0 7px 14px rgba(53, 42, 123, 0.1);
}

.action-btn.primary {
  background: linear-gradient(120deg, var(--accent), #ffb14d);
  color: #fff;
}

.action-btn.danger {
  background: linear-gradient(120deg, var(--danger), #ff8b72);
  color: #fff;
}

.action-btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.parent-icon-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  padding: 0;
  font-size: 1.32rem;
  display: grid;
  place-items: center;
  background: linear-gradient(140deg, #5b4cc7, #8d7cff);
  color: #fff;
  box-shadow: 0 10px 18px rgba(57, 43, 128, 0.34);
}

.fullscreen-icon-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  padding: 0;
  font-size: 1.3rem;
  display: grid;
  place-items: center;
  background: linear-gradient(140deg, #17a7c7, #5ad8ff);
  color: #fff;
  box-shadow: 0 10px 18px rgba(24, 123, 161, 0.28);
}

.fullscreen-icon-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.icon-btn {
  font-size: 1.25rem;
  display: grid;
  place-items: center;
  min-height: 46px;
  padding: 8px;
}

#speak-letter-btn,
#speak-word-btn {
  min-height: 54px;
  font-size: 1.5rem;
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(33, 23, 61, 0.58);
  z-index: 30;
  padding: 16px;
}

.hidden {
  display: none;
}

.overlay-card {
  width: min(780px, 100%);
  background: #fff;
  border-radius: 22px;
  padding: 20px;
  box-shadow: 0 18px 34px rgba(18, 9, 48, 0.34);
  display: grid;
  gap: 12px;
}

.reward-modal {
  text-align: center;
}

#reward-overlay {
  overflow-y: auto;
  place-items: start center;
  padding-top: 20px;
  padding-bottom: 20px;
}

#reward-overlay .overlay-card.reward-modal {
  width: min(760px, 100%);
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#reward-overlay .video-shell {
  max-width: min(100%, 680px);
  margin: 0 auto;
}

#reward-countdown {
  font-family: 'Fredoka', sans-serif;
  font-size: 2.2rem;
  color: #ff7f45;
}

.video-shell {
  width: 100%;
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 14px;
  overflow: hidden;
  background: #111;
}

.video-shell.portrait {
  width: min(300px, 78vw);
  margin: 0 auto;
  aspect-ratio: 9 / 16;
}

.video-shell.portrait.mobile-landscape-playback {
  width: min(300px, 78vw);
  margin: 0 auto;
  aspect-ratio: 9 / 16;
}

.video-shell.portrait.mobile-landscape-playback #youtube-player,
.video-shell.portrait.mobile-landscape-playback #youtube-player iframe {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 177.78%;
  height: 56.25%;
  transform: translate(-50%, -50%) rotate(90deg);
  transform-origin: center;
}

#youtube-player,
#youtube-player iframe {
  width: 100%;
  height: 100%;
}

.video-lock-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: rgba(0, 0, 0, 0.01);
}

.video-lock-layer.unlocked {
  pointer-events: none;
}

.reward-action-row {
  justify-content: center;
  position: sticky;
  bottom: 0;
  z-index: 3;
  margin-top: auto;
  padding-top: 10px;
  padding-bottom: 2px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0), #fff 34%);
}

#toggle-reward-lock-btn {
  min-height: 54px;
  min-width: min(340px, 100%);
  font-size: 1.08rem;
  font-weight: 700;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#toggle-reward-lock-btn.pressing {
  background: linear-gradient(120deg, #ffd478, #ffb14d);
  color: #5c3d12;
}

.parent-modal label {
  font-size: 1rem;
}

#parent-overlay {
  overflow-y: auto;
}

#parent-overlay .overlay-card.parent-modal {
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
}

.parent-modal input[type='text'],
.parent-modal input[type='password'],
.parent-modal input[type='number'],
.parent-modal select,
#pin-input {
  width: 100%;
  border: 2px solid rgba(85, 76, 139, 0.25);
  border-radius: 12px;
  font-size: 1rem;
  padding: 9px 10px;
  margin-top: 4px;
}

.modal-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.form-error {
  margin: 2px 0 0;
  color: #b42345;
  font-size: 0.94rem;
  font-weight: 700;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(14px);
  background: #352d6f;
  color: #fff;
  padding: 10px 14px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.28s ease;
  z-index: 50;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.mobile-dock {
  display: none;
}

.dock-btn {
  border: none;
  border-radius: 14px;
  padding: 9px 6px;
  background: rgba(255, 255, 255, 0.72);
  color: #4a3e88;
  font-family: 'Baloo 2', cursive;
  font-size: 0.95rem;
  font-weight: 700;
}

.dock-btn.active {
  background: linear-gradient(120deg, #5b4cc7, #7d6dff);
  color: #fff;
  box-shadow: 0 10px 20px rgba(58, 50, 128, 0.28);
}

.pop-star {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  animation: popStar 0.8s ease-out forwards;
}

@keyframes drift {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }
  50% {
    transform: translateY(-12px) scale(1.04);
  }
}

@keyframes popStar {
  from {
    transform: translate(0, 0) scale(1);
    opacity: 1;
  }
  to {
    transform: translate(var(--dx), var(--dy)) scale(0.2);
    opacity: 0;
  }
}

@media (max-width: 980px) {
  body {
    min-height: 100dvh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 8px 0 84px;
  }

  .top-bar {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0 6px 8px;
  }

  h1 {
    font-size: 1.35rem;
  }

  .top-bar .pill-btn {
    padding: 8px 8px;
    font-size: 0.9rem;
  }

  .top-bar .parent-icon-btn {
    width: 42px;
    height: 42px;
    font-size: 1.2rem;
  }

  .top-bar .fullscreen-icon-btn {
    width: 42px;
    height: 42px;
    font-size: 1.16rem;
  }

  .layout {
    width: 100%;
    max-width: none;
    flex: 1;
    min-height: 0;
    display: block;
    padding: 0 6px;
  }

  .card {
    height: 100%;
    overflow: hidden;
    padding: 12px;
    border-radius: 18px;
  }

  .mobile-hidden {
    display: none !important;
  }

  .hero-card,
  .progress-card,
  .alphabet-card,
  .quiz-card {
    grid-column: auto;
  }

  .hero-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .hero-card {
    grid-template-rows: auto auto;
    align-content: start;
    gap: 8px;
  }

  .hero-main {
    min-height: min(56dvh, 460px);
    padding: 6px 10px;
    display: grid;
    align-content: start;
    justify-items: center;
    gap: 3px;
  }

  .label {
    font-size: 0.82rem;
  }

  .letter-display {
    font-size: clamp(4rem, 18vw, 6rem);
  }

  .emoji-display {
    width: min(72vw, 280px);
    font-size: clamp(6rem, 30vw, 11rem);
    border-radius: 22px;
    margin: 2px auto;
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.95), 0 12px 22px rgba(70, 112, 175, 0.2);
  }

  .word-display {
    font-size: clamp(2rem, 9vw, 2.9rem);
    line-height: 1.04;
    margin-top: 2px;
  }

  .action-btn,
  .pill-btn {
    padding: 9px 8px;
    font-size: 0.86rem;
    border-radius: 12px;
  }

  .hero-controls .action-btn {
    min-height: 40px;
    line-height: 1.1;
  }

  .hero-controls .icon-btn {
    font-size: 1.35rem;
  }

  .hero-controls #speak-letter-btn,
  .hero-controls #speak-word-btn {
    min-height: 56px;
    font-size: 1.7rem;
  }

  .hero-controls #learned-btn {
    grid-column: 1 / -1;
  }

  .progress-card {
    gap: 10px;
    grid-template-rows: auto auto auto auto 1fr auto;
    align-content: stretch;
    min-height: 0;
  }

  .progress-head {
    align-items: start;
  }

  .progress-head h2 {
    font-size: 1.18rem;
    line-height: 1.1;
  }

  #score-text {
    font-size: 1rem;
  }

  .meter-wrap {
    height: 22px;
  }

  #progress-text {
    font-size: 1rem;
    font-weight: 700;
  }

  .reward-status {
    font-size: 0.98rem;
    line-height: 1.35;
    background: rgba(91, 76, 199, 0.08);
    border-radius: 14px;
    padding: 10px 12px;
  }

  .star-strip {
    min-height: 0;
    gap: 6px;
    align-content: start;
    padding: 8px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.72);
    overflow: auto;
  }

  .star {
    font-size: 1.18rem;
  }

  #manual-reward-btn {
    min-height: 52px;
    font-size: 1rem;
    font-weight: 700;
  }

  .alphabet-card {
    gap: 10px;
    grid-template-rows: auto 1fr;
    align-content: stretch;
    min-height: 0;
  }

  .alphabet-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    grid-auto-rows: minmax(50px, 1fr);
    gap: 10px;
    min-height: 0;
    height: 100%;
    align-content: stretch;
  }

  .letter-chip {
    min-height: 50px;
    padding: 6px 0;
    font-size: 1.28rem;
    border-radius: 16px;
    font-weight: 700;
  }

  .quiz-card {
    gap: 10px;
    grid-template-rows: auto auto 1fr auto;
    align-content: stretch;
    min-height: 0;
  }

  .quiz-prompt {
    font-size: 1.14rem;
    line-height: 1.35;
  }

  .quiz-options {
    gap: 10px;
    grid-auto-rows: minmax(74px, 1fr);
    min-height: 0;
    align-content: stretch;
  }

  .quiz-option {
    min-height: 74px;
    padding: 8px;
    font-size: 1.3rem;
    font-weight: 700;
    border-radius: 16px;
  }

  .quiz-result {
    min-height: 26px;
    font-size: 1.03rem;
  }

  .quiz-card #next-quiz-btn {
    min-height: 44px;
    padding: 8px 12px;
  }

  .mobile-dock {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 10px;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    padding: 8px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(8px);
    box-shadow: 0 12px 24px rgba(49, 36, 94, 0.25);
    z-index: 20;
  }

  .overlay {
    padding: 10px;
    z-index: 60;
  }

  .overlay-card {
    padding: 14px;
  }

  #toggle-reward-lock-btn {
    min-height: 58px;
    width: 100%;
    min-width: 0;
    font-size: 1.12rem;
  }

  .video-shell.portrait {
    width: min(260px, 72vw);
  }

  .learn-check-modal .quiz-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
