:root {
  --bg: #f6f2ea;
  --surface: #ffffff;
  --surface-2: #efe9dd;
  --text: #1c2523;
  --muted: #5d6865;
  --line: #e2dccf;
  --brand: #0f5c55;
  --brand-ink: #ffffff;
  --brand-soft: #dcebe8;
  --gold: #b07d1e;
  --gold-soft: #f6ead0;
  --night: #13233f;
  --night-2: #2a3f69;
  --shadow: 0 1px 2px rgba(20, 30, 28, .06), 0 6px 20px rgba(20, 30, 28, .06);
  --radius: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1514;
    --surface: #13201f;
    --surface-2: #1a2a28;
    --text: #e8efed;
    --muted: #9fb0ac;
    --line: #253634;
    --brand: #5cc2b4;
    --brand-ink: #062320;
    --brand-soft: #173b37;
    --gold: #e2b35a;
    --gold-soft: #33280f;
    --night: #0f1a30;
    --night-2: #23365c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0 auto;
  max-width: 720px;
  min-height: 100vh;
  padding: 0 16px calc(32px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Arabic", Tahoma, Arial, sans-serif;
}
[dir="rtl"] body { font-family: "Segoe UI", "Noto Sans Arabic", "Noto Naskh Arabic", "Geeza Pro", Tahoma, system-ui, sans-serif; }
button, select, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
/* Times and countdowns always read left to right, even in Arabic. */
.num { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 8px; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 0 10px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { flex: none; border-radius: 10px; }
.brand h1 { margin: 0; font-size: 1.15rem; line-height: 1.2; }
.dates { margin: 2px 0 0; color: var(--muted); font-size: .85rem; line-height: 1.3; display: flex; flex-direction: column; }
#hijri { color: var(--gold); font-weight: 600; }
.langs { display: flex; gap: 4px; flex: none; }
.langs button {
  min-width: 40px; height: 36px; padding: 0 8px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: .85rem; font-weight: 600;
}
.langs button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

/* ---------- place picker ---------- */
.place { display: flex; gap: 8px; margin: 6px 0 4px; }
.place select {
  flex: 1; min-width: 0; height: 46px; padding: 0 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: 1rem;
}
.ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 46px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; white-space: nowrap; color: var(--brand); font-weight: 600;
}
.ghost.icon { width: 46px; padding: 0; font-size: 1.6rem; line-height: 1; }
[dir="rtl"] .ghost.icon { transform: scaleX(-1); }
.msg { margin: 6px 0 0; padding: 8px 12px; border-radius: 10px; background: var(--gold-soft); font-size: .9rem; }

@media (max-width: 420px) {
  .place .locate-text { display: none; }
  .place .ghost { width: 46px; padding: 0; }
}

/* ---------- tabs ---------- */
.tabs {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin: 12px 0 14px;
  padding: 4px; border-radius: 14px; background: var(--surface-2);
}
.tabs button {
  height: 40px; border: 0; border-radius: 10px; background: transparent; cursor: pointer; font-weight: 600; color: var(--muted);
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- cards ---------- */
.card { background: var(--surface); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 14px; }
.label { margin: 0; color: var(--muted); font-size: .9rem; font-weight: 600; }
.big { margin: 2px 0; font-size: clamp(2.6rem, 13vw, 3.6rem); font-weight: 700; letter-spacing: -.02em; line-height: 1.05; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: .95rem; }

.next { background: linear-gradient(135deg, var(--brand) 0%, #13786f 100%); color: #fff; }
.next .label, .next .sub { color: rgba(255, 255, 255, .82); }
.next-name { margin: 4px 0 0; font-size: 1.5rem; font-weight: 700; }
/* In Ramadan the big countdown is the iftar/imsak one; the next prayer gets a slim card. */
.next.compact { display: grid; grid-template-columns: 1fr auto; column-gap: 12px; align-items: center; padding: 12px 18px; }
.next.compact .label { grid-column: 1; }
.next.compact .next-name { grid-column: 1; margin: 0; font-size: 1.2rem; }
.next.compact .sub { grid-column: 1; margin: 0; }
.next.compact .big { grid-column: 2; grid-row: 1 / span 3; font-size: 1.9rem; margin: 0; }
@media (prefers-color-scheme: dark) {
  .next { background: linear-gradient(135deg, #0f4a45 0%, #146b62 100%); }
}

.ramadan {
  position: relative; overflow: hidden; color: #fff;
  background: radial-gradient(120% 90% at 85% 0%, var(--night-2) 0%, var(--night) 60%);
}
[dir="rtl"] .ramadan { background: radial-gradient(120% 90% at 15% 0%, var(--night-2) 0%, var(--night) 60%); }
.ramadan::after {
  content: ""; position: absolute; inset-inline-end: 18px; top: 16px; width: 44px; height: 44px; border-radius: 50%;
  box-shadow: -10px 6px 0 0 #f2c66d; transform: rotate(-20deg); opacity: .95;
}
[dir="rtl"] .ramadan::after { box-shadow: 10px 6px 0 0 #f2c66d; transform: rotate(20deg); }
.ramadan .kicker, .preview-note { margin-inline-end: 60px; }
.ramadan .kicker { margin-top: 0; margin-bottom: 6px; color: #f2c66d; font-weight: 700; letter-spacing: .02em; }
.ramadan .label, .ramadan .sub { color: rgba(255, 255, 255, .8); }
.preview-note { margin-top: 0; margin-bottom: 8px; padding: 6px 10px; border-radius: 8px; background: rgba(255, 255, 255, .12); font-size: .85rem; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.pair div { background: rgba(255, 255, 255, .1); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; }
.pair span { font-size: .85rem; color: rgba(255, 255, 255, .8); }
.pair strong { font-size: 1.35rem; }

/* ---------- today's list ---------- */
.times { list-style: none; margin: 0; padding: 6px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 14px; border-radius: 12px; font-size: 1.08rem;
}
.row + .row { border-top: 1px solid var(--line); }
.row .name { font-weight: 600; }
.row .time { font-weight: 700; font-size: 1.15rem; }
.row.minor .name, .row.minor .time { color: var(--muted); font-weight: 500; }
.row.past { opacity: .55; }
.row.is-next { background: var(--brand-soft); border-top-color: transparent; }
.row.is-next + .row { border-top-color: transparent; }
.row.is-next .name, .row.is-next .time { color: var(--brand); }
.row.is-next .name::after {
  content: ""; display: inline-block; width: 8px; height: 8px; margin-inline-start: 8px; border-radius: 50%;
  background: var(--gold); vertical-align: middle;
}
.tz { margin: 10px 4px 0; color: var(--muted); font-size: .85rem; text-align: center; }

/* ---------- month ---------- */
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.month-nav h2 { margin: 0; text-align: center; font-size: 1.1rem; display: flex; flex-direction: column; }
.month-nav h2 small { color: var(--muted); font-weight: 500; font-size: .8rem; }
.table-wrap { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
table.month { width: 100%; border-collapse: collapse; font-size: .9rem; }
.month th, .month td { padding: 6px 3px; text-align: center; white-space: nowrap; }
.month thead th {
  position: sticky; top: 0; background: var(--surface-2); color: var(--muted); font-size: .78rem; font-weight: 700;
}
.month tbody th { font-weight: 700; line-height: 1.1; min-width: 40px; text-align: center; }
.month tbody th > span, .month tbody th > small { display: block; }
.month tbody th small { color: var(--muted); font-weight: 500; font-size: .7rem; }
.month tbody th small.hday { color: var(--gold); font-weight: 600; }
.month tbody tr + tr { border-top: 1px solid var(--line); }
.month tr.friday { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.month tr.today { background: var(--brand-soft); }
.month tr.today td, .month tr.today th { color: var(--brand); font-weight: 700; }
.month.wide { font-size: .84rem; }

/* ---------- settings ---------- */
.setting h2 { margin: 0 0 6px; font-size: 1.05rem; }
.help { margin: 6px 0; color: var(--muted); font-size: .92rem; }
.help.strong { color: var(--text); font-weight: 600; }
.seg { display: inline-grid; grid-template-columns: repeat(3, 64px); gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-2); margin: 6px 0; }
.seg button { height: 40px; border: 0; border-radius: 9px; background: transparent; cursor: pointer; font-weight: 700; }
.seg button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }
.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; font-weight: 600; }
.switch input { width: 22px; height: 22px; accent-color: var(--brand); flex: none; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #2fa36b; }
.primary {
  margin-top: 8px; height: 46px; padding: 0 18px; border: 0; border-radius: 12px;
  background: var(--brand); color: var(--brand-ink); font-weight: 700; cursor: pointer;
}

/* ---------- desktop ---------- */
@media (min-width: 760px) {
  body { padding-top: 12px; }
  .brand h1 { font-size: 1.4rem; }
  #view-today { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
  #view-today .ramadan, #view-today .next { margin-bottom: 0; }
  #view-today .ramadan { grid-column: 1 / -1; }
  #view-today .tz { grid-column: 1 / -1; margin-top: 0; }
  .month th, .month td { padding: 9px 8px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
