/* style.css — 紙の地図帳トーン（設計書 §0-16：クリーム紙 × インク紺 × 朱アクセント）
 * UIテク適用：見出し text-wrap:balance／本文 pretty／font-smoothing／数値 tabular-nums／
 * 多層box-shadow／中断可能な transition／状態変化前後のレイアウト固定（CLSゼロ）
 */

:root {
  --paper: #f7f3e8;
  --paper-card: #fffdf6;
  --paper-sunken: #f2ede0;
  --ink: #1f3a5f;
  --ink-soft: rgba(31, 58, 95, 0.68);
  --ink-faint: rgba(31, 58, 95, 0.45);
  --line: rgba(31, 58, 95, 0.16);
  --line-strong: rgba(31, 58, 95, 0.32);
  --accent: #d9442c;
  --accent-dark: #b9351f;
  --radius: 10px;
  --font: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
  --shadow-card:
    0 1px 1px rgba(31, 58, 95, 0.05),
    0 2px 4px rgba(31, 58, 95, 0.05),
    0 8px 16px rgba(31, 58, 95, 0.05);
  --shadow-pop:
    0 1px 2px rgba(31, 58, 95, 0.10),
    0 6px 12px rgba(31, 58, 95, 0.12),
    0 18px 32px rgba(31, 58, 95, 0.14);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background-color: var(--paper);
  /* 方眼紙の目（地図帳の下敷き） */
  background-image:
    linear-gradient(to right, rgba(31, 58, 95, 0.045) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(31, 58, 95, 0.045) 1px, transparent 1px);
  background-size: 28px 28px;
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.wrap { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 16px; }

h1, h2, h3 { text-wrap: balance; line-height: 1.4; margin: 0; }
p { text-wrap: pretty; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.num, .legend-range, .legend-count, .manual-input, .unmatched-raw {
  font-variant-numeric: tabular-nums;
}

/* ── ヘッダー ─────────────────────────────── */

.site-header {
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 253, 246, 0.92), rgba(247, 243, 232, 0.75));
}
.header-inner { padding: 14px 16px 16px; }
.brand { display: flex; align-items: center; gap: 10px; margin: 0; }
.brand-mark {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; border-radius: 6px;
  background: var(--ink); color: var(--paper-card);
  font-weight: 700; font-size: 19px; letter-spacing: 0;
}
.brand-text { font-size: 20px; font-weight: 700; letter-spacing: 0.01em; }
.tagline { margin: 6px 0 0; font-size: 13.5px; color: var(--ink-soft); }

/* ── レイアウト ───────────────────────────── */

.layout { display: grid; gap: 16px; padding: 16px 0 0; }
.controls { display: grid; gap: 16px; align-content: start; }

.card {
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 14px 16px 16px;
}
.card-title {
  font-size: 14px; font-weight: 700; letter-spacing: 0.04em;
  color: var(--ink-soft);
  padding-bottom: 8px; margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

/* ── 地図 ─────────────────────────────────── */

.map-wrap {
  position: relative;
  background: var(--paper-sunken);
  border: 1px solid var(--line);
  border-radius: 8px;
  /* 高さ固定＝データ読込・再分類でレイアウトが動かない（CLSゼロ） */
  aspect-ratio: 1000 / 1130.5;
  overflow: hidden;
}
.map-svg { display: block; width: 100%; height: 100%; }

/* fill はJS（map-render.js）が fill属性で与える。
   ここで fill を宣言するとCSSがプレゼンテーション属性に勝ってしまい、
   塗り分けが画面に出なくなる（PNG側はcanvas描画なので気付けない）ため宣言しない。 */
.map-svg .pref {
  stroke: rgba(31, 58, 95, 0.45);
  stroke-width: 0.9;
  stroke-linejoin: round;
  cursor: pointer;
  transition: fill 140ms ease-out, stroke-width 120ms ease-out;
}
.map-svg .pref:hover { stroke: var(--ink); stroke-width: 2.2; }
.map-svg .inset-frame { fill: none; stroke: var(--line-strong); stroke-width: 1.4; stroke-dasharray: 5 4; }
.map-svg .inset-label { fill: var(--ink-soft); font: 600 20px var(--font); }

.map-tip {
  position: absolute; z-index: 3; pointer-events: none;
  padding: 4px 9px; border-radius: 6px;
  background: var(--ink); color: #fffdf6;
  font-size: 13px; font-weight: 600; white-space: nowrap;
  font-variant-numeric: tabular-nums;
  box-shadow: var(--shadow-pop);
}

.popover {
  position: absolute; z-index: 4; width: 218px;
  padding: 10px 12px 12px;
  background: var(--paper-card);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: var(--shadow-pop);
}
.popover-title { margin: 0; font-size: 14px; font-weight: 700; }
.popover-desc { margin: 2px 0 8px; font-size: 12px; color: var(--ink-soft); }
.popover-colors { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch-btn {
  width: 26px; height: 26px; border-radius: 5px;
  border: 1px solid var(--line-strong); cursor: pointer;
  transition: transform 110ms ease-out;
}
.swatch-btn:hover { transform: translateY(-1px) scale(1.06); }
.popover-actions { display: flex; gap: 6px; margin-top: 10px; }

/* ── 凡例 ─────────────────────────────────── */

.legend-block { margin-top: 14px; }
.legend-heading {
  font-size: 12px; font-weight: 700; letter-spacing: 0.06em;
  color: var(--ink-faint); margin-bottom: 6px;
}
.legend {
  /* 段階数の変更で高さが跳ねないよう最小高を確保 */
  min-height: 168px;
}
.legend-list { list-style: none; margin: 0; padding: 0; }
.legend-item {
  display: flex; align-items: center; gap: 9px;
  padding: 3px 0; font-size: 14px;
}
.legend-swatch {
  flex: 0 0 auto; width: 30px; height: 15px; border-radius: 3px;
  border: 1px solid var(--line-strong);
}
.legend-range { font-weight: 600; }
.legend-count { color: var(--ink-faint); font-size: 12.5px; }
.legend-item--nodata .legend-range { font-weight: 500; color: var(--ink-soft); }
.legend-note { margin: 8px 0 0; font-size: 12px; color: var(--ink-soft); }
.legend-empty { margin: 0; font-size: 13.5px; color: var(--ink-faint); }

/* ── 完成・履歴 ───────────────────────────── */

.finish { margin-top: 14px; }
.history { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.history-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
.history-btn {
  width: 100%; text-align: left; padding: 7px 10px;
  background: var(--paper-sunken); border: 1px solid var(--line);
  border-radius: 6px; color: var(--ink); font-size: 13.5px; font-family: inherit;
  cursor: pointer; transition: background-color 120ms ease-out;
}
.history-btn:hover { background: #eae4d3; }

/* ── ボタン・フォーム ─────────────────────── */

.btn {
  font-family: inherit; font-size: 15px; font-weight: 700;
  padding: 11px 18px; border-radius: 7px; cursor: pointer;
  border: 1px solid transparent;
  transition: background-color 130ms ease-out, transform 90ms ease-out, box-shadow 130ms ease-out;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  width: 100%;
  background: var(--accent); color: #fffdf6;
  box-shadow: 0 1px 2px rgba(185, 53, 31, 0.25), 0 4px 10px rgba(185, 53, 31, 0.18);
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:disabled { background: var(--ink-faint); box-shadow: none; cursor: progress; }
.btn-quiet {
  background: var(--paper-sunken); color: var(--ink); border-color: var(--line-strong);
}
.btn-quiet:hover { background: #eae4d3; }
.btn-sm { font-size: 13.5px; padding: 8px 13px; width: auto; }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 9px; }

.field-label {
  display: block; font-size: 12.5px; font-weight: 700;
  color: var(--ink-soft); margin: 0 0 5px;
}
input[type="text"], select, textarea {
  width: 100%; font-family: inherit; font-size: 15px; color: var(--ink);
  background: var(--paper-card);
  border: 1px solid var(--line-strong); border-radius: 6px;
  padding: 9px 10px;
  transition: border-color 120ms ease-out, box-shadow 120ms ease-out;
}
input[type="text"]:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(31, 58, 95, 0.12);
}
.paste-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13.5px; line-height: 1.6; resize: vertical; min-height: 150px;
}

.status {
  /* 空でも高さを持たせてメッセージ表示時のズレを消す */
  min-height: 1.5em; margin: 8px 0 0;
  font-size: 13px; color: var(--ink-soft);
}
.status.is-error { color: var(--accent-dark); font-weight: 600; }
.hint { margin: 9px 0 0; font-size: 12.5px; color: var(--ink-soft); }
.hint-sm { margin-top: 5px; }

/* ── タブ ─────────────────────────────────── */

.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tab {
  font-family: inherit; font-size: 14px; font-weight: 700;
  padding: 8px 15px; border-radius: 7px 7px 0 0;
  background: transparent; color: var(--ink-soft);
  border: 1px solid transparent; border-bottom: 2px solid transparent;
  cursor: pointer; transition: color 120ms ease-out, border-color 120ms ease-out;
}
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.tab:hover { color: var(--ink); }

/* ── 列選択・マッチ結果 ───────────────────── */

.column-picker {
  margin-top: 12px; padding: 10px 12px;
  background: var(--paper-sunken); border: 1px solid var(--line); border-radius: 7px;
}
.match-panel {
  margin-top: 12px; padding: 10px 12px;
  background: var(--paper-sunken); border: 1px solid var(--line); border-radius: 7px;
}
.match-summary { margin: 0; font-size: 13.5px; font-weight: 700; }
.unmatched-list { list-style: none; margin: 9px 0 0; padding: 0; display: grid; gap: 7px; }
.unmatched-list li { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.unmatched-raw { font-size: 13px; color: var(--ink-soft); }
.unmatched-select { width: auto; min-width: 140px; font-size: 13.5px; padding: 6px 8px; }

/* ── 手入力テーブル ───────────────────────── */

.manual-scroll { max-height: 340px; overflow-y: auto; border: 1px solid var(--line); border-radius: 7px; }
.manual-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.manual-table thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--paper-sunken); text-align: left;
  font-size: 12px; color: var(--ink-soft); padding: 7px 10px;
  border-bottom: 1px solid var(--line);
}
.manual-table tbody th {
  text-align: left; font-weight: 500; padding: 4px 10px; white-space: nowrap;
}
.manual-table tbody td { padding: 3px 8px 3px 0; }
.manual-table tbody tr:nth-child(even) { background: rgba(31, 58, 95, 0.025); }
.manual-input { padding: 5px 8px; font-size: 14px; }

/* ── 設定 ─────────────────────────────────── */

.opt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.opt { margin-bottom: 12px; }

.palette-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.palette-btn {
  display: grid; gap: 5px; padding: 7px;
  background: var(--paper-card); border: 1px solid var(--line-strong);
  border-radius: 7px; cursor: pointer; font-family: inherit;
  transition: border-color 120ms ease-out, box-shadow 120ms ease-out;
}
.palette-btn[aria-pressed="true"] {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px rgba(31, 58, 95, 0.16);
}
.palette-strip { display: flex; height: 14px; border-radius: 3px; overflow: hidden; }
.palette-strip span { flex: 1 1 0; }
.palette-name { font-size: 11.5px; color: var(--ink-soft); font-weight: 700; }

/* ── 本文（FAQ） ──────────────────────────── */

.prose { margin: 16px 0 0; }
.prose h3 { font-size: 15.5px; margin: 18px 0 4px; }
.prose h3:first-of-type { margin-top: 4px; }
.prose p { margin: 0; font-size: 14.5px; color: rgba(31, 58, 95, 0.86); }

.noscript {
  margin: 16px 0 0; padding: 12px 14px;
  background: #fff4ef; border: 1px solid var(--accent);
  border-radius: 7px; font-size: 14px;
}

/* ── ナビ ─────────────────────────────────── */

.brand-link { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand-link:hover .brand-text { color: var(--accent-dark); }

.site-nav { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 9px 0 0; }
.site-nav a {
  font-size: 13px; font-weight: 700; color: var(--ink-soft); text-decoration: none;
  border-bottom: 1px solid transparent; transition: color 120ms ease-out, border-color 120ms ease-out;
}
.site-nav a:hover { color: var(--accent-dark); border-bottom-color: currentColor; }

/* ── プリセット ───────────────────────────── */

.preset-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; }
.preset-btn {
  padding: 9px 11px; text-align: left;
  background: var(--paper-sunken); border: 1px solid var(--line-strong);
  border-radius: 7px; color: var(--ink);
  font-family: inherit; font-size: 13.5px; font-weight: 700;
  cursor: pointer; transition: background-color 120ms ease-out, border-color 120ms ease-out;
}
.preset-btn:hover { background: #eae4d3; border-color: var(--ink); }

/* ── 共有 ─────────────────────────────────── */

.finish-actions { display: grid; gap: 8px; }
.btn-secondary {
  width: 100%;
  background: var(--paper-card); color: var(--ink); border-color: var(--ink);
}
.btn-secondary:hover { background: var(--paper-sunken); }
.btn-secondary:disabled { color: var(--ink-faint); border-color: var(--line-strong); cursor: progress; }

.share-result {
  margin-top: 12px; padding: 11px 12px 13px;
  background: var(--paper-sunken); border: 1px solid var(--line); border-radius: 7px;
}
.share-row { display: grid; grid-template-columns: 1fr auto; gap: 7px; align-items: center; }
.share-url { font-size: 13px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.share-result .btn-quiet { justify-self: start; margin-top: 9px; text-decoration: none; display: inline-block; }
.share-row .btn-quiet { margin-top: 0; }

/* ── 共有ページ（/m/） ────────────────────── */

.shared-card { margin-top: 16px; }
.shared-title { font-size: 21px; font-weight: 700; margin-bottom: 4px; }
.shared-unit { margin: 0 0 10px; font-size: 13px; color: var(--ink-soft); }
.shared-src { margin: 12px 0 0; font-size: 12.5px; color: var(--ink-soft); }
.shared-src a { color: var(--ink); }
.shared-cta { display: grid; gap: 8px; margin-top: 14px; }
.shared-cta .btn-quiet { text-align: center; text-decoration: none; padding: 11px 18px; }
.shared-note { margin: 10px 0 0; font-size: 12px; color: var(--ink-faint); }
.shared-explore { margin-top: 16px; }

/* ── 記事ページ（/data/ ・ガイド・定型ページ） ── */

.article { max-width: 760px; margin: 16px auto 0; }
.article h1 { font-size: 25px; margin-bottom: 10px; }
.article h2 {
  font-size: 18px; margin: 30px 0 8px;
  padding-bottom: 6px; border-bottom: 1px solid var(--line);
}
.article h3 { font-size: 15.5px; margin: 20px 0 4px; }
.article p { margin: 0 0 14px; font-size: 15px; color: rgba(31, 58, 95, 0.88); }
.article ul, .article ol { margin: 0 0 14px; padding-left: 1.4em; font-size: 15px; }
.article li { margin-bottom: 5px; }
.article a { color: var(--accent-dark); }
.article table { width: 100%; border-collapse: collapse; font-size: 14px; margin: 0 0 14px; }
.article th, .article td { border: 1px solid var(--line); padding: 6px 9px; text-align: left; }
.article th { background: var(--paper-sunken); font-size: 13px; }
.article td.num, .article td:last-child { font-variant-numeric: tabular-nums; }
.article code { font-size: 13px; background: var(--paper-sunken); padding: 1px 5px; border-radius: 4px; }

.breadcrumb { margin: 14px 0 0; font-size: 12.5px; color: var(--ink-soft); }
.breadcrumb a { color: var(--ink-soft); }
.breadcrumb ol { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; }
.breadcrumb li + li::before { content: "›"; margin-right: 6px; color: var(--ink-faint); }

.source-block {
  margin: 18px 0; padding: 11px 13px;
  background: var(--paper-sunken); border-left: 3px solid var(--ink-faint); border-radius: 0 7px 7px 0;
}
.source-block p { margin: 0 0 5px; font-size: 13px; color: var(--ink-soft); }
.source-block p:last-child { margin-bottom: 0; }
.checked-badge {
  display: inline-block; margin-bottom: 12px; padding: 3px 9px;
  background: var(--paper-sunken); border: 1px solid var(--line-strong); border-radius: 999px;
  font-size: 12px; color: var(--ink-soft); font-variant-numeric: tabular-nums;
}

.cta-block {
  margin: 22px 0; padding: 15px 16px;
  background: var(--paper-card); border: 1px solid var(--ink); border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}
.cta-block p { margin: 0 0 10px; font-size: 14.5px; }
.cta-block .btn { display: inline-block; width: auto; text-decoration: none; text-align: center; }

.link-list { list-style: none; margin: 10px 0 0; padding: 0; }
.link-list li { margin-bottom: 5px; font-size: 14.5px; }
.link-list a { color: var(--accent-dark); }
.link-list--grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px 14px; }

/* /data/ ハブ：リンクの下に一行の要約を敷く */
.hub-list li { margin-bottom: 12px; }
.hub-list a { font-weight: 700; }
.hub-desc { display: block; font-size: 13px; color: var(--ink-soft); line-height: 1.6; }

.article-map { margin: 0 0 16px; }
.article-map .map-wrap { max-width: 460px; margin: 0 auto; }
.article-map .legend { min-height: 0; }

/* ── お問い合わせフォーム ─────────────────── */

.form-field { margin-bottom: 14px; }
.form-field textarea { min-height: 150px; resize: vertical; }
.turnstile-slot { margin: 14px 0; min-height: 68px; }
.form-note { font-size: 12.5px; color: var(--ink-soft); }

/* ── フッター ─────────────────────────────── */

.site-footer {
  margin-top: 28px; padding: 18px 0 26px;
  border-top: 1px solid var(--line);
}
.site-footer p { margin: 0; font-size: 12px; color: var(--ink-faint); }
.credit { margin-bottom: 3px; }
.footer-nav { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 8px 0; }
.footer-nav a { font-size: 12.5px; color: var(--ink-soft); text-decoration: none; }
.footer-nav a:hover { color: var(--accent-dark); text-decoration: underline; }
/* お問い合わせはフッター最下部の小さいリンク1本だけ（独立管理ポリシー §3） */
.footer-contact { margin-top: 6px !important; font-size: 11.5px !important; }
.footer-contact a { color: var(--ink-faint); }

/* ── 広告枠・紹介リンク ─────────────────────── */

/* slot ID 発行前は中身が空。空のあいだは枠ごと消し、余白も罫線も出さない。
   ins 要素を入れた時点で min-height が効き、読み込み前後で高さが動かない（CLS抑制）。 */
.ad-slot { display: none; }
.ad-slot:not(:empty) {
  display: block;
  margin: 16px 0 0;
  min-height: 280px;
  text-align: center;
  overflow: hidden;
}
.ad-slot--article:not(:empty) { margin: 22px 0; }
.ad-slot--footer:not(:empty) { margin: 24px 0 0; }

.promo { margin-top: 16px; }
.promo-intro { margin: 0 0 12px; font-size: 14.5px; color: var(--ink-soft); }
.promo-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.promo-card {
  display: flex; flex-direction: column; gap: 3px;
  padding: 12px 14px;
  background: var(--paper-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-decoration: none;
  transition: border-color 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
}
.promo-card:hover {
  border-color: var(--line-strong);
  transform: translateY(-1px);
  box-shadow: var(--shadow-card);
}
.promo-card-name { font-size: 14.5px; font-weight: 700; color: var(--ink); }
.promo-card-desc { font-size: 12.5px; color: var(--ink-soft); }
.promo-note { margin: 12px 0 0; font-size: 12px; color: var(--ink-faint); }

.footer-pr { margin-bottom: 3px; }

/* ── モバイル（〜899px）＝1画面完結 ────────── */

@media (max-width: 899px) {
  .map-card {
    position: sticky; top: 0; z-index: 5;
    /* sticky時に背景が透けないよう不透明にする */
    background: var(--paper-card);
    padding-top: 10px;
  }
  .map-card .card-title { display: none; }
  .map-wrap {
    /* 画面高の40%で固定＝スクロール中も地図が見え、かつCLSが出ない */
    aspect-ratio: auto; height: 40vh; min-height: 220px;
  }
  .legend { min-height: 0; }
  .legend-block { margin-top: 10px; }
  .legend-list { display: flex; flex-wrap: wrap; gap: 4px 12px; }
  .legend-note, .history { display: none; }
  .finish { margin-top: 10px; }
  .palette-list { grid-template-columns: repeat(2, 1fr); }
  .manual-scroll { max-height: 300px; }
  .preset-list { grid-template-columns: 1fr; }
  .link-list--grid { grid-template-columns: 1fr; }
  .promo-grid { grid-template-columns: 1fr; }
  .article h1 { font-size: 21px; }
  .article-map .map-wrap { max-width: none; }
}

/* ── デスクトップ（900px〜） ───────────────── */

@media (min-width: 900px) {
  .layout { grid-template-columns: minmax(360px, 44%) 1fr; align-items: start; }
  .map-card { position: sticky; top: 16px; }
  .wrap { padding: 0 24px; }
  .header-inner { padding: 18px 24px 20px; }
  .brand-text { font-size: 23px; }
}

/* 動きを減らす設定を尊重する */
@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; }
}
