:root {
  --bg: #ffffff;
  --bg-elev: #ffffff;
  --ink: #1c1722;
  --ink-soft: #463f4e;
  --muted: #6b6472;
  --accent: #1a1a1a;
  --accent-deep: #000000;
  --accent-soft: #ececec;
  --line: #ece6f0;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-full: 999px;
  --transition: 180ms ease;
  --shadow-card: 0 8px 30px rgba(0, 0, 0, 0.12);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  color: var(--ink);
  background: #e9e4ef;
  -webkit-font-smoothing: antialiased;
}

.app { position: relative; height: 100dvh; width: 100vw; overflow: hidden; }

#map { position: absolute; inset: 0; background: #e9e4ef; }

/* ---- Panel ---- */
.panel {
  position: absolute;
  z-index: 2;
  left: 0; right: 0; bottom: 60px;
  max-height: 60%;
  background: var(--bg);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.mode-guide .filterbar { display: none; }

.brand {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 20px 22px 14px;
}
.brand-mark {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  color: var(--accent);
  flex-shrink: 0;
}
.brand-mark svg { width: 24px; height: 24px; }
.brand-text h1 {
  font-size: 22px; font-weight: 700; letter-spacing: -0.02em; line-height: 1;
}
.tagline { font-size: 13px; color: var(--ink-soft); margin-top: 3px; }

.panel-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0 22px 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#detail { flex: 1; display: flex; flex-direction: column; }

/* ---- Filter bar (floating over the map) ---- */
.filterbar {
  position: absolute;
  z-index: 3;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 24px);
}
.filterbar-inner {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-card);
  padding: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
.filterbar-inner::-webkit-scrollbar { display: none; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  height: 40px;
  min-width: 40px;
  padding: 0 10px;
  justify-content: center;
  border: none;
  background: none;
  color: var(--ink);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--transition), color var(--transition), padding var(--transition);
}
.pill-emoji { font-size: 19px; line-height: 1; }
.pill-label { display: none; font-family: inherit; font-size: 14px; font-weight: 600; white-space: nowrap; }
.pill:hover { background: var(--accent-soft); }
.pill.active { background: var(--accent); color: #fff; padding: 0 15px 0 12px; }
.pill.active .pill-label { display: inline; }

/* ---- Detail ---- */
.detail-intro {
  margin: auto 0;
  text-align: center;
  padding: 24px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.intro-mark { display: block; margin-bottom: 10px; }
.intro-mark img { width: 160px; height: auto; display: block; }
.intro-name { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 18px; }
.intro-prompt { font-size: 17px; font-weight: 500; color: var(--ink); }
.intro-sub { font-size: 14px; color: var(--muted); margin-top: 8px; }

.place { animation: rise var(--transition); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.place-top {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
}
.place h2 { font-size: 21px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.2; }
.place-close {
  flex-shrink: 0; border: none; background: none; cursor: pointer;
  color: var(--muted); font-size: 22px; line-height: 1; padding: 2px 4px;
  border-radius: var(--radius-sm); transition: var(--transition);
}
.place-close:hover { color: var(--ink); background: var(--line); }

.chip {
  display: inline-block; margin-top: 10px;
  font-size: 12px; font-weight: 600; letter-spacing: 0.03em;
  color: var(--accent); background: var(--accent-soft);
  padding: 4px 11px; border-radius: var(--radius-full);
}
.place-story { font-size: 15px; line-height: 1.65; margin-top: 14px; color: var(--ink); }
.place-addr { font-size: 13px; color: var(--muted); margin-top: 12px; }

.go-btn {
  display: inline-flex; align-items: center; gap: 7px;
  margin-top: 18px;
  font-size: 14px; font-weight: 600;
  color: var(--accent); text-decoration: none;
  border: 1px solid var(--accent); background: var(--bg-elev);
  padding: 10px 16px; border-radius: var(--radius-full);
  transition: var(--transition);
}
.go-btn:hover { background: var(--accent); color: #fff; transform: translateY(-2px); }
.go-btn.added { background: var(--accent); color: #fff; }

/* Place detail (left-aligned, top of panel) */
.place-detail { margin: 0; padding-top: 24px; }
.actions { margin-top: 18px; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.place-detail .go-btn { margin-top: 0; }
.back-btn {
  font-family: inherit; font-size: 14px; font-weight: 500;
  color: var(--ink-soft); background: none; border: none;
  cursor: pointer; padding: 8px 2px;
  transition: var(--transition);
}
.back-btn:hover { color: var(--ink); }

/* Sources pill + list */
.sources { margin-top: 14px; }
.sources-pill {
  font-family: inherit; font-size: 13px; font-weight: 600;
  color: var(--ink-soft); background: var(--accent-soft);
  border: none; border-radius: var(--radius-full);
  padding: 7px 13px; cursor: pointer; transition: var(--transition);
}
.sources-pill:hover { color: var(--ink); }
.src-caret { display: inline-block; transition: transform var(--transition); }
.sources-pill.open .src-caret { transform: rotate(90deg); }
.sources-list { display: flex; flex-direction: column; gap: 7px; margin-top: 10px; }
.sources-list[hidden] { display: none; }
.sources-list a {
  font-size: 13px; color: var(--ink); text-decoration: none;
  display: inline-flex; align-items: baseline; gap: 6px; line-height: 1.4;
}
.sources-list a::before { content: "↗"; color: var(--muted); font-size: 11px; }
.sources-list a:hover { text-decoration: underline; }

.panel-foot { padding: 12px 22px 18px; }
.ver { font-size: 12px; color: var(--muted); text-align: center; }

/* ---- Nav rail (mobile: bottom tab bar) ---- */
.rail {
  position: absolute; z-index: 4;
  left: 0; right: 0; bottom: 0;
  height: 60px;
  display: flex; align-items: center; justify-content: center; gap: 24px;
  background: var(--bg-elev);
  border-top: 1px solid var(--line);
}
.rail-logo { display: none; }
.rail-btn {
  position: relative;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; width: 72px; height: 48px;
  border: none; background: none; color: var(--muted);
  cursor: pointer; border-radius: var(--radius-md);
  transition: color var(--transition), background var(--transition);
}
.rail-btn svg { width: 22px; height: 22px; }
.rail-tab-label { font-size: 11px; font-weight: 600; }
.rail-btn.active { color: var(--accent); }
.rail-btn:hover { color: var(--accent); }
.rail-btn:focus { outline: none; }
.rail-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.rail-badge {
  position: absolute; top: 2px; right: 16px;
  min-width: 16px; height: 16px; padding: 0 4px; box-sizing: border-box;
  font-size: 10px; font-weight: 700; line-height: 16px; text-align: center;
  color: #fff; background: var(--accent); border-radius: 999px;
  display: none;
}
.rail-badge.show { display: block; }

.tour-view { padding-top: 24px; }
.tour-meta { font-size: 13px; color: var(--ink-soft); margin: 4px 0 14px; }
.tour-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.tour-card {
  position: relative;
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: 10px; padding: 18px 10px 14px;
  border: 1px solid var(--line); border-radius: var(--radius-md);
  background: var(--bg-elev);
  transition: var(--transition);
}
.tour-card.visited { background: var(--accent-soft); border-color: transparent; }
.tour-stamp {
  flex-shrink: 0; width: 42px; height: 42px; border-radius: 50%;
  border: 2px dashed var(--muted); background: none; color: #fff;
  display: grid; place-items: center; cursor: pointer; padding: 0;
  transition: var(--transition);
}
.tour-stamp svg { width: 20px; height: 20px; opacity: 0; transition: var(--transition); }
.tour-stamp:hover { border-color: var(--ink); }
.tour-card.visited .tour-stamp {
  background: var(--accent); border: 2px solid var(--accent); transform: rotate(-8deg);
}
.tour-card.visited .tour-stamp svg { opacity: 1; }
.tour-card-body {
  min-width: 0; text-align: center;
  display: flex; flex-direction: column; gap: 3px; align-items: center;
  background: none; border: none; cursor: pointer; font-family: inherit; padding: 0;
}
.tour-name { font-size: 14px; font-weight: 600; color: var(--ink); line-height: 1.3; }
.tour-card.visited .tour-name { color: var(--ink-soft); }
.tour-type { font-size: 11px; color: var(--muted); letter-spacing: 0.02em; }
.tour-remove {
  position: absolute; top: 6px; right: 6px;
  width: 24px; height: 24px;
  border: none; background: none; color: var(--muted);
  font-size: 16px; line-height: 1; cursor: pointer; border-radius: var(--radius-sm);
  display: grid; place-items: center;
}
.tour-remove:hover { color: var(--ink); background: var(--line); }

/* ---- Map markers ---- */
.marker { will-change: transform; cursor: pointer; }
.pin {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  cursor: pointer; padding: 0;
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
}
.pin svg { width: 16px; height: 16px; }
.pin:hover { transform: translateY(-2px) scale(1.1); }
.pin.active {
  background: var(--accent-deep);
  transform: scale(1.2);
  box-shadow: 0 0 0 4px var(--accent-soft), 0 4px 14px rgba(0, 0, 0, 0.4);
}
.marker.hidden { display: none; }

.maplibregl-ctrl-attrib { font-size: 10px; }

/* ---- Desktop: floating left card ---- */
@media (min-width: 860px) {
  .rail {
    top: 18px; bottom: 18px; left: 18px; right: auto;
    width: 62px; height: auto;
    flex-direction: column; justify-content: flex-start; gap: 6px;
    padding: 14px 0;
    border-top: none; border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
  }
  .rail-logo {
    display: grid; place-items: center;
    width: 38px; height: 38px; color: var(--accent); margin-bottom: 8px;
  }
  .rail-logo svg { width: 26px; height: 26px; }
  .rail-btn { width: 46px; height: 46px; }
  .rail-btn:not(.active):hover { background: #f3f3f3; color: var(--ink); }
  .rail-btn.active { background: var(--accent-soft); color: var(--ink); }
  .rail-tab-label { display: none; }
  .rail-badge { top: 0; right: 4px; }
  .panel {
    top: 18px; bottom: 18px; left: 92px; right: auto;
    width: 372px;
    max-height: none;
    border-radius: var(--radius-lg);
  }
  /* Bottom-center, offset right of the rail + panel so they don't collide */
  .filterbar {
    top: auto;
    bottom: 26px;
    left: calc(50% + 230px);
  }
}
