* {
  box-sizing: border-box;
}

html.game-root {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 12px;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100%;
  background: #ffffff;
  font-family: 'Poppins', sans-serif;
  margin: 0;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.fonts-loading .game-container {
  opacity: 0;
}

.game-container {
  position: relative;
  box-shadow: 0 8px 28px rgba(45, 90, 78, 0.12);
  border-radius: 16px;
  overflow: hidden;
  width: min(600px, 100vw, 100dvh);
  height: min(600px, 100vw, 100dvh);
  max-width: 100%;
  max-height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  isolation: isolate;
  touch-action: none;
  transition: opacity 0.14s ease-out;
}

.startup-overlay {
  position: absolute;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(58, 46, 37, 0.4);
  backdrop-filter: blur(1.5px);
  -webkit-backdrop-filter: blur(1.5px);
  pointer-events: auto;
}

.startup-overlay.hidden {
  display: none;
}

.startup-card {
  width: min(460px, calc(100% - 56px));
  border-radius: 14px;
  padding: 26px 26px 24px;
  background: linear-gradient(165deg, #f5ece2 0%, #eee0ce 45%, #e4d2bf 100%);
  border: 2px solid rgba(125, 102, 77, 0.45);
  color: #4d3a2a;
  text-align: center;
  box-shadow: 0 12px 30px rgba(58, 46, 37, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.startup-card h1 {
  margin: 0 0 10px;
  font-family: 'Press Start 2P', cursive;
  font-size: clamp(18px, 4.2vw, 26px);
  color: #5f7e51;
  line-height: 1.35;
  letter-spacing: 0.02em;
}

.startup-subtitle {
  margin: 0 0 16px;
  font-family: 'Poppins', sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  color: #8b6749;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.startup-copy {
  margin: 10px 0;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  color: #4a3828;
}

.startup-play-btn {
  margin-top: 18px;
  min-width: 210px;
  padding: 11px 22px;
  border-radius: 10px;
  border: 2px solid #4b6640;
  background: linear-gradient(180deg, #7fa06f 0%, #5f7e51 100%);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  font-family: 'Poppins', sans-serif;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(79, 59, 43, 0.22);
}

.startup-play-btn:hover {
  background: linear-gradient(180deg, #89aa79 0%, #688958 100%);
}

.startup-play-btn:active {
  transform: translateY(1px);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  background-color: #1e332c;
  border-radius: inherit;
  touch-action: none;
}

.sound-toggle {
  position: absolute;
  bottom: 12px;
  right: 12px;
  z-index: 60;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 2px solid #4A7C7A;
  border-radius: 8px;
  background: rgba(224, 201, 166, 0.9);
  color: #4A7C7A;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.1s, border-color 0.2s;
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.sound-toggle:hover {
  background: rgba(232, 212, 184, 0.95);
  border-color: #5AA4A1;
}

.sound-toggle:active {
  transform: scale(0.94);
}

.sound-toggle .sound-icon {
  position: absolute;
  width: 20px;
  height: 20px;
}

.sound-toggle .sound-off {
  display: none;
}

.sound-toggle.muted {
  background: rgba(224, 201, 166, 0.6);
  color: #2F4F4F;
  border-color: #2F4F4F;
}

.sound-toggle.muted:hover {
  background: rgba(224, 201, 166, 0.8);
}

.sound-toggle.muted .sound-on {
  display: none;
}

.sound-toggle.muted .sound-off {
  display: block;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(58, 46, 37, 0.42);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding: 20px;
  box-sizing: border-box;
  touch-action: none;
  overscroll-behavior: contain;
}

.mode-modal {
  z-index: 1200;
}

.mode-content {
  max-width: 360px;
}

.mode-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#modeDescription {
  margin: 0 0 18px;
  color: #5b4734;
  font-size: 0.98em;
  font-weight: 600;
}

.quiz-content {
  background: linear-gradient(165deg, #f5ece2 0%, #eee0ce 45%, #e4d2bf 100%);
  padding: 22px;
  border-radius: 16px;
  box-shadow: 0 10px 36px rgba(45, 90, 78, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.85);
  text-align: center;
  max-width: 400px;
  width: 100%;
  min-width: 280px;
  color: #4d3a2a;
  border: 2px solid rgba(125, 102, 77, 0.45);
  max-height: 90vh;
  overflow-y: auto;
  box-sizing: border-box;
  touch-action: pan-y;
}

.quiz-content h2 {
  margin-top: 0;
  margin-bottom: 15px;
  font-weight: 700;
  font-size: 1.35em;
  color: #2d5a4e;
  font-family: 'Press Start 2P', cursive;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.9);
  word-wrap: break-word;
  letter-spacing: 0.02em;
}

.quiz-hint {
  font-size: 0.78em;
  color: #5a8a7e;
  margin-bottom: 15px;
  margin-top: -12px;
  font-style: italic;
  display: none;
}

.quiz-content p#quizQuestionText {
  margin-bottom: 20px;
  color: #35564e;
  font-size: 1.02em;
  line-height: 1.45;
  font-weight: 600;
  word-wrap: break-word;
}

.quiz-feedback {
  min-height: 1.2em;
  margin: -6px 0 14px;
  color: #8b3f2f;
  font-size: 0.9em;
  font-weight: 700;
}

#quizOptionsContainer {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.answer-button {
  padding: 11px 16px;
  font-size: 0.9em;
  font-family: 'Poppins', sans-serif;
  font-weight: 600;
  cursor: pointer;
  background-color: rgba(255, 248, 240, 0.92);
  color: #4a3828;
  border: 2px solid rgba(128, 100, 72, 0.38);
  border-radius: 10px;
  transition: background-color 0.2s ease, transform 0.1s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 2px 8px rgba(45, 90, 78, 0.08);
  word-wrap: break-word;
  white-space: normal;
  text-align: center;
}

.answer-button:hover {
  background-color: #fffdf9;
  border-color: rgba(108, 137, 91, 0.68);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(45, 90, 78, 0.12);
}

.answer-button:active {
  transform: translateY(0);
  box-shadow: 0 1px 4px rgba(45, 90, 78, 0.1);
}

.answer-button.selected {
  background: linear-gradient(180deg, #7fa06f 0%, #5f7e51 100%);
  border-color: #4b6640;
  color: #fff;
  transform: scale(1.01);
  box-shadow: 0 4px 14px rgba(61, 138, 128, 0.35);
}

.answer-button.disabled,
.answer-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  background: #d6d6d6;
  border-color: #b8b8b8;
  color: #666;
  transform: none;
  box-shadow: none;
}

.question-progress {
  width: min(420px, calc(100% - 40px));
  margin-top: 2px;
  color: #4f3b2b;
  text-align: center;
}

.question-progress p {
  margin: 0 0 8px;
  font-size: 0.9em;
  font-weight: 700;
}

.question-progress-track {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: rgba(86, 65, 44, 0.14);
  border: 1px solid rgba(86, 65, 44, 0.25);
  overflow: hidden;
}

.question-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #7e9f6f 0%, #a5754c 100%);
  transition: width 0.25s ease;
}

body.quiz-only-mode {
  justify-content: center;
  align-items: center;
  flex-direction: column;
  overflow: hidden;
}

body.quiz-only-mode .game-container {
  display: none;
}

body.quiz-only-mode #quizModal {
  position: static;
  width: auto;
  height: auto;
  background: transparent;
  padding: 0;
  z-index: 900;
}

body.quiz-only-mode #questionProgress {
  display: block !important;
}

@media (max-width: 480px) {
  .quiz-content {
    padding: 15px;
    max-width: 95%;
  }
  .quiz-content h2 {
    font-size: 1.2em;
  }
  .quiz-content p#quizQuestionText {
    font-size: 0.9em;
  }
  .answer-button {
    padding: 8px 12px;
    font-size: 0.85em;
  }
}
