:root {
  --ink: #3B2F2A;
  --muted: #7a6b62;
  --sea: #D4ECF7;
  --wave: #9FCFE6;
  --ctx: #EEE7D8;
  --paper: #FBF7F0;
  --accent: #E07A5F;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --pop: "Mochiy Pop One", "Zen Maru Gothic", system-ui, sans-serif;
  --maru: "Zen Maru Gothic", system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none;
  background: var(--sea); color: var(--ink); font-family: var(--maru);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }

/* ---- 地図 ---- */
#stage {
  position: fixed; inset: 0; touch-action: none; cursor: grab;
  background-color: #C4E4F2;
  /* 手前: まばらな波（画面座標で敷き、パンに合わせて --wx/--wy で動かす）／奥: 沖ほど深い青のグラデーション */
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='170' height='110'%3E%3Cg fill='none' stroke='%2388BEDA' stroke-width='2' stroke-linecap='round' opacity='.5'%3E%3Cpath d='M14 26q5-5 10 0t10 0M112 92q5-5 10 0t10 0'/%3E%3Cpath d='M96 30q4-4 8 0t8 0' stroke-width='1.6'/%3E%3C/g%3E%3C/svg%3E"),
    radial-gradient(ellipse at 52% 46%, #DCF0F9 0%, #C9E7F4 48%, #AED6EA 100%);
  background-size: 170px 110px, 100% 100%;
  background-repeat: repeat, no-repeat;
  background-position: var(--wx, 0) var(--wy, 0), 0 0;
}
#stage.dragging { cursor: grabbing; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
/* 浅瀬: 海岸線の外側を、太い線で2重に明るくする（画面上の太さで固定） */
.shore { fill: none; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; pointer-events: none; }
.shore-a { stroke: #E3F4FA; stroke-width: 46px; opacity: .5; }
.shore-b { stroke: #F1FAFD; stroke-width: 20px; opacity: .85; }
.pref {
  stroke: #fff; stroke-width: 1.3; stroke-linejoin: round;
  vector-effect: non-scaling-stroke; transition: fill .35s, opacity .35s;
}
#terrain { pointer-events: none; }
.lake { fill: #CBE8F4; stroke: #fff; stroke-width: 1.2; stroke-linejoin: round; vector-effect: non-scaling-stroke; pointer-events: none; }
.pref.ctx { fill: var(--ctx); }
.pref.dim { opacity: .55; }
.nansei-frame { fill: none; stroke: #7FA9C2; stroke-width: 1.6; stroke-dasharray: 6 5; vector-effect: non-scaling-stroke; }

/* ---- 地図の上に重ねる要素（ラベル・イラスト） ---- */
#overlay { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.label {
  position: absolute; left: 0; top: 0; white-space: nowrap; text-align: center;
  font-family: var(--pop); line-height: 1.1; pointer-events: none;
  opacity: 0; transition: opacity .3s; will-change: transform;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 6px #fff, 0 0 8px #fff;
}
.label.on { opacity: 1; }
.label small { display: block; font-family: var(--maru); font-weight: 700; font-size: .55em; color: var(--muted); margin-top: 2px; }
.label.region { font-size: 26px; letter-spacing: .04em; }
.label.pref { font-size: 16px; }
.label.frame { font-size: 12px; color: #5C8AA6; font-family: var(--maru); font-weight: 700; }

.spot {
  position: absolute; left: 0; top: 0; width: var(--s); height: var(--s);
  margin: calc(var(--s) / -2) 0 0 calc(var(--s) / -2);
  padding: 0; border: 0; background: none; cursor: pointer;
  pointer-events: none; opacity: 0; transition: opacity .25s; will-change: transform;
}
.spot img {
  width: 100%; height: 100%; object-fit: contain; display: block; pointer-events: none;
  transform: scale(.35); transition: transform .35s cubic-bezier(.34, 1.56, .64, 1);
  filter: drop-shadow(0 2px 1.5px rgba(59, 47, 42, .28));
}
.spot.on { opacity: 1; pointer-events: auto; }
.spot.on img { transform: scale(1); }
.spot.placeholder img { padding: 10%; }
.spot:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 12px; }

/* ---- 上のバー ---- */
#bar {
  position: fixed; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-top)) 14px 10px; pointer-events: none;
}
#bar > * { pointer-events: auto; }
#bar .spacer { flex: 1; pointer-events: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 44px; padding: 0 16px;
  border: 0; border-radius: 22px; background: rgba(255, 255, 255, .92);
  box-shadow: 0 2px 8px rgba(59, 47, 42, .15); font-family: var(--pop); font-size: 16px; cursor: pointer;
}
.chip svg { width: 22px; height: 22px; }
.chip.round { width: 44px; padding: 0; justify-content: center; font-size: 22px; }
.chip.level { font-family: var(--maru); font-weight: 700; font-size: 13px; color: var(--muted); cursor: default; }
.zoom { display: flex; gap: 6px; }
#crumbs { display: flex; gap: 6px; align-items: center; overflow: hidden; }
#crumbs .sep { color: var(--muted); font-size: 18px; }
#crumbs .chip { font-size: 15px; }

/* ---- 詳細カード ---- */
#card-backdrop { position: fixed; inset: 0; background: rgba(59, 47, 42, .18); }
#card {
  position: fixed; left: 50%; bottom: calc(16px + var(--safe-bottom)); transform: translateX(-50%);
  width: min(640px, calc(100vw - 24px)); background: var(--paper); border-radius: 24px;
  box-shadow: 0 10px 40px rgba(59, 47, 42, .28); display: grid; grid-template-columns: 200px 1fr; gap: 16px;
  padding: 18px; animation: card-in .28s cubic-bezier(.2, .9, .3, 1.2);
}
@keyframes card-in { from { transform: translate(-50%, 40px); opacity: 0; } }
.card-img { background: #fff; border-radius: 16px; display: grid; place-items: center; aspect-ratio: 1; }
.card-img img { width: 88%; height: 88%; object-fit: contain; }
.card-body { min-width: 0; }
.card-body h2 { font-family: var(--pop); font-weight: 400; font-size: 30px; margin: 8px 0 0; line-height: 1.25; }
.kanji { margin: 2px 0 0; color: var(--muted); font-weight: 700; }
.desc { font-size: 19px; line-height: 1.7; margin: 10px 0 12px; }
.card-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.cat, .pref-chip { font-size: 13px; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.cat { color: #fff; }
.pref-chip { background: #fff; border: 1.5px solid var(--ctx); }
.card-actions { display: flex; gap: 8px; }
.btn {
  height: 46px; padding: 0 20px; border: 0; border-radius: 23px; background: var(--ink); color: #fff;
  font-family: var(--pop); font-size: 16px; cursor: pointer;
}
.note { font-size: 12px; color: var(--muted); margin: 10px 0 0; }
.card-close {
  position: absolute; top: 10px; right: 12px; width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: rgba(59, 47, 42, .08); font-size: 22px; cursor: pointer;
}
@media (max-width: 560px) {
  #card { grid-template-columns: 1fr; }
  .card-img { width: 50%; justify-self: center; }
  #crumbs, .chip.level { display: none; }
}

#attr {
  position: fixed; left: 10px; bottom: calc(6px + var(--safe-bottom)); font-size: 10px; color: #5C8AA6;
  background: rgba(255, 255, 255, .6); padding: 2px 8px; border-radius: 8px; pointer-events: none;
}
#loading {
  position: fixed; inset: 0; display: grid; place-items: center; font-family: var(--pop); font-size: 22px;
  background: var(--sea); transition: opacity .4s;
}
#loading.done { opacity: 0; pointer-events: none; }
