/* ===== Footsteps — desert-night theme =====
   Deep indigo ground, warm sand text, gold accent.
   Medina-green only for grade badges A/B; amber for C; muted slate for D. */

:root {
  --bg-0: #070a1c;
  --bg-1: #0b0f2a;
  --bg-2: #121738;
  --dune: rgba(217, 164, 65, 0.08);
  --dune-deep: rgba(140, 96, 40, 0.14);
  --glass: rgba(255, 244, 222, 0.045);
  --glass-strong: rgba(255, 244, 222, 0.08);
  --glass-border: rgba(255, 236, 200, 0.12);
  --sand-0: #f3e8cf;
  --sand-1: #cdbf9f;
  --sand-2: #8f8672;
  --gold: #d9a441;
  --gold-soft: rgba(217, 164, 65, 0.35);
  --green: #1f8a5b;          /* Medina green, badges only */
  --green-soft: #2fa873;
  --amber: #c7862b;
  --slate: #5b6275;
  --danger: #ff7b7b;
  --radius: 16px;
  --radius-sm: 10px;
  --measure: 68ch;
  --transition: 180ms cubic-bezier(.4,0,.2,1);
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --font-arabic: "Amiri", "Scheherazade New", "Noto Naskh Arabic", "Geeza Pro", "Al Bayan", "Traditional Arabic", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-0);
  color: var(--sand-0);
  font-family: var(--font-ui);
  min-height: 100%;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(ellipse 60% 40% at 20% 110%, var(--dune-deep), transparent 70%),
    radial-gradient(ellipse 50% 35% at 80% 108%, var(--dune), transparent 72%),
    radial-gradient(ellipse 70% 50% at 70% -10%, rgba(56, 72, 160, 0.22), transparent 65%),
    linear-gradient(180deg, var(--bg-0), var(--bg-1) 50%, var(--bg-2));
  background-attachment: fixed;
}

.sky {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 12% 18%, rgba(255,255,255,.7), transparent 60%),
    radial-gradient(1px 1px at 28% 62%, rgba(255,255,255,.5), transparent 60%),
    radial-gradient(1.5px 1.5px at 44% 30%, rgba(255,244,222,.8), transparent 60%),
    radial-gradient(1px 1px at 61% 76%, rgba(255,255,255,.45), transparent 60%),
    radial-gradient(1px 1px at 73% 22%, rgba(255,255,255,.6), transparent 60%),
    radial-gradient(1.5px 1.5px at 86% 48%, rgba(255,244,222,.7), transparent 60%),
    radial-gradient(1px 1px at 92% 86%, rgba(255,255,255,.5), transparent 60%),
    radial-gradient(1px 1px at 8% 88%, rgba(255,255,255,.4), transparent 60%),
    radial-gradient(1px 1px at 52% 8%, rgba(255,255,255,.6), transparent 60%),
    radial-gradient(1px 1px at 36% 94%, rgba(255,255,255,.35), transparent 60%);
  opacity: .8;
}

a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible, button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.skip-link {
  position: absolute; left: -999px; top: 8px; z-index: 100;
  background: var(--gold); color: var(--bg-0); padding: .5rem .8rem; border-radius: 8px;
}
.skip-link:focus { left: 8px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .7rem 1.2rem;
  background: rgba(7, 10, 28, 0.72);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--glass-border);
}
.brand { display: flex; align-items: center; gap: .6rem; color: var(--sand-0); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--gold);
  box-shadow: inset 0 0 0 6px var(--bg-1), inset 0 0 0 9px var(--gold);
}
.brand-text { font-family: var(--font-serif); font-size: 1.25rem; letter-spacing: .02em; display: flex; flex-direction: column; line-height: 1; }
.brand-sub { font-family: var(--font-ui); font-size: .7rem; color: var(--sand-2); margin-top: .25rem; letter-spacing: .05em; }
.site-nav { display: flex; gap: .2rem; margin-left: auto; flex-wrap: wrap; }
.site-nav a {
  color: var(--sand-1); padding: .4rem .7rem; border-radius: 8px; font-size: .92rem;
  transition: background var(--transition), color var(--transition);
}
.site-nav a:hover { background: var(--glass-strong); color: var(--sand-0); text-decoration: none; }
.site-nav a.active { color: var(--gold); background: var(--glass); }
.nav-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.25rem; height: 1.25rem; padding: 0 .35rem; margin-left: .25rem;
  border-radius: 999px; background: var(--gold); color: var(--bg-0);
  font-size: .7rem; font-weight: 700; font-variant-numeric: tabular-nums; vertical-align: middle;
}
.nav-badge[hidden] { display: none; }
.nav-toggle {
  display: none; margin-left: auto; background: var(--glass); color: var(--sand-0);
  border: 1px solid var(--glass-border); border-radius: 8px; font-size: 1.1rem; padding: .3rem .6rem; cursor: pointer;
}
@media (max-width: 720px) {
  .nav-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.25rem; height: 1.25rem; padding: 0 .35rem; margin-left: .25rem;
  border-radius: 999px; background: var(--gold); color: var(--bg-0);
  font-size: .7rem; font-weight: 700; font-variant-numeric: tabular-nums; vertical-align: middle;
}
.nav-badge[hidden] { display: none; }
.nav-toggle { display: block; }
  .site-nav { display: none; width: 100%; flex-direction: column; }
  .site-nav.open { display: flex; }
}

/* ---------- layout ---------- */
.app { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1.2rem 4rem; }
.app:focus { outline: none; }
.page-title { font-family: var(--font-serif); font-weight: 500; font-size: 2rem; margin: .2rem 0 .3rem; line-height: 1.2; }
.page-lead { color: var(--sand-1); max-width: var(--measure); margin: 0 0 1.4rem; line-height: 1.55; }
.eyebrow { color: var(--sand-2); font-size: .78rem; text-transform: uppercase; letter-spacing: .12em; margin: 0 0 .4rem; }
h2 { font-family: var(--font-serif); font-weight: 500; font-size: 1.35rem; margin: 2rem 0 .7rem; color: var(--sand-0); }
h3 { font-weight: 600; font-size: 1rem; margin: 1.2rem 0 .5rem; color: var(--sand-1); }
.muted { color: var(--sand-2); }
.small { font-size: .85rem; }

.card {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 1.1rem 1.3rem;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.card + .card { margin-top: 1rem; }

.footer { max-width: 1100px; margin: 0 auto; padding: 1rem 1.2rem 3rem; color: var(--sand-2); font-size: .82rem; line-height: 1.5; border-top: 1px solid var(--glass-border); }

.loading, .error { padding: 3rem 0; color: var(--sand-2); text-align: center; }
.error { color: var(--danger); }

/* ---------- badges & chips ---------- */
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.6rem; height: 1.6rem; padding: 0 .45rem;
  border-radius: 7px; font-weight: 700; font-size: .8rem; letter-spacing: .02em;
  color: #fff; flex-shrink: 0;
}
.badge.g-A { background: var(--green); }
.badge.g-B { background: var(--green-soft); color: #062a1a; }
.badge.g-C { background: var(--amber); color: #2a1800; }
.badge.g-D, .badge.g-X { background: var(--slate); color: #e5e7ee; }
.badge.lg { height: 2.3rem; min-width: 2.3rem; font-size: 1.2rem; border-radius: 10px; }

.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .18rem .6rem; border-radius: 999px; font-size: .8rem;
  background: var(--glass-strong); border: 1px solid var(--glass-border); color: var(--sand-1);
  white-space: nowrap; max-width: 26ch; overflow: hidden; text-overflow: ellipsis;
}
.chip > span { overflow: hidden; text-overflow: ellipsis; }
a.chip:hover { color: var(--sand-0); border-color: var(--gold-soft); text-decoration: none; }
.chip.place::before { content: "◦"; color: var(--gold); }
.chip.person::before { content: "•"; color: var(--sand-2); }
.chip-row { display: flex; flex-wrap: wrap; gap: .4rem; margin: .5rem 0; }
.year { color: var(--gold); font-variant-numeric: tabular-nums; font-size: .85rem; white-space: nowrap; }

/* ---------- journey ---------- */
.stats-row { display: flex; flex-wrap: wrap; gap: .8rem; margin: .2rem 0 1.6rem; }
.stat { background: var(--glass); border: 1px solid var(--glass-border); border-radius: var(--radius-sm); padding: .5rem .9rem; }
.stat b { font-family: var(--font-serif); font-size: 1.3rem; font-weight: 500; color: var(--gold); display: block; }
.stat span { color: var(--sand-2); font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; }

.stage { margin-bottom: 1rem; }
.stage summary {
  cursor: pointer; list-style: none; display: flex; align-items: center; gap: .8rem;
  padding: .9rem 1.2rem; border-radius: var(--radius);
  background: var(--glass-strong); border: 1px solid var(--glass-border);
}
.stage summary::-webkit-details-marker { display: none; }
.stage summary::before { content: "›"; font-size: 1.4rem; color: var(--gold); transition: transform var(--transition); }
.stage[open] summary::before { transform: rotate(90deg); }
.stage[open] summary { border-radius: var(--radius) var(--radius) 0 0; }
.stage-name { font-family: var(--font-serif); font-size: 1.25rem; flex: 1; }
.stage-meta { color: var(--sand-2); font-size: .82rem; display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.grade-bar { display: inline-flex; height: 6px; width: 120px; border-radius: 3px; overflow: hidden; background: var(--glass); }
.grade-bar i { display: block; height: 100%; }
.grade-bar .g-A { background: var(--green); }
.grade-bar .g-B { background: var(--green-soft); }
.grade-bar .g-C { background: var(--amber); }
.grade-bar .g-D { background: var(--slate); }

.event-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--glass-border); border-top: 0; border-radius: 0 0 var(--radius) var(--radius); background: var(--glass); }
.event-list li { border-top: 1px solid var(--glass-border); }
.event-list li:first-child { border-top: 0; }
.event-row {
  display: grid; grid-template-columns: auto 1fr auto; gap: .8rem; align-items: center;
  padding: .7rem 1.1rem; color: var(--sand-0);
  transition: background var(--transition);
}
.event-row:hover { background: var(--glass-strong); text-decoration: none; }
.event-row .t { font-size: .98rem; line-height: 1.35; }
.event-row .n { color: var(--sand-2); font-size: .75rem; margin-right: .4rem; font-variant-numeric: tabular-nums; }
.event-row .r { display: flex; gap: .5rem; align-items: center; }
@media (max-width: 600px) {
  .event-row { grid-template-columns: auto 1fr; }
  .event-row .r { grid-column: 2; }
}

/* ---------- bookmarks & reading progress ---------- */
.bm-icon { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; flex-shrink: 0; }
.bm-btn {
  display: inline-flex; align-items: center; gap: .4rem;
  background: var(--glass); color: var(--sand-1); border: 1px solid var(--glass-border);
  border-radius: 999px; padding: .35rem .85rem; font: inherit; font-size: .85rem; cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.bm-btn:hover { background: var(--glass-strong); color: var(--sand-0); border-color: var(--gold-soft); }
.bm-btn.on { color: var(--gold); border-color: var(--gold-soft); }
.bm-btn.on .bm-icon { fill: currentColor; }
.event-topline { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.event-topline .eyebrow { margin: 0; }
.bm-mark { display: inline-flex; color: var(--gold); margin-left: .45rem; vertical-align: -.1em; font-size: .9em; }
.bm-mark .bm-icon { fill: currentColor; }
.event-row.read .n::after { content: "✓"; color: var(--green-soft); margin-left: .3rem; font-size: .75rem; }
.progress { display: inline-flex; height: 6px; width: 80px; border-radius: 3px; overflow: hidden; background: var(--glass-strong); }
.progress i { display: block; height: 100%; background: var(--gold); transition: width var(--transition); }
.progress-txt { font-variant-numeric: tabular-nums; }
.continue { display: block; color: var(--sand-0); margin: 0 0 1.2rem; border-color: var(--gold-soft); }
.continue:hover { text-decoration: none; background: var(--glass-strong); }
.continue .dir { display: block; color: var(--gold); font-size: .72rem; text-transform: uppercase; letter-spacing: .1em; margin-bottom: .4rem; }
.continue .ct { display: flex; gap: .6rem; align-items: center; font-family: var(--font-serif); font-size: 1.2rem; margin-bottom: .2rem; }
.continue .n { color: var(--sand-2); font-size: .8rem; font-family: var(--font-ui); }
.bm-list { border-top: 1px solid var(--glass-border); border-radius: var(--radius); }
.bm-list li { display: grid; grid-template-columns: 1fr auto; align-items: center; }
.bm-list .event-row { min-width: 0; }
.bm-remove {
  margin-right: .8rem; background: transparent; color: var(--sand-2); border: 1px solid var(--glass-border);
  border-radius: 8px; padding: .3rem .6rem; font: inherit; font-size: .78rem; cursor: pointer;
}
.bm-remove:hover { color: var(--danger); border-color: var(--danger); }

/* ---------- event page ---------- */
.event-head { margin-bottom: 1.2rem; }
.event-head .page-title { max-width: 30ch; }
.event-meta { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; color: var(--sand-1); font-size: .9rem; }
.event-meta .sep { color: var(--sand-2); }
.prose { max-width: var(--measure); font-family: var(--font-serif); font-size: 1.08rem; line-height: 1.7; color: var(--sand-0); }
.prose p { margin: 0 0 1rem; }
.summary { font-size: 1.05rem; color: var(--sand-1); border-left: 3px solid var(--gold); padding-left: 1rem; max-width: var(--measure); line-height: 1.6; }
.auth { display: flex; gap: 1rem; align-items: flex-start; max-width: var(--measure); }
.auth .meaning { color: var(--sand-1); line-height: 1.55; }
.auth .meaning .s { color: var(--sand-0); display: block; margin-bottom: .3rem; }
.gaps { max-width: var(--measure); color: var(--sand-1); line-height: 1.6; }

.source { margin-top: .8rem; }
.source .src-head { display: flex; gap: .6rem; flex-wrap: wrap; align-items: baseline; margin-bottom: .4rem; }
.source .kind { font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; color: var(--gold); }
.source .ref { font-weight: 600; color: var(--sand-0); }
.source .rel { color: var(--sand-2); font-size: .85rem; margin: 0 0 .5rem; }
.source .text { line-height: 1.6; color: var(--sand-1); max-width: var(--measure); }
.source .ext { font-size: .82rem; margin-left: auto; }
.ar {
  font-family: var(--font-arabic); direction: rtl; text-align: right;
  font-size: 1.45rem; line-height: 2.1; color: var(--sand-0);
  unicode-bidi: isolate;
}
.ar.excerpt { font-size: 1.2rem; line-height: 1.95; max-height: 14rem; overflow: auto; padding-right: .2rem; }
.ar.title { font-size: 1.05rem; line-height: 1.6; color: var(--sand-1); }

/* English translation shown under a classical Arabic excerpt */
.tr-block { margin-top: .7rem; border-top: 1px solid var(--gold-soft); padding-top: .55rem; }
.tr-note {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .1em;
  color: var(--sand-2); margin: 0 0 .35rem;
}
.tr-note.flagged { color: var(--gold); }
.tr-text { max-width: var(--measure); }
.tr-text p { margin: 0 0 .6rem; }
.tr-text p:last-child { margin-bottom: 0; }
.ref-list { font-size: .8rem; color: var(--sand-2); word-break: break-all; }

.pager { display: flex; justify-content: space-between; gap: 1rem; margin-top: 2rem; flex-wrap: wrap; }
.pager a { flex: 1; min-width: 200px; display: block; }
.pager a:hover { text-decoration: none; border-color: var(--gold-soft); }
.pager .dir { color: var(--sand-2); font-size: .72rem; text-transform: uppercase; letter-spacing: .1em; display: block; }
.pager .next { text-align: right; }

/* ---------- lists / index pages ---------- */
.search-box {
  width: 100%; max-width: 36rem; padding: .7rem 1rem; font-size: 1rem;
  background: var(--glass-strong); border: 1px solid var(--glass-border); border-radius: var(--radius-sm);
  color: var(--sand-0); font-family: inherit;
}
.search-box::placeholder { color: var(--sand-2); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .6rem; margin-top: 1rem; }
.tile { display: flex; justify-content: space-between; gap: .5rem; align-items: center; padding: .6rem .9rem; border-radius: var(--radius-sm); background: var(--glass); border: 1px solid var(--glass-border); color: var(--sand-0); }
.tile:hover { background: var(--glass-strong); text-decoration: none; border-color: var(--gold-soft); }
.tile .cnt { color: var(--sand-2); font-size: .8rem; font-variant-numeric: tabular-nums; }
.result-list { list-style: none; padding: 0; margin: 1rem 0 0; }
.result-list li { margin-bottom: .6rem; }
.result { display: block; color: var(--sand-0); }
.result:hover { text-decoration: none; border-color: var(--gold-soft); }
.result .t { font-size: 1.02rem; display: flex; gap: .6rem; align-items: center; }
.result .s { color: var(--sand-1); font-size: .9rem; line-height: 1.5; margin-top: .3rem; max-width: var(--measure); }
.result .m { color: var(--sand-2); font-size: .78rem; margin-top: .3rem; display: flex; gap: .6rem; flex-wrap: wrap; }
dl.gloss { margin: 1rem 0; max-width: var(--measure); }
dl.gloss dt { font-weight: 600; color: var(--gold); margin-top: .9rem; }
dl.gloss dt small { color: var(--sand-2); font-weight: 400; margin-left: .4rem; }
dl.gloss dd { margin: .2rem 0 0; color: var(--sand-1); line-height: 1.55; }

/* ---------- map ---------- */
.map-wrap { display: grid; grid-template-columns: 1fr 280px; gap: 1rem; }
@media (max-width: 800px) { .map-wrap { grid-template-columns: 1fr; } }
.map-svg { width: 100%; height: auto; display: block; border-radius: var(--radius); background: #0a0e26; border: 1px solid var(--glass-border); }
.map-svg .sea { fill: #101a45; }
.map-svg .land { fill: #2b2a3f; stroke: rgba(243,232,207,.18); stroke-width: .6; }
.map-svg .grat { stroke: rgba(243,232,207,.06); stroke-width: .5; }
.map-svg .dot { fill: var(--gold); fill-opacity: .85; stroke: var(--bg-0); stroke-width: 1; cursor: pointer; transition: fill-opacity var(--transition); }
.map-svg .dot.off { fill: none; stroke: var(--gold); stroke-width: 1.5; stroke-dasharray: 2 2; }
.map-svg .dot:hover, .map-svg .dot:focus { fill-opacity: 1; stroke: var(--sand-0); outline: none; }
.map-svg .lbl { fill: var(--sand-0); font-size: 9px; font-family: var(--font-ui); pointer-events: none; paint-order: stroke; stroke: #0a0e26; stroke-width: 2.5px; }
.map-stage { position: relative; }
.map-svg { cursor: grab; user-select: none; -webkit-user-select: none; touch-action: none; }
.map-svg.dragging { cursor: grabbing; }
.map-svg .land, .map-svg .grat { vector-effect: non-scaling-stroke; }
.map-controls {
  position: absolute; top: .6rem; right: .6rem; display: flex; flex-direction: column; gap: .3rem; align-items: center;
}
.map-controls button {
  width: 2rem; height: 2rem; border-radius: 8px; cursor: pointer; font-size: 1.1rem; line-height: 1;
  background: rgba(7, 10, 28, 0.8); color: var(--sand-0); border: 1px solid var(--glass-border);
}
.map-controls button:hover { background: var(--glass-strong); border-color: var(--gold-soft); }
.mz-level { font-size: .7rem; color: var(--sand-2); font-variant-numeric: tabular-nums; }
.map-svg .sea-lbl { fill: rgba(243,232,207,.3); font-size: 8px; font-style: italic; letter-spacing: .1em; pointer-events: none; }
.map-side h3 { margin-top: 0; }
.map-side ol { padding-left: 1.2rem; margin: 0; color: var(--sand-1); font-size: .9rem; line-height: 1.7; }
.map-side a { color: var(--sand-0); }

/* ---------- about ---------- */
.about { max-width: var(--measure); line-height: 1.65; color: var(--sand-1); }
.about p { margin: 0 0 1rem; }
.about ul { padding-left: 1.2rem; }
.about li { margin-bottom: .4rem; }
.grade-table { display: grid; grid-template-columns: auto 1fr; gap: .6rem .9rem; align-items: start; margin: 1rem 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* zoom-to-box */
.map-svg.boxmode { cursor: crosshair; }
.map-svg .zoom-box { fill: rgba(232,196,106,0.12); stroke: var(--gold, #e8c46a); stroke-width: 1; stroke-dasharray: 4 3; pointer-events: none; }
.map-controls button.on { background: var(--gold, #e8c46a); color: #1a1408; }
