/* ==========================================================================
   quest.css — shared styles for TCMStudy quest games (used by quest-engine.js)
   ========================================================================== */

* {
  box-sizing: border-box;
}

body {
  font-family: Arial, sans-serif;
  margin: 0;
  padding: 0;
  background: #f4f4f9;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.container {
  width: 100%;
  max-width: 600px;
  margin: 84px auto 50px;
  background-color: #fff;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

h1 {
  text-align: center;
  margin-bottom: 20px;
}

p {
  font-size: 1.1em;
}

/* header bar + buttons now live in the shared style.css */

/* ---------- progress bar (lives in the fixed header) ---------- */

#progress-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  max-width: 420px;
  margin: 0 auto;
  padding: 0 16px;
}

#progress-label {
  font-size: 0.75rem;
  color: #888;
  white-space: nowrap;
}

#progress-track {
  flex: 1;
  height: 9px;
  background: #e6e6e6;
  border-radius: 5px;
  overflow: hidden;
}

#progress-fill {
  height: 100%;
  width: 0;
  background: #58cc02;
  border-radius: 5px;
  transition: width 0.6s ease;
}

/* ---------- question blocks ---------- */

.question-block {
  margin-bottom: 10px;
  position: relative;
  padding-bottom: 20px;
  clear: both;
}

.question-text {
  margin-bottom: 30px;
  line-height: 1.4;
}

.question-image,
.followup-image {
  max-width: 25%;
  height: auto;
  display: block;
  margin: 0 auto 40px auto;
  border-radius: 8px;
  aspect-ratio: 1 / 1;
}

.followup-image {
  max-width: 20%;
}

/* flaticon-style symptom icons: plain artwork, no badge — the circular badge is
   reserved for portraits so it reads as "a person" rather than "a symbol" */
.question-icon {
  display: block;
  width: 100px;
  max-width: 40%;   /* only bites on very narrow screens */
  aspect-ratio: 1 / 1;
  height: auto;
  margin: 0 auto 35px auto;
  object-fit: contain;
}

/* NPC face crop in a circular badge (question "portrait": true) */
.question-portrait {
  width: 150px;
  height: 150px;
  margin: 0 auto 35px auto;
  background: #eef1f5;
  border-radius: 50%;
  overflow: hidden;
}

.question-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 15%;   /* bias toward the top of the sprite — the face */
  transform-origin: 50% 20%;  /* puzzle-level portraitZoom scales around the face */
}

.followup-block {
  border-top: 1px solid #999;
  margin-top: 30px;
  padding-top: 30px;
}

.followup-intro {
  font-style: italic;
  font-size: 0.9em;
  font-weight: bold;
  margin-bottom: 35px;
}

/* ---------- answer options (tactile, Duolingo-style) ---------- */

.option {
  display: block;
  margin: 10px 0;
  padding: 12px 15px;
  border: 2px solid #d8dce2;
  border-bottom-width: 4px;
  border-radius: 10px;
  background-color: #f7f8fa;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
  .option:hover {
    background-color: #eef1f5;
    transform: translateY(-1px);
  }
}

.option:active {
  transform: translateY(2px);
  border-bottom-width: 2px;
  margin-bottom: 12px; /* compensate the border so the page doesn't shift */
}

.option.locked {
  cursor: default;
}

.option.correct {
  background-color: #c8f7c5;
  border-color: #8fd18a;
}

.option.incorrect {
  background-color: #ddd;
  border-color: #ccc;
  color: #888;
  text-decoration: line-through;
  cursor: default;
}

/* ---------- feedback ---------- */

.feedback {
  margin-top: 10px;
  text-align: left;
  padding: 10px;
  line-height: 1.4;
  font-size: 0.9em;
}

.feedback.correct h3 {
  font-size: 1.4rem;
  color: green;
}

.feedback.incorrect h3 {
  font-size: 1.2rem;
  color: red;
}

.feedback li {
  font-size: 0.9rem;
  margin: 0 0 12px 0;
  line-height: 1.2;
}

.feedback img {
  display: block;
  max-width: 40%;
  margin: 14px auto;
  border-radius: 8px;
}

.fade-in-feedback {
  animation: fadeInFeedback 0.5s ease-out forwards;
  opacity: 0;
}

@keyframes fadeInFeedback {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- entrance animations ---------- */

@keyframes qEnter {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

.q-enter {
  animation: qEnter 0.45s ease both;
}

.option-enter {
  animation: qEnter 0.4s ease both;
}

@keyframes popIn {
  0% { opacity: 0; transform: scale(0.7); }
  70% { transform: scale(1.06); }
  100% { opacity: 1; transform: scale(1); }
}

.congrats-message h2 {
  animation: popIn 0.5s ease both 0.2s;
}

/* ---------- answer animations ---------- */

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

@keyframes bounce {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

.shake {
  animation: shake 0.2s ease-in-out;
}

.bounce {
  animation: bounce 0.2s ease-in-out;
}

.mini-select-bounce {
  animation: bounce 0.2s ease-in-out;
}

.mini-match-bounce {
  animation: miniMatchBounce 0.2s ease-in-out;
}

.mini-wrong-shake {
  animation: miniWrongShake 0.3s ease-in-out;
}

@keyframes miniMatchBounce {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

@keyframes miniWrongShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-3px); }
  40% { transform: translateX(3px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(0); }
}

/* ---------- matching questions ---------- */

.matching-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 10px;
  padding: 20px 10px;
  align-items: start;
  border-top: 2px dotted #ddd;
  border-bottom: 2px dotted #ddd;
}

.matching-column {
  display: grid;
  gap: 12px;
}

.matching-button {
  font-size: 0.95rem;
  padding: 12px;
  border: 2px solid #d8dce2;
  border-bottom-width: 4px;
  border-radius: 12px;
  background-color: #f9fafb;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
  color: #555;
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  word-wrap: break-word;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.matching-button.category {
  font-size: 0.85rem;
}

.matching-button:hover {
  background-color: #eef2f7;
}

.matching-button:active {
  border-bottom-width: 2px;
  transform: translateY(2px);
}

.matching-button.selected {
  border-color: #007bff;
  background-color: #e3f2fd;
  color: #007bff;
}

.matching-button.matched {
  border: 1px solid #28a745;
  background-color: #d4edda;
  color: #155724;
  cursor: default;
}

.matching-button:disabled {
  cursor: default;
}

/* ---------- next / finish button ---------- */

.followup-button {
  float: right;
  margin: 15px 0 0 0;
  padding: 10px 20px;
  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 0.3s;
  font-size: 1em;
}

.followup-button:hover {
  background-color: #0056b3;
}

/* ---------- promo / CTA interstitial ---------- */

.promo-block {
  clear: both;
  border: 2px dashed #c5c9d0;
  border-radius: 12px;
  padding: 18px;
  margin: 30px 0;
  text-align: center;
  background: #f5f5f8;
}

.promo-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: #999;
  margin-bottom: 10px;
}

.promo-block img {
  display: block;
  max-width: 40%;
  margin: 10px auto;
  border-radius: 8px;
}

.promo-body {
  font-size: 0.95em;
  line-height: 1.4;
}

.promo-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 16px;
}

.promo-buttons button {
  padding: 10px 22px;
  border: none;
  border-radius: 8px;
  font-size: 0.95em;
  cursor: pointer;
  transition: background-color 0.2s;
}

.promo-cta {
  background-color: #28a745;
  color: #fff;
  font-weight: bold;
}

.promo-cta:hover {
  background-color: #218838;
}

.promo-continue-row {
  text-align: right;
  margin-top: 34px;
}

.promo-skip {
  background: none;
  border: none;
  padding: 6px 0;
  font-size: 1em;
  font-weight: bold;
  color: #007bff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* circled arrow trailing the label */
.promo-skip::after {
  content: "\2192";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5em;
  height: 1.5em;
  border-radius: 50%;
  background: #007bff;
  color: #fff;
  font-size: 0.85em;
  line-height: 1;
}

.promo-skip:hover {
  text-decoration: underline;
}

.promo-skip:disabled {
  color: #aaa;
  cursor: default;
  text-decoration: none;
}

.promo-skip:disabled::after {
  background: #aaa;
}

/* end-of-quiz one-liner reminder */
.promo-reminder {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 16px;
  padding: 14px 18px;
  /* width + margin match .share-box-wrapper so the two boxes line up */
  width: 90%;
  margin: 20px auto 0;
  font-size: 0.9em;
}

.promo-reminder .promo-cta.small {
  padding: 8px 18px;
  margin: 12px 0;
  font-size: 0.85em;
  border: none;
  border-radius: 8px;
  background-color: #28a745;
  color: #fff;
  font-weight: bold;
  cursor: pointer;
}

.promo-reminder .promo-cta.small:hover {
  background-color: #218838;
}

.quest-logo {
  display: block;
  width: 130px;
  max-width: 50%;
  height: auto;
  margin: 45px auto 10px auto;
  opacity: 0.9;
}

/* ---------- congrats & share ---------- */

.congrats-message {
  border-top: 1px solid #999;
  padding-top: 30px;
  padding-bottom: 30px;
  opacity: 0;
  animation: fadeIn 2s ease-in-out forwards;
  clear: both;
  text-align: center;
}

.congrats-message h2 {
  font-size: 1.5em;
  font-weight: bold;
  color: #2e7d32;
  text-align: center;
}

.streak-line {
  font-size: 1.2em;
  font-weight: bold;
  color: #ff9600;
  animation: popIn 0.5s ease both 0.9s;
}

.return-line {
  font-size: 0.85em;
  color: #777;
  margin-top: 8px;
}

/* section headings on the results screen ("Share Your Results:", "Before you go:") */
.congrats-heading {
  color: #555;
  margin-top: 50px;
}

.share-box-wrapper {
  position: relative;
  margin: 20px auto;
  width: 90%;
  text-align: left;
}

.share-box {
  font-family: Consolas, Menlo, Monaco, "Courier New", monospace;
  background: #f5f5f8;   /* matches .promo-block */
  padding: 40px 15px 16px 15px;
  border-radius: 8px;
  /* below the 0.9em used elsewhere: monospace reads larger at the same px */
  font-size: 0.8em;
  white-space: pre-wrap;
  color: #333;
  border: 1px solid #ccc;
}

.copy-button {
  position: absolute;
  top: 6px;
  right: 6px;
  background: transparent;
  border: none;
  font-size: 0.7em;
  color: #999;
  cursor: pointer;
}

.copy-button:hover {
  color: #666;
}

/* ---------- generic fades ---------- */

.fade-in {
  animation: fadeIn 1s ease-in-out forwards;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.fade-out-slow {
  animation: fadeOutSlow 1.5s forwards;
}

@keyframes fadeOutSlow {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ---------- NPC dialogue scene ---------- */

#dialogue-scene {
  position: relative;
  max-width: 600px;
  margin: 0 auto;
}

#background-img {
  width: 100%;
  border-radius: 10px;
}

#npc-img {
  position: absolute;
  bottom: 30%;
  left: 28%;
  width: 35%;
}

#npc-img,
#dialogue-box {
  opacity: 0;
}

#dialogue-box,
#dialogue-text,
#dialogue-next {
  font-family: "Handjet", sans-serif;
  font-size: 1.6rem;
}

#dialogue-box {
  padding: 16px;
  position: absolute;
  bottom: 20px;
  left: 5%;
  background-color: #F4E2BC;
  width: 90%;
  border: 2px solid #333;
  border-radius: 10px;
  box-shadow: 2px 2px 2px 2px #333;
  color: #000;
}

#dialogue-next {
  background-color: #666;
  color: #F4E2BC;
  border: 2px solid #000;
  padding: 6px 12px;
  cursor: pointer;
  box-shadow: 2px 2px 0px #000;
  text-transform: uppercase;
  transition: transform 0.1s ease;
  float: right;
}

#dialogue-next:hover {
  background-color: #555;
}

#dialogue-next:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}

/* ---------- modal ---------- */

.modal {
  display: none;
  position: fixed;
  z-index: 200;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.modal-overlay {
  background-color: rgba(0, 0, 0, 0);
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 80px;
  animation: fadeOverlay 0.3s forwards;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

@keyframes fadeOverlay {
  to { background-color: rgba(0, 0, 0, 0.6); }
}

.modal.fade-out .modal-overlay {
  animation: fadeOutOverlay 0.3s forwards;
}

@keyframes fadeOutOverlay {
  from { background-color: rgba(0, 0, 0, 0.6); }
  to { background-color: rgba(0, 0, 0, 0); }
}

.modal.fade-out .modal-content {
  animation: fadeSlideOut 0.3s ease-out;
}

@keyframes fadeSlideOut {
  0% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-30px); }
}

@keyframes fadeSlideIn {
  0% { opacity: 0; transform: translateY(-30px); }
  100% { opacity: 1; transform: translateY(0); }
}

.modal-content {
  background-color: #fff;
  padding: 24px;
  border-radius: 8px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
  font-size: 0.95rem;
}

.modal-content h2 {
  margin-top: 0;
}

.modal-close-button {
  display: block;
  margin: 20px auto 0;
  background-color: #333;
  color: #fff;
  padding: 10px 18px;
  font-size: 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.modal-close-button:hover {
  background-color: #000;
}

/* ---------- settings toggles ---------- */

.toggle-setting {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 16px 0;
}

.toggle-setting input[type="checkbox"] {
  display: none;
}

.toggle-setting .slider {
  position: relative;
  width: 40px;
  height: 20px;
  background-color: #ccc;
  border-radius: 20px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.toggle-setting .slider::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background-color: white;
  border-radius: 50%;
  transition: transform 0.3s;
}

.toggle-setting input[type="checkbox"]:checked + .slider {
  background-color: #007bff;
}

.toggle-setting input[type="checkbox"]:checked + .slider::before {
  transform: translateX(20px);
}

.setting-label-text {
  margin-right: 12px;
  flex: 1;
}

/* ---------- dark mode ---------- */

body.dark-mode {
  background-color: #1c1c1c;
  color: #ddd;
}

body.dark-mode .container {
  background-color: #2a2a2a;
  color: #ddd;
  box-shadow: 0 2px 10px rgba(255, 255, 255, 0.1);
}

body.dark-mode #progress-track {
  background: #444;
}

body.dark-mode #progress-label {
  color: #aaa;
}

body.dark-mode .question-portrait {
  background: #383838;
}

body.dark-mode .option {
  background-color: #333;
  border-color: #555;
  color: #eee;
}

body.dark-mode .option:hover {
  background-color: #444;
}

body.dark-mode .option.correct {
  background-color: #3c6;
  border-color: #2a5;
  color: #1c1c1c;
}

body.dark-mode .option.incorrect {
  background-color: #555;
  border-color: #444;
  color: #aaa;
}

body.dark-mode .feedback.correct h3 {
  color: #6f6;
}

body.dark-mode .feedback.incorrect h3 {
  color: #f66;
}

body.dark-mode .matching-button {
  background-color: #333;
  border-color: #555;
  color: #ddd;
}

body.dark-mode .matching-button:hover {
  background-color: #444;
}

body.dark-mode .matching-button.selected {
  border-color: #3399ff;
  background-color: #1a3350;
  color: #7bb8ff;
}

body.dark-mode .matching-button.matched {
  border-color: #28a745;
  background-color: #1e3b26;
  color: #7bd389;
}

body.dark-mode .followup-button {
  background-color: #3399ff;
}

body.dark-mode .followup-button:hover {
  background-color: #267acc;
}

body.dark-mode .promo-block {
  border-color: #555;
  background: #242424;
}

body.dark-mode .promo-skip {
  color: #6ab0ff;
}

body.dark-mode .promo-skip::after {
  background: #6ab0ff;
  color: #1c1c1c;
}

body.dark-mode .promo-skip:disabled {
  color: #777;
}

body.dark-mode .promo-skip:disabled::after {
  background: #777;
  color: #1c1c1c;
}

body.dark-mode .share-box {
  background: #242424;   /* matches .promo-block */
  color: #eee;
  border: 1px solid #555;
}

body.dark-mode .congrats-heading {
  color: #bbb;
}

body.dark-mode .return-line {
  color: #999;
}

body.dark-mode .copy-button {
  color: #aaa;
}

body.dark-mode .copy-button:hover {
  color: #fff;
}

body.dark-mode .modal-content {
  background-color: #2a2a2a;
  color: #ddd;
  box-shadow: 0 5px 15px rgba(255, 255, 255, 0.1);
}

body.dark-mode .modal-close-button {
  background-color: #444;
  color: #fff;
}

body.dark-mode .modal-close-button:hover {
  background-color: #666;
}

body.dark-mode .toggle-setting .slider {
  background-color: #555;
}

body.dark-mode .toggle-setting input[type="checkbox"]:checked + .slider {
  background-color: #3399ff;
}

/* ---------- accessibility ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- mobile ---------- */

@media (max-width: 600px) {
  body {
    padding: 10px;
    background-color: #fff;
  }

  .container {
    padding: 15px;
    box-shadow: none;
  }

  .modal-content {
    width: 80%;
    padding: 16px;
    margin-top: 5vh;
  }

  .modal-overlay {
    padding-top: 0;
  }

  #dialogue-box,
  #dialogue-text,
  #dialogue-next {
    font-size: 1.1em;
  }

  #dialogue-box {
    padding: 10px;
    bottom: 15px;
  }

  #npc-img {
    bottom: 38%;
    left: 28%;
    width: 30%;
  }

  .share-box {
    font-size: 0.7rem;
  }

  .matching-button {
    font-size: 0.85rem;
    min-height: 60px;
    padding: 8px;
  }

  .matching-button.category {
    font-size: 0.75rem;
  }

  body.dark-mode {
    background-color: #2a2a2a;
  }
}
