/* --- Base Styles --- */
* {
  box-sizing: border-box;
}

html {
  width: 100%;
  height: 100%;
}

/* Gutter around the largest square board (progress bar + safe breathing room). Uses vmin so wide+short iframes still get a big board. */
:root {
  --game-board-gutter: clamp(28px, 6vmin + 18px, 96px);
}

body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  min-height: 100%;
  min-height: 100dvh;
  background-color: #fff;
  font-family: 'Poppins', sans-serif;
  margin: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.game-container {
  position: relative;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  border-radius: 16px;
  overflow: hidden;
  /* Largest square that fits the viewport (and caps at 600). vmin matches the iframe’s smaller edge in embeds. */
  width: min(600px, calc(100vmin - var(--game-board-gutter)));
  height: min(600px, calc(100vmin - var(--game-board-gutter)));
  max-width: 100%;
  max-height: 100%;
  isolation: isolate;
  touch-action: none;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  background-color: #8FBC8F;
  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;
  -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;
}

/* ---------- VHS OVERLAY ---------- */
.vhs-overlay,
.vhs-overlay * {
  pointer-events: none;
}

.vhs-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  mix-blend-mode: normal;
  border-radius: inherit;
}

.vhs-scanlines {
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(0, 0, 0, 0.10) 0px,
      rgba(0, 0, 0, 0.10) 1px,
      transparent 1px,
      transparent 3px
    );
  opacity: 0.5;
}

.vhs-noise {
  position: absolute;
  inset: 0;
  opacity: 0;
  mix-blend-mode: overlay;
}

.vhs-noise svg {
  width: 100%;
  height: 100%;
  display: block;
}

.vhs-glare {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(60% 35% at 0% 0%, rgba(255, 255, 255, 0.06), transparent 65%),
    radial-gradient(60% 35% at 100% 0%, rgba(255, 255, 255, 0.05), transparent 70%);
  mix-blend-mode: screen;
}

.vhs-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 90%, rgba(0, 0, 0, 0.25) 100%);
}

/* --- Quiz Modal Styles --- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding: 20px;
  box-sizing: border-box;
}

.quiz-content {
  background-color: #FAF0E6;
  padding: 20px;
  border-radius: 16px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.15);
  text-align: center;
  max-width: min(400px, calc(100vw - 24px));
  width: min(400px, calc(100vw - 24px));
  min-width: 0;
  color: #696969;
  border: 3px solid #E0C9A6;
  max-height: min(90vh, calc(100dvh - 24px));
  overflow-y: auto;
  box-sizing: border-box;
}

.quiz-content h2 {
  margin-top: 0;
  margin-bottom: 15px;
  font-weight: 700;
  font-size: clamp(1rem, 3.4vw, 1.4rem);
  color: #8B4513;
  font-family: 'Press Start 2P', cursive;
  text-shadow: 1px 1px #FAF0E6;
  word-wrap: break-word;
}

#quizKeyboardHint {
  font-size: clamp(0.68rem, 2.4vw, 0.8rem);
  color: #A9A9A9;
  margin-bottom: 15px;
  margin-top: -15px;
  font-style: italic;
}

.quiz-content p#quizQuestionText {
  margin-bottom: 20px;
  color: #708090;
  font-size: clamp(0.82rem, 3vw, 1rem);
  line-height: 1.4;
  font-weight: 600;
  word-wrap: break-word;
}

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

.answer-button {
  padding: 10px 15px;
  font-size: clamp(0.72rem, 2.8vw, 0.9rem);
  font-family: 'Poppins', sans-serif;
  font-weight: 600;
  cursor: pointer;
  background-color: #F5E6D3;
  color: #2C3E50;
  border: 2px solid transparent;
  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 4px rgba(0, 0, 0, 0.1);
  word-wrap: break-word;
  white-space: normal;
  text-align: center;
}

.answer-button:hover {
  background-color: #E8D4B8;
  transform: translateY(-1px);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.15);
}

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

.answer-button.selected {
  background-color: #1ABC9C;
  border-color: #16A085;
  color: #fff;
  transform: scale(1.01);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.15);
}

.answer-button:disabled,
.answer-button.disabled-option {
  background-color: #d0d0d0;
  border-color: #b0b0b0;
  color: #666;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
  opacity: 0.9;
}

#quizFeedbackText {
  min-height: 1.2em;
  margin: -4px 0 14px;
  color: #8B4513;
  font-weight: 600;
  font-size: clamp(0.72rem, 2.6vw, 0.92rem);
}

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

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

.question-progress {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  top: calc(50% + min(300px, 50vmin) + 12px);
  width: min(420px, calc(100vw - 24px));
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(250, 240, 230, 0.96);
  border: 2px solid #E0C9A6;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.16);
  z-index: 1100;
}

#questionProgressLabel {
  margin: 0 0 8px 0;
  font-size: 0.9em;
  font-weight: 600;
  color: #4A7C7A;
  text-align: center;
}

.question-progress-track {
  height: 10px;
  background: #e8d4b8;
  border-radius: 999px;
  overflow: hidden;
}

.question-progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #5AA4A1, #1ABC9C);
  transition: width 0.25s ease;
}

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

body.quiz-only-mode {
  background-color: #fff;
}

body.quiz-only-mode #quizModal {
  background: transparent;
  align-items: center;
  justify-content: center;
}

body.quiz-only-mode .question-progress {
  top: calc(50% + 212px);
}

@media (max-width: 480px) {
  .quiz-content {
    padding: 12px;
    width: calc(100vw - 12px);
    max-width: calc(100vw - 12px);
    max-height: calc(100dvh - 16px);
    border-radius: 12px;
  }
  .quiz-content h2 {
    font-size: clamp(0.9rem, 4vw, 1.05rem);
  }
  .quiz-content p#quizQuestionText {
    font-size: clamp(0.74rem, 3.5vw, 0.88rem);
  }
  .answer-button {
    padding: 7px 10px;
    font-size: clamp(0.66rem, 3.2vw, 0.8rem);
  }
  .question-progress {
    top: calc(50% + min(300px, 50vmin) + 10px);
    padding: 9px 10px;
  }
  body.quiz-only-mode .question-progress {
    top: calc(50% + 196px);
  }
}
