:root {
  --ink: #2b2118;
  --paper: #f6efe2;
  --paper-2: #ece2cf;
  --accent: #8a4b1f;
  --muted: #6b5a4a;
  --standing: #3f7d4e;
  --altered: #c58a1b;
  --demolished: #a8372c;
  --unknown: #6b7280;
  --radius: 10px;
  --topbar-h: 52px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--paper);
  display: flex; flex-direction: column;
}
h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; margin: 0; }

.topbar {
  height: var(--topbar-h); flex: none; display: flex; align-items: center; gap: 12px;
  padding: 0 12px; padding-top: env(safe-area-inset-top);
  background: #3b2f25; color: #f6efe2;
}
.topbar h1 { font-size: 1.1rem; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modes { display: flex; border: 1px solid #6d5a48; border-radius: 999px; overflow: hidden; }
.mode { background: none; color: inherit; border: 0; padding: 6px 14px; font: inherit; cursor: pointer; }
.mode.active { background: #f6efe2; color: #3b2f25; }

button { font: inherit; cursor: pointer; }
.ghost { background: none; border: 1px solid #6d5a48; color: inherit; border-radius: 999px; padding: 6px 12px; }
.filters .ghost { color: var(--ink); border-color: #b9a88f; }
.ghost.small { padding: 3px 10px; font-size: .85rem; }

.filters {
  flex: none; background: var(--paper-2); padding: 10px 14px 12px; border-bottom: 1px solid #d3c5ac;
  display: grid; gap: 8px; grid-template-columns: 1fr 1fr; align-items: center;
}
.filters[hidden] { display: none; }
.filters .row { display: flex; flex-direction: column; gap: 2px; min-width: 0; margin: 0; padding: 0; border: 0; }
.filters .checks { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; gap: 6px 14px; }
.filters .checks legend { font-size: .8rem; color: var(--muted); padding: 0; width: 100%; }
.filters .inline { flex-direction: row; align-items: center; gap: 6px; }
.filters label { font-size: .9rem; }
.filters output { font-weight: 600; }
input[type=range] { width: 100%; accent-color: var(--accent); }

main { position: relative; flex: 1; min-height: 0; }
#map { position: absolute; inset: 0; background: #e9e2d2; }

.status-line {
  position: absolute; left: 10px; bottom: 10px; z-index: 500; background: rgba(246,239,226,.94);
  border: 1px solid #cdbd9f; border-radius: 999px; padding: 3px 12px; font-size: .85rem; pointer-events: none;
}
.fab {
  position: absolute; right: 10px; bottom: 24px; z-index: 500; width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid #cdbd9f; background: var(--paper); font-size: 1.4rem; line-height: 1; box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.fab.on { background: var(--accent); color: #fff; }

/* Map pins */
.pin {
  width: 18px; height: 18px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.45);
  background: var(--unknown);
}
.pin.standing { background: var(--standing); }
.pin.altered { background: var(--altered); }
.pin.demolished { background: var(--demolished); }
.pin.historic { outline: 2px solid #2b2118; outline-offset: 1px; }
.pin.selected { transform: scale(1.35); }
.stop-pin {
  width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700;
  display: grid; place-items: center; border: 2px solid #fff; box-shadow: 0 1px 5px rgba(0,0,0,.5);
}
.stop-pin.active { background: #2b2118; transform: scale(1.2); }
.me-dot { width: 16px; height: 16px; border-radius: 50%; background: #2563eb; border: 3px solid #fff; box-shadow: 0 0 0 4px rgba(37,99,235,.25); }

/* Side panel (desktop) / bottom sheet (mobile) */
.panel {
  position: absolute; z-index: 600; background: var(--paper); overflow-y: auto; -webkit-overflow-scrolling: touch;
  box-shadow: 0 0 20px rgba(0,0,0,.3);
  top: 0; right: 0; bottom: 0; width: 400px; padding: 16px 16px 24px;
}
.panel[hidden] { display: none; }
.panel-close {
  position: sticky; top: 0; float: right; z-index: 2; width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid #cdbd9f; background: var(--paper); font-size: 1.4rem; line-height: 1;
}
.panel h2 { font-size: 1.3rem; margin-bottom: 4px; padding-right: 40px; }
.panel h3 { font-size: 1.05rem; margin: 18px 0 6px; }
.meta { color: var(--muted); font-size: .9rem; margin: 2px 0; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.badge { font-size: .78rem; padding: 2px 9px; border-radius: 999px; background: var(--paper-2); border: 1px solid #cdbd9f; }
.badge.standing { background: #dcefe0; border-color: #a9d1b2; }
.badge.altered { background: #f6e6bd; border-color: #e0c274; }
.badge.demolished { background: #f2d3cf; border-color: #d99c95; }
.badge.historic { background: #2b2118; color: #f6efe2; border-color: #2b2118; }

.photo-card { margin: 14px 0 20px; }
.photo-card img { width: 100%; height: auto; display: block; border-radius: 6px; background: var(--paper-2); cursor: zoom-in; }
.photo-card .year { font-family: Georgia, serif; font-weight: 700; font-size: 1.05rem; margin-top: 6px; }
.photo-card .title { margin: 0; }
.tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.tags span { font-size: .75rem; color: var(--muted); border: 1px solid #cdbd9f; border-radius: 4px; padding: 0 6px; }

.tour-card {
  display: block; width: 100%; text-align: left; background: #fff8ea; border: 1px solid #d3c5ac; border-radius: var(--radius);
  padding: 12px 14px; margin: 10px 0; color: inherit;
}
.tour-card strong { font-family: Georgia, serif; font-size: 1.05rem; display: block; }
.stepper { display: flex; gap: 8px; margin: 16px 0 4px; }
.stepper button {
  flex: 1; padding: 10px; border-radius: var(--radius); border: 1px solid var(--accent);
  background: var(--accent); color: #fff; font-weight: 600;
}
.stepper button.secondary { background: none; color: var(--accent); }
.stepper button:disabled { opacity: .4; cursor: default; }
.progress { color: var(--muted); font-size: .85rem; margin-top: 6px; }
.arrived { background: #dcefe0; border: 1px solid #a9d1b2; padding: 8px 10px; border-radius: 8px; margin: 10px 0; }

.lightbox { position: fixed; inset: 0; z-index: 2000; background: rgba(20,14,8,.94); display: grid; place-items: center; padding: 16px; }
.lightbox[hidden] { display: none; }
.lightbox figure { margin: 0; max-width: 100%; max-height: 100%; color: #f6efe2; text-align: center; }
.lightbox img { max-width: 100%; max-height: 80vh; border-radius: 4px; }
.lightbox figcaption { margin-top: 8px; font-size: .95rem; }
.lightbox-close {
  position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 12px; width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid #6d5a48; background: none; color: #f6efe2; font-size: 1.6rem;
}

@media (max-width: 700px) {
  .filters { grid-template-columns: 1fr; }
  .panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 58%; border-radius: 16px 16px 0 0; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
  .fab { bottom: calc(58% + 12px); }
  body.panel-open .status-line { display: none; }
}

@media (prefers-reduced-motion: no-preference) {
  .pin, .stop-pin { transition: transform .12s ease; }
}
