:root {
  --ink: #172033;
  --muted: #6b7280;
  --line: #e5e7eb;
  --panel: #ffffff;
  --canvas: #edf1f5;
  --accent: #2563eb;
  --shadow: 0 18px 45px rgba(24, 32, 51, 0.14);
}

* { box-sizing: border-box; }

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

body {
  overflow: hidden;
  color: var(--ink);
  background: var(--canvas);
  font-family: "Yu Gothic UI", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
}

button, input, select { font: inherit; }

.app-shell {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  width: 100%;
  height: 100%;
}

.sidebar {
  z-index: 1001;
  display: flex;
  min-height: 0;
  flex-direction: column;
  padding: 24px 22px 16px;
  background: var(--panel);
  box-shadow: 8px 0 30px rgba(23, 32, 51, 0.09);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-bottom: 18px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  color: #fff;
  border-radius: 13px;
  background: linear-gradient(145deg, #172033, #334155);
  box-shadow: 0 8px 18px rgba(23, 32, 51, 0.22);
  font-family: Georgia, serif;
  font-size: 24px;
  font-weight: 700;
}

.eyebrow {
  margin: 0 0 2px;
  color: #94a3b8;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .18em;
}

h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: .02em;
}

h1 span { color: var(--accent); font-size: 15px; }

.summary-card {
  display: grid;
  grid-template-columns: 1fr 1px 1fr;
  gap: 14px;
  align-items: center;
  margin-bottom: 18px;
  padding: 13px 16px;
  color: #fff;
  border-radius: 15px;
  background: linear-gradient(135deg, #1e293b, #0f172a);
}

.summary-card > div { display: flex; flex-direction: column; }
.summary-label { color: #a5b4c7; font-size: 11px; }
.summary-card strong { margin-top: 2px; font-size: 21px; line-height: 1; }
.summary-card strong::after { content: "校"; margin-left: 3px; font-size: 11px; font-weight: 500; }
.summary-divider { align-self: stretch; background: rgba(255,255,255,.15); }

.filters { padding-bottom: 16px; border-bottom: 1px solid var(--line); }

.search-field {
  display: flex;
  align-items: center;
  gap: 9px;
  height: 44px;
  padding: 0 13px;
  border: 1px solid #dbe1ea;
  border-radius: 12px;
  background: #f8fafc;
  transition: border-color .2s, box-shadow .2s;
}

.search-field:focus-within {
  border-color: #93b4ff;
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

.search-field > span { color: #64748b; font-size: 22px; transform: translateY(-1px); }
.search-field input { width: 100%; border: 0; outline: 0; color: var(--ink); background: transparent; }
.search-field input::placeholder { color: #9ca3af; }

.filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.filter-grid label { display: flex; flex-direction: column; gap: 5px; }
.filter-grid label > span, .type-filter legend { color: #64748b; font-size: 11px; font-weight: 700; }

select {
  width: 100%;
  height: 38px;
  padding: 0 9px;
  color: var(--ink);
  border: 1px solid #dbe1ea;
  border-radius: 9px;
  outline: 0;
  background: #fff;
}

.type-filter {
  display: flex;
  gap: 7px;
  margin: 12px 0 0;
  padding: 0;
  border: 0;
}

.type-filter legend { margin-bottom: 6px; }
.type-filter label {
  display: inline-flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 7px 6px;
  border: 1px solid #dbe1ea;
  border-radius: 9px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}
.type-filter input { position: absolute; opacity: 0; pointer-events: none; }
.type-filter label:has(input:not(:checked)) { color: #9ca3af; background: #f8fafc; opacity: .65; }
.type-dot { width: 7px; height: 7px; border-radius: 50%; }
.type-dot.national { background: #6d5bd0; }
.type-dot.public { background: #0f8a8a; }
.type-dot.private { background: #d97706; }

.reset-button {
  width: 100%;
  margin-top: 10px;
  padding: 6px;
  color: #64748b;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-size: 12px;
}
.reset-button:hover { color: var(--accent); }

.result-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 2px 10px;
}
.result-heading h2 { margin: 0; font-size: 14px; }
.result-heading span { color: #94a3b8; font-size: 11px; }

.result-list {
  min-height: 0;
  flex: 1;
  overflow: auto;
  padding-right: 5px;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}

.result-card {
  display: grid;
  grid-template-columns: 13px minmax(0,1fr) auto;
  gap: 9px;
  align-items: center;
  width: 100%;
  margin-bottom: 7px;
  padding: 11px 10px;
  text-align: left;
  color: var(--ink);
  border: 1px solid #e7ebf0;
  border-radius: 11px;
  background: #fff;
  cursor: pointer;
  transition: transform .15s, border-color .15s, box-shadow .15s;
}
.result-card:hover {
  z-index: 1;
  transform: translateY(-1px);
  border-color: #bfdbfe;
  box-shadow: 0 7px 18px rgba(30,64,175,.08);
}
.result-color { width: 10px; height: 28px; border-radius: 9px; background: var(--pin-color); }
.result-copy { min-width: 0; }
.result-name { display: block; overflow: hidden; font-size: 13px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.result-meta { display: block; margin-top: 3px; color: #7c8798; font-size: 10px; }
.result-score { min-width: 38px; text-align: center; }
.result-score strong { display: block; font-size: 16px; }
.result-score span { color: #94a3b8; font-size: 9px; }
.empty-result { padding: 28px 12px; text-align: center; color: #64748b; font-size: 13px; }

.data-note { padding-top: 10px; color: #94a3b8; font-size: 9px; line-height: 1.45; }
.data-note p { margin: 0 0 3px; }
.data-note a { color: #64748b; }

.map-panel { position: relative; min-width: 0; min-height: 0; }
#map { width: 100%; height: 100%; background: #dfe6ec; }

.map-topbar {
  position: absolute;
  z-index: 800;
  top: 18px;
  right: 18px;
  left: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.legend, .japan-button, .share-button {
  pointer-events: auto;
  border: 1px solid rgba(255,255,255,.8);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  background: rgba(255,255,255,.92);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 9px 13px;
  border-radius: 12px;
}
.legend span { display: inline-flex; align-items: center; gap: 5px; color: #475569; font-size: 10px; font-weight: 700; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--legend-color); }

.map-actions { display: flex; gap: 8px; pointer-events: auto; }

.japan-button, .share-button {
  padding: 9px 13px;
  color: #334155;
  border-radius: 10px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
}
.share-button { color: #fff; border-color: #1d4ed8; background: #2563eb; }

.university-div-icon { border: 0; background: transparent; }
.university-pin {
  position: relative;
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 9px;
  background: var(--pin-color);
  box-shadow: 0 3px 8px rgba(15,23,42,.38);
  transform: rotate(-45deg);
}
.university-pin::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: rgba(255,255,255,.94); }

.marker-cluster-small, .marker-cluster-medium, .marker-cluster-large { background: rgba(30,41,59,.18); }
.marker-cluster-small div, .marker-cluster-medium div, .marker-cluster-large div {
  color: #fff;
  background: #1e293b;
  font-weight: 800;
}

.university-cluster-div-icon {
  border: 0;
  background: transparent;
}

.university-cluster {
  display: flex;
  width: 100%;
  height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  border: 3px solid var(--cluster-color);
  border-radius: 999px;
  background: rgba(15, 23, 42, .92);
  box-shadow: 0 8px 18px rgba(15, 23, 42, .34);
  line-height: 1;
}

.university-cluster strong {
  font-size: 15px;
  font-weight: 900;
}

.university-cluster small {
  display: none;
  margin-top: 2px;
  font-size: 7px;
  font-weight: 800;
}

.leaflet-popup-content-wrapper { border-radius: 15px; box-shadow: 0 15px 40px rgba(15,23,42,.2); }
.leaflet-popup-content { width: 250px !important; margin: 17px 18px; }
.popup-type { display: inline-block; margin-bottom: 6px; padding: 3px 7px; color: #475569; border-radius: 999px; background: #eef2f7; font-size: 10px; font-weight: 800; }
.popup-name { margin: 0; color: #172033; font-size: 16px; line-height: 1.35; }
.popup-score { display: flex; align-items: baseline; gap: 5px; margin: 11px 0 7px; color: var(--pin-color); }
.popup-score strong { font-size: 27px; line-height: 1; }
.popup-score span { color: #64748b; font-size: 10px; }
.popup-address { margin: 0 0 12px; color: #64748b; font-size: 11px; line-height: 1.5; }
.popup-link { display: inline-block; color: #2563eb !important; font-size: 11px; font-weight: 800; text-decoration: none; }
.popup-alias { margin: 8px 0 0; color: #9ca3af; font-size: 9px; }

.loading-state, .error-state {
  position: absolute;
  z-index: 900;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 11px;
  color: #475569;
  background: rgba(237,241,245,.93);
  font-size: 13px;
}
.loading-state[hidden], .error-state[hidden] { display: none; }
.loading-state p { margin: 0; }
.loading-spinner { width: 31px; height: 31px; border: 3px solid #d5dde6; border-top-color: #2563eb; border-radius: 50%; animation: spin .8s linear infinite; }
.error-state strong { font-size: 15px; }
.error-state span { font-size: 11px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
  body { overflow: hidden; }
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
  }
  .sidebar {
    order: 2;
    max-height: 46vh;
    max-height: 46dvh;
    overflow: auto;
    padding: 12px 14px max(10px, env(safe-area-inset-bottom));
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 28px rgba(23,32,51,.12);
  }
  .map-panel {
    order: 1;
    min-height: 0;
  }
  .brand-block { margin-bottom: 10px; }
  .brand-mark { width: 37px; height: 37px; font-size: 20px; }
  h1 { font-size: 18px; }
  .summary-card { margin-bottom: 10px; padding: 9px 13px; }
  .summary-card strong { font-size: 17px; }
  .filters { padding-bottom: 8px; }
  .search-field { height: 39px; }
  .filter-grid { margin-top: 8px; }
  .type-filter { margin-top: 8px; }
  .reset-button { margin-top: 3px; padding: 3px; }
  .result-heading, .result-list, .data-note { display: none; }
  .map-topbar {
    top: max(10px, env(safe-area-inset-top));
    right: 10px;
    left: 10px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 7px;
    align-items: start;
  }
  .map-topbar::after {
    content: "数字の丸をタップで拡大";
    justify-self: start;
    padding: 6px 9px;
    color: #334155;
    border: 1px solid rgba(255,255,255,.8);
    border-radius: 999px;
    background: rgba(255,255,255,.92);
    box-shadow: 0 8px 22px rgba(24, 32, 51, .13);
    font-size: 10px;
    font-weight: 800;
  }
  .legend {
    max-width: none;
    justify-content: center;
    gap: 7px;
    padding: 7px 9px;
  }
  .map-actions { justify-content: flex-end; gap: 7px; }
  .japan-button, .share-button { min-height: 34px; padding: 8px 9px; }
  .university-cluster small { display: block; }
  .leaflet-popup-content { width: min(250px, calc(100vw - 86px)) !important; }
}

@media (max-width: 430px) {
  .sidebar {
    max-height: 48vh;
    max-height: 48dvh;
    padding-right: 12px;
    padding-left: 12px;
  }
  .filter-grid { grid-template-columns: 1fr 1fr; }
  .type-filter { gap: 5px; }
  .type-filter label { padding: 6px 3px; font-size: 11px; }
  .legend span { font-size: 9px; }
}
