* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: linear-gradient(160deg, #6a4df0, #2aa7e8);
  font-family: ui-rounded, "Avenir Next", "Trebuchet MS", system-ui, sans-serif;
  color: #2a2356;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  /* room at the top so a tall card never slides under the sound button */
  padding: calc(58px + env(safe-area-inset-top)) 0 calc(12px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: center;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.hidden { display: none !important; }

/* ---------- sound ---------- */

#topRight {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 10;
}

#soundBtn {
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.8);
  background: rgba(30, 20, 90, 0.45);
  color: #fff;
  font-size: 12px;
  letter-spacing: 2px;
  padding: 8px 12px;
  min-height: 40px;
}

#soundBtn[aria-pressed="true"] { background: rgba(255, 255, 255, 0.92); color: #3a2ca0; }

/* ---------- cards ---------- */

.card {
  width: min(560px, calc(100% - 24px));
  max-height: 100%;
  overflow-y: auto;
  padding: 20px 20px 24px;
  border-radius: 28px;
  background: #fff;
  box-shadow: 0 10px 0 rgba(20, 10, 80, 0.25);
  text-align: center;
  animation: pop 0.3s ease-out;
}

@keyframes pop {
  from { transform: scale(0.92); opacity: 0; }
}

h1, h2 {
  margin: 4px 0 6px;
  letter-spacing: 1.5px;
  color: #6a4df0;
}

h1 { font-size: clamp(26px, 7vw, 38px); }
h2 { font-size: clamp(22px, 6vw, 30px); }

.tag { margin: 4px 0 10px; font-size: 17px; }
.tag b { color: #e8590c; }
.note { margin: 10px 0; font-size: 14px; opacity: 0.75; }
.ask { margin: 14px 0 8px; font-size: 20px; font-weight: 700; }

.label {
  font-size: 12px;
  letter-spacing: 2px;
  font-weight: 700;
  color: #6a4df0;
}

.buddy { font-size: 52px; line-height: 1; display: inline-block; }

.big {
  margin-top: 12px;
  padding: 14px 30px;
  border: 0;
  border-radius: 18px;
  background: #ffd23f;
  box-shadow: 0 6px 0 #d9a400;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 1.5px;
}

.big:active { transform: translateY(4px); box-shadow: 0 2px 0 #d9a400; }
.big.plain { background: #ece9ff; box-shadow: 0 6px 0 #c9c2f5; }
.big.plain:active { box-shadow: 0 2px 0 #c9c2f5; }

.buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 0 12px; }

/* ---------- pick your grade ---------- */

#gradeList {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.gradeBtn {
  position: relative;
  padding: 12px 4px;
  border: 0;
  border-radius: 18px;
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.22);
}

.gradeBtn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.22); }
.gradeBtn small { display: block; font-size: 11px; letter-spacing: 1px; font-weight: 600; opacity: 0.95; min-height: 14px; }

/* ---------- questions ---------- */

.top { display: flex; justify-content: space-between; }

#dots { display: flex; gap: 6px; margin: 10px 0; }
#dots i { flex: 1; height: 10px; border-radius: 999px; background: #e6e2fb; }
#dots i.now { background: #ffd23f; }
#dots i.right { background: #36c26b; }
#dots i.wrong { background: #ff6b6b; }

.talk { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 56px; }
.talk .buddy { font-size: 44px; }
.talk .buddy.hop { animation: hop 0.5s; }
#say { font-size: 20px; font-weight: 700; color: #e8590c; }

@keyframes hop {
  40% { transform: translateY(-14px) rotate(-8deg); }
  70% { transform: translateY(0) rotate(6deg); }
}

#question {
  margin: 6px 0 12px;
  font-size: clamp(24px, 6.5vw, 38px);
  font-weight: 700;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

#answerBox {
  margin: 0 auto 10px;
  width: min(260px, 100%);
  min-height: 56px;
  padding: 6px 12px;
  border: 4px solid #6a4df0;
  border-radius: 16px;
  font-size: 34px;
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

#answerBox.right { border-color: #36c26b; background: #e3f8eb; }
#answerBox.wrong { border-color: #ff6b6b; background: #ffe9e9; }
#answerBox:empty::before { content: "?"; opacity: 0.25; }

#keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: min(300px, 100%);
  margin: 0 auto;
}

#keypad button {
  height: clamp(40px, 7.5vh, 58px);
  border: 0;
  border-radius: 14px;
  background: #ece9ff;
  box-shadow: 0 4px 0 #c9c2f5;
  font-size: 24px;
  font-weight: 700;
}

#keypad button:active { transform: translateY(3px); box-shadow: 0 1px 0 #c9c2f5; }
#keypad button.extra { background: #d8f1ff; box-shadow: 0 4px 0 #a9d6f0; }

#choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

#choices button {
  padding: 18px 8px;
  border: 0;
  border-radius: 18px;
  color: #fff;
  font-size: 28px;
  font-weight: 700;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.22);
}

#choices button:nth-child(1) { background: #ff6b9d; }
#choices button:nth-child(2) { background: #2aa7e8; }
#choices button:nth-child(3) { background: #f59f00; }
#choices button:nth-child(4) { background: #8a5cf6; }
#choices button:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.22); }
#choices.locked button { opacity: 0.35; }
#choices.locked button.right { opacity: 1; background: #36c26b; }
#choices.locked button.wrong { opacity: 1; background: #ff6b6b; }

#wrongBox p { margin: 14px 0 0; font-size: 20px; }
#wrongBox b { font-size: 28px; color: #1f9d55; }

/* ---------- the puzzle ---------- */

#board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  width: min(400px, 100%);
  margin: 12px auto 4px;
}

#board button {
  aspect-ratio: 1;
  border: 0;
  border-radius: 16px;
  background: #6a4df0;
  box-shadow: 0 5px 0 #4a32c0;
  color: #fff;
  font-size: clamp(26px, 8vw, 40px);
  font-weight: 700;
  transition: transform 0.15s;
}

#board button.up { background: #fff3c4; box-shadow: 0 5px 0 #e6cf7a; transform: rotateY(180deg) scaleX(-1); }
#board button.matched { background: #d3f5df; box-shadow: 0 5px 0 #9bdcb3; animation: hop 0.5s; }

/* ---------- the report ---------- */

#letter {
  width: 120px;
  height: 120px;
  margin: 8px auto;
  border-radius: 50%;
  background: #ffd23f;
  box-shadow: 0 6px 0 #d9a400;
  font-size: 58px;
  font-weight: 700;
  line-height: 120px;
  color: #6a4df0;
  animation: pop 0.5s ease-out;
}

#rows { margin-top: 12px; text-align: left; }

#rows h3 {
  margin: 14px 0 6px;
  font-size: 12px;
  letter-spacing: 2px;
  color: #6a4df0;
}

.row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 10px;
  font-size: 15px;
}

.row:nth-child(even) { background: #f5f3ff; }
.row .q { flex: 1; overflow-wrap: anywhere; }
.row .a { text-align: right; font-weight: 700; }
.row.right .a { color: #1f9d55; }
.row.wrong .a { color: #e03131; }
.row .a small { display: block; font-weight: 600; color: #2a2356; opacity: 0.7; }

/* ---------- confetti ---------- */

.bit {
  position: fixed;
  left: 50%;
  top: 40%;
  z-index: 20;
  font-size: 28px;
  pointer-events: none;
  animation: fly 0.9s ease-out forwards;
}

@keyframes fly {
  to { transform: translate(var(--x), var(--y)) rotate(var(--r)); opacity: 0; }
}
