/* Shared by the short feed and standalone short-video page. */
:is(#cartoons-explode-root, .ce-quiz-history, .watch-detail-page[data-short-quiz]) [data-result="correct"],
.watch-detail-page[data-short-quiz] :is(button.correct, .quiz-feedback--ok) {
  --result-surface: #ddf7e9;
  --result-ink: #104c35;
  --result-accent: #22764e;
  --result-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 12 4 4 10-10'/%3E%3C/svg%3E");
}

:is(#cartoons-explode-root, .ce-quiz-history, .watch-detail-page[data-short-quiz]) [data-result="wrong"],
.watch-detail-page[data-short-quiz] :is(button.wrong, .quiz-feedback--err) {
  --result-surface: #ffe8e7;
  --result-ink: #7e2132;
  --result-accent: #b03344;
  --result-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round'%3E%3Cpath d='m6 6 12 12M18 6 6 18'/%3E%3C/svg%3E");
}

.ce-quiz-history {
  box-sizing: border-box;
  inset: auto 0 0;
  margin: 0 auto;
  width: min(100%, 29rem);
  max-width: 100%;
  max-height: 85vh;
  max-height: 85dvh;
  border: 1px solid #e4d8cc;
  border-radius: 1.4rem 1.4rem 0 0;
  padding: 1rem 1rem max(1rem, env(safe-area-inset-bottom));
  background: #fffaf3;
  color: #271d36;
  box-shadow: 0 -.4rem 2.3rem #1c112e33;
  overflow: auto;
  overscroll-behavior: contain;
  text-align: start;
  font: inherit;
}

.ce-quiz-history:not([open]),
.ce-quiz-history [hidden] {
  display: none;
}

.ce-quiz-history::backdrop {
  background: rgb(18 12 27 / 70%);
}

.ce-quiz-history__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .75rem;
}

.ce-quiz-history__heading {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 800;
  line-height: 1.65;
}

.ce-quiz-history__video,
.ce-quiz-history__status,
.ce-quiz-history__detail {
  margin: .2rem 0 0;
  color: #514859;
  line-height: 1.75;
  overflow-wrap: anywhere;
}

.ce-quiz-history__close,
.ce-quiz-history__retry,
#cartoons-explode-root .quiz-panel :is(.ce-quiz-retry, .ce-quiz-history-btn) {
  min-height: 44px;
  border: 1px solid #ddd1e6;
  border-radius: .8rem;
  padding: .4rem .85rem;
  background: #f5edf9;
  color: #49315d;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.ce-quiz-history__close {
  display: inline-grid;
  place-items: center;
  min-width: 44px;
  padding: .45rem;
  flex: none;
}

.ce-quiz-history__close svg {
  width: 1.25rem;
  height: 1.25rem;
}

.ce-quiz-history button:focus-visible {
  outline: 3px solid #7448aa;
  outline-offset: 2px;
}

.ce-quiz-history__list {
  display: grid;
  gap: .55rem;
  margin: .85rem 0 0;
  padding: 0;
  list-style: none;
}

.ce-quiz-history__list:empty { margin: 0; }

.ce-quiz-history__item {
  border: 1px solid #e8ded5;
  border-radius: .9rem;
  padding: .65rem .85rem;
  background: #fff;
}

.ce-quiz-history__badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .1rem .55rem;
  border-radius: 1rem;
  background: var(--result-surface, #f3edf9);
  color: var(--result-ink, #44345c);
  font-size: .8rem;
  font-weight: 750;
}

.ce-quiz-history__question {
  display: block;
  margin-top: .35rem;
  font-weight: 750;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

/* Keep the added history action reachable beside a video on short screens. */
@media (max-height: 680px) {
  body.page-cartoons-explode #cartoons-explode-root .reel-actions.action-sidebar {
    gap: .4rem;
    max-height: calc(100vh - 8.75rem);
    max-height: calc(100dvh - 8.75rem - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: .2rem;
  }

  body.page-cartoons-explode #cartoons-explode-root .reel-actions .action-avatar-wrap {
    display: none;
  }
}

@media (min-width: 600px) {
  .ce-quiz-history {
    inset: 0;
    margin: auto;
    border-radius: 1.35rem;
    box-shadow: 0 .65rem 3rem #1c112e55;
  }
}

/* The live reel renderer adds a result only after the server grades the answer. */
body.page-cartoons-explode #cartoons-explode-root .quiz-overlay .quiz-panel button[data-option-index][data-result],
.watch-detail-page[data-short-quiz] .quiz-shell button:is(.correct, .wrong) {
  position: relative;
  background: var(--result-surface);
  color: var(--result-ink);
  border: 2px solid var(--result-accent);
  box-shadow: none;
  opacity: 1;
  cursor: default;
}

body.page-cartoons-explode #cartoons-explode-root .quiz-panel button[data-option-index][data-result]:not(.quiz-image-card),
.watch-detail-page[data-short-quiz] .quiz-shell button:is(.correct, .wrong):not(.quiz-image-card) {
  padding-inline-end: 2.35rem;
  overflow-wrap: anywhere;
}

#cartoons-explode-root .quiz-panel button[data-option-index][data-result]::after,
.watch-detail-page[data-short-quiz] .quiz-shell button:is(.correct, .wrong)::after {
  content: "";
  position: absolute;
  inset-inline-end: .45rem;
  inset-block-start: 50%;
  transform: translateY(-50%);
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  background: var(--result-accent) var(--result-icon) center / 1.05rem no-repeat;
  pointer-events: none;
}

#cartoons-explode-root .quiz-panel .quiz-image-card[data-result]::after,
.watch-detail-page[data-short-quiz] .quiz-shell .quiz-image-card:is(.correct, .wrong)::after {
  inset-block-start: .35rem;
  transform: none;
  box-shadow: 0 0 0 2px #fff;
}

/* .quiz-feedback in the sample reel styles is hidden until .show. The live
   status remains mounted for screen readers and is visible on every result. */
#cartoons-explode-root .quiz-panel .ce-quiz-status[data-result]:not([hidden]),
.watch-detail-page[data-short-quiz] .quiz-shell .quiz-feedback:is(.quiz-feedback--ok, .quiz-feedback--err):not([hidden]) {
  display: block;
  margin: .75rem 0 0;
  padding: .65rem .85rem;
  border-radius: .8rem;
  border-inline-start: .25rem solid var(--result-accent, #7856a2);
  background: var(--result-surface, #f3edf9);
  color: var(--result-ink, #44345c);
  font-size: .95rem;
  font-weight: 750;
  line-height: 1.7;
  text-align: start;
  overflow-wrap: anywhere;
}

#cartoons-explode-root .quiz-panel .ce-quiz-status[data-result="error"] {
  --result-accent: #956216;
  --result-surface: #fff1d4;
  --result-ink: #65430b;
}

.ce-quiz-status .quiz-answer-explanation {
  margin: .25rem 0 0;
  font-size: .9rem;
  font-weight: 500;
  line-height: 1.65;
}

#cartoons-explode-root .quiz-panel [hidden] { display: none !important; }

#cartoons-explode-root .quiz-panel button:focus-visible {
  outline: 3px solid #7448aa;
  outline-offset: 2px;
}

#cartoons-explode-root .quiz-panel .quiz-head {
  flex-wrap: wrap;
  gap: .3rem;
}

#cartoons-explode-root .quiz-panel .quiz-head .ce-quiz-history-btn {
  margin-inline-start: auto;
  padding-inline: .55rem;
  font-size: .8rem;
}

@media (prefers-reduced-motion: no-preference) {
  #cartoons-explode-root .quiz-panel .selected[data-result="correct"],
  .watch-detail-page[data-short-quiz] button.correct.selected {
    animation: ce-answer-pop .38s ease-out;
  }

  #cartoons-explode-root .quiz-panel [data-option-index][data-result="wrong"],
  .watch-detail-page[data-short-quiz] button.wrong {
    animation: ce-answer-shake .32s ease-in-out;
  }

  .ce-quiz-history[open],
  #cartoons-explode-root .ce-quiz-status:is([data-result="correct"], [data-result="wrong"]),
  .watch-detail-page[data-short-quiz] .quiz-feedback:is(.quiz-feedback--ok, .quiz-feedback--err) {
    animation: ce-answer-arrive .18s ease-out;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.page-cartoons-explode #cartoons-explode-root .quiz-overlay,
  body.page-cartoons-explode #cartoons-explode-root .quiz-overlay .quiz-panel,
  body.page-cartoons-explode #cartoons-explode-root .quiz-overlay .ce-timed-quiz-panel,
  body.page-cartoons-explode #cartoons-explode-root .quiz-overlay button,
  .watch-detail-page[data-short-quiz] .quiz-shell button {
    transition: none;
  }
}

@keyframes ce-answer-pop {
  0%, 100% { transform: scale(1); }
  45% { transform: scale(1.035); box-shadow: 0 0 0 3px rgb(34 118 78 / 23%); }
}

@keyframes ce-answer-shake {
  0%, 100% { transform: translateX(0); }
  22% { transform: translateX(-4px); }
  48% { transform: translateX(4px); }
  73% { transform: translateX(-2px); }
}

@keyframes ce-answer-arrive {
  from { opacity: .6; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
