/* ==========================================================================
   Math Pet - styles
   Bright, rounded, high-contrast, large tap targets (min ~80px) for small
   fingers. Designed mobile-first for phones (portrait) and tablets
   (landscape).
   ========================================================================== */

:root {
  --sky: #eaf6ff;
  --sky-2: #d7f0ff;
  --card-bg: #ffffff;
  --text: #35314a;
  --text-soft: #6b6685;
  --primary: #ff9a3c;
  --primary-dark: #f07d1a;
  --secondary: #5fc9e8;
  --secondary-dark: #3ba9c9;
  --success: #6bd18f;
  --success-dark: #45b56b;
  --danger: #ff8a8a;
  --danger-dark: #f26363;
  --accent-pink: #ff9fd0;
  --accent-yellow: #ffd85e;
  --shadow: 0 6px 0 rgba(0, 0, 0, 0.12);
  --radius-lg: 28px;
  --radius-md: 20px;
  --radius-sm: 14px;
  --min-tap: 80px;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: 'Comic Sans MS', 'Trebuchet MS', 'Baloo 2', system-ui, -apple-system,
    sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 20% 10%, var(--sky-2), var(--sky) 60%);
  min-height: 100vh;
  overflow-x: hidden;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

/* ---------- Top bar ---------- */

#top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
}

#offline-badge {
  font-size: 0.85rem;
  background: #fff3d6;
  border: 2px solid var(--accent-yellow);
  border-radius: 999px;
  padding: 4px 12px;
  color: var(--text-soft);
}

.icon-btn {
  width: var(--min-tap);
  height: var(--min-tap);
  border-radius: 50%;
  border: none;
  background: #ffffffcc;
  font-size: 2rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

.icon-btn.small {
  width: 52px;
  height: 52px;
  font-size: 1.4rem;
  opacity: 0.6;
}

.icon-btn:active {
  transform: translateY(4px);
  box-shadow: none;
}

/* ---------- Layout: screens ---------- */

#screens {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.screen {
  width: 100%;
  max-width: 720px;
  display: none;
}

.screen.active {
  display: block;
  animation: fade-in 0.35s ease;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 28px 22px;
  box-shadow: 0 12px 0 rgba(0, 0, 0, 0.06), 0 20px 40px rgba(50, 40, 90, 0.12);
  text-align: center;
}

.center-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.title {
  font-size: clamp(2.2rem, 8vw, 3.2rem);
  margin: 0;
}

.subtitle {
  margin: 0 0 8px;
  color: var(--text-soft);
  font-size: 1.2rem;
}

.prompt {
  font-size: clamp(1.4rem, 5vw, 2rem);
  margin: 0 0 20px;
}

.parent-note {
  font-size: 0.85rem;
  color: var(--text-soft);
  max-width: 420px;
  margin: -8px 0 8px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
}

/* ---------- Big buttons ---------- */

.big-btn {
  min-height: var(--min-tap);
  border: none;
  border-radius: var(--radius-md);
  font-size: 1.4rem;
  font-weight: 700;
  font-family: inherit;
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px 28px;
  cursor: pointer;
  box-shadow: var(--shadow);
  touch-action: manipulation;
  width: 100%;
}

.big-btn:active {
  transform: translateY(6px);
  box-shadow: none;
}

.big-btn-emoji {
  font-size: 1.8rem;
}

.big-btn.primary {
  background: linear-gradient(180deg, var(--primary), var(--primary-dark));
}

.big-btn.secondary {
  background: linear-gradient(180deg, var(--secondary), var(--secondary-dark));
}

.text-back-btn {
  margin-top: 16px;
  border: none;
  background: none;
  color: var(--text-soft);
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  min-height: 44px;
}

.row-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ---------- Tile grids (animals, names, icons) ---------- */

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 14px;
}

.tile-btn {
  min-height: var(--min-tap);
  border: 4px solid transparent;
  border-radius: var(--radius-md);
  background: #fff6ea;
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  padding: 14px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: var(--shadow);
  touch-action: manipulation;
}

.tile-btn:active {
  transform: translateY(6px);
  box-shadow: none;
}

.tile-btn .tile-emoji {
  font-size: 2.6rem;
}

.tile-btn.selected {
  border-color: var(--success-dark);
  background: #e9fbef;
}

.icon-grid .tile-btn .tile-emoji {
  font-size: 2.2rem;
}

/* ---------- Picture code ---------- */

.code-tiles {
  display: flex;
  gap: 14px;
  justify-content: center;
  margin: 6px 0 10px;
}

.code-tile {
  width: 90px;
  height: 90px;
  border-radius: var(--radius-md);
  background: #fff6ea;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  box-shadow: var(--shadow);
}

.login-slots {
  display: flex;
  gap: 14px;
  justify-content: center;
  margin-bottom: 16px;
}

.login-slot {
  width: 60px;
  height: 60px;
  border-radius: var(--radius-sm);
  border: 3px dashed #cfcbe6;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  background: #faf9ff;
}

.login-slot.filled {
  border-style: solid;
  border-color: var(--secondary-dark);
  background: #eafaff;
}

.login-message {
  min-height: 28px;
  font-weight: 700;
  color: var(--danger-dark);
}

/* ---------- Hub / pet display ---------- */

.hub-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
}

.pet-panel {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 20px;
  width: 100%;
  text-align: center;
  box-shadow: 0 12px 0 rgba(0, 0, 0, 0.06), 0 20px 40px rgba(50, 40, 90, 0.12);
}

.pet-name-label {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 4px;
}

.pet-stage {
  width: 100%;
  max-width: 280px;
  margin: 0 auto;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pet-stage svg {
  width: 100%;
  height: 100%;
  animation: bob 3s ease-in-out infinite;
}

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

.progress-wrap {
  margin-top: 12px;
}

.progress-bar {
  height: 28px;
  border-radius: 999px;
  background: #f0eefc;
  overflow: hidden;
  border: 3px solid #e2dff5;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--success), var(--success-dark));
  border-radius: 999px;
  transition: width 0.6s ease;
}

.stage-label {
  margin-top: 8px;
  font-weight: 700;
  color: var(--text-soft);
}

.hub-actions {
  display: flex;
  gap: 16px;
  width: 100%;
}

/* ---------- Gallery ---------- */

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
  min-height: 80px;
}

.gallery-card {
  background: #fff6ea;
  border-radius: var(--radius-md);
  padding: 14px 8px;
  box-shadow: var(--shadow);
  text-align: center;
}

.gallery-card .tile-emoji {
  font-size: 2.4rem;
  display: block;
}

.gallery-card .gallery-name {
  font-weight: 700;
  margin-top: 4px;
}

.gallery-card .gallery-stage {
  font-size: 0.85rem;
  color: var(--text-soft);
}

.gallery-empty {
  grid-column: 1 / -1;
  color: var(--text-soft);
  padding: 20px 0;
}

/* ---------- Overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(53, 49, 74, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.overlay.overlay-transparent {
  background: transparent;
  pointer-events: none;
}

.overlay-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 26px 20px;
  max-width: 520px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 50px rgba(20, 15, 50, 0.35);
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}

.close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 52px;
  height: 52px;
  font-size: 1.2rem;
}

/* ---------- Math question ---------- */

.question-visual {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: clamp(1.8rem, 6vw, 2.6rem);
  margin-bottom: 24px;
  min-height: 90px;
}

.q-icon {
  display: inline-block;
}

.q-icon.faded {
  opacity: 0.25;
  text-decoration: line-through;
}

.q-op, .q-eq {
  font-weight: 800;
  color: var(--text-soft);
  margin: 0 6px;
}

.choice-row {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
}

.choice-btn {
  min-width: var(--min-tap);
  min-height: var(--min-tap);
  border-radius: var(--radius-md);
  border: none;
  background: linear-gradient(180deg, var(--secondary), var(--secondary-dark));
  color: white;
  font-size: 2rem;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
  box-shadow: var(--shadow);
  touch-action: manipulation;
  padding: 10px 22px;
}

.choice-btn:active {
  transform: translateY(6px);
  box-shadow: none;
}

.choice-btn.wrong-shake {
  animation: shake 0.5s ease;
  background: linear-gradient(180deg, var(--danger), var(--danger-dark));
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); }
  40% { transform: translateX(10px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

.choice-btn.correct-pop {
  animation: pop 0.4s ease;
  background: linear-gradient(180deg, var(--success), var(--success-dark));
}

@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* ---------- Feedback overlay ---------- */

.feedback-content {
  font-size: clamp(2.2rem, 10vw, 4rem);
  font-weight: 800;
  text-align: center;
  color: white;
  text-shadow: 0 4px 0 rgba(0,0,0,0.15);
  animation: float-up 1.1s ease forwards;
}

@keyframes float-up {
  0% { transform: translateY(20px) scale(0.7); opacity: 0; }
  20% { transform: translateY(0) scale(1.1); opacity: 1; }
  35% { transform: scale(1); }
  80% { opacity: 1; }
  100% { transform: translateY(-40px) scale(0.9); opacity: 0; }
}

/* ---------- Level up ---------- */

.levelup-emoji {
  font-size: 5rem;
  margin: 10px 0;
  animation: pop 0.6s ease;
}

.levelup-label {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 20px;
  color: var(--primary-dark);
}

#confetti-wrap {
  position: relative;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  width: 10px;
  height: 16px;
  opacity: 0.9;
  animation: confetti-fall 2.2s linear forwards;
}

@keyframes confetti-fall {
  to {
    transform: translateY(420px) rotate(360deg);
    opacity: 0;
  }
}

/* ---------- Settings ---------- */

.settings-label {
  font-weight: 700;
  margin: 16px 0 8px;
  text-align: left;
}

.difficulty-row {
  margin-bottom: 8px;
}

.pill-btn {
  min-height: 56px;
  border-radius: 999px;
  border: 3px solid #e2dff5;
  background: white;
  font-family: inherit;
  font-weight: 700;
  font-size: 1rem;
  padding: 10px 20px;
  cursor: pointer;
  touch-action: manipulation;
}

.pill-btn.active {
  background: var(--secondary);
  border-color: var(--secondary-dark);
  color: white;
}

.pill-btn.danger {
  color: var(--danger-dark);
  border-color: var(--danger);
}

#settings-sound-toggle {
  width: 100%;
}

/* ---------- Responsive ---------- */

@media (min-width: 700px) {
  .hub-layout {
    max-width: 560px;
  }

  .hub-actions {
    max-width: 420px;
    margin: 0 auto;
  }
}

@media (orientation: landscape) and (max-height: 480px) {
  .pet-stage {
    max-width: 180px;
  }

  .card {
    padding: 16px;
  }
}
