:root {
  --bg: #05070f;
  --ink: #eaf1ff;
  --muted: rgba(190, 210, 255, 0.55);
  --self: #ffe08a;
  --peer: #bfe0ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#map {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* 周辺を少し暗く落として中央の点を引き立てる */
#vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(
    120% 120% at 50% 45%,
    transparent 40%,
    rgba(0, 0, 0, 0.55) 100%
  );
}

#hud {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
  padding: 24px;
  gap: 2px;
}

#count {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: clamp(56px, 14vw, 168px);
  line-height: 1;
  letter-spacing: -0.02em;
  text-shadow: 0 0 40px rgba(150, 190, 255, 0.35);
  transition: text-shadow 1.2s ease;
}

#headline {
  margin: 18px 0 0;
  font-weight: 500;
  font-size: clamp(18px, 3.4vw, 30px);
  letter-spacing: 0.04em;
  color: var(--ink);
  opacity: 0.92;
}

#sub {
  margin: 6px 0 0;
  font-size: clamp(12px, 2.4vw, 15px);
  letter-spacing: 0.06em;
  color: var(--muted);
  text-transform: lowercase;
}

#tooltip {
  position: fixed;
  z-index: 10;
  transform: translate(-50%, -140%);
  padding: 6px 11px;
  border-radius: 999px;
  background: rgba(12, 18, 34, 0.82);
  border: 1px solid rgba(150, 190, 255, 0.25);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 13px;
  letter-spacing: 0.02em;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
}
#tooltip[hidden] {
  display: none;
}
#tooltip .tz-time {
  color: var(--muted);
}
/* タップ時の「👋 from 〇〇」＋滞在時間（複数行になるのでピル形をやめて角丸に） */
#tooltip:has(.tt-greet) {
  border-radius: 14px;
  text-align: center;
  line-height: 1.5;
}
#tooltip .tt-greet {
  font-weight: 600;
}

#status {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}
#status.show {
  opacity: 1;
}

#footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--muted);
}
#footer a {
  color: var(--muted);
  text-decoration: none;
  transition: color 0.25s ease;
}
#footer a:hover {
  color: var(--ink);
}
#footer strong {
  color: rgba(210, 225, 255, 0.85);
  font-weight: 600;
}
#self-label {
  opacity: 0.8;
}

@media (max-width: 560px) {
  #footer {
    flex-direction: column;
    gap: 4px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #count {
    transition: none;
  }
}

/* スマホでプルリフレッシュ/バウンスを抑止（地図のパン・ピンチを邪魔しない） */
html,
body {
  overscroll-behavior: none;
}

/* ズーム中は中央の大きな数字を退避して地図を見やすく */
#hud {
  transition: opacity 0.4s ease;
}
body.zoomed #hud {
  opacity: 0;
}

/* ───────── コントロール ───────── */
#controls {
  position: fixed;
  z-index: 20;
  right: max(14px, env(safe-area-inset-right));
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 46px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ctl {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(12, 18, 34, 0.7);
  border: 1px solid rgba(150, 190, 255, 0.22);
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background 0.2s, border-color 0.2s, transform 0.08s;
  -webkit-tap-highlight-color: transparent;
}
.ctl svg {
  fill: currentColor;
}
.ctl:hover {
  background: rgba(22, 32, 56, 0.85);
  border-color: rgba(150, 190, 255, 0.4);
}
.ctl:active {
  transform: scale(0.92);
}

/* ───────── 統計パネル ───────── */
#stats {
  position: fixed;
  z-index: 25;
  left: max(14px, env(safe-area-inset-left));
  top: max(14px, env(safe-area-inset-top));
  width: 290px;
  max-width: calc(100vw - 28px);
  padding: 14px 14px 12px;
  border-radius: 16px;
  background: rgba(10, 15, 28, 0.86);
  border: 1px solid rgba(150, 190, 255, 0.2);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  color: var(--ink);
  animation: stats-in 0.18s ease;
}
#stats[hidden] {
  display: none;
}
@keyframes stats-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.stats-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}
#stats-total {
  font-size: 34px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
#stats-sub {
  margin-top: 3px;
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--muted);
  text-transform: lowercase;
}
#stats-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
  -webkit-tap-highlight-color: transparent;
}
#stats-close:hover {
  color: var(--ink);
}
#stats-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
#stats-list li {
  display: grid;
  grid-template-columns: 20px 1fr 60px 26px;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.st-flag {
  font-size: 15px;
}
.st-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: rgba(225, 235, 255, 0.9);
}
.st-bar {
  height: 6px;
  background: rgba(150, 190, 255, 0.12);
  border-radius: 999px;
  overflow: hidden;
}
.st-bar i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(120, 170, 255, 0.7), rgba(190, 224, 255, 0.95));
}
.st-n {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.st-empty {
  color: var(--muted);
  font-size: 12px;
}
.stats-foot {
  margin-top: 10px;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: rgba(190, 210, 255, 0.4);
  text-transform: lowercase;
}

/* ───────── スマホ ───────── */
@media (max-width: 560px) {
  .ctl {
    width: 46px;
    height: 46px;
  }
  /* 統計をボトムシート化 */
  #stats {
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    width: auto;
    max-width: none;
    border-radius: 18px 18px 0 0;
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
    animation: sheet-in 0.22s ease;
  }
  @keyframes sheet-in {
    from {
      transform: translateY(100%);
    }
    to {
      transform: none;
    }
  }
  /* ボトムシートと被るのでコントロールは隠す */
  body.stats-open #controls {
    display: none;
  }
}
