/* ══════════════════════════════════════════════════════════════
   Explained Answers V3 — Skora Design System
   Desktop review workspace · Unified with variables.css tokens
   ══════════════════════════════════════════════════════════════ */

.ans-page {
  min-height: 100dvh;
  padding: var(--sp-lg) var(--sp-xl) var(--sp-2xl);
  background:
    radial-gradient(ellipse at 20% 0%, color-mix(in srgb, var(--hub-color, var(--violet)) 6%, transparent), transparent 50%),
    var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-family);
}

/* ── Topbar ──────────────────────────────────────────────── */
.ans-topbar {
  max-width: 1280px;
  margin: 0 auto var(--sp-lg);
  display: flex;
  align-items: center;
  gap: var(--sp-md);
}

.ans-back {
  width: 48px;
  height: 48px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--bg-white);
  color: var(--text-secondary);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  flex-shrink: 0;
}
.ans-back:hover {
  color: var(--text-primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
  background: var(--bg-hover);
}
.ans-back:active {
  transform: translateY(0);
}
.ans-back .material-symbols-outlined {
  font-size: 24px;
}

.ans-title-block {
  min-width: 0;
}

.ans-title {
  margin: 0;
  max-width: 800px;
  color: var(--text-primary);
  font-size: 1.25rem;
  line-height: 1.2;
  font-weight: var(--fw-bold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ans-subtitle {
  margin: 4px 0 0;
  color: var(--text-secondary);
  font-size: 0.88rem;
  line-height: 1.4;
}

/* ── Workspace Layout ────────────────────────────────────── */
.ans-workspace {
  width: min(1280px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: var(--sp-lg);
  align-items: start;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.ans-summary {
  position: sticky;
  top: var(--sp-lg);
  display: grid;
  gap: var(--sp-md);
}

/* ── Shared Panel Chrome ─────────────────────────────────── */
.ans-panel,
.ans-question-card,
.ans-review-toolbar,
.ans-empty {
  background: var(--bg-white);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}

.ans-panel {
  border-radius: var(--r-2xl);
  padding: var(--sp-lg);
}

/* ── Score Panel ─────────────────────────────────────────── */
.ans-score-panel {
  text-align: center;
}

.ans-score-ring {
  width: 160px;
  height: 160px;
  margin: 0 auto var(--sp-md);
  position: relative;
}

.ans-score-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
  filter: drop-shadow(0 8px 16px color-mix(in srgb, var(--hub-color, var(--violet)) 14%, transparent));
}

.ans-score-track,
.ans-score-fill {
  fill: none;
  stroke-width: 10;
}

.ans-score-track {
  stroke: var(--border);
}

.ans-score-fill {
  stroke: var(--hub-color, var(--violet));
  stroke-linecap: round;
  stroke-dasharray: 301.59;
  stroke-dashoffset: 301.59;
  transition: stroke-dashoffset 760ms cubic-bezier(0.22, 1, 0.36, 1);
}

.ans-score-center {
  position: absolute;
  inset: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--bg-white);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.04);
}

.ans-score-num {
  font-size: 2.2rem;
  line-height: 1;
  font-weight: var(--fw-extra);
  color: var(--text-primary);
}

.ans-score-label {
  margin-top: 6px;
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: var(--fw-bold);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.ans-score-detail {
  margin: 0;
  color: var(--text-primary);
  font-size: 1rem;
  font-weight: var(--fw-bold);
}

.ans-module-meta {
  margin: var(--sp-sm) auto var(--sp-md);
  max-width: 250px;
  color: var(--text-secondary);
  font-size: 0.84rem;
  line-height: 1.45;
}

/* ── Stats Grid ──────────────────────────────────────────── */
.ans-stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-sm);
}

.ans-stat {
  min-height: 88px;
  padding: var(--sp-sm);
  border-radius: var(--r-xl);
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 3px;
}

.ans-stat .material-symbols-outlined {
  font-size: 20px;
  color: var(--hub-color, var(--violet));
}

.ans-stat strong {
  color: var(--text-primary);
  font-size: 1.05rem;
  line-height: 1;
  font-weight: var(--fw-extra);
}

.ans-stat small {
  color: var(--text-secondary);
  font-size: 0.66rem;
  line-height: 1.2;
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* ── Panel Heading ───────────────────────────────────────── */
.ans-panel-heading {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  color: var(--text-primary);
  font-size: 0.86rem;
  font-weight: var(--fw-bold);
  margin-bottom: var(--sp-md);
}

.ans-panel-heading .material-symbols-outlined {
  color: var(--hub-color, var(--violet));
  font-size: 20px;
}

/* ── Filter Panel ────────────────────────────────────────── */
.ans-filters {
  display: grid;
  gap: var(--sp-sm);
}

.ans-filter {
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--bg-white);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--sp-sm);
  padding: 0 var(--sp-md);
  font-size: 0.88rem;
  font-weight: var(--fw-semi);
  cursor: pointer;
  transition: all 150ms var(--ease);
}

.ans-filter .material-symbols-outlined {
  font-size: 20px;
}

.ans-filter:hover {
  transform: translateY(-1px);
  color: var(--text-primary);
  border-color: color-mix(in srgb, var(--hub-color, var(--violet)) 30%, var(--border));
  box-shadow: var(--shadow-sm);
}

.ans-filter--active {
  color: #ffffff;
  border-color: var(--hub-color, var(--violet));
  background: var(--hub-color, var(--violet));
  box-shadow: 0 4px 12px color-mix(in srgb, var(--hub-color, var(--violet)) 24%, transparent);
}

/* ── Legend Panel ────────────────────────────────────────── */
.ans-legend p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.84rem;
  line-height: 1.6;
}

/* ── Review Area ─────────────────────────────────────────── */
.ans-review {
  min-width: 0;
}

.ans-review-toolbar {
  position: sticky;
  top: var(--sp-lg);
  z-index: 6;
  margin-bottom: var(--sp-md);
  padding: var(--sp-md) var(--sp-lg);
  border-radius: var(--r-2xl);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-md);
  background: color-mix(in srgb, var(--bg-white) 88%, transparent);
  backdrop-filter: blur(12px);
}

.ans-review-eyebrow {
  margin: 0 0 3px;
  color: var(--hub-color, var(--violet));
  font-size: 0.72rem;
  font-weight: var(--fw-bold);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.ans-review-toolbar h2 {
  margin: 0;
  color: var(--text-primary);
  font-size: 1.05rem;
  line-height: 1.2;
  font-weight: var(--fw-bold);
}

.ans-review-count {
  flex: 0 0 auto;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 var(--sp-md);
  border-radius: var(--r-full);
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: var(--fw-semi);
}

/* ── Question List ───────────────────────────────────────── */
.ans-list {
  display: grid;
  gap: var(--sp-md);
}

/* ── Question Card ───────────────────────────────────────── */
.ans-question-card {
  position: relative;
  overflow: hidden;
  border-radius: var(--r-2xl);
  padding: 0;
  transition: box-shadow var(--duration) var(--ease);
}
.ans-question-card:hover {
  box-shadow: var(--shadow-lg);
}

/* Left accent strip */
.ans-question-card::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--hub-color, var(--violet));
  opacity: 0.6;
}
.ans-question-card--incorrect::before,
.ans-question-card--skipped::before {
  background: var(--red);
}
.ans-question-card--correct::before {
  background: var(--green);
}

/* ── Card Head ───────────────────────────────────────────── */
.ans-card-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--sp-md);
  padding: var(--sp-lg) var(--sp-lg) var(--sp-sm) var(--sp-xl);
}

.ans-card-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

/* ── Pills ───────────────────────────────────────────────── */
.ans-index-pill,
.ans-status-pill,
.ans-meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 28px;
  border-radius: var(--r-full);
  padding: 0 10px;
  font-size: 0.72rem;
  line-height: 1;
  font-weight: var(--fw-bold);
}

.ans-index-pill {
  color: var(--text-primary);
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
}

.ans-status-pill {
  color: #ffffff;
}

.ans-status-pill .material-symbols-outlined,
.ans-meta-pill .material-symbols-outlined {
  font-size: 15px;
}

.ans-question-card--correct .ans-status-pill {
  background: var(--green);
}
.ans-question-card--incorrect .ans-status-pill {
  background: var(--red);
}
.ans-question-card--skipped .ans-status-pill {
  background: #F59E0B;
}

.ans-meta-pill {
  color: var(--text-secondary);
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
}

.ans-icfes {
  margin: 8px 0 0;
  color: var(--text-secondary);
  font-size: 0.82rem;
  line-height: 1.5;
}

/* ── Card Actions ────────────────────────────────────────── */
.ans-card-actions {
  align-self: start;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ans-answer-mini {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: var(--r-full);
  padding: 0 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.76rem;
  font-weight: var(--fw-semi);
}
.ans-answer-mini strong {
  color: var(--text-primary);
}

/* ── Stem ────────────────────────────────────────────────── */
.ans-stem {
  padding: var(--sp-sm) var(--sp-xl) var(--sp-lg);
  color: var(--text-primary);
  font-size: 1rem;
  line-height: 1.72;
}

.ans-stem p,
.ans-rich p {
  margin: 0 0 12px;
}
.ans-stem p:last-child,
.ans-rich p:last-child {
  margin-bottom: 0;
}

/* ── Question & Option Images ────────────────────────────── */
.ans-question-image,
.ans-option-image {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: var(--r-xl);
  margin: var(--sp-md) 0 0;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

/* ── Options Grid ────────────────────────────────────────── */
.ans-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-sm);
  padding: 0 var(--sp-lg) var(--sp-lg) var(--sp-xl);
}

/* ── Option Card ─────────────────────────────────────────── */
.ans-option {
  min-height: 76px;
  position: relative;
  border-radius: var(--r-xl);
  border: 1px solid var(--border);
  background: var(--bg-white);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-md);
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: var(--sp-sm);
  align-items: start;
  transition: transform var(--duration) var(--ease),
              box-shadow var(--duration) var(--ease);
}

.ans-option-letter {
  width: 42px;
  height: 42px;
  border-radius: var(--r-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-size: 1rem;
  font-weight: var(--fw-bold);
}

.ans-option-body {
  min-width: 0;
}

.ans-option-text {
  color: var(--text-primary);
  font-size: 0.92rem;
  line-height: 1.55;
}
.ans-option-text p {
  margin: 0 0 8px;
}
.ans-option-text p:last-child {
  margin-bottom: 0;
}

.ans-option-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: var(--sp-sm);
}

.ans-option-tag {
  min-height: 22px;
  display: inline-flex;
  align-items: center;
  border-radius: var(--r-full);
  padding: 0 8px;
  font-size: 0.66rem;
  line-height: 1;
  font-weight: var(--fw-bold);
}

/* Option: student answered correctly */
.ans-option--student-correct {
  border-color: color-mix(in srgb, var(--green) 40%, transparent);
  background: var(--green-light);
  box-shadow: 0 4px 12px color-mix(in srgb, var(--green) 12%, transparent);
}
.ans-option--student-correct .ans-option-letter,
.ans-option--correct .ans-option-letter {
  color: #ffffff;
  background: var(--green);
}
.ans-option--student-correct .ans-option-tag,
.ans-option--correct .ans-option-tag {
  color: #166534;
  background: color-mix(in srgb, var(--green) 14%, transparent);
}

/* Option: student answered wrong */
.ans-option--student-wrong {
  border-color: color-mix(in srgb, var(--red) 40%, transparent);
  background: var(--red-light);
  box-shadow: 0 4px 12px color-mix(in srgb, var(--red) 10%, transparent);
}
.ans-option--student-wrong .ans-option-letter {
  color: #ffffff;
  background: var(--red);
}
.ans-option--student-wrong .ans-option-tag {
  color: #991b1b;
  background: color-mix(in srgb, var(--red) 14%, transparent);
}

/* Option: correct (but not selected by student) */
.ans-option--correct {
  border-color: color-mix(in srgb, var(--green) 30%, transparent);
  background: color-mix(in srgb, var(--green) 5%, var(--bg-white));
}

/* Option: irrelevant / muted */
.ans-option--muted {
  opacity: 0.65;
}

/* ── Rationale (Explanation) ─────────────────────────────── */
.ans-card-rationale {
  margin: 0 var(--sp-lg) var(--sp-lg) var(--sp-xl);
  border-radius: var(--r-xl);
  border: 1px solid color-mix(in srgb, var(--hub-color, var(--violet)) 15%, var(--border));
  background: color-mix(in srgb, var(--hub-color, var(--violet)) 3%, var(--bg-white));
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.ans-rationale-toggle {
  min-height: 52px;
  padding: 0 var(--sp-md);
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  list-style: none;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: var(--fw-bold);
  user-select: none;
  transition: background var(--duration) var(--ease);
}
.ans-rationale-toggle:hover {
  background: color-mix(in srgb, var(--hub-color, var(--violet)) 5%, transparent);
}

.ans-rationale-toggle::-webkit-details-marker {
  display: none;
}

.ans-rationale-toggle .material-symbols-outlined:first-child {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-md);
  background: var(--hub-color, var(--violet));
  color: #ffffff;
  font-size: 18px;
  box-shadow: 0 4px 10px color-mix(in srgb, var(--hub-color, var(--violet)) 20%, transparent);
}

.ans-chevron {
  margin-left: auto;
  color: var(--text-secondary);
  transition: transform 180ms var(--ease);
}
.ans-card-rationale[open] .ans-chevron {
  transform: rotate(180deg);
}

.ans-rationale-body {
  padding: 0 var(--sp-lg) var(--sp-lg) calc(32px + var(--sp-md) + var(--sp-sm));
  color: var(--text-secondary);
  font-size: 0.92rem;
  line-height: 1.72;
}
.ans-rationale-body strong {
  color: var(--text-primary);
}

/* ── Loading / Empty / Error States ──────────────────────── */
.ans-loading,
.ans-empty {
  min-height: 240px;
  border-radius: var(--r-2xl);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-sm);
  color: var(--text-secondary);
  font-size: 0.9rem;
  text-align: center;
}

.ans-spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--hub-color, var(--violet));
  animation: ans-spin 760ms linear infinite;
}

.ans-empty {
  margin-top: var(--sp-md);
  padding: var(--sp-xl);
}
.ans-empty .material-symbols-outlined {
  color: var(--hub-color, var(--violet));
  font-size: 32px;
}
.ans-empty strong {
  color: var(--text-primary);
  font-size: 1rem;
}
.ans-empty p {
  margin: 0;
}

.ans-error {
  min-height: 260px;
  padding: var(--sp-xl);
  border-radius: var(--r-2xl);
  border: 1px solid color-mix(in srgb, var(--red) 20%, transparent);
  background: var(--red-light);
  color: var(--red);
  display: grid;
  place-items: center;
  text-align: center;
  line-height: 1.55;
}

/* ── Rich Content / KaTeX ────────────────────────────────── */
.ans-rich,
.ans-option-text {
  overflow-wrap: anywhere;
}

.ans-rich ul,
.ans-rich ol {
  margin: 10px 0 10px 22px;
  padding: 0;
}
.ans-rich li {
  margin: 6px 0;
}

.ans-card .katex,
.ans-question-card .katex {
  font-size: 1em;
}

.ans-card .katex-display,
.ans-question-card .katex-display {
  margin: 10px 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
}

@keyframes ans-spin {
  to { transform: rotate(360deg); }
}


/* ══════════════════════════════════════════════════════════════
   Entrance Animations
   ══════════════════════════════════════════════════════════════ */

@keyframes ans-fade-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.ans-panel {
  opacity: 0;
  animation: ans-fade-up 400ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
  animation-delay: calc(var(--panel-i, 0) * 80ms);
}

.ans-score-panel  { --panel-i: 0; }
.ans-filter-panel { --panel-i: 1; }
.ans-legend       { --panel-i: 2; }

.ans-review-toolbar {
  opacity: 0;
  animation: ans-fade-up 400ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
  animation-delay: 160ms;
}

.ans-question-card {
  opacity: 0;
  animation: ans-fade-up 400ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
  animation-delay: calc(var(--card-i, 0) * 60ms + 250ms);
}

.ans-question-card:nth-child(1)  { --card-i: 0; }
.ans-question-card:nth-child(2)  { --card-i: 1; }
.ans-question-card:nth-child(3)  { --card-i: 2; }
.ans-question-card:nth-child(4)  { --card-i: 3; }
.ans-question-card:nth-child(5)  { --card-i: 4; }
.ans-question-card:nth-child(6)  { --card-i: 5; }
.ans-question-card:nth-child(7)  { --card-i: 6; }
.ans-question-card:nth-child(8)  { --card-i: 7; }
.ans-question-card:nth-child(9)  { --card-i: 8; }
.ans-question-card:nth-child(10) { --card-i: 9; }
.ans-question-card:nth-child(n+11) { --card-i: 10; }


/* ══════════════════════════════════════════════════════════════
   Responsive
   ══════════════════════════════════════════════════════════════ */

@media (max-width: 1120px) {
  .ans-page {
    padding-inline: var(--sp-lg);
  }

  .ans-workspace {
    grid-template-columns: 280px minmax(0, 1fr);
    gap: var(--sp-md);
  }

  .ans-options {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .ans-page {
    padding: var(--sp-md) var(--sp-md) var(--sp-2xl);
  }

  .ans-workspace {
    grid-template-columns: 1fr;
  }

  .ans-summary,
  .ans-review-toolbar {
    position: static;
  }

  .ans-summary {
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-sm);
  }

  .ans-score-panel {
    grid-row: span 2;
  }

  .ans-card-head {
    grid-template-columns: 1fr;
    padding: var(--sp-md) var(--sp-md) var(--sp-sm) var(--sp-lg);
  }

  .ans-card-actions {
    flex-wrap: wrap;
  }

  .ans-stem {
    padding: var(--sp-sm) var(--sp-lg);
  }

  .ans-options {
    padding: 0 var(--sp-md) var(--sp-md) var(--sp-lg);
    grid-template-columns: 1fr;
  }

  .ans-card-rationale {
    margin: 0 var(--sp-md) var(--sp-md) var(--sp-lg);
  }
}

@media (max-width: 600px) {
  .ans-summary {
    grid-template-columns: 1fr;
  }

  .ans-score-panel {
    grid-row: auto;
  }

  .ans-score-ring {
    width: 130px;
    height: 130px;
  }
}


/* ══════════════════════════════════════════════════════════════
   Reduced Motion
   ══════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  .ans-score-fill,
  .ans-filter,
  .ans-back,
  .ans-chevron {
    transition-duration: 0.01ms;
  }

  .ans-spinner {
    animation-duration: 0.01ms;
  }

  .ans-panel,
  .ans-review-toolbar,
  .ans-question-card {
    animation-duration: 150ms;
    animation-delay: 0ms;
  }
}
