:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --ink: #0d1b2a;
  --sub: #5b6676;
  --line: #dde2ea;
  --blue: #1f6feb;
  --blue-deep: #1450b0;
  --red: #e5484d;
  --red-deep: #b4282d;
  --green: #12a150;
  --sans: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.6;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
input { -webkit-user-select: text; user-select: text; }
[hidden] { display: none !important; }
a { color: inherit; }

.shell {
  max-width: 520px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 0 16px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}
main { flex: 1; }

.site-header { padding: 14px 0 6px; }
.brand {
  display: inline-flex; align-items: center; gap: 8px;
  border: 0; background: none; padding: 4px 0; cursor: pointer;
  font: 800 16px/1 var(--sans); color: var(--ink); letter-spacing: .02em;
}
.brand svg { color: var(--blue); }

.screen { padding: 8px 0 16px; animation: rise .35s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* はじめ */
.radar { width: 148px; margin: 20px 0 8px; }
.radar svg { width: 100%; display: block; overflow: visible; }
.radar .ring { fill: none; stroke: #b9c6da; stroke-width: 1.5; }
.radar .sweep { transform-origin: 100px 100px; animation: spin 2.6s linear infinite; }
.radar .blip { fill: var(--red); animation: blip 2.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blip { 0%, 8% { opacity: 0; } 12% { opacity: 1; } 60%, 100% { opacity: 0; } }

.eyebrow {
  display: flex; align-items: center; gap: 10px;
  margin: 12px 0 6px; font-size: 14px; font-weight: 700; color: var(--blue);
}
.eyebrow .rule { width: 22px; height: 2px; background: currentColor; }
.eyebrow.red { color: var(--red); }

.headline { margin: 6px 0 14px; font-size: clamp(32px, 9.4vw, 44px); line-height: 1.25; font-weight: 900; letter-spacing: -.01em; }
.headline.small { font-size: clamp(28px, 8.2vw, 38px); }
.hl { background: linear-gradient(transparent 62%, #ffd84d 62%); }
.copy { margin: 0 0 22px; color: var(--sub); font-size: 16px; }
.copy strong { color: var(--ink); }
.fine { margin: 12px 0 0; color: var(--sub); font-size: 13px; text-align: center; }

/* ボタン：上の面＋下の厚み。押すと沈む */
.btn {
  --face: var(--card); --edge: #c6ceda; --text: var(--ink);
  display: flex; align-items: center; justify-content: center;
  width: 100%; min-height: 56px; padding: 12px 18px;
  border: 0; border-radius: 16px; cursor: pointer;
  font: 800 17px/1.2 var(--sans); color: var(--text); text-decoration: none;
  background: var(--face);
  box-shadow: 0 5px 0 var(--edge);
  transform: translateY(0);
  transition: transform .06s ease, box-shadow .06s ease, opacity .2s;
}
.btn:active:not(:disabled) { transform: translateY(5px); box-shadow: 0 0 0 var(--edge); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.big { min-height: 64px; font-size: 19px; }
.btn.primary { --face: var(--blue); --edge: var(--blue-deep); --text: #fff; }
.btn.sub { --face: var(--card); --edge: #c6ceda; }
.btn.x { --face: #0f1419; --edge: #000; --text: #fff; margin-top: 14px; }
.btn.yes { --face: var(--red); --edge: var(--red-deep); --text: #fff; }
.btn.no { --face: var(--card); --edge: #c6ceda; }

/* 地図 */
.map-card {
  position: relative; overflow: hidden;
  height: min(44dvh, 380px); min-height: 240px;
  border-radius: 18px; background: #e6ebf1;
  box-shadow: 0 1px 0 var(--line), 0 10px 30px rgba(13, 27, 42, .08);
}
#map { position: absolute; inset: 0; background: #e6ebf1; }
.map-badge {
  position: absolute; top: 10px; left: 10px; z-index: 500; margin: 0;
  display: flex; align-items: center; gap: 7px; padding: 5px 10px;
  border-radius: 99px; background: rgba(13, 27, 42, .82); color: #fff;
  font: 700 11px/1 var(--mono); letter-spacing: .12em;
}
.map-badge i { width: 8px; height: 8px; border-radius: 50%; background: var(--red); animation: rec 1s steps(1) infinite; }
@keyframes rec { 50% { opacity: .2; } }
.map-badge.done i { background: var(--green); animation: none; }
.leaflet-container { font-family: var(--sans); }
.leaflet-control-attribution { font-size: 10px; }

.panel {
  margin-top: 14px; padding: 18px;
  border-radius: 18px; background: var(--card);
  box-shadow: 0 1px 0 var(--line);
}

/* 逆探知のログ */
.log { list-style: none; margin: 0; padding: 0; font-family: var(--mono); font-size: 14px; }
.log li {
  display: grid; grid-template-columns: 6.6em 1fr; gap: 10px; align-items: baseline;
  padding: 7px 0; border-bottom: 1px dashed var(--line); opacity: .28;
  transition: opacity .2s;
}
.log li:last-child { border-bottom: 0; }
.log li.active, .log li.done { opacity: 1; }
.log .k { color: var(--sub); font-family: var(--sans); font-size: 13px; font-weight: 700; }
.log .v { font-weight: 700; word-break: break-all; }
.log li.active:not(.done) .v { color: var(--sub); }
.log li.active:not(.done) .v::after { content: "▍"; animation: rec .8s steps(1) infinite; }
.log li.done .v::after { content: " ✓"; color: var(--green); }
.log li.done[data-k="pin"] .v::after { content: ""; }

.meter { height: 8px; margin-top: 14px; border-radius: 99px; background: #e8ecf2; overflow: hidden; }
.meter-fill { width: 0; height: 100%; background: linear-gradient(90deg, var(--blue), #5aa0ff); border-radius: inherit; }
.meter-label { display: flex; justify-content: space-between; margin: 8px 0 0; font-size: 13px; color: var(--sub); }
.meter-label strong { font-family: var(--mono); color: var(--ink); }

/* 最後の質問 */
.ask-title { margin: 0 0 4px; font-size: 30px; line-height: 1.3; font-weight: 900; }
.ask .copy { margin-bottom: 16px; }
.q { display: block; margin: 0 0 10px; font-size: 18px; font-weight: 800; }
#place {
  width: 100%; height: 58px; padding: 0 16px; margin: 0 0 14px;
  border: 2px solid var(--line); border-radius: 14px; outline: none;
  background: #fbfcfe; color: var(--ink);
  font: 700 18px/1 var(--sans);
}
#place:focus { border-color: var(--blue); background: #fff; }
.error { margin: -6px 0 12px; color: var(--red); font-size: 14px; font-weight: 700; }
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* 結果 */
.result-head { position: relative; padding: 18px 0 16px; text-align: center; }
.stamp {
  display: inline-block; margin: 0 0 12px; padding: 4px 14px;
  border: 2.5px solid var(--red); border-radius: 8px; color: var(--red);
  font-size: 15px; font-weight: 900; letter-spacing: .2em; transform: rotate(-4deg);
  animation: stamp .45s cubic-bezier(.2, 1.6, .4, 1) both .1s;
}
@keyframes stamp { from { opacity: 0; transform: rotate(-4deg) scale(2.2); } }
.lead { margin: 0; font-size: 18px; font-weight: 700; color: var(--sub); }
.lead.end { color: var(--ink); font-size: 22px; font-weight: 900; }
.answer {
  margin: 6px 0; font-size: clamp(30px, 10vw, 46px); line-height: 1.25; font-weight: 900;
  word-break: break-word; -webkit-user-select: text; user-select: text;
}
.answer span { background: linear-gradient(transparent 64%, #ffd84d 64%); }
#b-answer { font-size: clamp(26px, 8.4vw, 40px); word-break: keep-all; overflow-wrap: anywhere; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 0; }
.stats div { padding: 12px 6px; border-radius: 14px; background: var(--card); text-align: center; box-shadow: 0 1px 0 var(--line); }
.stats dt { font-size: 12px; font-weight: 700; color: var(--sub); }
.stats dd { margin: 2px 0 0; font: 800 22px/1.2 var(--mono); }
.stats small { margin-left: 2px; font: 700 12px var(--sans); color: var(--sub); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.actions .btn.x { margin-top: 0; }

/* 二分探索 */
.qno { display: flex; align-items: baseline; gap: 6px; margin: 0 0 4px; font-family: var(--mono); color: var(--sub); font-weight: 700; }
.qno strong { font-size: 28px; color: var(--ink); }
.bisect-title { margin: 0 0 16px; font-size: 22px; line-height: 1.45; font-weight: 900; }
.red-area { color: var(--red); }
.yesno { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.yesno .btn { min-height: 64px; font-size: 20px; }
.bisect-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 14px; }
.back {
  border: 0; background: none; padding: 8px 2px; cursor: pointer;
  font: 700 14px var(--sans); color: var(--blue);
}
.back:disabled { color: #b4bcc8; cursor: default; }
.range { font-size: 13px; color: var(--sub); font-family: var(--mono); }

/* 地図の上の札・印 */
.tag.leaflet-tooltip {
  padding: 3px 8px; border: 0; border-radius: 8px;
  font: 800 12px/1.3 var(--sans); color: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .2);
}
.tag.leaflet-tooltip::before { display: none; }
.tag-ip { background: var(--blue); }
.tag-you { background: var(--red); }
.pin { position: relative; width: 26px; height: 40px; }
.pin::before {
  content: ""; position: absolute; left: 50%; bottom: 0; width: 26px; height: 26px;
  margin-left: -13px; border-radius: 50% 50% 50% 0; background: var(--red);
  transform: rotate(-45deg); transform-origin: center; box-shadow: 0 3px 8px rgba(0, 0, 0, .3);
  bottom: 6px;
}
.pin::after {
  content: ""; position: absolute; left: 50%; bottom: 15px; width: 9px; height: 9px;
  margin-left: -4.5px; border-radius: 50%; background: #fff;
}
.pin-drop { animation: drop .5s cubic-bezier(.3, 1.5, .5, 1) both; }
@keyframes drop { from { opacity: 0; transform: translateY(-30px); } }

.site-footer { padding: 18px 0 4px; border-top: 1px solid var(--line); font-size: 12px; color: var(--sub); }
.site-footer p { margin: 0 0 4px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
