/* Pick-a-Pol Game UI — Flashcard animations, progress ring, badge unlocks.
   Uses the generated artwork from /artwork/output/ as thematic backgrounds.
   All animations respect prefers-reduced-motion. */

/* ============================================================================
   FLASHCARD QUESTION CONTAINER
   ============================================================================ */

.flashcard-container {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background-color: var(--bg);
  overflow: hidden;
}

.flashcard-container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  opacity: 0.15;
  z-index: 0;
  pointer-events: none;
}

.flashcard {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 600px;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(10, 49, 97, 0.2);
  padding: 40px 32px;
  animation: cardEnter 0.4s ease-out;
}

/* Topic-specific backgrounds (CSS variables set by JS based on question category). */
.flashcard-container.topic-economy::before {
  background-image: url('/artwork/bg-economy.png');
}
.flashcard-container.topic-healthcare::before {
  background-image: url('/artwork/bg-healthcare.png');
}
.flashcard-container.topic-education::before {
  background-image: url('/artwork/bg-education.png');
}
.flashcard-container.topic-environment::before {
  background-image: url('/artwork/bg-environment.png');
}
.flashcard-container.topic-social::before {
  background-image: url('/artwork/bg-social.png');
}
.flashcard-container.topic-housing::before {
  background-image: url('/artwork/bg-housing.png');
}
.flashcard-container.topic-justice::before {
  background-image: url('/artwork/bg-justice.png');
}
.flashcard-container.topic-government::before {
  background-image: url('/artwork/bg-government.png');
}

@media (prefers-reduced-motion: reduce) {
  .flashcard {
    animation: none;
  }
}

@keyframes cardEnter {
  from {
    opacity: 0;
    transform: translateY(40px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes cardExit {
  to {
    opacity: 0;
    transform: translateX(-60px);
  }
}

.flashcard.exiting {
  animation: cardExit 0.3s ease-in forwards;
}

/* ============================================================================
   QUESTION TEXT & PROGRESS DOTS
   ============================================================================ */

.flashcard-header {
  margin-bottom: 32px;
  text-align: center;
}

.progress-dots {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.progress-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
  color: transparent;
  flex-shrink: 0;
  padding: 0;
  background: none;
}

.progress-dot.answered {
  border-color: #16a34a;
  background: #16a34a;
  color: white;
}

.progress-dot.current {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

.progress-dot.jumpable {
  cursor: pointer;
}

.progress-dot.jumpable:hover {
  border-color: var(--ink);
}

.question-text {
  font-size: 24px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--ink);
  margin: 16px 0;
}

/* ============================================================================
   LIKERT SCALE BUTTONS (5-POINT)
   ============================================================================ */

.scale-buttons {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-top: 32px;
}

.scale-btn {
  padding: 12px 8px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 80px;
}

.scale-btn-icon {
  font-size: 24px;
  line-height: 1;
}

.scale-btn-label {
  font-size: 11px;
  display: block;
}

/* Hover state */
.scale-btn:hover:not(:disabled) {
  border-color: var(--brand);
  background: rgba(31, 95, 168, 0.05);
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(31, 95, 168, 0.15);
}

/* Active/pressed state */
.scale-btn:active:not(:disabled) {
  transform: scale(0.95);
}

/* Selected state */
.scale-btn.selected {
  border-color: var(--brand);
  background: var(--brand);
  color: white;
  box-shadow: 0 8px 24px rgba(31, 95, 168, 0.25);
}

.scale-btn.selected .scale-btn-icon {
  animation: scaleIconPulse 0.4s ease;
}

@keyframes scaleIconPulse {
  0% {
    transform: scale(0.8);
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
  }
}

.scale-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (max-width: 600px) {
  .scale-buttons {
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
  }
  .scale-btn {
    min-height: 72px;
    padding: 10px 6px;
    font-size: 11px;
  }
  .scale-btn-icon {
    font-size: 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .scale-btn {
    transition: none;
  }
  .scale-btn-icon {
    animation: none;
  }
}

/* ============================================================================
   RESULTS SCREEN — PODIUM & LEADERBOARD
   ============================================================================ */

.results-container {
  animation: resultsEnter 0.6s ease-out;
}

@keyframes resultsEnter {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.results-header {
  text-align: center;
  margin-bottom: 40px;
}

.results-header h2 {
  font-size: 28px;
  margin-bottom: 8px;
}

.results-header p {
  color: var(--muted);
  font-size: 16px;
}

/* Podium Layout */
.podium {
  display: grid;
  grid-template-columns: 1fr 1.2fr 0.9fr;
  gap: 16px;
  margin-bottom: 48px;
  align-items: flex-end;
  perspective: 1200px;
}

.podium-rank {
  text-align: center;
  animation: podiumSlideIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.podium-rank:nth-child(1) {
  animation-delay: 0.2s;
}
.podium-rank:nth-child(2) {
  animation-delay: 0s;
}
.podium-rank:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes podiumSlideIn {
  from {
    opacity: 0;
    transform: translateY(60px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.podium-medal {
  font-size: 32px;
  margin-bottom: 12px;
}

.podium-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 8px 24px rgba(10, 49, 97, 0.12);
}

.podium-rank.second .podium-card {
  border-top: 4px solid var(--brand);
  padding-top: 24px;
}

.podium-identity {
  display: block;
  color: inherit;
  text-decoration: none;
  border-radius: 8px;
}

a.podium-link:hover .podium-name,
a.podium-link:focus-visible .podium-name {
  text-decoration: underline;
}
a.podium-link:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.podium-photo {
  width: 100%;
  aspect-ratio: 2 / 3;
  height: auto;
  border-radius: 8px;
  margin-bottom: 12px;
  object-fit: cover;
  object-position: center top;
  background: var(--line);
}

.podium-name {
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 4px;
}

.podium-match {
  font-size: 28px;
  font-weight: 700;
  color: var(--brand);
  margin-bottom: 8px;
  animation: counterUp 1s ease-out;
}

@keyframes counterUp {
  from {
    opacity: 0;
    content: '0%';
  }
  to {
    opacity: 1;
  }
}

.podium-office {
  font-size: 13px;
  color: var(--muted);
}

.podium-compare {
  margin-top: 12px;
  padding: 8px 14px;
  font-size: 13px;
}

/* Shared expansion slot under the podium: the podium cells are too narrow for
   the agreement scales, so a top-3 comparison opens full width below them. */
.podium-detail:not(:empty) {
  margin-top: 24px;
}

@media (max-width: 900px) {
  .podium {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
  .podium-rank.third {
    grid-column: 1 / -1;
    max-width: 50%;
    margin: 0 auto;
  }
}

@media (max-width: 600px) {
  .podium {
    grid-template-columns: 1fr;
  }
  .podium-rank.third {
    max-width: 100%;
  }
  .podium-name {
    font-size: 16px;
  }
  .podium-match {
    font-size: 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .podium-rank {
    animation: none;
  }
  .podium-match {
    animation: none;
  }
}

/* Leaderboard (all candidates) */
.leaderboard {
  margin-top: 48px;
}

.leaderboard-header {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}

.leaderboard-hint {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 16px;
}

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.leaderboard-item {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: 8px;
  border-left: 4px solid var(--line);
  transition: all 0.2s ease;
  animation: leaderboardSlide 0.4s ease-out;
}

.leaderboard-item:nth-child(1) {
  animation-delay: 0ms;
  border-left-color: #ffd700;
}
.leaderboard-item:nth-child(2) {
  animation-delay: 50ms;
  border-left-color: #c0c0c0;
}
.leaderboard-item:nth-child(3) {
  animation-delay: 100ms;
  border-left-color: #cd7f32;
}
.leaderboard-item:nth-child(n+4) {
  animation-delay: calc((var(--index, 4) - 3) * 50ms);
  border-left-color: var(--brand);
}

@keyframes leaderboardSlide {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.leaderboard-item:hover {
  background: rgba(31, 95, 168, 0.05);
  box-shadow: 0 4px 12px rgba(31, 95, 168, 0.1);
  transform: translateX(4px);
}

.leaderboard-rank {
  font-weight: 700;
  font-size: 16px;
  text-align: center;
}

.leaderboard-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.leaderboard-name {
  font-weight: 600;
  color: var(--ink);
}

a.leaderboard-name {
  text-decoration: none;
  width: fit-content;
}
a.leaderboard-name:hover,
a.leaderboard-name:focus-visible {
  text-decoration: underline;
}
a.leaderboard-name:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.leaderboard-office {
  font-size: 13px;
  color: var(--muted);
}

.leaderboard-match {
  font-weight: 700;
  color: var(--brand);
  text-align: right;
  min-width: 50px;
}

@media (prefers-reduced-motion: reduce) {
  .leaderboard-item {
    animation: none;
  }
  .leaderboard-item:hover {
    transform: none;
  }
}

/* ============================================================================
   RESULT DETAIL CARD (when clicking a candidate for reasoning)
   ============================================================================ */

.result-detail {
  background: var(--surface);
  border-radius: 12px;
  padding: 24px;
  margin-top: 16px;
  box-shadow: 0 4px 12px rgba(10, 49, 97, 0.1);
  animation: detailExpand 0.3s ease-out;
}

@keyframes detailExpand {
  from {
    opacity: 0;
    max-height: 0;
  }
  to {
    opacity: 1;
    max-height: 1000px;
  }
}

.detail-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}

.detail-summary {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 16px;
}

.agreement-item {
  padding: 14px 16px 10px;
  background: var(--bg);
  border-radius: 8px;
  border-left: 4px solid var(--line);
  margin-bottom: 12px;
}

.agreement-item.agree { border-left-color: var(--agree); }
.agreement-item.disagree { border-left-color: var(--disagree); }
.agreement-item.partial { border-left-color: var(--warn-ink); }

.agreement-head {
  display: flex;
  gap: 12px;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
}

.agreement-text {
  font-size: 14px;
  line-height: 1.4;
  color: var(--ink);
  flex: 1 1 240px;
}

.agreement-important {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.agreement-verdict {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.agreement-item.agree .agreement-verdict { color: var(--agree); }
.agreement-item.disagree .agreement-verdict { color: var(--disagree); }
.agreement-item.partial .agreement-verdict { color: var(--warn-ink); }
.agreement-item.unknown .agreement-verdict { color: var(--muted); }

.agreement-confidence {
  font-size: 12px;
  color: var(--muted);
  text-align: right;
}

/* Evidence for a position: the candidate's own verified words, or — clearly
   labelled as ours — our summary of the sources. */
.agreement-evidence {
  margin-top: 12px;
}

.evidence-quote {
  margin: 0;
  padding: 8px 0 8px 14px;
  border-left: 3px solid var(--brand);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  font-style: italic;
}

.evidence-quote::before { content: '“'; }
.evidence-quote::after { content: '”'; }

.evidence-summary {
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
  padding-left: 14px;
  border-left: 3px dotted var(--line);
}

.evidence-attribution {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
  padding-left: 14px;
}

.evidence-verified {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--agree);
  white-space: nowrap;
}
.evidence-verified::before { content: '✓ '; }

.evidence-sources {
  font-size: 12px;
  margin-top: 6px;
  padding-left: 14px;
}

.agreement-skipped {
  margin-top: 16px;
}
.agreement-skipped > summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 12px;
}

/* ----------------------------------------------------------------------------
   AGREEMENT SCALE — one strongly-disagree..strongly-agree track per question,
   with the user's answer above the line and the candidate's position below.
   ---------------------------------------------------------------------------- */

.stance-scale {
  --stance-tone: var(--muted);
  margin: 30px 8px 8px;
}

.stance-scale.agree { --stance-tone: var(--agree); }
.stance-scale.disagree { --stance-tone: var(--disagree); }
.stance-scale.partial { --stance-tone: var(--warn-ink); }

.stance-track {
  position: relative;
  height: 6px;
  border-radius: 999px;
  background: var(--line);
  margin-bottom: 26px;
}

.stance-tick {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 12px;
  border-radius: 1px;
  background: var(--line);
  transform: translateX(-50%);
}
/* Neutral (midpoint) is the reference line — draw it a little stronger. */
.stance-tick:nth-child(3) {
  background: var(--muted);
  opacity: 0.45;
}

/* Band spanning the distance between the two positions: the visual "gap". */
.stance-gap {
  position: absolute;
  top: 0;
  height: 6px;
  border-radius: 999px;
  background: var(--stance-tone);
  opacity: 0.35;
  min-width: 2px;
}

.stance-marker {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translateX(-50%);
}
.stance-marker.align-start { align-items: flex-start; transform: translateX(-8px); }
.stance-marker.align-end { align-items: flex-end; transform: translateX(calc(-100% + 8px)); }

.stance-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 3px solid var(--surface);
  box-shadow: 0 1px 3px rgba(10, 49, 97, 0.35);
}
.stance-marker.align-start .stance-dot { margin-left: 1px; }
.stance-marker.align-end .stance-dot { margin-right: 1px; }

.stance-label {
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* User marker sits above the track, candidate marker below it. */
.stance-marker.user {
  bottom: -4px;
  flex-direction: column-reverse;
}
.stance-marker.user .stance-dot { background: var(--flag-blue); margin-top: 2px; }
.stance-marker.user .stance-label { color: var(--flag-blue); }

.stance-marker.candidate {
  top: -4px;
}
.stance-marker.candidate .stance-dot { background: var(--stance-tone); margin-bottom: 2px; }
.stance-marker.candidate .stance-label { color: var(--stance-tone); }

.stance-ends {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
}

@media (max-width: 600px) {
  .stance-label { max-width: 96px; }
}

@media (prefers-reduced-motion: reduce) {
  .result-detail {
    animation: none;
  }
}

/* ============================================================================
   BUTTONS & CONTROLS
   ============================================================================ */

.btn {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn.primary {
  background: var(--brand);
  color: white;
}

.btn.primary:hover {
  background: #1a4c8a;
  box-shadow: 0 8px 16px rgba(31, 95, 168, 0.3);
  transform: translateY(-2px);
}

.btn.secondary {
  background: var(--line);
  color: var(--ink);
}

.btn.secondary:hover {
  background: #c9cdd2;
  transform: translateY(-2px);
}

.btn:active {
  transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  .btn {
    transition: none;
  }
  .btn:hover,
  .btn:active {
    transform: none;
  }
}

/* ============================================================================
   RESPONSIVE ADJUSTMENTS
   ============================================================================ */

@media (max-width: 600px) {
  .flashcard {
    padding: 24px 16px;
    border-radius: 12px;
  }

  .question-text {
    font-size: 20px;
  }

  .flashcard-header {
    margin-bottom: 24px;
  }

  .scale-buttons {
    margin-top: 24px;
  }
}

/* Ensure ad slot doesn't interfere */
.ad-slot {
  margin-top: 32px;
  margin-bottom: 32px;
}
