/* ===== FORCE LIGHT MODE ===== */
/* The app is always light/warm — block Android Chrome's
   Auto Dark Theme from inverting colors and piece images. */
:root { color-scheme: only light; }

@media (prefers-color-scheme: dark) {
  :root { color-scheme: only light; }
  /* Board colors must never change */
  .chess-board .square.light { background-color: #F0D9B5 !important; }
  .chess-board .square.dark  { background-color: #B58863 !important; }
}

/* ===== CSS VARIABLES ===== */
:root {
  --yellow:          #FFD700;
  --yellow-dark:     #F0A500;
  --yellow-glow:     rgba(255,215,0,0.4);
  --bg-main:         #FFF8E7;
  --bg-card:         #FFFFFF;
  --bg-header:       #FFD700;
  --green:           #4CAF50;
  --green-light:     #A8E6A3;
  --blue:            #42A5F5;
  --orange:          #FF7043;
  --purple:          #AB47BC;
  --red:             #F44336;
  --text-dark:       #2C2C2C;
  --text-medium:     #555555;
  --text-light:      #888888;
  --square-light:    #F0D9B5;
  --square-dark:     #B58863;
  --highlight-move:  rgba(127,201,127,0.85);
  --highlight-sel:   rgba(255,215,0,0.9);
  --highlight-cap:   rgba(255,107,107,0.85);
  --radius-sm:       8px;
  --radius-md:       14px;
  --radius-lg:       22px;
  --shadow-yellow:   0 4px 18px rgba(255,215,0,0.35);
  --shadow-card:     0 4px 20px rgba(0,0,0,0.10);
  --transition:      0.2s ease;
  --board-size:      480px;   /* ages 8-12 default */
}

/* Age-group overrides */
.age-5-7 { --board-size: 540px; }
.age-8-12 { --board-size: 480px; }

/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Cairo', sans-serif;
  font-weight: 500;
  direction: rtl;
  background: var(--bg-main);
  color: var(--text-dark);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ===== KEYFRAMES ===== */
@keyframes pulse-dot {
  0%, 100% { transform: scale(1);   opacity: 0.85; }
  50%       { transform: scale(1.4); opacity: 1; }
}

@keyframes pulse-dot-big {
  0%, 100% { transform: scale(1);   opacity: 0.9; }
  50%       { transform: scale(1.6); opacity: 1; }
}

@keyframes piece-select-glow {
  0%, 100% { box-shadow: 0 0 0 3px rgba(255,215,0,0.7); }
  50%       { box-shadow: 0 0 0 6px rgba(255,215,0,1), 0 0 20px rgba(255,215,0,0.5); }
}

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

@keyframes star-float {
  0%   { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-80px) scale(2); }
}

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

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

@keyframes fade-out {
  from { opacity: 1; }
  to   { opacity: 0; }
}

@keyframes trophy-bounce {
  0%,100% { transform: translateY(0) rotate(0deg); }
  25%     { transform: translateY(-12px) rotate(-5deg); }
  75%     { transform: translateY(-8px) rotate(5deg); }
}

@keyframes btn-click { 0% { transform: scale(1); } 50% { transform: scale(0.93); } 100% { transform: scale(1); } }

/* ===== HEADER ===== */
.app-header {
  background: var(--bg-header);
  box-shadow: 0 3px 12px rgba(240,165,0,0.4);
  padding: 10px 16px 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mascot {
  font-size: 2.2rem;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.brand-text h1 {
  font-size: 1.3rem;
  font-weight: 900;
  color: var(--text-dark);
  line-height: 1.1;
}

.brand-sub {
  font-size: 0.85rem;
  font-weight: 500;
  color: #6b5900;
}

/* Age Toggle */
.age-toggle {
  display: flex;
  gap: 6px;
  background: rgba(255,255,255,0.35);
  padding: 4px;
  border-radius: 30px;
}

.age-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: 'Cairo', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  color: #5a4500;
  padding: 6px 14px;
  border-radius: 24px;
  transition: var(--transition);
  white-space: nowrap;
}

.age-btn.active {
  background: white;
  color: var(--text-dark);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.age-btn:not(.active):hover { background: rgba(255,255,255,0.5); }

/* Voice Toggle */
.voice-toggle-btn {
  background: rgba(255,255,255,0.35);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.4rem;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}

.voice-toggle-btn:hover  { background: rgba(255,255,255,0.6); transform: scale(1.1); }
.voice-toggle-btn.muted  { opacity: 0.55; filter: grayscale(1); }

/* Mode Tabs */
.mode-tabs {
  display: flex;
  gap: 4px;
  margin-top: 10px;
}

.mode-btn {
  flex: 1;
  background: rgba(255,255,255,0.3);
  border: none;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  cursor: pointer;
  font-family: 'Cairo', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: #5a4500;
  padding: 10px;
  transition: var(--transition);
}

.mode-btn.active {
  background: var(--bg-main);
  color: var(--text-dark);
}

.mode-btn:not(.active):hover { background: rgba(255,255,255,0.5); }

/* ===== MAIN ===== */
.app-main { padding: 20px 16px 40px; max-width: 1100px; margin: 0 auto; }

/* ===== MODE SECTIONS ===== */
.mode-section { display: none; }
.mode-section.active { display: block; }

body.mode-teach   #teach-mode   { display: block; }
body.mode-play    #play-mode    { display: block; }
body.mode-setup   #setup-mode   { display: block; }
body.mode-puzzles #puzzles-mode { display: block; }
body.mode-teach  #play-mode, body.mode-teach  #setup-mode, body.mode-teach  #puzzles-mode { display: none; }
body.mode-play   #teach-mode, body.mode-play  #setup-mode, body.mode-play   #puzzles-mode { display: none; }
body.mode-setup  #teach-mode, body.mode-setup #play-mode,  body.mode-setup  #puzzles-mode { display: none; }
body.mode-puzzles #teach-mode, body.mode-puzzles #play-mode, body.mode-puzzles #setup-mode { display: none; }

/* ═══════════════════════════════════════════════════
   PUZZLE LIBRARY & BOARD
═══════════════════════════════════════════════════ */

.puzzle-phase { display: none; flex-direction: column; align-items: center; padding: 8px 12px 24px; width: 100%; }
.puzzle-phase.active { display: flex; }

/* ── Library ── */
.puzzle-library-header { text-align: center; margin-bottom: 14px; }
.pz-lib-title { font-size: 1.5rem; font-weight: 900; color: var(--text-dark); margin: 0; }
.pz-lib-sub   { font-size: 0.9rem; color: var(--text-medium); margin: 4px 0 0; }

.puzzle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  width: 100%;
  max-width: 700px;
}

/* ── Category sections ── */
.pz-sections {
  display: flex;
  flex-direction: column;
  gap: 24px;
  width: 100%;
  max-width: 1000px;
}

.pz-section .puzzle-grid { max-width: none; }

.pz-section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  padding: 0 4px;
}

.pz-section-chip {
  font-size: 1rem;
  font-weight: 900;
  padding: 5px 16px;
  border-radius: 20px;
}

.pz-section-count {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-light);
}

.puzzle-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 16px 12px 14px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s;
  position: relative;
  text-align: center;
}

.puzzle-card:hover { transform: translateY(-3px); box-shadow: 0 8px 28px rgba(0,0,0,0.14); }
.puzzle-card.solved { border-color: var(--green); }
.puzzle-card.solved::after {
  content: '✓';
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: 1rem;
  color: var(--green);
  font-weight: 900;
}

.pz-card-emoji  { font-size: 2.4rem; line-height: 1; }
.pz-card-title  { font-size: 0.82rem; font-weight: 700; color: var(--text-dark); margin: 0; }
.pz-card-cat    { font-size: 0.7rem; font-weight: 700; padding: 3px 8px; border-radius: 20px; }
.pz-card-stars  { display: flex; gap: 2px; font-size: 0.75rem; }

/* ── Puzzle board view ── */
.pz-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 560px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.pz-back-btn {
  background: #f0f0f0;
  border: 2px solid #ddd;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-family: 'Cairo', sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--text-medium);
  transition: all 0.18s;
  flex-shrink: 0;
}
.pz-back-btn:hover { background: #e0e0e0; }

.pz-meta { display: flex; align-items: center; gap: 6px; flex: 1; }
.pz-meta-emoji { font-size: 1.4rem; }
.pz-meta-title { font-size: 0.9rem; font-weight: 700; color: var(--text-dark); }
.pz-meta-cat   { font-size: 0.7rem; font-weight: 700; padding: 2px 8px; border-radius: 20px; }
.pz-stars      { font-size: 0.85rem; flex-shrink: 0; }

.pz-turn-badge {
  padding: 6px 18px;
  border-radius: 20px;
  font-size: 0.88rem;
  font-weight: 700;
  margin-bottom: 4px;
  background: #fff;
  border: 2px solid var(--yellow-dark);
  color: var(--text-dark);
}

.pz-hint-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fffde7;
  border: 2px solid var(--yellow);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  max-width: 520px;
  width: 100%;
  margin-bottom: 8px;
}
.pz-hint-icon { font-size: 1.2rem; flex-shrink: 0; }
.pz-hint-text { font-size: 0.88rem; font-weight: 700; color: #5d4037; line-height: 1.4; }

.pz-controls {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.pz-hint-btn {
  background: #fff8e1;
  border: 2px solid var(--yellow);
  border-radius: var(--radius-lg);
  padding: 10px 20px;
  font-family: 'Cairo', sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  color: #5d4037;
  transition: all 0.18s;
}
.pz-hint-btn:hover { background: #fff3cd; }

.pz-attempts {
  font-size: 0.78rem;
  color: var(--text-light);
  margin-top: 6px;
  min-height: 1.2em;
}

/* Wrong move flash on board */
.chess-board.wrong-flash { animation: wrong-flash 0.5s ease; }
@keyframes wrong-flash {
  0%,100% { box-shadow: 0 8px 32px rgba(0,0,0,0.25), 0 0 0 4px var(--yellow-dark); }
  30%,70% { box-shadow: 0 8px 32px rgba(244,67,54,0.5), 0 0 0 6px var(--red); }
}

/* ── Success card ── */
.pz-success-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 36px 40px;
  box-shadow: 0 6px 30px rgba(0,0,0,0.14);
  max-width: 380px;
  text-align: center;
  animation: bounce-in 0.4s ease;
}
.pz-success-emoji   { font-size: 5rem; animation: trophy-bounce 1s ease-in-out infinite; }
.pz-success-title   { font-size: 1.7rem; font-weight: 900; color: var(--yellow-dark); margin: 0; }
.pz-success-explain { font-size: 0.92rem; color: var(--text-medium); margin: 0; line-height: 1.55; }
.pz-success-btns    { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.pz-lib-btn {
  background: #f0f0f0;
  border: 2px solid #ddd;
  border-radius: var(--radius-lg);
  padding: 10px 22px;
  font-family: 'Cairo', sans-serif;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--text-medium);
  transition: all 0.18s;
}
.pz-lib-btn:hover { background: #e0e0e0; }

/* Age 5-7 bigger */
.age-5-7 .puzzle-card     { padding: 20px 14px 18px; }
.age-5-7 .pz-card-emoji   { font-size: 2.9rem; }
.age-5-7 .pz-card-title   { font-size: 0.92rem; }
.age-5-7 .pz-hint-text    { font-size: 0.96rem; }
.age-5-7 .pz-success-card { padding: 40px 44px; }
.age-5-7 .pz-success-emoji { font-size: 6rem; }

/* ===== PIECE SELECTOR ===== */
.piece-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-bottom: 20px;
}

.piece-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--bg-card);
  border: 3px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  padding: 10px 14px;
  font-family: 'Cairo', sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-dark);
  transition: var(--transition);
  box-shadow: var(--shadow-card);
  min-width: 80px;
}

.piece-btn:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-yellow);
  border-color: var(--yellow);
}

.piece-btn.active {
  border-color: var(--yellow);
  background: #FFFBE0;
  box-shadow: var(--shadow-yellow);
}

.piece-btn svg,
.piece-btn img { width: 44px; height: 44px; }

.age-5-7 .piece-btn { padding: 12px 16px; }
.age-5-7 .piece-btn svg,
.age-5-7 .piece-btn img { width: 52px; height: 52px; }
.age-5-7 .piece-btn .piece-btn-name { font-size: 1rem; }

/* ===== TEACH LAYOUT ===== */
.teach-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
}

/* ===== INFO CARD ===== */
.info-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 24px;
  min-width: 220px;
  max-width: 280px;
  flex: 1;
  text-align: center;
  border: 2px solid #FFE88A;
}

.info-emoji {
  font-size: 3rem;
  line-height: 1.2;
  margin-bottom: 8px;
}

.info-name {
  font-size: 2rem;
  font-weight: 900;
  color: var(--text-dark);
  margin-bottom: 8px;
}

.info-desc {
  font-size: 1rem;
  color: var(--text-medium);
  margin-bottom: 12px;
  line-height: 1.6;
}

.info-fact {
  font-size: 0.95rem;
  background: #FFF3CD;
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: #7a5900;
  line-height: 1.5;
}

.age-5-7 .info-name  { font-size: 2.4rem; }
.age-5-7 .info-emoji { font-size: 3.5rem; }
.age-5-7 .info-fact  { font-size: 1.05rem; }

/* ===== TURN INDICATOR ===== */
.turn-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--yellow);
  border-radius: var(--radius-md);
  padding: 12px 20px;
  margin-bottom: 16px;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-dark);
  box-shadow: var(--shadow-yellow);
  animation: slide-down 0.3s ease;
}

.turn-indicator.black-turn {
  background: #2C2C2C;
  color: #FFD700;
  box-shadow: 0 4px 18px rgba(0,0,0,0.3);
}

/* ===== PLAY LAYOUT ===== */
.play-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
}

/* ===== PLAY BUTTONS ===== */
.play-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 16px;
}

.action-btn {
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  font-family: 'Cairo', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  padding: 12px 22px;
  transition: var(--transition);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.action-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,0.2); }
.action-btn:active { animation: btn-click 0.15s ease; }

.btn-green  { background: var(--green);  color: white; }
.btn-orange { background: var(--orange); color: white; }
.btn-yellow { background: var(--yellow); color: var(--text-dark); }

/* ===== SIDEBAR ===== */
.play-sidebar {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 18px;
  min-width: 180px;
  max-width: 220px;
  flex: 1;
  border: 2px solid #FFE88A;
}

.sidebar-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-medium);
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 2px solid #F5F5F5;
}

.sidebar-section { margin-bottom: 18px; }

.captured-row {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  min-height: 28px;
}

.captured-row .captured-piece { font-size: 1.2rem; }

.move-count-display {
  font-size: 2rem;
  font-weight: 900;
  color: var(--yellow-dark);
  text-align: center;
}

.moves-list {
  list-style: none;
  padding: 0;
  font-size: 0.85rem;
  color: var(--text-medium);
  direction: ltr;
  text-align: left;
}

.moves-list li {
  padding: 3px 0;
  border-bottom: 1px solid #F5F5F5;
  font-family: monospace;
  font-size: 0.9rem;
}

/* Ages 8-12: sidebar visible; ages 5-7: hidden */
.age-5-7 .play-sidebar { display: none; }
.age-8-12 .play-sidebar { display: block; }

/* ===== GAME OVERLAY ===== */
.game-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.game-overlay.visible { display: flex; }

.overlay-box {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  text-align: center;
  max-width: 340px;
  width: 90%;
  box-shadow: 0 8px 40px rgba(0,0,0,0.3);
  z-index: 1;
  animation: bounce-in 0.4s ease;
}

.overlay-trophy {
  font-size: 4rem;
  margin-bottom: 12px;
  animation: trophy-bounce 1.2s ease infinite;
}

.overlay-title {
  font-size: 2rem;
  font-weight: 900;
  margin-bottom: 8px;
}

.overlay-msg {
  font-size: 1.2rem;
  color: var(--text-medium);
  margin-bottom: 24px;
}

.overlay-btn { font-size: 1.1rem; padding: 14px 28px; }

#confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ===== CHECK BANNER ===== */
.check-banner {
  display: none;
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--red);
  color: white;
  font-size: 1.4rem;
  font-weight: 900;
  padding: 12px 32px;
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 20px rgba(244,67,54,0.5);
  z-index: 150;
  animation: slide-down 0.3s ease;
}

.check-banner.visible { display: block; }

/* ===== ENCOURAGE BANNER ===== */
.encourage-banner {
  display: none;
  position: fixed;
  top: 80px;
  right: 20px;
  background: var(--green);
  color: white;
  font-size: 1.3rem;
  font-weight: 700;
  padding: 10px 24px;
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 16px rgba(76,175,80,0.4);
  z-index: 150;
  animation: bounce-in 0.3s ease;
}

.encourage-banner.visible { display: block; }

/* Stars */
#stars-container { position: fixed; inset: 0; pointer-events: none; z-index: 180; }

.star-particle {
  position: absolute;
  font-size: 1.8rem;
  pointer-events: none;
  animation: star-float 0.9s ease-out forwards;
}

/* ===== BOARD WRAPPER ===== */
.board-wrapper { display: flex; flex-direction: column; align-items: center; }

/* ═══════════════════════════════════════════════════
   SETUP MODE
═══════════════════════════════════════════════════ */

.setup-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  justify-content: center;
  padding: 12px 16px;
  flex-wrap: wrap;
}

/* ── Palette ── */
.setup-palette {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-card);
  min-width: 160px;
}

.palette-group { display: flex; flex-direction: column; gap: 8px; }

.palette-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-medium);
  text-align: center;
}

.palette-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.palette-piece-btn {
  width: 46px;
  height: 46px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  background: #f4f4f4;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.18s;
  padding: 4px;
}

.palette-piece-btn:hover { background: #e8e8e8; transform: scale(1.08); }

.palette-piece-btn.active {
  border-color: var(--yellow-dark);
  background: var(--yellow-glow);
  box-shadow: 0 0 0 3px rgba(255,215,0,0.35);
  transform: scale(1.12);
}

.palette-piece-btn img { width: 100%; height: 100%; display: block; }

.palette-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }

.palette-eraser {
  background: #f0f0f0;
  border: 2px solid #ddd;
  border-radius: var(--radius-sm);
  padding: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: 'Cairo', sans-serif;
  color: var(--text-medium);
  transition: all 0.18s;
}
.palette-eraser:hover { background: #e0e0e0; }
.palette-eraser.active {
  border-color: var(--orange);
  background: rgba(255,112,67,0.12);
  color: var(--orange);
}

.palette-clear {
  padding: 8px 12px;
  font-size: 0.82rem;
}

.palette-tip {
  font-size: 0.72rem;
  color: var(--text-light);
  text-align: center;
  margin: 0;
  line-height: 1.4;
}

.setup-turn-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding-top: 4px;
  border-top: 1px solid #eee;
}

.setup-turn-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-medium);
}

.setup-turn-btns {
  display: flex;
  gap: 6px;
  width: 100%;
}

.turn-sel-btn {
  flex: 1;
  padding: 7px 4px;
  border-radius: var(--radius-sm);
  border: 2px solid #ddd;
  background: #f4f4f4;
  font-family: 'Cairo', sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s;
  color: var(--text-dark);
}

.turn-sel-btn:hover { background: #e8e8e8; }
.turn-sel-btn.active {
  border-color: var(--yellow-dark);
  background: var(--yellow-glow);
  color: var(--text-dark);
}

.setup-start-btn {
  width: 100%;
  font-size: 1rem;
  padding: 12px;
  margin-top: 4px;
}

.setup-error {
  display: none;
  background: #ffebee;
  border: 2px solid var(--red);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  color: var(--red);
  font-size: 0.82rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.4;
  animation: bounce-in 0.3s ease;
}
.setup-error.visible { display: block; }

/* Active palette → board cursor */
.mode-setup.brush-active .chess-board { cursor: cell; }

/* ── Age 5-7 palette bigger ── */
.age-5-7 .palette-piece-btn { width: 54px; height: 54px; }
.age-5-7 .palette-row       { gap: 8px; }

/* ═══════════════════════════════════════════════════
   TEACHING PATH — LEVEL BUBBLES
═══════════════════════════════════════════════════ */

.level-path-bar {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 14px 8px 6px;
  gap: 0;
  overflow-x: auto;
  width: 100%;
}

.level-bubble {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  cursor: default;
}

.bubble-icon {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: #e0e0e0;
  border: 3px solid #bbb;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.55rem;
  transition: all 0.3s;
}

.bubble-name {
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--text-light);
  text-align: center;
  max-width: 54px;
}

.level-bubble.done .bubble-icon  { background: var(--green); border-color: #388E3C; color: white; font-size: 1.15rem; }
.level-bubble.done .bubble-name  { color: #388E3C; }
.level-bubble.done                { cursor: pointer; }

.level-bubble.current .bubble-icon {
  background: var(--yellow);
  border-color: var(--yellow-dark);
  box-shadow: 0 0 0 5px rgba(255,215,0,0.3);
  animation: bubble-pulse 1.6s ease-in-out infinite;
}
.level-bubble.current .bubble-name { color: var(--yellow-dark); font-weight: 900; }

.level-bubble.locked .bubble-icon { opacity: 0.38; filter: grayscale(0.7); }
.level-bubble.locked .bubble-name { opacity: 0.38; }

.level-connector {
  width: 22px;
  height: 4px;
  background: #ddd;
  border-radius: 2px;
  flex-shrink: 0;
  margin-top: 25px;   /* half of 54px bubble − 2px border = ~25px center alignment */
  transition: background 0.4s;
}
.level-connector.done { background: var(--green); }

@keyframes bubble-pulse {
  0%, 100% { transform: scale(1);    box-shadow: 0 0 0 5px rgba(255,215,0,0.3); }
  50%       { transform: scale(1.09); box-shadow: 0 0 0 9px rgba(255,215,0,0.15); }
}

/* ═══════════════════════════════════════════════════
   TEACH PHASES
═══════════════════════════════════════════════════ */

.teach-phase {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 4px 16px 20px;
  width: 100%;
}
.teach-phase.active { display: flex; }

/* ── Intro Card ─────────────────────────────────── */

.intro-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 28px 36px;
  box-shadow: var(--shadow-card);
  max-width: 380px;
  text-align: center;
  animation: bounce-in 0.35s ease;
}

.intro-piece-img {
  width: 120px;
  height: 120px;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,0.22));
  animation: float-piece 3s ease-in-out infinite;
}

@keyframes float-piece {
  0%, 100% { transform: translateY(0);   }
  50%       { transform: translateY(-9px); }
}

.intro-piece-name {
  font-size: 2rem;
  font-weight: 900;
  color: var(--yellow-dark);
  margin: 0;
}

.intro-piece-text {
  font-size: 1rem;
  color: var(--text-medium);
  line-height: 1.65;
  margin: 0;
  white-space: pre-line;
}

/* ── Challenge Top ──────────────────────────────── */

.challenge-top {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 14px 20px;
  box-shadow: var(--shadow-card);
  max-width: 520px;
  width: 100%;
}

.challenge-visual-info {
  display: flex;
  align-items: center;
  gap: 14px;
}

.ch-piece-img {
  width: 54px;
  height: 54px;
  filter: drop-shadow(0 2px 5px rgba(0,0,0,0.2));
}

.ch-arrow {
  font-size: 2rem;
  color: var(--text-light);
}

.ch-star {
  font-size: 2.5rem;
  animation: star-spin-pulse 1s ease-in-out infinite;
}

@keyframes star-spin-pulse {
  0%, 100% { transform: scale(1) rotate(-5deg); }
  50%       { transform: scale(1.25) rotate(5deg); }
}

.challenge-hint {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-dark);
  text-align: center;
  margin: 0;
}

.challenge-steps {
  display: flex;
  gap: 12px;
  align-items: center;
}

.teach-hint-btn {
  background: #fff8e1;
  border: 2px solid var(--yellow);
  border-radius: var(--radius-lg);
  padding: 8px 20px;
  font-family: 'Cairo', sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  color: #5d4037;
  transition: all 0.18s;
}

.teach-hint-btn:hover  { background: #fff3cd; transform: translateY(-1px); }
.teach-hint-btn:active { animation: btn-click 0.15s ease; }

.age-5-7 .teach-hint-btn { font-size: 1rem; padding: 10px 24px; }

.step-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #ddd;
  border: 2px solid #bbb;
  transition: all 0.3s;
}

.step-dot.done    { background: var(--green); border-color: #388E3C; }
.step-dot.current {
  background: var(--yellow);
  border-color: var(--yellow-dark);
  transform: scale(1.4);
  box-shadow: 0 0 0 3px rgba(255,215,0,0.4);
}

/* ── Target Star on Board ───────────────────────── */

.target-star-el {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1rem, 3.8vw, 1.8rem);
  z-index: 4;
  pointer-events: none;
  animation: star-spin-pulse 0.9s ease-in-out infinite;
}

.chess-board .square.target-sq { background-color: rgba(255, 215, 0, 0.28) !important; }

/* ── Complete Card ──────────────────────────────── */

.complete-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 36px 44px;
  box-shadow: 0 6px 30px rgba(0,0,0,0.14);
  max-width: 380px;
  text-align: center;
  animation: bounce-in 0.4s ease;
}

.complete-emoji { font-size: 4.5rem; animation: trophy-bounce 1s ease-in-out infinite; }
.complete-title { font-size: 1.7rem; font-weight: 900; color: var(--yellow-dark); margin: 0; }
.complete-msg   { font-size: 1rem; color: var(--text-medium); margin: 0; }

/* ── Feedback Popup ─────────────────────────────── */

.teach-feedback-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  z-index: 200;
  font-size: 6rem;
  pointer-events: none;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
  filter: drop-shadow(0 4px 16px rgba(0,0,0,0.2));
  line-height: 1;
}

.teach-feedback-popup.visible { transform: translate(-50%, -50%) scale(1); }

/* ── Age 5-7 overrides (bigger everything) ──────── */

.age-5-7 .bubble-icon      { width: 62px; height: 62px; font-size: 1.75rem; }
.age-5-7 .level-connector  { margin-top: 29px; }
.age-5-7 .intro-piece-img  { width: 140px; height: 140px; }
.age-5-7 .intro-piece-name { font-size: 2.3rem; }
.age-5-7 .intro-piece-text { font-size: 1.08rem; }
.age-5-7 .ch-piece-img     { width: 64px; height: 64px; }
.age-5-7 .ch-star          { font-size: 3rem; }
.age-5-7 .challenge-hint   { font-size: 1.1rem; }
.age-5-7 .step-dot         { width: 17px; height: 17px; }
.age-5-7 .complete-emoji   { font-size: 5.5rem; }
.age-5-7 .teach-feedback-popup { font-size: 8rem; }

/* ═══════════════════════════════════════════════════
   GAMIFICATION — session bar, star award, badges
═══════════════════════════════════════════════════ */

/* ── Session bar ── */
.session-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px 8px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #5a4500;
  flex-wrap: nowrap;
}

.session-label {
  white-space: nowrap;
  flex-shrink: 0;
  opacity: 0.75;
}

.session-track {
  flex: 1;
  height: 8px;
  background: rgba(255,255,255,0.5);
  border-radius: 4px;
  overflow: hidden;
  min-width: 60px;
}

.session-fill {
  height: 100%;
  background: linear-gradient(90deg, #4CAF50, #81C784);
  border-radius: 4px;
  width: 0%;
  transition: width 0.5s ease;
}

.session-stars {
  white-space: nowrap;
  flex-shrink: 0;
  font-size: 0.82rem;
}

.session-streak {
  white-space: nowrap;
  flex-shrink: 0;
  font-size: 0.82rem;
  background: rgba(255,255,255,0.45);
  padding: 2px 8px;
  border-radius: 12px;
  animation: bounce-in 0.3s ease;
}

/* Hide session bar in non-puzzle modes for cleanliness (optional) */
body:not(.mode-puzzles) .session-bar { opacity: 0.65; }
body.mode-puzzles .session-bar { opacity: 1; }

/* ── Star award flash ── */
.star-award {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  font-size: 4rem;
  pointer-events: none;
  z-index: 220;
  filter: drop-shadow(0 4px 12px rgba(255,215,0,0.6));
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.4s ease;
  opacity: 0;
  letter-spacing: 4px;
}

.star-award.visible {
  transform: translate(-50%, -60%) scale(1.2);
  opacity: 1;
  animation: star-award-anim 1.8s ease forwards;
}

@keyframes star-award-anim {
  0%   { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
  25%  { transform: translate(-50%, -65%) scale(1.3); opacity: 1; }
  70%  { transform: translate(-50%, -70%) scale(1.1); opacity: 1; }
  100% { transform: translate(-50%, -80%) scale(0.9); opacity: 0; }
}

/* ── Badge popup ── */
.badge-popup {
  position: fixed;
  bottom: -120px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #FFD700, #FFA000);
  border-radius: var(--radius-lg);
  padding: 16px 28px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 8px 32px rgba(255,160,0,0.5);
  z-index: 210;
  transition: bottom 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
  min-width: 240px;
  max-width: 90vw;
}

.badge-popup.visible { bottom: 32px; }

.badge-icon {
  font-size: 3rem;
  line-height: 1;
  flex-shrink: 0;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.2));
}

.badge-texts {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.badge-header {
  font-size: 0.75rem;
  font-weight: 700;
  color: rgba(0,0,0,0.6);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-label {
  font-size: 1.2rem;
  font-weight: 900;
  color: var(--text-dark);
}

/* Age 5-7 bigger badge */
.age-5-7 .badge-popup  { padding: 20px 34px; }
.age-5-7 .badge-icon   { font-size: 3.8rem; }
.age-5-7 .badge-label  { font-size: 1.4rem; }

/* =====================================================
   MASCOT BUDDY — animated owl speaker
===================================================== */

.mascot-buddy {
  position: fixed;
  bottom: 16px;
  left: 16px;
  z-index: 90;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.mascot-char {
  width: 120px;
  height: 140px;
  animation: mascot-bob 3.2s ease-in-out infinite;
  filter: drop-shadow(0 6px 12px rgba(0,0,0,0.25));
}

.mascot-char svg { width: 100%; height: 100%; display: block; }

@keyframes mascot-bob {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50%      { transform: translateY(-8px) rotate(2deg); }
}

/* Blinking eyelids */
.m-lid { opacity: 0; animation: mascot-blink 4.5s infinite; }
@keyframes mascot-blink {
  0%, 93%, 100% { opacity: 0; }
  95%, 97%      { opacity: 1; }
}

/* Wings + mouth need fill-box so CSS transforms rotate around themselves */
.m-wing, .m-mouth { transform-box: fill-box; transform-origin: center; }

/* ── Talking state ── */
.mascot-buddy.talking .mascot-char {
  animation: mascot-jump 0.5s ease infinite;
}
@keyframes mascot-jump {
  0%, 100% { transform: translateY(0) scale(1); }
  40%      { transform: translateY(-10px) scale(1.05); }
}

.mascot-buddy.talking .m-mouth {
  animation: mascot-mouth 0.22s ease-in-out infinite alternate;
}
@keyframes mascot-mouth {
  from { transform: scaleY(1); }
  to   { transform: scaleY(2.8); }
}

.mascot-buddy.talking .m-wing-l { animation: wing-flap-l 0.4s ease-in-out infinite alternate; }
.mascot-buddy.talking .m-wing-r { animation: wing-flap-r 0.4s ease-in-out infinite alternate; }
@keyframes wing-flap-l { from { transform: rotate(0); } to { transform: rotate(28deg); } }
@keyframes wing-flap-r { from { transform: rotate(0); } to { transform: rotate(-28deg); } }

/* ── Speech bubble ── */
.mascot-bubble {
  background: #fff;
  border: 3px solid var(--yellow-dark);
  border-radius: 16px;
  padding: 8px 18px;
  font-size: 1.1rem;
  font-weight: 900;
  color: var(--text-dark);
  box-shadow: 0 4px 14px rgba(0,0,0,0.15);
  margin-bottom: 8px;
  position: relative;
  white-space: nowrap;
  opacity: 0;
  transform: scale(0.4);
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.mascot-bubble::after {
  content: '';
  position: absolute;
  bottom: -12px;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--yellow-dark);
}

.mascot-bubble.visible { opacity: 1; transform: scale(1); }

/* Hide mascot on small screens to keep the board clear */
@media (max-width: 899px) {
  .mascot-buddy { display: none; }
}

/* =====================================================
   SETUP MODE — DRAG & DROP
===================================================== */

/* Let pointer-drags own the gesture (no page scroll) when the
   finger starts on a palette piece or a piece on the board */
.palette-piece-btn,
#setup-board .piece { touch-action: none; }

/* The piece flying under the pointer/finger */
.drag-ghost {
  position: fixed;
  z-index: 300;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1.18);
  filter: drop-shadow(0 10px 18px rgba(0,0,0,0.35));
}

.drag-ghost img {
  width: 100%;
  height: 100%;
  display: block;
}

/* Releasing here = delete (board piece dragged off the board) */
.drag-ghost.ghost-remove {
  filter: grayscale(1) drop-shadow(0 10px 18px rgba(244,67,54,0.6));
  opacity: 0.55;
}

/* Square under the dragged piece glows */
.square.drop-hover {
  box-shadow: inset 0 0 0 4px var(--yellow), inset 0 0 18px rgba(255,215,0,0.55);
}

/* Origin piece dims while its copy is being dragged */
.piece.drag-origin { opacity: 0.35; }

body.setup-dragging,
body.setup-dragging * { cursor: grabbing !important; }

/* Pieces hint that they're grabbable in setup mode */
#setup-board .piece,
.palette-piece-btn { cursor: grab; }

/* Hint overlay on the empty setup board */
.setup-board-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  z-index: 8;
  pointer-events: none;
  font-size: 1.05rem;
  font-weight: 900;
  line-height: 1.7;
  color: rgba(44, 44, 44, 0.62);
  background: rgba(255, 248, 231, 0.45);
  animation: bounce-in 0.4s ease;
}

.setup-board-hint.hidden { display: none; }
