/* ============================================================
   Learn Page – Sentence Analysis & Practice
   ============================================================ */

/* ── Token Card (Vocabulary Display) ───────────────────────── */
.token-card {
  cursor: pointer;
  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;
}

.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);
}

/* Radical indicator on token card */
.token-card-radical {
  position: absolute;
  top: 0.3rem;
  left: 0.4rem;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: "Noto Serif CJK SC", "Source Han Serif SC", "STSong", serif;
  color: #94a3b8;
  line-height: 1;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
}

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

/* Small screens: 2 per row */
@media (max-width: 576px) {
  #tokens {
    gap: 0.75rem !important;
  }

  .token-card {
    flex: 0 0 calc((100% - 0.75rem) / 2) !important;
    display: flex;
    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;
  }
}

/* ── Stroke Order Display ───────────────────────────────────── */
.stroke-char-wrapper {
  width: 180px;
  height: 180px;
}

.stroke-char-target {
  width: 100%;
  height: 100%;
  max-width: 100%;
  display: block;
}

@media (max-width: 576px) {
  .stroke-char-wrapper {
    width: 140px;
    height: 140px;
  }
}

@media (max-width: 320px) {
  .stroke-char-wrapper {
    width: 120px;
    height: 120px;
  }
}

.stroke-order-trigger:hover {
  background-color: var(--bs-primary-bg-subtle) !important;
  color: var(--bs-primary) !important;
}

/* ── Meaning Token (POS-colored tokens in analysis) ───────── */
.meaning-token {
  display: inline-block;
  padding: 0.5rem 0.65rem;
  margin: 0.15rem;
  border-radius: 0.4rem;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  transition:
    transform 0.12s ease,
    box-shadow 0.12s ease,
    background-color 0.12s ease;
  background: transparent;
  color: #212529;
  font-family: "Kaiti SC", "STKaiti", "STKaiti SC", "KaiTi", "BiauKai", "Noto Serif CJK SC", "STSong", "serif";
  letter-spacing: 0.05em;
}

.meaning-token:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.08);
}

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

/* POS-specific colors */
.meaning-token[data-pos^="NN"] {
  background: rgba(79, 70, 229, 0.12);
  color: #4f46e5;
}

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

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

/* ── Alternative Selection (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(79, 70, 229, 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: #4f46e5;
  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: #4f46e5;
}

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

.alt-item .meaning-token {
  font-size: 1.25rem !important;
  padding: 0.25rem 0.5rem !important;
}

/* Shared token popover styling moved to static/css/token_popover.css */

/* ── Analysis Container (Sentence Analysis) ───────────────── */
.chinese-analysis-container {
  font-family: var(--bs-body-font-family);
  letter-spacing: normal;
  min-height: 120px;
  gap: 0 !important;
}

.sentence-wrapper {
  margin-bottom: 0.5rem !important;
}

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

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

.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;
  }
  .analysis-line .flex-grow-1 {
    width: 100% !important;
    margin-bottom: 0.5rem;
  }
  .analysis-line .ms-3.d-flex {
    width: 100% !important;
    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;
}

.translation-pinyin {
  margin-left: 2rem;
  font-size: 0.9rem;
  font-weight: 400;
  line-height: 1.25;
  color: var(--bs-body-color);
  opacity: 0.75;
}

.translation-pinyin.small {
  font-size: 0.9rem;
}

/* ── Mastery Section ───────────────────────────────────────── */
#masterySection {
  margin-top: 1rem;
}

#masterySection .card {
  border-radius: 0.7rem;
}

#masterySection .mastery-controls .form-select {
  min-width: 180px;
  max-width: 320px;
}

#masterySection .mastery-controls .btn {
  min-width: 88px;
}

#masterySection .card .text-muted {
  color: #6c757d;
}

#ttsControls {
  margin-bottom: 0.6rem;
}

@media (max-width: 767px) {
  #masterySection .min-w-220 {
    min-width: 140px;
    width: 100%;
  }
  #masterySection .text-md-end {
    text-align: left !important;
  }
}

/* ── Dictionary Detail Modal ───────────────────────────────── */
#dictionaryDetailModal .modal-content {
  border: none;
  overflow: hidden;
}

#dictionaryDetailModal .dict-entry {
  animation: dictEntryFadeIn 0.3s ease-out;
}

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

.dict-char-box {
  transition: transform 0.2s ease;
}

.dict-char-box:hover {
  transform: scale(1.05);
  cursor: pointer;
}

.dict-meanings {
  padding-left: 1rem;
  border-left: 3px solid var(--bs-primary-bg-subtle);
}

/* ── Auto-resize Textarea Helper ──────────────────────────── */
textarea.autoresize {
  overflow-y: hidden;
  resize: none;
  min-height: 2.5rem;
  max-height: 48vh;
}

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

/* ── Grade Pill Styles (Video-game 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;
}

.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, #4f46e5);
  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;
}

/* ── Member Mastery Chip ──────────────────────────────────── */
.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;
}

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

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