/* Flipcard Styles */

/* ============================================================================
   Navigation Buttons - Consistent Width
   ============================================================================ */

.flipcards-container .btn[id="prevBtn"],
.flipcards-container .btn[id="nextBtn"],
.flipcards-container .btn[id="skipBtn"] {
  min-width: 110px;
}

/* ============================================================================
   Card Container - Moderate Min Height to Reduce Jumping
   ============================================================================ */

#cardContainer,
.flipcard-container {
  min-height: 300px;
}

/* ============================================================================
   Hover Effects
   ============================================================================ */

.hover-lift {
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease;
}

.hover-lift:hover {
  transform: translateY(-4px);
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15) !important;
}

/* ============================================================================
   Flipcard 3D Animation
   ============================================================================ */

.flipcard-container {
  perspective: 1000px;
  cursor: pointer;
  width: 100%;
  min-height: 350px;
}

.flipcard {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 350px;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
}

.flipcard.flipped {
  transform: rotateY(180deg);
}

.flipcard-front,
.flipcard-back {
  position: absolute;
  width: 100%;
  height: 100%;
  min-height: 350px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.flipcard-back {
  transform: rotateY(180deg);
}

/* Ensure cards don't overlap during flip */
.flipcard-container .card {
  height: 100%;
  min-height: 350px;
}

/* ============================================================================
   Card Content States
   ============================================================================ */

.card-marked-correct {
  opacity: 0.6;
  border-color: #198754 !important;
  background-color: rgba(25, 135, 84, 0.05);
}

.card-marked-incorrect {
  opacity: 0.6;
  border-color: #dc3545 !important;
  background-color: rgba(220, 53, 69, 0.05);
}

/* ============================================================================
   Timer Pulse Animation (Game Mode)
   ============================================================================ */

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.animate-pulse {
  animation: pulse 1s ease-in-out infinite;
}

/* Timer warning when time is low */
.timer-warning {
  color: #dc3545 !important;
  animation: pulse 0.5s ease-in-out infinite;
}

/* ============================================================================
   Option Button Styles (Game Mode)
   ============================================================================ */

.option-btn {
  transition: all 0.2s ease;
}

.option-btn:hover:not(:disabled) {
  transform: translateX(4px);
  border-color: #0d6efd;
  background-color: rgba(13, 110, 253, 0.05);
}

.option-btn:disabled {
  cursor: not-allowed;
}

/* Correct answer highlight */
.option-btn.btn-success {
  animation: correct-flash 0.3s ease;
}

@keyframes correct-flash {
  0%,
  100% {
    background-color: #198754;
  }
  50% {
    background-color: #20c997;
  }
}

/* Wrong answer shake */
.option-btn.btn-danger {
  animation: wrong-shake 0.3s ease;
}

@keyframes wrong-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

/* ============================================================================
   Code Block Styling in Cards
   ============================================================================ */

/* Flipcard-specific pre adjustments (inherits dark theme from base.html) */
.flipcard pre,
.flipcard-container pre {
  margin: 0;
  max-height: 200px;
  overflow-y: auto;
  text-align: left;
}

/* ============================================================================
   Progress Bar Enhancements
   ============================================================================ */

.progress {
  overflow: visible;
}

.progress-bar {
  transition: width 0.3s ease-out;
  border-radius: 0.375rem;
}

/* ============================================================================
   Score Badge Animations
   ============================================================================ */

@keyframes score-bump {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.2);
  }
}

.score-updated {
  animation: score-bump 0.3s ease;
}

/* Streak fire effect */
.streak-active {
  position: relative;
}

.streak-active::after {
  content: "🔥";
  position: absolute;
  right: -1.5rem;
  top: 50%;
  transform: translateY(-50%);
  animation: fire-float 0.5s ease infinite alternate;
}

@keyframes fire-float {
  0% {
    transform: translateY(-50%) scale(1);
  }
  100% {
    transform: translateY(-60%) scale(1.1);
  }
}

/* ============================================================================
   Mobile Optimizations
   ============================================================================ */

@media (max-width: 768px) {
  /* Reduce top padding on mobile */
  .container.py-4 {
    padding-top: 0.5rem !important;
    padding-bottom: 1rem !important;
  }

  /* Minimal side padding on mobile */
  .flipcards-container {
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
  }

  /* Hide breadcrumb on mobile */
  nav[aria-label="breadcrumb"] {
    margin-bottom: 0.5rem !important;
  }

  /* Smaller header on mobile */
  .flipcards-container h1.h3 {
    font-size: 1.25rem;
  }

  /* Height elastic flipcard using CSS Grid - both cards in same cell */
  .flipcard-container {
    min-height: auto;
  }

  .flipcard {
    display: grid;
    min-height: auto;
  }

  .flipcard-front,
  .flipcard-back {
    grid-area: 1 / 1;
    position: relative;
    min-height: auto;
    height: auto;
  }

  .flipcard-container .card {
    min-height: auto;
    height: auto;
  }

  /* Reduce card body min-height on mobile */
  .flipcard .card-body {
    min-height: 100px !important;
  }

  /* Larger touch targets for mobile */
  .option-btn {
    padding: 1rem !important;
    font-size: 1rem;
  }

  /* Stack score badges vertically on small screens */
  .d-flex.gap-4 {
    gap: 0.5rem !important;
  }

  /* Adjust keyboard hints on mobile */
  kbd {
    display: none;
  }

  .text-muted.small kbd {
    display: none;
  }

  /* Simplified hint text for mobile */
  .text-muted.small::after {
    content: "Tap to interact";
  }

  /* Hide keyboard instructions, show tap instructions */
  .text-muted.small {
    font-size: 0 !important;
  }

  .text-muted.small::after {
    font-size: 0.875rem;
  }
}

/* Touch feedback for mobile */
@media (hover: none) {
  .hover-lift:active {
    transform: translateY(-2px);
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.1) !important;
  }

  .option-btn:active:not(:disabled) {
    transform: translateX(2px);
    background-color: rgba(13, 110, 253, 0.1);
  }
}

/* ============================================================================
   Completion Celebration
   ============================================================================ */

@keyframes celebration {
  0% {
    transform: scale(0.8);
    opacity: 0;
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

#completeSection .card {
  animation: celebration 0.5s ease-out;
}

/* Trophy icon bounce */
#completeSection .bi-trophy,
#completeSection .bi-check-circle {
  animation: trophy-bounce 0.6s ease infinite alternate;
}

@keyframes trophy-bounce {
  0% {
    transform: translateY(0);
  }
  100% {
    transform: translateY(-5px);
  }
}

/* Final score display */
#completeSection .display-1 {
  font-weight: 700;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

/* ============================================================================
   Diagram Container
   ============================================================================ */

.diagram-container {
  max-width: 300px;
  margin: 0 auto;
}

.diagram-container iframe {
  border: 1px solid #dee2e6;
  border-radius: 0.375rem;
}

/* ============================================================================
   Accessibility Enhancements
   ============================================================================ */

/* Focus states for keyboard navigation */
.flipcard-container:focus {
  outline: 3px solid #0d6efd;
  outline-offset: 2px;
  border-radius: 0.5rem;
}

.option-btn:focus {
  outline: 3px solid #0d6efd;
  outline-offset: 2px;
  box-shadow: none;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  .flipcard {
    transition: none;
  }

  .flipcard.flipped {
    transform: none;
  }

  .flipcard-back {
    display: none;
  }

  .flipcard.flipped .flipcard-front {
    display: none;
  }

  .flipcard.flipped .flipcard-back {
    display: block;
    transform: none;
  }

  .hover-lift {
    transition: none;
  }

  .option-btn {
    transition: none;
  }

  .animate-pulse,
  .score-updated,
  .streak-active::after,
  #completeSection .bi-trophy,
  #completeSection .bi-check-circle {
    animation: none;
  }
}

/* ============================================================================
   Windows High Contrast Mode Support
   ============================================================================ */

@media (forced-colors: active) {
  .flipcard-container,
  .flipcard,
  .flipcard-front,
  .flipcard-back {
    forced-color-adjust: none;
  }

  .card-marked-correct {
    outline: 3px double LinkText;
    outline-offset: 2px;
    border-color: LinkText !important;
  }

  .card-marked-incorrect {
    outline: 3px dashed CanvasText;
    outline-offset: 2px;
    border-color: CanvasText !important;
  }

  .option-btn {
    border: 2px solid ButtonBorder;
  }

  .option-btn:hover:not(:disabled) {
    outline: 2px solid Highlight;
    outline-offset: 2px;
  }

  .option-btn.btn-success {
    outline: 3px solid LinkText;
    border-color: LinkText;
  }

  .option-btn.btn-danger {
    outline: 3px solid CanvasText;
    border-color: CanvasText;
  }

  #completeSection .display-1 {
    forced-color-adjust: none;
  }

  .diagram-container iframe {
    forced-color-adjust: none;
  }

  .flipcard-container:focus {
    forced-color-adjust: none;
  }

  .hover-lift:hover {
    forced-color-adjust: none;
  }

  .option-btn:focus {
    forced-color-adjust: none;
  }

  .timer-warning {
    forced-color-adjust: none;
  }

  .rank-gold {
    forced-color-adjust: none;
  }

  .rank-silver {
    forced-color-adjust: none;
  }

  .rank-bronze {
    forced-color-adjust: none;
  }

  .rank-default {
    forced-color-adjust: none;
  }

  .current-user-row {
    forced-color-adjust: none;
  }
}

/* ============================================================================
   Game Mode - Full Width / Centered Options
   ============================================================================ */

.game-mode-container {
  max-width: 800px;
  margin: 0 auto;
}

@media (min-width: 992px) {
  /* Center game content on wide screens */
  .game-mode-container {
    max-width: 700px;
  }
}

/* Ensure MCQ options are full width within container */
.game-mode-container .mcq-options {
  width: 100%;
}

.game-mode-container .mcq-option {
  width: 100%;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Leaderboard Styles
   ───────────────────────────────────────────────────────────────────────────── */

.rank-badge {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 0.85rem;
}

.rank-gold {
  background: linear-gradient(135deg, #ffd700, #ffec8b);
  color: #6b5900;
}

.rank-silver {
  background: linear-gradient(135deg, #c0c0c0, #e8e8e8);
  color: #4a4a4a;
}

.rank-bronze {
  background: linear-gradient(135deg, #cd7f32, #daa520);
  color: #4a2800;
}

.rank-default {
  background-color: #f0f0f0;
  color: #6c757d;
}

.current-user-row {
  background-color: #e7f3ff !important;
  font-weight: 600;
}

.leaderboard-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}

#leaderboardCard .table th {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
