:root {
  --bg: #f4ecdc;
  --paper: #fbf6ea;
  --ink: #2b2118;
  --muted: #7a6a58;
  --accent: #8a3b12;
  --accent-2: #2f5d50;
  --line: #ddcdab;
  --city: #8a3b12;
  --village: #2f5d50;
  --site: #6b5b95;
  --ending: #b3261e;
  --ghost: #8c8c8c;
  --user: #1a73e8;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Noto Kufi Arabic", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}
html[lang="en"] body { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; }
button, input, select { font: inherit; }

/* ---------- Top bar ---------- */
.topbar {
  position: relative;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 16px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  z-index: 1001;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 { font-family: "Amiri", serif; font-size: 1.9rem; margin: 0; color: var(--accent); line-height: 1.1; }
.brand .sub { font-size: .85rem; color: var(--muted); }
.tools { display: flex; gap: 10px; align-items: center; font-size: .85rem; flex-wrap: wrap; }
.toggle { display: flex; align-items: center; gap: 4px; cursor: pointer; white-space: nowrap; }
select, #search {
  padding: 5px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
#search { width: 190px; }
.lang-btn {
  border: 1px solid var(--accent); color: var(--accent); background: #fff;
  border-radius: 8px; padding: 4px 12px; cursor: pointer;
}
.lang-btn:hover { background: var(--accent); color: #fff; }
.search-results {
  position: absolute; top: 100%; inset-inline-end: 16px; width: 280px; max-height: 320px; overflow-y: auto;
  margin: 4px 0 0; padding: 4px; list-style: none;
  background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.12);
}
.search-results li { padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: .88rem; }
.search-results li:hover, .search-results li.active { background: var(--bg); }
.search-results li small { color: var(--muted); display: block; font-size: .75rem; }

/* ---------- Layout ---------- */
/* row-reverse: the text panel sits at the reading start — right in Arabic, left in English */
.layout { flex: 1; display: flex; flex-direction: row-reverse; min-height: 0; }
#map { flex: 1; min-width: 0; background: #d4dadc; }
/* Leaflet positions overlays assuming LTR; RTL shifts tooltips away from their pins */
.leaflet-container { font-family: inherit; direction: ltr; }
.leaflet-container .leaflet-tooltip { unicode-bidi: plaintext; }
.relief-tiles { filter: sepia(.4) saturate(.9) brightness(1.03); }

.panel {
  width: 370px; max-width: 42vw;
  background: var(--paper);
  border-inline-end: 1px solid var(--line);
  overflow-y: auto;
  padding: 16px 18px 24px;
}
.panel h2 { font-family: "Amiri", serif; font-size: 1.7rem; margin: 0 0 2px; color: var(--accent); line-height: 1.3; }
html[lang="en"] .panel h2 { font-family: Georgia, serif; }
.panel h3 { font-size: .95rem; margin: 20px 0 8px; color: var(--accent-2); }
.panel p { line-height: 1.85; font-size: .92rem; margin: 6px 0; }
.range { color: var(--muted); margin: 0 0 8px; font-size: .88rem; }
.muted { color: var(--muted); }
.stats { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: .8rem; }
.stat b { font-size: 1.1rem; color: var(--accent); margin-inline-end: 4px; }
.road-list { padding: 0; margin: 0; list-style: none; font-size: .88rem; }
.road-list li { display: flex; gap: 8px; align-items: flex-start; padding: 5px 0; line-height: 1.5; }
.road-list li small { display: block; color: var(--muted); font-size: .76rem; }
.swatch { width: 22px; height: 4px; border-radius: 2px; flex: none; margin-top: 9px; }
.swatch.dashed { background: repeating-linear-gradient(90deg, currentColor 0 5px, transparent 5px 8px) !important; }
.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-size: .78rem; margin-top: 18px; }
.legend span { display: flex; align-items: center; gap: 4px; }
.lp svg { width: 13px; height: 18px; display: block; filter: drop-shadow(0 1px 1px rgba(0,0,0,.3)); }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; vertical-align: middle; margin-inline-end: 4px; }
.dot.city { background: var(--city); }
.dot.village { background: var(--village); }
.dot.site { background: var(--site); }
.dot.ending { background: #fff; border: 2px dashed var(--ending); }
.dot.ghost { background: #fff; border: 2px dotted var(--ghost); }
.hint { color: var(--muted); font-size: .8rem !important; }

.btn {
  background: var(--accent-2); color: #fff; border: none; border-radius: 8px;
  padding: 7px 14px; cursor: pointer; font-size: .85rem;
}
.btn.ghost { background: none; color: var(--accent-2); padding: 0; }
.btn:disabled { opacity: .6; cursor: default; }

/* City card */
.type { font-size: .76rem; color: var(--muted); }
.latin { color: var(--muted); font-size: .85rem; }
.badge {
  display: inline-block; font-size: .76rem; padding: 3px 10px; border-radius: 12px;
  background: #fde8e6; color: var(--ending); margin: 6px 0 0; line-height: 1.6;
}
.badge.gone { background: #eee; color: #555; }
.names { list-style: none; padding: 0; margin: 0; border-inline-start: 2px solid var(--line); }
.names li { padding: 5px 12px; font-size: .9rem; }
.names li.current { color: var(--accent); font-weight: 700; border-inline-start: 3px solid var(--accent); margin-inline-start: -2px; }
.names li .yrs { color: var(--muted); font-size: .75rem; display: block; font-weight: 400; }
figure { margin: 10px 0; position: relative; }
figure img { width: 100%; border-radius: 8px; border: 1px solid var(--line); display: block; background: #eee; }
figcaption { font-size: .76rem; color: var(--muted); margin-top: 4px; line-height: 1.6; }
.info-i {
  position: absolute; top: 6px; inset-inline-end: 6px; width: 22px; height: 22px; border-radius: 50%;
  background: rgba(0,0,0,.55); color: #fff; font-size: 13px; line-height: 22px; text-align: center;
  text-decoration: none; font-family: Georgia, serif; font-style: italic;
}
button.info-i { border: none; cursor: pointer; padding: 0; }
figure img[data-zoom] { cursor: zoom-in; }
.credit {
  position: absolute; inset-inline: 6px; top: 32px; background: rgba(0,0,0,.75); color: #fff;
  font-size: .72rem; line-height: 1.5; padding: 4px 8px; border-radius: 6px; direction: ltr; text-align: left;
}
.lightbox {
  position: fixed; inset: 0; z-index: 3000; background: rgba(20,14,8,.9);
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; cursor: zoom-out;
}
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100%; max-height: 85vh; border-radius: 6px; }
.lightbox p { color: #eee; font-size: .85rem; margin-top: 10px; text-align: center; max-width: 900px; }
.gallery { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.gallery figure { margin: 0; }
.gallery img { height: 120px; object-fit: cover; }
.panel a { color: var(--accent-2); }

/* Here card */
.here {
  background: #eef4ff; border: 1px solid #c9dcff; border-radius: 10px; padding: 12px 14px; margin-bottom: 14px;
}
.here h3 { margin: 0 0 6px; color: var(--user); }
.here .big { font-family: "Amiri", serif; font-size: 1.35rem; color: var(--ink); margin: 2px 0; }
html[lang="en"] .here .big { font-family: Georgia, serif; }
.near { list-style: none; padding: 0; margin: 8px 0 0; font-size: .86rem; }
.near li { display: flex; justify-content: space-between; gap: 8px; padding: 5px 0; border-top: 1px dashed #c9dcff; cursor: pointer; }
.near li:hover { color: var(--accent); }
.near .km { color: var(--muted); white-space: nowrap; font-size: .78rem; }

/* ---------- Timeline ---------- */
.timeline {
  background: var(--paper);
  border-top: 1px solid var(--line);
  padding: 8px 12px 10px;
}
.era-buttons, .sub-buttons { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: thin; padding-bottom: 4px; }
.era-buttons button {
  flex: none; font-size: .8rem; line-height: 1.35;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 10px; padding: 5px 12px; cursor: pointer; white-space: nowrap; text-align: center;
}
.era-buttons button .y { display: block; font-size: .66rem; color: var(--muted); }
.era-buttons button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.era-buttons button.active .y { color: #f6dcc9; }
.sub-buttons { margin-top: 4px; }
.sub-buttons:empty { display: none; }
.sub-buttons button {
  flex: none; font-size: .74rem; border: 1px dashed var(--line); background: transparent; color: var(--accent-2);
  border-radius: 14px; padding: 3px 10px; cursor: pointer; white-space: nowrap;
}
.sub-buttons button.active { background: var(--accent-2); color: #fff; border-style: solid; border-color: var(--accent-2); }

/* ---------- Map bits ---------- */
.city-label {
  background: rgba(251, 246, 234, .9); border: none; box-shadow: none;
  font-size: 11px; font-weight: 600; color: var(--ink); padding: 0 5px; border-radius: 4px;
}
.city-label.ghost-label { color: #666; font-weight: 400; font-style: italic; }
.city-label::before { display: none; }
.hide-labels .city-label { display: none; }
.zoom-low .lbl-minor { display: none; }
.today-wrap { background: none; border: none; }
.today-label {
  display: none; transform: translate(-50%, -50%); white-space: nowrap;
  font-size: 11px; color: #555; text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff; pointer-events: none;
}
.zoom-mid .today-label { display: inline-block; }
.vlabel { display: none; font-size: 10px; }
.zoom-high .vlabel { display: block; }
.vlabel.show { display: block; }
.pin { background: none; border: none; }
.pin svg { display: block; filter: drop-shadow(0 2px 2px rgba(0,0,0,.35)); transition: transform .15s; transform-origin: 50% 100%; }
.pin:hover svg { transform: scale(1.18); }
.pin-ghost svg { opacity: .85; }
.locate-btn {
  width: 34px; height: 34px; font-size: 18px; line-height: 34px; text-align: center;
  background: #fff; cursor: pointer; border: none; display: block;
}
.locate-btn:hover { background: #f4f4f4; }
.locate-btn.busy { animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .4; } }
.base-switch { display: flex; gap: 6px; }
.base-switch button {
  width: 64px; height: 64px; border-radius: 10px; border: 2px solid #fff; padding: 0; cursor: pointer;
  background-size: cover; background-position: center; position: relative; overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.base-switch button.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.base-switch button span {
  position: absolute; inset-inline: 0; bottom: 0; background: rgba(0,0,0,.55); color: #fff;
  font-size: 10px; line-height: 1.6; text-align: center;
}
@media (max-width: 760px) { .base-switch button { width: 50px; height: 50px; } }
.list-q { width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; margin: 6px 0 10px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chips button {
  border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 3px 10px; font-size: .78rem; cursor: pointer;
}
.chips button small { color: var(--muted); }
.chips button.active { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.chips button.active small { color: #d5ebe0; }
.vlist { list-style: none; padding: 0; margin: 0; }
.vlist li { display: flex; justify-content: space-between; gap: 8px; padding: 8px 4px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: .9rem; }
.vlist li:hover { background: #fff; }
.vlist .vd { color: var(--muted); font-size: .76rem; white-space: nowrap; }
.share-btn { font-size: .8rem; padding: 5px 12px; }
.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: #2b2118; color: #fff; padding: 8px 16px; border-radius: 20px; font-size: .85rem; z-index: 4000; transition: .25s;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.privacy-note { font-size: .74rem; color: var(--muted); }

/* ---------- Mobile ---------- */
.era-info-ctl { display: none; }
.mobile-only { display: none; }
@media (max-width: 760px) {
  .topbar { padding: 6px 12px; gap: 6px; }
  .brand h1 { font-size: 1.45rem; }
  .brand .sub { font-size: .75rem; }
  .tools { font-size: .76rem; gap: 6px; width: 100%; }
  #search { flex: 1; width: auto; min-width: 120px; }
  /* the map takes the whole height between the header and the timeline */
  .layout { flex-direction: column; position: relative; }
  #map { flex: 1 1 auto; min-height: 0; }
  .era-info-ctl { display: block; }
  .mobile-only { display: block; }
  .era-info-ctl .locate-btn { font-size: 20px; font-family: Georgia, serif; }
  /* details (city, village, era, lists) open as their own full-screen page */
  .panel {
    position: fixed; inset: 0; z-index: 2500; width: 100%; max-width: none; height: 100%;
    border: none; padding: 14px 16px calc(24px + env(safe-area-inset-bottom));
    transform: translateY(100%); transition: transform .25s ease; visibility: hidden;
    overflow-y: auto; -webkit-overflow-scrolling: touch;
  }
  .panel.open { transform: none; visibility: visible; }
  .panel .btn.ghost#backBtn {
    position: sticky; top: -14px; z-index: 2; display: block; width: calc(100% + 32px); margin: -14px -16px 10px;
    padding: 12px 16px; background: var(--paper); border-bottom: 1px solid var(--line); text-align: start; font-size: .95rem;
  }
  .search-results { inset-inline: 12px; width: auto; }
}


.base-switch .op-slider {
  display: flex; align-items: center; gap: 4px; background: #fff; border-radius: 10px; padding: 0 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,.3); font-size: 14px; align-self: center; height: 34px;
}
.base-switch .op-slider input { width: 90px; accent-color: var(--accent); }
.brand { align-items: center; }
.brand-logo { height: 36px; width: auto; flex: none; }
@media (max-width: 760px) { .brand-logo { height: 28px; } }
