/* ── Fonts — self-hosted latin subsets of Google's variable Noto woff2 (assets/css/fonts/).
   One file per family covers every weight; no Arabic glyphs are rendered, so the
   arabic/math/symbols subsets are not shipped. Preloaded from index.php. ── */
@font-face {
  font-family: 'Noto Sans Arabic';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url('fonts/noto-sans-arabic-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Noto Naskh Arabic';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/noto-naskh-arabic-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ── Design tokens ─────────────────────────────────────── */
:root {
  --bg-start:      #1a4731;
  --bg-end:        #2d6a4f;
  --bg-card:       rgba(0, 0, 0, 0.22);
  --gold:          #ffd700;
  --gold-dim:      rgba(255, 215, 0, 0.45);
  --gold-faint:    rgba(255, 215, 0, 0.12);
  --surface:       rgba(0, 0, 0, 0.22);
  --border:        rgba(255, 215, 0, 0.22);
  --text:          #ffffff;
  --text-muted:    rgba(255, 255, 255, 0.55);
  --text-dim:      rgba(255, 255, 255, 0.30);
  --radius:        12px;
  --radius-sm:     8px;
  --radius-lg:     16px;
  --font-body:     'Noto Sans Arabic', system-ui, -apple-system, sans-serif;
  --font-display:  'Noto Naskh Arabic', 'Noto Sans Arabic', serif;
  --transition:    150ms ease;
  --ease-out:      cubic-bezier(0.16, 1, 0.3, 1);   /* confident deceleration for arrivals */
  --amber:         #ffb84d;                         /* "azan soon" — warmer than --gold */
  --z-modal:       200;
  --z-tabbar:      100;
  --z-content:     1;
}

/* ── Reset & base ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Author display values (e.g. display:flex) silently defeat the UA's
   [hidden] rule — restore the attribute's meaning */
[hidden] { display: none !important; }

html { font-size: 16px; }

body {
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.6;
  background: linear-gradient(160deg, var(--bg-start) 0%, var(--bg-end) 100%);
  min-height: 100vh;
  min-height: 100dvh; /* mobile Chrome: 100vh is the large viewport, leaving window scroll slack that scrollIntoView eats — tab bar drifts up */
  color: var(--text);
  position: relative;
  overflow-x: hidden;
  overscroll-behavior: contain;
}

/* Focus ring — visible on keyboard nav */
:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Respect prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Geometric circle decorations */
body::before, body::after {
  content: '';
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
}
body::before {
  width: 320px; height: 320px;
  top: -100px; right: -100px;
  border: 1px solid rgba(255, 215, 0, 0.08);
  box-shadow: 0 0 0 50px rgba(255, 215, 0, 0.03);
}
body::after {
  width: 240px; height: 240px;
  bottom: -80px; left: -80px;
  border: 1px solid rgba(255, 215, 0, 0.05);
  box-shadow: 0 0 0 30px rgba(255, 215, 0, 0.02);
}

/* ── App shell ─────────────────────────────────────────── */
#app {
  position: relative;
  z-index: var(--z-content);
  max-width: 480px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;              /* dynamic viewport — accounts for mobile address bar */
  height: var(--vh, 100dvh);   /* app.js measures it: standalone Chrome pops an origin strip
                                  for the GPS permission prompt, and dvh can lag one layout
                                  behind the resize, leaving slack that drops the tab bar */
  display: flex;
  flex-direction: column;
}

/* Scrollable content area between header and tab bar */
.content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Thin themed scrollbars on inner scroll areas */
.content,
.cal-table-wrap,
.modal {
  scrollbar-width: thin;
  scrollbar-color: var(--gold-dim) transparent;
}
.content::-webkit-scrollbar,
.cal-table-wrap::-webkit-scrollbar,
.modal::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.content::-webkit-scrollbar-track,
.cal-table-wrap::-webkit-scrollbar-track,
.modal::-webkit-scrollbar-track {
  background: transparent;
}
.content::-webkit-scrollbar-thumb,
.cal-table-wrap::-webkit-scrollbar-thumb,
.modal::-webkit-scrollbar-thumb {
  background: var(--gold-dim);
  border-radius: 3px;
}
.content::-webkit-scrollbar-thumb:hover,
.cal-table-wrap::-webkit-scrollbar-thumb:hover,
.modal::-webkit-scrollbar-thumb:hover {
  background: var(--gold);
}

/* ── Header ────────────────────────────────────────────── */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px 16px;
  /* viewport-fit=cover: standalone on Android/iOS draws under the status bar */
  padding-top: calc(18px + env(safe-area-inset-top));
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.header-brand {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--gold);
}
.header-sub {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
  letter-spacing: 0.5px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

/* Shown by app.js while navigator.onLine is false — cached data is on screen */
.offline-bar {
  background: #b8860b;
  color: #111;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  padding: 6px 12px;
  letter-spacing: 0.3px;
  transition: opacity 200ms ease, transform 200ms var(--ease-out);
}
@starting-style {
  .offline-bar:not([hidden]) { opacity: 0; transform: translateY(-6px); }
}

.gps-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--gold);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.gps-btn:hover { background: rgba(0,0,0,0.38); border-color: var(--gold-dim); }
@keyframes gpsSpin { to { transform: rotate(360deg); } }
.zone-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 8px 14px;
  min-height: 44px;
  font-size: 11px;
  font-family: var(--font-body);
  color: var(--gold);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  white-space: nowrap;
  min-width: 0;
  max-width: 200px;
  overflow: hidden;
}
.zone-pill:hover { background: rgba(0,0,0,0.38); border-color: var(--gold-dim); }
.zone-pill svg { flex-shrink: 0; }
#zonePillText {
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

/* ── Tab bar ────────────────────────────────────────────── */
.tab-bar {
  position: relative;
  display: flex;
  width: 100%;
  flex-shrink: 0;
  background: rgba(12, 30, 18, 0.97);
  border-top: 1px solid rgba(255, 215, 0, 0.12);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
/* One indicator that slides between the four tabs — continuity instead of a jumping border */
.tab-bar::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 0;
  width: calc(100% / 4);
  height: 2px;
  background: var(--gold);
  transition: transform 300ms var(--ease-out);
}
.tab-bar[data-active="calendar"]::before { transform: translateX(100%); }
.tab-bar[data-active="qibla"]::before    { transform: translateX(200%); }
.tab-bar[data-active="settings"]::before { transform: translateX(300%); }
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 0 8px;
  min-height: 56px;
  border: none;
  background: none;
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: 11px;
  letter-spacing: 0.8px;
  font-weight: 500;
  cursor: pointer;
  border-top: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
}
.tab-btn svg { transition: opacity var(--transition); opacity: 0.4; }
.tab-btn.active { color: var(--gold); }
.tab-btn.active svg { opacity: 1; }
.tab-btn:hover:not(.active) { color: var(--text-muted); }
.tab-btn:hover:not(.active) svg { opacity: 0.65; }
.tab-bar { padding-bottom: env(safe-area-inset-bottom); }

/* ── Tab panels ─────────────────────────────────────────── */
.tab-panel { display: none; flex: 1; padding: 0 0 8px; }
.tab-panel.active { display: block; animation: panelIn 180ms var(--ease-out); }
@keyframes panelIn { from { opacity: 0; transform: translateY(4px); } }

/* ── Today tab ──────────────────────────────────────────── */
.hijri-bar {
  text-align: center;
  padding: 16px 20px 0;
  font-size: 12px;
  letter-spacing: 1.5px;
  color: var(--gold);
  text-transform: uppercase;
  font-family: var(--font-body);
}

.next-prayer-card {
  position: relative;
  margin: 14px 16px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 20px 18px;
  text-align: center;
  backdrop-filter: blur(4px);
  transition: border-color 300ms ease, box-shadow 300ms ease;
}
/* ≤10 minutes to go — warm the card, no loop */
.next-prayer-card.soon { border-color: var(--gold-dim); box-shadow: 0 8px 32px rgba(255, 184, 77, 0.12); }
.next-prayer-card.soon .next-timer { color: var(--amber); }
/* Azan moment — one gold ring radiates outward, the new name rises in. Runs once per prayer. */
.next-prayer-card.azan::after {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  border: 2px solid var(--gold);
  pointer-events: none;
  animation: azanRing 800ms var(--ease-out) forwards;
}
@keyframes azanRing { from { opacity: 1; transform: scale(1); } to { opacity: 0; transform: scale(1.12); } }
.next-prayer-card.azan .next-name { animation: nameIn 500ms var(--ease-out); }
@keyframes nameIn { from { opacity: 0; transform: translateY(6px); } }
/* ── Current-prayer strip (dual home layout, opt-in in TETAPAN) ────────────
   One flex row above the focal card: eyebrow, name, time, and how long ago
   the period began. A size and a border step quieter than #nextCard so the
   countdown stays the focal point. */
.now-prayer-card {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 16px 0;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--gold-faint);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(4px);
}
.now-label {
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--gold);
  text-transform: uppercase;
}
.now-name {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.now-time {
  font-size: 15px;
  font-weight: 600;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}
.now-ago {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
}
/* The prayer that just arrived becomes the current one — rise it in with the
   same motion the focal card uses, so both cards move together. */
.now-prayer-card.azan .now-name { animation: nameIn 500ms var(--ease-out); }

/* Dual mode pays for the strip out of the focal card's breathing room, never the
   grid's legibility. Every rule is scoped to .dual — with the toggle off, none match. */
#tab-today.dual .next-prayer-card  { padding: 14px 20px 12px; }
#tab-today.dual .next-timer        { font-size: 34px; }
#tab-today.dual .next-lagi         { margin: 4px 0 0; }
#tab-today.dual .prayer-grid-label { margin-bottom: 6px; }
/* Only the smallest phones need the grid trimmed too — 360x640 has 35px to spare and the
   strip costs 58px. Wider portrait tiers and landscape already fit without it. */
@media (max-width: 430px) {
  #tab-today.dual .next-timer  { font-size: 30px; }
  #tab-today.dual .prayer-cell { padding: 8px 4px; }
}

.next-label {
  font-size: 11px;
  letter-spacing: 3px;
  color: var(--gold);
  text-transform: uppercase;
  margin-bottom: 8px;
}
.next-name-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
}
.next-name {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--text);
}
.next-pada {
  font-size: 20px;
  font-weight: 400;
  color: var(--text-muted);
}
.next-time {
  font-size: 20px;
  font-weight: 600;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}
.next-lagi {
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--text-muted);
  margin: 8px 0 2px;
}
.next-timer {
  font-family: var(--font-body);
  font-size: 42px;
  font-weight: 700;
  letter-spacing: 4px;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  transition: color 300ms ease;
}

.progress-bar-wrap {
  margin-top: 16px;
  height: 4px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  overflow: hidden;
}
.progress-bar-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--gold), rgba(255,215,0,0.5));
  border-radius: 2px;
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 1s linear;   /* transform, not width — no layout per tick */
}
.progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 5px;
}

.prayer-grid-label {
  font-size: 11px;
  letter-spacing: 1.5px;
  color: var(--gold);
  text-transform: uppercase;
  padding: 0 16px;
  margin-bottom: 8px;
}
.prayer-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 0 16px 14px;
}
.prayer-cell {
  position: relative;
  text-align: center;
  padding: 10px 4px;
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  transition: background var(--transition), border-color var(--transition), opacity 300ms ease;
  animation: cellIn 240ms var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 30ms);   /* 8 cells → 240ms total, capped by count */
}
@keyframes cellIn { from { opacity: 0; transform: translateY(6px); } }
.prayer-cell.active {
  background: var(--gold-faint);
  border-color: var(--gold-dim);
}
.prayer-cell.past { opacity: 0.40; }
.prayer-cell .pname {
  font-size: 12px;
  color: var(--gold-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.prayer-cell.active .pname { color: var(--gold); }
.prayer-cell .ptime {
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.prayer-cell.active .ptime { color: var(--gold); font-weight: 700; }
/* "Now" — ±10 min around a prayer time (NOW_WINDOW in countdown.js). A gold ring breathes on an overlay
   so the cell's own box never changes: no transform, no size, and the 3px glow stays inside the 6px grid gap. */
.prayer-cell.now { opacity: 1; }                                   /* after .past: the 10 min after azan is not "past" yet */
.prayer-cell.now .pname, .prayer-cell.now .ptime { color: var(--gold); }
.prayer-cell.now::after {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  border: 1px solid var(--gold);
  pointer-events: none;
  animation: nowBreathe 2s ease-in-out infinite;
}
@keyframes nowBreathe {
  0%, 100% { opacity: 0.3; box-shadow: 0 0 0 0   rgba(255, 215, 0, 0); }
  50%      { opacity: 1;   box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.14); }
}
@media (prefers-reduced-motion: reduce) {
  .prayer-cell.now::after { animation: none; opacity: 1; box-shadow: none; }   /* steady ring, same meaning, no loop */
}

/* ── Notification toggle (settings tab) ─────────────────── */
.toggle {
  width: 44px;
  height: 26px;
  background: rgba(255,255,255,0.15);
  border-radius: 13px;
  position: relative;
  cursor: pointer;
  transition: background 0.25s ease;
  border: none;
  flex-shrink: 0;
  min-width: 44px;
}
.toggle.on { background: var(--gold); }
.toggle::after {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  top: 4px; left: 4px;
  transition: transform 0.25s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.toggle.on::after { transform: translateX(18px); }

/* ── Calendar tab ───────────────────────────────────────── */
.cal-header {
  position: sticky;            /* stays visible while scrollIntoView centres today's row */
  top: 0;
  z-index: 2;
  padding: 16px 20px 12px;
  background: rgba(26, 71, 49, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.cal-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.5px;
}
.cal-sub { font-size: 12px; color: var(--text-muted); margin-top: 3px; }

.cal-table-wrap {
  overflow-x: auto;
  padding: 12px 16px;
  -webkit-overflow-scrolling: touch;
}
.cal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  min-width: 340px;
  font-variant-numeric: tabular-nums;
}
.cal-table th {
  padding: 8px 5px;
  text-align: center;
  color: rgba(255, 215, 0, 0.72); /* section-title tier — --gold-dim measured ~2.7:1 on this surface, under WCAG for 11px */
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-weight: 600;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.cal-table th:first-child { text-align: left; }
.cal-table td {
  padding: 7px 5px;
  text-align: center;
  color: var(--text-muted);
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.cal-table tbody tr { animation: rowIn 150ms var(--ease-out) both; }   /* month swap: rows fade in, no stagger */
@keyframes rowIn { from { opacity: 0; } }
.cal-table td:first-child {
  text-align: left;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
}
.cal-table tr.today td { color: var(--text); }
.cal-table tr.today td:first-child {
  color: var(--gold);
  font-weight: 700;
  border-left: 2px solid var(--gold);
  padding-left: 7px;
}
.cal-table tr.today { background: var(--gold-faint); }
.cal-table tr.past  { opacity: 0.38; }

.cal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 6px 16px 16px;
}
.print-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  min-height: 44px;
  background: var(--gold-faint);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--gold);
  font-size: 12px;
  font-family: var(--font-body);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}
.print-btn:hover { background: rgba(255,215,0,0.2); }

.cal-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}
.cal-nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--gold);
  cursor: pointer;
  transition: background var(--transition);
}
.cal-nav-btn:hover:not(:disabled) { background: rgba(255,215,0,0.15); }
.cal-nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ── Qibla tab ──────────────────────────────────────────── */
.qibla-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 36px 20px 24px;
  gap: 18px;
}
.compass {
  width: 190px; height: 190px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  position: relative;
  box-shadow:
    0 0 0 8px rgba(255,215,0,0.04),
    0 0 0 16px rgba(255,215,0,0.02);
}
.compass-ring {
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  border: 1px solid rgba(255,215,0,0.1);
}
.compass-label {
  position: absolute;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 700;
  letter-spacing: 0.5px;
}
.compass-label.n { top: 8px;   left: 50%; transform: translateX(-50%); }
.compass-label.s { bottom: 8px; left: 50%; transform: translateX(-50%); }
.compass-label.e { right: 10px; top: 50%; transform: translateY(-50%); }
.compass-label.w { left: 10px;  top: 50%; transform: translateY(-50%); }
.compass-needle {
  position: absolute;
  width: 3px;
  height: 78px;
  background: linear-gradient(to bottom, var(--gold) 0%, var(--gold) 65%, transparent 100%);
  border-radius: 3px 3px 0 0;
  top: 50%; left: 50%;
  transform-origin: bottom center;
  transform: translate(-50%, -100%) rotate(0deg);
  filter: drop-shadow(0 0 4px rgba(255,215,0,0.6));
  transition: transform 600ms var(--ease-out);
}
.compass-dot {
  position: absolute;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--gold);
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 6px rgba(255,215,0,0.8);
}
.qibla-bearing {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 1px;
}
.qibla-sub { font-size: 11px; color: var(--text-muted); text-align: center; }
.qibla-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
  text-align: left;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  line-height: 1.6;
  max-width: 300px;
}
.qibla-note svg { flex-shrink: 0; margin-top: 1px; color: var(--gold-dim); }

/* Live compass face — rotates with device heading */
.compass-face {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  transition: transform 0.08s linear;
}

/* LIVE badge shown when sensor is active */
.live-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: #4ade80;
}
.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  animation: livePulse 1.5s ease-in-out infinite;
}
@keyframes livePulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

/* Explanation card — shown on first visit if sensor available */
.qibla-live-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  max-width: 300px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.live-card-icon {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--gold);
  font-size: 13px;
  font-weight: 600;
}
.live-card-msg {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.6;
}
.btn-activate {
  padding: 10px 16px;
  min-height: 44px;
  background: var(--gold);
  color: #152e1f;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  transition: filter var(--transition);
  align-self: stretch;
}
.btn-activate:hover { filter: brightness(1.1); }
.btn-activate:disabled { opacity: 0.5; cursor: not-allowed; }

/* Mouse-driven devices have no gyroscope — static bearing applies,
   so the live-sensor card is noise even though desktop Chrome
   defines DeviceOrientationEvent */
@media (hover: hover) and (pointer: fine) {
  .qibla-live-card { display: none; }
}

/* ── Zone selector modal ────────────────────────────────── */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: var(--z-modal);
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  transition: opacity 200ms ease, display 200ms allow-discrete;   /* exit: 200ms fade, then display:none */
}
.modal-backdrop.open { display: flex; opacity: 1; }
.modal-backdrop .modal { transition: transform 300ms var(--ease-out); }
/* entrance: browsers without @starting-style keep the instant toggle */
@starting-style {
  .modal-backdrop.open { opacity: 0; }
  .modal-backdrop.open .modal { transform: translateY(100%); }
}
.modal {
  background: #152e1f;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  padding: 24px 20px 32px;
  width: 100%;
  max-width: 480px;
  max-height: 75vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  color: var(--gold);
}
.modal select {
  width: 100%;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 12px 14px;
  min-height: 48px;
  font-size: 13px;
  font-family: var(--font-body);
  appearance: none;
  cursor: pointer;
  transition: border-color var(--transition);
}
.modal select:focus { border-color: var(--gold); }
.modal select option { background: #1a4731; color: #fff; }
.modal-btns { display: flex; gap: 10px; }
.btn-primary {
  flex: 1;
  padding: 13px;
  min-height: 48px;
  background: var(--gold);
  color: #152e1f;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: filter var(--transition);
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-secondary {
  padding: 13px 18px;
  min-height: 48px;
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 13px;
  cursor: pointer;
  transition: background var(--transition);
}
.btn-secondary:hover { background: rgba(255,255,255,0.08); }

/* ── Loading / error states ─────────────────────────────── */
.loading {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 13px;
}
.loading::after {
  content: '';
  display: block;
  width: 24px; height: 24px;
  margin: 12px auto 0;
  border: 2px solid rgba(255,215,0,0.2);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-msg {
  margin: 16px;
  padding: 14px 16px;
  background: rgba(180,40,40,0.18);
  border: 1px solid rgba(220,80,80,0.35);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: #ffaaaa;
  line-height: 1.5;
}

/* ── Settings tab (vocabulary shared with the /reset emergency page) ── */
.settings-wrap {
  padding: 20px 16px 28px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.section-title {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: rgba(255, 215, 0, 0.72);
  margin-bottom: 10px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card + .card { margin-top: 12px; }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
.row:last-child { border-bottom: none; }
.row-icon {
  width: 34px; height: 34px;
  flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--gold-faint);
  color: var(--gold);
}
.row-body { flex: 1; min-width: 0; }
.row-name { font-size: 14px; font-weight: 600; line-height: 1.35; }
.row-desc { font-size: 12px; color: var(--text-muted); line-height: 1.45; margin-top: 2px; }
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-ok { background: rgba(74, 222, 128, 0.16); color: #86efac; border: 1px solid rgba(74, 222, 128, 0.35); }

/* Action buttons: rest → busy (spinner) → done (check) → rest */
.btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--gold-faint);
  color: var(--gold);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform 120ms var(--ease-out);
}
.btn:hover:not(:disabled) { background: rgba(255, 215, 0, 0.2); border-color: var(--gold-dim); }
.btn:active:not(:disabled) { transform: scale(0.96); }
.btn:disabled { cursor: progress; }
.btn .btn-state { position: absolute; inset: 0; display: grid; place-items: center; opacity: 0; transition: opacity var(--transition); }
.btn .btn-label { transition: opacity var(--transition); }
.btn.busy .btn-label, .btn.done .btn-label { opacity: 0; }
.btn.busy .btn-state.spin, .btn.done .btn-state.tick { opacity: 1; }
.btn .spin svg { animation: gpsSpin 900ms linear infinite; }
.btn.done { border-color: #4ade80; color: #4ade80; background: rgba(74, 222, 128, 0.14); }
.btn.done .tick svg { animation: tickIn 320ms var(--ease-out); }
@keyframes tickIn { from { transform: scale(0.5); opacity: 0; } }
.btn-danger { background: rgba(239, 68, 68, 0.12); border-color: rgba(239, 68, 68, 0.4); color: #fca5a5; }
.btn-danger:hover:not(:disabled) { background: rgba(239, 68, 68, 0.22); border-color: rgba(239, 68, 68, 0.6); }

.nuke {
  border-color: rgba(239, 68, 68, 0.3);
  background: rgba(239, 68, 68, 0.06);
}
.nuke .row-icon { background: rgba(239, 68, 68, 0.15); color: #fca5a5; }
.nuke .row-name { color: #fca5a5; }
.nuke .row-desc { color: rgba(255, 255, 255, 0.6); }

/* Language segment: two options, the active one filled gold */
.lang-seg {
  display: flex;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.lang-opt {
  min-width: 48px;
  min-height: 40px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.lang-opt + .lang-opt { border-left: 1px solid var(--border); }
.lang-opt:hover:not(.active) { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.lang-opt.active { background: var(--gold); color: #152e1f; }

/* Zone modal: GPS-first option above the manual select */
.modal-gps-btn { width: 100%; margin-bottom: 10px; }
.modal-gps-btn .btn-label { display: inline-flex; align-items: center; gap: 8px; }
.modal-or {
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.modal-msg {
  margin-bottom: 10px;
  padding: 10px 12px;
  background: rgba(180,40,40,0.18);
  border: 1px solid rgba(220,80,80,0.35);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: #ffaaaa;
  line-height: 1.5;
}

/* Native select, dressed in the app's tokens */
.fmt-select {
  flex-shrink: 0;
  max-width: 140px;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--gold-faint);
  color: var(--gold);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.fmt-select option { background: #1a4731; color: var(--text); }

.settings-version {
  text-align: center;
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* Narrow phones: button rows give the text the icon's width back */
@media (max-width: 430px) {
  .row:has(.btn) .row-icon { display: none; }
}

/* ── Print styles ───────────────────────────────────────── */
@media print {
  body { background: #fff; color: #000; font-family: Arial, sans-serif; }
  body::before, body::after { display: none; }
  .header, .tab-bar, .print-btn, .cal-nav { display: none !important; }
  #tab-today, #tab-qibla { display: none !important; }
  #tab-calendar { display: block !important; padding: 0; }
  .cal-header { border-bottom: 1px solid #ccc; }
  .cal-title { color: #1a4731; }
  .cal-sub   { color: #666; }
  .cal-table { font-size: 11px; }
  .cal-table th { color: #444; border-bottom: 1px solid #ccc; }
  .cal-table td { color: #222; border-bottom: 1px solid #eee; }
  .cal-table tr.today { background: #fff9db; }
  .cal-table tr.today td:first-child { border-left: 2px solid #1a4731; color: #1a4731; }
  .cal-table tr.past  { opacity: 1; color: #888; }
}

/* ── Responsive — 768px (tablet) ─────────────────────────── */
@media (min-width: 768px) {
  body {
    background-attachment: fixed;
    min-height: 100dvh;
    padding: 24px 0; /* outer gap lives on body, not #app — margins collapse past body and create a phantom page scrollbar */
  }

  #app {
    max-width: 540px;
    height: calc(100vh - 48px);
    height: calc(100dvh - 48px);
    height: calc(var(--vh, 100dvh) - 48px);
    margin: 0 auto;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 24px 64px rgba(0,0,0,0.4);
  }

  .tab-bar {
    border-radius: 0 0 20px 20px;
  }

  .next-timer { font-size: 48px; }

  .prayer-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }

  .compass { width: 220px; height: 220px; }
  .compass-needle { height: 90px; }
}

/* ── Responsive — laptops with short viewports ────────────
   Compress vertical rhythm so the SOLAT tab fits without
   inner scrolling down to ~640px of viewport height. */
@media (min-width: 768px) and (max-height: 820px) {
  .header { padding: 12px 20px 10px; padding-top: calc(12px + env(safe-area-inset-top)); }
  .hijri-bar { padding-top: 8px; }
  .next-prayer-card { margin: 10px 16px 10px; padding: 14px 20px 12px; }
  .next-name { font-size: 20px; }
  .next-pada { font-size: 17px; }
  .next-time { font-size: 17px; }
  .next-lagi { margin-top: 6px; }
  .next-timer { font-size: 36px; }
  .progress-bar-wrap { margin-top: 8px; }
  .prayer-grid-label { margin-bottom: 6px; }
  .prayer-cell { padding: 8px 4px; }
  .prayer-grid { padding-bottom: 10px; }
  .tab-btn { min-height: 50px; padding: 8px 0 6px; }
  .qibla-wrap { padding: 20px 20px 16px; gap: 12px; }
  .compass { width: 170px; height: 170px; }
  .compass-needle { height: 68px; }
}

/* ── Responsive — tall phones (≥780px high): fill the viewport ──
   The Today and Kiblat tabs otherwise end at ~70% height with dead
   space above the tab bar. Mirror of the short-laptop tier. */
@media (max-width: 767px) and (min-height: 780px) {
  .hijri-bar { padding-top: 26px; }
  .next-prayer-card { margin: 22px 16px 20px; padding: 36px 20px 30px; }
  .next-timer { font-size: 52px; }
  .progress-bar-wrap { margin-top: 26px; }
  .prayer-grid-label { margin-bottom: 14px; }
  .prayer-grid { gap: 10px; padding-bottom: 24px; }
  .prayer-cell { padding: 18px 4px; }
  .prayer-cell .ptime { font-size: 13px; }
  .notif-row { padding: 20px 16px; }
  .qibla-wrap { padding-top: 96px; gap: 30px; }
  .compass { width: 260px; height: 260px; }
  .compass-needle { height: 108px; }
}

/* ── Responsive — 480px ───────────────────────────────────── */
@media (min-width: 480px) and (max-width: 767px) {
  body { background-attachment: fixed; }
}

/* ── Responsive — narrow phones (≤430px): keep header on one line ── */
@media (max-width: 430px) {
  .header-brand { white-space: nowrap; }
  .zone-pill { max-width: 150px; }
  .gps-btn { width: 40px; height: 40px; }
}

/* ── Responsive — small phones (≤360px) ──────────────────── */
@media (max-width: 360px) {
  .next-timer { font-size: 34px; letter-spacing: 2px; }
  .next-name  { font-size: 20px; }
  .next-pada  { font-size: 16px; }
  .next-time  { font-size: 16px; }
  .prayer-cell .ptime { font-size: 11px; }
  .prayer-cell .pname { font-size: 11px; }
  .header-brand { font-size: 13px; }
  .zone-pill { max-width: 160px; padding: 7px 10px; }
}

/* ── Landscape mode: bottom bar becomes a left nav rail, panels go two-column.
   Orientation is the signal — a landscape phone (844×390) and a landscape tablet
   both waste flanking space in the portrait column layout. ── */
@media (orientation: landscape) and (min-width: 640px) {
  #app {
    max-width: 960px;
    display: grid;
    grid-template-columns: 84px minmax(0, 1fr);
    grid-template-rows: auto auto auto minmax(0, 1fr);
  }
  .header      { grid-column: 2; grid-row: 1; }
  #offlineBar  { grid-column: 2; grid-row: 2; }
  #gpsMsg      { grid-column: 2; grid-row: 3; }
  .content     { grid-column: 2; grid-row: 4; }

  /* Camera cutouts sit on landscape edges — keep the rail clear of them */
  .tab-bar {
    grid-column: 1;
    grid-row: 1 / -1;
    flex-direction: column;
    justify-content: flex-start;
    width: auto;
    border-top: none;
    border-right: 1px solid rgba(255, 215, 0, 0.12);
    border-radius: 20px 0 0 20px;
    padding-bottom: 0;
    padding-left: env(safe-area-inset-left);
  }
  .tab-btn { flex: 0 0 76px; min-height: 76px; }
  /* The sliding indicator turns vertical: same continuity, rotated */
  .tab-bar::before {
    top: 0;
    left: auto;
    right: -1px;
    width: 2px;
    height: 76px;
  }
  .tab-bar[data-active="calendar"]::before { transform: translateY(76px); }
  .tab-bar[data-active="qibla"]::before    { transform: translateY(152px); }
  .tab-bar[data-active="settings"]::before { transform: translateY(228px); }

  /* SOLAT: countdown focal moment left, prayer grid right (2×4) */
  #tab-today.active {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    column-gap: 8px;
    align-content: start;
  }
  .hijri-bar         { grid-column: 1; grid-row: 1; }
  .next-prayer-card  { grid-column: 1; grid-row: 2; align-self: start; }
  .prayer-grid-label { grid-column: 2; grid-row: 1; align-self: end; }
  .prayer-grid       { grid-column: 2; grid-row: 2; grid-template-columns: repeat(2, 1fr); align-content: start; }

  /* KIBLAT: compass left, readings right */
  .qibla-wrap {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    align-content: center;
    column-gap: 28px;
    text-align: left;
  }
  .compass { grid-column: 1; grid-row: 1 / span 5; }
  .live-badge, .qibla-bearing, .qibla-sub, .qibla-note, .qibla-live-card { grid-column: 2; }

  /* TETAPAN: cards flow into two columns. The short install banner spans both —
     grid rows align across columns, so leaving it in one column opens a dead gap
     under it as tall as the neighbouring card. */
  .settings-wrap {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
    align-items: start;
  }
  #installSection { grid-column: 1 / -1; }

  /* The strip joins the left column above the focal card; the right column
     (grid label + prayer grid) keeps its own rows. */
  #tab-today.dual.active { grid-template-rows: auto auto minmax(0, 1fr); }
  #tab-today.dual .now-prayer-card   { grid-column: 1; grid-row: 2; }
  #tab-today.dual .next-prayer-card  { grid-column: 1; grid-row: 3; }
  #tab-today.dual .prayer-grid-label { grid-column: 2; grid-row: 1; }
  #tab-today.dual .prayer-grid       { grid-column: 2; grid-row: 2 / -1; }
}

/* ── Short landscape (phones): edge-to-edge — every vertical pixel counts ── */
@media (orientation: landscape) and (min-width: 640px) and (max-height: 520px) {
  body { padding: 0; }
  #app {
    max-width: none;
    height: 100vh;
    height: 100dvh;
    height: var(--vh, 100dvh);
    border-radius: 0;
    box-shadow: none;
  }
  .tab-bar { border-radius: 0; }
  .header { padding: 10px 20px 8px; padding-top: calc(10px + env(safe-area-inset-top)); }
  .hijri-bar { padding-top: 8px; }
  .next-prayer-card { margin: 10px 16px; padding: 12px 20px; }
  .next-timer { font-size: 32px; }
  .prayer-cell { padding: 7px 4px; }
  .qibla-wrap { padding: 16px 20px; }
  .compass { width: 170px; height: 170px; }
  .compass-needle { height: 68px; }
}
