* { box-sizing: border-box; }

:root {
  --ink: #252525;
  --muted: #777873;
  --line: #dedbd2;
  --paper: #fbfaf5;
  --map-bg: #f4f2ec;
  --accent: #cf4b56;
}

html,
body,
.app {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Hiragino Sans", sans-serif;
}

.app {
  display: grid;
  grid-template-columns: clamp(340px, 32vw, 460px) minmax(0, 1fr);
}

.sidebar {
  position: relative;
  z-index: 5;
  min-width: 0;
  padding: 32px;
  background: var(--paper);
  border-right: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr) auto;
  gap: 24px;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.sidebar::-webkit-scrollbar {
  display: none;
}

header p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  line-height: 1.4;
}

.mobileRadius {
  display: none;
}

header h1 {
  margin: 0;
  font-size: clamp(52px, 8vw, 84px);
  font-weight: 800;
  line-height: .95;
  letter-spacing: -0.02em;
  font-family: "Noto Serif JP", serif;
  transition: opacity .18s ease;
}

.locationInfo {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 14px;
}

.modeTabs {
  display: flex;
  margin: 20px 0 32px;
  border-bottom: 1px solid var(--line);
}

.modeTabs button {
  flex: 1 1 0;
  min-width: 0;
  border: 0;
  padding: 0 0 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  position: relative;
  transition: color .14s;
}

.modeTabs button.active {
  color: var(--ink);
}

.modeTabs button::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 100%;
  height: 3px;
  background: transparent;
  transition: background .14s;
}

.modeTabs button.active::after {
  background: var(--ink);
}

.modeTabs button:hover:not(.active) {
  color: var(--ink);
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0;
  padding: 16px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.stats > div {
  padding: 0 12px;
}

.stats > div:first-child { padding-left: 0; }
.stats > div:last-child { padding-right: 0; }
.stats > div:not(:last-child) {
  border-right: 1px solid var(--line);
}

.stats span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stats span {
  display: block;
  margin-bottom: 8px;
  letter-spacing: .04em;
}

.stats b {
  display: block;
  font-size: 24px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.stats b small {
  font-size: 13px;
  font-weight: 500;
  margin-left: 1px;
}

.controls {
  display: grid;
  gap: 16px;
}

.sliderSection {
  display: grid;
  gap: 10px;
}

.sliderTicks {
  position: relative;
  height: 18px;
}

.sliderTick--min,
.sliderTick--max,
.sliderTick--center {
  position: absolute;
  font-size: 11px;
  color: var(--muted);
  line-height: 1;
  top: 0;
  white-space: nowrap;
}

.sliderTick--min { left: 0; }
.sliderTick--max { right: 0; }
.sliderTick--center {
  left: 50%;
  transform: translateX(-50%);
}

input[type="range"] {
  width: 100%;
  height: 20px;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
  margin: 0;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  background: var(--line);
  border-radius: 2px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--ink);
  margin-top: -4.5px;
  transition: transform .12s ease;
}

input[type="range"]:hover::-webkit-slider-thumb {
  transform: scale(1.25);
}

input[type="range"]::-moz-range-track {
  height: 3px;
  background: var(--line);
  border-radius: 2px;
  border: 0;
}

input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
}

.toggle {
  width: fit-content;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  cursor: pointer;
}

.toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggleTrack {
  position: relative;
  width: 30px;
  height: 17px;
  background: var(--line);
  border-radius: 9px;
  flex-shrink: 0;
  transition: background .18s;
}

.toggleTrack::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 11px;
  height: 11px;
  background: var(--paper);
  border-radius: 50%;
  transition: transform .18s;
  box-shadow: 0 1px 3px rgba(37, 37, 37, .22);
}

.toggle input:checked + .toggleTrack {
  background: var(--accent);
}

.toggle input:checked + .toggleTrack::after {
  transform: translateX(13px);
}

.legendList {
  display: grid;
  align-content: start;
  gap: 0;
  border-top: 1px solid var(--line);
}

.legendItem {
  min-width: 0;
  font-size: 13px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
}

.legendTop {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  width: 100%;
}

.legendSwatch {
  display: none;
}

.legendTop span {
  min-width: 80px;
  font-size: 12px;
  font-weight: 700;
}

.legendTop b {
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-left: auto;
}

.legendBar {
  flex-grow: 1;
  height: 10px;
  background: transparent;
  margin-top: 1px;
}

.legendBarFill {
  height: 10px;
  transition: width .35s ease;
}

footer {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

footer > div {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.55;
  font-weight: 400;
}

.footerIcon {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--muted);
  margin-top: 1px;
}

.footerIcon svg {
  width: 15px;
  height: 15px;
}

.footerLink {
  display: block;
  font-size: 11px;
  color: var(--muted);
  text-decoration: none;
  margin-top: 3px;
}

.footerLink:hover { color: var(--ink); }

.mapPane {
  position: relative;
  min-width: 0;
  background: var(--map-bg);
  overflow: hidden;
}

#map {
  position: absolute;
  inset: 0;
  background: var(--map-bg);
}

#ringOverlay {
  position: absolute;
  inset: 0;
  z-index: 640;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

#ringOverlay path {
  fill: none;
  stroke-linecap: butt;
  transition: opacity .18s ease;
}

#ringOverlay .ringBack {
  stroke: rgba(251, 250, 245, .92);
}

.ringTooltip {
  position: absolute;
  z-index: 720;
  max-width: 190px;
  padding: 7px 10px;
  background: rgba(37, 37, 37, .86);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
  border-radius: 5px;
  opacity: 0;
  transform: translate(-50%, -125%);
  transition: opacity .14s ease;
  pointer-events: none;
  white-space: nowrap;
}

.ringTooltip.active {
  opacity: 1;
}

.mapCenter {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 650;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  pointer-events: none;
}

.mapCenter::before,
.mapCenter::after {
  content: '';
  position: absolute;
  background: var(--ink);
  opacity: 0.45;
}

.mapCenter::before {
  width: 1px;
  height: 18px;
  left: 8.5px;
  top: 0;
}

.mapCenter::after {
  width: 18px;
  height: 1px;
  left: 0;
  top: 8.5px;
}

.loading {
  position: absolute;
  top: 0;
  left: -100%;
  z-index: 700;
  width: 100%;
  height: 2px;
  background: var(--accent);
  opacity: 0;
  pointer-events: none;
  font-size: 0;
  transition: opacity .12s ease;
}

.loading.active {
  opacity: 1;
  animation: loadBar 1.3s ease-in-out infinite;
}

@keyframes loadBar {
  0%   { transform: translateX(0%); }
  100% { transform: translateX(200%); }
}

.maplibregl-canvas-container {
  font-family: inherit;
  background: var(--map-bg);
}

.maplibregl-ctrl-top-right {
  margin: 18px !important;
}

.maplibregl-ctrl-group {
  box-shadow: 0 2px 8px rgba(37, 37, 37, .25) !important;
  background: var(--ink) !important;
  border-radius: 0 !important;
}

.maplibregl-ctrl-group button {
  width: 34px !important;
  height: 34px !important;
  border: 0 !important;
  background: transparent !important;
}

.maplibregl-ctrl-group button span {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.maplibregl-ctrl-icon {
  filter: invert(1) !important;
}

.maplibregl-ctrl-zoom-in {
  border-bottom: 1px solid rgba(255, 255, 255, .15) !important;
}

.maplibregl-ctrl-group button:hover {
  background: #000 !important;
}

@media (max-width: 760px) {
  .app {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 55vh 45vh;
  }

  .sidebar {
    position: relative;
    order: 2;
    z-index: 5;
    max-height: none;
    padding: 18px;
    background: var(--paper);
    border: 0;
    border-top: 1px solid var(--line);
    display: grid;
    grid-template-rows: auto auto auto minmax(0, 1fr);
    gap: 14px;
    overflow: auto;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .mapPane {
    position: relative;
    order: 1;
    min-height: 0;
  }

  header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 10px;
  }

  header p {
    position: fixed;
    top: 18px;
    left: 18px;
    z-index: 1000;
    margin: 0;
    font-size: 11px;
    color: var(--ink);
    text-shadow: 0 0 6px var(--map-bg), 0 0 6px var(--map-bg);
  }

  .mobileRadius {
    display: block;
    /* color: var(--muted); は削除し親(header p)の色を継承させる */
  }

  header h1 {
    min-width: 0;
    font-size: 30px;
    line-height: .95;
  }

  header span { display: none; }
  .locationInfo { display: none; }
  .stats { display: none; }

  .modeTabs {
    display: flex;
    margin: 12px 0 24px;
    padding: 0;
  }

  .modeTabs button {
    font-size: 10px;
    padding: 0 0 8px;
  }

  .controls {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: end;
  }

  .sliderSection { gap: 8px; }

  .toggle {
    padding-bottom: 1px;
  }

  .toggle .toggleLabel {
    display: none;
  }

  footer { display: none; }

  .legendList {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 16px;
    min-height: 0;
    max-height: 120px;
    overflow: auto;
    padding-right: 2px;
  }

  .legendList:not(.has-selection) {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px 12px;
    border-top: none;
    padding-top: 4px;
    max-height: none;
  }

  .legendList:not(.has-selection) .legendItem {
    padding: 0;
    border: none;
    background: transparent;
    width: auto;
    position: relative;
  }

  .legendList:not(.has-selection) .legendTop {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    position: relative;
    padding-left: 10px;
  }

  .legendList:not(.has-selection) .legendSwatch {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    display: block;
    width: calc(100% - 10px);
    height: 7px;
    z-index: -1;
  }

  .legendList:not(.has-selection) .legendTop span {
    min-width: 0;
    font-size: 11px;
    font-weight: 500;
    background: var(--paper);
    padding-left: 6px;
    text-align: right;
  }

  .legendList:not(.has-selection) .legendBar,
  .legendList:not(.has-selection) .legendTop b {
    display: none;
  }

  .legendList.has-selection {
    grid-template-columns: 1fr;
    max-height: auto;
  }

  .legendItem {
    font-size: 12px;
  }

  .legendItem b {
    font-size: 11px;
  }

  .maplibregl-ctrl-top-right {
    margin: 12px !important;
  }
}
