/* ===== Сброс и переменные ===== */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
:root {
  --c1: #5B8DEF; --c2: #2E2A72;
  --yellow: #FFC93C; --orange: #FF8C42; --red: #FF6B6B;
  --green: #4BCB6A; --teal: #2EC4B6; --purple: #9B6DFF;
  --pink: #FF92C8; --dark: #2E2A72; --white: #FFFFFF;
  --radius: 24px;
}
html, body { height: 100%; }
body {
  font-family: 'Baloo 2', 'Segoe UI', 'Comic Sans MS', 'Chalkboard SE', sans-serif;
  color: var(--dark);
  background: linear-gradient(160deg, #8EC5FC 0%, #E0C3FC 50%, #FCE38A 120%);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
body::before {
  content: "";
  position: fixed; inset: 0;
  background:
    radial-gradient(circle at 15% 20%, rgba(255,255,255,.55) 0 80px, transparent 82px),
    radial-gradient(circle at 85% 15%, rgba(255,255,255,.45) 0 110px, transparent 112px),
    radial-gradient(circle at 80% 85%, rgba(255,255,255,.5) 0 90px, transparent 92px),
    radial-gradient(circle at 10% 80%, rgba(255,255,255,.4) 0 70px, transparent 72px);
  pointer-events: none;
  z-index: 0;
}

#confetti-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 100; }

.app { position: relative; z-index: 1; height: 100%; }

/* ===== Общие ===== */
.screen {
  height: 100%;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: screenIn .35s ease;
}
@keyframes screenIn { from { opacity: 0; transform: translateY(16px) scale(.98); } to { opacity: 1; transform: none; } }

.screen-inner { width: 100%; max-width: 860px; }

h1.title {
  font-size: clamp(28px, 5.5vw, 46px);
  text-align: center;
  color: var(--white);
  text-shadow: 0 3px 0 rgba(46,42,114,.35), 0 8px 18px rgba(46,42,114,.25);
  letter-spacing: 1px;
  margin-bottom: 4px;
}
.subtitle { text-align: center; color: rgba(46,42,114,.75); font-weight: 700; font-size: clamp(14px,2.5vw,18px); margin-bottom: 18px; }

/* ===== Кнопки ===== */
.btn {
  font-family: inherit;
  font-weight: 800;
  border: none;
  border-radius: 18px;
  padding: 14px 22px;
  font-size: 18px;
  color: var(--white);
  background: linear-gradient(180deg, #7FB1FF, #4D78E6);
  box-shadow: 0 5px 0 #33549f, 0 10px 20px rgba(46,42,114,.25);
  cursor: pointer;
  transition: transform .12s, box-shadow .12s;
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 54px;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #33549f, 0 4px 8px rgba(46,42,114,.25); }
.btn.big { font-size: 22px; padding: 18px 30px; border-radius: 22px; }
.btn.green { background: linear-gradient(180deg, #6BE28B, #2FA85A); box-shadow: 0 5px 0 #1f7a40, 0 10px 20px rgba(46,42,114,.2); }
.btn.green:active { box-shadow: 0 2px 0 #1f7a40; }
.btn.orange { background: linear-gradient(180deg, #FFB26B, #F77F24); box-shadow: 0 5px 0 #c45f12, 0 10px 20px rgba(46,42,114,.2); }
.btn.orange:active { box-shadow: 0 2px 0 #c45f12; }
.btn.ghost { background: rgba(255,255,255,.85); color: var(--dark); box-shadow: 0 4px 0 rgba(46,42,114,.15); }
.btn.ghost:active { box-shadow: 0 2px 0 rgba(46,42,114,.15); }

/* ===== Экран «Домой» ===== */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 14px;
}
.icon-btn {
  position: relative;
  font-size: 24px; width: 54px; height: 54px;
  border-radius: 16px; border: 4px solid #fff;
  background: rgba(255,255,255,.85);
  box-shadow: 0 5px 0 rgba(46,42,114,.2), 0 8px 16px rgba(46,42,114,.15);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: transform .12s;
  overflow: hidden;
}
.icon-btn:active { transform: translateY(3px); }
.icon-btn.muted::after {
  content: "";
  position: absolute;
  left: -15%; right: -15%; top: 50%;
  height: 5px;
  background: #E5484D;
  border-radius: 999px;
  transform: translateY(-50%) rotate(-45deg);
  box-shadow: 0 0 0 2px #fff;
  pointer-events: none;
}
.icon-btn.neural { background: #E6FFF0; }
.toast {
  position: fixed;
  left: 50%; bottom: 24px;
  transform: translateX(-50%);
  background: rgba(46,42,114,.92);
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 15px;
  z-index: 120;
  box-shadow: 0 6px 18px rgba(0,0,0,.3);
  animation: screenIn .25s ease;
}

.total-stars {
  background: rgba(255,255,255,.9);
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 20px; font-weight: 800;
  color: var(--orange);
  box-shadow: 0 4px 0 rgba(46,42,114,.15);
  display: inline-flex; align-items: center; gap: 6px;
}

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 18px; }
.card {
  position: relative;
  border-radius: 26px;
  padding: 22px 18px;
  color: #fff;
  text-align: center;
  cursor: pointer;
  border: 5px solid rgba(255,255,255,.85);
  box-shadow: 0 8px 0 rgba(46,42,114,.22), 0 14px 26px rgba(46,42,114,.25);
  transition: transform .15s, box-shadow .15s;
  min-height: 170px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
}
.card:hover { transform: translateY(-4px) rotate(-1deg); }
.card:active { transform: translateY(3px); box-shadow: 0 4px 0 rgba(46,42,114,.22); }
.card .card-icon { font-size: 56px; filter: drop-shadow(0 4px 4px rgba(0,0,0,.2)); }
.card .card-title { font-size: 21px; font-weight: 800; text-shadow: 0 2px 0 rgba(0,0,0,.18); }
.card .card-stars { font-size: 18px; letter-spacing: 3px; text-shadow: 0 1px 0 rgba(0,0,0,.2); }

/* ===== Экран категории ===== */
.mode-list { display: grid; grid-template-columns: 1fr; gap: 16px; }
.back-row { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.back-row .icon-btn { width: 48px; height: 48px; font-size: 20px; }
.back-row .mode-title { font-size: clamp(22px,4vw,32px); color: #fff; text-shadow: 0 3px 0 rgba(46,42,114,.3); }

.mode-card {
  background: rgba(255,255,255,.92);
  border-radius: 22px;
  padding: 18px 20px;
  display: flex; align-items: center; gap: 16px;
  cursor: pointer;
  border: 4px solid #fff;
  box-shadow: 0 6px 0 rgba(46,42,114,.18), 0 10px 20px rgba(46,42,114,.15);
  transition: transform .13s, box-shadow .13s;
}
.mode-card:hover { transform: translateY(-3px); }
.mode-card:active { transform: translateY(2px); box-shadow: 0 3px 0 rgba(46,42,114,.18); }
.mode-card .mc-icon {
  width: 64px; height: 64px; flex: 0 0 64px;
  border-radius: 18px;
  display: flex; align-items: center; justify-content: center;
  font-size: 36px;
}
.mode-card .mc-info { flex: 1; }
.mode-card .mc-name { font-size: 21px; font-weight: 800; }
.mode-card .mc-sub { font-size: 14px; color: rgba(46,42,114,.6); font-weight: 700; }
.mode-card .mc-stars { font-size: 16px; letter-spacing: 2px; }

/* ===== Игра ===== */
.game-screen { padding: 14px; }
.game-top { display: flex; align-items: center; gap: 10px; width: 100%; max-width: 720px; }
.game-top .progress-dots { flex: 1; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: rgba(255,255,255,.6); box-shadow: inset 0 -2px 0 rgba(0,0,0,.12); transition: transform .2s; }
.dot.done { background: var(--green); transform: scale(1.15); }
.dot.current { background: var(--yellow); transform: scale(1.3); }
.dot.failed { background: var(--red); }

.quiz-card {
  background: rgba(255,255,255,.95);
  border-radius: 28px;
  border: 5px solid #fff;
  box-shadow: 0 8px 0 rgba(46,42,114,.2), 0 16px 30px rgba(46,42,114,.22);
  padding: 18px;
  width: 100%; max-width: 720px;
  margin-top: 14px;
  animation: screenIn .3s ease;
}
.question { text-align: center; font-size: clamp(20px,4vw,28px); font-weight: 800; margin-bottom: 6px; min-height: 42px; }
.sample { text-align: center; font-size: clamp(34px,8vw,60px); margin: 8px 0 12px; line-height: 1.2; }
.options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 10px;
}
.options.cols3 { grid-template-columns: repeat(3, 1fr); }
.option {
  position: relative;
  border-radius: 20px;
  border: 5px solid #fff;
  min-height: 118px;
  background: #F2F6FF;
  box-shadow: 0 5px 0 rgba(46,42,114,.18), 0 8px 16px rgba(46,42,114,.12);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(30px,7vw,48px);
  font-weight: 800;
  transition: transform .12s, box-shadow .12s;
  padding: 10px;
}
.option:hover { transform: translateY(-3px); }
.option:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(46,42,114,.18); }
.option .opt-inner { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; align-items: center; }
.option img, .sample img, .mem-card img, .opt-inner img {
  object-fit: contain;
  pointer-events: none;
  vertical-align: middle;
  background: #fff;
  border-radius: 14px;
  padding: 6px;
  box-sizing: border-box;
  box-shadow: 0 2px 6px rgba(46,42,114,.12);
}
.option img { width: 96px; height: 96px; }
.sample img { width: 150px; height: 150px; }
.mem-card img { width: 72px; height: 72px; }
.opt-inner img { width: 76px; height: 76px; }
.option .emg-fallback { font-size: 48px; }
.sample .emg-fallback { font-size: 64px; }
.mem-card .emg-fallback { font-size: 40px; }
.option.swatch { border-radius: 50%; width: clamp(84px,18vw,130px); height: clamp(84px,18vw,130px); min-height: 0; margin: 0 auto; }
.option.correct-anim { animation: correctPop .6s ease; border-color: var(--green) !important; background: rgba(75,203,106,.18) !important; }
.option.wrong-anim { animation: wrongShake .45s ease; border-color: var(--red) !important; background: rgba(255,107,107,.15) !important; }
.option.disabled { pointer-events: none; }
@keyframes correctPop { 0% { transform: scale(1);} 40% { transform: scale(1.18) rotate(4deg);} 100% { transform: scale(1);} }
@keyframes wrongShake { 0%,100%{transform:translateX(0);} 20%{transform:translateX(-10px);} 40%{transform:translateX(10px);} 60%{transform:translateX(-8px);} 80%{transform:translateX(8px);} }

/* память (пары) */
.memory-msg { text-align: center; font-size: 18px; font-weight: 700; color: rgba(46,42,114,.7); margin-top: 6px; min-height: 26px; }
.memory-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 12px; }
.mem-card {
  aspect-ratio: 1 / 1;
  border-radius: 18px;
  border: 4px solid #fff;
  background: linear-gradient(145deg, #7FB1FF, #4D78E6);
  box-shadow: 0 5px 0 rgba(46,42,114,.25), 0 8px 14px rgba(46,42,114,.15);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(32px,9vw,52px);
  transition: transform .2s;
  min-height: 96px;
}
.mem-card .back-emoji { font-size: clamp(24px,6vw,36px); opacity: .9; }
.mem-card.flipped { background: #fff; }
.mem-card.matched { background: rgba(75,203,106,.25); cursor: default; }
.mem-card:active { transform: scale(.95); }
.attempts { text-align: center; font-size: 15px; font-weight: 700; color: rgba(46,42,114,.6); margin-top: 8px; }

/* ===== Оверлей результата ===== */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(46,42,114,.45);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: screenIn .25s ease;
}
.result-box {
  background: linear-gradient(180deg, #fff, #F0F5FF);
  border-radius: 32px;
  border: 6px solid #fff;
  box-shadow: 0 12px 0 rgba(46,42,114,.25), 0 30px 60px rgba(46,42,114,.4);
  padding: 28px 26px;
  text-align: center;
  max-width: 420px; width: 100%;
}
.result-box .r-emoji { font-size: 64px; animation: bounce .8s ease infinite; }
@keyframes bounce { 0%,100%{transform:translateY(0);} 50%{transform:translateY(-10px);} }
.result-box .r-title { font-size: 28px; font-weight: 800; margin: 6px 0 4px; }
.result-box .r-text { font-size: 17px; color: rgba(46,42,114,.75); font-weight: 700; }
.result-stars { display: flex; justify-content: center; gap: 8px; margin: 10px 0 16px; font-size: 48px; }
.result-stars .star { opacity: .25; transform: scale(.8); }
.result-stars .star.earned { opacity: 1; animation: starPop .5s ease backwards; transform: scale(1); }
@keyframes starPop { from { transform: scale(0) rotate(-30deg); } 70% { transform: scale(1.3) rotate(10deg); } to { transform: scale(1); } }
.result-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ===== Родительский экран ===== */
.parent-card {
  background: rgba(255,255,255,.94);
  border-radius: 24px;
  border: 4px solid #fff;
  box-shadow: 0 6px 0 rgba(46,42,114,.18), 0 12px 24px rgba(46,42,114,.15);
  padding: 18px;
  margin-bottom: 16px;
}
.parent-card h3 { font-size: 20px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.stats-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.stats-table th, .stats-table td { text-align: left; padding: 8px 6px; border-bottom: 2px dashed rgba(46,42,114,.12); }
.stats-table th { font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: rgba(46,42,114,.6); }
.stats-table td.stars-td { letter-spacing: 2px; color: var(--orange); white-space: nowrap; }
.reset-note { font-size: 13px; color: rgba(46,42,114,.6); margin: 10px 0 4px; font-weight: 700; }
.voice-list { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 8px; }
.voice-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 3px solid rgba(46,42,114,.15);
  background: #F5F8FF;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .1s;
  font-weight: 800;
}
.voice-opt:hover { border-color: var(--c1); transform: translateY(-1px); }
.voice-opt.sel { border-color: var(--green); background: rgba(75,203,106,.14); }
.voice-opt input { display: none; }
.voice-emoji { font-size: 28px; }
.voice-name { font-size: 17px; flex: 1; }
.voice-dir { font-size: 13px; color: rgba(46,42,114,.55); font-weight: 700; }
.attr-details { margin-top: 8px; }
.attr-details summary {
  cursor: pointer;
  font-weight: 800;
  color: var(--c1);
  padding: 8px 12px;
  background: #EEF3FF;
  border-radius: 12px;
  display: inline-block;
}
.attr-list {
  margin-top: 8px;
  max-height: 260px;
  overflow-y: auto;
  border: 2px dashed rgba(46,42,114,.15);
  border-radius: 12px;
  padding: 8px 10px;
}
.attr-row {
  font-size: 13px;
  padding: 5px 0;
  border-bottom: 1px dashed rgba(46,42,114,.12);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.attr-row:last-child { border-bottom: none; }
.attr-file { font-weight: 800; color: rgba(46,42,114,.85); }
.attr-meta a { color: var(--c1); text-decoration: none; font-weight: 700; }

/* ===== Адаптивность ===== */
@media (min-width: 700px) {
  .options { grid-template-columns: repeat(4, 1fr); }
  .options.cols3 { grid-template-columns: repeat(3, 1fr); }
  .memory-grid { grid-template-columns: repeat(3, 1fr); }
  .mode-list { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .cards { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .card { min-height: 140px; padding: 16px 10px; }
  .card .card-icon { font-size: 44px; }
  .card .card-title { font-size: 17px; }
  .screen { padding: 14px; }
  .quiz-card { padding: 14px; }
  .topbar { gap: 6px; }
  .icon-btn { width: 46px; height: 46px; font-size: 20px; border-width: 3px; }
  .total-stars { padding: 6px 12px; font-size: 17px; }
}
@media (max-height: 640px) {
  .option { min-height: 72px; }
}
