:root {
  /* Light theme colors */
  --background: 0 0% 100%;
  --foreground: 222.2 84% 4.9%;
  --card: 0 0% 100%;
  --card-foreground: 222.2 84% 4.9%;
  --popover: 0 0% 100%;
  --popover-foreground: 222.2 84% 4.9%;
  --primary: 222.2 47.4% 11.2%;
  --primary-foreground: 210 40% 98%;
  --secondary: 210 40% 96.1%;
  --secondary-foreground: 222.2 47.4% 11.2%;
  --muted: 210 40% 96.1%;
  --muted-foreground: 215.4 16.3% 46.9%;
  --accent: 210 40% 96.1%;
  --accent-foreground: 222.2 47.4% 11.2%;
  --destructive: 0 84.2% 60.2%;
  --destructive-foreground: 210 40% 98%;
  --border: 214.3 31.8% 91.4%;
  --input: 214.3 31.8% 91.4%;
  --ring: 222.2 84% 4.9%;
  --radius: 0.5rem;
}

[data-theme="dark"] {
  --background: 222.2 84% 4.9%;
  --foreground: 210 40% 98%;
  --card: 222.2 84% 4.9%;
  --card-foreground: 210 40% 98%;
  --popover: 222.2 84% 4.9%;
  --popover-foreground: 210 40% 98%;
  --primary: 210 40% 98%;
  --primary-foreground: 222.2 47.4% 11.2%;
  --secondary: 217.2 32.6% 17.5%;
  --secondary-foreground: 210 40% 98%;
  --muted: 217.2 32.6% 17.5%;
  --muted-foreground: 215 20.2% 65.1%;
  --accent: 217.2 32.6% 17.5%;
  --accent-foreground: 210 40% 98%;
  --destructive: 0 62.8% 30.6%;
  --destructive-foreground: 210 40% 98%;
  --border: 217.2 32.6% 17.5%;
  --input: 217.2 32.6% 17.5%;
  --ring: 212.7 26.8% 83.9%;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "IBM Plex Sans Arabic", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  line-height: 1.5;
  transition: background-color 0.3s ease, color 0.3s ease;
  min-height: 100vh;
}

[dir="rtl"] {
  direction: rtl;
  text-align: right;
}

[dir="ltr"] {
  direction: ltr;
  text-align: left;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 0;
  margin-bottom: 2rem;
  border-bottom: 1px solid hsl(var(--border));
}

.header-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: hsl(var(--foreground));
}

.header-controls {
  display: flex;
  gap: 0.5rem;
}

/* Buttons */
.btn-primary,
.btn-secondary,
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: calc(var(--radius) - 2px);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s;
  cursor: pointer;
  border: none;
  outline: none;
  padding: 0.5rem 1rem;
  min-height: 2.5rem;
}

.btn-primary {
  background-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  width: 100%;
}

.btn-primary:hover {
  background-color: hsl(var(--primary) / 0.9);
}

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

.btn-secondary {
  background-color: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
}

.btn-secondary:hover {
  background-color: hsl(var(--secondary) / 0.8);
}

.btn-icon {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  background-color: transparent;
  color: hsl(var(--foreground));
  border: 1px solid hsl(var(--border));
}

.btn-icon:hover {
  background-color: hsl(var(--accent));
}

.icon {
  width: 1.25rem;
  height: 1.25rem;
}

/* Card */
.card {
  background-color: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
}

.card-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
  color: hsl(var(--card-foreground));
}

/* Form Elements */
.form-group {
  margin-bottom: 1.5rem;
}

.label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: hsl(var(--foreground));
}

.input,
.select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  border: 1px solid hsl(var(--input));
  border-radius: calc(var(--radius) - 2px);
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  transition: border-color 0.2s;
  min-height: 2.5rem;
}

.input:focus,
.select:focus {
  outline: none;
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 2px hsl(var(--ring) / 0.2);
}

/* Selection Grid */
.selection-container {
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  padding: 1rem;
  max-height: 300px;
  overflow-y: auto;
}

.selection-controls {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.selection-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.5rem;
}

.selection-item {
  padding: 0.5rem;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  background-color: hsl(var(--background));
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  font-size: 0.875rem;
}

.selection-item:hover {
  background-color: hsl(var(--accent));
}

.selection-item.selected {
  background-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  border-color: hsl(var(--primary));
}

/* Utility Classes */
.hidden {
  display: none !important;
}

/* Screen Management */
.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.screen.hidden {
  display: none;
}

/* Quiz Screen */
.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid hsl(var(--border));
}

.quiz-progress {
  font-size: 0.875rem;
  color: hsl(var(--muted-foreground));
}

.streak-display {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
}

.streak-value {
  font-weight: 600;
  color: hsl(var(--primary));
}

.question-container {
  margin-bottom: 2rem;
  padding: 1.5rem;
  background-color: hsl(var(--muted));
  border-radius: calc(var(--radius) - 2px);
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.question-instruction {
  font-size: 0.875rem;
  color: hsl(var(--muted-foreground));
  margin-bottom: 1rem;
  margin-top: 0;
  text-align: center;
  padding: 0 1rem;
}

.question-text {
  font-family: "Scheherazade New", serif;
  font-size: 1.5rem;
  font-weight: 400;
  text-align: right;
  direction: rtl;
  line-height: 2;
  color: hsl(var(--foreground));
}

.options-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.option-button {
  width: 100%;
  padding: 1rem;
  text-align: left;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  cursor: pointer;
  transition: all 0.2s;
  font-size: 1rem;
  min-height: 3.5rem;
  display: flex;
  align-items: center;
  font-family: "IBM Plex Sans Arabic", sans-serif;
}

.option-button[dir="rtl"] {
  font-family: "Scheherazade New", serif;
  font-size: 1.125rem;
  line-height: 1.8;
  text-align: right;
  direction: rtl;
}

.option-button:hover:not(:disabled) {
  background-color: hsl(var(--accent));
}

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

.option-button.correct {
  background-color: hsl(142 76% 36%);
  color: white;
  border-color: hsl(142 76% 36%);
}

.option-button.incorrect {
  background-color: hsl(var(--destructive));
  color: hsl(var(--destructive-foreground));
  border-color: hsl(var(--destructive));
}

.option-button.selected {
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 2px hsl(var(--ring) / 0.2);
}

.page-view-container {
  margin-top: 1rem;
  display: flex;
  justify-content: center;
}

.page-view-container.hidden {
  display: none;
}

.quiz-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.quiz-actions .btn-primary {
  width: auto;
  min-width: 120px;
}

.quiz-actions .btn-secondary {
  width: auto;
  min-width: 120px;
}

/* Results Screen */
.results-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  text-align: center;
  padding: 1.5rem;
  background-color: hsl(var(--muted));
  border-radius: calc(var(--radius) - 2px);
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: hsl(var(--primary));
  margin-bottom: 0.5rem;
}

#score-value {
  color: hsl(142 76% 36%);
}

.stat-label {
  font-size: 0.875rem;
  color: hsl(var(--muted-foreground));
}

.results-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Responsive Design */
@media (min-width: 640px) {
  .container {
    padding: 2rem;
  }

  .card {
    padding: 2rem;
  }

  .selection-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }

  .results-actions {
    flex-direction: row;
  }

  .results-actions .btn-primary,
  .results-actions .btn-secondary {
    width: auto;
    flex: 1;
  }
}

@media (min-width: 768px) {
  .header-title {
    font-size: 2rem;
  }

  .question-text {
    font-size: 2rem;
  }

  .options-container {
    gap: 1rem;
  }
}

/* Scrollbar Styling */
.selection-container::-webkit-scrollbar {
  width: 8px;
}

.selection-container::-webkit-scrollbar-track {
  background: hsl(var(--muted));
  border-radius: 4px;
}

.selection-container::-webkit-scrollbar-thumb {
  background: hsl(var(--muted-foreground) / 0.3);
  border-radius: 4px;
}

.selection-container::-webkit-scrollbar-thumb:hover {
  background: hsl(var(--muted-foreground) / 0.5);
}

/* Toggle Group */
.toggle-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  padding: 0.25rem;
  background-color: hsl(var(--muted));
}

.toggle-button {
  flex: 1;
  min-width: 120px;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  background-color: transparent;
  color: hsl(var(--foreground));
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.875rem;
  font-weight: 500;
}

.toggle-button:hover {
  background-color: hsl(var(--accent));
}

.toggle-button.active {
  background-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}

@media (max-width: 640px) {
  .toggle-group {
    flex-direction: column;
  }
  
  .toggle-button {
    width: 100%;
  }
}

/* Modal Styles */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}

.modal-content {
  position: relative;
  background-color: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  max-width: 90vw;
  max-height: 90vh;
  width: 100%;
  display: flex;
  flex-direction: column;
  z-index: 1001;
}

.modal-small {
  max-width: 400px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 1px solid hsl(var(--border));
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: hsl(var(--card-foreground));
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  padding: 0;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: calc(var(--radius) - 2px);
  transition: all 0.2s;
}

.modal-close:hover {
  background-color: hsl(var(--accent));
  color: hsl(var(--foreground));
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  padding: 1.5rem;
  border-top: 1px solid hsl(var(--border));
}

.modal-footer .btn-primary,
.modal-footer .btn-secondary {
  width: auto;
  min-width: 100px;
}

/* Page Content in Modal */
.page-loading,
.page-error {
  text-align: center;
  padding: 2rem;
  color: hsl(var(--muted-foreground));
}

.page-loading.hidden,
.page-error.hidden {
  display: none !important;
}

.page-content {
  font-family: "Scheherazade New", serif;
}

.page-content.hidden {
  display: none !important;
}

.page-verses {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.verse {
  padding: 1rem;
  border-radius: calc(var(--radius) - 2px);
  background-color: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  transition: all 0.2s;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  direction: rtl;
  text-align: right;
}

.verse.highlighted {
  background-color: hsl(var(--primary) / 0.1);
  border-color: hsl(var(--primary));
  box-shadow: 0 0 0 2px hsl(var(--primary) / 0.2);
}

.verse-number {
  font-family: "IBM Plex Sans Arabic", sans-serif;
  font-size: 0.875rem;
  font-weight: 600;
  color: hsl(var(--primary));
  min-width: 3rem;
  flex-shrink: 0;
}

.verse-text {
  font-size: 1.25rem;
  line-height: 2;
  color: hsl(var(--foreground));
  flex: 1;
}

/* Clickable Header Title */
.header-title.clickable {
  cursor: pointer;
  transition: opacity 0.2s;
}

.header-title.clickable:hover {
  opacity: 0.7;
}

@media (min-width: 768px) {
  .modal-content {
    max-width: 800px;
  }
  
  .verse-text {
    font-size: 1.5rem;
  }
}

/* History Screen */
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.history-filters {
  margin-bottom: 1.5rem;
}

.history-list {
  max-height: 500px;
  overflow-y: auto;
  margin-bottom: 1.5rem;
}

.history-empty {
  text-align: center;
  padding: 3rem;
  color: hsl(var(--muted-foreground));
}

.history-item {
  padding: 1rem;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  margin-bottom: 0.75rem;
  background-color: hsl(var(--background));
  transition: all 0.2s;
}

.history-item:hover {
  background-color: hsl(var(--accent));
}

.history-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.history-item-title {
  font-weight: 600;
  color: hsl(var(--foreground));
}

.history-item-date {
  font-size: 0.875rem;
  color: hsl(var(--muted-foreground));
}

.history-item-stats {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.history-stat {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.history-stat-label {
  font-size: 0.875rem;
  color: hsl(var(--muted-foreground));
}

.history-stat-value {
  font-weight: 600;
  color: hsl(var(--foreground));
}

.history-stat-value.score-number {
  color: hsl(142 76% 36%);
}

.history-detail-score-number {
  color: hsl(142 76% 36%);
}

.history-actions {
  display: flex;
  justify-content: flex-end;
}

.history-item.clickable {
  cursor: pointer;
}

.history-item.clickable:hover {
  transform: translateY(-2px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* History Detail Screen */
.history-detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.history-detail-meta-section {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid hsl(var(--border));
}

.history-detail-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  font-size: 0.875rem;
}

.history-meta-item {
  padding: 0.5rem;
  background-color: hsl(var(--muted));
  border-radius: calc(var(--radius) - 2px);
}

.history-detail-questions {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  max-height: 70vh;
  overflow-y: auto;
  padding-right: 0.5rem;
}

.history-question-item {
  padding: 1rem;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  background-color: hsl(var(--background));
}

.history-question-item.correct {
  border-left: 4px solid hsl(142 76% 36%);
}

.history-question-item.incorrect {
  border-left: 4px solid hsl(var(--destructive));
}

.history-question-number {
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: hsl(var(--foreground));
}

.history-question-text {
  font-family: "Scheherazade New", serif;
  font-size: 1.125rem;
  line-height: 2;
  margin-bottom: 1rem;
  color: hsl(var(--foreground));
  direction: rtl;
  text-align: right;
}

.history-answer-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.history-answer-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: hsl(var(--muted-foreground));
  margin-top: 0.5rem;
}

.history-answer-text {
  font-family: "Scheherazade New", serif;
  font-size: 1rem;
  line-height: 1.8;
  padding: 0.75rem;
  border-radius: calc(var(--radius) - 2px);
  direction: rtl;
  text-align: right;
}

.history-answer-text.correct {
  background-color: hsl(142 76% 36% / 0.1);
  color: hsl(142 76% 36%);
  border: 1px solid hsl(142 76% 36% / 0.3);
}

.history-answer-text.incorrect {
  background-color: hsl(var(--destructive) / 0.1);
  color: hsl(var(--destructive));
  border: 1px solid hsl(var(--destructive) / 0.3);
}

.history-page-btn {
  margin-top: 0.5rem;
  width: auto;
  align-self: flex-start;
}

/* Install Prompt */
.install-prompt {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 999;
  padding: 1rem;
  transform: translateY(0);
  transition: transform 0.3s ease-in-out, opacity 0.3s ease-in-out;
  pointer-events: none;
}

.install-prompt.hidden {
  transform: translateY(100%);
  opacity: 0;
  pointer-events: none;
}

.install-prompt-content {
  position: relative;
  background-color: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: 0 -4px 6px -1px rgb(0 0 0 / 0.1), 0 -2px 4px -2px rgb(0 0 0 / 0.1);
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  max-width: 600px;
  margin: 0 auto;
  pointer-events: auto;
}

.install-prompt-icon {
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: hsl(var(--primary) / 0.1);
  border-radius: calc(var(--radius) - 2px);
  color: hsl(var(--primary));
}

.install-prompt-icon svg {
  width: 1.5rem;
  height: 1.5rem;
}

.install-prompt-text {
  flex: 1;
  min-width: 0;
}

.install-prompt-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 0.25rem 0;
  color: hsl(var(--card-foreground));
}

.install-prompt-message {
  font-size: 0.875rem;
  margin: 0;
  color: hsl(var(--muted-foreground));
  line-height: 1.4;
}

.install-prompt-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.install-prompt-actions .btn-primary,
.install-prompt-actions .btn-secondary {
  padding: 0.5rem 1rem;
  min-height: 2.5rem;
  font-size: 0.875rem;
  white-space: nowrap;
}

.install-prompt-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: none;
  border: none;
  font-size: 1.25rem;
  line-height: 1;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  padding: 0.25rem;
  width: 1.75rem;
  height: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: calc(var(--radius) - 2px);
  transition: all 0.2s;
  flex-shrink: 0;
}

[dir="rtl"] .install-prompt-close {
  right: auto;
  left: 0.5rem;
}

.install-prompt-close:hover {
  background-color: hsl(var(--accent));
  color: hsl(var(--foreground));
}

/* RTL Support for Install Prompt */
[dir="rtl"] .install-prompt-content {
  flex-direction: row-reverse;
}

[dir="rtl"] .install-prompt-actions {
  flex-direction: row-reverse;
}

/* Responsive Design for Install Prompt */
@media (max-width: 640px) {
  .install-prompt {
    padding: 0.75rem;
  }
  
  .install-prompt-content {
    flex-wrap: wrap;
    padding: 0.75rem;
  }
  
  .install-prompt-text {
    flex-basis: 100%;
    order: 2;
    margin-top: 0.5rem;
  }
  
  .install-prompt-actions {
    flex: 1;
    order: 3;
    margin-top: 0.5rem;
  }
  
  .install-prompt-actions .btn-primary,
  .install-prompt-actions .btn-secondary {
    flex: 1;
  }
  
  .install-prompt-close {
    order: 1;
    position: static;
    margin-left: auto;
  }
  
  [dir="rtl"] .install-prompt-close {
    margin-left: 0;
    margin-right: auto;
  }
}

@media (min-width: 641px) {
  .install-prompt-content {
    padding: 1.25rem;
  }
}

