:root {
  --bg: #fbfaf7;
  --fg: #1d1c1a;
  --muted: #6a6560;
  --line: #ddd8d0;
  --accent: #7a4f1d;
  --mark: #ffe9a8;
  --card: #fff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614;
    --fg: #ece8e1;
    --muted: #a49d94;
    --line: #35322d;
    --accent: #d7a76a;
    --mark: #5c4a1c;
    --card: #201e1b;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "Frank Ruhl Libre", "Times New Roman", "David", serif;
  font-size: 18px;
  line-height: 1.75;
}

header {
  border-bottom: 1px solid var(--line);
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 5;
}

nav {
  max-width: 900px;
  margin: 0 auto;
  padding: .6rem 1rem;
  display: flex;
  gap: 1rem;
  align-items: baseline;
  flex-wrap: wrap;
}

nav a { color: var(--fg); text-decoration: none; }
nav a:hover { text-decoration: underline; }
.brand { font-weight: 700; font-size: 1.25rem; color: var(--accent); }

main { max-width: 900px; margin: 0 auto; padding: 1rem; }

footer {
  max-width: 900px;
  margin: 2rem auto;
  padding: 1rem;
  color: var(--muted);
  font-size: .85rem;
  border-top: 1px solid var(--line);
}

h1 { font-size: 1.5rem; margin: .4rem 0 1rem; }
h2 { font-size: 1.2rem; margin: 1.6rem 0 .6rem; }

form.search {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: .7rem;
  align-items: end;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem;
}

label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .25rem; }

input, select, button {
  width: 100%;
  padding: .55rem .6rem;
  font: inherit;
  font-size: 1rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
}

button {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
  cursor: pointer;
  font-weight: 600;
}
button:hover { filter: brightness(1.08); }

/* Selecteur du mode de recherche : les regles generiques ci-dessus etirent tout
   input sur 100 %, ce qui deformerait les boutons radio. */
.label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .25rem; }

.modes { display: flex; flex-wrap: wrap; gap: .4rem; }

label.mode {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  margin: 0;
  padding: .45rem .7rem;
  font-size: .95rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
}
label.mode:has(input:checked) { border-color: var(--accent); color: var(--accent); }
label.mode input { width: auto; margin: 0; padding: 0; }

.count { color: var(--muted); font-size: .9rem; margin: 1.2rem 0 .4rem; }
.count .fts {
  display: inline-block;
  direction: ltr;
  margin-inline-start: .5rem;
  padding: .05rem .35rem;
  font-size: .8rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 5px;
}

.result {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .85rem 1rem;
  margin-bottom: .8rem;
}

.trail { font-size: .78rem; color: var(--muted); margin-bottom: .4rem; }
.trail span::after { content: " ‹ "; }
.trail span:last-child::after { content: ""; }

.sentence { margin: .3rem 0; }
.note {
  font-size: .93rem;
  color: var(--muted);
  border-inline-start: 3px solid var(--line);
  padding-inline-start: .7rem;
  margin: .5rem 0 .2rem;
}

mark { background: var(--mark); color: inherit; padding: 0 .12em; border-radius: 3px; }

.links { font-size: .82rem; margin-top: .45rem; display: flex; gap: .9rem; flex-wrap: wrap; }
.links a { color: var(--accent); }

a.ref { color: var(--accent); text-decoration: none; border-bottom: 1px dotted; }
a.ref:hover { background: var(--mark); }

.fnref { font-size: .7em; }
.fnref a { color: var(--accent); text-decoration: none; padding: 0 .15em; }

.body p { margin: 0 0 .9rem; text-align: justify; }

.notes { border-top: 1px solid var(--line); margin-top: 2rem; padding-top: 1rem; }
.notes li { margin-bottom: .55rem; font-size: .93rem; }
.notes ol { padding-inline-start: 1.4rem; }

.daf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: .5rem;
  margin-top: 1rem;
}

.daf {
  display: block;
  text-align: center;
  padding: .5rem .3rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  text-decoration: none;
  color: var(--fg);
}
.daf:hover { border-color: var(--accent); }
.daf b { display: block; font-size: 1.05rem; }
.daf small { color: var(--muted); font-size: .74rem; }

.empty { color: var(--muted); padding: 1.5rem 0; }
.error { background: #fde8e4; color: #7d2318; border-radius: 8px; padding: .7rem 1rem; }
@media (prefers-color-scheme: dark) { .error { background: #4a201a; color: #f4c9c0; } }

table { width: 100%; border-collapse: collapse; }
td, th { text-align: start; padding: .35rem .5rem; border-bottom: 1px solid var(--line); }

@media (max-width: 560px) {
  body { font-size: 17px; }
  main { padding: .8rem; }
  form.search { grid-template-columns: 1fr 1fr; }
}

/* ------------------------------------------------------------ deux volets */

/* La page de resultats a besoin de plus que les 900 px de lecture confortable
   des autres pages : elle en montre deux cote a cote. */
main.wide { max-width: 1500px; }

/* En RTL le premier enfant d'un flex est a droite : les resultats sont donc en
   premier dans le flux et le volet de lecture se place a gauche, sans avoir a
   inverser quoi que ce soit en JavaScript. */
.split { display: flex; align-items: flex-start; }

.pane { min-width: 0; }

/* --results-w est pose par le script, depuis localStorage. */
.split.open > .pane-results { flex: 0 0 var(--results-w, 50%); }
.split.open > .pane-source { flex: 1 1 0; }

/* Tant qu'aucune source n'est ouverte, les resultats prennent toute la largeur
   et le volet n'occupe pas de place — il n'a rien a montrer. */
.split.closed > .pane-results { flex: 1 1 100%; }
.split.closed > .pane-source,
.split.closed > .resizer { display: none; }

.resizer {
  flex: 0 0 11px;
  align-self: stretch;
  min-height: 60vh;
  cursor: col-resize;
  background: transparent;
  position: relative;
}
.resizer::before {
  content: "";
  position: absolute;
  top: 0; bottom: 0; left: 5px;
  width: 1px;
  background: var(--line);
}
.resizer:hover::before, .resizer.dragging::before {
  background: var(--accent);
  width: 3px;
  left: 4px;
}

/* Le volet suit la lecture : il reste en vue et defile pour son propre compte,
   sinon une page longue obligerait a remonter tout le texte pour revenir aux
   resultats. */
.pane-source {
  position: sticky;
  top: 4rem;
  max-height: calc(100vh - 5rem);
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.source-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .4rem .6rem;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.source-title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: .85rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

button.icon {
  width: auto;
  flex: 0 0 auto;
  padding: .1rem .5rem;
  font-size: 1rem;
  line-height: 1.4;
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
}
button.icon:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); filter: none; }
button.icon:disabled { opacity: .35; cursor: default; }

.source-body { flex: 1 1 auto; overflow: auto; padding: .3rem 1rem 1.5rem; }
.source-body h1 { font-size: 1.2rem; }
/* Le volet reprend le fragment de la page complete, titre de niveau 1 compris ;
   on ne cherche pas a le distinguer de la page autonome, juste a le tasser. */
.source-body .page-body > .links { margin-bottom: .8rem; }

.pane-hint { color: var(--muted); font-size: .88rem; margin: .2rem 0 1rem; }
.split.open .pane-hint { display: none; }

.loading { color: var(--muted); padding: 1.5rem 0; }

/* Resultat dont la source est ouverte dans le volet. */
.result.is-active { border-color: var(--accent); }

/* Passage vise par le resultat clique, retrouve dans le texte du volet. */
.source-body mark.target { outline: 2px solid var(--accent); }

/* Sous 900 px les deux volets ne tiennent plus cote a cote : le volet passe
   par-dessus les resultats, qui restent intacts derriere lui. */
@media (max-width: 900px) {
  .split { display: block; }
  .split.open > .pane-results { flex: none; }
  .split > .resizer { display: none; }
  .split.open > .pane-source {
    position: fixed;
    inset: 0;
    z-index: 20;
    max-height: none;
    border-radius: 0;
  }
}

/* -------------------------------------------- pages liees par co-citation */

/* Le panneau prolonge l'appareil de la page — il suit les notes et se lit
   comme elles. Il est rendu dans le fragment, donc identique dans le volet de
   lecture et sur la page autonome. */
.cocit { border-top: 1px solid var(--line); margin-top: 2rem; padding-top: 1rem; }
.cocit h2 { font-size: 1.02rem; margin: 0 0 .3rem; }
.cocit-note { font-size: .8rem; color: var(--muted); margin: 0 0 .8rem; }

.cocit-list { list-style: none; margin: 0; padding: 0; }
.cocit-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .55rem .75rem;
  margin-bottom: .45rem;
}
/* Les pages du meme ouvrage font 30,9 % des liens contre 10,2 % au hasard :
   assez pour etre signalees, trop peu pour etre ecartees. */
.cocit-item.is-same-book { border-inline-start: 3px solid var(--accent); }

.cocit-page { display: block; text-decoration: none; color: var(--fg); }
.cocit-page:hover .cocit-heading { color: var(--accent); }
.cocit-book { display: block; font-size: .76rem; color: var(--muted); }
.cocit-heading { display: block; font-size: .95rem; line-height: 1.35; }

.cocit-badge {
  display: inline-block;
  font-size: .7rem;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 .45rem;
  margin-top: .25rem;
}

/* Ce qui justifie le lien, et rien d'autre : les references citees de part et
   d'autre. Chacune relance la recherche par reference de la tache 13. */
.cocit-shared { display: block; margin-top: .3rem; font-size: .85rem; }
.cocit-shared a.ref { border-bottom: none; }
.cocit-shared mark { padding: .05em .3em; }

@media (max-width: 560px) {
  .cocit-item { padding: .5rem .6rem; }
  .cocit-heading { font-size: .92rem; }
}

/* Shulhan Aroukh haRav : table des matieres, lecture par siman, pagination. */
.muted { color: var(--muted); font-size: .85em; }
.sa-toc details { margin: .2rem 0; }
.sa-toc summary { cursor: pointer; padding: .2rem 0; }
.sa-part > summary { font-weight: 700; font-size: 1.1rem; color: var(--accent); }
.sa-hil { margin-inline-start: 1rem; }
.sa-simanim { margin: .2rem 0 .6rem; padding-inline-start: 1.4rem; }
.sa-simanim a { color: var(--fg); text-decoration: none; }
.sa-simanim a:hover { text-decoration: underline; }
.sa-nav { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: space-between; margin: .8rem 0; }
.sa-seif { border-top: 1px solid var(--line); padding-top: .4rem; }
.sa-seif h2 { font-size: 1.05rem; margin: .6rem 0 .2rem; }
.sa-seif h2 a { color: var(--accent); text-decoration: none; }
.sa-seif .notes summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
.pager { display: flex; gap: 1.2rem; justify-content: center; margin: 1.2rem 0; }

/* Appels de note et notes : degager l'en-tete collant au saut natif, et
   signaler brievement la cible atteinte (voir notes.js). */
[id^="ref-"], [id^="note-"], [id*="-ref-"], [id*="-note-"] { scroll-margin-top: 5rem; scroll-margin-bottom: 2rem; }
.fnref:target, .notes li:target { background: var(--mark); border-radius: 3px; }
.flash { animation: flash 1.8s ease-out; border-radius: 3px; }
@keyframes flash { 0%, 40% { background: var(--mark); } 100% { background: transparent; } }
.fnref a, .notes li > a:first-child { cursor: pointer; }

/* Liste des massekhtot (voir combo.js) : haute, lisible, au-dessus du reste. */
.combo { position: relative; }
.combo-list {
  position: absolute;
  inset-inline: 0;
  top: calc(100% + 4px);
  z-index: 20;
  min-width: 14rem;
  max-height: min(70vh, 34rem);
  overflow-y: auto;
  margin: 0;
  padding: .3rem 0;
  list-style: none;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .15);
}
.combo-list li { padding: .45rem .9rem; font-size: 1.05rem; cursor: pointer; }
.combo-list li:hover, .combo-list li.active { background: var(--mark); }
.combo-list li.current { font-weight: 700; color: var(--accent); }

/* Facettes de la recherche plein texte : un lien par ouvrage, avec son compte. */
.facets { display: flex; flex-wrap: wrap; gap: .3rem .5rem; align-items: baseline; margin: .4rem 0 .8rem; font-size: .92rem; }
.facets .label { color: var(--muted); }
.facets a { padding: .1rem .5rem; border: 1px solid var(--line); border-radius: 1rem; text-decoration: none; white-space: nowrap; }
.facets a.on { background: var(--accent); color: var(--bg); border-color: transparent; }
.facets .n { opacity: .7; font-size: .85em; }
label.variants { font-size: .9rem; }

/* Texte Sefaria a cote des resultats d'une reference */
.sefaria { margin: 0.5rem 0 1rem; }
.sefaria-text { border: 1px solid var(--line); border-radius: 6px; padding: 0.5rem 0.75rem; background: var(--card); }
.sefaria-text summary { cursor: pointer; font-weight: 600; }
.sefaria-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; max-height: 22rem; overflow-y: auto; margin-top: 0.5rem; }
.sefaria-version p { margin: 0 0 0.4rem; line-height: 1.6; }
.sefaria-version[lang="en"] { font-family: Georgia, serif; font-size: 0.92em; }
.sefaria-license, .sefaria-src, .sefaria-none { color: var(--muted); font-size: 0.85em; }
@media (max-width: 700px) { .sefaria-cols { grid-template-columns: 1fr; } }

/* Pages qui renvoient a la page courante */
.cited-by { margin-top: 1.5rem; border-top: 1px solid var(--line); padding-top: 0.75rem; }
.cited-by h2 { font-size: 1.05rem; }
.cited-by ol { padding-inline-start: 1.2rem; }
.cited-by li { margin-bottom: 0.3rem; }
.cited-by .raw { color: var(--muted); font-size: 0.85em; margin-inline-start: 0.5rem; }

button.copy-ref { font: inherit; font-size: 0.9em; border: 1px solid var(--line); background: var(--bg); color: var(--accent); border-radius: 4px; padding: 0.1rem 0.5rem; cursor: pointer; }
a.xref { color: var(--accent); text-decoration: underline dotted; }

/* Calendrier */
.muted { color: var(--muted); }
.today { margin-top: 1.25rem; }
.sichot, .parasha-index { padding-inline-start: 1.2rem; }
.parasha-index { columns: 4 10rem; }
.parasha-index li { break-inside: avoid; }
