/*
 * games.css — Styles specific to the Learn page mini-game system.
 * Loaded only on the learn page via {% block head %} in learn.html.
 * Covers: game nav buttons, custom colors, all per-game UI, canvas, speaker pulse.
 */

/* ============================================================
   CUSTOM COLOR EXTENSIONS (game buttons: purple, orange)
   ============================================================ */
.btn-purple {
  --bs-btn-color: #fff;
  --bs-btn-bg: #6f42c1;
  --bs-btn-border-color: #6f42c1;
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: #5a35a6;
  --bs-btn-hover-border-color: #543199;
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: #543199;
  --bs-btn-active-border-color: #4e2e8d;
  --bs-btn-disabled-color: #fff;
  --bs-btn-disabled-bg: #6f42c1;
  --bs-btn-disabled-border-color: #6f42c1;
}

.btn-orange {
  --bs-btn-color: #fff;
  --bs-btn-bg: #fd7e14;
  --bs-btn-border-color: #fd7e14;
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: #e8720c;
  --bs-btn-hover-border-color: #d96b0b;
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: #d96b0b;
  --bs-btn-active-border-color: #ca640a;
  --bs-btn-disabled-color: #fff;
  --bs-btn-disabled-bg: #fd7e14;
  --bs-btn-disabled-border-color: #fd7e14;
}

.text-purple { color: #6f42c1 !important; }
.bg-purple-subtle { background-color: rgba(111, 66, 193, 0.1) !important; }
.text-orange { color: #fd7e14 !important; }
.bg-orange-subtle { background-color: rgba(253, 126, 20, 0.1) !important; }

/* ============================================================
   GAME NAVIGATION BUTTONS
   ============================================================ */
.game-nav-btn {
  font-size: 0.95rem;
  padding: 0.5rem 1.25rem !important;
}

@media (max-width: 767.98px) {
  .game-nav-btn {
    font-size: 0.8rem !important;
    padding: 0.35rem 0.85rem !important;
  }

  .buttons-container {
    gap: 0.5rem !important;
  }
}

/* ============================================================
   GAME SECTION FRAME & HEADER
   ============================================================ */
.game-section-border {
  border-top: 5px solid #ffc107 !important;
  scroll-margin-top: 100px;
}

.game-title-color {
  color: #856404;
}

.bg-game-result {
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
}

/* ============================================================
   SPEAKER PULSE ANIMATION (unified header)
   ============================================================ */
@keyframes speaker-pulse {
  0% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.4); }
  70% { box-shadow: 0 0 0 15px rgba(220, 53, 69, 0); }
  100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0); }
}

.speaker-pulse {
  animation: speaker-pulse 2s infinite;
}

/* ============================================================
   ACTION BUTTON RESPONSIVE OVERRIDES (shared across games)
   ============================================================ */
@media (max-width: 576px) {
  #sbCheckBtn,
  #pinyinCheckBtn,
  #matchingCheckBtn,
  #toneCheckBtn {
    padding-left: 1.5rem !important;
    padding-right: 1.5rem !important;
    font-size: 1rem;
  }
  .circle-80 {
    width: 60px !important;
    height: 60px !important;
  }
  .circle-80 i {
    font-size: 1.5rem !important;
  }
}

/* ============================================================
   SENTENCE BUILDER GAME
   ============================================================ */
/* Target drop area min height */
.sb-target {
  min-height: 80px;
}

/* Sentence chips */
.sentence-chip {
  font-size: 1.05rem;
  padding: 0.35rem 0.9rem;
  border-radius: 0.75rem;
  transition:
    background-color 0.12s ease,
    color 0.12s ease,
    transform 0.12s ease,
    border-color 0.12s ease;
  border-width: 2px !important;
}

.sentence-chip-target {
  background-color: #f0f7ff !important;
  border-color: #4f46e5 !important;
  color: #4f46e5 !important;
}

.sentence-chip-target:hover {
  background-color: #e0efff !important;
  transform: translateY(-2px);
}

.sentence-chip-source {
  background-color: #fff !important;
  border-color: #dee2e6 !important;
  color: #495057 !important;
}

.sentence-chip-source:hover {
  background-color: #f8f9fa !important;
  border-color: #adb5bd !important;
  transform: translateY(-2px);
}

.sentence-chip.btn-outline-secondary:hover,
.sentence-chip.btn-outline-secondary:focus {
  background-color: #f1f3f5;
  color: #000 !important;
}

.sentence-chip:hover {
  transform: translateY(-2px);
}

/* ============================================================
   TONE GAME
   ============================================================ */
#toneGameContainer .tone-btn {
  font-size: 1.25rem !important;
  font-weight: 500;
  border-width: 2px !important;
  border-radius: 0.75rem !important;
  min-width: 100px;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1) !important;
}
#toneGameContainer .tone-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Tone colour classes (used for button borders + active fills) */
#toneGameContainer .tone-1 { border-color: #4f46e5 !important; color: #4f46e5; }
#toneGameContainer .tone-1:hover, .tone-1.active { background-color: #4f46e5 !important; color: white !important; }
#toneGameContainer .tone-2 { border-color: #198754 !important; color: #198754; }
#toneGameContainer .tone-2:hover, .tone-2.active { background-color: #198754 !important; color: white !important; }
#toneGameContainer .tone-3 { border-color: #fd7e14 !important; color: #fd7e14; }
#toneGameContainer .tone-3:hover, .tone-3.active { background-color: #fd7e14 !important; color: white !important; }
#toneGameContainer .tone-4 { border-color: #dc3545 !important; color: #dc3545; }
#toneGameContainer .tone-4:hover, .tone-4.active { background-color: #dc3545 !important; color: white !important; }
#toneGameContainer .tone-5 { border-color: #6c757d !important; color: #6c757d; }
#toneGameContainer .tone-5:hover, .tone-5.active { background-color: #6c757d !important; color: white !important; }

/* Tone game — standout card visuals */
#toneGameContainer .card {
  position: relative;
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
  border: 1px solid rgba(79, 70, 229, 0.06);
  box-shadow:
    0 10px 30px rgba(2, 6, 23, 0.08),
    inset 0 -6px 24px rgba(79, 70, 229, 0.03);
  transition:
    transform 0.28s cubic-bezier(0.2, 1, 0.22, 1),
    box-shadow 0.2s ease,
    border-color 0.2s ease;
  overflow: visible;
}
#toneGameContainer .card::before {
  content: "";
  position: absolute;
  top: -10px;
  left: -10px;
  width: 56px;
  height: 56px;
  border-radius: 12px;
  background: radial-gradient(closest-side, rgba(79, 70, 229, 0.12), rgba(25, 135, 84, 0.06));
  filter: blur(18px);
  opacity: 0.9;
  pointer-events: none;
}
#toneGameContainer .card:not(.no-hover-elevate):hover {
  transform: translateY(-8px) scale(1.02);
  box-shadow: 0 22px 40px rgba(2, 6, 23, 0.14);
  border-color: rgba(79, 70, 229, 0.14);
}
#toneGameContainer .card.no-hover-elevate:hover {
  transform: none;
  box-shadow: 0 8px 18px rgba(13, 110, 253, 0.06);
  border-color: transparent;
}
#toneGameContainer .card .display-1 {
  font-size: 5.25rem;
  padding: 2rem;
  background:
    radial-gradient(120% 60% at 10% 10%, rgba(79, 70, 229, 0.06), transparent),
    linear-gradient(180deg, rgba(79, 70, 229, 0.03), rgba(255, 255, 255, 0));
  border-radius: 1rem;
  color: #1e3a8a;
  box-shadow: 0 8px 18px rgba(79, 70, 229, 0.06);
  display: inline-block;
  width: 100%;
}
#toneGameContainer .card .tone-btn {
  border-width: 2px;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(2, 6, 23, 0.04);
}

@media (max-width: 576px) {
  #toneGameContainer .card { width: 100% !important; }
  #toneGameContainer .card .display-1 {
    font-size: 3.6rem;
    padding: 1.25rem;
  }
}

/* ============================================================
   PINYIN GAME
   ============================================================ */
.pinyin-input-container .input-group {
  background: white;
}
.pinyin-input-container .input-group > * {
  border: none !important;
}
.pinyin-input-container .form-control:focus {
  box-shadow: none !important;
  outline: none !important;
}

@media (max-width: 576px) {
  .pinyin-input-container .input-group-lg { flex-wrap: nowrap; }
  .pinyin-input-container #pinyinGameInput {
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
    font-size: 1rem;
    min-width: 0;
  }
  .pinyin-input-container .btn {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }
  .pinyin-input-container .input-group-text {
    padding-left: 0.75rem !important;
    padding-right: 0.5rem !important;
  }
}

.pinyin-candidates {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  min-height: 68px;
  z-index: 10;
  padding: 0.5rem;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(250, 255, 250, 0.9));
  box-shadow: 0 10px 30px rgba(2, 6, 23, 0.06);
  border: 1px solid rgba(2, 6, 23, 0.04);
}

@media (max-width: 576px) {
  .pinyin-candidates {
    grid-template-columns: repeat(2, 1fr);
    max-height: 300px;
    overflow-y: auto;
    gap: 8px;
    padding: 0.4rem;
  }
  .candidate-item { padding: 0.5rem !important; }
}

.candidate-item {
  cursor: pointer;
  transition:
    transform 0.18s cubic-bezier(0.2, 1, 0.22, 1),
    box-shadow 0.18s ease,
    background-color 0.12s ease;
  border: 1px solid rgba(2, 6, 23, 0.04);
  border-radius: 0.75rem;
  padding: 0.55rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: linear-gradient(180deg, #ffffff, #fbfffb);
  box-shadow:
    0 6px 18px rgba(2, 6, 23, 0.04),
    inset 0 -6px 18px rgba(79, 70, 229, 0.02);
  min-height: 56px;
}
.candidate-item:hover {
  transform: translateY(-4px);
  box-shadow: 0 18px 40px rgba(2, 6, 23, 0.1);
  background: linear-gradient(180deg, #ffffff, #f8fff8);
  border-color: rgba(25, 135, 84, 0.12);
}
.candidate-item:active {
  transform: translateY(-1px) scale(0.997);
  box-shadow: 0 10px 30px rgba(2, 6, 23, 0.08);
}
.candidate-item:focus {
  outline: none;
  box-shadow: 0 0 0 4px rgba(25, 135, 84, 0.06);
}
.candidate-item .fs-2 {
  font-weight: 400;
  color: #0f172a;
  line-height: 1;
}
.candidate-item .badge {
  background: rgba(108, 117, 125, 0.06);
  border: 1px solid rgba(108, 117, 125, 0.08);
  color: var(--bs-secondary);
  font-size: 0.65rem;
  padding: 0 0.35rem;
  border-radius: 0.35rem;
}

.candidate-key {
  font-size: 0.75rem;
  background: rgba(79, 70, 229, 0.06);
  color: #4f46e5;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid rgba(79, 70, 229, 0.08);
  min-width: 22px;
  text-align: center;
  font-weight: 600;
}

.pinyin-fill-blank {
  width: 2rem;
  height: 3rem;
  border-bottom: 3px solid var(--bs-success);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  font-size: 2rem;
  color: var(--bs-success);
  vertical-align: middle;
}
@media (max-width: 576px) {
  .pinyin-fill-blank {
    width: 1.5rem;
    height: 2.2rem;
    font-size: 1.5rem;
    border-bottom-width: 2px;
  }
}

.pinyin-filled-word {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.15rem;
  margin: 0;
  background-color: var(--bs-success-subtle);
  color: var(--bs-success-emphasis);
  border-radius: 4px;
  font-size: 2.5rem;
  cursor: pointer;
  transition: filter 0.2s;
}
@media (max-width: 576px) {
  .pinyin-filled-word {
    font-size: 1.8rem;
    padding: 0 0.1rem;
  }
}
.pinyin-filled-word:hover {
  filter: brightness(0.9);
}

/* ============================================================
   MATCHING GAME
   ============================================================ */
.matching-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  perspective: 1000px;
}

.matching-card {
  min-height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  border: 2px solid #e9ecef;
  border-radius: 1rem;
  padding: 0.75rem;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  user-select: none;
  font-weight: 400;
  text-align: center;
  position: relative;
}

.pair-number {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 18px;
  height: 18px;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #adb5bd;
  background: #f8f9fa;
  font-weight: bold;
}

.matching-card.matched .pair-number,
.matching-card.missed .pair-number {
  background-color: var(--bs-light);
  color: var(--bs-secondary);
  border-color: currentColor;
}

.matching-card:hover:not(.matched):not(.selected) {
  transform: translateY(-3px);
  border-color: var(--bs-primary-subtle);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
}

.matching-card.selected {
  background-color: rgba(79, 70, 229, 0.1);
  color: var(--bs-primary);
  border-color: var(--bs-primary);
  box-shadow: 0 5px 15px rgba(79, 70, 229, 0.2);
}

.matching-card.matched {
  background-color: rgba(25, 135, 84, 0.05);
  color: #198754 !important;
  border-color: rgba(25, 135, 84, 0.2);
  cursor: default;
  opacity: 0.4;
  pointer-events: none;
  transform: none !important;
  box-shadow: none !important;
}

.matching-card.missed {
  background-color: rgba(255, 193, 7, 0.05);
  color: #856404 !important;
  border-color: rgba(255, 193, 7, 0.2);
  cursor: default;
  opacity: 0.5;
  pointer-events: none;
  transform: none !important;
  box-shadow: none !important;
}

.matching-card.wrong {
  animation: shake 0.5s;
  background-color: var(--bs-danger-subtle);
  color: var(--bs-danger);
  border-color: var(--bs-danger);
}

.matching-card.last-pair {
  opacity: 1 !important;
  z-index: 10;
}

.matching-card.last-pair.matched {
  background-color: rgba(25, 135, 84, 0.15) !important;
  box-shadow: 0 0 0 3px rgba(25, 137, 84, 0.5) !important;
}

.matching-card.last-pair.missed {
  background-color: rgba(255, 193, 7, 0.15) !important;
  box-shadow: 0 0 0 3px rgba(255, 193, 7, 0.5) !important;
}

.matching-card .original-text { font-size: 1.75rem; line-height: 1.2; }
.matching-card .meaning-text { font-size: 1rem; line-height: 1.2; }
.matching-card .meaning-explanation { font-size: 0.9rem; display: block; opacity: 0.8; margin-top: 2px; }

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

@media (max-width: 576px) {
  .matching-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }
  .matching-card { height: 80px; padding: 0.5rem; }
  .matching-card .chinese-text { font-size: 1.25rem; }
  .matching-card .meaning-text { font-size: 0.85rem; }
}

/* ============================================================
   FILL-IN-THE-BLANK GAME
   ============================================================ */
#fillBlankSentence {
  min-height: 100px;
  font-size: 1.75rem;
}

.fill-blank-placeholder {
  display: inline-block;
  min-width: 80px;
  text-align: center;
  transition: all 0.3s ease;
}

.fill-blank-placeholder.correct {
  background-color: #d1e7dd !important;
  border-color: #198754 !important;
  color: #198754;
}

.fill-blank-placeholder.incorrect {
  background-color: #f8d7da !important;
  border-color: #dc3545 !important;
  color: #dc3545;
}

.fill-blank-token {
  user-select: none;
}

.fill-blank-option {
  font-size: 1.25rem;
  min-width: 100px;
  transition: all 0.2s ease;
}

.fill-blank-option:hover:not(:disabled) {
  transform: translateY(-2px);
}

.fill-blank-option:disabled {
  cursor: default;
}

.fill-blank-option.btn-success {
  background-color: #198754 !important;
  border-color: #198754 !important;
}

.fill-blank-option.btn-danger {
  background-color: #dc3545 !important;
  border-color: #dc3545 !important;
}

@media (max-width: 576px) {
  #fillBlankSentence {
    font-size: 1.25rem;
    padding: 1rem !important;
  }
  .fill-blank-placeholder {
    min-width: 50px;
    font-size: 1.25rem;
  }
  .fill-blank-option {
    font-size: 1rem;
    min-width: 70px;
    padding: 0.5rem 1rem !important;
  }
}

/* ============================================================
   SPEAK GAME
   ============================================================ */
.speak-level-bar {
  display: block;
  width: 6px;
  min-height: 4px;
  height: 4px;
  border-radius: 3px;
  background: #0891b2; /* visible cyan on white at rest */
  transition: height 0.08s ease, background 0.15s ease;
}

/* ============================================================
   WRITING GAME (canvas + HanziWriter wrapper)
   ============================================================ */
#writingCanvasWrapper {
  height: 260px;
  background: linear-gradient(135deg, #fefcf8 0%, #f8f4ee 100%);
}

@media (max-width: 400px) {
  #writingCanvasWrapper {
    height: 220px;
  }
}

/* ============================================================
   GAME INSTRUCTION MEANING EXPLANATIONS
   Inline context for meaning sub-text in game hints / instructions
   ============================================================ */
#gameInstructionDetail .meaning-explanation,
#sbVietnameseHint .meaning-explanation,
#pinyinVietnameseHint .meaning-explanation,
#matchingGameInstruction .meaning-explanation,
#radicalOptionsGrid button .meaning-explanation,
#radicalMeaningDisplay .meaning-explanation {
  display: inline;
  margin-top: 0;
  margin-left: 0.35rem;
  font-weight: normal;
  font-size: 0.9em;
}
