/* ===== リセット & ベース ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f7f5f2;
  --surface: #ffffff;
  --surface-alt: #fdf9f6;
  --border: #e8e2dc;
  --text: #1c1a18;
  --text-2: #5c5854;
  --text-3: #9e9a96;
  --accent: #d63d5e;
  --accent-light: #f8d7df;
  --accent-dark: #b02d4c;
  --teal: #3bbfb8;
  --gold: #e0a83c;
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.07);
  --shadow: 0 2px 12px rgba(0,0,0,0.09);
  --shadow-lg: 0 4px 24px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 260px;
  --font: 'Noto Sans JP', sans-serif;
}

html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== ヘッダー ===== */
.site-header {
  background: linear-gradient(135deg, #c42048 0%, #e8436a 50%, #f07898 100%);
  color: white;
  padding: 1.6rem 2rem;
  display: flex;
  align-items: center;
  gap: 1.2rem;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 1000;
}
.header-icon { font-size: 2rem; }
.header-text h1 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}
.header-text p {
  font-size: 0.85rem;
  opacity: 0.88;
  margin-top: 0.15rem;
}
.header-link {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  background: rgba(255,255,255,0.18);
  color: white;
  text-decoration: none;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 500;
  border: 1px solid rgba(255,255,255,0.3);
  transition: background 0.2s;
  white-space: nowrap;
}
.header-link:hover { background: rgba(255,255,255,0.28); }

/* ===== レイアウト ===== */
.layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ===== サイドバー ===== */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.5rem 1.2rem;
  overflow-y: auto;
  position: sticky;
  top: 72px;
  height: calc(100vh - 72px);
}
.sidebar-section { margin-bottom: 1.6rem; }
.sidebar-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  margin-bottom: 0.6rem;
}
.sidebar select {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: var(--font);
  font-size: 0.88rem;
  color: var(--text);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  transition: border-color 0.2s;
}
.sidebar select:focus {
  outline: none;
  border-color: var(--accent);
}

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.stat-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.6rem;
  text-align: center;
}
.stat-box.wide { grid-column: 1 / -1; }
.stat-val {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
  display: block;
}
.stat-lbl {
  font-size: 0.72rem;
  color: var(--text-3);
  margin-top: 0.1rem;
}

/* ===== メインコンテンツ ===== */
.main-content {
  flex: 1;
  min-width: 0;
  padding: 1.6rem;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}

/* ===== セクションカード ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem 1.6rem;
  box-shadow: var(--shadow-sm);
}
.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.card-title .icon { font-size: 1.1rem; }
.question-badge {
  font-size: 0.78rem;
  background: var(--accent-light);
  color: var(--accent-dark);
  padding: 0.2rem 0.7rem;
  border-radius: 20px;
  font-weight: 600;
  margin-left: 0.5rem;
}

/* ===== 地図 ===== */
#map {
  width: 100%;
  height: 560px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  z-index: 1;
}
.map-legend-wrap {
  margin-top: 0.8rem;
}
#map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  padding-top: 0.4rem;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.83rem;
  color: var(--text-2);
}
.legend-dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  flex-shrink: 0;
}

/* Leaflet tooltip */
.custom-tooltip { background: transparent !important; border: none !important; box-shadow: none !important; }
.map-tooltip {
  background: white;
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  font-family: var(--font);
  min-width: 200px;
  border-left: 4px solid var(--accent);
}
.tooltip-city      { font-weight: 700; font-size: 0.95rem; margin-bottom: 8px; }
.tooltip-breakdown { display: flex; flex-direction: column; gap: 5px; margin-bottom: 6px; }
.breakdown-row     { display: flex; align-items: center; gap: 5px; }
.bd-dot    { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.bd-ans    { font-size: 0.8rem; color: var(--text); min-width: 5rem; flex-shrink: 0; }
.bd-bar-wrap { flex: 1; height: 7px; background: #f0eef4; border-radius: 3px; overflow: hidden; }
.bd-bar    { height: 100%; border-radius: 3px; }
.bd-pct    { font-size: 0.78rem; font-weight: 600; color: var(--text-2); min-width: 2.4rem; text-align: right; }
.tooltip-count { font-size: 0.75rem; color: var(--text-3); border-top: 1px solid #f0eef4; padding-top: 5px; }

/* 凡例 */
.legend-note { font-size: 0.72rem; color: var(--text-3); margin-top: 0.4rem; width: 100%; }

/* ===== チャートグリッド ===== */
.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.2rem;
}
.chart-wrap { position: relative; height: 340px; }

/* ===== スタックバー ===== */
.stacked-wrap { position: relative; min-height: 300px; }

/* ===== 自由記入 ===== */
.freetext-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.8rem;
}
.freetext-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-left: 3px solid var(--teal);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text);
}
.freetext-num {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--teal);
  margin-right: 0.4rem;
}
.freetext-tag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--accent-light);
  color: var(--accent-dark);
  padding: 0.1rem 0.5rem;
  border-radius: 10px;
  margin-right: 0.4rem;
}
.no-data { color: var(--text-3); font-size: 0.9rem; }

/* ===== 解析セクション ===== */
.analysis-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 0.4rem;
}
.analysis-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem 1.1rem;
}
.analysis-card h4 {
  font-size: 0.92rem;
  font-weight: 700;
  margin-bottom: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.analysis-card p { font-size: 0.86rem; color: var(--text-2); line-height: 1.65; }
.analysis-card ul {
  padding-left: 1.2rem;
  font-size: 0.84rem;
  color: var(--text-2);
  line-height: 1.8;
}
.comparison-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
  margin-top: 0.8rem;
}
.comparison-table th {
  padding: 0.5rem;
  text-align: center;
  font-weight: 700;
  border-bottom: 2px solid var(--border);
  background: var(--surface);
}
.comparison-table td {
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: center;
}
.comparison-table tr:last-child td { border-bottom: none; }
.col-shoai { color: var(--teal); font-weight: 600; }
.col-inland { color: var(--accent); font-weight: 600; }

.dialect-highlight {
  display: inline-block;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent-dark);
  margin: 0.2rem 0;
}
.dialect-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-top: 0.6rem;
}
.dialect-box {
  padding: 0.7rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
}
.dialect-box .word { font-size: 1.1rem; font-weight: 700; }
.dialect-box .note { font-size: 0.78rem; color: var(--text-3); margin-top: 0.2rem; }

.region-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
  margin-top: 0.6rem;
}
.region-table td { padding: 0.5rem 0.4rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.region-table tr:last-child td { border-bottom: none; }
.region-name { font-weight: 700; width: 3.5rem; }

.links-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.links-list a {
  display: inline-block;
  padding: 0.3rem 0.8rem;
  background: var(--accent-light);
  color: var(--accent-dark);
  border-radius: 20px;
  font-size: 0.82rem;
  text-decoration: none;
  font-weight: 500;
  transition: background 0.2s;
}
.links-list a:hover { background: #f2b8c6; }

/* ===== フッター ===== */
.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 1.2rem 2rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-3);
}

/* ===== ローディング ===== */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(247,245,242,0.96);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  flex-direction: column;
  gap: 1rem;
}
.loader {
  width: 48px; height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-overlay p { color: var(--text-2); font-size: 0.9rem; }
.load-error { text-align: center; color: var(--accent); }
.load-error button {
  margin-top: 0.8rem;
  padding: 0.5rem 1.2rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--font);
}

/* ===== フォームパネル ===== */
#form-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 1100;
  backdrop-filter: blur(2px);
}
#form-backdrop.open { display: block; }

#form-panel {
  position: fixed;
  top: 0; right: 0;
  width: 420px;
  max-width: 100vw;
  height: 100dvh;
  background: var(--surface);
  box-shadow: -4px 0 32px rgba(0,0,0,0.14);
  z-index: 1200;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
}
#form-panel.open { transform: translateX(0); }

.fp-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 1.2rem 1.4rem 0.8rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.fp-step-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--accent);
  margin-bottom: 0.2rem;
}
.fp-title { font-size: 1rem; font-weight: 700; color: var(--text); }
.fp-close {
  background: none; border: none; cursor: pointer;
  font-size: 1.1rem; color: var(--text-3); padding: 0.2rem 0.4rem;
  border-radius: 4px; transition: background 0.15s; flex-shrink: 0;
}
.fp-close:hover { background: var(--bg); }

.fp-progress-wrap {
  height: 3px;
  background: var(--border);
  flex-shrink: 0;
}
.fp-progress-bar {
  height: 100%;
  background: linear-gradient(to right, #e8436a, #c41e3a);
  transition: width 0.35s ease;
}

.fp-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.2rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.fp-footer {
  padding: 0.9rem 1.4rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  background: var(--surface);
}

/* フォームグループ */
.form-group { display: flex; flex-direction: column; gap: 0.4rem; }
.form-label { font-size: 0.9rem; font-weight: 700; color: var(--text); }
.form-hint  { font-size: 0.78rem; color: var(--text-3); line-height: 1.5; }
.req { font-size: 0.68rem; background: var(--accent); color: white; padding: 0.1rem 0.4rem; border-radius: 4px; margin-left: 0.4rem; vertical-align: middle; }
.form-select {
  padding: 0.6rem 0.8rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font); font-size: 0.88rem; color: var(--text);
  background: var(--surface);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  transition: border-color 0.2s;
}
.form-select:focus { outline: none; border-color: var(--accent); }

.radio-group { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.radio-item {
  display: flex; align-items: center; gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  border: 1.5px solid var(--border); border-radius: 20px;
  cursor: pointer; font-size: 0.83rem; color: var(--text-2);
  transition: all 0.15s;
}
.radio-item:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent-dark);
}
.radio-item input { display: none; }

/* 設問カード */
.form-qcard {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.qcard-label { font-size: 0.78rem; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: 0.05em; }
.qcard-scenario { font-size: 0.88rem; color: var(--text); line-height: 1.6; }
.qcard-hint { font-size: 0.76rem; color: var(--text-3); }

.check-group { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.check-item {
  display: flex; align-items: center; gap: 0.3rem;
  padding: 0.32rem 0.7rem;
  border: 1.5px solid var(--border); border-radius: 20px;
  cursor: pointer; font-size: 0.82rem; color: var(--text-2);
  transition: all 0.15s;
}
.check-item:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent-dark);
  font-weight: 600;
}
.check-item input { display: none; }

.other-wrap { display: flex; flex-direction: column; gap: 0.35rem; margin-top: 0.1rem; }
.other-input {
  padding: 0.5rem 0.7rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font); font-size: 0.85rem; color: var(--text);
  background: var(--surface);
  transition: border-color 0.2s;
}
.other-input:focus { outline: none; border-color: var(--accent); }

.form-textarea {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font); font-size: 0.86rem; color: var(--text);
  background: var(--surface);
  resize: vertical;
  transition: border-color 0.2s;
}
.form-textarea:focus { outline: none; border-color: var(--accent); }

/* ナビゲーションボタン */
.btn-form {
  padding: 0.6rem 1.4rem;
  border: none; border-radius: var(--radius-sm);
  font-family: var(--font); font-size: 0.9rem; font-weight: 600;
  cursor: pointer; transition: all 0.2s;
}
.btn-next, .btn-submit {
  background: linear-gradient(135deg, #e8436a, #c41e3a);
  color: white;
  box-shadow: 0 2px 8px rgba(196,30,58,0.3);
}
.btn-next:hover, .btn-submit:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(196,30,58,0.4); }
.btn-submit:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.btn-back { background: var(--bg); color: var(--text-2); border: 1px solid var(--border); }
.btn-back:hover { background: var(--border); }

.form-error {
  font-size: 0.82rem; color: var(--accent);
  background: var(--accent-light); border-radius: var(--radius-sm);
  padding: 0.5rem 0.8rem; margin-bottom: 0.5rem;
}

/* 送信完了 */
.form-success {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; gap: 0.8rem; padding: 2rem;
}
.success-icon { font-size: 3rem; }
.form-success h3 { font-size: 1.2rem; font-weight: 700; color: var(--text); }
.form-success p { font-size: 0.9rem; color: var(--text-2); line-height: 1.7; }

/* ===== レスポンシブ ===== */
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 1rem;
  }
  .sidebar-section { margin-bottom: 1rem; }
  .chart-grid { grid-template-columns: 1fr; }
  .analysis-grid { grid-template-columns: 1fr; }
  .dialect-pair { grid-template-columns: 1fr; }
  #map { height: 400px; }
  .site-header { padding: 1rem; }
  .header-text h1 { font-size: 1.1rem; }
  .header-link { display: none; }
  .main-content { padding: 1rem; }
}
