:root {
  --gold: #b8860b;
  --gold-dark: #8a6608;
  --bg: #ffffff;
  --panel: #f7f6f2;
  --border: #e4e1d8;
  --text: #24221d;
  --muted: #6b665c;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
.hidden { display: none !important; }
body {
  font-family: "Hiragino Sans", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}
#app {
  display: flex;
  height: 100vh;
  height: calc(100vh - 42px);
  height: 100dvh;
  height: calc(100dvh - 42px);
  width: 100%;
  position: relative;
}

#sidebar {
  width: 340px;
  flex: 0 0 340px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--panel);
  height: 100%;
}
#brand {
  background: var(--gold);
  color: #fff;
  padding: 16px 18px;
  position: relative;
}
#brand h1 { margin: 0; font-size: 18px; line-height: 1.3; font-weight: 700; }
#brand h1 span { font-size: 12px; font-weight: 400; opacity: .9; }
#count { margin: 8px 0 0; font-size: 13px; opacity: .95; }

#sidebarClose { display: none; }

#sidebarOpen {
  display: none;
  position: absolute;
  left: 12px; bottom: 16px;
  z-index: 500;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  cursor: pointer;
}

#controls { padding: 12px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid var(--border); }
#search, #prefFilter {
  width: 100%; padding: 8px 10px; font-size: 14px;
  border: 1px solid var(--border); border-radius: 6px; background: #fff;
}
#search:focus, #prefFilter:focus { outline: 2px solid var(--gold); border-color: var(--gold); }

#list {
  list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1;
}
#list li {
  padding: 10px 14px; border-bottom: 1px solid var(--border); cursor: pointer;
  display: flex; flex-direction: column; gap: 2px;
}
#list li:hover { background: #f1efe7; }
#list li.active { background: #f6ead0; border-left: 4px solid var(--gold); padding-left: 10px; }
#list li .name { font-size: 14px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 6px; }
#list li .name .dot { width: 10px; height: 10px; }
#list li .meta { font-size: 12px; color: var(--muted); }
#list li .badge { font-size: 11px; color: #b00020; }

#src { font-size: 11px; color: var(--muted); padding: 10px 14px; border-top: 1px solid var(--border); line-height: 1.5; }
#src a { color: var(--gold-dark); }

#map { flex: 1; height: 100%; }

/* tier / category filter */
#tierFilter, #catFilter { border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; legend { font-size: 11px; color: var(--muted); padding: 0 4px; } }
.brand-chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; margin: 3px 6px 3px 0; cursor: pointer; white-space: nowrap; }
.brand-chip input { margin: 0; }
.brand-chip em { font-style: normal; color: var(--muted); font-size: 11px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }

/* popup */
.leaflet-popup-content { font-size: 13px; line-height: 1.5; }
.leaflet-popup-content .pname { font-weight: 700; font-size: 14px; margin: 0 0 4px; color: var(--text); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.leaflet-popup-content .ptag { color: #fff; font-size: 10px; font-weight: 600; padding: 1px 6px; border-radius: 8px; }
.leaflet-popup-content .pcat { font-size: 11px; color: var(--muted); margin: 0 0 4px; }
.leaflet-popup-content .paddr { margin: 0 0 4px; }
.leaflet-popup-content .pnote { margin: 0 0 6px; font-size: 12px; color: var(--muted); }
.leaflet-popup-content .plinks { display: flex; flex-wrap: wrap; gap: 6px; }
.leaflet-popup-content .plinks a.lk {
  color: #fff; background: var(--gold); text-decoration: none;
  padding: 4px 9px; border-radius: 4px; font-size: 12px; line-height: 1.4;
}
.leaflet-popup-content .plinks a.lk.g { background: #1a73e8; }
.leaflet-popup-content .plinks a.lk.s { background: #555; }

@media (max-width: 720px) {
  #app { position: relative; overflow: hidden; }
  #sidebar {
    position: absolute;
    inset: 0;
    width: 100%;
    flex: none;
    z-index: 1000;
    border-right: none;
    transform: translateY(0);
    transition: transform .25s ease;
  }
  #sidebar.closed { transform: translateY(100%); }
  #sidebarClose {
    display: block;
    position: absolute;
    top: 12px; right: 14px;
    background: rgba(255,255,255,.2);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 30px; height: 30px;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
  }
  #sidebarOpen { display: block; }
  #map { width: 100%; height: 100%; }
}

/* tabs */
#tabs { display: flex; gap: 0; background: var(--gold-dark); }
#tabs .tab {
  border: none; background: transparent; color: #f0e6cf; cursor: pointer;
  padding: 10px 18px; font-size: 14px; font-weight: 600; border-bottom: 3px solid transparent;
}
#tabs .tab:hover { color: #fff; background: rgba(255,255,255,.08); }
#tabs .tab.active { color: #fff; border-bottom-color: #ffd84d; background: var(--gold); }

/* ranking view */
#rankingView {
  display: block;
  height: calc(100vh - 42px);
  height: calc(100dvh - 42px);
  overflow: auto;
  background: var(--panel);
}
.ranking-inner { max-width: 900px; margin: 0 auto; padding: 20px; }
.ranking-head h2 { margin: 0 0 6px; font-size: 20px; color: var(--text); }
.ranking-note { margin: 0 0 10px; font-size: 13px; color: var(--muted); line-height: 1.6; }
.ranking-note strong { color: var(--gold-dark); }
.ranking-summary { font-size: 13px; color: var(--text); background: #fff; border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; }
.rank-sort { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.rank-sort-label { font-size: 13px; color: var(--muted); }
.sortbtn { border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 6px 12px; border-radius: 20px; font-size: 13px; cursor: pointer; }
.sortbtn:hover { border-color: var(--gold); }
.sortbtn.active { background: var(--gold); color: #fff; border-color: var(--gold); }
.ranking-table-wrap { background: #fff; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
#rankingTable { width: 100%; border-collapse: collapse; font-size: 14px; }
#rankingTable th { background: #f1efe7; color: var(--gold-dark); text-align: left; padding: 9px 12px;
  font-size: 12px; position: sticky; top: 0; }
#rankingTable th.r, #rankingTable th.pt, #rankingTable th.n { text-align: right; }
#rankingTable td { padding: 8px 12px; border-top: 1px solid var(--border); }
#rankingTable tbody tr { cursor: pointer; }
#rankingTable tbody tr:hover { background: #f7f4ec; }
#rankingTable td.r { text-align: right; font-weight: 700; }
#rankingTable td.pt { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--gold-dark); }
#rankingTable td.n { text-align: right; font-variant-numeric: tabular-nums; }
#rankingTable td.pref { font-weight: 600; }
#rankingTable td.zero { color: var(--border); }
#rankingTable td.pt { min-width: 120px; }
.devbar { width: 100%; height: 8px; background: #f1efe7; border-radius: 4px; overflow: hidden; margin-bottom: 3px; }
.devbar span { display: block; height: 100%; }

@media (max-width: 600px) {
  #rankingTable th, #rankingTable td { padding: 6px 8px; font-size: 12px; }
}