:root {
  --bg-top: #8de7ff;
  --bg-mid: #9af2ff;
  --bg-bottom: #00a8d8;
  --sea-deep: #0078a7;
  --coral: #ff6fa8;
  --mint: #49f8d3;
  --sun: #ffe066;
  --card: rgba(255, 255, 255, 0.9);
}

* { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  /* Minder dubbel-tik-zoom op mobiel; canvas zelf heeft touch-action: none */
  touch-action: manipulation;
}

#gameWrap {
  position: relative;
  width: 100%;
  max-width: 100vw;
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  touch-action: none;
}

#gameCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#highscoreHud {
  position: fixed;
  left: 12px;
  right: auto;
  top: 10px;
  display: flex;
  gap: 8px;
  pointer-events: none;
  z-index: 5;
}

#hud {
  position: fixed;
  right: 12px;
  left: auto;
  top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  pointer-events: none;
  z-index: 5;
}

#hud > div,
#highscoreHud > div {
  background: linear-gradient(155deg, rgba(255,255,255,0.96), rgba(236, 251, 255, 0.96));
  color: #ff2f87;
  border-radius: 999px;
  border: 2px solid rgba(152, 233, 255, 0.9);
  padding: 8px 16px;
  font-weight: 900;
  font-size: 1.02rem;
  letter-spacing: 0.4px;
  text-align: center;
  text-shadow: 0 1px 0 #fff;
  box-shadow: 0 6px 16px rgba(0, 118, 168, 0.16);
}

#highscore {
  text-align: left;
  line-height: 1.15;
  max-width: min(42vw, 340px);
  white-space: normal;
}

#highscore .highscoreMainLine {
  display: block;
}

#highscore .highscoreSchoolLine {
  display: block;
  margin-top: 2px;
  font-size: 0.72rem;
  font-weight: 800;
  color: #0d79a3;
  opacity: 0.94;
}

#energyWrap {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-start;
  background: linear-gradient(155deg, rgba(255,255,255,0.98), rgba(238, 252, 255, 0.96));
  border: 2px solid rgba(152, 233, 255, 0.95);
  border-radius: 999px;
  padding: 10px 14px;
  box-shadow: 0 8px 18px rgba(0, 87, 126, 0.2);
}

#energyWrap > span {
  font-size: 0.88rem;
  font-weight: 900;
  color: #0a7aa7;
  letter-spacing: 0.3px;
}

/* Compact label + bar on one row (quiz timer & superdier timer). */
#energyWrap.energy-mode-timer > span {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  white-space: nowrap;
  flex-shrink: 0;
}

#footerBar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: max(10px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: flex-start;
  pointer-events: none;
  z-index: 5;
}

#energyBar {
  width: 170px;
  height: 14px;
  border-radius: 999px;
  background: rgba(0, 139, 183, 0.18);
  overflow: hidden;
}

#energyFill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #ffe26c, #5ff0d9, #34b8ff);
}

.overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 38, 62, 0.45);
  z-index: 10;
}

.overlay.visible { display: flex; }

#finalQuizOverlay {
  z-index: 12;
  background: rgba(0, 28, 48, 0.52);
}

.finalQuizCard {
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.98), rgba(220, 252, 255, 0.96));
  border-color: #b8f0ff;
}

.finalQuizSub {
  font-size: 1rem !important;
  font-weight: 600;
  color: #0a6d94 !important;
  margin-bottom: 6px !important;
}

.finalQuizPrompt {
  margin: 10px 0 16px !important;
  font-size: clamp(1.2rem, 4.2vw, 1.55rem) !important;
  font-weight: 800;
  color: #05334f !important;
  line-height: 1.35;
}

.finalQuizAnswers {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

#finalQuizOverlay .finalQuizBtn {
  min-width: 76px;
  min-height: 58px;
  font-size: 1.45rem;
  font-weight: 900;
  box-shadow: 0 8px 18px rgba(0, 100, 140, 0.22);
}

#finalQuizSkip {
  margin-top: 4px;
  background: linear-gradient(120deg, #7a9eb5, #5a8aa8);
  font-size: 0.95rem;
  padding: 10px 20px;
}

.card {
  width: min(560px, 94vw);
  background: var(--card);
  border-radius: 20px;
  padding: 22px;
  border: 3px solid #fff;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.25);
  color: #05334f;
  text-align: center;
}

.card h1, .card h2 {
  margin: 0 0 10px;
  font-size: clamp(2.2rem, 8vw, 3.8rem);
  color: #ff2f87;
  text-shadow: 0 2px 0 #fff;
  letter-spacing: 2px;
}

#introScreen .card h1 {
  font-weight: 900;
  letter-spacing: 3px;
  text-shadow: 0 3px 0 #fff, 0 10px 18px rgba(255, 47, 135, 0.24);
}

#introScreen .card h1 .ctMark {
  display: inline-block;
  margin: 0 2px;
  padding: 0 8px 2px;
  border-radius: 10px;
  background: linear-gradient(180deg, #ff76b5, #ff2f87);
  color: #fff;
  text-shadow: none;
  box-shadow: 0 6px 14px rgba(255, 47, 135, 0.28);
}

#introScreen .card h1 small {
  display: block;
  margin-top: 6px;
  font-size: clamp(0.8rem, 2.7vw, 1.05rem);
  letter-spacing: 1.8px;
  color: #0c83ae;
  text-shadow: none;
}

.card p { margin: 0 0 10px; font-size: 1.1rem; }
.card ul {
  margin: 0 0 14px;
  padding: 0;
  list-style-position: inside;
}
.card li { margin: 6px 0; }

/* Intro text block: centered container, left-aligned readable text */
#introScreen .card p,
#introScreen .card ul {
  max-width: 460px;
  margin-left: auto;
  margin-right: auto;
  text-align: left;
}

#introScreen .card ul {
  padding-left: 8px;
}

#introScreen .card li {
  line-height: 1.35;
}

#introWatermark {
  margin: 4px auto 10px;
  text-align: center !important;
  font-size: clamp(0.58rem, 1.8vw, 0.72rem);
  letter-spacing: 0.8px;
  color: rgba(6, 84, 116, 0.58);
  user-select: none;
  pointer-events: none;
  opacity: 0.78;
}

/* Game over — rustig, Fredoka, groene CTA */
#endScreen .card,
#endScreen .end-card {
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.98), rgba(232, 250, 255, 0.96));
  border-color: #d4f4ff;
  font-family: Fredoka, "Trebuchet MS", system-ui, sans-serif;
  max-width: min(420px, 94vw);
  padding: 1.15rem 1.2rem 1.1rem;
}

#endScreen .card h2 {
  font-family: Fredoka, system-ui, sans-serif;
  font-weight: 800;
  font-size: clamp(1.45rem, 4.5vw, 1.85rem);
  color: #ff2f87;
  text-shadow: none;
  margin: 0 0 0.85rem;
  letter-spacing: 0.01em;
}

.end-score-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  margin: 0 0 0.55rem;
}

.end-score-label {
  font-family: Fredoka, system-ui, sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(7, 81, 113, 0.55);
}

#endScore,
.end-score-value {
  margin: 0 !important;
  font-family: Fredoka, system-ui, sans-serif !important;
  font-size: clamp(2rem, 7vw, 2.75rem) !important;
  font-weight: 800 !important;
  line-height: 1 !important;
  color: #0a5f82 !important;
  letter-spacing: -0.02em;
}

#endHighscore,
.end-highscore {
  margin: 0 0 0.35rem !important;
  font-family: Fredoka, system-ui, sans-serif !important;
  font-size: 0.95rem !important;
  font-weight: 600 !important;
  color: rgba(10, 110, 145, 0.78) !important;
}

#endQuizStats,
.end-quiz-stats {
  margin: 0 0 0.85rem !important;
  font-family: Fredoka, system-ui, sans-serif !important;
  font-size: 0.82rem !important;
  font-weight: 500 !important;
  color: rgba(7, 90, 120, 0.72) !important;
  letter-spacing: 0.01em;
  line-height: 1.35;
  max-width: 22rem;
  margin-left: auto !important;
  margin-right: auto !important;
}

#endScreen .end-hs-prompt {
  font-family: Fredoka, system-ui, sans-serif;
  font-size: 0.9rem !important;
  font-weight: 600 !important;
  color: #0a6d94 !important;
  margin-bottom: 0.5rem !important;
}

#newHighscoreWrap.hidden {
  display: none;
}

#highscoreForm {
  display: grid;
  grid-template-columns: minmax(220px, 1fr);
  gap: 8px;
  justify-content: center;
  margin-bottom: 12px;
  width: min(320px, 100%);
  margin-left: auto;
  margin-right: auto;
}

#playerNameInput,
#schoolNameInput {
  width: 100%;
  min-width: 220px;
  border: 2px solid #b9efff;
  border-radius: 999px;
  padding: 10px 14px;
  font-family: Fredoka, system-ui, sans-serif;
  font-size: 1rem;
  font-weight: 600;
  outline: none;
}

#playerNameInput:focus,
#schoolNameInput:focus {
  border-color: #59cfff;
  box-shadow: 0 0 0 3px rgba(89, 207, 255, 0.2);
}

#top5Wrap {
  margin: 0.35rem auto 1rem;
  width: min(300px, 100%);
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
}

#top5Wrap h3 {
  margin: 0 0 0.45rem;
  font-family: Fredoka, system-ui, sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(11, 124, 168, 0.7);
}

#top5List {
  margin: 0;
  padding-left: 1.15rem;
  text-align: left;
  color: #045070;
  font-family: Fredoka, system-ui, sans-serif;
  font-weight: 600;
  font-size: 0.88rem;
}

#top5List li {
  margin: 0.35rem 0;
}

.end-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
  margin-top: 0.25rem;
}

/* Kleine groene CTA (zelfde feel als LEES MEER elders) */
#restartBtn,
.end-btn-primary {
  margin: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.32rem 1.05rem;
  min-height: 1.85rem;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  background:
    radial-gradient(circle at 18% 0%, rgba(255, 255, 255, 0.28) 0, transparent 42%),
    linear-gradient(135deg, #34d399 0%, #22c55e 55%, #16a34a 100%);
  color: #fff !important;
  font-family: Fredoka, system-ui, sans-serif;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(22, 163, 74, 0.28);
  transition: transform 0.15s ease, filter 0.15s ease;
}

#restartBtn:hover,
.end-btn-primary:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
  color: #fff !important;
}

.end-btn-home,
a.end-btn-home {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.32rem 1.05rem;
  min-height: 1.85rem;
  border-radius: 999px;
  border: 1.5px solid rgba(10, 109, 148, 0.35);
  background: rgba(255, 255, 255, 0.92);
  color: #0a6d94 !important;
  font-family: Fredoka, system-ui, sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-decoration: none;
  box-shadow: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.end-btn-home:hover,
.end-btn-home:focus-visible {
  background: #f0fcff;
  border-color: rgba(10, 109, 148, 0.55);
  color: #054a66 !important;
}

/* legacy share UI removed */
#shareOptionsWrap,
#shareGameBtn,
#shareWhatsappBtn,
#shareFacebookBtn,
.end-home-link {
  display: none !important;
}

.top5NameLine {
  display: block;
}

.top5SchoolLine {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  color: #0f769f;
  opacity: 0.9;
}

button {
  border: none;
  border-radius: 999px;
  padding: 12px 22px;
  font-size: 1.05rem;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(120deg, #00a9ff, #00d4a5);
  cursor: pointer;
}

#mobileControls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(10px, env(safe-area-inset-bottom));
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 0;
  pointer-events: none;
  z-index: 6;
}

.quiz-blast-tip {
  pointer-events: none;
  margin: 0 auto 5px;
  padding: 4px 10px;
  max-width: min(92vw, 300px);
  font-size: 0.66rem;
  font-weight: 800;
  line-height: 1.22;
  letter-spacing: 0.02em;
  text-align: center;
  color: #063d52;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(90, 190, 240, 0.92);
  border-radius: 10px;
  box-shadow: 0 3px 10px rgba(0, 70, 110, 0.14);
}

.quiz-blast-tip.hidden {
  display: none !important;
}

.quiz-blast-tip-emoji {
  display: inline;
}

#waterBtn {
  pointer-events: auto;
  min-width: 180px;
  min-height: 64px;
  font-size: 1.25rem;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.24);
}

#levelBanner {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.92);
  padding: 14px 22px;
  border-radius: 22px;
  border: 3px solid rgba(255, 255, 255, 0.96);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.96), rgba(224, 252, 255, 0.94));
  color: #ff2f87;
  font-size: clamp(1.7rem, 6.5vw, 3.4rem);
  font-weight: 900;
  letter-spacing: 1px;
  text-shadow: 0 2px 0 #fff, 0 10px 20px rgba(255, 47, 135, 0.3);
  box-shadow: 0 16px 34px rgba(0, 80, 118, 0.24);
  opacity: 0;
  pointer-events: none;
  z-index: 9;
  transition: opacity 220ms ease, transform 220ms ease;
}

#levelBanner.visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

#levelBanner.bonusPoints {
  text-align: center;
  min-width: min(64vw, 360px);
  padding: 10px 18px 12px;
}

#levelBanner .bonusTextSmall {
  display: block;
  font-size: clamp(0.92rem, 2.4vw, 1.15rem);
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #0f769f;
  text-shadow: 0 1px 0 #fff;
}

#levelBanner .bonusPointsBig {
  display: block;
  margin-top: 2px;
  font-size: clamp(2.1rem, 9vw, 4rem);
  line-height: 0.95;
  font-weight: 900;
  letter-spacing: 1px;
  color: #ff2f87;
  text-shadow: 0 2px 0 #fff, 0 10px 20px rgba(255, 47, 135, 0.3);
}

@media (max-width: 900px), (hover: none) and (pointer: coarse) {
  #introScreen {
    align-items: flex-start;
    padding: max(8px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
    overflow-y: auto;
  }
  #introScreen .card {
    width: min(96vw, 560px);
    margin: 0 auto;
    max-height: calc(100vh - max(12px, env(safe-area-inset-top)) - max(12px, env(safe-area-inset-bottom)));
    overflow-y: auto;
    border-radius: 16px;
    padding: 12px 12px 10px;
    background: linear-gradient(165deg, rgba(255, 255, 255, 0.99), rgba(242, 251, 255, 0.97));
    border-color: #e8f8ff;
    box-shadow: 0 8px 18px rgba(0, 108, 148, 0.14);
  }
  #introScreen .card h1 {
    margin-bottom: 6px;
    font-size: clamp(1.45rem, 8.2vw, 2.05rem);
    letter-spacing: 1.3px;
  }
  #introScreen .card h1 .ctMark {
    padding: 0 5px 1px;
    border-radius: 8px;
  }
  #introScreen .card h1 small {
    margin-top: 2px;
    font-size: clamp(0.62rem, 3vw, 0.82rem);
    letter-spacing: 0.85px;
  }
  #introScreen .card p {
    font-size: 0.82rem;
    margin-bottom: 6px;
    max-width: 100%;
  }
  #introScreen .card ul {
    max-width: 100%;
    margin-bottom: 8px;
    padding-left: 4px;
  }
  #introScreen .card li {
    margin: 4px 0;
    font-size: 0.76rem;
    line-height: 1.23;
  }
  #introWatermark {
    margin: 2px auto 7px;
    font-size: 0.56rem;
    letter-spacing: 0.45px;
  }
  #startBtn {
    font-size: 0.92rem;
    padding: 9px 14px;
    min-height: 40px;
  }
  #endScreen {
    align-items: flex-start;
    padding: max(8px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
    overflow-y: auto;
  }
  #endScreen .card {
    width: min(96vw, 560px);
    margin: 0 auto;
    max-height: calc(100vh - max(12px, env(safe-area-inset-top)) - max(12px, env(safe-area-inset-bottom)));
    overflow-y: auto;
    border-radius: 16px;
    padding: 12px 12px 10px;
  }
  #endScreen .card h2 {
    font-size: clamp(1.35rem, 6.6vw, 1.8rem);
    margin-bottom: 6px;
  }
  #endScreen .card p {
    font-size: 0.88rem;
    margin-bottom: 6px;
  }
  #endQuizStats {
    font-size: 0.74rem;
    margin-bottom: 6px;
  }
  #top5Wrap {
    margin: 6px auto 10px;
    width: min(300px, 94%);
    padding: 8px 10px;
  }
  #top5Wrap h3 {
    font-size: 0.92rem;
    margin-bottom: 6px;
  }
  #top5List {
    padding-left: 18px;
    font-size: 0.82rem;
  }
  #top5List li {
    margin: 4px 0;
  }
  .top5NameLine {
    font-size: 0.8rem;
  }
  #shareGameBtn {
    padding: 5px 9px;
    font-size: 0.66rem;
    min-height: 34px;
  }
  #shareOptionsWrap {
    gap: 4px;
    margin-top: 6px;
    flex-wrap: nowrap;
  }
  #shareOptionsWrap a,
  #shareOptionsWrap button {
    padding: 5px 9px;
    font-size: 0.66rem;
    min-height: 30px;
  }
  .end-home-link {
    margin-top: 10px;
    padding: 7px 14px;
    font-size: 0.74rem;
  }
  #finalQuizOverlay .finalQuizCard h2 {
    font-size: clamp(1.2rem, 5.5vw, 1.75rem);
    margin-bottom: 4px;
  }
  #finalQuizOverlay .finalQuizSub {
    font-size: 0.78rem !important;
    margin-bottom: 4px !important;
  }
  #finalQuizOverlay .finalQuizPrompt {
    font-size: clamp(0.95rem, 3.6vw, 1.15rem) !important;
    margin: 6px 0 10px !important;
  }
  #finalQuizOverlay .finalQuizBtn {
    min-width: 64px;
    min-height: 50px;
    font-size: 1.2rem;
  }
  #finalQuizSkip {
    font-size: 0.82rem;
    padding: 8px 16px;
  }
  #highscoreHud {
    top: 6px;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    z-index: 8;
  }
  #hud {
    top: 34px;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    gap: 3px;
    max-width: 96vw;
    justify-content: center;
    flex-wrap: nowrap;
    z-index: 8;
  }
  #hud > div {
    padding: 3px 6px;
    font-size: 0.62rem;
    line-height: 1;
    white-space: nowrap;
  }
  #highscoreHud > div {
    padding: 4px 8px;
    font-size: 0.66rem;
    line-height: 1.15;
    white-space: normal;
    max-width: min(92vw, 300px);
  }
  #highscore .highscoreSchoolLine {
    font-size: 0.56rem;
    margin-top: 1px;
  }
  #energyBar { width: 88px; height: 10px; }
  #footerBar {
    left: 0;
    right: 0;
    bottom: max(6px, env(safe-area-inset-bottom));
    justify-content: center;
    z-index: 8;
  }
  #energyWrap {
    padding: 5px 8px;
    gap: 6px;
    max-width: min(96vw, 420px);
  }
  #energyWrap > span {
    font-size: 0.7rem;
  }
  #energyWrap.energy-mode-timer > span {
    font-size: clamp(0.48rem, 2.85vw, 0.58rem);
    letter-spacing: 0;
    line-height: 1.05;
  }
  .top5SchoolLine {
    font-size: 0.68rem;
  }
  #mobileControls {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    bottom: calc(max(10px, env(safe-area-inset-bottom)) + 40px);
    z-index: 9;
  }
  .quiz-blast-tip {
    font-size: clamp(0.61rem, 2.9vw, 0.72rem);
    padding: 3px 9px;
    margin-bottom: 4px;
    max-width: min(90vw, 280px);
  }
  #waterBtn {
    min-width: 136px;
    min-height: 50px;
    font-size: 1rem;
  }
  #playerNameInput,
  #schoolNameInput {
    min-width: 170px;
    width: min(250px, 82vw);
    font-size: 0.9rem;
    padding: 9px 12px;
  }
  #levelBanner {
    padding: 10px 14px;
    border-radius: 16px;
    max-width: 92vw;
    text-align: center;
    font-size: clamp(1rem, 4.2vw, 1.45rem);
    line-height: 1.12;
  }
  #levelBanner.bonusPoints {
    min-width: min(84vw, 320px);
    padding: 8px 12px 10px;
  }
  #levelBanner .bonusTextSmall {
    font-size: clamp(0.8rem, 3vw, 0.98rem);
  }
  #levelBanner .bonusPointsBig {
    font-size: clamp(1.8rem, 12vw, 3rem);
  }
}

@media (max-width: 720px) {
  #endScreen .end-card {
    padding: 0.95rem 0.85rem 0.9rem;
  }
  #endScore,
  .end-score-value {
    font-size: clamp(1.75rem, 9vw, 2.35rem) !important;
  }
  #endQuizStats,
  .end-quiz-stats {
    font-size: 0.74rem !important;
  }
  #top5List {
    font-size: 0.8rem;
  }
  .end-btn-primary,
  #restartBtn,
  .end-btn-home {
    width: min(100%, 260px);
  }
}

