:root {
  --bg: #f5f1e8;
  --surface: #ffffff;
  --surface-2: #efe8da;
  --text: #17202c;
  --muted: #5b6472;
  --border: #e1d8c6;
  --accent: #0e6b58;
  --accent-soft: #d6ebe4;
  --gold: #b7802a;
  --gold-soft: #f6e7c8;
  --danger: #a33b2b;
  --shadow: 0 1px 2px rgb(23 32 44 / 6%), 0 8px 24px rgb(23 32 44 / 8%);
  --radius: 18px;
  --night: #16233b;
  --dawn: #e9a86b;
  --day: #8fd0e8;
  --dusk: #c8607a;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-arabic: "Geeza Pro", "Noto Naskh Arabic", "Segoe UI", "Arabic Typesetting", serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a1120;
    --surface: #111b2e;
    --surface-2: #17233a;
    --text: #edf1f7;
    --muted: #9ba7ba;
    --border: #23314b;
    --accent: #52c7a6;
    --accent-soft: #143a35;
    --gold: #e8b65a;
    --gold-soft: #3a2e17;
    --danger: #f08a78;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a1120;
  --surface: #111b2e;
  --surface-2: #17233a;
  --text: #edf1f7;
  --muted: #9ba7ba;
  --border: #23314b;
  --accent: #52c7a6;
  --accent-soft: #143a35;
  --gold: #e8b65a;
  --gold-soft: #3a2e17;
  --danger: #f08a78;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 25%);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-underline-offset: 3px; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 6px; }
.ar { font-family: var(--font-arabic); direction: rtl; unicode-bidi: isolate; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wrap { width: min(1100px, 100% - 32px); margin-inline: auto; }

/* Header */
.site-header { padding: 18px 0; }
.site-header .wrap { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; letter-spacing: -0.01em; font-size: 1.1rem; }
.brand svg { width: 30px; height: 30px; color: var(--gold); }
.site-nav { display: flex; gap: 4px; flex-wrap: wrap; }
.site-nav a, .site-nav button {
  border: 0; background: none; color: var(--muted); text-decoration: none; padding: 8px 12px; border-radius: 999px; font-size: 0.95rem;
}
.site-nav a:hover, .site-nav button:hover { background: var(--surface-2); color: var(--text); }

/* Hero */
.hero {
  position: relative;
  border-radius: 28px;
  padding: clamp(20px, 4vw, 40px);
  color: #f4f6fb;
  background: var(--sky, linear-gradient(160deg, #10203d 0%, #1d3a63 55%, #2c5a7c 100%));
  box-shadow: var(--shadow);
  overflow: hidden;
  isolation: isolate;
}
.hero::after {
  content: "";
  position: absolute; inset: auto -10% -60% auto; width: 70%; aspect-ratio: 1;
  background: radial-gradient(circle, rgb(255 255 255 / 10%), transparent 60%);
  z-index: -1;
}
.hero-top { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px 24px; }
.hero h1 { margin: 0; font-size: clamp(1.5rem, 3.6vw, 2.2rem); line-height: 1.15; letter-spacing: -0.02em; font-weight: 700; }
.place-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 14px; border-radius: 999px; border: 1px solid rgb(255 255 255 / 22%);
  background: rgb(255 255 255 / 10%); color: inherit; font-size: 0.95rem; backdrop-filter: blur(6px);
}
.chip:hover { background: rgb(255 255 255 / 18%); }
.chip svg { width: 18px; height: 18px; flex: none; }
.dates { margin: 6px 0 0; color: rgb(244 246 251 / 80%); font-size: 0.98rem; }
.dates .sep { margin: 0 8px; opacity: 0.6; }

.next { margin: clamp(20px, 4vw, 36px) 0 clamp(16px, 3vw, 28px); display: grid; gap: 2px; }
.next-label { margin: 0; text-transform: uppercase; letter-spacing: 0.12em; font-size: 0.78rem; color: rgb(244 246 251 / 75%); }
.next-name { margin: 0; font-size: clamp(2.4rem, 8vw, 4.4rem); line-height: 1; font-weight: 750; letter-spacing: -0.03em; display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.next-name .ar { font-size: 0.55em; font-weight: 400; opacity: 0.85; }
.next-meta { margin: 6px 0 0; font-size: 1.15rem; color: rgb(244 246 251 / 90%); }
.next-meta strong { font-variant-numeric: tabular-nums; }

.times { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
.times li {
  border-radius: 16px; padding: 12px 12px 14px; background: rgb(255 255 255 / 9%); border: 1px solid rgb(255 255 255 / 12%);
  display: grid; gap: 2px; min-width: 0;
}
.times .name { font-size: 0.9rem; font-weight: 600; display: flex; justify-content: space-between; gap: 6px; }
.times .name .ar { font-weight: 400; opacity: 0.75; }
.times .time { font-size: 1.55rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.times .hint { font-size: 0.75rem; opacity: 0.7; }
.times li.past { opacity: 0.55; }
.times li.current { background: rgb(255 255 255 / 92%); color: #12203a; border-color: transparent; opacity: 1; }
.times li.current .hint { opacity: 0.8; }
.times li.secondary .time { font-weight: 500; }

.daybar { position: relative; margin-top: 22px; height: 54px; }
.daybar-track { position: absolute; inset: 0 0 auto; height: 12px; border-radius: 999px; background: var(--daybar, #222); box-shadow: inset 0 0 0 1px rgb(255 255 255 / 15%); }
.daybar-mark { position: absolute; top: -3px; width: 2px; height: 18px; background: rgb(255 255 255 / 85%); border-radius: 2px; transform: translateX(-1px); }
.daybar-label { position: absolute; top: 22px; transform: translateX(-50%); font-size: 0.72rem; color: rgb(244 246 251 / 80%); white-space: nowrap; }
.daybar-now { position: absolute; top: -6px; width: 24px; height: 24px; transform: translateX(-12px); border-radius: 50%; background: #ffd27a; box-shadow: 0 0 0 4px rgb(255 210 122 / 30%), 0 0 18px #ffd27a; }
.daybar-hours { position: absolute; inset: auto 0 0; display: flex; justify-content: space-between; font-size: 0.68rem; color: rgb(244 246 251 / 55%); }

.day-nav { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.day-nav input[type="date"] { border: 1px solid rgb(255 255 255 / 22%); background: rgb(255 255 255 / 10%); border-radius: 999px; padding: 7px 12px; color: inherit; color-scheme: dark; }

/* Sections */
main > section:not(.hero) { margin-top: 28px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: clamp(18px, 3vw, 28px); box-shadow: var(--shadow); }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.section-head h2, .card h2 { margin: 0; font-size: 1.35rem; letter-spacing: -0.01em; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 8px 14px; font-size: 0.92rem; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn-icon { padding: 8px 10px; }
.btn svg { width: 18px; height: 18px; }
.btn-group { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* Month table */
.table-scroll { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
table.month { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; min-width: 640px; }
.month th, .month td { padding: 9px 10px; text-align: center; border-bottom: 1px solid var(--border); white-space: nowrap; }
.month thead th { position: sticky; top: 0; background: var(--surface); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.month th[scope="row"] { text-align: left; font-weight: 600; }
.month .hijri { color: var(--muted); font-size: 0.85rem; }
.month tr.friday th[scope="row"]::after { content: " · Jumu'a"; color: var(--gold); font-weight: 500; font-size: 0.82rem; }
.month tr.ramadan { background: var(--gold-soft); }
.month tr.today { background: var(--accent-soft); }
.month tr.today th[scope="row"] { color: var(--accent); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 14px; font-size: 0.85rem; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: 6px; vertical-align: -1px; }
.legend .l-today::before { background: var(--accent-soft); border: 1px solid var(--accent); }
.legend .l-ramadan::before { background: var(--gold-soft); border: 1px solid var(--gold); }

/* Settings */
.settings-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.field { display: grid; gap: 6px; align-content: start; }
.field label { font-weight: 600; font-size: 0.92rem; }
.field select { width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 12px; padding: 10px 12px; }
.field small { color: var(--muted); font-size: 0.82rem; }

/* Content */
.content-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 24px; }
.prose h2 { margin-top: 0; }
.prose h3 { margin: 22px 0 6px; font-size: 1.05rem; }
.prose p { margin: 0 0 12px; color: var(--muted); }
.prose p strong { color: var(--text); }
.prayer-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.prayer-list li { display: grid; grid-template-columns: 92px 1fr; gap: 12px; align-items: baseline; }
.prayer-list b { font-size: 1.02rem; }
.prayer-list span { color: var(--muted); font-size: 0.95rem; }
details { border-top: 1px solid var(--border); padding: 12px 0; }
details:last-of-type { border-bottom: 1px solid var(--border); }
summary { cursor: pointer; font-weight: 600; list-style-position: outside; }
details p { margin: 8px 0 0; color: var(--muted); }

.cities { columns: 4 180px; column-gap: 24px; margin: 0; padding: 0; list-style: none; }
.cities li { break-inside: avoid; padding: 3px 0; }
.cities a { color: var(--text); text-decoration: none; }
.cities a:hover { color: var(--accent); text-decoration: underline; }
.cities small { color: var(--muted); }

/* Footer */
.site-footer { margin: 48px 0 32px; color: var(--muted); font-size: 0.9rem; }
.site-footer .wrap { display: flex; flex-wrap: wrap; gap: 12px 24px; justify-content: space-between; border-top: 1px solid var(--border); padding-top: 20px; }
.site-footer nav { display: flex; gap: 18px; flex-wrap: wrap; }
.site-footer a { color: var(--muted); }

/* Search dialog */
dialog.search {
  width: min(560px, 100% - 32px); border: 1px solid var(--border); border-radius: 22px; padding: 0;
  background: var(--surface); color: var(--text); box-shadow: 0 30px 80px rgb(0 0 0 / 35%);
}
dialog.search::backdrop { background: rgb(10 17 32 / 55%); backdrop-filter: blur(3px); }
.search-head { display: flex; gap: 8px; padding: 14px; border-bottom: 1px solid var(--border); align-items: center; }
.search-head input { flex: 1; border: 0; background: var(--surface-2); border-radius: 12px; padding: 12px 14px; font-size: 1.05rem; min-width: 0; }
.search-results { list-style: none; margin: 0; padding: 8px; max-height: min(420px, 60vh); overflow: auto; }
.search-results button { width: 100%; text-align: left; border: 0; background: none; border-radius: 12px; padding: 10px 12px; display: grid; }
.search-results button:hover, .search-results button[aria-selected="true"] { background: var(--surface-2); }
.search-results small { color: var(--muted); }
.search-status { padding: 14px 18px; color: var(--muted); margin: 0; }

/* Plain pages (legal) */
.page { max-width: 760px; }
.page h1 { font-size: 2rem; letter-spacing: -0.02em; }

@media (max-width: 860px) {
  .times { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .settings-grid, .content-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .site-nav { display: none; }
  .card { padding: 16px 12px; }
  .card h2 { padding-inline: 4px; }
  table.month { min-width: 0; font-size: 0.84rem; }
  .month th, .month td { padding: 8px 2px; }
  .cities { columns: 2; }
  .month thead th { font-size: 0.6rem; letter-spacing: 0; }
  .month .hijri { display: none; }
  .month tr.friday th[scope="row"]::after { content: none; }
  .month tr.friday th[scope="row"] { color: var(--gold); }
  .legend::after { content: "Vendredi en doré"; color: var(--gold); }
}
@media (max-width: 480px) {
  .times { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .times .time { font-size: 1.35rem; }
  .daybar-label { display: none; }
}

@media print {
  .site-header, .hero, .site-footer, #parametres, .content, #villes, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border: 0; padding: 0; }
  .month tr.today, .month tr.ramadan { background: #eee; }
}

@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

/* Theme toggle */
.header-actions { display: flex; align-items: center; gap: 8px; }
.theme-toggle {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 0.88rem;
}
.theme-toggle:hover { background: var(--surface-2); }
.theme-toggle svg { width: 17px; height: 17px; flex: none; }
@media (max-width: 480px) { .theme-toggle .theme-label { display: none; } .theme-toggle { padding: 6px 9px; } }
