:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1c2330;
  --muted: #66707f;
  --line: #e3e7ee;
  --accent: #0288d1;
  --accent-soft: #e3f2fd;
  --accent-ink: #01579b;
  --navy: #14213d;
  --shadow: 0 8px 24px rgba(20, 33, 61, 0.14);
  --sidebar-w: 380px;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
        "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; }

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

/* ---------- sidebar ---------- */

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
  z-index: 1100;
}

.sidebar-header {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 16px 14px 14px 18px;
  background: var(--navy);
  color: #fff;
}

.brand { min-width: 0; }
.brand h1 { margin: 0; font-size: 19px; font-weight: 700; line-height: 1.25; letter-spacing: 0.01em; }
.subtitle { margin: 2px 0 0; font-size: 13px; color: rgba(255, 255, 255, 0.88); }
.stats { margin: 4px 0 0; font-size: 12px; color: rgba(255, 255, 255, 0.66); }

.header-actions { margin-left: auto; display: flex; gap: 4px; flex: 0 0 auto; }

.icon-btn {
  width: 32px; height: 32px;
  border: 0; border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-weight: 600; font-size: 13px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.24); }
.icon-btn.dark { background: var(--bg); color: var(--ink); }
#btn-lang { width: auto; padding: 0 10px; white-space: nowrap; }
.icon-btn.dark:hover { background: var(--line); }

.controls {
  display: grid; gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.search-wrap { position: relative; }
.search-wrap input {
  width: 100%;
  padding: 9px 32px 9px 34px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink);
  font: inherit;
}
.search-wrap input:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: #fff; }
.search-wrap input::-webkit-search-cancel-button { display: none; }
.search-ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-wrap .clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 24px; height: 24px; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted); cursor: pointer; font-size: 12px;
}
.search-wrap .clear:hover { background: var(--line); color: var(--ink); }

.suggest {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 20;
  max-height: 340px; overflow-y: auto;
  padding: 4px;
  background: #fff;
  border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow);
}
.suggest[hidden] { display: none; }
.sg {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 7px 8px;
  border: 0; border-radius: 7px;
  background: transparent; color: var(--ink);
  text-align: left; cursor: pointer;
}
.sg:hover, .sg.active { background: var(--accent-soft); }
.sg-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.sg-text mark { background: rgba(2, 136, 209, 0.18); color: inherit; border-radius: 3px; padding: 0 1px; }
.sg-sub { font-size: 11px; color: var(--muted); margin-top: 1px; }
.sg-kind {
  flex: 0 0 auto;
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--muted); background: var(--bg); border-radius: 999px; padding: 2px 7px;
}
.dot-country { background: #9aa4b2; }
.dot-region { background: var(--navy); }

select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink);
  font: inherit;
}

.filter-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.filter-row[hidden] { display: none; }

.pill {
  display: inline-block; flex: 0 0 auto;
  padding: 1px 7px; border-radius: 999px;
  font-size: 10.5px; font-weight: 600; line-height: 1.5; white-space: nowrap;
  background: var(--bg); color: var(--muted);
}
.pill-type-boys { background: #e3f2fd; color: #01579b; }
.pill-type-boys_girls_separate { background: #ede7f6; color: #4527a0; }
.pill-type-mixed { background: #e8f5e9; color: #1b5e20; }
.pill-type-unknown { background: var(--bg); color: var(--muted); }
.pill-status-active { background: #e8f5e9; color: #1b5e20; }
.pill-status-uncertain { background: #fff8e1; color: #8d6e00; }
.pill-status-inactive { background: #fdecea; color: #b71c1c; }
.pill-status-none { background: var(--bg); color: var(--muted); }
.item.inactive .name { color: var(--muted); }
.item.inactive .dot { opacity: 0.45; }
.pp-facts { margin: 0 0 8px; display: flex; flex-wrap: wrap; gap: 4px; }
.pp-facts .pill { font-size: 11px; padding: 2px 8px; }
.note.closed { background: #fdecea; color: #7f1d1d; border-radius: 8px; padding: 6px 8px; font-size: 12px; }
.note.renamed { background: #e8f5e9; color: #1b5e20; border-radius: 8px; padding: 6px 8px; font-size: 12px; }

.legend { display: grid; gap: 8px; }
.legend-group { display: grid; gap: 4px; }
.legend-title { font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.legend-row { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.legend-item {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12.5px; cursor: pointer; user-select: none;
}
.legend-item input { accent-color: var(--accent); margin: 0; }
.legend-pin { display: inline-flex; width: 14px; height: 18px; }
.legend-pin svg { display: block; }
.legend-pin.pin-inactive { opacity: 0.55; }
.svg-pin.pin-inactive { opacity: 0.6; }

.dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  flex: 0 0 auto; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
}
.count { color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }

.list-status { margin: 0; padding: 8px 18px 0; font-size: 12px; color: var(--muted); }

.list { flex: 1; overflow-y: auto; padding: 6px 8px 16px; }

.group summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 8px 4px;
  font-size: 11.5px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted);
}
.group summary::-webkit-details-marker { display: none; }
.group summary::before {
  content: ""; width: 0; height: 0;
  border: 4px solid transparent; border-left: 5px solid currentColor;
  transition: transform 0.15s;
}
.group[open] summary::before { transform: rotate(90deg); }
.group-name { flex: 1; }

.country { padding-bottom: 2px; }
.subhead {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 9px 10px 3px;
  border: 0; background: transparent; color: var(--ink);
  font-size: 12.5px; font-weight: 700; text-align: left; cursor: pointer;
}
.subhead:hover .subhead-name { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.subhead-name { flex: 1; }
.country .item { padding-left: 22px; }
.no-country .item { padding-left: 10px; }

.item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 8px 10px;
  border: 0; border-radius: 8px;
  background: transparent; color: var(--ink);
  text-align: left; cursor: pointer;
}
.item:hover { background: var(--bg); }
.item:focus-visible { outline: 2px solid var(--accent); }
.item.active { background: var(--accent-soft); color: var(--accent-ink); }
.item .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .alt-name { display: block; font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.pp-alt { margin: -2px 0 6px; color: var(--muted); font-size: 12.5px; }
.item .nlinks {
  font-size: 11px; color: var(--muted);
  background: var(--bg); border-radius: 999px; padding: 1px 7px;
  font-variant-numeric: tabular-nums;
}
.item.active .nlinks { background: rgba(2, 136, 209, 0.14); color: var(--accent-ink); }

.empty { padding: 28px 16px; color: var(--muted); text-align: center; }

.sidebar-footer {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 10px 18px;
  border-top: 1px solid var(--line);
  font-size: 12px; color: var(--muted);
}
.kbd-hint { white-space: nowrap; }

.link-btn {
  background: none; border: 0; padding: 0;
  color: var(--accent); cursor: pointer;
  text-decoration: underline; text-underline-offset: 2px;
}

/* ---------- map ---------- */

#map-wrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: #dfe8f1; }

.leaflet-container { font: inherit; }
.leaflet-bar a { color: var(--ink); }
.leaflet-control-reset a { font-size: 18px; line-height: 30px; }

.kmz-icon { filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, 0.35)); }
.svg-pin { background: none; border: 0; }
.svg-pin svg { display: block; filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, 0.35)); }

.cluster { background: rgba(2, 136, 209, 0.22); border-radius: 50%; }
.cluster span {
  position: absolute; inset: 5px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--accent); color: #fff;
  font-weight: 700; font-size: 12px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
.cluster-md span { font-size: 13px; }
.cluster-lg span { font-size: 14px; background: #0277bd; }

.country-label { background: none; border: 0; }
.country-label span {
  position: absolute; left: 0; top: 0;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  font-size: 11px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  color: #4f5866;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 999px; padding: 2px 8px;
  cursor: pointer;
}
.country-label span:hover { background: #fff; color: var(--accent-ink); }

/* popup */
.choir-popup .leaflet-popup-content-wrapper { border-radius: 12px; box-shadow: var(--shadow); }
.choir-popup .leaflet-popup-content { margin: 14px 16px 12px; font-size: 13px; line-height: 1.4; }
.choir-popup .leaflet-popup-tip { box-shadow: none; }
.pp-name { margin: 0 0 4px; font-size: 15px; line-height: 1.3; padding-right: 12px; }
.pp-meta { margin: 0 0 8px; display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.note { margin: 0 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.chip {
  display: inline-flex; align-items: center;
  padding: 4px 10px;
  border-radius: 999px; border-left: 4px solid #9aa4b2;
  background: #f1f3f6; color: var(--ink) !important;
  font-size: 12px; font-weight: 600; text-decoration: none;
}
.chip:hover { background: #e6eaf0; }
.chip-website { border-color: #607d8b; }
.chip-youtube { border-color: #ff0000; }
.chip-facebook { border-color: #1877f2; }
.chip-instagram { border-color: #e1306c; }
.chip-twitter { border-color: #1d9bf0; }
.chip-soundcloud { border-color: #ff5500; }
.chip-vk { border-color: #0077ff; }
.chip-vimeo { border-color: #1ab7ea; }
.chip-flickr { border-color: #ff0084; }
.chip-tiktok { border-color: #000000; }
.chip-spotify { border-color: #1db954; }
.chip-wikipedia { border-color: #333333; }

.pp-foot { margin: 0; display: flex; gap: 14px; font-size: 12px; }
.pp-foot a { color: var(--accent); }

/* ---------- overlay / dialogs ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 3000;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: rgba(20, 33, 61, 0.55);
  backdrop-filter: blur(2px);
}
.overlay[hidden] { display: none; }

.card {
  width: 100%; max-width: 440px;
  padding: 28px 28px 24px;
  border-radius: 16px;
  background: #fff;
  box-shadow: var(--shadow);
  text-align: center;
}
.card h2 { margin: 0 0 6px; font-size: 17px; }
.card p { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.card .err {
  padding: 8px; border-radius: 8px;
  background: #fff3f3; color: #b71c1c;
  font: 11.5px/1.4 ui-monospace, Consolas, Menlo, monospace;
  word-break: break-all; text-align: left;
}
.card .btn { margin: 6px 0 12px; }
.only-error { display: none; }
.overlay[data-mode="error"] .only-error { display: block; }
.overlay[data-mode="error"] .btn.only-error { display: inline-block; }
.overlay[data-mode="error"] .spinner { display: none; }

.spinner {
  width: 36px; height: 36px; margin: 0 auto 14px;
  border: 3px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn {
  display: inline-block;
  padding: 10px 16px;
  border: 0; border-radius: 10px;
  background: var(--accent); color: #fff;
  font-weight: 600; cursor: pointer;
}
.btn:hover { background: #0277bd; }

.footer-note { color: var(--muted); }

dialog.about {
  width: calc(100% - 32px); max-width: 520px;
  padding: 22px 24px 24px;
  border: 0; border-radius: 16px;
  box-shadow: var(--shadow);
  color: var(--ink);
}
dialog.about::backdrop { background: rgba(20, 33, 61, 0.5); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.dialog-head h2 { margin: 0; font-size: 17px; }
.dialog-body h3 { margin: 0 0 8px; font-size: 15px; }
.dialog-body p { margin: 0 0 10px; }
.dialog-body a { color: var(--accent); word-break: break-all; }
.dialog-body .meta {
  display: grid; grid-template-columns: auto 1fr; gap: 4px 14px;
  margin: 14px 0 10px; padding: 12px 14px;
  background: var(--bg); border-radius: 10px;
  font-size: 12.5px;
}
.dialog-body .meta dt { color: var(--muted); }
.dialog-body .meta dd { margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 3500;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--navy); color: #fff;
  font-size: 13px;
  box-shadow: var(--shadow);
  pointer-events: none;
}
.toast[hidden] { display: none; }

/* ---------- mobile ---------- */

.only-mobile { display: none; }
.fab {
  position: absolute; top: 12px; left: 12px; z-index: 1000;
  width: 40px; height: 40px;
  border: 0; border-radius: 10px;
  background: #fff; color: var(--ink);
  font-size: 18px; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  align-items: center; justify-content: center;
}
.fab-search { left: 60px; }

@media (max-width: 767px) {
  .only-mobile { display: inline-flex; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    width: min(88vw, 380px);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow);
  }
  body.sidebar-open .sidebar { transform: none; }
  .kbd-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
  .spinner { animation-duration: 1.6s; }
}
