/* Style: paper + pen ink. Tokens first; components use tokens only. */
@font-face { font-family: "Plex Arabic"; src: url("../fonts/ibm-plex-sans-arabic-arabic-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: "Plex Arabic"; src: url("../fonts/ibm-plex-sans-arabic-arabic-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: "Plex Arabic"; src: url("../fonts/ibm-plex-sans-arabic-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; unicode-range: U+0000-05FF, U+2000-206F; }
@font-face { font-family: "Plex Arabic"; src: url("../fonts/ibm-plex-sans-arabic-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; unicode-range: U+0000-05FF, U+2000-206F; }
@font-face { font-family: "Amiri"; src: url("../fonts/amiri-arabic-700-normal.woff2") format("woff2"); font-weight: 700; font-display: swap; unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: "Amiri"; src: url("../fonts/amiri-latin-700-normal.woff2") format("woff2"); font-weight: 700; font-display: swap; unicode-range: U+0000-05FF, U+2000-206F; }

:root {
  color-scheme: light dark;
  --paper: #F3EFE6; --surface: #FBF9F4; --ink: #1B2233; --muted: #565E6E; --line: #D6CFBF;
  --pen: #2340A0; --pen-soft: #E4E8F6; --qada: #9A3F18; --qada-soft: #F6E6DC;
  --hero: #1B2A5C; --hero-ink: #F3EFE6; --hero-muted: #BFC8E6;
  --ok: #2E7D46;
  --shadow-1: 0 1px 2px rgb(27 34 51 / .04), 0 2px 10px rgb(27 34 51 / .05);
  --shadow-2: 0 10px 30px rgb(20 26 48 / .18);
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s6: 24px; --s8: 32px;
  --r-sm: 8px; --r-md: 14px; --r-pill: 999px;
  --f-body: "Plex Arabic", system-ui, "Segoe UI", Tahoma, sans-serif;
  --f-display: "Amiri", "Plex Arabic", Georgia, serif;
  --tabs-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #12151C; --surface: #1A1F2A; --ink: #ECE8DD; --muted: #A3AAB8; --line: #2E3545;
    --pen: #9DB1F7; --pen-soft: #232C47; --qada: #EBA27A; --qada-soft: #3A2A22;
    --hero: #1D2B5E; --hero-ink: #F3EFE6; --hero-muted: #BFC8E6;
    --ok: #7FC796;
    --shadow-1: 0 1px 2px rgb(0 0 0 / .25), 0 2px 10px rgb(0 0 0 / .20);
    --shadow-2: 0 10px 30px rgb(0 0 0 / .45);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 16px/1.6 var(--f-body); font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; }
#app:focus { outline: none; }
[hidden] { display: none !important; }

#app {
  max-width: 560px; margin: 0 auto;
  padding: calc(var(--s4) + env(safe-area-inset-top)) var(--s4) calc(var(--tabs-h) + var(--s8) + env(safe-area-inset-bottom));
  display: grid; gap: var(--s6);
}

/* ----- header ----- */
.top { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); }
.top h1 { font: 700 32px/1.2 var(--f-display); }
.top p { color: var(--muted); font-size: 14px; text-align: end; }
.eyebrow { color: var(--muted); font-size: 14px; font-weight: 600; }
.section-title { font-size: 18px; font-weight: 600; }

/* ----- mihrab hero: the arch from the sheet's title, holding the next prayer ----- */
.hero {
  background: linear-gradient(172deg, color-mix(in srgb, var(--hero) 82%, #8FA3E8) 0%, var(--hero) 52%);
  color: var(--hero-ink); text-align: center;
  border-radius: 50% 50% var(--r-md) var(--r-md) / 96px 96px var(--r-md) var(--r-md);
  padding: 56px var(--s6) var(--s6); position: relative;
  box-shadow: var(--shadow-2);
}
.hero::before {
  content: ""; position: absolute; inset: 8px; pointer-events: none;
  border: 1px solid color-mix(in srgb, var(--hero-ink) 35%, transparent);
  border-radius: 50% 50% var(--r-sm) var(--r-sm) / 90px 90px var(--r-sm) var(--r-sm);
}
.hero .eyebrow { color: var(--hero-muted); }
.hero-name { font: 700 40px/1.3 var(--f-display); }
.hero-time { font-size: 24px; font-weight: 600; direction: ltr; unicode-bidi: isolate; }
.hero-count { color: var(--hero-muted); font-size: 16px; margin-top: var(--s1); }
.hero-count b { color: var(--hero-ink); font-weight: 600; direction: ltr; unicode-bidi: isolate; display: inline-block; }

/* ----- cards / setup ----- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s4); display: grid; gap: var(--s3); box-shadow: var(--shadow-1); }
.card p { color: var(--muted); font-size: 14px; }
.btn {
  min-height: 44px; padding: var(--s2) var(--s4); border-radius: var(--r-pill);
  border: 1px solid var(--pen); background: var(--pen); color: var(--paper); font-weight: 600;
  transition: background .15s, color .15s, transform .06s;
}
.btn.ghost { background: transparent; color: var(--pen); }
.btn.danger { border-color: var(--qada); color: var(--qada); background: transparent; }
.btn.link { border: 0; background: none; color: var(--muted); text-decoration: underline; font-weight: 400; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:not(:disabled):active { transform: scale(.97); }
@media (hover: hover) {
  .btn:not(:disabled, .ghost, .danger, .link):hover { background: color-mix(in srgb, var(--pen) 85%, var(--ink)); }
  .btn.ghost:not(:disabled):hover, .btn.danger:not(:disabled):hover { background: color-mix(in srgb, currentColor 10%, transparent); }
  .row:not(:disabled):hover { background: color-mix(in srgb, var(--pen-soft) 45%, transparent); }
  .icon-btn:not(:disabled):hover, .chip-t:not(.sel):hover { background: var(--pen-soft); }
}
.btn-row { display: flex; flex-wrap: wrap; gap: var(--s2); }

/* ----- day navigator ----- */
.daynav { display: flex; align-items: center; gap: var(--s2); }
.daynav-label { flex: 1; text-align: center; line-height: 1.4; }
.daynav-label strong { display: block; font-size: 18px; font-weight: 600; }
.daynav-label span { color: var(--muted); font-size: 14px; }
.icon-btn {
  width: 44px; height: 44px; flex: none; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: var(--r-pill); background: var(--surface);
}
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[dir="rtl"] .icon-btn svg.flip { transform: scaleX(-1); }

/* ----- log rows ----- */
.rows { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; box-shadow: var(--shadow-1); }
.rows li + li { border-top: 1px solid var(--line); }
.row {
  width: 100%; min-height: 64px; display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4); background: none; border: 0; text-align: start;
}
.row:disabled { cursor: default; }
.row:disabled .row-name, .row:disabled .mark { opacity: .45; }
.row:not(:disabled):active { background: var(--pen-soft); }
.row-main { flex: 1; min-width: 0; display: grid; }
.row-name { font-size: 18px; font-weight: 600; overflow-wrap: anywhere; }
.row-sub { color: var(--muted); font-size: 14px; }
.row-end { text-align: end; display: grid; justify-items: end; }
.row-time { font-weight: 600; direction: ltr; unicode-bidi: isolate; }
.chip { font-size: 14px; font-weight: 600; padding: 0 var(--s2); border-radius: var(--r-pill); }
.chip.hadir { color: var(--pen); background: var(--pen-soft); }
.chip.qada { color: var(--qada); background: var(--qada-soft); }
.chip.due { color: var(--ink); border: 1px solid var(--ink); }
.chip.late { color: var(--qada); border: 1px solid var(--qada); }

/* Marks copy the paper sheet: circle = on time, square = made up, a pen slash when ticked. */
.mark, .m {
  --c: var(--muted); flex: none; position: relative; display: inline-block;
  border: 2px solid var(--c); border-radius: 50%;
}
.mark { width: 30px; height: 30px; }
.m { width: 16px; height: 16px; border-width: 1.5px; vertical-align: middle; }
.mark.sq, .m.sq { border-radius: 5px; }
.m.sq { border-radius: 3px; }
.mark.on, .m.on { --c: var(--pen); }
.mark.sq.on, .m.sq.on { --c: var(--qada); }
.mark.on::after, .m.on::after {
  content: ""; position: absolute; inset-block: -18%; inset-inline-start: 50%; width: 2.5px; margin-inline-start: -1.25px;
  background: var(--c); border-radius: 2px; transform: rotate(38deg);
}
.m.on::after { width: 1.5px; margin-inline-start: -.75px; }
.m.future { border-style: dotted; opacity: .55; }
.mark.due { --c: var(--ink); }

/* ----- progress ----- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s2); }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s3) var(--s4); box-shadow: var(--shadow-1); }
.tile b { display: block; font: 700 32px/1.3 var(--f-display); direction: ltr; unicode-bidi: isolate; text-align: start; }
[dir="rtl"] .tile b { text-align: right; }
.tile b small { font: 400 16px var(--f-body); color: var(--muted); }
.tile span { color: var(--muted); font-size: 14px; }
.tile.pen b { color: var(--pen); } .tile.qada b { color: var(--qada); }
.note { color: var(--muted); font-size: 14px; }

.sheet-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
table.sheet { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 14px; }
.sheet th, .sheet td { padding: var(--s2) 2px; text-align: center; border-top: 1px solid var(--line); }
.sheet thead th { border-top: 0; color: var(--muted); font-weight: 600; font-size: 13px; }
.sheet th[scope="row"] { text-align: start; padding-inline-start: var(--s3); font-weight: 400; width: 26%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet tr.week th { background: var(--ink); color: var(--paper); text-align: start; padding: var(--s1) var(--s3); font-size: 13px; font-weight: 600; }
.sheet tr.week span { float: inline-end; font-weight: 400; }
.sheet thead th:first-child { width: 25%; text-align: start; padding-inline-start: var(--s3); }
.sheet tr.is-today th[scope="row"] { font-weight: 600; color: var(--pen); }
.sheet td small { display: block; color: var(--muted); font-size: 11px; line-height: 1.2; min-height: 13px; direction: ltr; }
.sheet td .m + .m { margin-inline-start: 2px; }
.legend { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); color: var(--muted); font-size: 14px; }
.legend span { display: inline-flex; align-items: center; gap: var(--s2); }

.bars { display: grid; gap: var(--s3); }
.bar { display: grid; grid-template-columns: 4.500em 1fr auto; align-items: center; gap: var(--s3); font-size: 14px; }
.bar-track { height: 8px; background: var(--pen-soft); border-radius: var(--r-pill); overflow: hidden; }
.bar-fill { display: block; height: 100%; width: var(--w, 0%); background: var(--pen); border-radius: var(--r-pill); }
.bar b { font-weight: 600; direction: ltr; unicode-bidi: isolate; }

/* ----- settings ----- */
.group { display: grid; gap: var(--s3); }
.field { display: grid; gap: var(--s1); }
.field > span, .field > label { font-size: 14px; color: var(--muted); }
.field input:not([type="checkbox"]), .field select, .inline-add input {
  min-height: 44px; width: 100%; padding: var(--s2) var(--s3);
  border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--paper);
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.grid5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--s2); }
.grid5 .field > span { text-align: center; }
.grid5 input { text-align: center; padding-inline: 2px !important; }
.check { display: flex; align-items: center; gap: var(--s3); min-height: 44px; }
.check input { width: 22px; height: 22px; accent-color: var(--pen); flex: none; }
.inline-add { display: flex; gap: var(--s2); }
.inline-add input { flex: 1; min-width: 0; }
.pills { display: flex; flex-wrap: wrap; gap: var(--s2); }
.pill { display: inline-flex; align-items: center; gap: var(--s1); padding-inline-start: var(--s3); border: 1px solid var(--line); border-radius: var(--r-pill); background: var(--paper); font-weight: 600; }
.pill button { width: 40px; height: 40px; border: 0; background: none; font-size: 20px; line-height: 1; color: var(--muted); border-radius: 50%; }
.list-edit { display: grid; gap: var(--s2); }
.list-edit > div { display: flex; gap: var(--s2); }
.list-edit input { flex: 1; min-width: 0; }
.status-line { font-size: 14px; font-weight: 600; color: var(--pen); }
.status-line.bad { color: var(--qada); }

/* ----- tabs: bottom bar on mobile, top bar with brand on wide screens ----- */
.nav-brand { display: none; }
.tabs {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 5; display: flex; justify-content: center;
  background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(8px); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; max-width: 186px; height: var(--tabs-h); display: grid; place-content: center; justify-items: center; gap: 2px;
  position: relative; background: none; border: 0; color: var(--muted); font-size: 12px; font-weight: 600;
  transition: color .15s;
}
.tab::before {
  content: ""; position: absolute; top: 0; inset-inline-start: 50%; translate: -50% 0;
  width: 32px; height: 3px; border-radius: var(--r-pill); background: transparent; transition: background .15s;
}
[dir="rtl"] .tab::before { translate: 50% 0; }
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.tab[aria-current="page"] { color: var(--pen); }
.tab[aria-current="page"]::before { background: var(--pen); }

/* ----- wide screens: top navigation, wider content, centered dialog ----- */
@media (min-width: 860px) {
  .tabs {
    top: 0; bottom: auto; border-top: 0; border-bottom: 1px solid var(--line);
    align-items: center; gap: var(--s1); padding: 0 var(--s6); height: 60px;
  }
  .nav-brand {
    display: block; margin-inline-end: auto;
    font: 700 24px/1 var(--f-display); color: var(--ink);
  }
  .tab {
    flex: none; max-width: none; height: 40px; border-radius: var(--r-pill);
    display: flex; flex-direction: row; align-items: center; gap: var(--s2); padding: 0 var(--s4);
    font-size: 14px;
  }
  .tab::before { display: none; }
  .tab svg { width: 20px; height: 20px; }
  .tab[aria-current="page"] { background: var(--pen-soft); }
  @media (hover: hover) { .tab:not([aria-current="page"]):hover { color: var(--ink); background: color-mix(in srgb, var(--pen-soft) 50%, transparent); } }
  #app {
    max-width: 720px;
    padding-top: calc(60px + var(--s8));
    padding-bottom: var(--s8);
  }
  .hero { padding: 72px var(--s8) var(--s8); }
  .tiles { grid-template-columns: repeat(4, 1fr); }
  #toast { bottom: var(--s6); }
  dialog#sheet { margin: auto; max-width: 480px; border-radius: var(--r-md); box-shadow: var(--shadow-2); }
  .tap { width: 240px; }
  .dial { width: 300px; }
}

/* ----- dialog + toast ----- */
dialog#sheet {
  width: min(100%, 560px); max-width: 100%; margin: auto auto 0; border: 0; padding: var(--s6) var(--s4) calc(var(--s6) + env(safe-area-inset-bottom));
  background: var(--surface); color: var(--ink); border-radius: var(--r-md) var(--r-md) 0 0;
}
dialog#sheet::backdrop { background: rgb(10 14 24 / .5); }
dialog#sheet form { display: grid; gap: var(--s4); }
dialog#sheet h2 { font: 700 24px/1.3 var(--f-display); }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.seg label { display: grid; place-items: center; min-height: 44px; font-weight: 600; cursor: pointer; }
.seg label + label { border-inline-start: 1px solid var(--line); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--pen); color: var(--paper); }
.seg label:has(input:focus-visible) { outline: 2px solid var(--pen); outline-offset: -4px; }
.error { color: var(--qada); font-size: 14px; font-weight: 600; min-height: 1.6em; }

#toast {
  position: fixed; inset-inline: var(--s4); bottom: calc(var(--tabs-h) + var(--s4) + env(safe-area-inset-bottom)); z-index: 10;
  margin: 0 auto; max-width: 420px; padding: var(--s3) var(--s4); border-radius: var(--r-sm);
  background: var(--ink); color: var(--paper); text-align: center; font-size: 14px; font-weight: 600;
  opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; pointer-events: none;
}
#toast.show { opacity: 1; transform: none; }

/* ----- hero progress dots ----- */
.hero-dots { display: flex; justify-content: center; gap: var(--s2); margin-top: var(--s3); }
.hd {
  width: 12px; height: 12px; border-radius: 50%;
  border: 1.5px solid color-mix(in srgb, var(--hero-ink) 45%, transparent); background: transparent;
}
.hd.hadir { background: var(--hero-ink); border-color: var(--hero-ink); }
.hd.qada { background: var(--qada); border-color: var(--qada); border-radius: 3px; }
.hd.late { border-color: var(--qada); border-radius: 3px; }
.hd.due { border-color: var(--hero-ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--hero-ink) 25%, transparent); }

/* ----- qibla ----- */
.qibla-card { justify-items: center; text-align: center; }
.dial {
  position: relative; width: min(280px, 72vw); aspect-ratio: 1; margin: var(--s2) auto;
  border-radius: 50%; border: 1px solid var(--line); background: var(--paper);
}
.dial-rose, .dial-needle { position: absolute; inset: 0; transform: rotate(var(--rot, 0deg)); transition: transform .15s linear; }
.dial-rose {
  border-radius: 50%;
  background:
    repeating-conic-gradient(from -0.75deg, var(--line) 0 1.5deg, transparent 1.5deg 30deg);
  -webkit-mask: radial-gradient(circle, transparent 0 62%, #000 62% 70%, transparent 70%);
  mask: radial-gradient(circle, transparent 0 62%, #000 62% 70%, transparent 70%);
}
/* Compass geometry is physical, not logical: no RTL flipping inside the dial. */
.dial-n {
  position: absolute; top: 3.5%; left: 50%; transform: translateX(-50%);
  font-weight: 700; font-size: 14px; color: var(--qada); direction: ltr;
}
.needle-line { position: absolute; top: 17%; bottom: 58%; left: calc(50% - 1.5px); width: 3px; background: var(--pen); border-radius: 2px; }
.needle-kaaba { position: absolute; top: 4.5%; left: 50%; width: 13%; margin-left: -6.5%; fill: var(--pen); }
.dial.hit .needle-line { background: var(--ok); }
.dial.hit .needle-kaaba { fill: var(--ok); }
.dial-center { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); display: grid; text-align: center; }
.dial-center b { font: 700 32px/1.2 var(--f-display); direction: ltr; }
.dial-center span { color: var(--muted); font-size: 13px; }
.q-facing { visibility: hidden; font-weight: 600; color: var(--ok); min-height: 1.6em; }
.dial.hit + .q-facing { visibility: visible; }
.q-meta { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--s2) var(--s4); color: var(--muted); font-size: 14px; }
.q-meta b { direction: ltr; unicode-bidi: isolate; }
.center { justify-content: center; text-align: center; }

/* ----- tasbih ----- */
.chips { display: flex; gap: var(--s2); overflow-x: auto; padding-bottom: var(--s1); scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip-t {
  flex: none; min-height: 40px; padding: var(--s1) var(--s4); border-radius: var(--r-pill);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 600; font-size: 14px;
}
.chip-t.sel { background: var(--pen); border-color: var(--pen); color: var(--paper); }
.tap-wrap { display: grid; gap: var(--s4); justify-items: center; }
.tap {
  position: relative; width: min(260px, 64vw); aspect-ratio: 1; border-radius: 50%;
  border: 0; background: var(--surface); display: grid; place-content: center; gap: 2px;
  box-shadow: inset 0 0 0 1px var(--line);
  -webkit-user-select: none; user-select: none; touch-action: manipulation;
}
.tap:active { background: var(--pen-soft); }
.tap svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); pointer-events: none; }
.tap-track { fill: none; stroke: var(--pen-soft); stroke-width: 6; }
.tap-ring { fill: none; stroke: var(--pen); stroke-width: 6; stroke-linecap: round; transition: stroke-dashoffset .12s linear; }
.tap-num { font: 700 64px/1.1 var(--f-display); color: var(--pen); direction: ltr; }
.tap-sub { color: var(--muted); font-size: 14px; }
.seg-4 { grid-template-columns: repeat(4, minmax(56px, 1fr)); background: var(--surface); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; font-size: 14px; color: var(--muted); margin-bottom: var(--s1); }
