/* Sakenah — styles.css
 * Design tokens + components. Light/dark via [data-theme], RTL-first
 * with logical properties so LTR needs no overrides.
 */

/* ---------- fonts (self-hosted) ---------- */
@font-face {
  font-family: "Plex Arabic";
  src: url("../fonts/IBMPlexSansArabic-Regular.woff2") format("woff2");
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: "Plex Arabic";
  src: url("../fonts/IBMPlexSansArabic-Medium.woff2") format("woff2");
  font-weight: 500; font-display: swap;
}
@font-face {
  font-family: "Plex Arabic";
  src: url("../fonts/IBMPlexSansArabic-SemiBold.woff2") format("woff2");
  font-weight: 600; font-display: swap;
}
@font-face {
  font-family: "Plex Arabic";
  src: url("../fonts/IBMPlexSansArabic-Bold.woff2") format("woff2");
  font-weight: 700; font-display: swap;
}
@font-face {
  font-family: "Amiri Quran";
  src: url("../fonts/AmiriQuran.woff2") format("woff2");
  font-weight: 400; font-display: swap;
}

/* ---------- tokens ---------- */
:root {
  --bg: #f4f7f2;
  --surface: #ffffff;
  --surface-2: #eef4ee;
  --ink: #152820;
  --muted: #5d7166;
  --line: #dbe6dc;
  --pine: #17694c;
  --pine-strong: #0f5138;
  --pine-soft: #e2efe6;
  --hero-a: #114f3a;
  --hero-b: #0a3527;
  --on-hero: #f2f8f3;
  --on-hero-muted: #b9d2c2;
  --brass: #c9a86a;
  --brass-deep: #a8853f;
  --ring-track: rgba(255, 255, 255, .14);
  --ring-fill: #7fd4ab;
  --danger: #b3423f;
  --shadow: 0 18px 48px rgba(17, 55, 40, .10);
  --shadow-soft: 0 8px 24px rgba(17, 55, 40, .07);
  --r-lg: 24px;
  --r-md: 16px;
  --r-sm: 12px;
  --dur: .22s;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0b1712;
  --surface: #122019;
  --surface-2: #16281f;
  --ink: #e7f1ea;
  --muted: #90a598;
  --line: #223529;
  --pine: #55c493;
  --pine-strong: #7fd4ab;
  --pine-soft: #163223;
  --hero-a: #123f2f;
  --hero-b: #0a2018;
  --on-hero: #ecf6ef;
  --on-hero-muted: #a3bfae;
  --ring-track: rgba(255, 255, 255, .09);
  --ring-fill: #6fcda0;
  --brass: #d4b078;
  --brass-deep: #c9a86a;
  --shadow: 0 18px 48px rgba(0, 0, 0, .35);
  --shadow-soft: 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Plex Arabic", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.7;
  transition: background-color var(--dur), color var(--dur);
  padding-inline: max(16px, env(safe-area-inset-left)) ;
  padding-inline-end: max(16px, env(safe-area-inset-right));
  padding-bottom: env(safe-area-inset-bottom);
}
#app { max-width: 920px; margin-inline: auto; }
p { margin: 0; }
h1, h2, h3 { margin: 0; line-height: 1.35; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--pine); outline-offset: 2px; border-radius: 6px; }
::selection { background: color-mix(in srgb, var(--pine), transparent 75%); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}
.skip-link {
  position: absolute; inset-inline-start: 12px; top: -48px;
  background: var(--pine); color: #fff; padding: 8px 16px;
  border-radius: 0 0 10px 10px; text-decoration: none; z-index: 60;
  transition: top var(--dur);
}
.skip-link:focus-visible { top: 0; }

/* ---------- header ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding-block: 14px; gap: 12px;
  padding-top: max(14px, env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.brand-mark { width: 42px; height: 42px; flex: none; }
.bm-bg { fill: var(--pine-strong); }
[data-theme="dark"] .bm-bg { fill: #1b5f43; }
.bm-crescent { fill: #eaf5ee; }
.bm-star { fill: var(--brass); }
.brand-text strong { display: block; font-size: 17px; font-weight: 700; }
.brand-text small { display: block; font-size: 10.5px; color: var(--muted); letter-spacing: .02em; }

.top-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--r-sm); transition: background-color var(--dur), border-color var(--dur);
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:hover { border-color: var(--pine); }
.icon-btn.ghost { border-color: transparent; background: transparent; }
.icon-btn.ghost:hover { background: var(--surface-2); }
.lang-btn { font-weight: 700; font-size: 12.5px; letter-spacing: .02em; }

.pill-btn {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 9px 18px; font-weight: 600; font-size: 13px;
  transition: border-color var(--dur), background-color var(--dur);
}
.pill-btn:hover { border-color: var(--pine); }
.pill-btn.solid { background: var(--pine); border-color: var(--pine); color: #fff; }
.pill-btn.solid:hover { background: var(--pine-strong); border-color: var(--pine-strong); }
.pill-btn.wide { width: 100%; padding-block: 12px; }

/* ---------- banner / toast / error ---------- */
.banner {
  background: color-mix(in srgb, var(--brass), transparent 82%);
  border: 1px solid color-mix(in srgb, var(--brass), transparent 55%);
  color: var(--ink); border-radius: var(--r-sm);
  padding: 10px 16px; font-size: 13px; margin-bottom: 12px; text-align: center;
}
.toast {
  position: fixed; inset-inline: 0; bottom: calc(24px + env(safe-area-inset-bottom));
  margin-inline: auto; width: fit-content; max-width: min(90vw, 420px);
  background: var(--ink); color: var(--bg);
  padding: 11px 20px; border-radius: 999px; font-size: 13.5px;
  opacity: 0; translate: 0 12px; pointer-events: none;
  transition: opacity var(--dur), translate var(--dur);
  z-index: 70; box-shadow: var(--shadow-soft); text-align: center;
}
.toast.show { opacity: 1; translate: 0 0; }

.error-box {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 28px; text-align: center;
  display: grid; justify-items: center; gap: 10px; margin-bottom: 16px;
}
.error-box svg { width: 34px; height: 34px; color: var(--danger); }
.error-box p { max-width: 46ch; color: var(--muted); }
.dim { opacity: .45; pointer-events: none; }

/* ---------- hero ---------- */
.hero-card {
  position: relative; overflow: hidden;
  background: linear-gradient(150deg, var(--hero-a), var(--hero-b));
  color: var(--on-hero);
  border-radius: var(--r-lg);
  padding: 22px 24px 20px;
  box-shadow: var(--shadow);
}
.hero-card::before {
  /* Quiet eight-point star lattice — the only ornament on the page */
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .05;
  background-image:
    radial-gradient(circle at center, transparent 5px, currentColor 5px 5.8px, transparent 5.8px);
  background-size: 56px 56px;
  mask-image: linear-gradient(200deg, #000 0%, transparent 55%);
  -webkit-mask-image: linear-gradient(200deg, #000 0%, transparent 55%);
}

.hero-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.place { display: flex; align-items: center; gap: 2px; min-width: 0; }
.place-btn {
  display: flex; align-items: center; gap: 7px;
  background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .14);
  color: inherit; border-radius: 999px; padding: 7px 14px;
  font-size: 13px; font-weight: 600; max-width: 100%;
  transition: background-color var(--dur);
}
.place-btn:hover { background: rgba(255, 255, 255, .15); }
.place-btn svg { width: 15px; height: 15px; flex: none; }
.place-btn .chev { width: 13px; height: 13px; opacity: .7; }
.place-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fav-btn { color: var(--on-hero-muted); }
.fav-btn:hover { background: rgba(255,255,255,.1); }
.fav-btn.active { color: var(--brass); }
.fav-btn.active svg { fill: currentColor; }

.hero-meta { display: flex; align-items: baseline; gap: 10px; }
.city-clock { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tz-badge { font-size: 10px; color: var(--on-hero-muted); letter-spacing: .03em; direction: ltr; }

.hero-main {
  display: grid; grid-template-columns: 1fr auto;
  align-items: center; gap: 18px; margin-top: 18px;
}
.kicker {
  font-size: 12px; font-weight: 600; color: var(--on-hero-muted);
  letter-spacing: .04em;
}
.next-name { font-size: clamp(38px, 7vw, 58px); font-weight: 700; margin-top: 2px; }
.next-at { margin-top: 6px; font-size: 14px; color: var(--on-hero-muted); }
.next-at strong { color: var(--on-hero); font-variant-numeric: tabular-nums; font-weight: 600; }
.tomorrow-tag {
  display: inline-block; margin-top: 10px; font-size: 11px; font-weight: 600;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.16);
  padding: 3px 12px; border-radius: 999px; color: var(--on-hero-muted);
}

.ring-wrap { position: relative; width: clamp(190px, 32vw, 236px); aspect-ratio: 1; }
.ring { width: 100%; height: 100%; display: block; }
.ring-bg { fill: none; stroke: var(--ring-track); stroke-width: 7; }
.ring-fg {
  fill: none; stroke: var(--ring-fill); stroke-width: 7; stroke-linecap: round;
  transition: stroke-dashoffset .9s linear;
}
.cd {
  position: absolute; inset: 0; display: grid; place-content: center;
  text-align: center; gap: 4px;
}
.cd-caption { font-size: 11px; color: var(--on-hero-muted); font-weight: 600; }
.cd-digits {
  display: flex; align-items: baseline; justify-content: center; gap: 4px;
  font-variant-numeric: tabular-nums; font-weight: 700;
  font-size: clamp(30px, 5.4vw, 40px); line-height: 1;
}
.cd-digits b { font-weight: 400; opacity: .45; font-size: .75em; }
.cd-units {
  display: flex; justify-content: center; gap: 0;
  font-size: 9.5px; color: var(--on-hero-muted);
}
.cd-units span { width: 52px; text-align: center; }

.hero-dates {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 16px; padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, .12);
  font-size: 13.5px; color: var(--on-hero-muted);
}
.hero-dates .hijri { color: var(--on-hero); font-weight: 600; }
.hijri-mark { color: var(--brass); font-size: .85em; }
.dot-sep { width: 4px; height: 4px; border-radius: 50%; background: var(--brass); }

/* ---------- actions ---------- */
.actions {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px;
  margin-top: 14px;
}
.action-btn {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 14px 6px 12px;
  font-size: 12px; font-weight: 600; color: var(--ink);
  transition: border-color var(--dur), background-color var(--dur), translate var(--dur);
}
.action-btn svg { width: 21px; height: 21px; color: var(--pine); }
.action-btn:hover { border-color: var(--pine); translate: 0 -1px; }
.spinning .refresh-icon, .is-loading .refresh-icon { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- schedule ---------- */
.schedule { margin-top: 26px; }
.schedule h2 { font-size: 18px; font-weight: 700; margin-bottom: 12px; }
.prayer-list {
  list-style: none; margin: 0; padding: 0;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-soft);
}
.prayer-row {
  display: grid; grid-template-columns: 44px 1fr auto; align-items: center;
  min-height: 62px; padding-inline: 20px;
  border-bottom: 1px solid var(--line);
  transition: background-color var(--dur);
}
.prayer-row:last-child { border-bottom: 0; }
.p-icon { width: 21px; height: 21px; color: var(--muted); }
.p-name { font-weight: 600; font-size: 14.5px; }
.p-time { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 15.5px; }
.prayer-row.active {
  background: var(--pine-soft);
  box-shadow: inset 3px 0 0 var(--pine);
}
html[dir="rtl"] .prayer-row.active { box-shadow: inset -3px 0 0 var(--pine); }
.prayer-row.active .p-icon, .prayer-row.active .p-time { color: var(--pine-strong); }
.row-sunrise .p-icon { color: var(--brass-deep); }
.row-sunrise .p-name { color: var(--muted); font-weight: 500; }
.row-sunrise .p-time { color: var(--muted); font-weight: 500; }
.method-line { margin-top: 10px; font-size: 12px; color: var(--muted); padding-inline: 6px; }
.method-line strong { color: var(--ink); font-weight: 600; }

/* ---------- ayah ---------- */
.ayah { text-align: center; padding: 52px 12px 44px; }
.ayah-text {
  font-family: "Amiri Quran", "Plex Arabic", serif;
  white-space: nowrap;
  font-size: min(calc(4.5vw - 2px), 32px); line-height: 2;
  margin-inline: auto; color: var(--ink);
}
.ayah-translation { margin-top: 14px; color: var(--muted); font-size: 14px; max-width: 52ch; margin-inline: auto; }
.ayah-ref { margin-top: 12px; font-size: 12px; color: var(--brass-deep); font-weight: 600; letter-spacing: .04em; }

/* ---------- footer ---------- */
.footer {
  border-top: 1px solid var(--line);
  padding: 22px 6px calc(30px + env(safe-area-inset-bottom));
  display: grid; gap: 6px; text-align: center;
}
.footer p { font-size: 12.5px; color: var(--muted); }
.fine { font-size: 11.5px; color: var(--muted); line-height: 1.8; }

/* ---------- dialogs / sheets ---------- */
.sheet {
  border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--surface); color: var(--ink);
  width: min(94vw, 460px); max-height: 86dvh;
  padding: 22px; margin: auto;
  box-shadow: var(--shadow);
}
.sheet-wide { width: min(96vw, 640px); }
.sheet::backdrop { background: rgba(8, 20, 14, .45); backdrop-filter: blur(3px); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.sheet-head h2 { font-size: 17px; font-weight: 700; }

@media (max-width: 560px) {
  .sheet {
    width: 100vw; max-width: none; margin: auto 0 0;
    border-radius: var(--r-lg) var(--r-lg) 0 0; border-bottom: 0;
    max-height: 88dvh;
    padding-bottom: calc(22px + env(safe-area-inset-bottom));
  }
}

/* location sheet */
.geo-btn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 9px;
  background: var(--pine-soft); color: var(--pine-strong);
  border: 1px solid color-mix(in srgb, var(--pine), transparent 70%);
  border-radius: var(--r-md); padding: 13px; font-weight: 700; font-size: 14px;
  transition: background-color var(--dur);
}
.geo-btn:hover { background: color-mix(in srgb, var(--pine), transparent 82%); }
.geo-btn svg { width: 19px; height: 19px; }

.city-form { display: grid; gap: 12px; margin-top: 16px; }
.city-form label span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.city-form select, .city-form input, .set-select {
  width: 100%; height: 48px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  padding-inline: 14px; font: inherit; font-size: 14px;
}
.city-form select:focus, .city-form input:focus, .set-select:focus {
  outline: none; border-color: var(--pine);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--pine), transparent 84%);
}
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--bg);
  border-radius: 999px; padding: 7px 14px; font-size: 12.5px; font-weight: 600;
  transition: border-color var(--dur), background-color var(--dur);
}
.chip:hover { border-color: var(--pine); background: var(--pine-soft); }
.fav-section { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.fav-section h3 { font-size: 13px; font-weight: 700; margin-bottom: 10px; }
.fav-section .fine { margin-bottom: 8px; }

/* settings */
.set-group { margin-bottom: 18px; }
.set-label { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 8px; }
.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 3px; gap: 3px; }
.seg label { flex: 1; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block; text-align: center; padding: 8px 6px;
  border-radius: 9px; font-size: 12.5px; font-weight: 600; color: var(--muted);
  transition: background-color var(--dur), color var(--dur);
}
.seg input:checked + span { background: var(--surface); color: var(--pine-strong); box-shadow: var(--shadow-soft); }
.seg input:focus-visible + span { outline: 2px solid var(--pine); outline-offset: 1px; }
.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  padding-block: 8px; font-size: 14px; gap: 12px;
}
.switch-row input[type="checkbox"] {
  appearance: none; width: 44px; height: 26px; border-radius: 999px;
  background: var(--line); position: relative; cursor: pointer; flex: none;
  transition: background-color var(--dur); margin: 0;
}
.switch-row input[type="checkbox"]::after {
  content: ""; position: absolute; top: 3px; inset-inline-start: 3px;
  width: 20px; height: 20px; border-radius: 50%; background: #fff;
  transition: translate var(--dur); box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch-row input[type="checkbox"]:checked { background: var(--pine); }
html[dir="rtl"] .switch-row input[type="checkbox"]:checked::after { translate: -18px 0; }
html[dir="ltr"] .switch-row input[type="checkbox"]:checked::after { translate: 18px 0; }
.mins-input {
  width: 76px; height: 40px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  text-align: center; font: inherit;
}

/* month table */
.month-caption { margin-bottom: 10px; }
.table-scroll { overflow: auto; max-height: 62dvh; border: 1px solid var(--line); border-radius: var(--r-md); }
.month-table { width: 100%; border-collapse: collapse; font-size: 12.5px; min-width: 520px; }
.month-table thead th {
  position: sticky; top: 0; background: var(--surface-2);
  padding: 10px 8px; font-weight: 700; font-size: 12px; z-index: 1;
}
.month-table td, .month-table tbody th { padding: 9px 8px; text-align: center; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.month-table tbody th { font-weight: 600; }
.m-g { display: block; font-size: 13px; }
.m-h { display: block; font-size: 10px; color: var(--brass-deep); }
.m-sunrise { color: var(--muted); }
.month-table .is-today { background: var(--pine-soft); }
.month-table .is-today th, .month-table .is-today td { font-weight: 700; color: var(--pine-strong); }

/* qibla */
.compass { display: grid; place-items: center; padding: 18px 0 8px; }
.compass-dial {
  position: relative; width: 210px; height: 210px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--bg);
  transition: transform .3s ease;
}
.compass-dial span {
  position: absolute; font-size: 11px; font-weight: 700; color: var(--muted);
}
.c-n { top: 8px; left: 50%; translate: -50% 0; color: var(--pine-strong) !important; }
.c-s { bottom: 8px; left: 50%; translate: -50% 0; }
.c-e { right: 10px; top: 50%; translate: 0 -50%; }
.c-w { left: 10px; top: 50%; translate: 0 -50%; }
.compass-needle {
  position: absolute; inset: 0; display: grid; place-items: center;
  transition: transform .3s ease; color: var(--pine);
}
.compass-needle svg { width: 44px; height: 130px; margin-top: -66px; }
.kaaba-dot {
  position: absolute; top: 22px; left: 50%; translate: -50% 0;
  width: 12px; height: 12px; border-radius: 3px; background: var(--brass);
}
.qibla-deg { text-align: center; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; margin-bottom: 6px; }
#qiblaSheet .fine { text-align: center; margin-bottom: 10px; }
#compassBtn { margin-top: 8px; }

/* ---------- loading ---------- */
.is-loading .hero-card, .is-loading .prayer-list { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .72; } }

/* ---------- responsive ---------- */
@media (max-width: 700px) {
  .hero-main { grid-template-columns: 1fr; justify-items: center; text-align: center; gap: 8px; }
  .next-info { order: 2; }
  .ring-wrap { order: 1; width: min(64vw, 250px); margin-top: 4px; }
  .hero-dates { justify-content: center; }
  .actions { grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .action-btn { padding: 12px 4px 10px; font-size: 11px; }
  .brand-text small { display: none; }
}
@media (max-width: 380px) {
  .cd-digits { font-size: 26px; }
  .cd-units span { width: 44px; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .ring-fg { transition: none; }
}
