/* Minimal, Bootstrap-first stylesheet for the Learn page */

body {
  background-color: #b5d1f7;
  min-height: 100vh;
}

/* Container improvements for mobile */
@media (max-width: 576px) {
  .container {
    padding-left: 1rem;
    padding-right: 1rem;
  }
  .container-learn {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }
  .card-body.p-4.p-md-5 {
    padding: 1.5rem 1rem !important;
  }
  .display-5 {
    font-size: 1.75rem;
  }
  .display-6 {
    font-size: 1.5rem;
  }
}

@media (min-width: 992px) {
  .container {
    padding-left: 2rem;
    padding-right: 2rem;
  }
}

/* Small hover helper used by JS for list rows */
.hover-bg-light:hover {
  background-color: var(--bs-light);
}

/* Token card: minimal helper (use Bootstrap's `card` and utilities for most visuals) */
.token-card {
  cursor: pointer;
  display: inline-flex; /* shrink-to-fit and sit nicely in flex container */
  flex-direction: column;
  align-items: center;
  flex: 0 0 calc(12.5% - 0.875rem); /* 8 per row on desktop (100%/8 - gaps) */
  min-width: 0;
  padding: 0;
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease;
  text-align: center;
}

#tokens {
  gap: 1rem !important;
}

/* Medium screens: 4 per row */
@media (max-width: 1200px) and (min-width: 577px) {
  .token-card {
    flex: 0 0 calc(25% - 0.75rem) !important;
  }
}

.token-card .card-body {
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  align-items: center;
}

.token-card .h5 {
  margin-bottom: 0;
  font-size: 1.15rem;
}

.token-card .small {
  font-size: 0.85rem;
}

.token-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.06);
}
.token-card.playing {
  transform: scale(1.03);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.08);
}

/* On small screens, allow cards to become two per row */
@media (max-width: 576px) {
  #tokens {
    gap: 0.5rem !important;
    padding: 0 0.25rem;
  }
  .token-card {
    flex: 0 0 calc(50% - 0.25rem) !important;
    display: flex; /* revert to flex on narrow screens */
    margin: 0 !important;
    min-width: 0 !important;
    max-width: none !important;
  }
  .token-card .card-body {
    padding: 0.5rem 0.25rem !important;
  }
  .token-card .h5 {
    font-size: 1rem;
  }
  .token-card .small {
    font-size: 0.75rem;
  }
  .token-card .badge {
    font-size: 0.65rem;
    padding: 0.2rem 0.4rem;
  }
}

/* Small utility for circular 60x60 controls */
.circle-60 {
  width: 60px !important;
  height: 60px !important;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.circle-80 {
  width: 80px !important;
  height: 80px !important;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.circle-34 {
  width: 34px !important;
  height: 34px !important;
  min-width: 34px !important;
}

/* Sentence builder target area min height */
.sb-target {
  min-height: 80px;
}

/* Preserve preformatted wrapping for translations */
.pre-wrap {
  white-space: pre-wrap;
}

/* Meaning tokens shown in translated/analysis text — larger and colored by POS */
.meaning-token {
  display: inline-block;
  padding: 0.5rem 0.65rem;
  margin: 0.15rem;
  border-radius: 0.4rem;
  font-size: 2rem; /* larger for readability */
  line-height: 1;
  cursor: pointer;
  transition:
    transform 0.12s ease,
    box-shadow 0.12s ease,
    background-color 0.12s ease;
  background: transparent;
  color: #212529;
}

@media (max-width: 768px) {
  .meaning-token {
    padding: 0.25rem 0.4rem;
    font-size: 1.5rem;
    border-radius: 0.3rem;
    margin: 0.1rem;
  }
}

/* Alternative selection styles (Dropdown style) */
.alt-group {
  display: inline-flex;
  align-items: center;
  position: relative;
  background-color: transparent;
  border: 2px dashed rgba(0, 0, 0, 0.1);
  border-radius: 0.75rem;
  transition: all 0.2s;
  cursor: pointer;
  margin: 0.25rem;
}

.alt-group:hover {
  border-color: rgba(13, 110, 253, 0.4);
  background-color: rgba(0, 0, 0, 0.02);
}

.alt-selected {
  display: inline-flex;
  align-items: center;
  padding: 2px 4px;
}

.alt-dropdown-icon {
  font-size: 0.8rem;
  margin-left: 4px;
  color: #0d6efd;
  opacity: 0.7;
}

.alt-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 1000;
  min-width: 120px;
  padding: 0.5rem 0;
  margin: 0.125rem 0 0;
  background-color: #fff;
  background-clip: padding-box;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 0.5rem;
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.175);
}

.alt-menu.show {
  display: block;
}

.alt-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 0.5rem 1rem;
  clear: both;
  color: #212529;
  text-align: inherit;
  white-space: nowrap;
  background-color: transparent;
  border: 0;
  cursor: pointer;
  transition: background-color 0.15s;
}

.alt-item:hover {
  background-color: #f8f9fa;
  color: #0d6efd;
}

.alt-item.active {
  background-color: #e9ecef;
  font-weight: bold;
  color: #0d6efd;
}

.alt-item .meaning-token {
  font-size: 1.25rem !important; /* Scale down in menu */
  padding: 0.25rem 0.5rem !important;
}

/* Hover and playing state */
.meaning-token:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.08);
}

/* POS-specific colors */
.meaning-token[data-pos^="NN"] {
  background: rgba(13, 110, 253, 0.12);
  color: #0d6efd;
}

/* User selector pill styles */
.user-selector-pill {
  transition: all 0.2s ease;
  user-select: none;
}

.user-selector-pill:hover {
  border-color: var(--bs-primary) !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08) !important;
  transform: translateY(-1px);
}

.user-selector-pill:active {
  transform: translateY(0);
}

.user-selector-pill.dropdown-toggle::after {
  display: none;
}

.dropdown-menu.animate-fade-in {
  animation: fadeIn 0.15s ease-out;
}

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

.dropdown-item.user-option {
  transition: background-color 0.2s;
  border-radius: 8px;
  margin: 0 8px;
  width: calc(100% - 16px);
}

.dropdown-item.user-option.active {
  background-color: #f0f7ff;
  color: var(--bs-primary);
}

.dropdown-item.user-option:hover:not(.active) {
  background-color: var(--bs-light);
}

.dropdown-item.user-option .avatar-sm {
  transition: all 0.2s;
}

.dropdown-item.user-option:hover .avatar-sm {
  background-color: var(--bs-primary-bg-subtle) !important;
}

.dropdown-item.user-option:hover .bi-person {
  color: var(--bs-primary) !important;
}
.meaning-token[data-pos^="VV"],
.meaning-token[data-pos^="VA"] {
  background: rgba(25, 135, 84, 0.12);
  color: #198754;
}
.meaning-token[data-pos^="JJ"] {
  background: rgba(253, 126, 20, 0.12);
  color: #fd7e14;
}
.meaning-token[data-pos^="AD"] {
  background: rgba(111, 66, 193, 0.12);
  color: #6f42c1;
}
.meaning-token[data-pos^="P"] {
  background: rgba(214, 51, 132, 0.12);
  color: #d63384;
}
.meaning-token[data-pos^="DT"] {
  background: rgba(32, 201, 151, 0.12);
  color: #20c997;
}
.meaning-token[data-pos="PU"] {
  background: transparent;
  color: #6c757d;
}

/* small playing state highlight */
.meaning-token.playing {
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.12);
  transform: scale(1.04);
}

/* Legend helper */
.legend-color {
  width: 20px;
  height: 20px;
  border-radius: 4px;
}

/* Grade pill styles (video-game style tiers) */
.grade-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  margin-left: 6px;
  vertical-align: middle;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  text-transform: uppercase;
}
.member-mastery-chip {
  transition: all 0.2s ease;
  padding: 0.35rem 0.85rem;
}
.member-mastery-chip .mastery-name {
  font-size: 0.9rem;
}
.member-mastery-chip .mastery-value {
  font-size: 1.1rem;
}
.member-mastery-chip .grade-pill {
  font-size: 0.8rem;
  padding: 2px 7px;
}
.member-mastery-chip .mastery-count {
  font-size: 0.75rem;
}

@media (max-width: 768px) {
  .member-mastery-chip {
    padding: 0.25rem 0.75rem !important;
  }
  .member-mastery-chip .mastery-name {
    font-size: 0.85rem !important;
  }
  .member-mastery-chip .mastery-value {
    font-size: 1rem !important;
  }
  .member-mastery-chip .grade-pill {
    font-size: 0.75rem !important;
    padding: 1px 6px !important;
  }
  .member-mastery-chip .mastery-count {
    font-size: 0.7rem !important;
  }
}
.member-mastery-chip:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1) !important;
  border-color: var(--bs-primary) !important;
}
.grade-tier-s {
  background: linear-gradient(90deg, #ffd24a, #f3b400);
  color: #1f1f1f;
}
.grade-tier-a {
  background: linear-gradient(90deg, #8a2be2, #7a1fe5);
  color: #ffffff;
}
.grade-tier-b {
  background: linear-gradient(90deg, #4ea1ff, #0d6efd);
  color: #ffffff;
}
.grade-tier-c {
  background: linear-gradient(90deg, #37d67a, #198754);
  color: #ffffff;
}
.grade-tier-d {
  background: linear-gradient(90deg, #ffb86b, #fd7e14);
  color: #ffffff;
}
.grade-tier-f {
  background: linear-gradient(90deg, #ff6b6b, #dc3545);
  color: #ffffff;
}
.grade-tier-i {
  background: linear-gradient(90deg, #c8c8c8, #6c757d);
  color: #ffffff;
}

/* Keep a few layout utilities used elsewhere */
.section-title {
  font-weight: 600;
  color: #495057;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Small utility for mastery user select width */
.min-w-220 {
  min-width: 220px;
}

/* Sentence chip helpers */
.sentence-chip {
  font-size: 1.05rem; /* slightly larger for readability */
  padding: 0.35rem 0.9rem;
  border-radius: 0.75rem; /* more rounded for elegance */
  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: #0d6efd !important;
  color: #0d6efd !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);
}

/* Make outline secondary chips show a light background on hover and keep dark text for contrast */
.sentence-chip.btn-outline-secondary:hover,
.sentence-chip.btn-outline-secondary:focus {
  background-color: #f1f3f5;
  color: #000 !important;
}

/* Slight lift on hover for tactile feel */
.sentence-chip:hover {
  transform: translateY(-2px);
}

/* Common sizing utilities */
.icon-2rem {
  font-size: 2rem;
}
.h-10px {
  height: 10px;
}
.circle-32 {
  width: 32px;
  height: 32px;
}
.circle-34 {
  width: 34px;
  height: 34px;
}
.circle-100 {
  width: 100px !important;
  height: 100px !important;
  padding: 0 !important;
  flex: 0 0 100px !important;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
}

.circle-80 {
  width: 80px !important;
  height: 80px !important;
  padding: 0 !important;
  flex: 0 0 80px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
}

/* Backgrounds */
.bg-bronze {
  background-color: #cd7f32 !important;
}
.bg-game-result {
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
}
/* Tone Colors & Buttons */
.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;
}
.tone-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
.tone-1 {
  border-color: #0d6efd !important;
  color: #0d6efd;
}
.tone-1:hover,
.tone-1.active {
  background-color: #0d6efd !important;
  color: white !important;
}
.tone-2 {
  border-color: #198754 !important;
  color: #198754;
}
.tone-2:hover,
.tone-2.active {
  background-color: #198754 !important;
  color: white !important;
}
.tone-3 {
  border-color: #fd7e14 !important;
  color: #fd7e14;
}
.tone-3:hover,
.tone-3.active {
  background-color: #fd7e14 !important;
  color: white !important;
}
.tone-4 {
  border-color: #dc3545 !important;
  color: #dc3545;
}
.tone-4:hover,
.tone-4.active {
  background-color: #dc3545 !important;
  color: white !important;
}
.tone-5 {
  border-color: #6c757d !important;
  color: #6c757d;
}
.tone-5:hover,
.tone-5.active {
  background-color: #6c757d !important;
  color: white !important;
}

/* Popover modern styling */
.popover {
  border: none;
  box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.175) !important;
  border-radius: 1rem !important;
  padding: 0;
  max-width: 320px !important;
  transition:
    opacity 0.2s ease,
    transform 0.2s ease !important;
}

.popover-header {
  background-color: transparent !important;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05) !important;
  padding: 1rem 1.25rem !important;
  font-weight: 700 !important;
  color: #212529 !important;
  font-size: 0.9rem !important;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.popover-body {
  padding: 1.25rem !important;
}

.word-detail-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.word-detail-char {
  font-size: 2.5rem;
  font-weight: 400;
  color: #212529;
  line-height: 1.2;
  margin-bottom: 0.25rem;
}

.word-detail-pinyin {
  font-size: 1.1rem;
  color: #6c757d;
  font-weight: 500;
  margin-bottom: 0.75rem;
}

.word-detail-meaning {
  font-size: 1rem;
  color: #0d6efd;
  font-weight: 500;
  line-height: 1.4;
  margin-bottom: 0.75rem;
}

.meaning-explanation {
  font-size: 0.85rem;
  color: #6c757d;
  font-weight: 400;
  display: block; /* Show explanation on new line for better focus on main meaning */
  margin-top: 0.25rem;
}

.word-detail-pron {
  font-size: 0.9rem;
  color: #adb5bd;
  margin-bottom: 1rem;
}

.word-detail-pos-badge {
  padding: 0.35em 1em !important;
  font-weight: 600 !important;
  border-radius: 0.5rem !important;
  font-size: 0.75rem !important;
  letter-spacing: 0.02em;
}

.word-detail-example-zh {
  font-size: 1.1rem;
  line-height: 1.4;
  margin-bottom: 0.2rem;
}

.word-detail-example-pinyin {
  font-size: 0.8rem;
  margin-bottom: 0.2rem;
}

.word-detail-example-vn {
  font-size: 0.8rem;
  opacity: 0.85;
}

/* Custom shadow for popover arrow */
.bs-popover-top > .popover-arrow::after {
  border-top-color: #fff !important;
}
.bs-popover-bottom > .popover-arrow::after {
  border-bottom-color: #fff !important;
}

/* Pulse animation for the speaker */
@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;
}

.z-modal {
  z-index: 1055;
}

/* Toast override for higher elevation */
.toast-container {
  z-index: 1055;
}

/* Cursor utilities */
.cursor-pointer {
  cursor: pointer;
}

/* Learn page specific */
.chinese-analysis-container {
  font-family: var(--bs-body-font-family);
  letter-spacing: normal;
  min-height: 120px;
  gap: 0 !important; /* Reduce gap between analysis lines */
}

.sentence-wrapper {
  margin-bottom: 0.5rem !important; /* Reduce space between sentences */
}

.analysis-line {
  padding: 0.5rem !important;
}

@media (max-width: 768px) {
  .chinese-analysis-container {
    padding: 0.75rem !important;
  }
}

.meaning-token,
.chinese-text {
  font-family: "Kaiti SC", "STKaiti", "STKaiti SC", "KaiTi", "BiauKai", "Noto Serif CJK SC", "STSong", "serif";
  letter-spacing: 0.05em;
}

@media (max-width: 768px) {
  .sentence-wrapper {
    margin-bottom: 0.5rem !important;
  }
  .analysis-line {
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
    flex-wrap: wrap !important; /* Allow wrapping */
  }
  .analysis-line .flex-grow-1 {
    width: 100% !important; /* Force text to full width on mobile */
    margin-bottom: 0.5rem;
  }
  .analysis-line .ms-3.d-flex {
    width: 100% !important; /* Force buttons to wrap below */
    justify-content: flex-end !important;
    margin-left: 0 !important;
    border-top: 1px dashed rgba(0, 0, 0, 0.05);
    padding-top: 0.25rem;
  }
  .circle-34 {
    width: 30px !important;
    height: 30px !important;
    min-width: 30px !important;
  }
  .translation-text {
    margin-left: 2rem !important;
    padding: 0.25rem 0.75rem !important;
    font-size: 1rem !important;
  }
}

.translation-text {
  font-family: var(--bs-body-font-family);
  letter-spacing: normal;
}

.game-section-border {
  border-top: 5px solid #ffc107 !important;
}
.game-title-color {
  color: #856404;
}

@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;
  }
}

.tracking-wider {
  letter-spacing: 0.05em;
}
.ls-1 {
  letter-spacing: 0.1em;
}
.fs-tiny {
  font-size: 0.7rem;
}

/* Auto-resize helper for textareas — JS toggles overflow when exceeding maxHeight */
textarea.autoresize {
  overflow-y: hidden;
  resize: none; /* JS manages height */
  min-height: 2.5rem;
  max-height: 48vh; /* avoid taking the whole viewport */
}

/* Mastery section helpers */
#masterySection {
  /* Visual separation from the controls above (TTS/buttons) */
  margin-top: 1rem;
}
#masterySection .card {
  border-radius: 0.7rem;
}

/* Use Bootstrap's default badge sizing — no custom badge size overrides to keep framework defaults consistent */

#masterySection .mastery-controls .form-select {
  min-width: 180px;
  max-width: 320px;
}
#masterySection .mastery-controls .btn {
  min-width: 88px;
}
#masterySection .card .text-muted {
  color: #6c757d;
}
#masterySection .mastery-controls .form-select {
  min-width: 180px;
  max-width: 320px;
}
#masterySection .mastery-controls .btn {
  min-width: 88px;
}
#masterySection .card .text-muted {
  color: #6c757d;
}
/* Slight breathing room underneath the TTS control area */
#ttsControls {
  margin-bottom: 0.6rem;
}
@media (max-width: 767px) {
  /* stack controls on small screens for easy tapping */
  #masterySection .min-w-220 {
    min-width: 140px;
    width: 100%;
  }
  #masterySection .text-md-end {
    text-align: left !important;
  }
}

/* The rest of the app should rely on Bootstrap's utilities and components. */

/* Pinyin Game Styles */
.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: 10px;
  min-height: 60px;
  z-index: 10;
}

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

.candidate-item {
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.candidate-item:hover {
  background-color: var(--bs-success-subtle);
  border-color: var(--bs-success);
}

.candidate-key {
  font-size: 0.75rem;
  color: var(--bs-secondary);
  background: rgba(0, 0, 0, 0.05);
  padding: 1px 5px;
  border-radius: 3px;
}

.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 Styles */
.matching-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  perspective: 1000px;
}

.matching-card {
  height: 90px;
  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; /* For pair number positioning */
}

/* Pair Number Badge */
.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(13, 110, 253, 0.1);
  color: var(--bs-primary);
  border-color: var(--bs-primary);
  box-shadow: 0 5px 15px rgba(13, 110, 253, 0.2);
}

.matching-card.matched {
  background-color: rgba(25, 135, 84, 0.05); /* Very light green */
  color: #198754 !important; /* Success green */
  border-color: rgba(25, 135, 84, 0.2);
  cursor: default;
  opacity: 0.4; /* Faded out */
  pointer-events: none; /* Disable interaction */
  transform: none !important; /* Force no hover transform */
  box-shadow: none !important; /* Remove shadows */
}

.matching-card.missed {
  background-color: rgba(255, 193, 7, 0.05); /* Very light yellow */
  color: #856404 !important; /* Warning yellow tech */
  border-color: rgba(255, 193, 7, 0.2);
  cursor: default;
  opacity: 0.5; /* Faded out */
  pointer-events: none; /* Disable interaction */
  transform: none !important; /* Force no hover transform */
  box-shadow: none !important; /* Remove shadows */
}

.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; /* Make sure it's fully visible */
  z-index: 10;
}

/* Specific fills and border highlights for last-pair based on status */
.matching-card.last-pair.matched {
  background-color: rgba(25, 135, 84, 0.15) !important; /* Success green transparent */
  box-shadow: 0 0 0 3px rgba(25, 137, 84, 0.5) !important; /* Green glow for correct pair */
}

.matching-card.last-pair.missed {
  background-color: rgba(255, 193, 7, 0.15) !important; /* Warning yellow transparent */
  box-shadow: 0 0 0 3px rgba(255, 193, 7, 0.5) !important; /* Yellow glow for incorrect pair */
}

.matching-card .chinese-text {
  font-size: 1.5rem;
  font-weight: 400; /* Explicitly not bold */
}

.matching-card .meaning-text {
  font-size: 1rem;
  line-height: 1.2;
}

.matching-card .meaning-explanation {
  font-size: 0.8rem;
  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;
  }
}
