:root {
  --bg: #f6f0e3;
  --surface: #fffaf0;
  --ink: #2a2118;
  --muted: #6d5e4b;
  --line: #ddd0b6;
  --accent: #8a3b12;
  --accent-soft: #f1dfcb;
  --gold: #a87b2a;
  --talmud: #2f5d8a;
  --witness: #2e7046;
  --tradition: #9a6a12;
  --folklore: #8a3b6e;
  --serif: "EB Garamond", Georgia, serif;
  --hebrew: "Frank Ruhl Libre", "Times New Roman", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17130e; --surface: #221c15; --ink: #efe6d6; --muted: #b3a48c; --line: #3d3326;
    --accent: #e08a55; --accent-soft: #3a2618; --gold: #d4a64a;
    --talmud: #7fb0e0; --witness: #7cc795; --tradition: #e0b260; --folklore: #d78ebf;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17130e; --surface: #221c15; --ink: #efe6d6; --muted: #b3a48c; --line: #3d3326;
  --accent: #e08a55; --accent-soft: #3a2618; --gold: #d4a64a;
  --talmud: #7fb0e0; --witness: #7cc795; --tradition: #e0b260; --folklore: #d78ebf;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 19px/1.55 var(--serif); }
a { color: var(--accent); }
[lang="he"], .he { font-family: var(--hebrew); }
html[lang="he"] body { font-family: var(--hebrew); font-size: 18px; }
[lang="en"] { font-family: var(--serif); }
.alt { color: var(--muted); }

.site-header {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px;
  padding: 18px max(16px, calc((100vw - 1100px) / 2)); border-bottom: 1px solid var(--line); background: var(--surface);
}
.brand { text-decoration: none; color: var(--ink); display: flex; flex-direction: column; line-height: 1.1; }
.brand-he { font-family: var(--hebrew); font-size: 30px; font-weight: 700; color: var(--accent); }
.brand-en { font-size: 15px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.nav { display: flex; flex-wrap: wrap; gap: 4px; }
.nav a { text-decoration: none; color: var(--ink); padding: 6px 12px; border-radius: 999px; font-size: 17px; }
.nav a:hover { background: var(--accent-soft); }
.nav a.active { background: var(--accent); color: var(--surface); }
.lang-btn { font: 600 16px var(--serif); padding: 5px 14px; border-radius: 999px; border: 1px solid var(--accent); background: transparent; color: var(--accent); cursor: pointer; }
.lang-btn[lang="he"] { font-family: var(--hebrew); }
.lang-btn:hover { background: var(--accent-soft); }

.filters, main, .site-footer { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.filters { padding-top: 18px; display: grid; gap: 10px; }
.filters[hidden] { display: none; }
#q { width: 100%; font: inherit; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: 15px var(--serif); padding: 3px 11px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.chip .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-inline-end: 6px; vertical-align: 1px; }

main { padding-top: 24px; padding-bottom: 48px; min-height: 60vh; }
h1, h2, h3 { font-weight: 600; line-height: 1.2; }
h1 { font-size: 34px; margin: 0 0 6px; }
.lede { color: var(--muted); margin-top: 0; max-width: 720px; }

/* badges */
.badge { display: inline-block; font-size: 13px; letter-spacing: .04em; text-transform: uppercase; padding: 1px 8px; border-radius: 4px; border: 1px solid currentColor; white-space: nowrap; }
.src-talmud { color: var(--talmud); } .src-witness { color: var(--witness); }
.src-tradition { color: var(--tradition); } .src-folklore { color: var(--folklore); }
.bg-talmud { background: var(--talmud); } .bg-witness { background: var(--witness); }
.bg-tradition { background: var(--tradition); } .bg-folklore { background: var(--folklore); }

/* timeline */
.era { margin: 34px 0 6px; display: flex; align-items: baseline; gap: 12px; border-bottom: 2px solid var(--gold); padding-bottom: 4px; }
.era h2 { margin: 0; font-size: 24px; }
.era .alt { color: var(--gold); font-size: 20px; margin-inline-start: auto; }
.tl { list-style: none; margin: 0; padding: 0; padding-inline-start: 26px; border-inline-start: 2px solid var(--line); margin-inline-start: 8px; }
.tl li { position: relative; margin: 18px 0; }
.tl li::before { content: ""; position: absolute; inset-inline-start: -33px; top: 22px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }
.card { display: block; text-decoration: none; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px; transition: border-color .15s, transform .15s; }
a.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; font-size: 15px; color: var(--muted); }
.card-title { font-size: 22px; margin: 4px 0 2px; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.card-title .alt { font-size: 18px; }
.card p { margin: 6px 0 0; }
.year { font-weight: 600; color: var(--accent); }

/* map */
#map { height: min(70vh, 640px); border-radius: 12px; border: 1px solid var(--line); z-index: 0; }
.leaflet-popup-content { font: 16px/1.4 var(--serif); }
.leaflet-popup-content a { display: block; margin: 3px 0; }
.pin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.35); }
.pin-count { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; display: grid; place-items: center; color: #fff; font: 600 13px var(--serif); box-shadow: 0 0 0 1px rgba(0,0,0,.35); }
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-inline-end: 6px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 10px 0; font-size: 15px; color: var(--muted); }

/* grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.rabbi-alt { font-size: 20px; color: var(--accent); }

/* story page */
.story { max-width: 740px; }
.story h1 .alt { display: block; font-size: 24px; margin-top: 4px; text-align: start; }
.story p { font-size: 20px; }
.box { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px; margin: 20px 0; }
.box h3 { margin: 0 0 6px; font-size: 18px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.box ul { margin: 0; padding-inline-start: 20px; }
.note { border-inline-start: 4px solid var(--gold); }
.photo { margin: 24px 0; }
.photo img { display: block; width: 100%; max-width: 520px; height: auto; border-radius: 10px; border: 1px solid var(--line); }
.photo figcaption { font-size: 16px; color: var(--muted); font-style: italic; margin-top: 6px; }
.back { display: inline-block; margin-bottom: 14px; font-size: 16px; }
.empty { color: var(--muted); font-style: italic; }

/* golem chain */
.chain { list-style: none; padding: 0; margin: 24px 0; counter-reset: c; }
.chain li { display: grid; grid-template-columns: 96px 1fr; gap: 16px; margin-bottom: 14px; }
.chain .when { text-align: end; font-weight: 600; color: var(--accent); padding-top: 16px; }

/* submission form */
.form fieldset { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); padding: 14px 18px 18px; margin: 0 0 18px; }
.form legend { font-weight: 600; padding: 0 6px; }
.form label { display: block; margin-top: 12px; }
.form input:not([type=radio]):not([type=checkbox]), .form select, .form textarea {
  display: block; width: 100%; margin-top: 4px; font: inherit; font-size: 18px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink);
}
.form textarea { resize: vertical; }
.form .radio { display: flex; gap: 10px; align-items: baseline; }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form .hint { margin: 4px 0 8px; font-size: 16px; color: var(--muted); }
.form .photo-in { margin-top: 8px; }
.form .req { color: var(--accent); }
.form .error { color: var(--accent); font-weight: 600; }
.form [hidden] { display: none; }
.hp { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.submit { font: 600 19px var(--serif); padding: 10px 26px; border: 0; border-radius: 999px; background: var(--accent); color: var(--surface); cursor: pointer; }
.submit:hover { filter: brightness(1.08); }
.share-cta { margin-top: 24px; }
@media (max-width: 600px) { .form .row { grid-template-columns: 1fr; } }
main.story { max-width: 740px; margin: 0 auto; }

.site-footer { color: var(--muted); font-size: 15px; border-top: 1px solid var(--line); padding-top: 14px; padding-bottom: 30px; }

@media (max-width: 600px) {
  body { font-size: 18px; }
  h1 { font-size: 28px; }
  .chain li { grid-template-columns: 1fr; gap: 2px; }
  .chain .when { text-align: start; padding-top: 0; }
  .tl { padding-inline-start: 18px; }
  .tl li::before { inset-inline-start: -25px; }
}

/* in Hebrew mode the English subtitle is an LTR span; keep it on the reading side */
html[dir="rtl"] .story h1 .alt { text-align: right; }
