:root {
  --bg: #0b1f1a;
  --bg-elevated: #102b23;
  --card: #123329;
  --card-border: #1e4438;
  --accent: #e6be6e;
  --accent-soft: #f0d9a3;
  --green: #1a7a54;
  --green-bright: #22a06b;
  --text: #f2f5f3;
  --text-dim: #a9c2b8;
  --text-faint: #6f8c81;
  --danger: #e08585;
  --success: #ffd76a;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% 0%, rgba(34, 160, 107, 0.25), transparent 45%),
    radial-gradient(circle at 90% 15%, rgba(230, 190, 110, 0.10), transparent 40%),
    var(--bg);
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: calc(24px + var(--safe-bottom));
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(16px + var(--safe-top)) 20px 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
}

.brand-icon {
  width: 52px;
  height: 52px;
  border-radius: 13px;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.35);
}

.brand-text {
  display: flex;
  flex-direction: column;
  justify-content: center;
  line-height: 1.05;
}

.brand-name {
  font-family: "GFS Didot", Georgia, "Times New Roman", serif;
  font-size: 1.82rem;
  letter-spacing: 3.25px;
  color: var(--accent-soft);
  text-transform: uppercase;
}

.brand-tagline {
  font-family: "Montserrat", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 0.47rem;
  font-weight: 500;
  letter-spacing: 0.4px;
  color: var(--accent);
  text-transform: uppercase;
  margin-top: 3px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 12px;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn:active { transform: scale(0.95); }

#qiblaBtn {
  background: linear-gradient(160deg, #cbb27e 0%, #a98c56 100%);
  border-color: rgba(230, 190, 110, 0.6);
  box-shadow: inset 0 0 0 1px rgba(255, 245, 220, 0.25);
}

#settingsBtn { font-size: 1.4rem; }

main {
  padding: 8px 20px 20px;
}

.location-bar {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 14px;
  font-size: 0.95rem;
  margin-top: 8px;
  cursor: pointer;
  text-align: left;
}
.location-bar .pin { color: var(--accent); flex-shrink: 0; display: flex; }
.location-bar .pin svg { width: 18px; height: 18px; display: block; }
.location-bar #locationLabel,
.location-bar #dateLabel {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-dim);
}
.location-bar .chevron { color: var(--text-faint); font-size: 1.2rem; }

.date-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.date-field-wrap {
  position: relative;
  flex: 1;
}
.date-field-wrap .location-bar {
  pointer-events: none; /* purely decorative — the real <input> on top handles taps */
}
.date-reset-btn {
  margin-top: 8px;
  white-space: nowrap;
  color: var(--accent-soft);
  font-weight: 600;
}
/* The actual native date input sits invisibly on top of the styled bar, at
   full size, so tapping anywhere on the bar taps the real control directly —
   far more reliable across mobile browsers than triggering it from JS
   (Mobile Safari in particular can silently refuse a JS-triggered picker). */
.date-input-overlay {
  position: absolute;
  inset: 0;
  margin-top: 8px;
  width: 100%;
  height: calc(100% - 8px);
  opacity: 0;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.hero-card.static-mode .hero-mid { display: none; }

/* ---------- View over time ---------- */
.trend-link {
  display: block;
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 0.78rem;
  padding: 8px 4px 0;
  margin: 0;
  cursor: pointer;
  text-align: left;
  text-decoration: underline;
  text-decoration-color: transparent;
  transition: color 0.15s ease;
}
.trend-link:hover, .trend-link:active {
  color: var(--accent-soft);
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 6px 0 4px;
}
.pill {
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text-dim);
  padding: 8px 13px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.pill.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #241d0c;
}

.trend-custom-range {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}
.trend-custom-range[hidden] { display: none; }
#trendPrayerField[hidden] { display: none; }
.trend-date-field { flex: 1; margin: 8px 0; }

.trend-chart-wrap {
  margin-top: 18px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 14px 10px 10px;
}
.trend-chart-wrap svg { display: block; width: 100%; height: auto; }

.trend-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  justify-content: center;
  margin-bottom: 10px;
  font-size: 0.78rem;
}
.trend-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
}
.trend-legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.trend-summary {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin: 2px 0 12px;
}
.trend-summary b { color: var(--accent-soft); }

.hero-card {
  margin-top: 18px;
  background: linear-gradient(160deg, var(--green) 0%, #0e5b3d 60%, #0a4530 100%);
  border-radius: 24px;
  padding: 22px 20px 26px;
  box-shadow: 0 12px 30px -12px rgba(0, 0, 0, 0.5);
  position: relative;
  overflow: hidden;
}
.hero-card::after {
  content: "";
  position: absolute;
  right: -40px;
  top: -40px;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(230,190,110,0.25), transparent 70%);
}

.hero-top {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: rgba(255,255,255,0.75);
}

.hero-mid {
  text-align: center;
  margin-top: 18px;
}

.next-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: rgba(255,255,255,0.65);
}

.next-name {
  font-size: 1.8rem;
  font-weight: 700;
  color: #fff;
  margin-top: 4px;
}
.next-name-ar {
  display: inline-block;
  margin-left: 10px;
  font-size: 0.62em;
  font-weight: 400;
  color: rgba(255,255,255,0.55);
  vertical-align: middle;
}

.countdown {
  font-size: 2.6rem;
  font-weight: 700;
  color: var(--accent-soft);
  margin-top: 10px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
}

.next-time {
  margin-top: 6px;
  font-size: 0.9rem;
  color: rgba(255,255,255,0.75);
}

.prayer-list {
  margin-top: 18px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  overflow: hidden;
}

.prayer-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--card-border);
}
.prayer-row:last-child { border-bottom: none; }

.prayer-row .p-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: rgba(230,190,110,0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
}
.prayer-row .p-icon svg {
  width: 20px;
  height: 20px;
  display: block;
}

.prayer-row .p-name {
  flex: 1;
  font-size: 1rem;
  color: var(--text);
}
.prayer-row .p-name-ar {
  display: inline-block;
  margin-left: 8px;
  font-size: 0.85em;
  color: var(--text-faint);
  font-weight: 400;
}

.prayer-row .p-sub {
  display: block;
  font-size: 0.72rem;
  color: var(--text-faint);
  margin-top: 1px;
}

.prayer-row .p-time {
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
}

.prayer-row.is-next {
  background: rgba(34, 160, 107, 0.12);
}
.prayer-row.is-next .p-icon {
  background: var(--accent);
  color: #10281f;
}
.prayer-row.is-next .p-name,
.prayer-row.is-next .p-time {
  color: var(--accent-soft);
  font-weight: 700;
}

.prayer-row.is-passed .p-name,
.prayer-row.is-passed .p-time {
  color: var(--text-faint);
}

.note {
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(230,190,110,0.10);
  color: var(--accent-soft);
  font-size: 0.85rem;
}
.note-error {
  background: rgba(224,133,133,0.12);
  color: var(--danger);
}

.skeleton { display: none; padding-top: 10px; }
.skeleton.show { display: block; }
.skel-line {
  height: 14px;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--card) 25%, var(--card-border) 37%, var(--card) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  margin: 10px 0;
}
.skel-card {
  height: 170px;
  border-radius: 24px;
  background: linear-gradient(90deg, var(--card) 25%, var(--card-border) 37%, var(--card) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  margin: 18px 0;
}
@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.install-banner {
  position: sticky;
  bottom: 0;
  margin: 12px 20px calc(12px + var(--safe-bottom));
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.install-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.install-banner[hidden] { display: none; }

.btn {
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--green-bright);
  color: #06140f;
}
.btn-small { padding: 8px 12px; font-size: 0.82rem; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--card-border);
  color: var(--text);
}
.btn-full { width: 100%; margin-top: 6px; }
.btn-text {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 0.82rem;
  cursor: pointer;
  padding: 6px;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: flex-end;
  z-index: 50;
}
.modal[hidden] {
  display: none;
}
.modal-sheet {
  background: var(--bg-elevated);
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  border-radius: 22px 22px 0 0;
  padding: 18px 20px calc(24px + var(--safe-bottom));
  max-height: 86vh;
  overflow-y: auto;
  border-top: 1px solid var(--card-border);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.modal-header h2 { margin: 0; font-size: 1.2rem; }

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-faint);
  font-size: 0.78rem;
  margin: 16px 0 12px;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--card-border);
}

.search-input {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 1rem;
}
.search-input:focus { outline: 2px solid var(--green-bright); }

.search-status {
  font-size: 0.82rem;
  color: var(--text-faint);
  min-height: 1.2em;
  margin-top: 8px;
}

.search-results {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
}
.search-results li {
  padding: 12px 10px;
  border-bottom: 1px solid var(--card-border);
  cursor: pointer;
  display: flex;
  flex-direction: column;
}
.search-results li:active { background: var(--card); }
.result-name { font-size: 0.98rem; color: var(--text); }
.result-sub { font-size: 0.78rem; color: var(--text-faint); margin-top: 2px; }

.field {
  display: block;
  margin: 16px 0;
}
.field-label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.field select {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text);
  padding: 11px 12px;
  border-radius: 12px;
  font-size: 0.95rem;
}
.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.field-row .field-label { margin-bottom: 0; }

.toggle {
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: var(--card-border);
  border: none;
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
}
.toggle .toggle-dot {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: left 0.15s ease, background 0.15s ease;
}
.toggle[aria-pressed="true"] { background: var(--green-bright); }
.toggle[aria-pressed="true"] .toggle-dot {
  left: 23px;
  background: #06140f;
}

.hint {
  font-size: 0.78rem;
  color: var(--text-faint);
  margin: 6px 0 0;
  line-height: 1.4;
}
.about-hint {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--card-border);
}

/* Qibla compass */
.qibla-location {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.88rem;
  margin: 4px 0 18px;
}

.compass-wrap {
  position: relative;
  width: min(280px, 78vw);
  height: min(280px, 78vw);
  margin: 0 auto;
}

.compass-rose {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, #163f33, #0c241d 75%);
  border: 1px solid var(--card-border);
  box-shadow: inset 0 0 30px rgba(0,0,0,0.4);
  transition: transform 0.05s linear, border-color 0.2s ease, box-shadow 0.2s ease;
}

.compass-wrap.is-aligned .compass-rose {
  border-color: var(--success);
  box-shadow: inset 0 0 30px rgba(0,0,0,0.4), 0 0 22px 2px rgba(255, 215, 106, 0.55);
}

.compass-wrap.is-aligned .qibla-marker .kaaba-icon {
  transform: translateX(-50%) scale(1.25);
  filter: drop-shadow(0 0 8px rgba(255, 215, 106, 0.9));
}

.compass-wrap.is-aligned .compass-fixed-pointer {
  color: var(--success);
  transform: translateX(-50%) scale(1.3);
}

.compass-tick {
  position: absolute;
  color: var(--text-faint);
  font-size: 0.78rem;
  font-weight: 700;
}
.compass-tick.n { top: 8px; left: 50%; transform: translateX(-50%); color: var(--accent-soft); }
.compass-tick.e { right: 10px; top: 50%; transform: translateY(-50%); }
.compass-tick.s { bottom: 8px; left: 50%; transform: translateX(-50%); }
.compass-tick.w { left: 10px; top: 50%; transform: translateY(-50%); }

.qibla-marker {
  position: absolute;
  inset: 0;
  transform-origin: 50% 50%;
  /* rotated via inline style: rotate(bearingDeg) — the icon inside sits near
     the top edge, so rotating this whole box sweeps it around the dial. */
}
.qibla-marker .kaaba-icon {
  position: absolute;
  top: 10px;
  left: 50%;
  font-size: 1.6rem;
  transform: translateX(-50%);
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
  transition: transform 0.2s ease, filter 0.2s ease;
  z-index: 1;
}

/* Glowing spoke from the Kaaba icon to the dial's centre, so the bearing
   reads as a line at a glance rather than just an icon floating on the rim.
   Lives inside #qiblaMarker, so it rotates as one rigid piece with the icon
   — always pointing correctly regardless of live heading. */
.qibla-marker .qibla-line {
  position: absolute;
  top: 27px;
  bottom: 50%;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
  background: linear-gradient(to bottom, rgba(230, 190, 110, 0.15), var(--accent-soft) 70%, var(--accent-soft));
  border-radius: 2px;
  box-shadow: 0 0 6px 1px rgba(240, 217, 163, 0.85), 0 0 16px 3px rgba(230, 190, 110, 0.5);
  animation: qiblaLineGlow 2.4s ease-in-out infinite;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.compass-wrap.is-aligned .qibla-line {
  background: linear-gradient(to bottom, rgba(255, 215, 106, 0.2), var(--success) 70%, var(--success));
  box-shadow: 0 0 8px 2px rgba(255, 215, 106, 0.95), 0 0 20px 5px rgba(255, 215, 106, 0.6);
}

@keyframes qiblaLineGlow {
  0%, 100% { opacity: 0.8; }
  50% { opacity: 1; }
}

.compass-fixed-pointer {
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--accent);
  font-size: 1.1rem;
  z-index: 2;
  transition: color 0.2s ease, transform 0.2s ease;
}

.compass-center-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  transform: translate(-50%, -50%);
}

.qibla-bearing {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent-soft);
  margin: 18px 0 6px;
}

.qibla-aligned-label {
  text-align: center;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--success);
  margin: 0 0 6px;
  animation: qibla-pop 0.25s ease;
}

@keyframes qibla-pop {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@media (min-width: 520px) {
  #app { padding-top: 12px; }
}
