:root {
  --bg-deep: #0a1a1f;
  --bg-panel: #102830;
  --bg-panel-2: #16333d;
  --accent: #d4af37;
  --accent-soft: #f0d78c;
  --teal: #1f8a70;
  --teal-light: #2fb894;
  --text-main: #eef7f5;
  --text-dim: #9db3b0;
  --danger: #c0392b;
  --radius-lg: 22px;
  --radius-md: 14px;
  --shadow-soft: 0 8px 30px rgba(0, 0, 0, 0.35);
}

/* Generic utility: any element (not just the specific IDs below) can be
   hidden by toggling this class from JS. Keeping the more specific
   #id.hidden rules further down is harmless (same effect, higher
   specificity) but this generic rule ensures elements like #install-btn
   that only ever get toggled via classList are actually hidden by default. */
.hidden { display: none !important; }

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: radial-gradient(circle at 50% -10%, #1a3d40 0%, var(--bg-deep) 55%, #050d10 100%);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
}

.arabic-text {
  font-family: 'Amiri', serif;
  direction: rtl;
  display: block;
}

/* ---------- RTL support ---------- */
body.rtl {
  direction: rtl;
}
body.rtl .np-body,
body.rtl .np-body-left,
body.rtl .np-location,
body.rtl .np-header,
body.rtl .pt-header,
body.rtl .settings-label,
body.rtl .settings-header,
body.rtl #location-search-row,
body.rtl .option-item,
body.rtl #volume-row,
body.rtl .ft-controls,
body.rtl .fine-tune-row,
body.rtl .top-bar-actions {
  direction: rtl;
}
body.rtl #calc-method-select,
body.rtl #asr-method-select,
body.rtl #latitude-method-select,
body.rtl #audio-quality-select,
body.rtl #language-select {
  background-position: left 14px center;
  padding: 12px 14px 12px 38px;
}
body.rtl .arabic-text {
  direction: rtl;
}

/* ---------- Offline banner ---------- */
#offline-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(192, 57, 43, 0.85);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
  text-align: center;
}
#offline-banner.hidden { display: none; }

/* ---------- Top bar actions ---------- */
.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

#app-root {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Loading screen ---------- */
#loading-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-deep);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}
#loading-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.loading-inner {
  text-align: center;
  color: var(--accent-soft);
}
.loading-icon {
  font-size: 48px;
  margin-bottom: 14px;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.5; transform: scale(0.95); }
  50% { opacity: 1; transform: scale(1.05); }
}

/* ---------- Top bar ---------- */
#top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  color: var(--accent-soft);
  letter-spacing: 0.2px;
}
.brand i { font-size: 22px; }

.icon-btn {
  background: var(--bg-panel);
  border: 1px solid rgba(212, 175, 55, 0.25);
  color: var(--text-main);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  transition: background 0.2s, transform 0.15s;
}
.icon-btn:hover { background: var(--bg-panel-2); transform: translateY(-1px); }
.icon-btn:active { transform: scale(0.95); }

/* ---------- Main content ---------- */
#main-content {
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
  padding: 0 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  flex: 1;
}

section {
  background: linear-gradient(155deg, var(--bg-panel) 0%, var(--bg-panel-2) 100%);
  border: 1px solid rgba(212, 175, 55, 0.12);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}

/* ---------- Now playing card ---------- */
#now-playing-card {
  padding: 28px 24px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(31, 138, 112, 0.18);
  color: var(--teal-light);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 18px;
}
.status-pill.azan-mode {
  background: rgba(212, 175, 55, 0.2);
  color: var(--accent-soft);
}
.status-pill.paused-mode {
  background: rgba(255,255,255,0.08);
  color: var(--text-dim);
}

.reciter-portrait {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #2b5c56, #0c1f22);
  border: 2px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  color: var(--accent-soft);
  margin-bottom: 16px;
  box-shadow: 0 0 0 6px rgba(212,175,55,0.08);
}

#reciter-name {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 2px;
}
#reciter-name-ar {
  color: var(--text-dim);
  font-size: 16px;
  margin: 0 0 16px;
}

#surah-display {
  margin-bottom: 20px;
}
#surah-name {
  display: block;
  font-size: 15px;
  color: var(--text-dim);
  font-weight: 500;
}
#surah-name-ar {
  font-size: 20px;
  color: var(--accent-soft);
  margin-top: 2px;
}

#player-controls {
  display: flex;
  align-items: center;
  gap: 22px;
  margin-bottom: 18px;
}
.control-btn {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text-main);
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s;
}
.control-btn:hover { background: rgba(255,255,255,0.1); }
.control-btn-main {
  width: 64px;
  height: 64px;
  font-size: 22px;
  background: linear-gradient(145deg, var(--accent), #b8901f);
  color: #1a1305;
  border: none;
  box-shadow: 0 6px 20px rgba(212,175,55,0.35);
}
.control-btn-main:hover { transform: scale(1.04); }
.control-btn-main:active { transform: scale(0.97); }
.control-btn:disabled, .control-btn-main:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
}

#progress-wrap {
  width: 100%;
  margin-bottom: 14px;
}
input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 5px;
  border-radius: 3px;
  background: rgba(255,255,255,0.12);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 0 3px rgba(212,175,55,0.25);
}
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}
.time-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 6px;
}

#volume-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  color: var(--text-dim);
}
#volume-row input[type="range"] { flex: 1; }

/* ---------- Next prayer card ---------- */
#next-prayer-card {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.np-header {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}
.hijri-date {
  margin-left: auto;
  text-transform: none;
  font-weight: 500;
  letter-spacing: normal;
  font-size: 12px;
  color: var(--text-dim);
  opacity: 0.85;
}
body.rtl .hijri-date { margin-left: 0; margin-right: auto; }
.np-body {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.np-body-left {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
#next-prayer-name {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent-soft);
}
#next-prayer-clock {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
#next-prayer-countdown {
  font-size: 26px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text-main);
}
.np-location {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  font-size: 13px;
  padding-top: 8px;
  border-top: 1px solid rgba(255,255,255,0.07);
}

/* ---------- Prayer times card ---------- */
#prayer-times-card {
  padding: 20px 24px;
}
.pt-header {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  margin-bottom: 14px;
}
#prayer-times-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.prayer-time-item {
  background: rgba(255,255,255,0.04);
  border-radius: var(--radius-md);
  padding: 10px 8px;
  text-align: center;
}
.prayer-time-item.active-next {
  background: rgba(212,175,55,0.15);
  border: 1px solid rgba(212,175,55,0.4);
}
.prayer-time-item .pname {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.prayer-time-item .ptime {
  display: block;
  font-size: 15px;
  font-weight: 700;
}

/* ---------- Settings overlay ---------- */
#settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 12, 14, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 500;
  transition: opacity 0.25s ease;
}
#settings-overlay.hidden { display: none; }

#settings-panel {
  background: var(--bg-panel);
  border: 1px solid rgba(212,175,55,0.2);
  border-radius: 26px 26px 0 0;
  width: 100%;
  max-width: 640px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 22px 22px 28px;
  animation: slideUp 0.3s ease;
}
@media (min-width: 700px) {
  #settings-overlay { align-items: center; }
  #settings-panel { border-radius: var(--radius-lg); max-height: 82vh; }
}
@keyframes slideUp {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.settings-header h2 {
  font-size: 19px;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-section {
  margin-bottom: 22px;
}
.settings-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--accent-soft);
  margin-bottom: 10px;
}

#location-search-row {
  display: flex;
  gap: 10px;
}
#city-search-input {
  flex: 1;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--text-main);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
}
#city-search-input:focus { border-color: var(--accent); }

#city-results-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
  border-radius: var(--radius-md);
}
#city-results-list li {
  padding: 10px 14px;
  background: rgba(255,255,255,0.03);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
}
#city-results-list li:hover { background: rgba(212,175,55,0.12); }
#city-results-list li:first-child { border-radius: var(--radius-md) var(--radius-md) 0 0; }
#city-results-list li:last-child { border-radius: 0 0 var(--radius-md) var(--radius-md); border-bottom: none; }
#city-results-list .city-sub { color: var(--text-dim); font-size: 12px; }

#selected-city-box {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(31,138,112,0.15);
  color: var(--teal-light);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 14px;
}
#selected-city-box.hidden { display: none; }

#calc-method-select,
#asr-method-select,
#latitude-method-select,
#audio-quality-select,
#language-select {
  width: 100%;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--text-main);
  border-radius: var(--radius-md);
  padding: 12px 38px 12px 14px;
  font-size: 14.5px;
  outline: none;
  appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'><path d='M1 1l6 6 6-6' fill='none' stroke='%23d4af37' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
#calc-method-select:focus,
#asr-method-select:focus,
#latitude-method-select:focus,
#audio-quality-select:focus,
#language-select:focus { border-color: var(--accent); }
#calc-method-select option,
#asr-method-select option,
#latitude-method-select option,
#audio-quality-select option,
#language-select option { background: var(--bg-panel); color: var(--text-main); }

/* ---------- Fine-tune prayer times grid ---------- */
#fine-tune-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.fine-tune-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255,255,255,0.03);
  border-radius: var(--radius-md);
  padding: 10px 14px;
}
.ft-name {
  font-size: 14px;
  font-weight: 600;
}
.ft-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}
.ft-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid rgba(212,175,55,0.3);
  background: rgba(212,175,55,0.08);
  color: var(--accent-soft);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.ft-btn:hover { background: rgba(212,175,55,0.18); }
.ft-value {
  min-width: 34px;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-main);
}

.settings-hint {
  font-size: 12.5px;
  color: var(--text-dim);
  margin: 8px 2px 0;
  line-height: 1.5;
}

.option-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: rgba(255,255,255,0.03);
  border: 1px solid transparent;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.option-item:hover { background: rgba(255,255,255,0.06); }
.option-item.selected {
  border-color: var(--accent);
  background: rgba(212,175,55,0.12);
}
.option-item .oi-main {
  display: flex;
  flex-direction: column;
}
.option-item .oi-name { font-weight: 600; font-size: 14.5px; }
.option-item .oi-name-ar { font-size: 13px; color: var(--text-dim); }
.option-item .oi-check {
  color: var(--accent);
  font-size: 18px;
  opacity: 0;
  transition: opacity 0.15s;
}
.option-item.selected .oi-check { opacity: 1; }
.option-item .oi-preview-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 15px;
  cursor: pointer;
  padding: 6px;
}
.option-item .oi-preview-btn:hover { color: var(--accent-soft); }

#save-settings-btn {
  width: 100%;
  padding: 15px;
  border-radius: var(--radius-md);
  border: none;
  background: linear-gradient(145deg, var(--accent), #b8901f);
  color: #1a1305;
  font-size: 15.5px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 6px;
}
#save-settings-btn:hover { filter: brightness(1.05); }
#save-settings-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Azan overlay ---------- */
#azan-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(160deg, #1a3d40, #050d10);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 800;
}
#azan-overlay.hidden { display: none; }
#azan-panel {
  text-align: center;
  color: var(--accent-soft);
}
.azan-icon {
  font-size: 56px;
  margin-bottom: 18px;
  animation: pulse 2s ease-in-out infinite;
}
#azan-panel h2 { font-size: 26px; margin: 0 0 6px; }
#azan-panel p { color: var(--text-dim); margin: 0 0 22px; }

.azan-wave {
  display: flex;
  gap: 6px;
  justify-content: center;
  align-items: flex-end;
  height: 34px;
}
.azan-wave span {
  width: 6px;
  background: var(--accent);
  border-radius: 3px;
  animation: wave 1.1s ease-in-out infinite;
}
.azan-wave span:nth-child(1) { height: 12px; animation-delay: 0s; }
.azan-wave span:nth-child(2) { height: 24px; animation-delay: 0.1s; }
.azan-wave span:nth-child(3) { height: 34px; animation-delay: 0.2s; }
.azan-wave span:nth-child(4) { height: 20px; animation-delay: 0.3s; }
.azan-wave span:nth-child(5) { height: 14px; animation-delay: 0.4s; }
@keyframes wave {
  0%, 100% { transform: scaleY(0.4); }
  50% { transform: scaleY(1); }
}

#audio-player { display: none; }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: rgba(212,175,55,0.3); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 420px) {
  #prayer-times-list { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .reciter-portrait { width: 72px; height: 72px; font-size: 26px; }
}
