* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  height: 100%;
}

body.page-addition {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  font-family: 'Fredoka', system-ui, sans-serif;
  color: #1f2a44;
  background:
    radial-gradient(ellipse 90% 70% at 12% 8%, rgba(90, 190, 255, 0.35), transparent 55%),
    radial-gradient(ellipse 80% 55% at 92% 18%, rgba(62, 207, 142, 0.28), transparent 50%),
    radial-gradient(ellipse 70% 50% at 48% 100%, rgba(255, 120, 140, 0.22), transparent 55%),
    linear-gradient(165deg, #eef6ff 0%, #e8fff6 48%, #f0f4ff 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.home-link {
  position: absolute;
  top: 12px;
  left: 16px;
  z-index: 5;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-decoration: none;
  color: #4a5a7a;
}

.home-link:hover {
  color: #1f2a44;
}

.game {
  width: min(640px, 100%);
  height: 100%;
  max-height: 100%;
  padding: clamp(36px, 4.5vh, 52px) 16px clamp(8px, 1.5vh, 16px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 1.2vh, 12px);
  min-height: 0;
}

.game-header {
  text-align: center;
  flex-shrink: 0;
}

.game-title {
  margin: 0;
  font-size: clamp(1.55rem, 4.2vh, 2.2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #1f2a44;
  line-height: 1.1;
}

.game-prompt {
  margin: 4px 0 0;
  font-size: clamp(0.95rem, 2.2vh, 1.15rem);
  font-weight: 500;
  color: #4a5a7a;
  line-height: 1.25;
}

.stage-wrap {
  width: auto;
  height: min(26vh, 220px);
  aspect-ratio: 16 / 9;
  max-width: min(100%, 560px);
  border-radius: 20px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.55);
  box-shadow: 0 10px 28px rgba(50, 80, 140, 0.12);
  flex-shrink: 0;
}

#stage {
  display: block;
  width: 100%;
  height: 100%;
}

.choices {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: clamp(8px, 1.2vh, 12px);
  width: 100%;
  max-width: 420px;
  flex-shrink: 0;
}

.choices[hidden],
.typed[hidden] {
  display: none !important;
}

.choice {
  appearance: none;
  border: none;
  cursor: pointer;
  width: clamp(56px, 8vh, 76px);
  height: clamp(56px, 8vh, 76px);
  border-radius: 18px;
  font-family: inherit;
  font-size: clamp(1.4rem, 3.8vh, 1.9rem);
  font-weight: 700;
  color: #1f2a44;
  background: #ffffff;
  box-shadow: 0 5px 0 #c8d6f0, 0 8px 18px rgba(50, 80, 140, 0.12);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

.choice:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 7px 0 #c8d6f0, 0 12px 22px rgba(50, 80, 140, 0.16);
}

.choice:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #c8d6f0, 0 5px 12px rgba(50, 80, 140, 0.1);
}

.choice:focus-visible {
  outline: 3px solid #3d9cf0;
  outline-offset: 3px;
}

.choice:disabled {
  cursor: default;
  opacity: 0.85;
}

.choice.correct {
  background: #8ef0a8;
  box-shadow: 0 5px 0 #4cb86a, 0 8px 18px rgba(40, 140, 70, 0.2);
}

.choice.wrong {
  background: #ffd0d8;
  box-shadow: 0 5px 0 #e8909c, 0 8px 18px rgba(180, 70, 90, 0.15);
  animation: shake 0.35s ease;
}

.typed {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(6px, 1vh, 10px);
  width: 100%;
  max-width: min(260px, 42vh);
  flex-shrink: 0;
}

.typed-display {
  width: 100%;
  min-height: clamp(40px, 5.8vh, 56px);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  font-size: clamp(1.6rem, 4vh, 2.2rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #1f2a44;
  background: #ffffff;
  box-shadow: 0 4px 0 #c8d6f0, 0 8px 18px rgba(50, 80, 140, 0.12);
}

.typed-display.empty {
  color: #a0aec8;
}

.typed-display.correct {
  background: #8ef0a8;
  box-shadow: 0 4px 0 #4cb86a, 0 8px 18px rgba(40, 140, 70, 0.2);
}

.typed-display.wrong {
  background: #ffd0d8;
  box-shadow: 0 4px 0 #e8909c, 0 8px 18px rgba(180, 70, 90, 0.15);
  animation: shake 0.35s ease;
}

.digit-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(5px, 0.9vh, 8px);
  width: 100%;
}

.digit {
  appearance: none;
  border: none;
  cursor: pointer;
  height: clamp(34px, 5vh, 46px);
  border-radius: 14px;
  font-family: inherit;
  font-size: clamp(1.15rem, 3.2vh, 1.45rem);
  font-weight: 700;
  color: #1f2a44;
  background: #ffffff;
  box-shadow: 0 4px 0 #c8d6f0, 0 6px 14px rgba(50, 80, 140, 0.1);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.digit:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #c8d6f0, 0 10px 18px rgba(50, 80, 140, 0.14);
}

.digit:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #c8d6f0, 0 4px 10px rgba(50, 80, 140, 0.1);
}

.digit:focus-visible {
  outline: 3px solid #3d9cf0;
  outline-offset: 2px;
}

.digit:disabled {
  cursor: default;
  opacity: 0.7;
}

.digit.clear {
  grid-column: span 2;
  font-size: clamp(0.9rem, 2.4vh, 1.05rem);
  letter-spacing: 0.02em;
}

.typed-submit {
  appearance: none;
  border: none;
  cursor: pointer;
  width: 100%;
  min-height: clamp(36px, 5vh, 46px);
  border-radius: 14px;
  font-family: inherit;
  font-size: clamp(1.05rem, 2.8vh, 1.25rem);
  font-weight: 700;
  color: #ffffff;
  background: #3d9cf0;
  box-shadow: 0 4px 0 #2a6fb0, 0 6px 14px rgba(50, 80, 140, 0.18);
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}

.typed-submit:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #2a6fb0, 0 10px 18px rgba(50, 80, 140, 0.2);
}

.typed-submit:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #2a6fb0, 0 4px 10px rgba(50, 80, 140, 0.12);
}

.typed-submit:focus-visible {
  outline: 3px solid #1f2a44;
  outline-offset: 2px;
}

.typed-submit:disabled {
  cursor: default;
  opacity: 0.45;
  box-shadow: 0 4px 0 #7aa8d0, 0 6px 14px rgba(50, 80, 140, 0.08);
}

.feedback {
  min-height: 1.25em;
  margin: 0;
  font-size: clamp(1rem, 2.4vh, 1.15rem);
  font-weight: 600;
  text-align: center;
  color: #4a5a7a;
  flex-shrink: 0;
}

.feedback.success {
  color: #1f8a45;
}

.feedback.retry {
  color: #c45a6a;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* Shorter desktop heights: keep typed pad fully on-screen */
@media (max-height: 820px) {
  .stage-wrap {
    height: min(22vh, 180px);
  }
}

@media (max-height: 720px) {
  .stage-wrap {
    height: min(18vh, 150px);
    border-radius: 16px;
  }

  .game {
    padding-top: clamp(28px, 3.5vh, 40px);
  }
}

/* Phones / narrow screens may scroll */
@media (max-width: 480px) {
  body.page-addition {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    justify-content: flex-start;
  }

  .game {
    height: auto;
    max-height: none;
    padding: 52px 14px 24px;
    gap: 12px;
    justify-content: flex-start;
  }

  .stage-wrap {
    width: 100%;
    height: auto;
    max-width: 100%;
    aspect-ratio: 16 / 9;
    border-radius: 16px;
  }

  .choice {
    border-radius: 16px;
  }

  .typed {
    max-width: 280px;
  }

  .typed-display {
    border-radius: 16px;
  }

  .digit {
    border-radius: 12px;
    height: 48px;
  }

  .typed-submit {
    border-radius: 12px;
    min-height: 48px;
  }
}
