:root {
  --font-sans: 'Inter', system-ui, sans-serif;
  --font-arabic: 'Amiri Quran', serif;
  
  /* Light Theme Colors */
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --bg-page: #fdfcf8; /* slightly warmer paper feel */
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --accent: #10b981;
  --accent-light: #d1fae5;
  --accent-text: #047857;
  --header-bg: rgba(255, 255, 255, 0.85);

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius-md: 0.5rem;
  --radius-lg: 1rem;
  
  /* Transitions */
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg-main: #0f172a;
  --bg-card: #1e293b;
  --bg-page: #1e293b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border: #334155;
  --accent: #34d399;
  --accent-light: #064e3b;
  --accent-text: #6ee7b7;
  --header-bg: rgba(15, 23, 42, 0.85);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.8);
}

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

html {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-main);
  scroll-behavior: smooth;
  transition: background-color var(--transition), color var(--transition);
}

body {
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

.header {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(12px);
  background-color: var(--header-bg);
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
  transition: var(--transition);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
}

.search-bar {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.5rem 1rem;
  flex: 1;
  max-width: 400px;
  margin: 0 1rem;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.search-bar:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.search-input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  width: 100%;
  font-size: 1rem;
  margin-left: 0.5rem;
}

.search-input::placeholder {
  color: var(--text-muted);
}

.icon-button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 50%;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.icon-button:hover {
  background: var(--bg-card);
  border-color: var(--border);
  color: var(--accent);
}

/* Main Content */
.main-content {
  padding: 2rem 0;
  flex: 1;
}

.page-title {
  text-align: center;
  margin-bottom: 2rem;
  font-size: 2rem;
  font-weight: 700;
}

.page-subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-top: -1.5rem;
  margin-bottom: 2rem;
}

/* Grid System */
.surah-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}

/* Cards */
.surah-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-sm);
}

.surah-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--accent);
}

.surah-card-number {
  background-color: var(--accent-light);
  color: var(--accent-text);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.surah-card-info {
  flex: 1;
  margin-left: 1rem;
  display: flex;
  flex-direction: column;
}

.surah-card-title {
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--text-main);
}

.surah-card-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.surah-card-arabic {
  font-family: var(--font-arabic);
  font-size: 1.5rem;
  color: var(--accent);
  text-align: right;
  flex-shrink: 0;
  margin-left: 1rem;
}

/* Ayah View */
.ayah-list {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  max-width: 800px;
  margin: 0 auto;
}

.ayah-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  position: relative;
}

.ayah-card:hover {
  box-shadow: var(--shadow-md);
}

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

.ayah-number {
  background-color: var(--accent-light);
  color: var(--accent-text);
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 600;
}

.ayah-actions {
  display: flex;
  gap: 0.5rem;
}

.ayah-arabic {
  font-family: var(--font-arabic);
  font-size: 2.25rem;
  line-height: 2;
  text-align: right;
  direction: rtl;
  color: var(--text-main);
  margin-bottom: 1.5rem;
  padding: 0.5rem 0;
}

.ayah-translation {
  font-size: 1.125rem;
  line-height: 1.7;
  color: var(--text-muted);
}

/* Mushaf Mode Styling */
.mushaf-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem 0;
}

.mushaf-page {
  background-color: var(--bg-page);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  padding: 3rem;
  max-width: 800px;
  width: 100%;
  position: relative;
  transition: opacity 0.3s ease;
  min-height: 850px;
  display: flex;
  align-items: stretch;
}

.mushaf-page-inner {
  border: 4px double var(--accent);
  padding: 2rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.mushaf-text {
  font-family: var(--font-arabic);
  line-height: 2.3;
  text-align: justify;
  text-align-last: center;
  direction: rtl;
  color: var(--text-main);
  transition: font-size 0.2s;
  width: 100%;
}

.surah-mushaf-header {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: var(--bg-card);
  border: 2px solid var(--accent);
  border-radius: 8px;
  padding: 0.5rem 2rem;
  margin: 1.5rem auto 1rem auto;
  position: relative;
  width: 90%;
  box-shadow: inset 0 0 10px rgba(16, 185, 129, 0.1);
}

/* Simulate the decorative pattern of a physical mushaf header */
.surah-mushaf-header::before {
  content: '';
  position: absolute;
  top: 4px; left: 4px; right: 4px; bottom: 4px;
  border: 1px dashed var(--accent);
  border-radius: 4px;
  pointer-events: none;
}

.surah-mushaf-name {
  font-family: var(--font-arabic);
  font-size: 1.8em;
  font-weight: bold;
  color: var(--accent-text);
}

.bismillah-block {
  display: block;
  text-align: center;
  font-family: var(--font-arabic);
  font-size: 1.4em;
  margin-bottom: 0.5rem;
  color: var(--text-main);
  width: 100%;
}

.ayah-symbol {
  color: var(--accent);
  margin: 0 4px;
}

.mushaf-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 800px;
  margin-top: 2rem;
}

.zoom-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
  color: var(--text-muted);
}

.page-indicator {
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--text-muted);
}

.goto-input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 0.25rem 0.5rem;
  width: 60px;
  border-radius: 4px;
  text-align: center;
  margin: 0 0.5rem;
}

/* Shared UI Utilities */
.highlight {
  background-color: rgba(16, 185, 129, 0.2);
  color: var(--accent-text);
  border-radius: 2px;
  padding: 0 2px;
}

.loader-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 50vh;
  gap: 1rem;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.nav-button {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-lg);
  cursor: pointer;
  font-weight: 600;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-button:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.error-msg {
  color: #ef4444;
  background: #fee2e2;
  padding: 1rem;
  border-radius: var(--radius-md);
  text-align: center;
  font-weight: 500;
}

[data-theme="dark"] .error-msg {
  background: rgba(239, 68, 68, 0.1);
}

/* Animations */
.fade-in {
  animation: fadeIn 0.4s ease-out forwards;
}

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

@media (max-width: 768px) {
  .surah-grid {
    grid-template-columns: 1fr;
  }
  
  .header-content {
    flex-wrap: wrap;
    gap: 1rem;
  }
  
  .search-bar {
    order: 3;
    max-width: none;
    margin: 0;
    width: 100%;
  }

  .ayah-arabic {
    font-size: 1.75rem;
  }

  .mushaf-page {
    padding: 1.5rem;
    min-height: auto;
  }
  
  .mushaf-page-inner {
    padding: 1rem;
  }

  .mushaf-text {
    font-size: 22px !important; /* Force smaller base on mobile */
  }
}
