:root {
  --bg: #e9e2d3;
  --panel: rgba(255, 252, 245, 0.9);
  --panel-border: rgba(70, 50, 30, 0.12);
  --ink: #2b2118;
  --muted: #7a6a58;
  --accent: #c2410c;
  --accent-ink: #fff7ed;
  --chip: rgba(70, 50, 30, 0.06);
  --shadow: 0 8px 28px rgba(60, 40, 20, 0.14);
}
:root[data-mode='dusk'] { --bg: #e2b99a; }
:root[data-mode='night'] {
  --bg: #0f1526;
  --panel: rgba(18, 24, 42, 0.88);
  --panel-border: rgba(255, 255, 255, 0.1);
  --ink: #f1e8d8;
  --muted: #a69c8c;
  --accent: #ffc56a;
  --accent-ink: #1a1206;
  --chip: rgba(255, 255, 255, 0.07);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 Inter, system-ui, -apple-system, sans-serif;
  transition: background-color 0.4s;
}
.deva { font-family: 'Noto Sans Devanagari', Inter, sans-serif; }

#map {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
#map.dragging { cursor: grabbing; }

.panel {
  position: fixed;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.title { top: calc(16px + env(safe-area-inset-top, 0px)); left: calc(16px + env(safe-area-inset-left, 0px)); padding: 12px 16px; max-width: calc(100vw - 32px); }
.title h1 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.title h1 .deva { color: var(--accent); margin-right: 6px; }
.title p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.title .attrib { font-size: 11px; }
.title .attrib a { color: inherit; }

.places {
  top: calc(16px + env(safe-area-inset-top, 0px));
  right: calc(16px + env(safe-area-inset-right, 0px));
  width: 248px;
  max-height: calc(100vh - 260px);
  display: flex;
  flex-direction: column;
  padding: 12px 8px 8px;
}
.places h2 { margin: 0 8px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.places ul { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.list-toggle { display: none; }
.lm {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
  padding: 6px 8px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.lm:hover { background: var(--chip); }
.lm.on { background: var(--accent); color: var(--accent-ink); }
.lm .hi { font-family: 'Noto Sans Devanagari', sans-serif; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }
.lm.on .hi { color: inherit; opacity: 0.8; }

.card {
  left: calc(16px + env(safe-area-inset-left, 0px));
  bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  width: 340px;
  max-width: calc(100vw - 32px);
  padding: 16px 18px;
}
.card h2 { margin: 0; font-size: 20px; letter-spacing: -0.01em; }
.card .photo { margin: -16px -18px 12px; }
.card .photo img {
  display: block;
  width: 100%;
  height: 190px;
  object-fit: cover;
  border-radius: 14px 14px 0 0;
  background: var(--chip);
}
.card .photo figcaption { padding: 4px 18px 0; font-size: 10.5px; color: var(--muted); line-height: 1.35; }
.card .photo figcaption a { color: inherit; }
.card .close { z-index: 1; background: rgba(255, 252, 245, 0.85); color: #2b2118; }
@media (max-width: 720px) { .card .photo img { height: 140px; } }
.card .era { margin: 0 0 2px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); }
.card .hi-name { margin: 0 0 8px; color: var(--muted); font-size: 15px; }
.card p:last-child { margin: 0; }
.close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: var(--chip);
  color: inherit;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.controls {
  left: calc(16px + env(safe-area-inset-left, 0px));
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex;
  gap: 8px;
  padding: 6px;
  flex-wrap: wrap;
  max-width: calc(100vw - 32px);
}
.seg { display: flex; background: var(--chip); border-radius: 9px; padding: 2px; }
.seg button {
  border: 0;
  background: none;
  color: inherit;
  font: 500 13px Inter, system-ui, sans-serif;
  padding: 6px 11px;
  border-radius: 7px;
  cursor: pointer;
  min-width: 34px;
}
.seg button:hover { background: var(--chip); }
.seg button[aria-pressed='true'] { background: var(--accent); color: var(--accent-ink); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.minimap-wrap { right: calc(16px + env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); padding: 8px; width: 248px; }
#minimap { display: block; width: 100%; height: 124px; cursor: crosshair; border-radius: 8px; }
.legend { list-style: none; display: flex; gap: 10px; margin: 6px 2px 0; padding: 0; font-size: 11px; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }

.loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  background: var(--bg);
  color: var(--muted);
  z-index: 10;
}
.loading[hidden] { display: none; }
.loading-mark {
  width: 34px;
  height: 34px;
  background: var(--accent);
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  animation: spin 1.4s ease-in-out infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 720px) {
  .title { padding: 10px 12px; }
  .title h1 { font-size: 16px; }
  .title p:not(.attrib) { display: none; }
  .places {
    top: calc(92px + env(safe-area-inset-top, 0px));
    bottom: auto;
    right: calc(16px + env(safe-area-inset-right, 0px));
    width: auto;
    max-height: none;
    padding: 4px;
  }
  .places h2, .places ul, .places .search { display: none; }
  .list-toggle {
    display: block;
    border: 0;
    background: none;
    color: inherit;
    font: 600 13px Inter, system-ui, sans-serif;
    padding: 6px 10px;
    cursor: pointer;
  }
  body.list-open .places { left: calc(16px + env(safe-area-inset-left, 0px)); }
  body.list-open .places ul { display: block; max-height: calc(100vh - 340px); }
  body.list-open .places .search { display: block; }
  .minimap-wrap { display: none; }
  .card { bottom: calc(150px + env(safe-area-inset-bottom, 0px)); }
  .controls { left: 16px; right: 16px; justify-content: center; }
  .seg button { padding: 6px 9px; }
}

.search {
  margin: 0 4px 6px;
  padding: 7px 10px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--chip);
  color: inherit;
  font: 13px Inter, system-ui, sans-serif;
}
.search:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.places .empty { padding: 6px 8px; color: var(--muted); font-size: 13px; }

/* Panels hidden for a clean view: only the controls stay. */
body.clean .title,
body.clean .places,
body.clean .card,
body.clean .minimap-wrap { display: none; }

/* Wikipedia summary in a landmark card */
.wiki { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--panel-border); }
.wiki p { margin: 0; font-size: 13px; line-height: 1.45; }
.wiki #card-wiki-text { display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.wiki .wiki-src { margin-top: 4px; font-size: 10.5px; color: var(--muted); }
.wiki a { color: inherit; }
.card { max-height: calc(100vh - 120px); overflow-y: auto; }

/* Building inspector */
.tip {
  left: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 190px;
  max-width: 260px;
  padding: 10px 34px 10px 12px;
  font-size: 12.5px;
  line-height: 1.35;
  pointer-events: auto;
  will-change: transform;
}
.tip[hidden] { display: none; }
.tip strong { font-size: 14px; }
.tip span { color: var(--muted); }
.tip a { margin-top: 3px; color: var(--accent); font-weight: 600; font-size: 12px; }
.tip .close { top: 4px; right: 4px; width: 26px; height: 26px; font-size: 16px; }
.tip.peek { pointer-events: none; padding-right: 12px; }
.tip.peek .close, .tip.peek a { display: none; }

/* Tours */
.tours-menu {
  left: calc(16px + env(safe-area-inset-left, 0px));
  bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  width: 320px;
  max-width: calc(100vw - 32px);
  padding: 12px;
}
.tours-menu[hidden] { display: none; }
.tours-menu h2 { margin: 0 6px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.tours-menu ul { list-style: none; margin: 0; padding: 0; }
.tours-menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  color: inherit;
  padding: 8px;
  border-radius: 9px;
  font: 600 14px Inter, system-ui, sans-serif;
  cursor: pointer;
}
.tours-menu button:hover { background: var(--chip); }
.tours-menu button small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); margin-top: 1px; }
.tourbar {
  top: calc(16px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 40px 6px 14px;
  max-width: calc(100vw - 32px);
}
.tourbar[hidden] { display: none; }
.tour-text { display: flex; flex-direction: column; min-width: 0; }
.tour-name { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); }
.tour-step { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tourbar .close { top: 50%; transform: translateY(-50%); }
#tours-btn[aria-expanded='true'] { background: var(--accent); color: var(--accent-ink); }
@media (max-width: 720px) {
  .tourbar { top: calc(88px + env(safe-area-inset-top, 0px)); left: 16px; right: 16px; transform: none; }
  .tour-step { font-size: 13px; }
  body.touring .places { display: none; }
  .tours-menu { left: 16px; right: 16px; width: auto; bottom: calc(150px + env(safe-area-inset-bottom, 0px)); }
}
body.clean .tip, body.clean .tours-menu { display: none; }
