:root {
  --green: #2f9e6e;
  --green-dark: #257f58;
  --green-soft: #e6f5ee;
  --ink: #1f2d27;
  --muted: #6b7a73;
  --line: #dde6e1;
  --bg: #f6faf7;
  --warn: #fff4d6;
  --thanks: #f59f00;
  --danger: #d6454a;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column; height: 100dvh;
  font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", sans-serif;
  color: var(--ink); background: var(--bg); font-size: 15px;
}
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---- ヘッダー ---- */
#topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px; background: var(--green); color: #fff;
}
#topbar h1 { margin: 0; font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 6px; flex-shrink: 0; }
.top-btn {
  border: 0; border-radius: 999px; padding: 6px 12px; background: rgba(255,255,255,.2); color: #fff; font-weight: 600;
  max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.top-btn:active { background: rgba(255,255,255,.35); }

/* ---- 絞り込みチップ ---- */
#filters {
  display: flex; align-items: center; gap: 6px; overflow-x: auto; padding: 8px 10px;
  background: #fff; border-bottom: 1px solid var(--line); scrollbar-width: none;
}
#filters::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 999px; padding: 6px 11px; font-size: 13px; white-space: nowrap;
}
.chip.on { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
.chip.mode { background: var(--green-soft); border-color: var(--green); color: var(--green-dark); }
.chip.reset { border-style: dashed; color: var(--danger); }
.sep { flex-shrink: 0; width: 1px; height: 22px; background: var(--line); margin: 0 2px; }

/* ---- 地図 ---- */
main { position: relative; flex: 1; min-height: 0; }
#map { position: absolute; inset: 0; }
#count-hint {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 900;
  background: rgba(31,45,39,.85); color: #fff; padding: 6px 12px; border-radius: 999px; font-size: 12px; white-space: nowrap;
}
.fabs {
  position: absolute; right: 12px; bottom: calc(14px + env(safe-area-inset-bottom)); z-index: 1000;
  display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
}
body.sheet-open .fabs { display: none; }
.fab {
  border: 0; background: #fff; color: var(--ink); box-shadow: 0 2px 10px rgba(0,0,0,.28);
  width: 46px; height: 46px; border-radius: 50%; font-size: 20px;
}
.fab.primary { width: auto; padding: 0 18px; height: 48px; border-radius: 999px; background: var(--green); color: #fff; font-size: 15px; font-weight: 700; }
.fab:active { transform: scale(.96); }

#toast {
  position: absolute; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translate(-50%, 10px);
  z-index: 1400; max-width: 88%; background: rgba(31,45,39,.92); color: #fff; padding: 10px 16px; border-radius: 12px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- ピン ---- */
.pin-wrap { background: none; border: 0; }
.pin {
  width: 34px; height: 34px; background: var(--green); border: 3px solid #fff; border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg); box-shadow: 0 2px 6px rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center;
}
.pin span { transform: rotate(45deg); font-size: 16px; line-height: 1; }
.pin.plain { background: #8a9a92; }
.marker-cluster-small, .marker-cluster-medium, .marker-cluster-large { background: rgba(47,158,110,.35); }
.marker-cluster-small div, .marker-cluster-medium div, .marker-cluster-large div { background: rgba(47,158,110,.9); color: #fff; font-weight: 700; }

/* ---- ボトムシート ---- */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1100; max-height: 58dvh; overflow-y: auto;
  background: #fff; border-radius: 18px 18px 0 0; box-shadow: 0 -4px 20px rgba(0,0,0,.25);
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 720px) {
  .sheet { left: 16px; right: auto; bottom: 16px; width: 400px; border-radius: 16px; max-height: calc(100dvh - 140px); }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; font-size: 17px; }
.x { border: 0; background: var(--bg); width: 32px; height: 32px; border-radius: 50%; font-size: 15px; color: var(--muted); }
.sheet h3, .modal-card h3 { margin: 14px 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.sheet h3 small { font-weight: 400; }

.photo { display: block; margin-bottom: 10px; }
.photo img { width: 100%; max-height: 190px; object-fit: cover; border-radius: 12px; background: var(--bg); display: block; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.tag { background: var(--green-soft); color: var(--green-dark); border-radius: 999px; padding: 4px 10px; font-size: 13px; font-weight: 600; }
.note { white-space: pre-wrap; word-break: break-word; margin: 6px 0 10px; line-height: 1.6; }
.finder { margin: 6px 0 2px; font-size: 14px; }
.date { color: var(--muted); font-size: 12px; margin: 0 0 12px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 12px; padding: 10px 14px; font-weight: 600; text-decoration: none; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #f0c9ca; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; }
.btn.thanks { background: #fff8e6; border-color: #f7d98b; color: #8a5a00; flex: 1; }
.btn.thanks.on { background: var(--thanks); border-color: var(--thanks); color: #fff; }

/* ---- 登録フォーム ---- */
.hint { font-size: 13px; color: var(--muted); margin: 2px 0 6px; }
.warn { background: var(--warn); border-radius: 10px; padding: 8px 10px; font-size: 13px; margin: 6px 0; }
.tagbtns { display: flex; flex-wrap: wrap; gap: 6px; }
.tagbtn { border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 9px 12px; font-size: 14px; }
.tagbtn.on { background: var(--green); border-color: var(--green); color: #fff; font-weight: 700; }
.photo-pick { display: inline-flex; }
.photo-pick span { border: 1px dashed var(--green); color: var(--green-dark); border-radius: 12px; padding: 10px 14px; font-weight: 600; background: var(--green-soft); cursor: pointer; }
#f-prev { display: block; margin-top: 8px; max-width: 100%; max-height: 150px; border-radius: 10px; }
textarea, input[type=text], input[type=email], input[type=password] {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font: inherit; background: #fff; color: var(--ink);
}
textarea { min-height: 76px; resize: vertical; }
.sheet .row.end { margin-top: 14px; justify-content: flex-end; }
.sheet .row.end .btn.primary { flex: 1; }

/* ---- モーダル ---- */
.modal {
  position: fixed; inset: 0; z-index: 1200; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center;
}
.modal-card {
  width: 100%; max-width: 460px; max-height: 92dvh; overflow-y: auto; background: #fff; border-radius: 18px 18px 0 0;
  padding: 18px 18px calc(20px + env(safe-area-inset-bottom)); animation: up .2s ease-out;
}
@media (min-width: 720px) { .modal { align-items: center; } .modal-card { border-radius: 18px; } }
.modal-card h2 { margin: 0 0 8px; font-size: 18px; }
.modal-card form { display: grid; gap: 10px; margin-top: 8px; }
.modal-card label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
.modal-card label input { color: var(--ink); font-weight: 400; font-size: 15px; }
.modal-card small { color: var(--muted); }
.err { color: var(--danger); font-size: 13px; margin: 0; min-height: 1em; }
.tabs { display: flex; background: var(--bg); border-radius: 12px; padding: 4px; gap: 4px; margin: 8px 0; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.tabs button.on { background: #fff; color: var(--green-dark); box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 14px 0 10px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
#g-btn { display: flex; justify-content: center; min-height: 44px; }
.profile { display: flex; align-items: center; gap: 12px; margin: 6px 0 12px; }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--green-soft); display: grid; place-items: center; font-size: 22px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px; }
.stats div { background: var(--green-soft); border-radius: 12px; padding: 10px; text-align: center; }
.stats b { display: block; font-size: 22px; color: var(--green-dark); }
.stats span { font-size: 12px; color: var(--muted); }
.inline-form { display: flex !important; gap: 8px; }
.inline-form input { flex: 1; }
.month-nav { display: flex; align-items: center; justify-content: space-between; margin: 8px 0; }
.month-nav button { border: 1px solid var(--line); background: #fff; border-radius: 10px; width: 40px; height: 36px; }
.month-nav button:disabled { opacity: .35; }
.rank { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 6px; }
.rank li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--bg); }
.rank li.me { background: #fff3cf; outline: 2px solid #f7d98b; }
.rank .no { width: 30px; text-align: center; font-weight: 700; }
.rank .nm { flex: 1; word-break: break-all; }
.rank .ct { font-weight: 700; color: var(--green-dark); }
.empty { text-align: center; color: var(--muted); padding: 24px 0; }

/* ---- お知らせ・バッジ・確認メール・チェックボックス ---- */
.top-btn.icon { position: relative; padding: 6px 10px; }
.dot { position: absolute; top: 3px; right: 4px; width: 11px; height: 11px; border-radius: 50%; background: #ff4d4f; border: 2px solid var(--green); }
.modal-card label.check { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--ink); font-weight: 500; }
.modal-card label.check input { width: 22px; height: 22px; flex-shrink: 0; accent-color: var(--green); }
.notice-list { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 8px; }
.notice-list button { width: 100%; text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 12px 14px; display: grid; gap: 2px; color: var(--ink); }
.notice-list button:active { background: var(--bg); }
.notice-list b { font-size: 15px; }
.notice-list small { color: var(--muted); }
.notice-list .new { color: #d6454a; font-weight: 700; font-size: 11px; margin-left: 6px; }
.notice-body { white-space: pre-wrap; line-height: 1.8; word-break: break-word; margin: 10px 0; }
.ver { text-align: center; color: var(--muted); font-size: 12px; margin: 12px 0 0; }
.badge { display: inline-block; font-size: 12px; border-radius: 999px; padding: 2px 9px; font-weight: 700; }
.badge.ok { background: var(--green-soft); color: var(--green-dark); }
.badge.ng { background: var(--warn); color: #8a5a00; }
.verify-box { background: var(--warn); border-radius: 12px; padding: 12px; margin: 8px 0; font-size: 14px; line-height: 1.65; }
.verify-box .btn { margin-top: 8px; }

/* ---- スマホ最適化 ---- */
html { -webkit-text-size-adjust: 100%; }
button, a, .chip { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.sheet, .modal-card { overscroll-behavior: contain; }
input, textarea { font-size: 16px !important; } /* iOSで入力時に画面が勝手に拡大されるのを防ぐ */
@media (max-width: 719px) {
  .top-btn { min-height: 40px; }
  .chip { padding: 9px 13px; font-size: 14px; }
  .btn { min-height: 46px; }
  .tagbtn { min-height: 44px; }
  .x { width: 40px; height: 40px; }
  .leaflet-control-zoom { display: none; } /* ピンチ操作で拡大縮小できるので隠す */
  .fab { width: 54px; height: 54px; }
  .fab.primary { width: auto; height: 54px; }
  .sheet { max-height: 64dvh; padding-top: 8px; }
  .sheet::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 10px; }
  .modal-card { max-height: 94dvh; }
  .modal-card h2 { font-size: 17px; }
  .photo img { max-height: 220px; }
}
@media (max-width: 480px) {
  #btn-account .nick { display: none; } /* ログイン中は 👤 だけにしてタイトルの幅を確保 */
}
@media (max-width: 400px) {
  #topbar h1 { font-size: 13px; }
  .top-btn { padding: 6px 9px; }
}
