/* ========================================================
   Совёнок v2 — Design Tokens & Base Styles
   ======================================================== */

/* --- Reset --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

*:focus {
  outline: none;
}

/* --- Design Tokens --- */
:root {
  --base-size: calc(1vmin * 1);

  --color-bg:       #FFF8E1;
  --color-surface:  #FFFFFF;
  --color-primary:  #FF9800;
  --color-primary-light: #FFE0B2;
  --color-secondary: #7C4DFF;
  --color-secondary-light: #D1C4E9;
  --color-success:  #4CAF50;
  --color-success-light: #C8E6C9;
  --color-error:    #F44336;
  --color-error-light: #FFCDD2;
  --color-warning:  #FFC107;
  --color-text:     #3E2723;
  --color-text-light: #8D6E63;
  --color-shadow:   rgba(62, 39, 35, 0.12);

  --color-age3: #FFE0B2;
  --color-age4: #C8E6C9;
  --color-age5: #BBDEFB;

  --radius:       1.5rem;
  --radius-small: 0.75rem;
  --radius-round: 50%;

  --gap:     1.25rem;
  --gap-lg:  2rem;
  --padding: 1.25rem;

  --font-family: "SF Pro Rounded", "Nunito", "Comfortaa", system-ui, -apple-system, sans-serif;
  --font-size-xs:    clamp(0.75rem,  2vmin, 0.875rem);
  --font-size-sm:    clamp(0.875rem, 2.5vmin, 1rem);
  --font-size-base:  clamp(1rem,     3vmin, 1.25rem);
  --font-size-lg:    clamp(1.25rem,  4vmin, 1.5rem);
  --font-size-xl:    clamp(1.5rem,   5vmin, 2rem);
  --font-size-2xl:   clamp(2rem,     7vmin, 3rem);
  --font-size-hero:  clamp(3rem,    10vmin, 5rem);

  --transition-fast:   150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow:   400ms ease-out;
}

/* --- Body & App --- */
html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  color: var(--color-text);
  background: var(--color-bg);
  display: flex;
  justify-content: center;
  align-items: center;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  -webkit-font-smoothing: antialiased;
}

#app {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  overflow: hidden;
}

/* --- Screen --- */
.screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
  padding: var(--padding);
  gap: var(--gap);
  animation: fadeIn var(--transition-slow) both;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* --- Typography --- */
.subtitle {
  font-size: var(--font-size-lg);
  font-weight: 500;
  color: var(--color-text-light);
  text-align: center;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 60px;
  min-height: 60px;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  font-weight: 700;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition:
    transform var(--transition-fast),
    box-shadow var(--transition-fast),
    background-color var(--transition-normal);
  -webkit-tap-highlight-color: transparent;
}

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

.btn-play {
  background: var(--color-success);
  color: #FFFFFF;
  min-width: 200px;
  padding: 1rem 2.5rem;
  font-size: var(--font-size-lg);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(76, 175, 80, 0.35), 0 2px 4px var(--color-shadow);
}

.btn-play:active {
  background: #43A047;
}

.btn-back {
  width: 52px;
  height: 52px;
  min-width: 52px;
  min-height: 52px;
  padding: 0;
  border-radius: var(--radius-round);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--font-size-lg);
  box-shadow: 0 2px 8px var(--color-shadow);
}

.btn-back:active {
  background: #F5F5F5;
}

.btn-small {
  min-width: 44px;
  min-height: 44px;
  padding: 0.5rem 1rem;
  font-size: var(--font-size-sm);
  border-radius: var(--radius-small);
}

.btn-mute {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.8rem;
  cursor: pointer;
  padding: 0.5rem;
  opacity: 0.6;
  transition: opacity var(--transition-normal);
  z-index: 10;
  min-width: auto;
  min-height: auto;
}

.btn-mute:active {
  opacity: 1;
}

.btn-reset {
  background: none;
  border: none;
  font-family: var(--font-family);
  font-size: var(--font-size-xs);
  color: var(--color-text-light);
  opacity: 0.5;
  cursor: pointer;
  padding: 0.5rem 1rem;
  margin-top: auto;
  min-width: auto;
  min-height: auto;
}

.btn-reset:active {
  opacity: 1;
}

/* --- Stars --- */
.stars-count {
  font-size: var(--font-size-lg);
  font-weight: 700;
  white-space: nowrap;
}

/* ========================================================
   Animations
   ======================================================== */

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes bounce {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.2); }
  100% { transform: scale(1); }
}

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

@keyframes flash-green {
  0%   { background-color: inherit; }
  50%  { background-color: var(--color-success-light); }
  100% { background-color: inherit; }
}

@keyframes pop-in {
  0%   { transform: scale(0); }
  70%  { transform: scale(1.1); }
  100% { transform: scale(1); }
}

@keyframes pulse {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.05); }
  100% { transform: scale(1); }
}

@keyframes slide-down {
  from { opacity: 0; transform: translateY(-20px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes zoom-bounce {
  0%   { opacity: 0; transform: scale(0); }
  70%  { transform: scale(1.15); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes celebrate {
  0%   { transform: scale(1) rotate(0deg); }
  25%  { transform: scale(1.15) rotate(-5deg); }
  50%  { transform: scale(1.1) rotate(5deg); }
  75%  { transform: scale(1.15) rotate(-3deg); }
  100% { transform: scale(1) rotate(0deg); }
}

@keyframes slide-up {
  from { opacity: 0; transform: translateY(40px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes star-pop {
  0%   { opacity: 0; transform: scale(0) rotate(-30deg); }
  60%  { transform: scale(1.3) rotate(10deg); }
  100% { opacity: 1; transform: scale(1) rotate(0deg); }
}

@keyframes progress-glow {
  0%, 100% { box-shadow: none; }
  50%      { box-shadow: 0 0 8px var(--color-primary), inset 0 0 4px var(--color-primary); }
}

@keyframes fade-slide-in {
  from { opacity: 0; transform: translateX(-15px); }
  to   { opacity: 1; transform: translateX(0); }
}

.bounce { animation: bounce 0.4s ease; }
.shake { animation: shake 0.4s ease; }
.pop-in { animation: pop-in 0.35s ease-out both; }

/* ========================================================
   Home Screen — Age Group Selection
   ======================================================== */

.home {
  gap: var(--gap-lg);
  justify-content: center;
}

.home-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.home-header h1 {
  font-size: var(--font-size-2xl);
  font-weight: 800;
  color: var(--color-primary);
}

.owl-big {
  font-size: clamp(4rem, 12vmin, 6rem);
  line-height: 1;
  animation: bounce 0.6s ease both;
}

.age-groups {
  display: flex;
  flex-direction: row;
  gap: var(--gap);
  justify-content: center;
  flex-wrap: wrap;
  max-width: 500px;
  padding: 0 var(--padding);
}

.age-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 130px;
  min-height: 140px;
  padding: var(--padding);
  gap: 0.4rem;
  background: linear-gradient(to bottom, var(--card-color, #fff), var(--color-surface));
  border: 3px solid var(--card-color, #ddd);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px var(--color-shadow);
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  animation: pop-in 0.35s ease-out both;
}

.age-card:nth-child(1) { animation-delay: 0s; }
.age-card:nth-child(2) { animation-delay: 0.1s; }
.age-card:nth-child(3) { animation-delay: 0.2s; }

.age-card:active {
  transform: scale(0.95);
}

.age-icon {
  font-size: var(--font-size-2xl);
  line-height: 1;
}

.age-title {
  font-size: var(--font-size-base);
  font-weight: 700;
  color: var(--color-text);
}

.age-subtitle {
  font-size: var(--font-size-xs);
  color: var(--color-text-light);
  text-align: center;
}

.age-stars {
  font-size: var(--font-size-xs);
  color: var(--color-warning);
  font-weight: 600;
}

/* ========================================================
   Subjects Screen — Subject Grid
   ======================================================== */

.subjects {
  justify-content: flex-start;
  padding-top: var(--padding);
}

.screen-header {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 0;
  gap: var(--gap);
  flex-shrink: 0;
}

.screen-header h2 {
  font-size: var(--font-size-lg);
  font-weight: 700;
  flex: 1;
  text-align: center;
}

.screen-subtitle {
  font-size: var(--font-size-sm);
  color: var(--color-text-light);
  text-align: center;
  flex-shrink: 0;
}

.subject-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--gap);
  width: 100%;
  max-width: 500px;
  padding: var(--gap) 0;
}

.subject-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  padding: 1.25rem 0.75rem;
  gap: 0.4rem;
  background: linear-gradient(to bottom,
    color-mix(in srgb, var(--card-color, #ddd) 20%, var(--color-surface)),
    var(--color-surface));
  border-top: 4px solid var(--card-color, #ddd);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px var(--color-shadow);
  cursor: pointer;
  transition: transform var(--transition-fast);
  animation: pop-in 0.35s ease-out both;
}

.subject-card:nth-child(1) { animation-delay: 0s; }
.subject-card:nth-child(2) { animation-delay: 0.06s; }
.subject-card:nth-child(3) { animation-delay: 0.12s; }
.subject-card:nth-child(4) { animation-delay: 0.18s; }
.subject-card:nth-child(5) { animation-delay: 0.24s; }
.subject-card:nth-child(6) { animation-delay: 0.30s; }

.subject-card:active {
  transform: scale(0.95);
}

.subject-icon {
  font-size: var(--font-size-2xl);
  line-height: 1;
}

.subject-title {
  font-size: var(--font-size-base);
  font-weight: 700;
  color: var(--color-text);
  text-align: center;
}

.subject-progress {
  font-size: var(--font-size-xs);
  color: var(--color-text-light);
}

.subject-stars {
  font-size: var(--font-size-xs);
  color: var(--color-warning);
  font-weight: 600;
}

/* ========================================================
   Topics Screen — Topic List
   ======================================================== */

.topics {
  justify-content: flex-start;
  padding-top: var(--padding);
}

.topics-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
  max-width: 500px;
  padding: var(--gap) 0;
}

.topic-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  min-height: 60px;
  padding: 0.75rem 1rem;
  background: var(--color-surface);
  border: 2px solid transparent;
  border-radius: var(--radius-small);
  box-shadow: 0 2px 8px var(--color-shadow);
  cursor: pointer;
  transition: transform var(--transition-fast), background var(--transition-normal);
  text-align: left;
  -webkit-appearance: none;
  appearance: none;
  animation: fade-slide-in 0.35s ease-out both;
}

.topic-item:nth-child(1)  { animation-delay: 0s; }
.topic-item:nth-child(2)  { animation-delay: 0.04s; }
.topic-item:nth-child(3)  { animation-delay: 0.08s; }
.topic-item:nth-child(4)  { animation-delay: 0.12s; }
.topic-item:nth-child(5)  { animation-delay: 0.16s; }
.topic-item:nth-child(6)  { animation-delay: 0.20s; }
.topic-item:nth-child(7)  { animation-delay: 0.24s; }
.topic-item:nth-child(8)  { animation-delay: 0.28s; }
.topic-item:nth-child(9)  { animation-delay: 0.32s; }
.topic-item:nth-child(10) { animation-delay: 0.36s; }

.topic-item:active {
  transform: scale(0.98);
}

.topic-item.done {
  background: var(--color-success-light);
  border-color: var(--color-success);
}

.topic-item.locked {
  opacity: 0.4;
  cursor: not-allowed;
}

.topic-item.locked:active {
  transform: none;
}

.topic-num {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-round);
  background: var(--color-primary-light);
  color: var(--color-text);
  font-size: var(--font-size-sm);
  font-weight: 700;
  flex-shrink: 0;
}

.topic-item.done .topic-num {
  background: var(--color-success);
  color: white;
}

.topic-info {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  flex: 1;
  min-width: 0;
}

.topic-title {
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--color-text);
}

.topic-progress {
  font-size: var(--font-size-xs);
  color: var(--color-text-light);
}

.topic-status {
  font-size: var(--font-size-sm);
  flex-shrink: 0;
}

/* ========================================================
   Play Screen & Game Engine
   ======================================================== */

.play {
  position: relative;
  justify-content: flex-start;
  padding-top: var(--padding);
  overflow: hidden;
}

.play-header {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  gap: 0.75rem;
  flex-shrink: 0;
}

.progress-bar {
  flex: 1;
  height: 12px;
  background: var(--color-primary-light);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

.progress-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: 6px;
  transition: width 400ms ease;
}

.progress-fill.updated {
  animation: progress-glow 0.6s ease-out;
}

.progress-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--color-text);
}

#game-area {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  flex: 1;
}

/* --- Game Container --- */
.game {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--gap-lg);
  padding: var(--padding);
  width: 100%;
}

.game-question {
  font-size: var(--font-size-xl);
  font-weight: 700;
  text-align: center;
  color: var(--color-text);
  animation: slide-down 0.3s ease-out both;
}

.game-image {
  font-size: clamp(3rem, 10vmin, 5rem);
  line-height: 1;
  text-align: center;
  animation: zoom-bounce 0.4s ease-out 0.1s both;
}

.game-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--gap);
  width: 100%;
  max-width: 400px;
}

/* --- Option Buttons --- */
.btn-option {
  min-height: 70px;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: var(--color-surface);
  border: 2px solid var(--color-primary-light);
  font-family: var(--font-family);
  font-size: clamp(2.2rem, 7vmin, 3rem);
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
  transition:
    transform var(--transition-fast),
    background-color var(--transition-normal),
    border-color var(--transition-normal);
  box-shadow: 0 2px 8px var(--color-shadow);
}

.btn-option:active { transform: scale(0.95); }
.btn-option.correct {
  background: var(--color-success);
  border-color: var(--color-success);
  color: #FFFFFF;
  animation: flash-green 0.6s ease;
}
.btn-option.wrong {
  background: var(--color-error);
  border-color: var(--color-error);
  color: #FFFFFF;
  animation: shake 0.4s ease;
}
.btn-option:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.btn-option:disabled:active { transform: none; }
.btn-option.correct, .btn-option.wrong { opacity: 1; }

.game-options.compact {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 100%;
}
.game-options.compact .btn-option {
  aspect-ratio: 1;
  width: 70px;
  min-height: unset;
  padding: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- Sequence Game --- */
.sequence-selected {
  display: flex;
  flex-direction: row;
  gap: 0.75rem;
  justify-content: center;
  align-items: center;
  margin-bottom: 1rem;
}

.seq-item {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-small);
  border: 2px solid;
  font-size: 2.2rem;
  font-weight: bold;
}

.seq-item.done {
  background: var(--color-primary-light);
  border-color: var(--color-primary);
}

.seq-item.empty {
  background: #F5F5F5;
  border-color: #E0E0E0;
  border-style: dashed;
  color: #BDBDBD;
  transition: border-color var(--transition-fast), background-color var(--transition-fast), transform var(--transition-fast);
  position: relative;
}
.seq-item.empty::after {
  content: '';
  position: absolute;
  inset: -12px;
}

/* --- Match Game --- */
.match-area {
  position: relative;
  width: 100%;
  max-width: 500px;
}

.match-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.match-line { stroke-width: 3; stroke-linecap: round; }
.matched-line { stroke: var(--color-success); opacity: 0.7; }
.drag-line { stroke: var(--color-primary); stroke-dasharray: 8 4; opacity: 0.8; }

.match-columns {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: row;
  gap: 2rem;
  justify-content: center;
  align-items: flex-start;
  width: 100%;
}

.match-col {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.match-item {
  min-width: 80px;
  min-height: 60px;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-small);
  border: 2px solid var(--color-primary-light);
  background: var(--color-surface);
  font-size: clamp(2.2rem, 7vmin, 3rem);
  font-weight: 600;
  text-align: center;
  color: var(--color-text);
  cursor: pointer;
  transition: transform var(--transition-fast), border-color var(--transition-normal), background-color var(--transition-normal);
  box-shadow: 0 2px 8px var(--color-shadow);
}

.match-item:active { transform: scale(0.95); }
.match-item.selected {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  transform: scale(1.05);
  box-shadow: 0 3px 12px rgba(255, 152, 0, 0.3);
}
.match-item.matched {
  border-color: var(--color-success);
  background: rgba(76, 175, 80, 0.15);
  color: var(--color-success);
  cursor: default;
  opacity: 0.85;
}
.match-item.matched:active { transform: none; }
.match-item.wrong {
  border-color: var(--color-error);
  background: var(--color-error-light);
  animation: shake 0.4s ease;
}

/* --- Drag & Drop Game --- */
.drop-slots {
  display: flex;
  flex-direction: row;
  gap: 0.75rem;
  justify-content: center;
  margin-bottom: 1.5rem;
}

.drop-slot {
  width: 60px;
  height: 60px;
  border: 2px dashed var(--color-primary);
  border-radius: var(--radius-small);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  font-weight: bold;
  background: var(--color-surface);
  cursor: pointer;
  transition: background-color var(--transition-normal), border-color var(--transition-normal), transform var(--transition-fast);
}

.drop-slot.filled {
  border-style: solid;
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  animation: pop-in 0.25s ease-out both;
}

.drag-items {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
}

.drag-item {
  width: 60px;
  height: 60px;
  border-radius: var(--radius-small);
  border: 2px solid var(--color-primary-light);
  font-size: 2.2rem;
  font-weight: bold;
  background: var(--color-surface);
  cursor: pointer;
  transition: transform var(--transition-fast), opacity var(--transition-normal);
}

.drag-item.selected {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  transform: scale(1.1);
}

.drag-item.used,
.drag-item:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}

/* Drag hover & clone */
.drop-hover,
.seq-item.empty.drop-hover,
.drop-slot.drop-hover,
.work-cell.drop-hover {
  border-color: var(--color-primary) !important;
  background: var(--color-primary-light) !important;
  transform: scale(1.1);
}

.drag-clone {
  border-radius: var(--radius-small);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3), 0 0 12px rgba(255,152,0,0.2);
  will-change: transform;
}

.dragging {
  opacity: 0.4 !important;
}

.drag-source.used {
  opacity: 0.3;
}

/* --- Feedback Overlay --- */
.feedback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.85);
  border-radius: var(--radius);
  animation: pop-in 0.35s ease-out both;
  z-index: 20;
  font-size: var(--font-size-xl);
  font-weight: 700;
}

.feedback.correct {
  background: rgba(200, 230, 201, 0.9);
  color: var(--color-success);
}

.feedback.correct .owl-big {
  animation: celebrate 0.8s ease-out;
}

.feedback.wrong {
  background: rgba(255, 205, 210, 0.9);
  color: var(--color-error);
}

.feedback.wrong .owl-big {
  animation: shake 0.5s ease;
}

/* --- Completion Screen --- */
.complete {
  gap: var(--gap-lg);
  text-align: center;
  justify-content: center;
}

.complete .owl-big {
  animation: celebrate 0.8s ease-out both;
}

.complete h1 {
  font-size: var(--font-size-2xl);
  font-weight: 800;
  color: var(--color-primary);
  animation: slide-up 0.4s ease-out 0.2s both;
}

.complete p {
  font-size: var(--font-size-lg);
  color: var(--color-text-light);
  animation: slide-up 0.4s ease-out 0.35s both;
}

.complete .stars-count {
  font-size: var(--font-size-xl);
  color: var(--color-warning);
  animation: star-pop 0.5s ease-out 0.5s both;
}

.complete .btn-play {
  animation: slide-up 0.4s ease-out 0.6s both;
}

/* --- Count Game --- */
.count-scene {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  align-items: center;
  max-width: 400px;
}

.count-item {
  font-size: clamp(2rem, 8vmin, 3.5rem);
  line-height: 1;
}

.count-tappable {
  font-size: clamp(2rem, 8vmin, 3.5rem);
  line-height: 1;
  padding: 0.5rem;
  border: 3px solid transparent;
  border-radius: var(--radius-small);
  background: var(--color-surface);
  cursor: pointer;
  transition: transform var(--transition-fast), border-color var(--transition-normal), background-color var(--transition-normal);
  box-shadow: 0 2px 8px var(--color-shadow);
}

.count-tappable:active { transform: scale(0.9); }

.count-tappable.count-tapped {
  border-color: var(--color-success);
  background: var(--color-success-light);
  cursor: default;
}

.count-tappable:disabled:not(.count-tapped) {
  opacity: 0.5;
  cursor: default;
}

.count-counter {
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--color-primary);
}

/* --- Classify Game --- */
.classify-baskets {
  display: flex;
  flex-direction: row;
  gap: var(--gap);
  justify-content: center;
  width: 100%;
  max-width: 400px;
}

.classify-basket {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  min-height: 100px;
  padding: 0.75rem;
  border: 2px dashed var(--color-primary);
  border-radius: var(--radius);
  background: var(--color-surface);
  cursor: pointer;
  transition: background-color var(--transition-normal), border-color var(--transition-normal);
}

.basket-label {
  font-size: clamp(1.5rem, 6vmin, 2.5rem);
  line-height: 1;
}

.basket-items {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  justify-content: center;
}

.basket-item {
  font-size: 2.2rem;
  animation: pop-in 0.25s ease-out both;
}

.classify-pool {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  max-width: 400px;
}

.classify-item {
  width: 60px;
  height: 60px;
  border-radius: var(--radius-small);
  border: 2px solid var(--color-primary-light);
  font-size: 2.2rem;
  background: var(--color-surface);
  cursor: pointer;
  transition: transform var(--transition-fast), opacity var(--transition-normal);
  box-shadow: 0 2px 8px var(--color-shadow);
}

.classify-item.selected {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  transform: scale(1.1);
}

.classify-item.used,
.classify-item:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}

/* --- Maze Game --- */
.maze-grid {
  display: grid;
  width: fit-content;
  margin: 0 auto;
}

.maze-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface);
  cursor: pointer;
  transition: background-color var(--transition-fast);
  position: relative;
}

.maze-cell.maze-visited {
  background: var(--color-primary-light);
}

.maze-cell.maze-current {
  background: var(--color-primary-light);
}

.maze-cell.maze-end {
  background: var(--color-success-light);
}

.maze-player, .maze-target {
  font-size: 1.5rem;
  line-height: 1;
  animation: pop-in 0.25s ease-out both;
}

/* --- Trace Game --- */
.trace-container {
  position: relative;
  width: 300px;
  height: 300px;
  border: 2px solid #E0E0E0;
  border-radius: var(--radius-small);
  background: #fff;
  touch-action: none;
}

.trace-template, .trace-user {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.trace-template {
  z-index: 1;
  pointer-events: none;
}

.trace-user {
  z-index: 2;
}

.trace-controls {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.trace-clear, .trace-check {
  font-size: 1.5rem;
  background: var(--color-surface);
  border: 2px solid var(--color-primary-light);
  box-shadow: 0 2px 8px var(--color-shadow);
}

/* --- Missing Game --- */
.missing-scene {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  align-items: center;
  max-width: 400px;
}

.missing-item {
  font-size: clamp(2.5rem, 9vmin, 4rem);
  line-height: 1;
  transition: transform var(--transition-normal), opacity var(--transition-normal);
}

.missing-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(3rem, 10vmin, 4.5rem);
  height: clamp(3rem, 10vmin, 4.5rem);
  border: 3px dashed var(--color-primary);
  border-radius: var(--radius-small);
  background: var(--color-primary-light);
  font-size: clamp(2rem, 7vmin, 3rem);
  animation: pulse 1.5s ease infinite;
}

.missing-revealed {
  animation: pop-in 0.35s ease-out both;
}

/* --- Mirror Game --- */
.mirror-original {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.mirror-pattern {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: var(--color-surface);
  border: 2px solid var(--color-secondary-light);
  border-radius: var(--radius);
  box-shadow: 0 2px 8px var(--color-shadow);
}

.mirror-item {
  font-size: clamp(2.2rem, 8vmin, 3.5rem);
  line-height: 1;
}

.mirror-divider {
  font-size: var(--font-size-2xl);
  line-height: 1;
}

.mirror-option {
  letter-spacing: 0.15em;
}

/* --- Tangram Game --- */
.tangram-layout {
  display: flex;
  flex-direction: row;
  gap: var(--gap-lg);
  justify-content: center;
  align-items: flex-start;
  width: 100%;
  max-width: 500px;
}

.tangram-target-wrap,
.tangram-work-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.tangram-label {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text-light);
}

.tangram-grid {
  display: grid;
  gap: 4px;
  width: fit-content;
}

.tangram-cell {
  width: clamp(40px, 12vmin, 56px);
  height: clamp(40px, 12vmin, 56px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.8rem, 7vmin, 2.5rem);
  border-radius: var(--radius-small);
  transition: background-color var(--transition-normal), border-color var(--transition-normal);
}

.target-cell {
  background: var(--color-surface);
  border: 2px solid #E0E0E0;
}

.work-cell.active {
  background: var(--color-surface);
  border: 2px dashed var(--color-primary);
  cursor: pointer;
}

.work-cell.active.filled {
  border-style: solid;
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  animation: pop-in 0.25s ease-out both;
}

.work-cell.empty-target {
  background: transparent;
  border: 2px solid transparent;
}

.tangram-pieces {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  max-width: 400px;
}

.tangram-piece {
  width: 56px;
  height: 56px;
  font-size: 2rem;
}

/* ========================================================
   Puzzles & Gallery
   ======================================================== */

/* Puzzle preview in play header */
.puzzle-preview {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  border-radius: var(--radius-small);
  overflow: hidden;
  background: var(--color-surface);
  box-shadow: 0 2px 8px var(--color-shadow);
  cursor: pointer;
}

.puzzle-svg-wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.puzzle-svg-wrapper svg {
  display: block;
}

/* Puzzle piece states */
.puzzle-piece-hidden {
  opacity: 0.08;
  filter: grayscale(1);
  transition: opacity 0.3s ease, filter 0.3s ease;
}

.puzzle-piece-revealed {
  opacity: 1;
  filter: none;
  transition: opacity 0.3s ease, filter 0.3s ease;
}

@keyframes puzzle-pop {
  0%   { opacity: 0; transform: scale(0.5) rotate(-10deg); }
  70%  { transform: scale(1.1) rotate(3deg); }
  100% { opacity: 1; transform: scale(1) rotate(0deg); }
}

/* Completion puzzle */
.puzzle-complete {
  animation: zoom-bounce 0.6s ease-out both;
}

/* Gallery screen */
.gallery {
  justify-content: flex-start;
  padding-top: var(--padding);
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  width: 100%;
  max-width: 500px;
  padding: var(--gap) 0;
}

.gallery-item {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 0.5rem;
  border-radius: var(--radius);
  background: var(--color-surface);
  border: 2px solid transparent;
  box-shadow: 0 2px 8px var(--color-shadow);
  min-width: auto;
  min-height: auto;
}

.gallery-item.complete {
  border-color: var(--color-success);
  background: var(--color-success-light);
}

.gallery-item.partial {
  border-color: var(--color-primary-light);
}

.gallery-item.locked {
  opacity: 0.4;
}

.gallery-preview {
  width: 100%;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.gallery-preview svg {
  width: 100% !important;
  height: 100% !important;
}

.gallery-label {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--color-text-light);
}

/* Puzzle modal */
.puzzle-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s ease both;
}

.puzzle-modal-content {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: var(--padding);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  animation: pop-in 0.35s ease-out both;
  max-width: 90vw;
}

.puzzle-modal-title {
  font-size: var(--font-size-lg);
  font-weight: 700;
  color: var(--color-text);
}

.puzzle-modal-progress {
  font-size: var(--font-size-sm);
  color: var(--color-text-light);
}

/* Home gallery buttons */
.home-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
}

.btn-gallery {
  background: var(--color-secondary-light);
  color: var(--color-text);
  padding: 0.5rem 1.5rem;
  font-size: var(--font-size-sm);
  border-radius: var(--radius);
  min-width: auto;
  min-height: 44px;
}

/* ========================================================
   Responsive
   ======================================================== */

@media (min-width: 600px) {
  :root {
    --gap:     1.75rem;
    --gap-lg:  2.5rem;
    --padding: 2rem;
  }

  .subject-grid {
    grid-template-columns: repeat(3, 1fr);
    max-width: 600px;
  }

  .game-options {
    max-width: 500px;
  }

  .btn-option {
    min-height: 80px;
    font-size: 3rem;
  }

  .game-options.compact .btn-option {
    width: 80px;
    min-height: unset;
  }

  .age-card {
    width: 150px;
    min-height: 160px;
  }

  .classify-baskets {
    max-width: 500px;
  }

  .classify-pool {
    max-width: 500px;
  }

  .count-scene {
    max-width: 500px;
  }
}

/* ── Auth / Purchase modals ─────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1.5rem;
  backdrop-filter: blur(2px);
}
.modal-overlay[hidden] { display: none; }

.modal-box {
  background: var(--surface, #fff);
  border-radius: 1.5rem;
  padding: 2rem 1.75rem;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}
.modal-icon { font-size: 2.5rem; margin-bottom: 0.5rem; }
.modal-box h2 { margin: 0 0 0.4rem; font-size: 1.3rem; }
.modal-box p  { color: var(--text-secondary, #666); margin: 0 0 1rem; font-size: 0.95rem; line-height: 1.4; }

.modal-box input[type="email"] {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid var(--border, #e0e0e0);
  border-radius: 0.75rem;
  font-size: 1rem;
  margin-bottom: 0.75rem;
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.15s;
}
.modal-box input[type="email"]:focus { border-color: var(--accent, #FF9800); }

.btn-primary {
  width: 100%;
  padding: 0.85rem;
  background: var(--accent, #FF9800);
  color: #fff;
  border: none;
  border-radius: 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.auth-status {
  min-height: 1.4em;
  font-size: 0.875rem;
  color: var(--text-secondary, #666);
  margin: 0.5rem 0;
}

.btn-ghost {
  background: none;
  border: none;
  color: var(--text-secondary, #999);
  font-size: 0.875rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  margin-top: 0.25rem;
  text-decoration: underline;
}

/* ── Purchase modal ─────────────────────────────────────────── */
.purchase-features {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
  text-align: left;
  font-size: 0.95rem;
  line-height: 2;
}
.purchase-price {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--accent, #FF9800);
  margin: 0.25rem 0;
}
.purchase-note {
  font-size: 0.8rem;
  color: var(--text-secondary, #999);
  margin: 0 0 1rem;
}

/* Lock style for paywalled topics */
.topic-item.locked {
  opacity: 0.65;
}
.topic-locked-hint {
  color: var(--accent, #FF9800);
  font-size: 0.8rem;
}

/* ── App footer ─────────────────────────────────────────────── */
.app-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  padding: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-secondary, #999);
  background: transparent;
  pointer-events: none;
}
.app-footer a {
  color: var(--text-secondary, #999);
  text-decoration: none;
  pointer-events: all;
}
.app-footer a:hover {
  text-decoration: underline;
}
.app-footer span {
  margin: 0 0.4rem;
}
