* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #6c5ce7;
  --accent: #fd79a8;
  --text: #2d3436;
  --muted: #636e72;
  --shadow: 0 8px 24px rgba(108, 92, 231, 0.15);
  --shadow-lg: 0 16px 48px rgba(108, 92, 231, 0.25);
}

html, body { height: 100%; }

body {
  font-family: 'Fredoka', system-ui, -apple-system, Segoe UI, sans-serif;
  background:
    radial-gradient(circle at 10% 20%, #ffe5f1 0%, transparent 40%),
    radial-gradient(circle at 90% 30%, #e0f4ff 0%, transparent 40%),
    radial-gradient(circle at 50% 90%, #fff4cc 0%, transparent 40%),
    linear-gradient(135deg, #fdf2f8, #f0f9ff);
  background-attachment: fixed;
  min-height: 100vh;       /* fallback */
  min-height: 100dvh;      /* iOS Safari: не прыгает с адресной строкой */
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;  /* блок pull-to-refresh */
}

button {
  font-family: inherit;
  touch-action: manipulation;       /* убрать 300ms задержку на iOS */
}

#app {
  max-width: 1100px;
  margin: 0 auto;
  padding-top:    max(24px, env(safe-area-inset-top));
  padding-bottom: max(48px, env(safe-area-inset-bottom));
  padding-left:   max(16px, env(safe-area-inset-left));
  padding-right:  max(16px, env(safe-area-inset-right));
}

.screen { display: none; animation: fadeIn 0.35s ease; }
.screen.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============== Навигация по детским модулям ============== */
.kids-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  overflow-x: auto;
  padding: 4px 2px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.kids-nav::-webkit-scrollbar { display: none; }
.kids-nav__chip {
  flex-shrink: 0;
  padding: 8px 16px;
  background: white;
  border-radius: 22px;
  text-decoration: none;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  white-space: nowrap;
  transition: transform 0.2s;
}
.kids-nav__chip:active { transform: scale(0.95); }
.kids-nav__chip--active {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  pointer-events: none;
}
.kids-nav__chip--hub { padding: 8px 12px; }

/* ============== ГЛАВНАЯ ============== */
.home-header { text-align: center; margin-bottom: 32px; }

.home-header h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 8px;
}

.subtitle {
  color: var(--muted);
  font-size: 1rem;
  margin-bottom: 20px;
}

.progress-wrap { max-width: 420px; margin: 0 auto; }

.progress-bar {
  background: rgba(255, 255, 255, 0.7);
  height: 14px;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  width: 0%;
  transition: width 0.6s cubic-bezier(.4, 1.4, .6, 1);
  border-radius: 8px;
}

.progress-text {
  text-align: center;
  margin-top: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 14px;
  margin-bottom: 32px;
}

.letter-tile {
  aspect-ratio: 1;
  border: none;
  border-radius: 22px;
  background: white;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
  overflow: hidden;
  padding: 8px;
}

.letter-tile::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--tile-color), transparent 70%);
  opacity: 0.18;
  transition: opacity 0.2s;
}

.letter-tile:active { transform: scale(0.96); }

.tile-letter {
  font-size: 2.6rem;
  font-weight: 700;
  color: var(--tile-color);
  line-height: 1;
  z-index: 1;
}

.tile-emoji {
  font-size: 1.4rem;
  margin-top: 6px;
  z-index: 1;
}

.tile-star {
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 1.1rem;
  z-index: 2;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
}

/* «Сложная» буква — была ошибка, требует повторения */
.letter-tile--tricky {
  box-shadow: 0 0 0 3px #ff9f43, var(--shadow);
}
.tile-tricky {
  position: absolute;
  top: 6px;
  left: 8px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ff9f43;
  z-index: 2;
  box-shadow: 0 0 0 2px white, 0 2px 4px rgba(0, 0, 0, 0.15);
  animation: trickyPulse 1.6s ease-in-out infinite;
}
@keyframes trickyPulse {
  0%, 100% { transform: scale(1);   opacity: 1;   }
  50%      { transform: scale(1.3); opacity: 0.7; }
}

/* Кнопка «Тренировать сложные» — оранжевая, выделяется среди CTA */
.cta-btn.cta-btn--tricky {
  background: linear-gradient(135deg, #ff9f43, #ee5a6f);
}

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

.cta-btn {
  font-size: 1.1rem;
  font-weight: 600;
  padding: 14px 28px;
  border-radius: 16px;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  box-shadow: var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s;
}

.cta-btn:active { transform: scale(0.96); }

.cta-btn.ghost {
  background: white;
  color: var(--text);
}

/* ============== КАРТОЧКА БУКВЫ ============== */
.back-btn {
  font-size: 1rem;
  font-weight: 500;
  padding: 10px 18px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  background: white;
  color: var(--text);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
  transition: transform 0.2s;
}

.letter-card {
  background: white;
  border-radius: 36px;
  padding: 40px 32px 32px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  max-width: 600px;
  margin: 0 auto;
  border: 6px solid var(--tile-color, var(--primary));
  transition: border-color 0.4s;
}

.letter-display {
  font-size: clamp(5rem, 16vw, 9rem);
  font-weight: 700;
  line-height: 1;
  color: var(--tile-color, var(--primary));
  margin-bottom: 8px;
  letter-spacing: -0.04em;
}

.letter-emoji {
  font-size: clamp(4rem, 11vw, 6.5rem);
  margin-bottom: 8px;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.1));
}

.letter-word {
  font-size: clamp(1.5rem, 4vw, 2.2rem);
  font-weight: 600;
  margin-bottom: 28px;
  color: var(--text);
}

.letter-word .highlight {
  color: var(--tile-color, var(--primary));
  font-weight: 700;
}

.letter-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.speak-btn {
  font-size: 1.05rem;
  font-weight: 500;
  padding: 14px 24px;
  border-radius: 16px;
  border: none;
  cursor: pointer;
  background: var(--tile-color, var(--primary));
  color: white;
  box-shadow: var(--shadow);
  transition: transform 0.2s, filter 0.2s;
}

.speak-btn:active { transform: scale(0.95); }

.learn-btn {
  font-size: 1rem;
  font-weight: 500;
  padding: 12px 24px;
  border-radius: 14px;
  border: 2px solid var(--tile-color, var(--primary));
  cursor: pointer;
  background: white;
  color: var(--tile-color, var(--primary));
  transition: all 0.2s;
}

.learn-btn.learned {
  background: var(--tile-color, var(--primary));
  color: white;
}

.letter-nav {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 28px;
}

.nav-btn {
  font-size: 1.6rem;
  font-weight: 700;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: white;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s;
}

.nav-btn:active { transform: scale(0.95); }

/* ============== ИГРА ============== */
.game-header { text-align: center; margin-bottom: 28px; }

.game-header h2 {
  font-size: 2rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 8px;
}

.game-stats {
  font-size: 1rem;
  color: var(--muted);
}

.game-prompt { text-align: center; margin-bottom: 32px; }

.big-speak {
  font-size: 1.4rem;
  font-weight: 600;
  padding: 22px 44px;
  border-radius: 24px;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  box-shadow: var(--shadow-lg);
  transition: transform 0.2s;
}

.big-speak:active { transform: scale(0.96); }

.game-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 16px;
  max-width: 600px;
  margin: 0 auto;
}

.game-option {
  aspect-ratio: 1;
  border-radius: 24px;
  background: white;
  font-size: 4rem;
  font-weight: 700;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: all 0.2s;
  color: var(--primary);
}

.game-option:active { transform: scale(0.96); }
.game-option:disabled { cursor: default; }

.game-option.correct {
  background: #55efc4;
  color: white;
  animation: pop 0.45s ease;
}

.game-option.wrong {
  background: #ff7675;
  color: white;
  animation: shake 0.4s ease;
}

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

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-10px); }
  75%      { transform: translateX(10px); }
}

.game-result {
  text-align: center;
  margin-top: 28px;
  font-size: 1.4rem;
  font-weight: 600;
  min-height: 2em;
  color: var(--text);
}

.game-final { padding: 32px 20px; }
.game-final .emoji-final { font-size: 5rem; margin-bottom: 12px; }
.game-final h3 { font-size: 1.8rem; margin-bottom: 8px; }
.game-final__score {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 16px;
}
.game-final__tricky {
  display: inline-block;
  margin: 0 auto 20px;
  padding: 10px 18px;
  background: #fff5e6;
  border: 2px dashed #ff9f43;
  border-radius: 14px;
  color: #d35400;
  font-size: 1.05rem;
  font-weight: 500;
  max-width: 90%;
}
.game-final__buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ============== HOVER только для мыши ============== */
/* На тачскринах :hover «залипает» после тапа — отключаем */
@media (hover: hover) and (pointer: fine) {
  .letter-tile:hover {
    transform: translateY(-4px) scale(1.03);
    box-shadow: var(--shadow-lg);
  }
  .letter-tile:hover::before { opacity: 0.32; }

  .cta-btn:hover    { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
  .back-btn:hover   { transform: translateX(-3px); }
  .speak-btn:hover  { transform: scale(1.05); filter: brightness(1.05); }
  .learn-btn:hover  { background: var(--tile-color, var(--primary)); color: white; }
  .nav-btn:hover    { transform: scale(1.1); box-shadow: var(--shadow-lg); }
  .big-speak:hover  { transform: scale(1.05); }
  .game-option:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
}

/* ============== iPad (планшеты) ============== */
@media (min-width: 481px) and (max-width: 1024px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 16px; }
  .tile-letter { font-size: 2.8rem; }
  .letter-card { padding: 36px 28px; max-width: 540px; }
  .letter-display { font-size: clamp(6rem, 14vw, 8rem); }
  .game-options  { grid-template-columns: repeat(4, 1fr); }
  .game-option   { font-size: 3.6rem; }
}

/* ============== Телефоны ============== */
@media (max-width: 480px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(85px, 1fr)); gap: 10px; }
  .tile-letter { font-size: 2rem; }
  .tile-emoji  { font-size: 1.1rem; }
  .letter-card { padding: 28px 18px; border-radius: 28px; }
  .letter-actions { gap: 8px; }
  .speak-btn { padding: 12px 18px; font-size: 1rem; }
  .game-options { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .game-option  { font-size: 3rem; border-radius: 20px; }
  .big-speak    { font-size: 1.2rem; padding: 18px 32px; }
  .nav-btn      { width: 56px; height: 56px; font-size: 1.4rem; }
}

/* ============== PWA standalone ============== */
/* Когда добавили на главный экран и открыли как приложение */
@media all and (display-mode: standalone) {
  body { background-attachment: scroll; } /* fixed бывает багует в standalone iOS */
}

/* ============== Feedback panel (после ответа) ============== */
.feedback-msg {
  font-size: clamp(1.05rem, 2.6vw, 1.3rem);
  font-weight: 500;
  margin-bottom: 14px;
  color: var(--text);
}
.feedback-correct, .feedback-correct-letter {
  font-weight: 700;
  font-size: 1.3em;
  vertical-align: -0.05em;
}
.feedback-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}
.feedback-btn {
  font-size: 1.05rem;
  font-weight: 600;
  padding: 14px 28px;
  border-radius: 16px;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  box-shadow: var(--shadow);
  font-family: inherit;
  transition: transform 0.15s, box-shadow 0.15s;
}
.feedback-btn:active { transform: scale(0.96); }
.feedback-btn--ghost {
  background: white;
  color: var(--text);
}
@media (hover: hover) and (pointer: fine) {
  .feedback-btn:hover { transform: translateY(-2px); }
}
