:root {
  --parchment: #f7f0e1;
  --panel: #fcf8ee;
  --ink: #2b1d12;
  --ink-soft: #6b5a48;
  --line: #e6d9bd;
  --maroon: #6d1a1f;
  --maroon-deep: #4a1014;
  --saffron: #e08a1e;
  --gold: #d9b24a;
  --teal: #2f7d6b;
  --serif: 'Gentium Book Plus', 'Noto Serif', Georgia, 'Times New Roman', serif;
  --sans: 'Segoe UI', system-ui, -apple-system, 'Noto Sans', Roboto, Arial, sans-serif;
  --shadow: 0 10px 30px rgba(60, 30, 10, .22);
  --side-w: 360px;
  --detail-w: 420px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: var(--sans); color: var(--ink); background: var(--parchment); font-size: 15px; line-height: 1.5; }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3, h4 { font-family: var(--serif); margin: 0; }

#app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

/* ───────────── Sidebar ───────────── */
#sidebar { width: var(--side-w); flex: none; display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); z-index: 1100; box-shadow: 4px 0 24px rgba(60, 30, 10, .12); }

.brand { display: flex; align-items: center; gap: 14px; padding: 18px 18px 16px; color: #fbeccb;
  background: radial-gradient(120% 140% at 0% 0%, #8e2a22 0%, var(--maroon) 45%, var(--maroon-deep) 100%); position: relative; }
.brand::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: linear-gradient(90deg, var(--gold), var(--saffron), var(--gold)); }
.brand .wheel { width: 46px; height: 46px; color: var(--gold); flex: none; animation: turn 60s linear infinite; }
@keyframes turn { to { transform: rotate(360deg); } }
.brand h1 { font-size: 21px; line-height: 1.15; letter-spacing: .2px; }
.brand p { margin: 3px 0 0; font-size: 12.5px; opacity: .85; font-family: var(--serif); font-style: italic; }
#side-close { display: none; margin-left: auto; color: #fbeccb; }

.tabs { display: flex; border-bottom: 1px solid var(--line); background: #f5ecd8; }
.tabs button { flex: 1; padding: 11px 6px; border: 0; background: none; font-size: 13px; font-weight: 600; color: var(--ink-soft); border-bottom: 3px solid transparent; }
.tabs button:hover { color: var(--maroon); }
.tabs button.on { color: var(--maroon); border-bottom-color: var(--saffron); background: var(--panel); }

.search { padding: 12px 14px 6px; }
.search input { width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 999px; background: #fff; font: inherit; font-size: 14px; outline: none; }
.search input:focus { border-color: var(--saffron); box-shadow: 0 0 0 3px rgba(224, 138, 30, .18); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 14px 10px; }
.chip { border: 1.5px solid var(--c); background: var(--c); color: #fff; border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 600; transition: .15s; }
.chip.off { background: transparent; color: var(--c); opacity: .75; }

.list { flex: 1; overflow-y: auto; padding: 0 0 12px; scrollbar-width: thin; scrollbar-color: #d6c59f transparent; }
.intro { margin: 4px 14px 12px; padding: 14px 16px; border-radius: 12px; background: linear-gradient(135deg, #fff7e2, #fbe9c4); border: 1px solid #ecd9a8; font-family: var(--serif); font-size: 15.5px; }
.intro button { margin-top: 10px; border: 0; background: var(--maroon); color: #fff; padding: 8px 16px; border-radius: 999px; font-family: var(--sans); font-size: 13px; font-weight: 600; }
.intro button:hover { background: #8a2228; }

.ph-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: baseline; gap: 8px; padding: 9px 14px 7px; background: linear-gradient(var(--panel) 85%, transparent); border-left: 5px solid var(--c); margin-top: 6px; }
.ph-head h3 { font-size: 16.5px; color: var(--c); }
.ph-head span { font-size: 11.5px; color: var(--ink-soft); margin-left: auto; white-space: nowrap; }
.ph-sub { padding: 0 14px 6px 19px; font-size: 12px; color: var(--ink-soft); font-style: italic; }

.row { display: flex; gap: 11px; width: 100%; text-align: left; border: 0; background: none; padding: 8px 14px; border-left: 5px solid transparent; align-items: flex-start; }
.row:hover { background: #f6ecd4; }
.row.on { background: #f9e7c0; border-left-color: var(--c, var(--saffron)); }
.row .n { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--c, var(--teal)); color: #fff; font-size: 11.5px; font-weight: 700; display: grid; place-items: center; margin-top: 1px; }
.row .t { font-family: var(--serif); font-size: 15.5px; line-height: 1.25; display: block; }
.row .m { font-size: 12px; color: var(--ink-soft); display: block; margin-top: 1px; }
.row .n.sm { width: 10px; height: 10px; margin: 7px 8px 0 8px; }
.empty { padding: 24px 18px; color: var(--ink-soft); font-style: italic; text-align: center; }

.person { border-bottom: 1px solid #efe5cc; }
.person summary { list-style: none; cursor: pointer; padding: 8px 14px; display: flex; gap: 8px; align-items: baseline; }
.person summary::-webkit-details-marker { display: none; }
.person summary:hover { background: #f6ecd4; }
.person .pn { font-family: var(--serif); font-size: 15.5px; font-weight: 700; }
.person .pr { font-size: 12px; color: var(--ink-soft); flex: 1; }
.person .pc { font-size: 11px; background: #eadfc3; border-radius: 999px; padding: 1px 7px; color: var(--ink-soft); }
.person .seen { padding: 0 14px 8px 22px; }
.person .seen button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 5px 8px; border-left: 3px solid var(--c); margin: 4px 0; font-size: 13px; border-radius: 0 6px 6px 0; }
.person .seen button:hover { background: #f6ecd4; }
.person .seen b { font-family: var(--serif); font-size: 14px; }

.note { padding: 10px 14px 12px; font-size: 11px; line-height: 1.45; color: var(--ink-soft); border-top: 1px solid var(--line); background: #f5ecd8; }

/* ───────────── Map stage ───────────── */
#stage { position: relative; flex: 1; min-width: 0; }
#map { position: absolute; inset: 0; background: #e9dfc6; }
.tiles-parchment { filter: sepia(.22) saturate(.92); }
.leaflet-container { font-family: var(--sans); }
.leaflet-control-layers, .leaflet-bar { border: 1px solid var(--line) !important; box-shadow: var(--shadow) !important; border-radius: 10px !important; overflow: hidden; }
.leaflet-control-layers { background: var(--panel); font-size: 13px; }
.leaflet-bar a { background: var(--panel); color: var(--maroon); }
.leaflet-bottom.leaflet-right { margin-bottom: 96px; }
.leaflet-bottom.leaflet-left { margin-bottom: 96px; }

.pin { --c: var(--teal); display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--c); color: #fff; font: 700 11.5px/1 var(--sans); border: 2.5px solid #fff8e6; box-shadow: 0 2px 7px rgba(40, 15, 0, .45); transition: transform .2s; }
.pin:hover { transform: scale(1.15); }
.pin-minor { width: 12px; height: 12px; border-width: 2px; background: var(--teal); opacity: .85; margin: 1px; }
.pin.sel { transform: scale(1.25); border-color: var(--gold); animation: pulse 1.8s ease-out infinite; opacity: 1; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(224, 138, 30, .75), 0 2px 7px rgba(40, 15, 0, .45); }
  100% { box-shadow: 0 0 0 20px rgba(224, 138, 30, 0), 0 2px 7px rgba(40, 15, 0, .45); }
}
.place-tip { font-family: var(--serif); font-size: 14px; font-weight: 700; color: var(--maroon-deep); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 3px 9px; }
.place-tip::before { display: none; }
.place-label { font: 700 13px/1 var(--serif); color: var(--maroon-deep); white-space: nowrap; text-shadow: 0 0 3px #fff8e6, 0 0 3px #fff8e6, 0 0 5px #fff8e6, 0 0 6px #fff8e6; pointer-events: none; display: block; position: absolute; left: 18px; top: -7px; }

.float { position: absolute; z-index: 1000; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); }
.icon-btn { border: 0; background: none; width: 38px; height: 38px; border-radius: 50%; font-size: 22px; line-height: 1; display: grid; place-items: center; }
.icon-btn:hover { background: rgba(224, 138, 30, .18); }
#menu-btn { display: none; top: 12px; left: 12px; border: 1px solid var(--line); background: var(--panel); }
.toggle { top: 12px; left: 12px; padding: 7px 12px; border-radius: 999px; font-size: 12.5px; display: flex; gap: 6px; align-items: center; cursor: pointer; user-select: none; }
.toggle input { accent-color: var(--teal); margin: 0; }

/* ───────────── Detail card ───────────── */
#detail { position: absolute; z-index: 1001; top: 12px; right: 12px; bottom: 108px; width: var(--detail-w); max-width: calc(100% - 24px); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); display: none; flex-direction: column; overflow: hidden; }
#detail.open { display: flex; animation: slide .28s ease-out; }
@keyframes slide { from { opacity: 0; transform: translateX(24px); } }
.d-head { padding: 16px 52px 14px 20px; color: #fff; position: relative; background: linear-gradient(135deg, var(--c), color-mix(in srgb, var(--c) 70%, #000)); }
.d-head .eyebrow { font-size: 11.5px; letter-spacing: .9px; text-transform: uppercase; opacity: .9; font-weight: 600; }
.d-head h2 { font-size: 25px; line-height: 1.15; margin: 4px 0 6px; }
.d-head .where { font-size: 13.5px; opacity: .95; }
.d-head .where button { border: 0; background: none; color: #fff; padding: 0; font-family: var(--serif); font-size: 16px; font-weight: 700; text-decoration: underline; text-decoration-color: rgba(255, 255, 255, .5); text-underline-offset: 3px; }
.d-close { position: absolute; top: 10px; right: 10px; color: #fff; }
.d-close:hover { background: rgba(255, 255, 255, .2); }
.d-body { flex: 1; overflow-y: auto; padding: 14px 20px 18px; scrollbar-width: thin; scrollbar-color: #d6c59f transparent; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.badge { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: #f1e4c3; color: #5a4424; white-space: nowrap; }
.badge.age { background: var(--maroon); color: #fff; }
.badge.warn { background: #fde8d0; color: #9a4a06; }
.badge.canonical { background: #dff0e6; color: #1f5c41; }
.badge.commentarial { background: #e8e4f6; color: #45358a; }
.badge.chronicle { background: #fbe3df; color: #8f2a1c; }
.when { font-size: 13px; color: var(--ink-soft); font-style: italic; margin: 0 0 10px; }
.summary { font-family: var(--serif); font-size: 17px; line-height: 1.55; margin: 0 0 6px; }
.d-body h4 { font-size: 13px; font-family: var(--sans); text-transform: uppercase; letter-spacing: 1px; color: var(--maroon); margin: 18px 0 8px; display: flex; align-items: center; gap: 8px; }
.d-body h4::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.item { padding: 9px 12px; border-radius: 10px; background: #fff; border: 1px solid #efe5cc; margin-bottom: 7px; }
.item b { font-family: var(--serif); font-size: 15.5px; }
.item p { margin: 2px 0 0; font-size: 13.5px; color: #4a3a2a; }
.item .ref { float: right; font-size: 11.5px; font-weight: 700; color: var(--maroon); background: #f6e7c5; border-radius: 6px; padding: 1px 7px; margin-left: 8px; }
.item .role { font-size: 12px; color: var(--ink-soft); font-style: italic; }
.item.sutta { border-left: 4px solid var(--saffron); }
.item.person-c { border-left: 4px solid var(--teal); }
.item.visit { border-left: 4px solid var(--c); cursor: pointer; display: block; width: 100%; text-align: left; font: inherit; }
.item.visit:hover { background: #fdf3da; }
.sources { font-size: 12px; color: var(--ink-soft); margin: 14px 0 0; }
.d-nav { display: flex; border-top: 1px solid var(--line); background: #f5ecd8; }
.d-nav button { flex: 1; border: 0; background: none; padding: 10px; font-size: 13px; font-weight: 600; color: var(--maroon); }
.d-nav button:hover:not(:disabled) { background: #efe0bc; }
.d-nav button:disabled { opacity: .35; cursor: default; }
.d-nav span { align-self: center; font-size: 12px; color: var(--ink-soft); padding: 0 8px; white-space: nowrap; }

/* ───────────── Timeline ───────────── */
#timeline { position: absolute; z-index: 1000; left: 12px; right: 12px; bottom: 12px; display: flex; align-items: center; gap: 14px; padding: 10px 18px 10px 10px; background: rgba(252, 248, 238, .96); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); backdrop-filter: blur(4px); }
.tl-controls { display: flex; align-items: center; gap: 2px; flex: none; }
.play { background: var(--maroon); color: #fff; font-size: 15px; width: 44px; height: 44px; }
.play:hover { background: #8a2228; }
.tl-track { flex: 1; min-width: 0; position: relative; padding-top: 2px; }
.tl-bands { display: flex; height: 8px; border-radius: 999px; overflow: hidden; }
.tl-bands i { display: block; background: var(--c); opacity: .9; }
.tl-bands i.off { opacity: .2; }
#tl-range { position: absolute; left: 0; right: 0; top: -5px; width: 100%; margin: 0; height: 22px; background: none; -webkit-appearance: none; appearance: none; cursor: pointer; }
#tl-range::-webkit-slider-runnable-track { background: transparent; height: 22px; }
#tl-range::-moz-range-track { background: transparent; height: 22px; }
#tl-range::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%; background: var(--gold); border: 3px solid #fff; box-shadow: 0 1px 6px rgba(40, 15, 0, .5); }
#tl-range::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--gold); border: 3px solid #fff; box-shadow: 0 1px 6px rgba(40, 15, 0, .5); }
.tl-labels { display: flex; margin-top: 7px; font-size: 11px; color: var(--ink-soft); }
.tl-labels span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; padding-right: 6px; }
.tl-labels b { color: var(--c); font-weight: 700; }
.tl-readout { flex: none; width: 190px; text-align: right; font-size: 12.5px; line-height: 1.3; color: var(--ink-soft); }
.tl-readout strong { display: block; font-family: var(--serif); font-size: 19px; color: var(--maroon); }

/* ───────────── Small screens ───────────── */
@media (max-width: 900px) {
  #sidebar { position: fixed; inset: 0 auto 0 0; width: min(92vw, 380px); transform: translateX(-105%); transition: transform .25s; }
  body.side-open #sidebar { transform: none; }
  #side-close { display: grid; }
  #menu-btn { display: grid; }
  .toggle { left: 60px; }
  #detail { top: auto; left: 8px; right: 8px; bottom: 100px; width: auto; max-width: none; height: 52vh; }
  @keyframes slide { from { opacity: 0; transform: translateY(24px); } }
  #timeline { left: 8px; right: 8px; bottom: 8px; gap: 8px; padding: 8px 12px 8px 6px; }
  .tl-readout { width: 104px; font-size: 11px; }
  .tl-readout strong { font-size: 15px; }
  .tl-labels { display: none; }
  .d-head h2 { font-size: 21px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ───────────── Top bar, language switch ───────────── */
.topbar { position: absolute; z-index: 1000; top: 12px; left: 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; max-width: calc(100% - 24px); }
.topbar > * { position: static; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); }
.lang { display: flex; border-radius: 999px; overflow: hidden; padding: 3px; gap: 2px; }
.lang button { border: 0; background: none; padding: 4px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.lang button.on { background: var(--maroon); color: #fff; }

/* ───────────── Walk-the-path button and the walking figure ───────────── */
#play { width: auto; height: 44px; padding: 0 18px 0 14px; border-radius: 999px; gap: 8px; display: flex; align-items: center; font-size: 14px; font-weight: 700; white-space: nowrap; background: var(--maroon); color: #fff; box-shadow: 0 3px 10px rgba(109, 26, 31, .4); }
#play:hover { background: #8a2228; }
#play .ico { font-size: 14px; width: 14px; text-align: center; }
#play.on { background: var(--saffron); box-shadow: 0 3px 10px rgba(224, 138, 30, .5); }
#speed { width: auto; min-width: 38px; padding: 0 8px; font-size: 12.5px; font-weight: 700; color: var(--maroon); border-radius: 999px; }
.walker { animation: bob .45s ease-in-out infinite alternate; filter: drop-shadow(0 3px 4px rgba(40, 15, 0, .45)); }
.walker.flip svg { transform: scaleX(-1); }
@keyframes bob { from { transform: translateY(0); } to { transform: translateY(-4px); } }

/* ───────────── Sinhala typography ───────────── */
:root {
  --serif: 'Gentium Book Plus', 'Noto Serif Sinhala', 'Noto Serif', 'Iskoola Pota', Georgia, serif;
  --sans: 'Segoe UI', 'Noto Sans Sinhala', 'Nirmala UI', 'Iskoola Pota', system-ui, -apple-system, Roboto, Arial, sans-serif;
}
body.lang-si { line-height: 1.65; }
body.lang-si .brand h1 { font-size: 19px; line-height: 1.4; }
body.lang-si .d-head h2 { font-size: 21px; line-height: 1.45; }
body.lang-si .summary { font-size: 15.5px; line-height: 1.8; }
body.lang-si .intro { font-size: 14.5px; line-height: 1.8; }
body.lang-si .row .t, body.lang-si .item b, body.lang-si .person .pn { font-size: 14.5px; line-height: 1.5; }
body.lang-si .ph-head h3 { font-size: 15.5px; }
body.lang-si .d-body h4, body.lang-si .d-head .eyebrow { letter-spacing: 0; text-transform: none; font-size: 13.5px; }
body.lang-si .chip { font-size: 11.5px; }
body.lang-si .place-label, body.lang-si .place-tip { font-size: 13px; }
@media (max-width: 900px) { #play .lbl { display: none; } #play { padding: 0 15px; } .tl-controls #speed { display: none; } }

/* ───────────── Dhamma Chakka image in the header ───────────── */
.brand img.wheel { width: 56px; height: 56px; filter: drop-shadow(0 2px 5px rgba(0, 0, 0, .45)); }

/* ───────────── Photos of the site today ───────────── */
.photos { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.photos .ph { border: 0; padding: 0; background: #e9dfc6; border-radius: 10px; overflow: hidden; aspect-ratio: 4 / 3; display: block; box-shadow: 0 1px 4px rgba(60, 30, 10, .25); }
.photos .ph img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
.photos .ph:hover img { transform: scale(1.06); }
.photos .ph:first-child:nth-last-child(odd) { grid-column: span 2; aspect-ratio: 16 / 9; }
.credit { font-size: 11.5px; color: var(--ink-soft); margin: 6px 0 0; }
#lightbox { position: fixed; inset: 0; z-index: 3000; background: rgba(20, 8, 4, .93); display: none; align-items: center; justify-content: center; padding: 16px 64px; }
#lightbox.open { display: flex; }
#lightbox figure { margin: 0; max-width: 1200px; display: flex; flex-direction: column; align-items: center; }
#lightbox img { max-width: 100%; max-height: calc(100vh - 150px); max-height: calc(100dvh - 150px); border-radius: 8px; box-shadow: 0 10px 40px rgba(0, 0, 0, .6); background: #2b1d12; }
#lightbox figcaption { color: #fbeccb; font-size: 14.5px; line-height: 1.5; text-align: center; margin-top: 12px; max-width: 800px; }
#lightbox figcaption b { font-family: var(--serif); font-size: 17px; }
#lightbox figcaption span { font-size: 12.5px; opacity: .85; }
#lightbox figcaption a { color: var(--gold); }
#lightbox button { position: absolute; border: 0; background: rgba(255, 255, 255, .12); color: #fff; width: 46px; height: 46px; border-radius: 50%; font-size: 28px; line-height: 1; cursor: pointer; }
#lightbox button:hover { background: rgba(255, 255, 255, .28); }
#lightbox .lb-x { top: 14px; right: 14px; }
#lightbox .lb-prev { left: 10px; top: 50%; transform: translateY(-50%); }
#lightbox .lb-next { right: 10px; top: 50%; transform: translateY(-50%); }
#lightbox.single .lb-nav { display: none; }
@media (max-width: 900px) { #lightbox { padding: 12px 8px; } #lightbox .lb-prev, #lightbox .lb-next { top: auto; bottom: 14px; transform: none; } #lightbox .lb-prev { left: 30%; } #lightbox .lb-next { right: 30%; } #lightbox figure { padding-bottom: 60px; } }
