/* Shared reading-card UI — extracted from thai-flashcards/style.css */

/* -------------------- flashcard -------------------- */

.card-stage {
  margin: 1.5rem 0;
}

.flashcard {
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 1.5rem 1.5rem 1.25rem;
  min-height: 22rem;
  display: flex;
  flex-direction: column;
  animation: card-in 0.28s ease both;
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.995);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .flashcard {
    animation: none;
  }
}

/* Retriggered by script.js on Next/Prev/Shuffle/jump-to-card (see
   playCardTransition()) so switching cards reads as a deliberate reveal
   instead of an instant text swap. Same motion as the initial load-in,
   just re-armed via a class toggle + forced reflow. Skipped entirely
   under prefers-reduced-motion (checked in JS before the class is ever
   added, so no @media override is needed here). */
.flashcard.is-turning {
  animation: card-in 0.22s ease both;
}

.card-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-height: 1.6rem;
}

.card-topline-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
}

.explain-topline {
  justify-content: flex-start;
  margin-bottom: 0.35rem;
}

.mastery-badge {
  padding: 0.28rem 0.65rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}

.mastery-badge--mastered {
  background: var(--jade-soft);
  color: var(--jade-ink);
}

.mastery-badge--practice {
  background: var(--clay-soft);
  color: var(--clay);
}

.speak-btn {
  background: none;
  border: none;
  color: var(--ink-faint);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  transition: color 0.15s ease, transform 0.15s ease;
}

.speak-btn:hover:not(:disabled) {
  color: var(--jade);
}

.speak-btn[aria-pressed="true"],
.speak-btn.is-speaking {
  color: var(--jade);
}

.speak-btn:active:not(:disabled) {
  transform: scale(0.92);
}

.speak-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.icon-speak {
  width: 1.4rem;
  height: 1.4rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}

.star-btn {
  background: none;
  border: none;
  color: var(--ink-faint);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  transition: color 0.15s ease, transform 0.15s ease;
}

.star-btn:hover {
  color: var(--saffron);
}

.star-btn[aria-pressed="true"] {
  color: var(--saffron);
}

.star-btn[aria-pressed="true"] .icon-star {
  fill: var(--saffron);
}

.star-btn:active {
  transform: scale(0.92);
}

.icon-star {
  width: 1.4rem;
  height: 1.4rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
}

.card-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.3rem;
  text-align: center;
  padding: 1rem 0;
}

.thai-text {
  font-family: var(--font-thai), "Work Sans", sans-serif;
  font-size: clamp(2.4rem, 9vw, 3.6rem);
  font-weight: 700;
  color: var(--ink);
  line-height: 1.9;
  margin: 0;
  cursor: pointer;
  user-select: text;
  letter-spacing: 0.01em;
}

/* Word groups: adjacent by default (Thai script has no inter-word spaces).
   The "Split Words" toggle adds visible spacing between groups without
   inserting extra characters into the DOM text, so copy-to-clipboard still
   yields the exact original sentence. */
.thai-word-group {
  display: inline;
}

.thai-text.is-split .thai-word-group + .thai-word-group {
  margin-left: 0.5em;
}

/* Per-grapheme hover/tap tooltip. Glyphs still render per codepoint
   (.thai-char) for CHAR_INFO lookup, but the interactive hit-box is the
   visual grapheme cluster (.thai-grapheme = base + combining marks) so
   tone marks and stacked vowels are reachable by mouse/touch. The
   accessible name is on the cluster via aria-label; the visual tooltip is
   aria-hidden to avoid double announcement. */
.thai-grapheme {
  position: relative;
  display: inline-block;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.thai-char {
  display: inline;
}

.thai-grapheme:hover,
.thai-grapheme:focus-visible,
.thai-grapheme.is-open {
  background: var(--jade-soft);
}

.thai-grapheme:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}

.char-tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translate(-50%, -4px);
  width: max-content;
  max-width: min(18rem, calc(100vw - 2rem));
  background: var(--ink);
  color: var(--paper);
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-sm);
  font-family: "Work Sans", sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1.45;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 30;
}

.char-tooltip-entry + .char-tooltip-entry {
  display: block;
  margin-top: 0.45rem;
  padding-top: 0.4rem;
  border-top: 1px solid rgba(250, 245, 233, 0.25);
}

.thai-grapheme:hover .char-tooltip,
.thai-grapheme:focus-visible .char-tooltip,
.thai-grapheme.is-open .char-tooltip {
  opacity: 1;
  transform: translate(-50%, -8px);
}

@media (prefers-reduced-motion: reduce) {
  .char-tooltip {
    transition: opacity 0.01s linear;
  }
}

.char-tooltip strong {
  display: block;
  font-weight: 700;
}

.char-tooltip-thai {
  display: block;
  font-family: var(--font-thai), sans-serif;
  opacity: 0.85;
}

.char-tooltip-meaning {
  display: block;
  font-style: italic;
  opacity: 0.85;
  margin-top: 0.1rem;
}

.char-tooltip-class {
  display: block;
  opacity: 0.7;
  font-size: 0.85em;
  margin-top: 0.1rem;
}

.reveal-block {
  width: 100%;
  max-width: 22rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.reveal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.reveal-btn {
  width: 100%;
  padding: 0.65rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--rule-strong);
  background: var(--paper);
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.split-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  width: 100%;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-md);
  border: 1px dashed var(--rule-strong);
  background: transparent;
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.split-btn:hover {
  border-color: var(--jade);
  color: var(--jade-ink);
  background: var(--jade-soft);
}

.split-btn.is-active {
  border-style: solid;
  border-color: var(--jade);
  color: var(--jade-ink);
  background: var(--jade-soft);
}

.literal-gloss-block {
  margin-bottom: 0.55rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px dashed var(--rule);
}

.literal-value {
  font-style: italic;
  color: var(--ink-soft);
  font-weight: 500;
  cursor: text;
}

.reveal-btn:hover {
  border-color: var(--jade);
  color: var(--jade-ink);
  background: var(--jade-soft);
}

.reveal-btn.is-active {
  background: var(--jade);
  border-color: var(--jade);
  color: var(--paper-raised);
}

.reveal-btn--secondary.is-active {
  background: var(--saffron);
  border-color: var(--saffron);
  color: var(--paper-raised);
}

.reveal-panel {
  margin-top: 0.7rem;
  animation: fade-up 0.22s ease both;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .reveal-panel {
    animation: none;
  }
}

.reveal-label {
  margin: 0 0 0.2rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.reveal-value {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}

.phonetic-value {
  color: var(--jade-ink);
}

/* word-by-word breakdown */

.breakdown-block {
  width: 100%;
  max-width: 22rem;
  padding-top: 0.4rem;
  border-top: 1px dashed var(--rule);
}

.breakdown-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin: 0.6rem auto 0;
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.2rem 0.3rem;
}

.breakdown-toggle:hover {
  color: var(--jade-ink);
}

.chevron {
  width: 0.9rem;
  height: 0.9rem;
  transition: transform 0.18s ease;
}

.breakdown-toggle[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

@media (prefers-reduced-motion: reduce) {
  .chevron {
    transition: none;
  }
}

.breakdown-panel {
  margin-top: 0.6rem;
  animation: fade-up 0.22s ease both;
}

@media (prefers-reduced-motion: reduce) {
  .breakdown-panel {
    animation: none;
  }
}

.word-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.word-chip {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  padding: 0.5rem 0.75rem;
  text-align: left;
  min-width: 6.5rem;
}

.word-chip-thai {
  font-family: var(--font-thai), sans-serif;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--ink);
  display: block;
}

.word-chip-phonetic {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--jade-ink);
  margin-top: 0.15rem;
}

.word-chip-translation {
  display: block;
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin-top: 0.1rem;
}

/* Nested syllable reveal — one level deeper than word chips */

.syllable-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  margin-top: 0.45rem;
  padding: 0.1rem 0;
  background: none;
  border: none;
  color: var(--ink-faint);
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
  line-height: 1.2;
}

.syllable-toggle:hover {
  color: var(--jade-ink);
}

.chevron--sm {
  width: 0.7rem;
  height: 0.7rem;
}

.syllable-toggle[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

.syllable-list {
  list-style: none;
  margin: 0.4rem 0 0;
  padding: 0.35rem 0 0 0.55rem;
  border-left: 2px solid var(--rule);
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  animation: fade-up 0.22s ease both;
}

@media (prefers-reduced-motion: reduce) {
  .syllable-list {
    animation: none;
  }
}

.syllable-chip {
  background: var(--paper-raised);
  border: 1px dashed var(--rule);
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.4rem;
  text-align: left;
  min-width: 0;
}

.syllable-chip-thai {
  font-family: var(--font-thai), sans-serif;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  display: block;
  line-height: 1.45;
}

.syllable-chip-phonetic {
  display: block;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--jade-ink);
  margin-top: 0.05rem;
}

.card-footer {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.72rem;
  color: var(--ink-faint);
  border-top: 1px solid var(--rule);
  padding-top: 0.8rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}
