/*
 * Phrase Builder — standalone game styles.
 *
 * Lifted from the Translator client, which is why the overlay is still fixed/inset:
 * the game fills its iframe exactly as it filled the in-app overlay. Uses no host CSS
 * variables (only its own --phrase-progress), so it is self-contained.
 */

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

html, body {
  margin: 0;
  height: 100%%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: #2c2338;
  background: #f6f3fb;
}

.phrase-lesson-overlay {
  position: fixed;
  inset: 0;
  z-index: 2100;
  padding: clamp(0px, 2vw, 24px);
  background: rgba(30, 24, 43, 0.42);
  backdrop-filter: blur(14px);
}

.phrase-lesson-overlay[hidden] { display: none; }

.phrase-lesson-shell {
  width: min(980px, 100%);
  height: min(760px, 100%);
  min-height: 560px;
  margin: auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: #302d36;
  border: 1px solid rgba(116, 87, 169, 0.17);
  border-radius: 28px;
  background:
    radial-gradient(circle at 10% 0%, rgba(207, 184, 255, 0.3), transparent 28%),
    #fbfafc;
  box-shadow: 0 28px 80px rgba(32, 20, 52, 0.28);
}

.phrase-lesson-header {
  position: relative;
  padding: 18px 24px 16px;
  border-bottom: 1px solid #ebe8ef;
  background: rgba(255, 255, 255, 0.8);
}

.phrase-lesson-header > div {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
}

.phrase-lesson-brand {
  color: #8b56e9;
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.phrase-lesson-progress-text {
  color: #7a7382;
  font-size: 0.78rem;
  font-weight: 650;
}

.phrase-lesson-close {
  position: absolute;
  top: 10px;
  right: 16px;
  width: 40px;
  height: 40px;
  color: #6d6873;
  font-size: 1.65rem;
  line-height: 1;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.phrase-lesson-close:hover { color: #342e3e; background: #f0edf3; }

.phrase-lesson-progress-track {
  height: 6px;
  margin-top: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #ece8f1;
}

.phrase-lesson-progress-fill {
  width: var(--phrase-progress);
  height: 100%;
  display: block;
  border-radius: inherit;
  background: linear-gradient(90deg, #ae6fff, #6a56e9);
  transition: width 280ms ease;
}

.phrase-lesson-stage {
  min-height: 0;
  flex: 1;
  padding: clamp(24px, 5vw, 52px);
  overflow-y: auto;
}

.phrase-lesson-kicker {
  margin: 0 0 0.8rem;
  color: #9c5ef1;
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.phrase-lesson-intro,
.phrase-lesson-exercise,
.phrase-lesson-complete {
  width: min(820px, 100%);
  margin: 0 auto;
}

.phrase-lesson-loading {
  min-height: 420px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  text-align: center;
}

.phrase-lesson-loading__mark {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  color: #fff;
  border-radius: 24px;
  background: linear-gradient(145deg, #bc7cff, #6846df);
  box-shadow: 0 14px 36px rgba(111, 72, 212, 0.28);
  font-size: 2rem;
}

.phrase-lesson-loading h2 { margin: 6px 0 0; }
.phrase-lesson-loading p { margin: 0; color: #766f7c; }

.phrase-lesson-loading__spinner {
  width: 32px;
  height: 32px;
  margin-top: 8px;
  border: 3px solid #e5d8f4;
  border-top-color: #8454cf;
  border-radius: 50%;
  animation: app-loading-spin 0.8s linear infinite;
}

.phrase-lesson-intro h2,
.phrase-lesson-exercise h2,
.phrase-lesson-complete h2 {
  margin: 0;
  color: #343139;
  font-size: clamp(1.7rem, 3.5vw, 2.55rem);
  line-height: 1.12;
}

.phrase-lesson-source-phrase {
  margin: 1rem 0 0.4rem;
  color: #5f5a66;
  font-size: clamp(1.05rem, 2vw, 1.3rem);
}

.phrase-lesson-target-phrase {
  margin: 0.25rem 0 0;
  color: #7145cb;
  font-size: clamp(1.25rem, 2.5vw, 1.75rem);
  font-weight: 750;
}

.phrase-lesson-phrase-row {
  margin: 0.25rem 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.phrase-lesson-phrase-row > div { min-width: 0; }

.phrase-lesson-transliteration,
.phrase-lesson-phrase-transliteration {
  color: #9a70c9;
  font-size: 0.82rem;
  font-style: italic;
}

.phrase-lesson-phrase-transliteration {
  margin: 0.25rem 0 0;
  letter-spacing: 0.01em;
}

.phrase-lesson-word-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

.phrase-lesson-word-card,
.phrase-lesson-picture-choice {
  position: relative;
  min-width: 0;
  padding: 10px;
  display: grid;
  text-align: left;
  border: 2px solid #e7e3e9;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 4px 0 #e4e0e6;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.phrase-lesson-word-card:hover,
.phrase-lesson-picture-choice:hover {
  transform: translateY(-2px);
  border-color: #c49af7;
  box-shadow: 0 6px 0 #dbc9ee;
}

.phrase-lesson-word-card.is-met {
  border-color: #5bc995;
  background: #f1fcf7;
  box-shadow: 0 4px 0 #a8dfc6;
}

.phrase-lesson-word-card.is-met::before {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  content: "✓";
  color: #fff;
  border-radius: 50%;
  background: #45b983;
  font-size: 0.8rem;
  font-weight: 900;
}

.phrase-lesson-word-card img,
.phrase-lesson-picture-choice img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 12px;
  background: #f4f1f6;
}

.phrase-lesson-word-card__target {
  margin-top: 9px;
  color: #4f386f;
  font-size: 1rem;
  font-weight: 800;
}

.phrase-lesson-word-card .phrase-lesson-transliteration {
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.phrase-lesson-word-card__source {
  margin-top: 2px;
  overflow: hidden;
  color: #827b8a;
  font-size: 0.77rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.phrase-lesson-word-card__audio,
.phrase-lesson-picture-choice__audio {
  position: absolute;
  right: 14px;
  bottom: 12px;
  color: #9b68e8;
  font-weight: 800;
}

.phrase-lesson-intro__hint {
  margin: 1rem 0;
  color: #7a7480;
  font-size: 0.88rem;
}

.phrase-lesson-primary,
.phrase-lesson-secondary {
  min-height: 48px;
  padding: 0.75rem 1.25rem;
  border-radius: 14px;
  font-size: 0.95rem;
  font-weight: 800;
  cursor: pointer;
}

.phrase-lesson-primary {
  color: #fff;
  border: 1px solid #7045d5;
  background: linear-gradient(145deg, #9b63ed, #6844dc);
  box-shadow: 0 4px 0 #5334b3;
}

.phrase-lesson-primary:hover:not(:disabled) { transform: translateY(-1px); }

.phrase-lesson-primary:disabled {
  color: #a5a0aa;
  border-color: #e0dce3;
  background: #e8e5ea;
  box-shadow: 0 3px 0 #d9d5dc;
  cursor: default;
}

.phrase-lesson-secondary {
  color: #5d5666;
  border: 1px solid #d9d4de;
  background: #fff;
}

.phrase-lesson-prompt-row {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.phrase-lesson-speaker {
  width: 60px;
  height: 60px;
  flex: 0 0 auto;
  color: #fff;
  font-size: 1.6rem;
  border: 0;
  border-radius: 18px;
  background: linear-gradient(145deg, #43c9ff, #159ee4);
  box-shadow: 0 5px 0 #1384c1;
  cursor: pointer;
}

.phrase-lesson-choices {
  margin-top: clamp(24px, 5vw, 48px);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.phrase-lesson-choices.is-text { grid-template-columns: 1fr; gap: 12px; }
.phrase-lesson-picture-choice { padding: 14px; }

.phrase-lesson-picture-choice > span:not(.phrase-lesson-picture-choice__audio) {
  margin-top: 10px;
  color: #463a50;
  font-size: 1.05rem;
  font-weight: 800;
}

.phrase-lesson-picture-choice small { margin-top: 2px; color: #85808a; }
.phrase-lesson-picture-choice em {
  margin-top: 1px;
  color: #9a70c9;
  font-size: 0.8rem;
}

.phrase-lesson-text-choice {
  min-height: 66px;
  padding: 0.9rem 1.2rem;
  color: #49444f;
  text-align: center;
  border: 2px solid #e4e0e6;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 4px 0 #dfdbe2;
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
}

.phrase-lesson-text-choice span,
.phrase-lesson-text-choice small {
  display: block;
}

.phrase-lesson-text-choice small {
  margin-top: 3px;
  color: #9a70c9;
  font-size: 0.78rem;
  font-weight: 600;
}

.phrase-lesson-text-choice:hover:not(:disabled) { border-color: #ba8bf2; }

.phrase-lesson-picture-choice.is-wrong,
.phrase-lesson-text-choice.is-wrong {
  border-color: #f0787c;
  background: #fff2f2;
  box-shadow: 0 4px 0 #e8b0b1;
}

.phrase-lesson-picture-choice.is-correct,
.phrase-lesson-text-choice.is-correct {
  border-color: #56c894;
  background: #effcf6;
  box-shadow: 0 4px 0 #a7dfc5;
}

.phrase-lesson-picture-choice.is-revealed,
.phrase-lesson-text-choice.is-revealed {
  outline: 3px solid rgba(86, 200, 148, 0.22);
  outline-offset: 3px;
}

.phrase-lesson-gap-phrase {
  margin: clamp(28px, 5vw, 52px) 0 0;
  padding: 1.1rem 1.25rem;
  color: #4b3c5d;
  border: 1px solid #ded8e5;
  border-radius: 16px;
  background: #fff;
  font-size: clamp(1.3rem, 2.5vw, 1.8rem);
  font-weight: 700;
}

.phrase-lesson-build-audio {
  margin-top: 1.25rem;
  padding: 0.8rem 1rem;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  column-gap: 0.8rem;
  text-align: left;
  border: 1px solid #dfeaf0;
  border-radius: 16px;
  background: #f4fbff;
}

.phrase-lesson-build-audio .phrase-lesson-speaker {
  grid-row: 1 / span 2;
  width: 50px;
  height: 50px;
  border-radius: 15px;
  font-size: 1.3rem;
}

.phrase-lesson-build-audio span { color: #43515a; font-weight: 800; }
.phrase-lesson-build-audio small { color: #7e7190; font-style: italic; }

.phrase-lesson-answer-row {
  min-height: 78px;
  margin-top: 2rem;
  padding: 12px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  border: 2px dashed #d7d0dd;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.65);
}

.phrase-lesson-answer-row.is-correct { border-color: #65c998; background: #effcf6; }
.phrase-lesson-answer-placeholder { color: #aaa3af; }

.phrase-lesson-selected-tile,
.phrase-lesson-pool-tile {
  min-height: 46px;
  padding: 0.65rem 0.9rem;
  color: #4c4455;
  border: 1px solid #ddd7e2;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 3px 0 #ddd9df;
  font-size: 1rem;
  font-weight: 750;
  cursor: pointer;
}

.phrase-lesson-selected-tile span,
.phrase-lesson-selected-tile small,
.phrase-lesson-pool-tile span,
.phrase-lesson-pool-tile small {
  display: block;
}

.phrase-lesson-selected-tile small,
.phrase-lesson-pool-tile small {
  margin-top: 2px;
  color: #9a70c9;
  font-size: 0.67rem;
  font-weight: 600;
}

.phrase-lesson-selected-tile.is-fixed {
  color: #6946a7;
  background: #f2ebff;
  cursor: default;
}

.phrase-lesson-tile-pool {
  min-height: 72px;
  margin: 1rem 0 1.4rem;
  padding: 12px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  border-top: 1px solid #e1dce5;
  border-bottom: 1px solid #e1dce5;
}

.phrase-lesson-feedback-bar {
  min-height: 78px;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 1rem;
  border-top: 1px solid #e7e3e9;
  background: #fff;
}

.phrase-lesson-feedback-bar[hidden] { display: none; }
.phrase-lesson-feedback { margin: 0; color: #a6434a; font-weight: 750; }
.phrase-lesson-feedback.is-success { color: #287b56; }
.phrase-lesson-feedback-bar .phrase-lesson-primary { margin-left: auto; }

.phrase-lesson-feedback[hidden],
.phrase-lesson-feedback-bar .phrase-lesson-primary[hidden] { display: none; }

.phrase-lesson-complete { text-align: center; }

.phrase-lesson-celebration {
  width: 76px;
  height: 76px;
  margin: 0 auto 1rem;
  display: grid;
  place-items: center;
  color: #fff;
  border-radius: 24px;
  background: linear-gradient(145deg, #bc7cff, #6846df);
  box-shadow: 0 12px 30px rgba(111, 72, 212, 0.3);
  font-size: 2rem;
}

.phrase-lesson-complete__result { color: #625c69; }
.phrase-lesson-save-warning { color: #b84e52; font-weight: 700; }

.phrase-lesson-saved-badge {
  width: fit-content;
  margin: 1rem auto;
  padding: 0.55rem 0.85rem;
  color: #287b56;
  border: 1px solid #9ad9bd;
  border-radius: 999px;
  background: #effcf6;
  font-weight: 850;
}

.phrase-lesson-result-words {
  margin: 1.5rem 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  list-style: none;
}

.phrase-lesson-result-words li {
  padding: 8px;
  display: grid;
  gap: 3px;
  text-align: left;
  border: 1px solid #e1dce5;
  border-radius: 14px;
  background: #fff;
}

.phrase-lesson-result-words img {
  width: 100%;
  aspect-ratio: 1.35;
  object-fit: cover;
  border-radius: 9px;
}

.phrase-lesson-result-words span { margin-top: 4px; color: #543b72; font-weight: 800; }
.phrase-lesson-result-words em { color: #9a70c9; font-size: 0.72rem; }
.phrase-lesson-result-words small { color: #817a87; }

.phrase-lesson-games-discovery {
  margin: 1.5rem 0;
  padding: 1rem;
  display: grid;
  gap: 0.55rem;
  color: #554961;
  text-align: left;
  border: 1px solid #d7c3f2;
  border-radius: 18px;
  background: linear-gradient(145deg, #faf6ff, #f3edff);
}

.phrase-lesson-games-discovery strong { color: #573b82; font-size: 1.05rem; }
.phrase-lesson-games-discovery .phrase-lesson-primary { margin-top: 0.35rem; }

.phrase-lesson-complete__actions {
  display: flex;
  justify-content: center;
  gap: 12px;
}

@media (max-width: 720px) {
  .phrase-lesson-overlay { padding: 0; }

  .phrase-lesson-shell {
    width: 100%;
    height: 100%;
    min-height: 0;
    border: 0;
    border-radius: 0;
  }

  .phrase-lesson-header { padding-inline: 16px; }
  .phrase-lesson-stage { padding: 24px 16px; }

  .phrase-lesson-word-grid,
  .phrase-lesson-result-words { grid-template-columns: repeat(3, minmax(0, 1fr)); }

  .phrase-lesson-choices { grid-template-columns: 1fr; }

  .phrase-lesson-picture-choice {
    grid-template-columns: 92px 1fr;
    align-items: center;
    column-gap: 12px;
  }

  .phrase-lesson-picture-choice img { grid-row: 1 / span 2; }
  .phrase-lesson-picture-choice > span:not(.phrase-lesson-picture-choice__audio) { margin: 0; }

  .phrase-lesson-picture-choice__audio {
    top: 14px;
    right: 14px;
    bottom: auto;
  }

  .phrase-lesson-feedback-bar { min-height: 72px; padding: 12px 16px; }
  .phrase-lesson-complete__actions { flex-direction: column-reverse; }
}

@media (prefers-reduced-motion: reduce) {
  .phrase-lesson-word-card,
  .phrase-lesson-picture-choice,
  .phrase-lesson-progress-fill { transition: none; }
}

/* Standalone toast (the host's toast lives in the parent frame). */
.pb-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 2200;
  max-width: min(90vw, 420px);
  padding: 12px 18px;
  border-radius: 12px;
  background: rgba(44, 35, 56, 0.94);
  color: #fff;
  font-size: 0.9rem;
  box-shadow: 0 12px 30px rgba(30, 24, 43, 0.28);
}

.pb-toast[hidden] { display: none; }
.pb-toast[data-type="info"] { background: rgba(58, 44, 96, 0.94); }
