/* Sakinah — Modern Qur'an & Ambience UI */

:root {
  --bg: #f8f9fc;
  --bg-card: #ffffff;
  --bg-elevated: #ffffff;
  --text: #1a1d26;
  --text-secondary: #5c6370;
  --text-muted: #8b92a0;
  --accent: #0d9488;
  --accent-hover: #0f766e;
  --accent-muted: rgba(13, 148, 136, 0.12);
  --border: #e8eaef;
  --border-focus: #0d9488;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.08);
  --radius: 16px;
  --radius-md: 12px;
  --radius-sm: 10px;
  --radius-full: 9999px;
  --transition: 0.2s ease;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(13, 148, 136, 0.08), transparent);
  pointer-events: none;
  z-index: 0;
}

.app {
  max-width: 440px;
  margin: 0 auto;
  padding: 1rem;
  padding-top: max(1rem, env(safe-area-inset-top));
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
}

/* Header */
.header {
  text-align: center;
  margin-bottom: 2rem;
  padding-top: 0.5rem;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 100%;
}

.header-top .title {
  margin: 0;
}

.btn-theme {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  transition: color var(--transition), background var(--transition);
}

.btn-theme:hover {
  color: var(--accent);
  background: var(--accent-muted);
}

.btn-theme .icon-moon {
  display: none;
}

.dark .btn-theme .icon-sun {
  display: none;
}

.dark .btn-theme .icon-moon {
  display: block;
}

.title {
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.title-ar {
  font-family: 'Noto Naskh Arabic', serif;
  display: block;
  margin-bottom: 0.1em;
  color: var(--text);
}

.title-en {
  font-size: 0.55em;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.tagline {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  transition: box-shadow var(--transition);
}

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

.card-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.5rem;
}

.card-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

/* Selectors */
.selectors-card .selectors {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.select-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

.btn-selector {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.7rem 1rem;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.btn-selector:hover {
  border-color: var(--accent);
  background: var(--accent-muted);
}

.btn-selector .chevron {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--text-muted);
}

.selector-content {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  overflow: hidden;
}

.selector-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selector-star {
  flex-shrink: 0;
  display: none;
  color: var(--accent);
}

.selector-star.visible {
  display: flex;
}

.selector-star svg {
  width: 16px;
  height: 16px;
}

/* Sidebar */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition), visibility var(--transition);
  z-index: 100;
}

.sidebar-overlay.open {
  opacity: 1;
  visibility: visible;
}

.sidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(320px, 90vw);
  max-width: 100%;
  background: var(--bg-card);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
  transform: translateX(100%);
  transition: transform 0.3s ease;
  z-index: 101;
  display: flex;
  flex-direction: column;
}

.sidebar.open {
  transform: translateX(0);
}

.sidebar[aria-hidden="true"] {
  pointer-events: none;
}

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

.sidebar-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0;
}

.btn-close {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}

.btn-close:hover {
  color: var(--accent);
  background: var(--accent-muted);
}

.btn-close svg {
  width: 22px;
  height: 22px;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}

.sidebar-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-list li {
  margin: 0;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.85rem 1.5rem;
  font-family: inherit;
  font-size: 0.95rem;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition);
}

.sidebar-item:hover {
  background: var(--accent-muted);
}

.sidebar-item.selected {
  background: var(--accent-muted);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-item .surah-num {
  font-size: 0.85rem;
  color: var(--text-muted);
  min-width: 2ch;
  width: 2ch;
}

.sidebar-item.selected .surah-num {
  color: var(--accent);
}

.sidebar-item-row {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.sidebar-item-row .sidebar-item {
  flex: 1;
  min-width: 0;
}

.btn-star {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}

.btn-star:hover {
  color: var(--accent);
  background: var(--accent-muted);
}

.btn-star .star-icon {
  width: 20px;
  height: 20px;
}

.btn-star .star-filled {
  color: var(--accent);
}

.sidebar-section-header {
  padding: 0.6rem 1.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  list-style: none;
  margin-top: 0.5rem;
}

.sidebar-section-header:first-child {
  margin-top: 0;
}

/* Player card */
.player-card {
  padding: 1.75rem;
}

.recitation-info {
  text-align: center;
  margin-bottom: 1.5rem;
}

.surah-name {
  font-family: 'Noto Naskh Arabic', serif;
  font-size: 1.6rem;
  font-weight: 600;
  display: block;
  color: var(--text);
}

.reciter-name {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

/* Controls */
.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  transition: color var(--transition), background var(--transition), transform var(--transition);
}

.btn:active {
  transform: scale(0.96);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-nav {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
}

.btn-nav:hover {
  color: var(--accent);
  background: var(--accent-muted);
}

.btn-nav svg {
  width: 24px;
  height: 24px;
}

.btn-play {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
  color: white;
  border-radius: 50%;
  box-shadow: 0 4px 16px rgba(13, 148, 136, 0.35);
}

.btn-play:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(13, 148, 136, 0.4);
}

.btn-play:active {
  transform: scale(0.98);
}

.btn-play svg {
  width: 28px;
  height: 28px;
}

.icon-pause {
  display: none;
}

.playing .icon-play {
  display: none;
}

.playing .icon-pause {
  display: block;
}

/* Progress */
.progress-container {
  margin-bottom: 1rem;
}

.progress {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: var(--radius-full);
  margin-bottom: 0.4rem;
}

.progress::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  min-width: 20px;
  min-height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition: transform var(--transition);
  box-shadow: 0 2px 6px rgba(13, 148, 136, 0.3);
}

.progress::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.progress::-moz-range-thumb {
  width: 20px;
  height: 20px;
  min-width: 20px;
  min-height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
  box-shadow: 0 2px 6px rgba(13, 148, 136, 0.3);
}

.time-display {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}

/* Toolbar */
.player-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.toolbar-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toolbar-item .volume {
  width: 80px;
}

.toolbar-icon {
  font-size: 1rem;
  opacity: 0.7;
}

.toolbar-item select {
  padding: 0.45rem 0.75rem;
  font-family: inherit;
  font-size: 1rem; /* 16px avoids iOS zoom on focus */
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

.toolbar-item select:focus {
  outline: none;
  border-color: var(--border-focus);
}

.btn-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.85rem;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-chip:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

.btn-chip[aria-pressed="true"] {
  background: var(--accent-muted);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-chip svg {
  width: 16px;
  height: 16px;
}

.sleep-timer {
  margin-left: auto;
}

.sleep-countdown {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Volume sliders */
.volume {
  height: 5px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: var(--radius-full);
}

.volume::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  min-width: 18px;
  min-height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition: transform var(--transition);
}

.volume::-webkit-slider-thumb:hover {
  transform: scale(1.1);
}

.volume::-moz-range-thumb {
  width: 18px;
  height: 18px;
  min-width: 18px;
  min-height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
}

/* Footer */
.footer {
  margin-top: auto;
  padding-top: 2rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.footer a:hover {
  text-decoration: underline;
}

/* Dark mode */
.dark body::before {
  background: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(45, 212, 191, 0.06), transparent);
}

.dark {
  --bg: #0f1116;
  --bg-card: #181b22;
  --bg-elevated: #1e222a;
  --text: #f0f2f5;
  --text-secondary: #b4b9c4;
  --text-muted: #7a8190;
  --accent: #2dd4bf;
  --accent-hover: #5eead4;
  --accent-muted: rgba(45, 212, 191, 0.15);
  --border: #2a2e38;
  --border-focus: #2dd4bf;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.35);
}

/* Mobile-friendly layout */
@media (max-width: 480px) {
  .app {
    padding: 0.75rem;
    padding-top: max(0.75rem, env(safe-area-inset-top));
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  }

  .header {
    margin-bottom: 1.25rem;
  }

  .title {
    font-size: 1.65rem;
  }

  .tagline {
    font-size: 0.85rem;
  }

  /* Stack selectors vertically on narrow screens */
  .selectors-card .selectors {
    grid-template-columns: 1fr;
    gap: 0.6rem;
  }

  .btn-selector {
    padding: 0.85rem 1rem;
    font-size: 1rem;
  }

  /* Sidebar full-width on small screens */
  .sidebar {
    width: 100%;
    max-width: 100%;
  }

  .sidebar-header {
    padding: 1rem 1.25rem;
  }

  .sidebar-item {
    padding: 1rem 1.25rem;
    font-size: 1rem;
  }

  .sidebar-section-header {
    padding: 0.5rem 1.25rem;
  }

  /* Player card */
  .player-card {
    padding: 1.25rem;
  }

  .surah-name {
    font-size: 1.4rem;
  }

  .reciter-name {
    font-size: 0.85rem;
  }

  .controls {
    gap: 0.75rem;
    margin-bottom: 1rem;
  }

  .btn-nav {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
  }

  .btn-play {
    width: 60px;
    height: 60px;
    min-width: 60px;
    min-height: 60px;
  }

  /* Toolbar: wrap and stack on mobile */
  .player-toolbar {
    gap: 0.75rem;
    padding-top: 0.75rem;
  }

  .toolbar-item {
    min-height: 44px;
  }

  .toolbar-item .volume {
    width: 70px;
  }

  .btn-chip {
    padding: 0.5rem 0.9rem;
    font-size: 0.9rem;
    min-height: 44px;
  }

  .sleep-timer {
    margin-left: 0;
    width: 100%;
    margin-top: 0.25rem;
  }

  .sleep-timer .toolbar-item {
    width: 100%;
    justify-content: space-between;
  }

  .sleep-timer select {
    flex: 1;
    max-width: 140px;
  }

  .card {
    padding: 1.25rem;
    margin-bottom: 0.85rem;
  }

  .footer {
    padding-top: 1.5rem;
    font-size: 0.75rem;
  }
}

