/* ==========================================================================
   Panda Chess Quest — styles
   Bright, chunky, touch-friendly. Designed for kids + classroom whiteboards.
   ========================================================================== */

:root {
  --bg1: #6a4bc4;
  --bg2: #8b5cf6;
  --bg3: #ec4899;
  --panel: #ffffff;
  --ink: #2b1a4a;
  --muted: #6b5b8a;
  --light: #f3e9d2;   /* light board square */
  --dark: #6f9b5b;    /* dark board square  */
  --dot: rgba(46, 204, 113, 0.55);
  --ring: #ef476f;
  --gold: #ffd166;
  --good: #06d6a0;
  --bad: #ef476f;
  --shadow: 0 10px 30px rgba(30, 10, 60, 0.25);
  --radius: 20px;
  font-family: 'Baloo 2', 'Comic Sans MS', 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh;
  color: var(--ink);
  background: linear-gradient(135deg, var(--bg1), var(--bg2) 45%, var(--bg3));
  background-attachment: fixed;
  overflow-x: hidden;
}

/* ------- top bar ------- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 18px;
  background: rgba(255,255,255,0.14);
  backdrop-filter: blur(8px);
  border-bottom: 3px solid rgba(255,255,255,0.25);
  position: sticky; top: 0; z-index: 40;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; color: #fff; }
.brand-panda { font-size: 30px; }
.brand-name { font-size: 20px; text-shadow: 0 2px 0 rgba(0,0,0,0.15); }
@media (max-width: 560px) { .brand-name { display: none; } }

.profile { margin-left: auto; display: flex; flex-direction: column; gap: 4px; min-width: 180px; }
.profile-main { display: flex; align-items: center; gap: 8px; }
.pname { color: #fff; font-weight: 800; font-size: 15px; }
.level-badge {
  background: var(--gold); color: #6a4a00; font-weight: 800;
  padding: 1px 9px; border-radius: 999px; font-size: 13px;
  box-shadow: 0 2px 0 rgba(0,0,0,0.15);
}
.xp-bar {
  position: relative; height: 16px; width: 100%;
  background: rgba(0,0,0,0.22); border-radius: 999px; overflow: hidden;
  border: 2px solid rgba(255,255,255,0.35);
}
.xp-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--good), var(--gold));
  transition: width 0.5s cubic-bezier(.2,.8,.2,1);
}
.xp-text {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 800; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}
.badges { display: flex; gap: 4px; }
.badge {
  font-size: 18px; filter: grayscale(1) opacity(0.4);
  transition: transform .3s, filter .3s;
}
.badge.earned { filter: none; transform: scale(1.05); animation: pop .4s; }

.icon-btn {
  font-size: 22px; background: rgba(255,255,255,0.2); border: none;
  width: 44px; height: 44px; border-radius: 14px; cursor: pointer;
}
.icon-btn:active { transform: scale(0.92); }

/* ------- screens ------- */
.screen { max-width: 780px; margin: 0 auto; padding: 20px 16px 120px; }
.hidden { display: none !important; }

.home-hero { text-align: center; color: #fff; margin: 6px 0 22px; }
.home-hero h2 { font-size: 30px; margin: 0 0 6px; text-shadow: 0 3px 0 rgba(0,0,0,0.18); }
.home-hero p { margin: 0 auto; max-width: 460px; opacity: 0.95; }

/* ------- game menu cards ------- */
.game-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
}
@media (max-width: 480px) { .game-grid { grid-template-columns: 1fr; } }
.game-card {
  border: none; cursor: pointer; text-align: left;
  border-radius: var(--radius); padding: 20px 18px;
  display: flex; flex-direction: column; gap: 6px;
  color: #3a2a10; box-shadow: var(--shadow);
  transition: transform .15s, box-shadow .15s;
  position: relative; overflow: hidden;
  min-height: 160px;
}
.game-card::after {
  content: ''; position: absolute; right: -20px; top: -20px;
  width: 90px; height: 90px; border-radius: 50%;
  background: rgba(255,255,255,0.25);
}
.game-card:hover { transform: translateY(-4px) rotate(-.5deg); }
.game-card:active { transform: scale(0.97); }
.gc-emoji { font-size: 46px; }
.gc-title { font-size: 21px; font-weight: 800; }
.gc-blurb { font-size: 14px; opacity: 0.85; flex: 1; }
.gc-play { align-self: flex-start; font-weight: 800; background: rgba(255,255,255,0.5); padding: 4px 14px; border-radius: 999px; font-size: 14px; }
.tint-green  { background: linear-gradient(135deg, #a8e063, #56ab2f); }
.tint-yellow { background: linear-gradient(135deg, #ffe259, #ffa751); }
.tint-purple { background: linear-gradient(135deg, #c471f5, #8b5cf6); color: #fff; }
.tint-purple .gc-play { background: rgba(255,255,255,0.3); }
.tint-pink   { background: linear-gradient(135deg, #ff9a9e, #f857a6); color: #fff; }
.tint-pink .gc-play { background: rgba(255,255,255,0.3); }

.home-foot { text-align: center; color: rgba(255,255,255,0.8); margin-top: 26px; font-size: 13px; }

/* ------- play screen ------- */
.play-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.play-bar h2 { color: #fff; margin: 0; font-size: 24px; text-shadow: 0 2px 0 rgba(0,0,0,0.18); }
.spacer { flex: 1; }
.play-area {
  background: var(--panel); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}

/* ------- buttons ------- */
.btn {
  border: none; cursor: pointer; font-family: inherit; font-weight: 800;
  padding: 10px 18px; border-radius: 999px; font-size: 15px;
  transition: transform .12s; color: var(--ink);
}
.btn:active { transform: scale(0.94); }
.btn.primary { background: linear-gradient(135deg, var(--good), #048f6f); color: #fff; box-shadow: 0 4px 0 #036a53; }
.btn.primary:active { box-shadow: 0 1px 0 #036a53; }
.btn.ghost { background: rgba(255,255,255,0.85); color: var(--ink); box-shadow: 0 3px 0 rgba(0,0,0,0.12); }
.btn.big { font-size: 20px; padding: 14px 34px; margin-top: 8px; }

/* ------- board ------- */
.board-wrap { display: flex; justify-content: center; margin: 12px 0; }
.board {
  width: min(92vw, 460px); aspect-ratio: 1 / 1;
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  border-radius: 12px; overflow: hidden;
  box-shadow: 0 8px 20px rgba(0,0,0,0.25), 0 0 0 5px #4a3a2a;
  touch-action: manipulation;
}
.sq {
  position: relative; border: none; padding: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(26px, 9vw, 46px); line-height: 1;
  transition: background .12s;
}
.sq.light { background: var(--light); }
.sq.dark { background: var(--dark); }
.sq .piece { position: relative; z-index: 3; filter: drop-shadow(0 2px 1px rgba(0,0,0,0.35)); }
.sq .piece.white { color: #ffffff; text-shadow: 0 0 3px rgba(0,0,0,0.6), 0 1px 2px rgba(0,0,0,0.5); }
.sq .piece.black { color: #1b1b2b; }
.sq .decor { position: absolute; z-index: 2; font-size: 0.7em; animation: bob 1.6s ease-in-out infinite; }
.sq .decor.star { filter: drop-shadow(0 0 6px rgba(255,209,102,0.9)); }

.coord {
  position: absolute; font-size: 10px; font-weight: 800; opacity: 0.5; z-index: 1;
  color: #3a2a1a;
}
.coord.rank { top: 2px; left: 3px; }
.coord.file { bottom: 1px; right: 3px; }

.sq.dot::before {
  content: ''; position: absolute; width: 34%; height: 34%; border-radius: 50%;
  background: var(--dot); z-index: 1; animation: pulse 1.1s ease-in-out infinite;
}
.sq.ring::after {
  content: ''; position: absolute; inset: 8%; border-radius: 50%;
  border: 5px solid var(--ring); z-index: 1; box-sizing: border-box;
  animation: pulse 1.1s ease-in-out infinite;
}
.sq.selected { box-shadow: inset 0 0 0 5px var(--gold); }
.sq.mark-good { box-shadow: inset 0 0 0 5px var(--good); }
.sq.flash-good { animation: flashGood .6s; }
.sq.flash-bad { animation: flashBad .6s; }

/* ------- HUD + controls ------- */
.game-hud {
  display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-bottom: 6px;
}
.hud-item {
  background: #f4f0fb; border-radius: 14px; padding: 6px 14px; text-align: center;
  min-width: 74px; border: 2px solid #e6def7;
}
.hud-k { display: block; font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
.hud-v { display: block; font-size: 17px; font-weight: 800; }
.game-controls { display: flex; gap: 10px; justify-content: center; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.win-banner {
  width: 100%; text-align: center; font-weight: 800; font-size: 18px; color: var(--good);
  margin-top: 6px; animation: pop .4s;
}

/* ------- Meet the Pieces ------- */
.piece-picker { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 4px; }
.piece-chip {
  border: 3px solid #e6def7; background: #fff; border-radius: 16px;
  padding: 6px 10px; cursor: pointer; display: flex; flex-direction: column; align-items: center;
  min-width: 60px; transition: transform .12s, border-color .12s;
}
.piece-chip:active { transform: scale(0.92); }
.piece-chip.active { border-color: var(--gold); background: #fff7e0; transform: translateY(-2px); }
.piece-chip .pg { font-size: 30px; line-height: 1; }
.piece-chip .pn { font-size: 12px; font-weight: 800; color: var(--muted); }

.fact-card { background: #f4f0fb; border-radius: 16px; padding: 14px 16px; border: 2px solid #e6def7; }
.fact-title { font-size: 20px; font-weight: 800; margin-bottom: 4px; }
.fact-body { font-size: 15px; color: var(--ink); line-height: 1.4; }
.fact-cta { margin-top: 8px; font-weight: 800; color: var(--good); font-size: 14px; }

/* ------- Quiz ------- */
.quiz-card { text-align: center; }
.quiz-top { color: var(--muted); font-weight: 800; font-size: 14px; }
.quiz-glyphs { font-size: 66px; line-height: 1; margin: 6px 0; }
.quiz-q { font-size: 20px; font-weight: 800; margin: 6px auto 16px; max-width: 460px; }
.quiz-opts { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
@media (max-width: 480px) { .quiz-opts { grid-template-columns: 1fr; } }
.quiz-opt {
  border: 3px solid #e6def7; background: #fff; border-radius: 16px; padding: 14px 8px;
  cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-family: inherit; font-weight: 800; font-size: 15px; transition: transform .12s;
}
.quiz-opt:active { transform: scale(0.95); }
.quiz-opt .qg { font-size: 34px; }
.quiz-opt.right { border-color: var(--good); background: #e6fff6; animation: pop .3s; }
.quiz-opt.wrong { border-color: var(--bad); background: #ffe9ef; }
.quiz-result { padding: 20px 10px; }
.big-emoji { font-size: 70px; animation: bob 1.6s ease-in-out infinite; }
.quiz-score { font-size: 26px; font-weight: 800; margin-top: 8px; }
.quiz-sub { color: var(--muted); margin-top: 4px; }

/* ------- panda coach ------- */
.coach {
  position: fixed; left: 14px; bottom: 14px; z-index: 60;
  display: flex; align-items: center; gap: 10px; max-width: min(90vw, 420px);
  background: #fff; border-radius: 22px; padding: 10px 16px 10px 10px;
  box-shadow: var(--shadow); border: 3px solid var(--gold);
  transform: translateY(140%); opacity: 0; transition: transform .4s cubic-bezier(.2,.9,.3,1.3), opacity .3s;
}
.coach.show { transform: translateY(0); opacity: 1; }
.coach.pop .coach-face { animation: pop .3s; }
.coach-face { font-size: 38px; flex-shrink: 0; }
.coach-text { font-size: 15px; font-weight: 700; line-height: 1.3; }

/* ------- toast ------- */
.toast {
  position: fixed; top: 74px; left: 50%; transform: translateX(-50%) translateY(-20px);
  background: #2b1a4a; color: #fff; padding: 10px 20px; border-radius: 999px;
  font-weight: 800; font-size: 14px; z-index: 70; opacity: 0; pointer-events: none;
  transition: transform .3s, opacity .3s; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ------- overlay ------- */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: linear-gradient(135deg, var(--bg1), var(--bg3));
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.overlay-card {
  background: #fff; border-radius: 28px; padding: 30px 26px; text-align: center;
  max-width: 380px; width: 100%; box-shadow: var(--shadow); animation: pop .4s;
}
.overlay-panda { font-size: 80px; animation: bob 2s ease-in-out infinite; }
.overlay-title { font-size: 30px; margin: 4px 0; color: var(--ink); }
.overlay-sub { color: var(--muted); margin: 0 0 16px; }
.name-input {
  width: 100%; padding: 14px 18px; border-radius: 16px; border: 3px solid #e6def7;
  font-family: inherit; font-size: 18px; font-weight: 700; text-align: center; color: var(--ink);
  outline: none;
}
.name-input:focus { border-color: var(--gold); }

/* ------- confetti ------- */
.confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 90; overflow: hidden; }
.confetti {
  position: absolute; top: -20px; width: 12px; height: 16px; border-radius: 2px;
  animation: fall linear forwards;
}

/* ------- keyframes ------- */
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes pulse { 0%,100% { transform: scale(1); opacity: .8; } 50% { transform: scale(1.25); opacity: 1; } }
@keyframes pop { 0% { transform: scale(0.6); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes fall {
  0% { transform: translateY(0) rotate(0); opacity: 1; }
  100% { transform: translateY(105vh) rotate(720deg); opacity: 0.9; }
}
@keyframes flashGood { 0%,100% { background: inherit; } 40% { background: var(--good); } }
@keyframes flashBad  { 0%,100% { background: inherit; } 40% { background: var(--bad); } }
