:root {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --surface-2: #eef2f6;
  --text: #1b2430;
  --text-muted: #556274;
  --border: #d5dde6;
  --accent: #0b5cad;
  --accent-text: #ffffff;
  --shadow: 0 6px 24px rgba(15, 30, 50, 0.18);
  /* 点の色（Okabe-Ito系。色覚の違いでも区別しやすい組み合わせ） */
  --pt-visited: #009e73;
  --pt-wanted: #e69f00;
  --pt-none: #0072b2;
  --pt-stroke: #ffffff;
  --radius: 18px;
  --danger: #b3261e;
  /* 地図（自作の日本地図） */
  --map-sea: #cde8f4;
  --map-sea-grad: linear-gradient(180deg, #e6f6fc 0%, #c6e7f5 55%, #a9d9ef 100%);
  --map-land: #fbfaf5;
  --map-border: #b9c8d3;
  --tile-filter: saturate(0.35) brightness(1.05) contrast(0.92);
  /* 海の色（詳細パネル） */
  --sea-1: #0a4f8a;
  --sea-2: #127fb8;
  --sea-3: #2fb3d6;
  --wave-back: rgba(255, 255, 255, 0.28);
  --wave-mid: rgba(255, 255, 255, 0.5);
  --topbar-h: 104px;
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11161d;
    --surface: #1a212b;
    --surface-2: #232c38;
    --text: #e8edf3;
    --text-muted: #a3afbf;
    --border: #334050;
    --accent: #5aa9f0;
    --accent-text: #0b1520;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
    --pt-stroke: #1a212b;
    --sea-1: #04203d;
    --danger: #ff8a80;
    --map-sea: #0d2a42;
    --map-sea-grad: linear-gradient(180deg, #123552 0%, #0d2a42 55%, #08203a 100%);
    --map-land: #263342;
    --map-border: #3f5266;
    --tile-filter: saturate(0.3) brightness(0.72) contrast(1.05);
    --sea-2: #0a4a78;
    --sea-3: #11789f;
    --wave-back: rgba(255, 255, 255, 0.10);
    --wave-mid: rgba(255, 255, 255, 0.20);
  }
}
:root[data-theme="dark"] {
  --bg: #11161d;
  --surface: #1a212b;
  --surface-2: #232c38;
  --text: #e8edf3;
  --text-muted: #a3afbf;
  --border: #334050;
  --accent: #5aa9f0;
  --accent-text: #0b1520;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  --pt-stroke: #1a212b;
  --sea-1: #04203d;
  --danger: #ff8a80;
  --map-sea: #0d2a42;
  --map-sea-grad: linear-gradient(180deg, #123552 0%, #0d2a42 55%, #08203a 100%);
  --map-land: #263342;
  --map-border: #3f5266;
  --tile-filter: saturate(0.3) brightness(0.72) contrast(1.05);
  --sea-2: #0a4a78;
  --sea-3: #11789f;
  --wave-back: rgba(255, 255, 255, 0.10);
  --wave-mid: rgba(255, 255, 255, 0.20);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
  overflow: hidden;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* 上部バー */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 1000;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.search { display: flex; gap: 8px; }
.search input {
  flex: 1; min-width: 0;
  height: 44px; padding: 0 12px;
  font: inherit; color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px;
}
.search input:focus-visible, .btn:focus-visible, .chip:focus-visible, .list button:focus-visible, .panel__close:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-height: 44px; padding: 0 16px;
  font: inherit; font-weight: 600; color: var(--text); text-decoration: none;
  background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px;
  cursor: pointer;
}
.btn[aria-expanded="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn--primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.filters { display: flex; gap: 6px; margin-top: 8px; overflow-x: auto; scrollbar-width: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  min-height: 36px; padding: 0 12px;
  font: inherit; font-size: 14px; color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border); border-radius: 999px;
  cursor: pointer;
}
.chip[aria-pressed="true"] { color: var(--text); background: var(--surface-2); border-color: var(--text-muted); }
.chip[aria-pressed="false"] .dot { opacity: 0.3; }
.dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--pt-stroke); box-shadow: 0 0 0 1px var(--border); }
.dot--visited { background: var(--pt-visited); }
.dot--wanted { background: var(--pt-wanted); }
.dot--none { background: var(--pt-none); }

/* 地図 */
#map {
  position: fixed; inset: var(--topbar-h) 0 0 0;
  background: var(--surface-2);
}
.leaflet-container { font: inherit; }
/* 全国〜地方の表示：海は水色のグラデーション */
#map.leaflet-container {
  background-color: var(--map-sea);
  background-image: var(--map-sea-grad);
}
/* 地方ごとの魚のイラスト */
.region-fish { display: flex; flex-direction: column; align-items: center; pointer-events: none; }
.region-fish svg { display: block; animation: fish-bob 4s ease-in-out infinite; filter: drop-shadow(0 2px 3px rgba(0, 40, 80, 0.18)); }
.region-fish__label {
  margin-top: 1px; padding: 0 6px;
  font-size: 10px; line-height: 16px; white-space: nowrap; color: var(--text-muted);
  background: color-mix(in srgb, var(--surface) 75%, transparent); border-radius: 8px;
}
@keyframes fish-bob { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-3px) rotate(2deg); } }
@media (prefers-reduced-motion: reduce) { .region-fish svg { animation: none; } }
/* 拡大時：OSMは色を抑える */
.leaflet-tile-pane { filter: var(--tile-filter); }
.leaflet-control-attribution { font-size: 11px; }

.status-message {
  position: fixed; left: 16px; right: 16px; top: calc(var(--topbar-h) + 8px); z-index: 1100;
  margin: 0; padding: 10px 14px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
}

/* 一覧 */
.list-view {
  position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 1050;
  overflow-y: auto; padding: 8px 16px calc(24px + env(safe-area-inset-bottom));
  background: var(--bg);
}
.list-count { margin: 4px 0 8px; font-size: 14px; color: var(--text-muted); }
.list { list-style: none; margin: 0; padding: 0; }
.list li + li { margin-top: 6px; }
.list button {
  display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 56px; padding: 8px 12px;
  font: inherit; color: var(--text); text-align: left;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px;
  cursor: pointer;
}
.list .list__name { font-weight: 600; overflow-wrap: anywhere; }
.list .list__place { font-size: 13px; color: var(--text-muted); }
.list-empty { color: var(--text-muted); }

/* 詳細パネル（スマホ：下から／PC：右側）。上部は海のグラデーションと波 */
.panel {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1080;
  max-height: 66vh; overflow-y: auto;
  background: var(--surface);
  border-top-left-radius: var(--radius); border-top-right-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel__hero {
  position: relative;
  min-height: 156px;
  padding: 10px 100px 44px 16px;
  color: #ffffff;
  background: linear-gradient(170deg, var(--sea-1) 0%, var(--sea-2) 55%, var(--sea-3) 100%);
  overflow: hidden;
}
/* 水面のきらめき */
.panel__hero::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(circle at 18% 22%, rgba(255,255,255,0.22) 0 2px, transparent 3px),
    radial-gradient(circle at 72% 30%, rgba(255,255,255,0.18) 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 46% 12%, rgba(255,255,255,0.16) 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 88% 58%, rgba(255,255,255,0.14) 0 2px, transparent 3px);
}
.panel__handle { position: relative; width: 40px; height: 4px; margin: 0 auto 10px; border-radius: 2px; background: rgba(255,255,255,0.6); }
.panel__waves {
  position: absolute; left: 0; bottom: -1px; width: 200%; height: 40px;
  display: block; pointer-events: none;
}
.panel__waves .w1 { fill: var(--wave-back); }
.panel__waves .w2 { fill: var(--wave-mid); }
.panel__waves .w3 { fill: var(--surface); }
.panel__waves .layer { animation: drift 14s linear infinite; }
.panel__waves .layer--mid { animation-duration: 10s; animation-direction: reverse; }
.panel__waves .layer--front { animation: none; }
@keyframes drift { from { transform: translateX(0); } to { transform: translateX(-50%); } }
@media (prefers-reduced-motion: reduce) {
  .panel__waves .layer { animation: none; }
}
.panel__close {
  position: absolute; top: 8px; right: 8px; z-index: 1;
  width: 44px; height: 44px;
  font-size: 24px; line-height: 1; color: #ffffff;
  background: rgba(255,255,255,0.14); border: 0; border-radius: 50%; cursor: pointer;
}
.panel__close:hover { background: rgba(255,255,255,0.26); }
.panel__kana { position: relative; margin: 0; font-size: 13px; opacity: 0.9; }
.panel__name { position: relative; margin: 0 0 2px; font-size: 24px; line-height: 1.35; overflow-wrap: anywhere; text-shadow: 0 1px 8px rgba(0, 30, 60, 0.35); }
.panel__place { position: relative; margin: 0; opacity: 0.92; }
.panel__animal {
  position: absolute; right: 12px; bottom: 16px; z-index: 1; margin: 0;
  display: flex; flex-direction: column; align-items: center; gap: 2px; width: 84px;
}
/* 売りの動物の絵（FR-017）。ライト・ダークとも同じ明るい丸の上に描く */
.panel__animal-art {
  display: grid; place-items: center; width: 64px; height: 64px; border-radius: 50%; overflow: hidden;
  background: radial-gradient(circle at 35% 30%, #ffffff 0%, #e6f4fb 70%, #cfe8f5 100%);
  box-shadow: 0 2px 10px rgba(0, 30, 60, 0.3); border: 2px solid rgba(255,255,255,0.85);
}
.panel__animal-name {
  max-width: 84px; padding: 1px 7px; border-radius: 999px;
  font-size: 11px; line-height: 1.5; text-align: center; color: #0d3550;
  background: rgba(255,255,255,0.92); overflow-wrap: anywhere;
}
.panel__body { padding: 4px 16px calc(20px + env(safe-area-inset-bottom)); }
.panel__feature { margin: 4px 0 14px; font-size: 15px; line-height: 1.75; }
.panel__actions { display: flex; flex-wrap: wrap; gap: 8px; }
.btn--want[aria-pressed="true"] { background: var(--pt-wanted); border-color: var(--pt-wanted); color: #1b1300; }
.want-icon { font-size: 18px; line-height: 1; }
.want-names { margin: 8px 0 0; font-size: 14px; color: var(--text-muted); }

.records { margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--border); }
.records__title { margin: 0 0 8px; font-size: 17px; }
.records__message { margin: 0 0 8px; font-size: 14px; color: var(--text-muted); }
.records__list { list-style: none; margin: 0 0 12px; padding: 0; }
.record { padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }
.record + .record { margin-top: 8px; }
.record__head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.record__date { font-weight: 600; }
.record__stars { color: var(--pt-wanted); letter-spacing: 1px; }
.record__by { font-size: 13px; color: var(--text-muted); }
.record__comment { margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.record__tools { display: flex; gap: 6px; margin-top: 8px; }
.record__tools .btn { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn--add { width: 100%; }

.record-form { padding: 12px; border: 1px solid var(--border); border-radius: 12px; }
.record-form__title { margin: 0 0 8px; font-size: 16px; }
.field { display: block; margin-bottom: 12px; }
.field__label { display: flex; justify-content: space-between; margin-bottom: 4px; font-size: 14px; font-weight: 600; }
.field__count { font-weight: 400; color: var(--text-muted); }
.field input[type="date"], .field textarea {
  width: 100%; padding: 10px 12px;
  font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
.field input[type="date"] { min-height: 44px; }
.stars { display: flex; gap: 2px; margin: 0 0 12px; padding: 0; border: 0; }
.stars legend { width: 100%; padding: 0; }
.stars label { position: relative; cursor: pointer; }
.stars input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.stars span[aria-hidden] { display: inline-block; width: 44px; height: 44px; font-size: 32px; line-height: 44px; text-align: center; color: var(--border); }
.stars label.on span[aria-hidden] { color: var(--pt-wanted); }
.stars input:focus-visible + span { outline: 3px solid var(--accent); border-radius: 8px; }
.record-form__error { margin: 0 0 10px; color: var(--danger); font-size: 14px; }
.record-form__buttons { display: flex; gap: 8px; }
.field input:focus-visible, .field textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }

.panel__checked { margin: 16px 0 0; font-size: 12px; color: var(--text-muted); }
.btn--sea {
  color: #ffffff; border: 0;
  background: linear-gradient(135deg, var(--sea-2), var(--sea-3));
  box-shadow: 0 4px 14px rgba(0, 90, 150, 0.28);
}

@media (min-width: 768px) {
  :root { --topbar-h: 64px; }
  .topbar { display: flex; align-items: center; gap: 16px; }
  .search { flex: 0 1 480px; }
  .filters { margin-top: 0; }
  .list-view { right: auto; width: 380px; border-right: 1px solid var(--border); }
  .panel {
    left: auto; top: var(--topbar-h); width: 380px; max-height: none;
    border-radius: 0; border-left: 1px solid var(--border);
  }
  .panel__hero { padding-top: 20px; }
  .panel__handle { display: none; }
}
