/* Ramadan4 — by ByHamad4
   Colours change with the time of day: <html data-phase="suhoor|day|maghrib|night">.
   "day-dark" is the daytime look when the phone is in dark mode. */

:root {
  --font-body: 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --font-display: 'Readex Pro', 'IBM Plex Sans Arabic', sans-serif;
  --radius: 18px;
  --gutter: 20px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);

  /* Dark defaults (shared by suhoor / maghrib / night / day-dark) */
  --text: #F7F3F4;
  --sub: #C9BCC0;
  --muted: #8E8388;
  --glass: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.13);
  --track: rgba(255, 255, 255, 0.08);
  --accent: #FF2D55;
  --on-accent: #FFFFFF;
  --sheet: rgba(24, 14, 18, 0.95);
  --scrim: rgba(5, 3, 5, 0.6);
  --bg: radial-gradient(130% 48% at 50% 100%, #7A0F25 0%, #2A0A13 42%, #0B070A 78%);
  --bg-solid: #0B070A;
  --line: #FF8FA3;
  --line-opacity: 0.85;
  --garland: #FF8FA3;
  --lights: 0;
  --sun: 0;
  --stars: 0;
}

html[data-phase="suhoor"] {
  --bg: linear-gradient(180deg, #03030A 0%, #0B0A1F 55%, #221236 100%);
  --bg-solid: #03030A;
  --line: #E7B6D0; --garland: #E7B6D0; --line-opacity: 0.7;
  --lights: 1; --stars: 0.9;
}

html[data-phase="day"] {
  --text: #111014; --sub: #5E575C; --muted: #8A8287;
  --glass: rgba(255, 255, 255, 0.7); --border: rgba(17, 16, 20, 0.08); --track: rgba(17, 16, 20, 0.08);
  --accent: #E0102F; --sheet: rgba(253, 248, 243, 0.96); --scrim: rgba(17, 16, 20, 0.35);
  --bg: linear-gradient(180deg, #FDF8F3 0%, #F9EADF 65%, #F3D6C4 100%);
  --bg-solid: #FDF8F3;
  --line: #B8142F; --garland: #B8142F; --line-opacity: 0.6;
}

html[data-phase="maghrib"] {
  --glass: rgba(20, 4, 10, 0.35); --border: rgba(255, 255, 255, 0.18);
  --bg: linear-gradient(180deg, #14060C 0%, #3D0816 34%, #9E1230 64%, #F0442F 86%, #FF9A5A 100%);
  --bg-solid: #3D0816;
  --line: #2A0710; --garland: #FF8FA3; --line-opacity: 0.95;
  --lights: 0.55; --sun: 1; --stars: 0.3;
}

html[data-phase="night"] {
  --bg: linear-gradient(180deg, #020203 0%, #07060C 60%, #150A14 100%);
  --bg-solid: #020203;
  --line-opacity: 0.55;
  --lights: 1; --stars: 1;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg-solid);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
[hidden] { display: none !important; }

.display { font-family: var(--font-display); font-weight: 700; margin: 0; }
.sub { color: var(--sub); font-size: 13px; }
.small { font-size: 11px; }
.accent { color: var(--accent); }
.glass {
  background: var(--glass);
  border: 1px solid var(--border);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

/* ---------- App frame ---------- */
.app {
  position: relative;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  overflow: hidden;
  background: var(--bg);
  transition: background 1.2s var(--ease);
}

.backdrop { position: absolute; inset: 0; pointer-events: none; }
.stars { position: absolute; top: 0; left: 0; width: 100%; height: 600px; opacity: var(--stars); transition: opacity 1.2s; }
.garland { position: absolute; top: 0; left: 0; width: 100%; height: 130px; filter: drop-shadow(0 0 4px var(--garland)); }
.garland g:first-child { stroke: var(--garland); opacity: 0.75; }
.garland .bulbs { fill: var(--garland); opacity: 0.9; }
#skyline { position: absolute; left: 0; right: 0; bottom: 0; }
.skyline { display: block; width: 100%; height: auto; filter: drop-shadow(0 0 5px var(--line)); }
.sky-lines { stroke: var(--line); opacity: var(--line-opacity); transition: opacity 1.2s; }
.sky-lights { opacity: var(--lights); filter: drop-shadow(0 0 4px #FFB347); transition: opacity 1.2s; }
.sky-sun { opacity: var(--sun); transition: opacity 1.2s; }

/* ---------- Home ---------- */
.home {
  position: relative;
  display: flex; flex-direction: column; gap: 14px;
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top) + 26px) var(--gutter) calc(env(safe-area-inset-bottom) + 34vw);
}
@media (min-width: 480px) { .home { padding-bottom: 170px; } }

.top { display: flex; justify-content: space-between; align-items: flex-start; padding-inline-start: 34px; }
.top-text { display: flex; flex-direction: column; gap: 2px; }
.top-text h1 { font-size: 24px; white-space: nowrap; }
.top-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; margin-inline-end: 34px; }
.logo { font-weight: 800; font-size: 18px; letter-spacing: -0.3px; }
.chip {
  display: flex; align-items: center; gap: 6px;
  min-height: 32px; padding: 0 12px; border-radius: 16px;
  font-size: 12px; cursor: pointer;
}

.ring-wrap { position: relative; width: 236px; height: 236px; align-self: center; }
.ring { position: absolute; inset: 0; width: 100%; height: 100%; }
.ring circle { fill: none; }
.ring-track { stroke: var(--track); stroke-width: 6; }
.ring-fill {
  stroke: var(--accent); stroke-width: 6; stroke-linecap: round;
  stroke-dasharray: 0 666; filter: drop-shadow(0 0 6px var(--accent));
}
.ring-dots { stroke: var(--line); stroke-width: 0.6; stroke-dasharray: 2 6; opacity: 0.6; }
.ring-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  text-align: center; padding: 0 24px;
}
.count { font-size: 44px; letter-spacing: -1px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.count.is-text { font-size: 32px; letter-spacing: 0; }

.times { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.time-pill { padding: 10px 12px; border-radius: 16px; display: flex; flex-direction: column; gap: 2px; }
.time-pill .label { font-size: 11px; color: var(--sub); }
.time-pill b { font-family: var(--font-display); font-size: 17px; }
.time-pill b small { font-size: 11px; font-weight: 500; margin-inline-start: 3px; }
.time-pill.is-next { border-color: var(--accent); }
.time-pill.is-next .label { color: var(--accent); }

.ward {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; border-radius: var(--radius);
}
.ward-text { display: flex; flex-direction: column; gap: 2px; }
.ward-title { font-size: 15px; }
.btn-accent {
  min-height: 40px; padding: 0 18px; border-radius: 20px; border: 0;
  background: var(--accent); color: var(--on-accent); font-size: 13px; font-weight: 600; cursor: pointer;
}

.sections { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 64px; border-radius: var(--radius);
  font-size: 11px; font-weight: 600; cursor: pointer;
  transition: transform 0.15s var(--ease);
}
.tile:active { transform: scale(0.96); }
.tile svg {
  width: 22px; height: 22px; fill: none; stroke: var(--accent);
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- Bottom sheet ---------- */
.sheet-scrim {
  position: fixed; inset: 0; z-index: 10;
  background: var(--scrim);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  opacity: 0; transition: opacity 0.25s var(--ease);
}
.sheet-scrim.is-open { opacity: 1; }
.sheet {
  position: fixed; z-index: 11; left: 50%; bottom: 0;
  width: 100%; max-width: 480px; max-height: 92dvh;
  display: flex; flex-direction: column; gap: 14px;
  padding: 10px var(--gutter) calc(env(safe-area-inset-bottom) + 24px);
  border-radius: 30px 30px 0 0;
  border-top: 1px solid var(--border);
  background: var(--sheet);
  -webkit-backdrop-filter: blur(24px); backdrop-filter: blur(24px);
  transform: translate(-50%, 100%);
  transition: transform 0.32s var(--ease);
}
.sheet.is-open { transform: translate(-50%, 0); }
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--border); align-self: center; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.sheet-head h2 { font-size: 24px; }
.sheet-body { overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding-bottom: 4px; }
.icon-btn {
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 44px; height: 44px; border-radius: 22px; border: 0;
  background: var(--glass); cursor: pointer;
}

.soon { padding: 28px 16px; border-radius: var(--radius); text-align: center; line-height: 1.7; }
.soon b { display: block; font-family: var(--font-display); font-size: 17px; margin-bottom: 4px; }

.list { display: flex; flex-direction: column; border-radius: var(--radius); overflow: hidden; }
.list-row {
  display: flex; justify-content: space-between; align-items: center;
  min-height: 48px; padding: 0 16px; border-bottom: 1px solid var(--border); font-size: 15px;
}
.list-row:last-child { border-bottom: 0; }
.list-row b { font-family: var(--font-display); }
.list-row.is-next { color: var(--accent); }

.field { display: flex; flex-direction: column; gap: 8px; }
.field > span { font-size: 13px; color: var(--sub); }
.options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.option {
  min-height: 44px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--glass); font-size: 14px; cursor: pointer;
}
.option[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.note { font-size: 12px; line-height: 1.7; color: var(--muted); text-align: center; }

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

/* ---------- Imsakiya ---------- */
.segment { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 4px; border-radius: 22px; background: var(--glass); }
.segment button { min-height: 40px; border: 0; border-radius: 18px; background: transparent; color: var(--sub); font-size: 14px; cursor: pointer; }
.segment button[aria-selected="true"] { background: var(--accent); color: var(--on-accent); font-weight: 600; }

.table-wrap { border-radius: var(--radius); overflow: auto; max-height: 46dvh; }
.imsakiya { width: 100%; border-collapse: collapse; font-size: 13px; text-align: center; font-variant-numeric: tabular-nums; }
.imsakiya thead th {
  position: sticky; top: 0; z-index: 1;
  padding: 10px 2px; font-size: 11px; font-weight: 600; color: var(--sub);
  background: var(--sheet); border-bottom: 1px solid var(--border);
}
.imsakiya td, .imsakiya tbody th { padding: 9px 2px; border-bottom: 1px solid var(--border); }
.imsakiya tbody th { font-weight: 400; }
.imsakiya tbody th b { display: block; font-family: var(--font-display); font-size: 14px; }
.imsakiya tbody th span { font-size: 10px; color: var(--muted); }
.imsakiya td:nth-child(2), .imsakiya td:nth-child(6) { font-weight: 700; }
.imsakiya tr.is-odd th b { color: #FFC27A; }
html[data-phase="day"] .imsakiya tr.is-odd th b { color: #B26A00; }
.imsakiya tr.is-today { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.imsakiya tr.is-today th b { color: var(--accent); }

.btn-block { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; border-radius: 24px; text-decoration: none; font-size: 15px; }
.btn-ghost { border: 1px solid var(--border); color: var(--text); background: transparent; font-size: 13px; min-height: 44px; }

/* ---------- Khatma sheet ---------- */
.options.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.options.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.inline-input { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 4px; font-size: 14px; }
.inline-input input, .paper-row input {
  width: 96px; min-height: 44px; padding: 0 12px; border-radius: 14px;
  border: 1px solid var(--border); background: var(--glass); color: var(--text);
  font: 600 16px var(--font-display); text-align: center;
}
.preview { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border-radius: var(--radius); }
.preview b { font-family: var(--font-display); font-size: 16px; }
.warn { font-size: 12px; line-height: 1.6; color: #FFC27A; }
html[data-phase="day"] .warn { color: #9A5B00; }

.khatma-head { display: flex; align-items: center; gap: 16px; padding: 14px 16px; border-radius: 22px; }
.mini-ring { position: relative; width: 84px; height: 84px; flex-shrink: 0; }
.mini-ring svg { position: absolute; inset: 0; }
.mini-ring circle { fill: none; stroke-width: 7; }
.mini-ring .track { stroke: var(--track); }
.mini-ring .fill { stroke: var(--accent); stroke-linecap: round; }
.mini-ring > div { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.mini-ring b { font-family: var(--font-display); font-size: 18px; }
.mini-ring span { font-size: 10px; color: var(--sub); }
.khatma-facts { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--sub); }
.khatma-facts b { color: var(--text); }

.ward-box { display: flex; flex-direction: column; gap: 6px; padding: 14px 16px; border-radius: var(--radius); }
.ward-big { font-family: var(--font-display); font-size: 18px; }
.prayer-split { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; margin-top: 6px; }
.prayer-split div { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; border-radius: 12px; background: var(--glass); font-size: 11px; color: var(--sub); }
.prayer-split b { font-size: 12px; color: var(--text); font-variant-numeric: tabular-nums; }
.prayer-split .is-done { opacity: 0.45; text-decoration: line-through; }

.btn-row { display: flex; gap: 8px; }
.btn-row > * { flex: 1; min-height: 48px; border-radius: 24px; font-size: 15px; }
.paper { display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; border-radius: var(--radius); font-size: 13px; }
.paper-row { display: flex; gap: 8px; }
.paper-row input { flex: 1; width: auto; }
.paper-row .btn-accent { min-height: 44px; }
.link-row { display: flex; justify-content: center; gap: 24px; }
.link { min-height: 44px; border: 0; background: none; color: var(--sub); font-size: 13px; text-decoration: underline; text-underline-offset: 4px; cursor: pointer; }
.note a { color: inherit; }

/* ---------- Mushaf reader ---------- */
.reader {
  position: fixed; z-index: 20; top: 0; bottom: 0; left: 50%; right: auto;
  width: 100%; max-width: 480px;
  display: flex; flex-direction: column;
  background: var(--paper, #FBF6EE); color: #1B1714;
  transform: translate(-50%, 100%); transition: transform 0.28s var(--ease);
}
.reader.is-open { transform: translate(-50%, 0); }
html[data-phase="suhoor"] .reader, html[data-phase="night"] .reader, html[data-phase="maghrib"] .reader, html[data-phase="day-dark"] .reader {
  --paper: #120D10; color: #F1E9DF;
}
.reader .sub { color: inherit; opacity: 0.65; }
.reader .icon-btn { background: rgba(127, 127, 127, 0.14); font-family: var(--font-display); font-weight: 700; }
.reader-top {
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  border-bottom: 1px solid rgba(127, 127, 127, 0.18);
}
.reader-title { flex: 1; display: flex; flex-direction: column; align-items: center; text-align: center; }
.reader-title b { font-family: var(--font-display); font-size: 15px; }
.reader-font { display: flex; gap: 6px; }
.mushaf { flex: 1; overflow-y: auto; padding: 18px 20px 28px; }
.mushaf-text {
  font-family: 'Amiri Quran', 'Amiri', serif;
  font-size: var(--mushaf-size, 24px); line-height: 2.25;
  text-align: justify; text-align-last: center; word-spacing: 2px;
}
.ayah-num { color: var(--accent); font-size: 0.85em; white-space: nowrap; }
.sura-head {
  margin: 8px 0 6px; padding: 6px 0; text-align: center;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); border-radius: 12px;
  font-family: var(--font-display); font-weight: 700; font-size: 16px; color: var(--accent);
}
.basmala { text-align: center; font-family: 'Amiri Quran', serif; font-size: var(--mushaf-size, 24px); line-height: 2; }
.reader-bottom {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px calc(env(safe-area-inset-bottom) + 12px);
  border-top: 1px solid rgba(127, 127, 127, 0.18);
}
.reader-progress { flex: 1; text-align: center; }
.page-btn {
  display: flex; align-items: center; gap: 4px; min-height: 44px; padding: 0 14px;
  border-radius: 22px; border: 1px solid rgba(127, 127, 127, 0.3); background: transparent; font-size: 14px; cursor: pointer;
}
.page-btn.is-next { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.page-btn:disabled { opacity: 0.35; }
.reader-toast {
  position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 84px); transform: translateX(-50%);
  padding: 12px 18px; border-radius: 22px; background: #111014; color: #fff;
  font-size: 14px; font-weight: 600; white-space: nowrap; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
}
