/* QPal Ask Qbao — controlled AI-generated rationale interface. */
.qbao-inline-host {
  display: flex;
  justify-content: center;
  margin: 14px 0 2px;
}

.qbao-inline-host[hidden] {
  display: none !important;
}

.qbao-trigger {
  min-height: 44px;
  width: min(100%, 360px);
  padding: 11px 18px;
  border: 1px solid var(--bg-white);
  border-radius: 12px;
  background: var(--bg-black);
  color: var(--bg-white);
  font: inherit;
  font-size: max(13px, calc(13px * var(--quiz-font-scale, 1)));
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  transition: transform 160ms ease, background-color 160ms ease,
    color 160ms ease, border-color 160ms ease;
}

.qbao-trigger:hover {
  background: var(--bg-white);
  color: var(--bg-black);
}

.qbao-trigger:active {
  transform: translateY(1px);
}

.qbao-trigger:focus-visible,
.qbao-close:focus-visible,
.qbao-action:focus-visible {
  outline: 2px solid var(--bg-white);
  outline-offset: 3px;
}

.qbao-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483300;
  display: grid;
  place-items: center;
  padding: max(14px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
  background: rgba(0, 0, 0, 0.72);
  overflow: auto;
  overscroll-behavior: contain;
  animation: qbao-fade-in 150ms ease both;
}

.qbao-dialog {
  width: min(620px, 100%);
  max-height: min(86vh, 780px);
  max-height: min(86dvh, 780px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--bg-white);
  border-radius: 18px;
  background: var(--bg-black);
  color: var(--bg-white);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
  animation: qbao-dialog-in 180ms ease both;
}

.qbao-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid color-mix(in srgb, var(--bg-white) 22%, transparent);
}

.qbao-identity {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.qbao-monogram {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--bg-white);
  border-radius: 50%;
  background: var(--bg-white);
  color: var(--bg-black);
  font-size: 22px;
  font-weight: 800;
}

.qbao-heading-copy {
  min-width: 0;
}

.qbao-eyebrow {
  display: block;
  margin-bottom: 3px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  opacity: 0.72;
}

.qbao-title {
  margin: 0;
  font-size: 24px;
  line-height: 1.05;
}

.qbao-close {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--bg-white) 35%, transparent);
  border-radius: 50%;
  background: var(--bg-black);
  color: var(--bg-white);
  font: inherit;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.qbao-body {
  overflow: auto;
  padding: 18px 20px 20px;
  overscroll-behavior: contain;
}

.qbao-description,
.qbao-remaining,
.qbao-status,
.qbao-disclaimer,
.qbao-result-meta {
  margin: 0;
}

.qbao-description {
  font-size: 15px;
  line-height: 1.5;
}

.qbao-remaining {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.45;
  opacity: 0.72;
}

.qbao-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.qbao-action {
  min-height: 78px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 5px;
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--bg-white) 35%, transparent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--bg-black) 96%, var(--bg-white));
  color: var(--bg-white);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 150ms ease, background-color 150ms ease,
    transform 150ms ease;
}

.qbao-action:hover:not(:disabled) {
  border-color: var(--bg-white);
  background: color-mix(in srgb, var(--bg-black) 88%, var(--bg-white));
}

.qbao-action:active:not(:disabled) {
  transform: translateY(1px);
}

.qbao-action:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.qbao-action-label {
  font-size: 13px;
  line-height: 1.3;
}

.qbao-action-description {
  font-size: 11px;
  line-height: 1.35;
  opacity: 0.7;
}

.qbao-loading {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 16px 0 4px;
}

.qbao-loading[hidden] {
  display: none !important;
}

.qbao-loading-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--bg-white);
  animation: qbao-pulse 900ms ease-in-out infinite;
}

.qbao-loading-dot:nth-child(2) {
  animation-delay: 120ms;
}

.qbao-loading-dot:nth-child(3) {
  animation-delay: 240ms;
}

.qbao-status {
  min-height: 18px;
  margin-top: 10px;
  font-size: 12px;
  line-height: 1.45;
  text-align: center;
}

.qbao-status[data-type="error"] {
  font-weight: 700;
}

.qbao-result {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid color-mix(in srgb, var(--bg-white) 38%, transparent);
  border-radius: 14px;
  background: color-mix(in srgb, var(--bg-black) 94%, var(--bg-white));
}

.qbao-result[hidden] {
  display: none !important;
}

.qbao-result-title {
  margin: 0;
  font-size: 17px;
  line-height: 1.3;
}

.qbao-result-meta {
  margin-top: 4px;
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.65;
}

.qbao-result-text {
  margin-top: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.65;
  text-align: left;
}

.qbao-disclaimer {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid color-mix(in srgb, var(--bg-white) 24%, transparent);
  font-size: 11px;
  line-height: 1.5;
  opacity: 0.72;
}

.qbao-exam-review-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483200;
  display: grid;
  place-items: center;
  padding: max(14px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
  background: rgba(0, 0, 0, 0.72);
  overflow: auto;
}

.qbao-exam-review-dialog {
  box-sizing: border-box;
  width: min(640px, 100%);
  max-height: min(88vh, 760px);
  max-height: min(88dvh, 760px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 18px;
  border: 1px solid var(--bg-white);
  border-radius: 16px;
  background: var(--bg-black);
  color: var(--bg-white);
  box-shadow: var(--shadow-dialog, 0 24px 64px rgba(0, 0, 0, 0.42));
}

.qbao-exam-review-header,
.qbao-exam-review-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.qbao-exam-review-header {
  margin-bottom: 16px;
}

.qbao-exam-review-heading {
  margin: 0;
  font-size: 20px;
}

.qbao-exam-review-close {
  width: 40px;
  height: 40px;
  border: 1px solid var(--bg-white);
  border-radius: 50%;
  background: var(--bg-black);
  color: var(--bg-white);
  font: inherit;
  font-size: 22px;
  cursor: pointer;
}

.qbao-exam-review-question {
  margin: 0 0 14px;
  font-size: 17px;
  line-height: 1.55;
}

.qbao-exam-review-choice {
  display: flex;
  gap: 10px;
  margin-top: 8px;
  padding: 11px 13px;
  border: 1px solid color-mix(in srgb, var(--bg-white) 28%, transparent);
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.45;
}

.qbao-exam-review-choice.is-correct {
  border-width: 2px;
}

.qbao-exam-review-choice.is-selected-wrong {
  border-style: dashed;
  border-width: 2px;
}

.qbao-exam-review-status {
  margin: 12px 0 0;
  font-size: 12px;
  opacity: 0.76;
}

.qbao-exam-review-footer {
  margin-top: 16px;
}

.qbao-exam-review-nav {
  min-height: 42px;
  padding: 9px 14px;
  border: 1px solid var(--bg-white);
  border-radius: 10px;
  background: var(--bg-black);
  color: var(--bg-white);
  font: inherit;
  cursor: pointer;
}

.qbao-exam-review-nav:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

@keyframes qbao-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes qbao-dialog-in {
  from { opacity: 0; transform: translateY(8px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes qbao-pulse {
  0%, 100% { opacity: 0.35; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-2px); }
}

@media (max-width: 560px) {
  .qbao-dialog {
    max-height: calc(100dvh - 24px);
    border-radius: 16px;
  }

  .qbao-header,
  .qbao-body {
    padding-left: 15px;
    padding-right: 15px;
  }

  .qbao-actions {
    grid-template-columns: 1fr;
  }

  .qbao-action {
    min-height: 68px;
  }

  .qbao-exam-review-overlay {
    padding: max(10px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
  }

  .qbao-exam-review-dialog {
    width: 100%;
    max-height: calc(100vh - 20px);
    max-height: calc(100dvh - 20px);
    padding: 14px;
    border-radius: 14px;
  }

  .qbao-exam-review-header {
    margin-bottom: 12px;
  }

  .qbao-exam-review-heading {
    font-size: 17px;
    line-height: 1.25;
  }

  .qbao-exam-review-close {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    font-size: 20px;
  }

  .qbao-exam-review-question {
    margin-bottom: 10px;
    font-size: 15px;
    line-height: 1.45;
  }

  .qbao-exam-review-choice {
    gap: 8px;
    margin-top: 7px;
    padding: 9px 10px;
    border-radius: 9px;
  }

  .qbao-exam-review-footer {
    margin-top: 13px;
  }

  .qbao-exam-review-nav {
    min-height: 40px;
    padding: 8px 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .qbao-overlay,
  .qbao-dialog,
  .qbao-loading-dot,
  .qbao-trigger,
  .qbao-action {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

.qbao-exam-review-choice.correct {
  border-color: #34d399;
  color: #34d399;
}

.qbao-exam-review-choice.wrong {
  border-color: #f87171;
  color: #f87171;
}

html:not(.dark-mode) .qbao-exam-review-choice.correct {
  border-color: #0f7a4b;
  color: #0f7a4b;
}

html:not(.dark-mode) .qbao-exam-review-choice.wrong {
  border-color: #b3263a;
  color: #b3263a;
}
