/* Brainy Lab Games: big, bright, simple. Every button is at least 56px. */
:root {
  --bg: #fff8ec;
  --ink: #1f2937;
  --card: #ffffff;
  --line: #e5e7eb;
  --pink: #ec4899;
  --teal: #0d9488;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1917;
    --ink: #fef3c7;
    --card: #292524;
    --line: #57534e;
  }
}
:root[data-theme="dark"] {
  --bg: #1c1917;
  --ink: #fef3c7;
  --card: #292524;
  --line: #57534e;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background:
    radial-gradient(circle at 12% 18%, rgba(236, 72, 153, .18), transparent 40%),
    radial-gradient(circle at 88% 14%, rgba(13, 148, 136, .18), transparent 38%),
    radial-gradient(circle at 50% 100%, rgba(251, 191, 36, .22), transparent 45%),
    linear-gradient(160deg, #fff1f8 0%, #f0fdfa 55%, #fff7e0 100%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  font-size: 18px;
  min-height: 100vh;
  padding: 0 16px 24px;
}
[hidden] { display: none !important; }

.top { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 16px 0; }
.top h1 { margin: 0; font-size: 26px; font-weight: 900; flex: 1; }
.back, .tab, .btn {
  min-height: 56px;
  padding: 0 18px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.tab.active { border-color: var(--pink); }
.btn-small { min-height: 44px; padding: 0 12px; }
.btn:focus-visible, .tab:focus-visible, .choice:focus-visible, .tile:focus-visible, .swatch:focus-visible {
  outline: 4px solid var(--teal);
  outline-offset: 2px;
}

.tiles { display: grid; grid-template-columns: 1fr; gap: 16px; max-width: 560px; margin: 0 auto; }
.tile {
  min-height: 180px;
  border: none;
  border-radius: 28px;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font: inherit;
}
.tile b { font-size: 26px; font-weight: 900; }
.tile small { font-size: 16px; font-weight: 700; opacity: 0.95; }
.tile-big { font-size: 64px; font-weight: 900; line-height: 1; }
.tile-pink { background: var(--pink); }
.tile-teal { background: var(--teal); }

.card {
  max-width: 420px;
  margin: 8px auto 0;
  background: var(--card);
  border: 3px solid var(--line);
  border-radius: 28px;
  padding: 20px;
  text-align: center;
}
.big-letter { font-size: 140px; font-weight: 900; line-height: 1; color: var(--pink); }
.emoji { font-size: 72px; line-height: 1.2; }
.btn-listen { margin: 12px auto 0; }

.choices {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
  margin: 24px auto 0;
  max-width: 420px;
}
.choice {
  min-width: 96px;
  min-height: 96px;
  border-radius: 28px;
  border: 3px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 48px;
  font-weight: 900;
  cursor: pointer;
}

.feedback { text-align: center; font-size: 20px; font-weight: 800; margin-top: 16px; min-height: 28px; }

.reward {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-top: 12px;
}
.reward-face, .reward-thumb { font-size: 96px; line-height: 1; }

.trace-bar, .trace-colors, .trace-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: center;
  margin: 8px 0;
}
.pill {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 700;
}
.swatch {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 4px solid var(--card);
  box-shadow: 0 0 0 2px var(--line);
  background: var(--c);
  cursor: pointer;
}
.trace-canvas {
  display: block;
  margin: 4px auto;
  background: linear-gradient(180deg, #ffffff 0%, #fdf4ff 100%);
  border: 4px solid #ffffff;
  box-shadow: 0 0 0 4px #f9a8d4, 0 0 28px 6px rgba(236, 72, 153, .35), 0 18px 40px -12px rgba(13, 148, 136, .45);
  height: calc(100dvh - 250px);
  min-height: 240px;
  width: auto;
  aspect-ratio: 360 / 380;
  max-width: 100%;
  border-radius: 24px;
  background: var(--card);
  border: 3px solid var(--line);
  touch-action: none;
}
.coach { text-align: center; font-weight: 800; font-size: 20px; min-height: 28px; }

.foot { text-align: center; font-size: 14px; opacity: 0.8; margin-top: 16px; }

/* ShapeSpeak: the whole game fits on one screen with the mic under the letter */
.mic {
  display: block;
  margin: 16px auto 0;
  width: 130px;
  height: 130px;
  border-radius: 50%;
  border: 6px solid var(--card);
  background: var(--pink);
  color: #ffffff;
  font-size: 64px;
  line-height: 1;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  box-shadow: 0 0 0 3px var(--line);
}
.mic.listening { background: var(--teal); transform: scale(1.08); animation: pulse .8s ease-in-out infinite; }
.card {
  max-width: 560px;
  padding: 20px 24px;
  background: linear-gradient(180deg, #ffffff 0%, #fdf2f8 100%);
  border: 4px solid #fbcfe8;
  box-shadow: 0 0 0 4px #ffffff, 0 16px 34px -14px rgba(236, 72, 153, .45);
}
.big-letter { font-size: min(170px, 26vh);text-shadow: 0 6px 0 #fbcfe8, 0 0 26px rgba(236, 72, 153, .35); }
.emoji { font-size: min(110px, 16vh); }
.btn-listen { min-height: 64px; font-size: 20px; }
.feedback { margin-top: 10px; font-size: 26px; min-height: 36px; }
.reward { margin-top: 6px; }
.reward-face { font-size: 90px; }
.shake { animation: shake .5s ease-in-out; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-12px); }
  40% { transform: translateX(12px); }
  60% { transform: translateX(-8px); }
  80% { transform: translateX(8px); }
}

/* Happy celebration: stars burst out and the box bounces */
.card, #screenTrace { position: relative; }
.burst { position: absolute; left: 50%; top: 45%; width: 0; height: 0; pointer-events: none; z-index: 5; }
.spark {
  position: absolute; left: 0; top: 0;
  font-size: 34px; line-height: 1;
  transform: translate(-50%, -50%) scale(0.2);
  animation: spark var(--d, 1.2s) cubic-bezier(.2, .7, .3, 1) forwards;
}
@keyframes spark {
  0%   { transform: translate(-50%, -50%) scale(0.2); opacity: 0; }
  15%  { opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.3) rotate(200deg); opacity: 0; }
}
.bounce { animation: bounce .7s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes bounce {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.06) rotate(-1deg); }
  70%  { transform: scale(0.98) rotate(1deg); }
  100% { transform: scale(1); }
}
.coach-win { color: #0f766e; font-size: 24px; animation: pulse .9s ease-in-out 3; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.12); } }

/* Diagnostic readout for the mic problem; remove once fixed */
.diag { font-size: 12px; text-align: left; max-width: 560px; margin: 8px auto 0; white-space: pre-wrap; background: rgba(255,255,255,.8); border-radius: 12px; padding: 6px 10px; color: #334155; }
.diag:empty { display: none; }

/* Keep every game on one screen; no scrolling */
body { padding-bottom: 8px; }
.top { padding: 8px 0; }
#screenShapespeak, #screenTrace { min-height: calc(100dvh - 90px); }
#screenTrace { display: flex; flex-direction: column; align-items: center; }
.trace-colors { margin: 4px 0; }
.trace-nav { margin: 4px 0; }
.coach { margin: 2px 0; }
.foot a { color: var(--teal); font-weight: 700; }
