* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Comic Sans MS", "Chalkboard SE", "Baloo 2", system-ui, sans-serif;
  background: linear-gradient(#dff4ff, #fdf2ff);
  color: #3b2f5c;
  touch-action: manipulation;
}

.screen {
  display: none;
  height: 100%;
  flex-direction: column;
  align-items: center;
}
.screen.active { display: flex; }
#waiting-room { overflow-y: auto; padding-bottom: 4vh; }
#exam-room { touch-action: none; }

h1 { font-size: clamp(2.2rem, 7vw, 4rem); margin: 4vh 0 0; }
.subtitle { font-size: clamp(1.2rem, 3.5vw, 2rem); margin: 1vh 0 3vh; }

/* ---------- Waiting room ---------- */
.patient-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4vw;
  justify-content: center;
  padding: 2vh 4vw;
  max-width: 1100px;
}

.patient-card {
  width: clamp(130px, 26vw, 230px);
  aspect-ratio: 3 / 4;
  border: none;
  border-radius: 28px;
  background: #fff;
  box-shadow: 0 8px 0 #c9b8ef, 0 12px 24px rgba(80, 50, 140, 0.15);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  font: inherit;
  font-size: clamp(1.1rem, 3vw, 1.6rem);
  color: inherit;
  cursor: pointer;
  transition: transform 0.15s;
}
.patient-card:active { transform: translateY(6px); box-shadow: 0 2px 0 #c9b8ef; }
.patient-card svg { width: 100%; height: auto; }
.patient-card.cured::after { content: "⭐ All better"; font-size: 0.8em; color: #2e9e5b; }

/* ---------- Exam room ---------- */
.exam-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
}
.exam-header h2 { margin: 0; font-size: clamp(1.4rem, 4vw, 2.2rem); }

.round-btn {
  width: 60px; height: 60px;
  border-radius: 50%;
  border: none;
  background: #fff;
  font-size: 1.8rem;
  box-shadow: 0 4px 0 #c9b8ef;
  cursor: pointer;
}

.progress { font-size: 1.8rem; min-width: 60px; text-align: right; }

.exam-table {
  position: relative;
  /* Must stay square: problems are placed as % of this box, matching the SVG's 100×100 viewBox.
     ~300px is reserved for the header, hint and tool tray. */
  flex: 0 0 auto;
  width: min(94vw, calc(100dvh - 300px));
  height: min(94vw, calc(100dvh - 300px));
  margin: auto 0;
  background: radial-gradient(ellipse at 50% 85%, #b9e4c9 0 38%, transparent 39%);
}

.toy, .problems { position: absolute; inset: 0; }
.toy svg { width: 100%; height: 100%; }
.toy.happy { animation: bounce 0.6s ease 3; }

/* A problem sits on top of the toy at a % position */
.problem {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: clamp(2rem, 7vmin, 3.6rem);
  width: 1.6em; height: 1.6em;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.2s, opacity 0.4s;
}
.problem.bug { animation: wiggle 0.8s ease-in-out infinite; }
.problem.scratch {
  font-size: clamp(1.4rem, 5vmin, 2.6rem);
  color: #b3261e;
  font-weight: bold;
  letter-spacing: -0.15em;
}
.problem.scratch.treated { color: #f0a8a0; text-shadow: 0 0 10px #fff; }
.problem.tear { font-size: clamp(1.8rem, 6vmin, 3rem); }
.problem.stitched { color: #7b5cd6; font-weight: bold; font-size: clamp(1.1rem, 4vmin, 2rem); letter-spacing: -0.1em; }
.problem.mud { font-size: clamp(2.4rem, 9vmin, 4.4rem); filter: blur(0.5px); }
.problem.fever { animation: pulse 1s ease-in-out infinite; }
.problem.target { box-shadow: 0 0 0 6px rgba(123, 92, 214, 0.5); background: rgba(255, 255, 255, 0.5); }
.problem.fixed { opacity: 0; transform: translate(-50%, -50%) scale(0.2); pointer-events: none; }
.problem.bandaged, .problem.stitched { animation: none; cursor: default; transform: translate(-50%, -50%) rotate(-30deg); }
.problem.nope { animation: shake 0.4s; }
.problem.flyaway { animation: flyaway 0.8s forwards; }

.hint {
  min-height: 2.4em;
  margin: 4px 16px;
  font-size: clamp(1.1rem, 3.2vw, 1.6rem);
  text-align: center;
}

/* ---------- Tool tray ---------- */
.tool-tray {
  width: 100%;
  margin-top: auto;
  display: flex;
  justify-content: center;
  gap: 3vw;
  padding: 12px 12px 20px;
  background: #fff8e7;
  border-top: 6px solid #f5d98b;
}

.tool {
  width: clamp(80px, 18vw, 130px);
  border: 4px solid transparent;
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 5px 0 #e8cf85;
  font: inherit;
  font-size: clamp(0.9rem, 2.4vw, 1.2rem);
  color: inherit;
  padding: 8px 4px;
  cursor: grab;
  touch-action: none;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.tool .icon { font-size: clamp(2.2rem, 7vw, 3.4rem); line-height: 1.2; }
.tool.dragging { opacity: 0.35; }

/* The tool following your finger. Drawn above the finger so it isn't hidden. */
.drag-ghost {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  font-size: clamp(3.2rem, 12vmin, 5rem);
  transform: translate(-50%, -50%) scale(1.1) rotate(-15deg);
  filter: drop-shadow(0 8px 6px rgba(0, 0, 0, 0.25));
}

/* ---------- Celebration ---------- */
.celebration {
  position: fixed;
  inset: 0;
  background: rgba(59, 47, 92, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.celebration.hidden { display: none; }
.celebration-card {
  background: #fff;
  border-radius: 32px;
  padding: 32px 48px;
  text-align: center;
  animation: pop 0.4s ease;
}
.sticker { font-size: 6rem; animation: spin 1.2s ease; }
.big-btn {
  border: none;
  border-radius: 999px;
  background: #7b5cd6;
  color: #fff;
  font: inherit;
  font-size: 1.6rem;
  padding: 14px 32px;
  box-shadow: 0 6px 0 #4f3a99;
  cursor: pointer;
}

.confetti {
  position: fixed;
  top: -5vh;
  font-size: 2rem;
  pointer-events: none;
  z-index: 11;
  animation: fall linear forwards;
}

/* Mood: SVGs carry both mouths, CSS shows the right one */
.mouth-happy { display: none; }
.happy .mouth-happy, .patient-card.cured .mouth-happy { display: inline; }
.happy .mouth-sad, .patient-card.cured .mouth-sad { display: none; }

/* ---------- Animations ---------- */
@keyframes wiggle {
  0%, 100% { transform: translate(-50%, -50%) rotate(-12deg); }
  50% { transform: translate(-50%, -50%) rotate(12deg); }
}
@keyframes shake {
  0%, 100% { transform: translate(-50%, -50%); }
  25% { transform: translate(-60%, -50%); }
  75% { transform: translate(-40%, -50%); }
}
@keyframes flyaway {
  to { transform: translate(-50%, -400%) scale(0.3) rotate(540deg); opacity: 0; }
}
@keyframes pulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.2); }
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6%); }
}
@keyframes pop { from { transform: scale(0.5); } to { transform: scale(1); } }
@keyframes spin { from { transform: rotate(-360deg) scale(0); } to { transform: rotate(0) scale(1); } }
@keyframes fall { to { transform: translateY(115vh) rotate(720deg); } }

/* Back to the lab landing page (waiting room only, so kids don't wander off mid-exam) */
.lab-link {
  position: absolute;
  top: 12px;
  left: 16px;
  color: #7b5cd6;
  font-size: 1rem;
  text-decoration: none;
  opacity: 0.8;
}
#waiting-room { position: relative; }
