:root {
  --bg-primary: #ffffff;
  --bg-secondary: #F5F4ED;
  --bg-tertiary: #FAFAF7;
  --bg-info: #E6F1FB;
  --bg-success: #EAF3DE;
  --bg-warning: #FAEEDA;
  --bg-danger: #FCEBEB;
  --bg-important: #FAF0E1;
  --bg-accent: #185FA5;
  --text-primary: #1F1E1B;
  --text-secondary: #6B6962;
  --text-tertiary: #9A988F;
  --text-info: #185FA5;
  --text-success: #27500A;
  --text-warning: #854F0B;
  --text-danger: #791F1F;
  --text-important: #854F0B;
  --border-tertiary: rgba(0, 0, 0, 0.08);
  --border-secondary: rgba(0, 0, 0, 0.18);
  --border-info: #185FA5;
  --border-important: #BA7517;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
  --transition-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --transition-smooth: cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  color: var(--text-primary);
  background: var(--bg-tertiary);
  font-size: 16px;
  line-height: 1.7;
  overscroll-behavior: none;
}

/* Loading */
.loader {
  position: fixed; inset: 0;
  background: var(--bg-tertiary);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  transition: opacity 0.4s var(--transition-smooth);
}
.loader.hidden { opacity: 0; pointer-events: none; }
.loader-msg { font-size: 14px; color: var(--text-secondary); }
.loader-msg::after {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  margin-left: 6px;
  background: var(--text-info);
  border-radius: 50%;
  animation: dot-pulse 1.2s infinite;
}
@keyframes dot-pulse { 0%,100% { opacity: 0.3; transform: scale(0.8); } 50% { opacity: 1; transform: scale(1.2); } }

/* Layout */
.container {
  width: 100%;            /* flex(body)内でコンテンツ幅依存になり設問ごとに列幅が変動するのを防ぐ
                            (max-width + margin:auto と併せた標準の中央寄せコンテナ。全設問で幅・位置を一定に) */
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* === Top bar === */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg-tertiary);
  padding: 12px 20px 8px;
}
.topbar-inner {
  background: var(--bg-primary);
  border: 0.5px solid var(--border-tertiary);
  border-radius: var(--radius-xl);
  padding: 10px 16px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: var(--shadow-sm);
}
.progress-bar {
  flex: 1;
  height: 8px;
  background: var(--bg-secondary);
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--bg-accent), #4A8FD4);
  border-radius: 4px;
  transition: width 0.5s var(--transition-spring);
  width: 0%;
}
.progress-num {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  min-width: 60px;
  text-align: right;
}
.progress-num strong { color: var(--text-primary); font-weight: 600; }

/* === Main area === */
.main {
  flex: 1;
  padding: 16px 20px 120px;
  overflow-x: hidden;
}

/* === Step view === */
.step-wrap {
  position: relative;
  min-height: 60vh;
}
.step-wrap.transitioning { pointer-events: none; }
.step {
  background: var(--bg-primary);
  border: 0.5px solid var(--border-tertiary);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  box-shadow: var(--shadow-sm);
  animation: step-in 0.4s var(--transition-smooth) both;
}
@keyframes step-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.step.leaving { animation: step-out 0.25s var(--transition-smooth) both; }
@keyframes step-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(-20px); }
}

/* Welcome */
.welcome { text-align: center; padding: 40px 24px; }
.welcome h1 {
  font-size: 22px;
  font-weight: 500;
  margin: 0 0 12px;
  line-height: 1.4;
}
.welcome .meta { font-size: 12px; color: var(--text-tertiary); margin-bottom: 24px; }
.welcome .intro {
  text-align: left;
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.8;
  margin-bottom: 24px;
  background: var(--bg-secondary);
  padding: 18px 20px;
  border-radius: var(--radius-md);
}
.welcome .intro p { margin: 0 0 10px; }
.welcome .intro p:last-child { margin: 0; }
.welcome .stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 24px;
}
.welcome .stat {
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 12px 8px;
}
.welcome .stat .label { font-size: 11px; color: var(--text-tertiary); margin-bottom: 4px; }
.welcome .stat .value { font-size: 18px; font-weight: 500; color: var(--text-primary); }

.privacy-notice {
  text-align: left;
  font-size: 11px;
  color: var(--text-tertiary);
  line-height: 1.7;
  margin-top: 24px;
  padding: 14px 16px;
  border: 0.5px dashed var(--border-tertiary);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
}
.privacy-notice strong { color: var(--text-secondary); font-weight: 500; }

/* Category indicator */
.category-indicator {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 20px;
  font-size: 12px;
  color: var(--text-tertiary);
}
.category-indicator .cat-icon {
  background: var(--bg-secondary);
  color: var(--bg-accent);
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.category-indicator .cat-icon svg { width: 20px; height: 20px; }

/* SVG line icon 基底 + 完了画面チェックサークル(従来の完了絵文字の置換) */
.icon { display: inline-block; vertical-align: middle; flex-shrink: 0; }
.completion-icon { margin: 12px 0 8px; color: var(--bg-accent); line-height: 0; }
.completion-icon .completion-svg { width: 72px; height: 72px; stroke-width: 1.4; }
.category-indicator .cat-name { flex: 1; font-weight: 500; color: var(--text-secondary); }
.category-indicator .cat-num { font-variant-numeric: tabular-nums; }

/* Question */
.q-num {
  font-size: 11px;
  color: var(--text-tertiary);
  font-weight: 500;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}
.q-label {
  font-size: 18px;
  font-weight: 500;
  line-height: 1.6;
  margin: 0 0 8px;
}
.q-label .important-mark {
  display: inline-block;
  padding: 2px 8px;
  background: var(--bg-important);
  color: var(--text-important);
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 500;
  border: 0.5px solid var(--border-important);
  margin-left: 8px;
  vertical-align: middle;
}
.q-hint { font-size: 13px; color: var(--text-tertiary); margin-bottom: 20px; line-height: 1.6; }

/* Inputs */
.input-area { margin-top: 24px; }
input[type="text"], textarea {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 16px;
  color: var(--text-primary);
  background: var(--bg-primary);
  transition: all 0.2s var(--transition-smooth);
  -webkit-appearance: none;
}
input[type="text"]:focus, textarea:focus {
  outline: none;
  border-color: var(--border-info);
  box-shadow: 0 0 0 3px rgba(24, 95, 165, 0.12);
}
textarea { resize: vertical; min-height: 100px; line-height: 1.7; }

/* 文字数カウンタ (maxlength 指定の text/textarea) */
.char-counter {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-tertiary);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.char-counter.cc-warn { color: var(--text-danger, #c0392b); font-weight: 600; }

/* Choice cards */
.choices { display: flex; flex-direction: column; gap: 10px; }
.choice {
  background: var(--bg-primary);
  border: 1.5px solid var(--border-secondary);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  font-size: 16px;
  cursor: pointer;
  user-select: none;
  transition: all 0.2s var(--transition-smooth);
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  text-align: left;
  width: 100%;
  color: var(--text-primary);
  font-family: inherit;
}
.choice:hover { background: var(--bg-secondary); border-color: var(--border-info); }
.choice:active { transform: scale(0.98); }
.choice:disabled { cursor: default; opacity: 0.85; }
.choice .check-icon {
  width: 24px; height: 24px;
  border: 2px solid var(--border-secondary);
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.25s var(--transition-spring);
}
.choice.checkbox-style .check-icon { border-radius: 6px; }
.choice .check-icon::after {
  content: '✓';
  color: white;
  font-size: 14px;
  font-weight: 700;
  opacity: 0;
  transform: scale(0.5);
  transition: all 0.25s var(--transition-spring);
}
.choice.selected {
  background: var(--bg-info);
  border-color: var(--border-info);
  color: var(--text-info);
  font-weight: 500;
}
.choice.selected .check-icon {
  background: var(--border-info);
  border-color: var(--border-info);
}
.choice.selected .check-icon::after { opacity: 1; transform: scale(1); }
.choice.just-selected { animation: bounce 0.4s var(--transition-spring); }
@keyframes bounce {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

/* Pair input */
.pair-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pair-row .pair-field { display: flex; flex-direction: column; gap: 6px; }
.pair-row .pair-label { font-size: 12px; color: var(--text-secondary); font-weight: 500; }

/* Followup */
.followup {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  transition: all 0.3s var(--transition-smooth);
}
.followup.hidden { display: none; }
.followup-label { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.followup textarea { background: var(--bg-primary); min-height: 60px; font-size: 14px; }

/* === Bottom Nav === */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(250, 250, 247, 0.95);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-top: 0.5px solid var(--border-tertiary);
  padding: 14px 20px max(14px, env(safe-area-inset-bottom));
  z-index: 20;
}
.bottom-nav-inner {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
/* 上段: 補助操作(戻る/リセット)。両端寄せ。両方非表示でも高さを確保し主ボタンを動かさない */
.nav-secondary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 22px;
}
/* 補助操作は控えめなテキストリンク調。主ボタン(次へ)と視覚的に区別し、段も分けて誤タップを防ぐ */
.nav-link {
  background: none;
  border: none;
  padding: 4px 6px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 400;
  color: var(--text-tertiary);
  cursor: pointer;
}
.nav-link:hover { color: var(--text-secondary); text-decoration: underline; }
.nav-link:active { transform: scale(0.97); }
/* 主操作(次へ/送信)は常に全幅。全設問・全デバイス・確認画面で位置と幅を統一 */
.btn-block { width: 100%; }

.btn {
  padding: 14px 16px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s var(--transition-smooth);
  border: 1px solid var(--border-secondary);
  min-height: 50px;
}
.btn:hover { background: var(--bg-secondary); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary {
  background: var(--bg-accent);
  color: white;
  border-color: var(--bg-accent);
}
.btn-primary:hover { background: #0F4A85; }
.btn-primary:disabled { background: var(--bg-accent); opacity: 0.4; }
/* 旧 .btn-skip / .btn-icon は廃止(ナビ補助操作は .nav-link / .nav-secondary に統合) */

/* Save status */
.save-indicator {
  position: fixed;
  top: 70px; right: 20px;
  background: var(--bg-success);
  color: var(--text-success);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 11px;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  z-index: 5;
}
.save-indicator.visible { opacity: 1; }
.save-indicator.error {
  background: var(--bg-warning);
  color: var(--text-warning);
}

/* Final / Summary */
.summary {
  background: var(--bg-primary);
  border: 0.5px solid var(--border-tertiary);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
}
.summary h2 { font-size: 20px; font-weight: 500; margin: 0 0 8px; }
.summary .summary-meta { font-size: 13px; color: var(--text-secondary); margin-bottom: 24px; }
.summary .cat-summary {
  margin-bottom: 16px;
  padding: 14px 16px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
}
.summary .cat-summary-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 500;
}
.summary .cat-summary-header > span:first-child { display: inline-flex; align-items: center; gap: 6px; }
.summary .cat-summary-header .cat-icon { display: inline-flex; color: var(--bg-accent); }
.summary .cat-summary-header .cat-icon svg { width: 16px; height: 16px; }
.summary .cat-summary-header .cat-progress {
  font-size: 11px;
  color: var(--text-tertiary);
  background: var(--bg-primary);
  padding: 2px 8px;
  border-radius: 10px;
}
.summary .cat-items { font-size: 13px; color: var(--text-secondary); line-height: 1.8; }
.summary .cat-item { margin-bottom: 10px; }
.summary .cat-item-q { display: block; color: var(--text-secondary); font-size: 12px; }
.summary .cat-item-a { display: block; color: var(--text-primary); margin-left: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.summary .cat-item-empty { display: block; color: var(--text-tertiary); font-style: italic; }

.summary-actions {
  display: flex; flex-direction: column; gap: 10px;
  margin-top: 24px;
}
.summary-actions .btn { padding: 16px; font-size: 15px; }

/* Confetti */
.confetti-container {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 200;
  overflow: hidden;
}
.confetti {
  position: absolute;
  width: 8px; height: 8px;
  border-radius: 2px;
  animation: confetti-fall 2.5s linear forwards;
}
@keyframes confetti-fall {
  0% { transform: translateY(-20px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: none;
  align-items: center; justify-content: center;
  z-index: 50; padding: 20px;
  animation: fade-in 0.2s ease-out;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  max-width: 480px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  animation: modal-in 0.3s var(--transition-spring);
}
@keyframes modal-in { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }
.modal h2 { margin: 0 0 12px; font-size: 18px; font-weight: 500; }
.modal pre {
  background: var(--bg-secondary);
  padding: 14px;
  border-radius: var(--radius-md);
  font-size: 11px;
  line-height: 1.5;
  overflow: auto;
  max-height: 350px;
}
/* 確認モーダルの整形表示 (設問文：回答) */
.review {
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 4px 16px;
  max-height: 360px;
  overflow-y: auto;
}
.review-cat { padding: 12px 0; border-bottom: 1px solid var(--border-tertiary); }
.review-cat:last-child { border-bottom: none; }
.review-cat-title { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; }
.review-cat-title .cat-icon { display: inline-flex; color: var(--bg-accent); }
.review-cat-title .cat-icon svg { width: 14px; height: 14px; }
.review-row { display: flex; flex-direction: column; gap: 2px; padding: 6px 0; }
.review-q { font-size: 12px; color: var(--text-secondary); }
.review-a { font-size: 14px; color: var(--text-primary); white-space: pre-wrap; word-break: break-word; }
.review-empty { padding: 20px; text-align: center; color: var(--text-secondary); font-size: 13px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: flex-end; }

/* Footer */
footer {
  text-align: center;
  font-size: 11px;
  color: var(--text-tertiary);
  padding: 20px;
  margin-bottom: 80px;
}

/* Already-submitted badge */
.banner {
  background: var(--bg-success);
  color: var(--text-success);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 13px;
  text-align: center;
}

/* === v2: paged layout, conditional blocks, headings, required, scale, errors === */

/* Page description (paged layout) */
.cat-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin: -8px 0 20px;
  line-height: 1.6;
}

/* Question block — one per item. In paged layout multiple blocks share a screen. */
.q-block { position: relative; }
.step.paged .q-block + .q-block {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 0.5px solid var(--border-tertiary);
}
.q-block.has-error .q-label { color: var(--text-danger); }

/* In paged layout the per-question id is a subtle chip */
.q-id-chip {
  display: inline-block;
  font-size: 10px;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  background: var(--bg-secondary);
  padding: 1px 7px;
  border-radius: 10px;
  margin-bottom: 6px;
}

/* Required / optional badges */
.required-mark, .optional-mark {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 500;
  margin-left: 8px;
  vertical-align: middle;
}
.required-mark { background: var(--bg-danger); color: var(--text-danger); border: 0.5px solid rgba(121,31,31,0.25); }
.optional-mark { background: var(--bg-secondary); color: var(--text-tertiary); border: 0.5px solid var(--border-tertiary); }

/* Heading-only block (section intro) */
.heading-block .q-heading {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary);
  line-height: 1.7;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
}

/* Inline validation error */
.q-error {
  display: none;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-danger);
  background: var(--bg-danger);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}
.q-error.visible { display: block; animation: step-in 0.25s var(--transition-smooth) both; }

/* Scale (NPS 0–10)
   先方要望: スマホで選択肢が折り返してボタンサイズが変わるのを解消。
   方針 = 常に「単一行・全ボタン等幅・折り返し無し」。
   - flex-wrap:nowrap で改行を構造的に禁止(= サイズ変化が起きない)
   - flex:1 1 0 + min-width:0 で全ボタンを等しい幅に按分し、狭い画面では
     全ボタンが等しく縮む(一部だけ伸びる現象を排除)。PC/SP どちらも横一列。 */
.scale-wrap { margin-top: 10px; }
.scale {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
}
.scale-btn {
  flex: 1 1 0;
  min-width: 0;
  min-height: 48px;
  padding: 0 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid var(--border-secondary);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 16px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.2s var(--transition-smooth), border-color 0.2s var(--transition-smooth), color 0.2s var(--transition-smooth), transform 0.1s var(--transition-smooth);
}
.scale-btn:hover { background: var(--bg-secondary); border-color: var(--border-info); }
.scale-btn:active { transform: scale(0.95); }
.scale-btn:disabled { cursor: default; opacity: 0.85; }
.scale-btn.selected {
  background: var(--bg-accent);
  border-color: var(--bg-accent);
  color: #fff;
}
.scale-labels {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 8px;
}
.scale-labels span:last-child { text-align: right; }

/* Mobile */
@media (max-width: 600px) {
  .container { padding: 0; }
  .topbar { padding: 8px 12px; }
  .main { padding: 12px 12px 116px; }
  .step { padding: 24px 18px; }
  .welcome { padding: 24px 16px; }
  .welcome h1 { font-size: 20px; }
  .q-label { font-size: 17px; }
  .choice { padding: 14px 16px; font-size: 15px; min-height: 52px; }
  .nav-link { font-size: 12px; padding: 4px; }
  .btn { padding: 12px 14px; font-size: 14px; min-height: 48px; }
  /* スマホ: 11ボタンを1行に収めるため間隔/文字を詰める(等幅・nowrap は維持) */
  .scale { gap: 4px; }
  .scale-btn { min-height: 46px; font-size: 14px; padding: 0 1px; }
  .scale-labels { font-size: 11px; }
}

/* 極小幅(iPhone SE 等 ≤360px): さらに詰めて 1 行を死守 */
@media (max-width: 360px) {
  .scale { gap: 3px; }
  .scale-btn { min-height: 44px; font-size: 13px; }
}
