/* This file controls how everything LOOKS and MOVES. */

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  height: 100vh;
  overflow: hidden;
  background: #06161f;
  font-family: Georgia, "Times New Roman", serif;
  user-select: none;
}

#scene, #vines, #particles {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#vines, #particles { pointer-events: none; overflow: hidden; }

[hidden] { display: none !important; }

/* ---------- Question screen ---------- */

#game {
  position: relative;
  z-index: 2;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 2vh;
  padding: 3vh 20px;
}

#topBar {
  width: min(900px, 100%);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  color: #fff3c4;
  font-size: clamp(18px, 3.5vh, 30px);
  font-weight: bold;
  text-shadow: 0 2px 4px #000;
}

.card {
  width: min(760px, 100%);
  padding: 3.5vh 28px;
  text-align: center;
  color: #3b2610;
  background: #f4e3b5;
  border: 6px solid #6b4a1f;
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.card h2 { font-size: clamp(20px, 4.2vh, 36px); margin-bottom: 3vh; }

#answers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2.5vh 18px;
}

.stone-button.answer { padding: 0.7em 0.6em; }
.stone-button:disabled { cursor: default; transform: none; filter: none; }
.stone-button.answer:disabled:not(.right, .wrong) { opacity: 0.55; }
.stone-button.right { background: linear-gradient(#4fbf45, #23771f); }
.stone-button.wrong { background: linear-gradient(#e0574a, #8f1f17); }

#feedback {
  min-height: 2.8em;
  margin: 2vh 0 1vh;
  font-size: clamp(15px, 2.6vh, 22px);
  font-weight: bold;
}

/* The box for typing answers */
#typeForm { display: flex; flex-wrap: wrap; justify-content: center; gap: 2vh 14px; }

#typeBox {
  flex: 1;
  min-width: 200px;
  padding: 0.5em 0.7em;
  font: bold clamp(18px, 3.2vh, 28px) Georgia, serif;
  color: #3b2610;
  background: #fffbe8;
  border: 4px solid #6b4a1f;
  border-radius: 14px;
  user-select: text;
}

#typeBox.right { background: #c4f0b8; border-color: #23771f; }
#typeBox.wrong { background: #f6c2bb; border-color: #8f1f17; }
#typeForm p { width: 100%; font-size: clamp(14px, 2.3vh, 19px); }

/* keeps the card from jumping when the Next button appears */
#questionCard { min-height: min(470px, 66vh); }

#endCard, #readyCard { margin: auto 0; }
#readyCard p { font-size: 22px; margin-bottom: 28px; }
#endCard p { font-size: 22px; margin-bottom: 16px; }
#endText, #readyText { white-space: pre-line; line-height: 1.5; }
#endCard #endScore { font-size: 30px; font-weight: bold; margin-bottom: 28px; }
#endCard .stone-button { margin: 0 8px 14px; }

/* The path along the bottom. Left side leaves room for the sound button. */
#path {
  position: relative;
  width: min(900px, calc(100% - 340px));
  min-width: 240px;
  height: 18px;
  margin: 5vh 0 1vh;
  background: #a8824a;
  border: 3px solid #4a3414;
  border-radius: 12px;
}

.runner, #goal {
  position: absolute;
  bottom: 0;
  font-size: clamp(30px, 7vh, 60px);
  line-height: 1;
  translate: -50% 0;
}

/* flip the emoji so they face the temple */
.runner { transform: scaleX(-1); transition: left 0.8s ease; }
#explorer { z-index: 1; }
#goal { left: 100%; }

/* The countdown timer */
#timer { display: flex; align-items: center; gap: 14px; margin-bottom: 2.5vh; }

#timerTrack {
  flex: 1;
  height: 18px;
  overflow: hidden;
  background: #cdb57c;
  border: 3px solid #6b4a1f;
  border-radius: 12px;
}

#timerBar { height: 100%; background: #3f9c35; transition: width 0.1s linear; }
#timerText { min-width: 2.6em; font-size: 22px; font-weight: bold; text-align: right; }
#timer.hurry #timerBar  { background: #d12f1f; }
#timer.hurry #timerText { color: #b3190b; }

/* The big tiger that jumps out */
#pounce {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  animation: redFlash 1.4s ease-out forwards;
}

#pounce svg {
  width: min(80vw, 75vh);
  filter: drop-shadow(0 20px 30px rgba(0, 0, 0, 0.7));
  animation: pounce 1.4s ease-out forwards;
}

#pounce p {
  font-size: min(14vw, 14vh);
  font-weight: bold;
  line-height: 1;
  color: #fff;
  text-shadow: 0 6px 0 #8f1f17, 0 0 30px #000;
  animation: pounce 1.4s ease-out forwards;
}

@keyframes redFlash {
  0%, 100% { background: rgba(150, 10, 0, 0); }
  20%, 70% { background: rgba(150, 10, 0, 0.55); }
}

@keyframes pounce {
  0%   { opacity: 0; transform: translateY(40vh) scale(0.1); }
  25%  { opacity: 1; transform: translateY(0) scale(1.15); }
  35%  { transform: translateX(-20px) scale(1); }
  45%  { transform: translateX(20px) scale(1.04); }
  55%  { transform: translateX(-14px) scale(1); }
  75%  { opacity: 1; transform: scale(1.05); }
  100% { opacity: 0; transform: scale(1.7); }
}

.shake { animation: shake 0.45s; }
@keyframes shake { 20%, 60% { translate: -12px 0; } 40%, 80% { translate: 12px 0; } }

/* ---------- Places along the way ---------- */

/* Every place is invisible until you get there, then it fades in. */
.place { opacity: 0; transition: opacity 1.2s; }

body[data-place="river"] .place-river,
body[data-place="cave"]  .place-cave,
body[data-place="gold"]  .place-gold { opacity: 1; }

/* no leaves or vines inside the cave */
.vine, .leaf { transition: opacity 1.2s; }
body[data-place="cave"] .vine { opacity: 0; }
body[data-place="cave"] #particles .leaf { visibility: hidden; }

.falls    { animation: pour 0.7s linear infinite; }
.waves    { animation: slosh 2.5s ease-in-out infinite alternate; }
.croc     { animation: bob 3s ease-in-out infinite; }
.crystals { animation: glow 2s ease-in-out infinite alternate; }
.bat      { animation: flutter 4s ease-in-out infinite alternate; }
.bat-late { animation-delay: -2s; }
.sun-rays { transform-origin: 800px 430px; animation: spin 60s linear infinite; }

@keyframes pour    { to { stroke-dashoffset: -70; } }
@keyframes slosh   { from { translate: -25px 0; } to { translate: 25px 0; } }
@keyframes bob     { 50% { translate: 0 12px; } }
@keyframes flutter { to { translate: 70px -50px; } }
@keyframes spin    { to { rotate: 360deg; } }

#placeSign {
  position: fixed;
  z-index: 5;
  left: 50%;
  bottom: 10vh;
  translate: -50% 0;
  width: max-content;
  max-width: 90vw;
  padding: 0.5em 1.2em;
  font-size: clamp(20px, 4.5vh, 40px);
  font-weight: bold;
  text-align: center;
  color: #fff3c4;
  background: #3d2a10;
  border: 4px solid #ffc233;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  animation: signPop 2.8s ease-out forwards;
}

@keyframes signPop {
  0%        { opacity: 0; scale: 0.4; }
  15%       { opacity: 1; scale: 1.1; }
  25%, 85%  { opacity: 1; scale: 1; }
  100%      { opacity: 0; scale: 1; }
}

/* ---------- Title ---------- */

#menu {
  position: relative;
  z-index: 2;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 5vh 20px 6vh;
  pointer-events: none;
}

h1 {
  text-align: center;
  text-transform: uppercase;
  line-height: 1.05;
  filter: drop-shadow(0 6px 0 #3a1f05) drop-shadow(0 0 28px rgba(255, 176, 46, 0.45));
  animation: float 5s ease-in-out infinite;
}

h1 span {
  display: block;
  background: linear-gradient(#fff3b0, #ffc233 55%, #d9791a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.title-top    { font-size: min(6.4vw, 9vh);  letter-spacing: 0.03em; }
.title-bottom { font-size: min(10vw, 14vh);  letter-spacing: 0.18em; padding-left: 0.18em; }

/* ---------- Buttons ---------- */

.buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2vh;
}

.stone-button {
  pointer-events: auto;
  font-family: inherit;
  font-weight: bold;
  font-size: clamp(16px, 3vh, 28px);
  color: #fff3c4;
  background: linear-gradient(#6f7f68, #3d4b3c);
  border: 3px solid #1c271d;
  border-radius: 14px;
  padding: 0.5em 1.6em;
  cursor: pointer;
  text-shadow: 0 2px 0 #14190f;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.25), 0 6px 0 #1c271d, 0 10px 18px rgba(0, 0, 0, 0.5);
  transition: transform 0.1s, filter 0.1s;
}

.stone-button:hover  { transform: translateY(-3px) scale(1.04); filter: brightness(1.2); }
.stone-button:active { transform: translateY(4px); box-shadow: 0 2px 0 #1c271d; }

button:focus-visible { outline: 4px solid #fff; outline-offset: 4px; }

.stone-button.big {
  font-size: clamp(26px, 6vh, 56px);
  padding: 0.35em 2em;
  text-transform: uppercase;
  background: linear-gradient(#ffcf4d, #d9791a);
  border-color: #4a2606;
  color: #fff;
  text-shadow: 0 3px 0 #7a3d07;
  animation: pulse 2.2s ease-in-out infinite;
}

.stone-button.small {
  position: fixed;
  z-index: 3;
  left: 18px;
  bottom: 22px;
  font-size: clamp(14px, 2.2vh, 20px);
  padding: 0.5em 1em;
}

/* ---------- Pop-ups ---------- */

dialog {
  margin: auto;
  max-width: min(620px, 90vw);
  padding: 28px 34px 34px;
  text-align: center;
  color: #3b2610;
  background: #f4e3b5;
  border: 6px solid #6b4a1f;
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
}

dialog::backdrop { background: rgba(2, 12, 10, 0.7); }
dialog h2 { margin-bottom: 16px; font-size: 30px; }
dialog p  { margin-bottom: 24px; font-size: 20px; }
dialog ol { margin: 0 0 26px 24px; text-align: left; font-size: clamp(15px, 2.6vh, 19px); line-height: 1.4; }
dialog li { margin-bottom: 8px; }

/* The difficulty and topic pickers */
.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px 14px;
  margin-bottom: 28px;
}

.stone-button.topic { padding: 0.6em 0.5em; }
.stone-button.topic:last-child:nth-child(odd) { grid-column: 1 / -1; }
.stone-button.topic small { display: block; margin-top: 4px; font-size: 0.7em; font-weight: normal; }

#levelPopup, #topicPopup { width: min(620px, 90vw); }

/* ---------- Monkey buddy ---------- */

#monkey {
  position: fixed;
  z-index: 3;
  top: -10px;
  right: 7vw;
  width: min(17vw, 30vh);
  min-width: 100px;
  background: none;
  border: none;
  cursor: pointer;
  transform-origin: 50% 0;
  animation: swing 4.5s ease-in-out infinite;
}

#monkey svg { display: block; width: 100%; overflow: visible; }

.wave-arm {
  transform-origin: 125px 218px;
  animation: wave 3s ease-in-out infinite;
}

.monkey-eyes {
  transform-origin: 100px 155px;
  animation: blink 4s infinite;
}

/* On narrow windows, the monkey hangs lower so it does not cover the title. */
@media (max-aspect-ratio: 3/2) {
  #monkey { top: 28vh; right: 3vw; }
}

#speech {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 220px;
  padding: 8px 14px;
  font: bold 17px Georgia, serif;
  color: #3b2610;
  background: #fffbe8;
  border: 3px solid #6b4a1f;
  border-radius: 16px;
}

#speech:empty { display: none; }

/* ---------- Moving scenery ---------- */

.vine {
  position: absolute;
  top: -12px;
  transform-origin: 50% 0;
  animation: swing ease-in-out infinite;
}

.firefly {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #eaff8a;
  box-shadow: 0 0 10px 4px rgba(214, 255, 90, 0.7);
  animation: drift ease-in-out infinite alternate, glow ease-in-out infinite alternate;
}

.leaf {
  position: absolute;
  top: -40px;
  width: 22px;
  height: 12px;
  border-radius: 100% 0;
  animation: fall linear infinite;
}

.door-glow { animation: glow 3s ease-in-out infinite alternate; }
.eyes      { animation: peek 7s infinite; }
.eyes-late { animation-delay: 3.5s; }

/* ---------- Animations ---------- */

@keyframes float { 50% { transform: translateY(-8px); } }
@keyframes pulse { 50% { scale: 1.06; } }
@keyframes swing { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }
@keyframes wave  { 0%, 50%, 100% { transform: rotate(0); } 60%, 80% { transform: rotate(-30deg); } 70%, 90% { transform: rotate(10deg); } }
@keyframes blink { 0%, 93%, 100% { transform: scaleY(1); } 96% { transform: scaleY(0.1); } }
@keyframes peek  { 0%, 55% { opacity: 0; } 60%, 72% { opacity: 1; } 74% { opacity: 0; } 76%, 90% { opacity: 1; } 95%, 100% { opacity: 0; } }
@keyframes glow  { from { opacity: 0.35; } to { opacity: 1; } }
@keyframes drift { to { translate: var(--dx) var(--dy); } }
@keyframes fall  {
  from { transform: translate(0, 0) rotate(0); }
  50%  { transform: translate(60px, 55vh) rotate(260deg); }
  to   { transform: translate(-20px, 112vh) rotate(520deg); }
}

/* Pocket Arcade: the Back button, tucked in the bottom-right corner */
.stone-button.small.arcade-back { left: auto; right: 18px; text-decoration: none; }
