/* The parts of a point wherever it shows (feedback cards, the latest
   conversation, the practice card): what was said and how to say it, the
   changed words, the speaker button, the "why" and "explain more", level dots. */

.sentence-box {
  border: 1px solid;
  border-radius: 10px;
  padding: 12px;
}

.sentence-box.wrong {
  background: #fff1f2;
  border-color: #fda4af;
  color: #4c0519;
}

.sentence-box.right {
  background: #f0fdf4;
  border-color: #86efac;
  color: #052e16;
}

.box-label {
  display: block;
  direction: rtl;
  text-align: right;
  font-size: 0.78rem;
  font-weight: 750;
  margin-bottom: 8px;
  opacity: 0.78;
}

.sentence {
  direction: ltr;
  text-align: left;
  line-height: 1.65;
  font-size: 1.02rem;
}

.change {
  border-radius: 4px;
  padding: 1px 3px;
  font-weight: 750;
}

.wrong .change {
  background: #fecdd3;
  color: #9f1239;
  text-decoration-line: underline;
  text-decoration-style: solid;
  text-decoration-color: #e11d48;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
}

.right .change {
  background: #bbf7d0;
  color: #166534;
}

.explanation {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 9px;
  background: #3b82f610;
  line-height: 1.5;
}

.explanation strong {
  margin-left: 5px;
}

@media (prefers-color-scheme: dark) {
  .sentence-box.wrong {
    background: #4c051955;
    color: #ffe4e6;
    border-color: #be123c;
  }

  .sentence-box.right {
    background: #052e1655;
    color: #dcfce7;
    border-color: #15803d;
  }

  .wrong .change {
    background: #9f1239;
    color: #fff1f2;
  }

  .right .change {
    background: #166534;
    color: #f0fdf4;
  }
}

.sentence-box {
  border-radius: 12px;
}

.sentence-box.wrong {
  border-color: #c95f56;
  background: #f9e5df;
  color: #512720;
}

.sentence-box.right {
  position: relative;
  border-color: #548364;
  background: #e1eee2;
  color: #203d2a;
}

/* Speaker button: reads the corrected sentence aloud. It sits in the corner
   above the start of the English sentence, across from the label. */
.speak-button {
  position: absolute;
  top: 6px;
  left: 6px;
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: none;
  color: inherit;
  cursor: pointer;
  opacity: 0.75;
  transition:
    opacity 0.15s ease,
    color 0.15s ease,
    background-color 0.15s ease;
}

.speak-button svg {
  width: 17px;
  height: 17px;
}

.speak-button:hover {
  background: #54836433;
  opacity: 1;
}

.speak-button.loading,
.speak-button.speaking {
  background: #54836433;
  opacity: 1;
}

/* Waiting for the audio: the icon breathes. Playing: the two sound waves of
   the icon go out one after the other. */
.speak-button.loading svg {
  animation: speak-loading 0.7s ease-in-out infinite alternate;
}

.speak-button.speaking svg path:nth-child(n + 2) {
  animation: speak-wave 1s ease-in-out infinite;
}

.speak-button.speaking svg path:nth-child(3) {
  animation-delay: 0.2s;
}

@keyframes speak-loading {
  to {
    opacity: 0.3;
  }
}

@keyframes speak-wave {
  0%,
  100% {
    opacity: 0.15;
  }
  45%,
  70% {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .speak-button.loading svg,
  .speak-button.speaking svg path:nth-child(n + 2) {
    animation: none;
  }

  .speak-button.speaking {
    background: #548364;
    color: #fff;
  }
}

/* Right after a talk, while its audio is being prepared: the icon is faint
   and a ring turns around it, so the button does not look ready. */
.speak-button.preparing:not(.loading, .speaking) {
  cursor: progress;
}

.speak-button.preparing:not(.loading, .speaking) svg {
  opacity: 0.35;
}

.speak-button.preparing:not(.loading, .speaking)::before {
  content: "";
  position: absolute;
  inset: 2px;
  border: 2px solid currentColor;
  border-block-start-color: transparent;
  border-radius: 50%;
  animation: speak-preparing 0.9s linear infinite;
}

@keyframes speak-preparing {
  to {
    transform: rotate(1turn);
  }
}

/* Without motion, a still dotted ring. */
@media (prefers-reduced-motion: reduce) {
  .speak-button.preparing:not(.loading, .speaking)::before {
    border-style: dotted;
    border-block-start-color: currentColor;
    animation: none;
  }
}

/* The audio did not come: the icon in the warning color. After a press, a
   short note beside the button says so, in the empty strip above the
   sentence; the next press asks again. */
.speak-button.failed:not(.loading) {
  color: var(--signal);
  opacity: 1;
}

.speak-button[data-note]::after {
  content: attr(data-note);
  position: absolute;
  z-index: 3;
  top: 50%;
  left: calc(100% + 6px);
  transform: translateY(-50%);
  width: max-content;
  max-width: 14rem;
  padding: 3px 8px;
  border-radius: 8px;
  background: var(--signal);
  color: #fff;
  font-size: 0.78rem;
  line-height: 1.35;
  text-align: start;
  white-space: normal;
  /* In the page's language, also beside an English sentence. */
  unicode-bidi: plaintext;
  pointer-events: none;
}

.speak-button:focus-visible {
  outline: 3px solid var(--butter);
  outline-offset: 2px;
}

/* No reading aloud during a talk: the mic would pick it up. */
.talk-stage:not([data-state="idle"]) .speak-button {
  opacity: 0.3;
  pointer-events: none;
}

.wrong .change {
  background: #edb6ad;
  color: #7a2f27;
  text-decoration-color: #b84d43;
}

.right .change {
  background: #aed0b5;
  color: #244d31;
}

.explanation {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--sky);
}

/* "Explain more": a small text button under the short "why". The longer
   explanation opens below it, inside the same box. */
.explain-more {
  margin-top: 6px;
}

/* The summary sits inside a conversation card, so the card's own summary
   styles (spacing, boxed arrow) are reset here. */
.explanation .explain-more > summary {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  margin: 0;
  padding: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
  list-style: none;
  cursor: pointer;
  transition: color 0.2s ease;
}

.explanation .explain-more > summary::-webkit-details-marker {
  display: none;
}

.explanation .explain-more > summary::before {
  content: none;
}

.explanation .explain-more > summary:hover,
.explanation .explain-more[open] > summary {
  color: var(--text);
}

.explanation .explain-more > summary:focus-visible {
  border-radius: 6px;
  outline: 3px solid var(--butter);
  outline-offset: 3px;
}

.explanation .explain-more > summary::after {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  rotate: 45deg;
  translate: 0 -2px;
  transition: rotate 0.2s ease;
}

.explanation .explain-more[open] > summary::after {
  rotate: 225deg;
  translate: 0 2px;
}

/* Waiting for the explanation: the label breathes, like the speaker icon. */
.explanation .explain-more.loading > summary {
  cursor: progress;
  animation: speak-loading 0.7s ease-in-out infinite alternate;
}

.explain-more::details-content {
  block-size: 0;
  opacity: 0;
  overflow: clip;
  transition:
    block-size 0.28s cubic-bezier(0.16, 1, 0.3, 1),
    opacity 0.2s ease,
    content-visibility 0.28s allow-discrete;
}

.explain-more[open]::details-content {
  block-size: auto;
  opacity: 1;
}

.explain-more-body {
  display: grid;
  gap: 6px;
  padding-top: 8px;
}

.explain-more-body p {
  margin: 0;
}

.explain-more-failed {
  color: var(--muted);
}

/* The two sentences to compare, one under the other. */
.explain-more-examples {
  display: grid;
  gap: 2px;
  margin: 2px 0 0;
  padding: 8px 12px;
  border-inline-start: 3px solid var(--accent);
  border-radius: 4px 10px 10px 4px;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  font-size: 1.02rem;
  line-height: 1.65;
  list-style: none;
  text-align: left;
}

@media (prefers-reduced-motion: reduce) {
  .explanation .explain-more > summary,
  .explanation .explain-more > summary::after,
  .explain-more::details-content {
    transition: none;
  }

  .explanation .explain-more.loading > summary {
    animation: none;
    opacity: 0.5;
  }
}

/* Practice level: four dots, filled as the point is used correctly. */
.level-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.level-dots i {
  width: 9px;
  height: 9px;
  border: 1.5px solid var(--accent);
  border-radius: 50%;
}

.level-dots i.filled {
  background: var(--accent);
}

.level-dots i.new {
  animation: level-dot-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.25s
    backwards;
}

@keyframes level-dot-pop {
  from {
    background: transparent;
    scale: 0.4;
  }
  60% {
    scale: 1.5;
  }
}

@media (prefers-reduced-motion: reduce) {
  .level-dots i.new {
    animation: none;
  }
}
