/* Keep effects on the feedback surface so controls and reading order stay put. */
:root { --motion-out: cubic-bezier(.18,.76,.25,1); }

.audio-symbol { position: relative; display: inline-grid; width: 1.15rem; aspect-ratio: 1; place-items: center; vertical-align: middle; }
.audio-symbol .ui-icon { grid-area: 1 / 1; width: 1rem; height: 1rem; }
.audio-wave {
  display: flex;
  grid-area: 1 / 1;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 100%;
  height: .9rem;
  visibility: hidden;
}
.audio-wave i { width: 2px; height: .62rem; border-radius: 2px; background: currentColor; }
.audio-wave i:nth-child(1) { scale: 1 .47; --wave-phase: -360ms; }
.audio-wave i:nth-child(3) { scale: 1 .72; --wave-phase: -210ms; }
.audio-wave i:nth-child(4) { scale: 1 .39; --wave-phase: -440ms; }
:is(.exercise-audio, .audio-settings)[data-audio-state="speaking"] .audio-wave { visibility: visible; }
:is(.exercise-audio, .audio-settings)[data-audio-state="speaking"] .audio-symbol > .ui-icon { visibility: hidden; }

.result-scoreline { display: flex; align-items: center; justify-content: center; gap: clamp(.45rem, 3vw, .9rem); }
.result-ring {
  inline-size: clamp(2rem, 8vw, 3.5rem);
  flex: none;
  margin-block-start: 8px;
  fill: none;
  stroke: #fff8e94d;
  stroke-width: 3.5;
}
#result-ring-value {
  stroke: #f5b198;
  stroke-dasharray: 100 100;
  transform: rotate(-90deg);
  transform-origin: center;
}
#exercise-zone > .prompt::after {
  content: '';
  display: block;
  width: 2.05rem;
  height: .19rem;
  margin: .55rem auto 0;
  border-radius: 1rem;
  background: var(--coral);
}

@media (prefers-reduced-motion: no-preference) {
  .route-stage[data-transition] {
    --route-duration: 250ms;
    --route-enter-x: 15px;
    --route-enter-y: 0px;
    --route-exit-x: -8px;
    --route-exit-y: 0px;
  }
  .route-stage[data-transition="back"] {
    --route-enter-x: -15px;
    --route-exit-x: 8px;
  }
  @media (min-width: 1024px) {
    .route-stage[data-transition] {
      --route-enter-x: 0px;
      --route-enter-y: 13px;
      --route-exit-x: 0px;
      --route-exit-y: -7px;
    }
    .route-stage[data-transition="back"] {
      --route-enter-y: -13px;
      --route-exit-y: 7px;
    }
  }
  .route-stage[data-resizing] {
    animation: route-resize var(--route-duration) var(--motion-out) both;
  }
  [data-route-panel][data-entering] { animation: route-arrive var(--route-duration) var(--motion-out) both; }
  [data-route-panel][data-leaving] { animation: route-depart 180ms ease-out both; }

  .landing-specimen[data-visible] .specimen-glyph { animation: specimen-guides 360ms var(--motion-out) both; }
  .landing-specimen[data-visible] .specimen-letter { animation: specimen-letter-in 350ms var(--motion-out) both; }
  .landing-specimen[data-visible] .specimen-letter i { animation: specimen-accent-in 300ms var(--motion-out) 80ms both; }

  #view-session button, #view-result button {
    transition: background-color 155ms ease, border-color 155ms ease, box-shadow 190ms ease, scale 150ms ease;
  }
  #view-session button:active:not(:disabled), #view-result button:active:not(:disabled),
  #settings-panel button:active:not(:disabled), .studio-feature .btn-primary:active {
    scale: .975;
  }
  .studio-feature .btn-primary, #settings-panel button { transition: background-color 150ms ease, scale 150ms ease; }
  #view-session .session-toolbar { animation: route-layer 520ms var(--motion-out); }
  #view-session .session-meter .progress-fill {
    position: relative;
    overflow: hidden;
    transition: width 560ms var(--motion-out);
  }
  #view-session:has(#btn-next:not(.hidden)) .progress-fill::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent 22%, #fff6e5b8 50%, transparent 78%);
    animation: progress-glint 760ms var(--motion-out) both;
  }
  #view-session #sess-count { transition: color 200ms; }
  #view-session:has(#btn-next:not(.hidden)) #sess-count { animation: count-nudge 420ms var(--motion-out); }

  #exercise-zone > .prompt { animation: exercise-in 490ms var(--motion-out); }
  #exercise-zone > .prompt::after { animation: prompt-underline 610ms var(--motion-out) 45ms both; }
  #exercise-zone > :is(.word-big, .context-sentence, .practice-writing, .exercise-audio-slot),
  #view-session .audio-ask.show, #view-session #audio-error {
    animation: exercise-in 500ms var(--motion-out) 60ms both;
  }
  #exercise-zone :is(.choice, .syl) {
    animation: exercise-in 510ms var(--motion-out) 75ms both;
  }
  #exercise-zone :is(.choice, .syl):nth-child(2) { animation-delay: 125ms; }
  #exercise-zone :is(.choice, .syl):nth-child(3) { animation-delay: 185ms; }
  #exercise-zone :is(.choice, .syl):nth-child(n+4) { animation-delay: 235ms; }
  #view-session :is(.choice,.syl).is-selected { animation: answer-mark 510ms var(--motion-out); }
  #view-session :is(.choice,.syl).is-selected::before {
    content: '';
    position: absolute;
    inset: 0;
    border: 2px solid currentColor;
    border-radius: inherit;
    pointer-events: none;
    animation: selection-echo 540ms ease-out both;
  }
  #view-session :is(.choice,.syl).is-selected::after { animation: answer-caption 370ms var(--motion-out) both; }
  #view-session .feedback.show { animation: route-layer 520ms var(--motion-out); }
  #view-session .feedback.ok .fb-icon { animation: correction-check 580ms var(--motion-out) 70ms both; }
  #view-session .feedback.bad .fb-icon { animation: answer-caption 425ms var(--motion-out) both; }
  #view-session .fb-word { animation: exercise-in 500ms var(--motion-out) 65ms both; }
  #view-session .fb-word mark { animation: letter-reveal 630ms var(--motion-out) 80ms both; }
  #view-session #btn-next:not(.hidden), #view-session .self-correction-controls {
    animation: exercise-in 510ms var(--motion-out) 100ms both;
  }

  :is(.exercise-audio, .audio-settings)[data-audio-state="preparing"] .audio-symbol > .ui-icon {
    animation: speech-ready 820ms ease-in-out infinite alternate;
  }
  :is(.exercise-audio, .audio-settings)[data-audio-state="speaking"] .audio-wave i {
    animation: speech-level 580ms ease-in-out var(--wave-phase, -70ms) infinite alternate;
  }

  #view-result:not(.hidden) .result-overview { animation: surface-in 480ms var(--motion-out); }
  #view-result:not(.hidden) .result-outcome { animation: result-in 570ms var(--motion-out) both; }
  #view-result:not(.hidden) #result-ring-value { animation: score-trace 920ms var(--motion-out) 150ms both; }
  #view-result:not(.hidden) #result-score { animation: result-score-in 585ms var(--motion-out) 95ms both; }
  #view-result:not(.hidden) :is(#result-sub, #result-insight, .result-actions, .result-words) {
    animation: surface-in 345ms var(--motion-out) 75ms both;
  }
  #view-result:not(.hidden) :is(.result-actions, .result-words) { animation-delay: 145ms; }
  #view-result .streak-result[data-celebrate="true"]:not([hidden]) { animation: streak-banner-in 430ms var(--motion-out) 80ms both; }

  details:is(.settings-card, .practice-focus, .result-words)[open] > :not(summary) {
    animation: surface-in 435ms var(--motion-out);
  }
  .result-words[open] li:nth-child(-n+5) { animation: exercise-in 290ms var(--motion-out) both; }
  .result-words[open] li:nth-child(2) { animation-delay: 28ms; }
  .result-words[open] li:nth-child(3) { animation-delay: 56ms; }
  .result-words[open] li:nth-child(4) { animation-delay: 84ms; }
  .result-words[open] li:nth-child(5) { animation-delay: 112ms; }
  .section-dialog[open] .auth-context-action:not([hidden]),
  .section-dialog[open] .auth-resend-note:not([hidden]) {
    animation: surface-in 260ms var(--motion-out);
  }

  @keyframes route-arrive {
    from { opacity: .08; transform: translate(var(--route-enter-x), var(--route-enter-y)); }
    to { opacity: 1; transform: none; }
  }
  @keyframes route-depart {
    from { opacity: var(--route-exit-opacity, 1); transform: var(--route-exit-transform, none); }
    to { opacity: 0; transform: translate(var(--route-exit-x), var(--route-exit-y)); }
  }
  @keyframes route-resize {
    from { block-size: var(--route-start-size); }
    to { block-size: var(--route-end-size); }
  }
  @keyframes route-layer { from { opacity: .48; transform: translateY(20px) scale(.985); } }
  @keyframes surface-in { from { opacity: .61; transform: translateY(12px); } }
  @keyframes specimen-guides { from { opacity: .35; background-position: -65px 22%, -45px 49%, -72px 78%; } }
  @keyframes specimen-letter-in {
    from { opacity: .68; transform: translateY(8px) scale(.96); }
    to { opacity: 1; transform: none; }
  }
  @keyframes specimen-accent-in {
    from { opacity: .45; transform: translate(5px,-7px) rotate(-25deg) scaleX(.75); }
    to { opacity: 1; transform: rotate(-39deg); }
  }
  @keyframes exercise-in { from { opacity: .64; transform: translateY(14px); } }
  @keyframes prompt-underline { from { opacity: .2; transform: scaleX(.12); } }
  @keyframes count-nudge { 0% { transform: translateX(-3px); } 60% { transform: translateX(2px); } }
  @keyframes answer-mark { 0% { transform: scale(.958); } 52% { transform: scale(1.025); } 100% { transform: none; } }
  @keyframes selection-echo { from { opacity: .42; transform: scale(.98); } to { opacity: 0; transform: scale(1.045); } }
  @keyframes answer-caption { from { opacity: .38; transform: translateY(5px); } }
  @keyframes correction-check { 0% { opacity: .65; transform: scale(.67) rotate(-18deg); } 58% { transform: scale(1.24) rotate(5deg); } }
  @keyframes letter-reveal { from { background-color: transparent; } to { background-color: var(--amber-mark); } }
  @keyframes progress-glint { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
  @keyframes speech-ready { from { opacity: .55; } to { opacity: 1; } }
  @keyframes speech-level { from { transform: scaleY(.42); } to { transform: scaleY(1.16); } }
  @keyframes result-in { from { opacity: .58; transform: scale(.946); } }
  @keyframes score-trace { from { stroke-dashoffset: 100; } }
  @keyframes result-score-in { from { opacity: .47; transform: translateY(16px); } }
  @keyframes streak-banner-in {
    0% { opacity: .65; transform: translateY(6px) scale(.98); }
    60% { transform: translateY(0) scale(1.012); }
  }
}
