/* ============================================================
   Design Tokens
   ============================================================ */
:root {
  --c-bg:           #FFF8F0;
  --c-surface:      #FFFFFF;
  --c-primary:      #7C3AED;
  --c-primary-dark: #6D28D9;
  --c-primary-soft: #EDE9FE;
  --c-secondary:    #16A34A;
  --c-accent:       #F59E0B;
  --c-danger:       #EF4444;
  --c-text:         #1F2937;
  --c-muted:        #6B7280;
  --c-border:       #E5E7EB;

  --r-sm:   10px;
  --r-md:   16px;
  --r-lg:   22px;
  --r-xl:   32px;
  --r-full: 9999px;

  --shadow-sm: 0 2px 6px rgba(0,0,0,0.07);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.11);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.15);

  --nav-h:    68px;
  --font:     'Nunito', system-ui, sans-serif;
}

/* ============================================================
   Reset & Base
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  height: 100%;
  font-family: var(--font);
  background: #D1D5DB; /* visible behind the card on desktop */
}

body {
  height: 100%;
  background: #D1D5DB;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

/* ============================================================
   App Shell — mobile card, centered on desktop
   ============================================================ */
#app {
  position: relative;
  width: 100%;
  max-width: 430px;
  height: 100dvh;
  background: var(--c-bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

@media (min-width: 500px) {
  body { align-items: center; }
  #app { height: min(900px, 100dvh); border-radius: var(--r-xl); }
}

/* ============================================================
   Screen base
   ============================================================ */
.screen {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

.screen.entering {
  animation: screen-fade-in 0.2s ease-out;
}

@keyframes screen-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   Bottom Navigation
   ============================================================ */
.bottom-nav {
  display: flex;
  height: var(--nav-h);
  background: var(--c-surface);
  border-top: 1.5px solid var(--c-border);
  flex-shrink: 0;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
  color: var(--c-muted);
  transition: color 0.15s;
  padding-top: 6px;
}

.nav-btn.active  { color: var(--c-primary); }
.nav-btn:active  { transform: scale(0.92); }

.nav-icon  { font-size: 1.4rem; }
.nav-label { font-size: 0.62rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; }

/* ============================================================
   Home Screen
   ============================================================ */
.screen-home {
  background: linear-gradient(160deg, #EDE9FE 0%, #FFF8F0 55%);
  padding-bottom: var(--nav-h);
}

.home-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 28px 24px 12px;
}

.app-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-logo-icon { font-size: 3.2rem; line-height: 1; }

.app-title {
  font-size: 2rem;
  font-weight: 900;
  color: var(--c-primary);
  line-height: 1;
  letter-spacing: -0.5px;
}

.app-subtitle {
  font-size: 0.85rem;
  color: var(--c-muted);
  font-weight: 700;
  margin-top: 3px;
}

.mascot {
  font-size: 4.5rem;
  animation: mascot-sway 2.8s ease-in-out infinite;
  transform-origin: 50% 90%;
  user-select: none;
}

@keyframes mascot-sway {
  0%, 100% { transform: rotate(-6deg); }
  50%       { transform: rotate(6deg); }
}

.home-menu {
  display: flex;
  flex-direction: column;
  gap: 11px;
  padding: 8px 20px 24px;
}

.menu-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 15px 18px;
  border: none;
  border-radius: var(--r-lg);
  cursor: pointer;
  font-family: inherit;
  color: white;
  text-align: left;
  box-shadow: var(--shadow-md);
  transition: transform 0.12s, box-shadow 0.12s;
}

.menu-btn:active { transform: scale(0.97); box-shadow: var(--shadow-sm); }

.btn-continue { background: linear-gradient(135deg, #7C3AED, #9333EA); }
.btn-levels   { background: linear-gradient(135deg, #0284C7, #0EA5E9); }
.btn-daily    { background: linear-gradient(135deg, #D97706, #F59E0B); }
.btn-parent   { background: linear-gradient(135deg, #374151, #4B5563); }

.btn-icon    { font-size: 1.7rem; flex-shrink: 0; }
.btn-label   { font-size: 1.05rem; font-weight: 800; }
.btn-sub     { font-size: 0.75rem; opacity: 0.85; margin-top: 1px; font-weight: 600; }

/* ============================================================
   Sub-screen Header
   ============================================================ */
.sub-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--c-surface);
  border-bottom: 1.5px solid var(--c-border);
  flex-shrink: 0;
}

.sub-header h2 {
  font-size: 1.15rem;
  font-weight: 900;
  color: var(--c-primary);
}

.back-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid var(--c-border);
  background: white;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--c-text);
  flex-shrink: 0;
  font-family: inherit;
  transition: background 0.12s;
}

.back-btn:hover  { background: var(--c-primary-soft); }
.back-btn:active { transform: scale(0.9); }

/* ============================================================
   Play Screen
   ============================================================ */
.screen-play {
  background: var(--c-bg);
  overflow: hidden; /* children manage their own scroll */
}

.play-header {
  padding: 10px 14px 8px;
  background: var(--c-surface);
  border-bottom: 1.5px solid var(--c-border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.play-header-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.puzzle-counter {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--c-muted);
  white-space: nowrap;
}

.level-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.level-name {
  font-size: 0.95rem;
  font-weight: 900;
  color: var(--c-primary);
}

.star-display .star { font-size: 0.9rem; }

.progress-dots {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.pdot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--c-border);
  transition: background 0.3s;
  flex-shrink: 0;
}

.pdot.done    { background: var(--c-secondary); }
.pdot.current { background: var(--c-primary); }

/* Main play area */
.play-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 16px 8px;
  min-height: 0;
}

.instruction {
  font-size: 1rem;
  font-weight: 700;
  color: var(--c-text);
  text-align: center;
  padding: 9px 18px;
  background: var(--c-surface);
  border-radius: var(--r-full);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
  line-height: 1.4;
}

.wheel-container {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.wheel-svg {
  width: min(72vmin, calc(100dvh - 340px), 300px);
  height: min(72vmin, calc(100dvh - 340px), 300px);
  max-width: calc(100vw - 40px);
  filter: drop-shadow(0 4px 14px rgba(0,0,0,0.13));
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
}

.wheel-slice {
  cursor: pointer;
  transition: filter 0.18s;
}

.wheel-slice:hover { filter: brightness(0.94); }
.wheel-slice.sel   { filter: drop-shadow(0 0 5px rgba(0,0,0,0.25)); }

/* Wheel animations */
@keyframes wheel-correct-glow {
  0%   { filter: drop-shadow(0 4px 14px rgba(0,0,0,0.13)); }
  40%  { filter: drop-shadow(0 0 28px rgba(22,163,74,0.7)); }
  100% { filter: drop-shadow(0 4px 14px rgba(0,0,0,0.13)); }
}

@keyframes wheel-wrong-shake {
  0%,100% { transform: translateX(0); }
  20%     { transform: translateX(-9px) rotate(-1.5deg); }
  40%     { transform: translateX(9px) rotate(1.5deg); }
  60%     { transform: translateX(-6px); }
  80%     { transform: translateX(6px); }
}

.wheel-correct { animation: wheel-correct-glow 0.9s ease-out forwards; }
.wheel-wrong   { animation: wheel-wrong-shake 0.42s ease-in-out; }

/* Feedback strip */
.feedback {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--r-full);
  font-weight: 800;
  font-size: 0.9rem;
  text-align: center;
  min-height: 46px;
  flex-shrink: 0;
  animation: pop-in 0.22s ease-out;
}

@keyframes pop-in {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

.feedback-correct      { background: #D1FAE5; color: #065F46; }
.feedback-level-complete { background: linear-gradient(135deg,#D1FAE5,#A7F3D0); color: #065F46; border: 1.5px solid #6EE7B7; }
.feedback-wrong        { background: #FEE2E2; color: #7F1D1D; }
.feedback-hint         { background: #FEF3C7; color: #78350F; }
.feedback-empty        { background: transparent; }
.feedback-emoji   { font-size: 1.3rem; }

/* Stars earned strip */
.stars-earned {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
}

.star-earned {
  font-size: 1.5rem;
  animation: star-pop 0.4s ease-out both;
}

.star-earned:nth-child(2) { animation-delay: 0.12s; }
.star-earned:nth-child(3) { animation-delay: 0.24s; }

@keyframes star-pop {
  0%   { transform: scale(0) rotate(-30deg); opacity: 0; }
  70%  { transform: scale(1.3) rotate(10deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* Action Bar */
.action-bar {
  display: flex;
  gap: 9px;
  padding: 10px 14px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--c-surface);
  border-top: 1.5px solid var(--c-border);
  flex-shrink: 0;
}

.action-btn {
  flex: 1;
  padding: 13px 8px;
  border: none;
  border-radius: var(--r-lg);
  font-family: inherit;
  font-weight: 800;
  font-size: 0.88rem;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
  box-shadow: var(--shadow-sm);
  line-height: 1.2;
}

.action-btn:active { transform: scale(0.95); }

.btn-hint  { background: #FEF3C7; color: #78350F; }
.btn-undo  { background: #E0E7FF; color: #3730A3; }
.btn-check { background: linear-gradient(135deg, #16A34A, #22C55E); color: white; font-size: 0.95rem; box-shadow: 0 3px 10px rgba(22,163,74,0.35); }
.btn-next  { background: linear-gradient(135deg, #7C3AED, #9333EA); color: white; font-size: 0.95rem; box-shadow: 0 3px 10px rgba(124,58,237,0.35); }

/* ============================================================
   Level Select Screen
   ============================================================ */
.screen-levels {
  background: var(--c-bg);
  padding-bottom: var(--nav-h);
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  padding: 14px;
}

.level-card {
  aspect-ratio: 1;
  border-radius: var(--r-sm);
  border: 2px solid transparent;
  background: var(--c-surface);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-family: inherit;
  transition: transform 0.12s;
}

.level-card:active        { transform: scale(0.93); }
.level-card.current       { border-color: var(--c-primary); background: var(--c-primary-soft); }
.level-card.locked        { opacity: 0.35; cursor: not-allowed; }
.level-card-num           { font-size: 0.9rem; font-weight: 900; color: var(--c-text); }
.level-card-stars         { font-size: 0.5rem; letter-spacing: 0; line-height: 1; }

/* ============================================================
   Progress Screen
   ============================================================ */
.screen-progress {
  background: var(--c-bg);
  padding-bottom: var(--nav-h);
  gap: 12px;
  padding-top: 4px;
}

.progress-hero {
  display: flex;
  gap: 10px;
  padding: 12px 14px 0;
}

.total-stars-badge {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(135deg, #F59E0B, #FBBF24);
  border-radius: var(--r-lg);
  padding: 14px;
  color: white;
  box-shadow: var(--shadow-md);
}

.tsbadge-icon  { font-size: 2rem; }
.tsbadge-num   { font-size: 2rem; font-weight: 900; line-height: 1; }
.tsbadge-label { font-size: 0.72rem; font-weight: 700; opacity: 0.9; }

.level-badge {
  width: 86px;
  background: linear-gradient(135deg, #7C3AED, #9333EA);
  border-radius: var(--r-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: var(--shadow-md);
}

.lbadge-label { font-size: 0.68rem; font-weight: 700; opacity: 0.9; }
.lbadge-num   { font-size: 2rem; font-weight: 900; line-height: 1.1; }

.skill-section,
.recent-section {
  margin: 0 14px;
  background: var(--c-surface);
  border-radius: var(--r-lg);
  padding: 0 14px 12px;
  box-shadow: var(--shadow-sm);
}

.section-title {
  font-size: 0.78rem;
  font-weight: 900;
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 14px 0 10px;
}

.skill-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-top: 1px solid var(--c-border);
}

.skill-emoji { font-size: 1.1rem; flex-shrink: 0; width: 26px; text-align: center; }
.skill-info  { flex: 1; min-width: 0; }
.skill-label { font-size: 0.82rem; font-weight: 700; margin-bottom: 4px; }

.skill-bar-track {
  height: 7px;
  background: var(--c-border);
  border-radius: var(--r-full);
  overflow: hidden;
}

.skill-bar-fill {
  height: 100%;
  border-radius: var(--r-full);
  transition: width 0.7s ease-out 0.1s;
  min-width: 2px;
}

.skill-pct { font-size: 0.77rem; font-weight: 700; color: var(--c-muted); flex-shrink: 0; }

.badge-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  padding-top: 4px;
}

.badge-item { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.badge-icon  { font-size: 2rem; }
.badge-label { font-size: 0.62rem; font-weight: 700; color: var(--c-muted); text-align: center; max-width: 54px; }
.no-badges   { font-size: 0.82rem; color: var(--c-muted); }

.bear-mascot {
  text-align: center;
  padding: 14px 16px;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--c-muted);
}

/* ============================================================
   Rewards Screen
   ============================================================ */
.screen-rewards {
  background: var(--c-bg);
  padding-bottom: var(--nav-h);
}

.stars-header {
  margin-left: auto;
  font-size: 1rem;
  font-weight: 900;
  color: var(--c-primary);
}

/* Next-reward motivational banner */
.next-reward-banner {
  margin: 8px 14px 0;
  padding: 10px 14px;
  background: linear-gradient(135deg, var(--c-primary-soft), #FFF8F0);
  border-radius: var(--r-lg);
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 700;
  flex-wrap: wrap;
}

.next-reward-done {
  background: linear-gradient(135deg, #D1FAE5, #A7F3D0);
  color: #065F46;
  justify-content: center;
}

.next-reward-label { color: var(--c-muted); }
.next-reward-emoji { font-size: 1.3rem; }
.next-reward-name  { color: var(--c-text); }
.next-reward-level { color: var(--c-muted); font-size: 0.78rem; }

.rewards-section { padding: 0 14px 4px; }
.rewards-section .section-title { padding: 14px 0 10px; }

.rewards-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.reward-card {
  background: var(--c-surface);
  border-radius: var(--r-lg);
  border: none;
  padding: 14px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s;
  width: 100%;
  min-height: 92px;
  color: inherit;
  font-family: inherit;
  text-align: center;
}

.reward-card.unlocked { cursor: pointer; }
.reward-card.unlocked:hover { transform: scale(1.06); }
.reward-card.unlocked:active { transform: scale(0.95); }
.reward-card.locked         { opacity: 0.5; cursor: default; }

.reward-emoji { font-size: 2rem; }
.reward-name  { font-size: 0.72rem; font-weight: 800; color: var(--c-text); }
.reward-req   { font-size: 0.62rem; color: var(--c-muted); }

/* ============================================================
   Reward Detail Screen
   ============================================================ */
.screen-reward-detail {
  background: linear-gradient(160deg, #EDE9FE 0%, #FFF8F0 62%);
  padding-bottom: var(--nav-h);
}

.reward-detail-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 28px 24px 42px;
  text-align: center;
}

.reward-detail-icon {
  width: min(190px, 58vw);
  aspect-ratio: 1;
  border-radius: var(--r-xl);
  background: var(--c-surface);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 7rem;
  line-height: 1;
}

.reward-detail-fact {
  max-width: 340px;
  margin: 0;
  padding: 16px 18px;
  border-radius: var(--r-lg);
  background: var(--c-surface);
  box-shadow: var(--shadow-sm);
  color: var(--c-text);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.6;
}

/* ============================================================
   Parent Screen
   ============================================================ */
.screen-parent {
  background: var(--c-bg);
  padding-bottom: var(--nav-h);
}

.parent-gate {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  gap: 16px;
  text-align: center;
}

.gate-emoji { font-size: 3.5rem; }
.gate-text  { font-size: 0.9rem; color: var(--c-muted); max-width: 270px; line-height: 1.5; font-weight: 600; }

.gate-puzzle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 270px;
}

.gate-question { font-size: 1.35rem; font-weight: 900; }

.gate-input {
  width: 100%;
  padding: 11px 14px;
  border: 2px solid var(--c-border);
  border-radius: var(--r-md);
  font-family: inherit;
  font-size: 1.1rem;
  text-align: center;
  outline: none;
  transition: border-color 0.15s;
  background: white;
}

.gate-input:focus { border-color: var(--c-primary); }

.gate-btn {
  width: 100%;
  padding: 13px;
  background: var(--c-primary);
  color: white;
  border: none;
  border-radius: var(--r-md);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.15s;
}

.gate-btn:hover  { background: var(--c-primary-dark); }
.gate-btn:active { transform: scale(0.97); }

.parent-content { padding: 14px; display: flex; flex-direction: column; gap: 14px; }

.parent-section {
  background: var(--c-surface);
  border-radius: var(--r-lg);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}

.parent-section h3 {
  font-size: 0.78rem;
  font-weight: 900;
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

/* Custom toggle */
.setting-toggle {
  appearance: none;
  -webkit-appearance: none;
  width: 44px;
  height: 26px;
  background: var(--c-border);
  border-radius: var(--r-full);
  cursor: pointer;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}

.setting-toggle:checked { background: var(--c-secondary); }

.setting-toggle::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: left 0.2s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.setting-toggle:checked::after { left: 21px; }

.report-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 0.88rem;
  border-top: 1px solid var(--c-border);
}

.parent-text {
  font-size: 0.82rem;
  color: var(--c-muted);
  line-height: 1.6;
  font-weight: 600;
}

.reset-btn {
  padding: 13px;
  background: #FEE2E2;
  color: #B91C1C;
  border: none;
  border-radius: var(--r-md);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.15s;
}

.reset-btn:hover { background: #FECACA; }

/* ============================================================
   Celebration Overlay
   ============================================================ */
.celebration-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 200;
}

.confetti-piece {
  position: absolute;
  animation: confetti-fly 1.1s ease-out forwards;
}

@keyframes confetti-fly {
  0%   { transform: scale(0) rotate(0deg) translateY(0); opacity: 1; }
  60%  { transform: scale(1.4) rotate(25deg) translateY(-40px); opacity: 1; }
  100% { transform: scale(0.9) rotate(-15deg) translateY(-90px); opacity: 0; }
}

/* ============================================================
   Utility Animations
   ============================================================ */
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25%      { transform: translateX(-8px); }
  75%      { transform: translateX(8px); }
}

.shake { animation: shake 0.38s ease-in-out; }
