/*
 * Word pronunciation card (shared by Speaking, Read Aloud and the CRM entrance-test result page).
 * Rendered by public/js/pronunciation-tooltip.js.
 * The root uses `#crm-word-tooltip.pt-card` so it wins over the legacy dark `#crm-word-tooltip` rules.
 */

.pt-card,
#crm-word-tooltip.pt-card {
  --pt-arrow-x: 50%;
  --pt-surface: #ffffff;
  --pt-foot: #f8fafc;
  --pt-border: #e2e8f0;
  --pt-ink: #0f172a;
  --pt-text: #1e293b;
  --pt-muted: #64748b;
  --pt-link: #2563eb;

  position: fixed;
  z-index: 25000;
  display: none;
  flex-direction: column;
  gap: 0;
  box-sizing: border-box;
  width: 328px;
  min-width: 0;
  max-width: calc(100vw - 16px);
  padding: 0;
  overflow: visible;
  background: var(--pt-surface);
  color: var(--pt-text);
  border: 1px solid var(--pt-border);
  border-radius: 14px;
  box-shadow: 0 18px 40px -12px rgba(15, 23, 42, 0.28), 0 4px 12px -4px rgba(15, 23, 42, 0.12);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  text-align: left;
  white-space: normal;
  letter-spacing: normal;
  pointer-events: auto;
  transition: none;
  animation: pt-card-in 0.14s ease-out;
}

.pt-card *,
.pt-card *::before,
.pt-card *::after {
  box-sizing: border-box;
}

.pt-card p {
  margin: 0;
}

/* Neutralise page-wide button styles inside the card. */
.pt-card button {
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  font: inherit;
  color: inherit;
  text-transform: none;
  letter-spacing: normal;
  min-height: 0;
  min-width: 0;
  width: auto;
  box-shadow: none;
  cursor: pointer;
}

.pt-card :focus-visible {
  outline: 2px solid var(--pt-link);
  outline-offset: 2px;
}

/* Invisible bridge over the gap between the word and the card. */
.pt-card::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 14px;
  background: transparent;
}

.pt-card[data-placement="top"]::before { top: 100%; }
.pt-card[data-placement="bottom"]::before { bottom: 100%; }

/* Arrow pointing at the word. */
.pt-card::after {
  content: "";
  position: absolute;
  left: var(--pt-arrow-x);
  width: 12px;
  height: 12px;
  border: 1px solid var(--pt-border);
  transform: translateX(-50%) rotate(45deg);
  pointer-events: none;
}

.pt-card[data-placement="top"]::after {
  bottom: -7px;
  background: var(--pt-foot);
  border-top: none;
  border-left: none;
}

.pt-card[data-placement="bottom"]::after {
  top: -7px;
  background: var(--pt-surface);
  border-right: none;
  border-bottom: none;
}

@keyframes pt-card-in {
  from { opacity: 0; transform: translateY(4px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* ---------- Tone palette ---------- */
.pt-tone--green { --pt-c: #047857; --pt-fill: #10b981; --pt-bg: #ecfdf5; --pt-bd: #a7f3d0; }
.pt-tone--amber { --pt-c: #b45309; --pt-fill: #f59e0b; --pt-bg: #fffbeb; --pt-bd: #fde68a; }
.pt-tone--red   { --pt-c: #b91c1c; --pt-fill: #ef4444; --pt-bg: #fef2f2; --pt-bd: #fecaca; }
.pt-tone--none  { --pt-c: #475569; --pt-fill: #94a3b8; --pt-bg: #f1f5f9; --pt-bd: #e2e8f0; }

/* ---------- Header ---------- */
.pt-card__head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px 8px;
}

.pt-card__title {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 8px;
}

.pt-card__word {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--pt-ink);
  overflow-wrap: anywhere;
}

.pt-card__play-word {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  border: 1px solid var(--pt-border);
  background: var(--pt-foot);
  color: var(--pt-muted);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease, color 0.12s ease;
  vertical-align: middle;
}

.pt-card__play-word:hover {
  background: #e2e8f0;
  color: var(--pt-ink);
  transform: scale(1.08);
}

.pt-card__play-word .pt-icon {
  width: 10px;
  height: 10px;
  fill: currentColor;
  margin-left: 1px;
}

.pt-card__ipa {
  font-size: 15px;
  color: var(--pt-muted);
}

.pt-card__score {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.pt-ring {
  position: relative;
  width: 52px;
  height: 52px;
}

.pt-ring__svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.pt-ring__track,
.pt-ring__value {
  fill: none;
  stroke-width: 4;
}

.pt-ring__track { stroke: #e2e8f0; }

.pt-ring__value {
  stroke: var(--pt-fill);
  stroke-linecap: round;
}

.pt-card__score-num {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--pt-c);
}

.pt-card__score-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--pt-muted);
}

.pt-card .pt-card__close {
  position: relative;
  display: none;
  flex: 0 0 auto;
  align-self: flex-start;
  width: 28px;
  height: 28px;
  padding: 0;
  margin: -4px -6px 0 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--pt-muted);
  font-size: 20px;
  line-height: 28px;
  text-align: center;
}

.pt-card .pt-card__close::before {
  content: "";
  position: absolute;
  inset: -6px;
}

.pt-card .pt-card__close:hover { background: #f1f5f9; color: var(--pt-ink); }
.pt-card.pt-card--pinned .pt-card__close { display: inline-block; }

/* ---------- Body ---------- */
.pt-card__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.pt-card__summary {
  padding: 0 16px 12px;
  color: #334155;
}

.pt-card__section {
  padding: 12px 16px;
  border-top: 1px solid #f1f5f9;
}

.pt-card__label {
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--pt-muted);
}

.pt-card__label-hint { font-weight: 400; }

.pt-icon {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  fill: currentColor;
}

/* ---------- Syllable tiles ---------- */
.pt-syls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pt-syl {
  flex: 1 1 0;
  min-width: 56px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 5px;
  padding: 8px 8px 6px;
  border: 1px solid var(--pt-bd);
  border-radius: 10px;
  background: var(--pt-bg);
  color: var(--pt-c);
  text-align: center;
  cursor: default;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.pt-card button.pt-syl {
  border: 1px solid var(--pt-bd);
  background: var(--pt-bg);
  color: var(--pt-c);
  cursor: pointer;
}

button.pt-syl:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px -4px rgba(15, 23, 42, 0.25);
}

.pt-syl.is-focus { box-shadow: 0 0 0 2px var(--pt-fill); }
.pt-card button.pt-syl.is-focus { box-shadow: 0 0 0 2px var(--pt-fill); }

.pt-syl__text {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.pt-syl__bar {
  display: block;
  height: 5px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.08);
  overflow: hidden;
}

.pt-syl__fill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--pt-fill);
  transition: width 0.35s ease-out;
}

.pt-syl__score {
  font-size: 12px;
  font-weight: 600;
}

/* ---------- Focus (main problem) ---------- */
.pt-focus {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pt-focus__head {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pt-focus__label {
  font-size: 12px;
  font-weight: 600;
  color: var(--pt-muted);
}

.pt-focus__syl {
  font-size: 15px;
  font-weight: 700;
  color: var(--pt-ink);
}

.pt-focus__score {
  margin-left: auto;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--pt-bg);
  border: 1px solid var(--pt-bd);
  color: var(--pt-c);
  font-size: 12px;
  font-weight: 700;
}

.pt-compare {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.pt-compare__box {
  flex: 1 1 0;
  min-width: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid;
  text-align: left;
}

.pt-compare__box--heard,
.pt-card button.pt-compare__box--heard {
  background: #fef2f2;
  border-color: #fecaca;
  color: #b91c1c;
}

.pt-compare__box--target {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #047857;
}

button.pt-compare__box--heard:hover { background: #fee2e2; }

.pt-compare__cap {
  font-size: 11px;
  font-weight: 600;
  opacity: 0.85;
}

.pt-compare__ipa {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.pt-compare__play {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: inline-flex;
}

.pt-compare__play .pt-icon { width: 12px; height: 12px; }

.pt-compare__arrow {
  align-self: center;
  color: #94a3b8;
  font-size: 16px;
}

.pt-focus__heard,
.pt-focus__change,
.pt-more__change {
  font-size: 13px;
  color: #475569;
}

.pt-focus__note,
.pt-more__note {
  color: var(--pt-text);
}

/* ---------- How to fix ---------- */
.pt-fix {
  margin: 0;
}

.pt-fix__toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--pt-link);
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.pt-fix__toggle::-webkit-details-marker,
.pt-more__toggle::-webkit-details-marker { display: none; }

.pt-fix__toggle::before,
.pt-more__toggle::before {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.15s ease;
}

.pt-fix[open] > .pt-fix__toggle::before,
.pt-more[open] > .pt-more__toggle::before { transform: rotate(90deg); }

.pt-card .pt-fix__text {
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #eff6ff;
  color: #1e3a8a;
}

/* ---------- More issues ---------- */
.pt-more__toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #475569;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.pt-more__list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pt-more__item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.pt-more__syl,
.pt-card button.pt-more__syl {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 8px;
  border: 1px solid var(--pt-bd);
  background: var(--pt-bg);
  color: var(--pt-c);
  font-size: 13px;
  font-weight: 700;
}

.pt-more__body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ---------- Footer ---------- */
.pt-card__foot {
  padding: 9px 16px;
  background: var(--pt-foot);
  border-top: 1px solid #f1f5f9;
  border-radius: 0 0 14px 14px;
  font-size: 12px;
  color: var(--pt-muted);
}

.pt-card--pinned .pt-card__foot { color: #334155; }

/* ---------- Playing state ---------- */
.pt-card .is-playing {
  animation: pt-playing 0.9s ease-in-out infinite;
}

@keyframes pt-playing {
  0%, 100% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.45); }
  50% { box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15); }
}

@media (prefers-reduced-motion: reduce) {
  .pt-card,
  .pt-card .is-playing,
  .pt-syl__fill,
  button.pt-syl {
    animation: none;
    transition: none;
  }
}

@media print {
  .pt-card,
  #crm-word-tooltip.pt-card {
    display: none !important;
  }
}
