/* Reset and Base Styles */
body, html {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow-x: auto;
  background: #f8f9fa;
}

/* Background Animation */
.animated-bg {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: 100vw;
  background: linear-gradient(270deg, #ffd6e8, #ffeacc, #d4f0fc, #d0f0e0, #fce4ec, #fff9c4, #e1bee7, #ffd6e8);
  background-size: 1600% 1600%;
  animation: rainbowBackground 90s ease infinite;
  z-index: 0;
}

@keyframes rainbowBackground {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.animated-icon {
  position: fixed;
  width: 64px;
  height: 64px;
  pointer-events: none;
  opacity: 0.06;
  z-index: 1;
}

/* Floating Icons Animation */
{% for icon in floating_objects %}
.icon-{{ icon.index }} {
  {% if icon.direction == 'ltr' %} 
    top: {{ icon.index|add:"5" }}%; 
    left: -70px; 
    animation: move-ltr-{{ icon.index }} {{ icon.duration }}s linear infinite; 
    animation-delay: {{ icon.delay }}s;
  {% elif icon.direction == 'rtl' %} 
    top: {{ icon.index|add:"5" }}%; 
    left: 100vw; 
    animation: move-rtl-{{ icon.index }} {{ icon.duration }}s linear infinite; 
    animation-delay: {{ icon.delay }}s;
  {% elif icon.direction == 'ttb' %} 
    top: -70px; 
    left: {{ icon.index|add:"5" }}%; 
    animation: move-ttb-{{ icon.index }} {{ icon.duration }}s linear infinite; 
    animation-delay: {{ icon.delay }}s;
  {% elif icon.direction == 'btt' %} 
    top: 100vh; 
    left: {{ icon.index|add:"5" }}%; 
    animation: move-btt-{{ icon.index }} {{ icon.duration }}s linear infinite; 
    animation-delay: {{ icon.delay }}s;
  {% endif %}
}

@keyframes move-{{ icon.direction }}-{{ icon.index }} {
  from { transform: translate(0, 0); }
  to {
    {% if icon.direction == 'ltr' %} transform: translateX(110vw);
    {% elif icon.direction == 'rtl' %} transform: translateX(-110vw);
    {% elif icon.direction == 'ttb' %} transform: translateY(110vh);
    {% elif icon.direction == 'btt' %} transform: translateY(-110vh);
    {% endif %}
  }
}
{% endfor %}

/* Main Quiz Container */
.quiz-main-container {
  position: relative;
  width: 100%;
  min-height: 100vh;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  background: white;
  max-width: 1400px;
  margin: 0 auto;
  box-shadow: 0 0 20px rgba(0,0,0,0.1);
}

/* Ensure flying coins work with new structure */
.quiz-main-container .flying-coin,
.quiz-main-container .coin-landing {
  z-index: 2000;
}

/* Header Styling */
.quiz-header {
  width: 100vw;
  position: sticky;
  top: 0;
  left: 0;
  padding: 1rem 0;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  z-index: 1000;
  margin: 0;
  border-bottom: 2px solid #e9ecef;
  margin-left: calc(-50vw + 50%);
  margin-right: calc(-50vw + 50%);
}

.quiz-header .container-fluid {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: nowrap;
  gap: 1rem;
}

/* Header Layout Sections */
.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
}

.header-center {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  max-width: 500px;
  margin: 0 auto;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

/* Progress Components */
.progress-container {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.progress-thick {
  flex-grow: 1;
  margin: 0;
  height: 1rem;
  transition: width 0.6s ease;
}

.progress-text {
  white-space: nowrap;
  font-weight: 600;
  color: #0d6efd;
}

/* Progress Tracker */
.progress-tracker {
  position: fixed;
  top: 20px;
  right: 20px;
  background: rgba(255, 255, 255, 0.9);
  padding: 10px 15px;
  border-radius: 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  z-index: 100;
  display: flex;
  align-items: center;
}

.progress-tracker .coins {
  display: flex;
  align-items: center;
  margin-right: 15px;
}

.progress-tracker .coins i {
  color: gold;
  margin-right: 5px;
}

.progress-tracker .progress-bar-container {
  width: 100px;
  height: 10px;
  background: #f0f0f0;
  border-radius: 5px;
  overflow: hidden;
}

.progress-tracker .progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #4CAF50, #8BC34A);
  transition: width 0.3s ease;
}

/* Content Area */
.quiz-content-container {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  margin-top: 2vh;
  margin-bottom: 2vh;
  width: 100%;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  position: relative;
  z-index: 1;
}

/* Hide animated background in content area */
.quiz-content-container .animated-bg,
.quiz-content-container .animated-icon {
  display: none !important;
}

.quiz-content {
  width: 100%;
  height: 100%;
  margin: 0 auto;
  padding: 0;
  background: transparent;
}

.quiz-content-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Question Area */
.question-area {
  transition: opacity .28s ease, transform .28s ease;
  min-height: calc(100vh - 180px);
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: transparent;
}

.question-area.fade-out {
  opacity: 0;
  transform: translateY(8px);
}

.question-area.fade-in {
  opacity: 1;
  transform: none;
}

.question-container {
  flex: 1;
  min-height: 200px;
  overflow-y: auto;
}

/* Quiz Cards */
.quiz-card {
  transition: all 0.3s ease;
  transform: translateY(20px);
  opacity: 0;
}

.quiz-card.visible {
  transform: translateY(0);
  opacity: 1;
}

.quiz-main-container img {
  object-fit: cover;
  object-position: center;
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: .5rem;
}

/* Option Cards */
.option-card.card {
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  transform-style: preserve-3d;
  background: white;
  height: 100%;
}

.option-card.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(0,0,0,.08);
}

.option-card.correct {
  outline: 2px solid #28a745;
  background: rgba(40, 167, 69, 0.05);
  border-color: #4CAF50;
  background-color: #e8f5e9;
  box-shadow: 0 0 20px rgba(76, 175, 80, 0.4);
  animation: correctPulse 0.6s ease-out forwards;
}

.option-card.incorrect {
  outline: 2px solid #dc3545;
  background: rgba(220, 53, 69, 0.05);
  border-color: #f44336;
  background-color: #ffebee;
  animation: incorrectShake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

/* Card Animations */
@keyframes correctPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@keyframes incorrectShake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
  20%, 40%, 60%, 80% { transform: translateX(5px); }
}

/* Coin Animations */
.flying-coin, .coin-landing {
  position: absolute;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 6px 15px rgba(0,0,0,.25);
  z-index: 2000;
  pointer-events: none;
}

.flying-coin i, .coin-landing i {
  font-size: 18px;
}

.flying-coin i {
  font-size: 24px;
  color: gold;
  animation: coin-spin 1.2s linear infinite;
}

@keyframes coin-spin {
  0% { transform: rotateY(0deg); }
  100% { transform: rotateY(360deg); }
}

@keyframes coin-fly {
  0% {
    transform: 
      translate3d(var(--start-x), var(--start-y), 0)
      scale(1)
      rotateY(0deg);
    opacity: 1;
  }
  70% {
    opacity: 1;
  }
  100% {
    transform: 
      translate3d(var(--end-x), var(--end-y), 0)
      scale(0.5)
      rotateY(1440deg);
    opacity: 0;
  }
}

.coin-landing {
  animation: coin-land 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes coin-land {
  0% {
    transform: scale(1.5);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 0;
  }
}

/* Introduction Screen */
.hordhac-screen {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 180px);
  padding: 2rem;
  text-align: center;
}

.hordhac-content {
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
}

.hordhac-image {
  width: 100%;
  max-width: 400px;
  height: auto;
  border-radius: 16px;
  margin-bottom: 2rem;
}

.hordhac-title {
  font-size: 2.5rem;
  font-weight: 700;
  color: #0d6efd;
  margin-bottom: 1.5rem;
}

.hordhac-description {
  font-size: 1.2rem;
  color: #6c757d;
  line-height: 1.6;
  margin-bottom: 2.5rem;
}

.start-button {
  padding: 1rem 3rem;
  font-size: 1.25rem;
  font-weight: 600;
  border-radius: 50px;
  background: linear-gradient(135deg, #0d6efd, #0dcaf0);
  border: none;
  color: white;
  box-shadow: 0 8px 25px rgba(13, 110, 253, 0.3);
  transition: all 0.3s ease;
}

.start-button:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 30px rgba(13, 110, 253, 0.4);
}

.start-button:active {
  transform: translateY(1px);
}

/* Completion Screen */
.completion-screen {
  text-align: center;
  padding: 2rem 1rem;
  min-height: auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 100%;
}

.completion-badge {
  width: 120px;
  height: 120px;
  margin: 0 auto 2rem;
  background: linear-gradient(145deg, #28a745, #20c997);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 3rem;
  box-shadow: 0 8px 25px rgba(40, 167, 69, 0.3);
  animation: pulse 2s infinite;
}

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

.completion-content {
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.completion-stats {
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-radius: 20px;
  padding: 2rem;
  margin-bottom: 2.5rem;
  box-shadow: 0 10px 30px rgba(0,0,0,0.08);
  border: 1px solid rgba(0,0,0,0.05);
}

.progress-score {
  font-size: 3.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, #0d6efd, #0dcaf0);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.5rem;
}

.coins-earned {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-size: 1.5rem;
  font-weight: 600;
  color: #fd7e14;
  margin: 1rem 0;
}

.completion-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1rem;
  margin: 2rem 0;
}

.btn-celebration {
  padding: 0.75rem 2rem;
  border-radius: 50px;
  font-weight: 600;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.btn-celebration:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(0,0,0,0.15);
}

.related-cashirro {
  margin: 3rem 0;
  padding: 2rem 0;
  border-top: 1px solid #e9ecef;
  border-bottom: 1px solid #e9ecef;
}

.related-item {
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  border-radius: 16px;
  overflow: hidden;
  height: 100%;
}

.related-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 15px 35px rgba(0,0,0,0.1);
}

.related-thumb {
  position: relative;
  overflow: hidden;
  height: 160px;
}

.related-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.related-item:hover .related-thumb img {
  transform: scale(1.05);
}

.related-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}

.related-badge img {
  width: 24px;
  height: 24px;
  object-fit: cover;
}

.related-content {
  padding: 1.25rem;
}

.related-category {
  font-size: 0.875rem;
  color: #6c757d;
  margin-bottom: 0.5rem;
}

.related-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: #212529;
  line-height: 1.4;
}

.related-play {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #0d6efd;
  color: white;
  text-decoration: none;
  transition: all 0.3s ease;
}

.related-play:hover {
  background: #0b5ed7;
  transform: scale(1.1);
}

/* TTS Speaker Button */
.tts-speaker-button i {
  font-size: 2.2em !important;
}

/* Responsive Design */
@media (max-width: 767.98px) {
  .quiz-main-container {
    min-height: 100vh;
    border-radius: 0;
  }
  
  .quiz-header {
    padding: 0.5rem 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  }
  
  .quiz-header .container-fluid {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
    gap: 0.5rem;
  }
  
  .header-left, .header-right {
    gap: 0.5rem;
  }
  
  .progress-text {
    font-size: 0.875rem;
  }
  
  .answered-icon {
    display: none !important;
  }
  
  .quiz-content {
    width: 100%;
    padding: 0;
  }
  
  .quiz-content-container {
    margin-top: 1.5vh;
  }
  
  .container-fluid {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
  
  .question-area {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
  
  .option-card .card-body {
    padding: 0.75rem;
  }
  
  /* Introduction responsive */
  .hordhac-screen {
    padding: 1.5rem 0.75rem;
  }
  
  .hordhac-title {
    font-size: 2rem;
  }
  
  .hordhac-description {
    font-size: 1.1rem;
  }
  
  .start-button {
    padding: 0.875rem 2.5rem;
    font-size: 1.1rem;
  }
  
  /* Completion screen responsive */
  .completion-screen {
    padding: 1.5rem 0.75rem;
  }
  
  .completion-badge {
    width: 100px;
    height: 100px;
    font-size: 2.5rem;
  }
  
  .completion-stats {
    padding: 1.5rem;
  }
  
  .progress-score {
    font-size: 2.5rem;
  }
  
  .coins-earned {
    font-size: 1.25rem;
  }
  
  .completion-actions {
    flex-direction: column;
    align-items: center;
  }
  
  .btn-celebration {
    width: 100%;
    max-width: 300px;
  }
  
  .related-thumb {
    height: 140px;
  }
}

@media (max-width: 575.98px) {
  .progress-text {
    font-size: 0.8125rem;
  }
  
  .hordhac-title {
    font-size: 1.75rem;
  }
  
  .hordhac-description {
    font-size: 1rem;
  }
  
  .completion-badge {
    width: 80px;
    height: 80px;
    font-size: 2rem;
    margin-bottom: 1.5rem;
  }
  
  .completion-stats {
    padding: 1.25rem;
    margin-bottom: 2rem;
  }
  
  .progress-score {
    font-size: 2rem;
  }
}

@media (min-width: 768px) and (max-width: 991.98px) {
  .quiz-content {
    width: 95%;
    padding: 0 0.75rem;
  }
}

@media (min-width: 992px) {
  .quiz-content {
    width: 90%;
    max-width: 1200px;
    padding: 0 1rem;
  }
}

/* Height-based responsive adjustments */
@media (max-height: 600px) {
  .quiz-main-container {
    min-height: 300px;
    max-height: 95vh;
  }
}

@media (min-width: 576px) {
  .quiz-main-container {
    min-height: 450px;
  }
  .question-container {
    min-height: 250px;
  }
}

@media (min-width: 768px) {
  .quiz-main-container {
    min-height: 500px;
  }
}

@media (min-width: 992px) {
  .quiz-main-container {
    min-height: 550px;
  }
  .question-container {
    min-height: 300px;
  }
}