@import url("https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;700;800&family=Nunito:wght@600;800;900&display=swap");
:root {
  font-family: Nunito, system-ui, sans-serif;
  color: #293850;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: #283950;
  overflow: hidden;
}
button,
input {
  font: inherit;
}
button {
  cursor: pointer;
  touch-action: manipulation;
}
#game {
  position: relative;
  margin: auto;
  width: min(100vw, 650px);
  height: 100dvh;
  overflow: hidden;
  background: linear-gradient(#55bada, #b9edec);
  box-shadow: 0 0 80px #101b2e;
}
#scene,
#scene canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#scene canvas {
  touch-action: none;
}
.hidden {
  display: none !important;
}
#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(180deg, #26466699, #21334bb9);
  backdrop-filter: blur(7px);
  z-index: 10;
  padding: 20px;
}
.panel {
  width: min(100%, 390px);
  max-height: 92%;
  overflow: auto;
  text-align: center;
  background: #fffaf0;
  border: 5px solid #fff;
  box-shadow:
    0 20px 0 #21384d50,
    0 28px 55px #13233677;
  border-radius: 29px;
  padding: 24px 22px;
}
.emblem {
  font-size: 48px;
  color: #f0b644;
  text-shadow: 2px 4px #bb7047;
}
h1,
h2,
.brand,
#equation,
#introCard {
  font-family: "Baloo 2", system-ui, sans-serif;
}
h1 {
  font-size: clamp(46px, 12vw, 68px);
  line-height: 0.81;
  color: #365476;
  margin: 10px 0 20px;
  text-shadow: 3px 4px #dce1d5;
}
h1 span {
  color: #dd8054;
}
h2 {
  font-size: 36px;
  color: #334f70;
  margin: 6px 0 10px;
  line-height: 1;
}
.tagline,
.panel p {
  color: #78889b;
  font-weight: 800;
  margin: 9px 0 21px;
}
label {
  display: block;
  text-align: left;
  color: #55728b;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 2px;
  margin-bottom: 5px;
}
input {
  width: 100%;
  padding: 14px 16px;
  border: 3px solid #d8e5e4;
  border-radius: 14px;
  background: #fff;
  font-size: 18px;
  outline: none;
  color: #293850;
}
input:focus {
  border-color: #eaa566;
}
.actions {
  display: grid;
  gap: 9px;
  margin-top: 18px;
}
.panel button {
  display: block;
  width: 100%;
  min-height: 51px;
  border: 0;
  border-radius: 14px;
  font-weight: 900;
  letter-spacing: 0.6px;
  margin: 9px 0;
  transition:
    transform 0.15s,
    filter 0.15s;
}
.panel button:active,
#answers button:active {
  transform: scale(0.95);
}
.primary {
  background: #ee9e58;
  color: #fff;
  box-shadow:
    inset 0 -5px #d47546,
    0 5px 0 #cba47c;
  font-size: 18px;
}
.primary span {
  float: right;
  padding-right: 13px;
}
.secondary {
  background: #dcefeb;
  color: #3a6774;
  box-shadow: inset 0 -4px #b2d4d3;
}
.text-button {
  background: transparent;
  color: #82949c;
}
.panel button:hover {
  filter: brightness(1.05);
}
#levelGrid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  max-height: 43vh;
  overflow: auto;
}
#levelGrid button {
  margin: 0;
  min-height: 94px;
}
#levelGrid button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
#hud {
  position: absolute;
  z-index: 2;
  inset: 0;
  pointer-events: none;
}
.brand {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 17px;
  color: #fff;
  font-size: 20px;
  font-weight: 800;
  line-height: 0.85;
  text-shadow: 0 2px 4px #37536b;
}
.brand b {
  color: #ffe5a2;
}
.brand small {
  display: block;
  font: 900 11px Nunito;
  margin-top: 7px;
  letter-spacing: 1px;
}
.height {
  position: absolute;
  top: 75px;
  right: 13px;
  display: flex;
  align-items: center;
  flex-direction: column;
  color: #fff;
  font-size: 13px;
  text-shadow: 0 1px 3px #20354d;
}
.rail {
  height: min(38vh, 280px);
  width: 12px;
  border-radius: 9px;
  background: #ffffff77;
  border: 2px solid white;
  position: relative;
  overflow: hidden;
  margin: 5px;
}
.rail div {
  position: absolute;
  bottom: 0;
  width: 100%;
  background: #f7b655;
  transition: height 0.5s;
}
.icon {
  position: absolute;
  top: max(15px, env(safe-area-inset-top));
  right: 16px;
  border: 2px solid #ffffffb0;
  background: #2b4e6c9c;
  color: white;
  border-radius: 13px;
  font-size: 23px;
  width: 45px;
  height: 45px;
  pointer-events: auto;
}
#viewBtn {left:16px;right:auto;top:max(65px,calc(env(safe-area-inset-top) + 50px));height:53px;font-size:24px;line-height:1}
#viewBtn small {display:block;font-size:9px;letter-spacing:.5px}
#viewBtn[aria-pressed="true"] {background:#ca8850;border-color:#ffe5a2}
#prompt {
  position: absolute;
  bottom: max(8px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: min(92%, 410px);
  z-index: 4;
}
.question-card {
  background: #fffaf0;
  border: 4px solid white;
  border-radius: 25px;
  box-shadow:
    0 10px 0 #39546a66,
    0 22px 35px #23334465;
  padding: 13px 17px 15px;
  text-align: center;
}
.question-card small {
  font-weight: 900;
  letter-spacing: 2px;
  color: #9d927c;
}
#equation {
  font-size: clamp(33px, 9vw, 53px);
  font-weight: 800;
  line-height: 1.2;
  color: #314e69;
}
#answers {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
#answers button {
  height: clamp(61px, 10vh, 83px);
  font-size: clamp(26px, 7vw, 36px);
  font-weight: 900;
  color: #3c6380;
  background: #e0f2e9;
  border: 3px solid white;
  border-radius: 16px;
  box-shadow: inset 0 -5px #b6dbd2;
  transition:
    transform 0.14s,
    background 0.14s;
}
#answers button.correct {
  background: #98df9f;
  color: #215a43;
  animation: pop 0.3s;
}
#answers button.wrong {
  background: #f4bb9e;
  color: #8c4d44;
}
#answers button:disabled {
  opacity: 1;
}
#prompt:not(.active) .question-card {
  background: #fffaf0df;
}
#prompt:not(.active) #answers button {
  background: #dce9e3;
  color: transparent;
  box-shadow: inset 0 -4px #b3c9c1;
}
#prompt:not(.active) #questionFloor,
#prompt:not(.active) #equation,
#prompt:not(.active) #feedback {
  display: none;
}
#answers button.flip {
  animation: keyFlip 0.23s ease-in-out;
}
#answers button.reveal {
  animation: keyReveal 0.22s ease-out;
}
@keyframes keyFlip {
  50% {
    transform: rotateX(90deg);
  }
}
@keyframes keyReveal {
  from {
    transform: rotateX(-85deg);
  }
  to {
    transform: rotateX(0);
  }
}
#feedback {
  min-height: 17px;
  font-size: 13px;
  font-weight: 900;
  color: #569a70;
}
@keyframes pop {
  50% {
    transform: scale(1.1);
  }
}
#toast {
  position: absolute;
  left: 50%;
  top: 21%;
  transform: translate(-50%, -20px);
  z-index: 7;
  pointer-events: none;
  color: white;
  font: 800 30px "Baloo 2";
  text-shadow: 0 3px 5px #315672;
  opacity: 0;
  transition: 0.25s;
  white-space: nowrap;
}
#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
#introCard {
  position: absolute;
  top: 34%;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  color: white;
  text-shadow: 0 4px 10px #29495c;
  z-index: 5;
  white-space: nowrap;
  pointer-events: none;
}
#introCard strong {
  display: block;
  font-size: clamp(45px, 13vw, 78px);
  line-height: 1;
}
#introCard span {
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 3px;
}
#orientation {
  display: none;
  position: absolute;
  bottom: 7px;
  right: 8px;
  z-index: 6;
  color: white;
  background: #31495a88;
  padding: 4px 9px;
  border-radius: 8px;
  font-size: 11px;
}
@media (max-width: 600px) and (orientation: portrait) {
  #prompt {
    width: min(94%, 410px);
  }
  .question-card {
    padding: 8px 13px 9px;
  }
  #equation {
    font-size: clamp(30px, 8vw, 43px);
  }
  #answers {
    gap: 7px;
  }
  #answers button {
    height: clamp(44px, 6.4vh, 55px);
    font-size: clamp(22px, 6vw, 29px);
    border-radius: 12px;
  }
  #feedback {
    min-height: 14px;
    font-size: 12px;
  }
}
@media (max-height: 500px) and (orientation: landscape) {
  #orientation {
    display: block;
  }
  #prompt {
    bottom: 4px;
    width: min(70%, 540px);
  }
  .question-card {
    padding: 5px 12px;
  }
  #equation {
    font-size: 28px;
  }
  #answers button {
    height: 40px;
    font-size: 22px;
  }
  .height .rail {
    height: 90px;
  }
}
