/* コースケ 案内サポート — スマートフォン優先（基準 390px、320px〜デスクトップ対応） */

:root {
  --bg: #fbf8f1;
  --bg-outer: #f1ece0;
  --surface: #ffffff;
  --line: #e4dccb;
  --line-strong: #b9b09c;
  --text: #22302a;
  --muted: #56615a;
  --green: #1f5c3d;
  --green-dark: #17472f;
  --green-tint: #e8f1ea;
  --amber-tint: #fff3d1;
  --amber-text: #6a4b00;
  --amber-line: #e9cf85;
  --gray-tint: #eeebe4;
  --gray-text: #4a4f4b;
  --error: #a3261b;
  --focus: #0b57d0;
  --radius: 14px;
  --tap: 48px;
  --nav-h: 64px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic",
    "Noto Sans JP", Meiryo, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.7;
  overflow-wrap: anywhere;
  line-break: strict;
}

h1,
h2,
h3,
p,
ul,
fieldset,
legend {
  margin: 0;
  padding: 0;
}

fieldset {
  border: 0;
  min-width: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button:disabled {
  cursor: not-allowed;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

h2:focus,
main:focus {
  outline: none;
}

h2:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 4px;
  border-radius: 4px;
}

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

.skip-link {
  position: absolute;
  left: 8px;
  top: -80px;
  z-index: 30;
  padding: 10px 14px;
  background: var(--green);
  color: #fff;
  border-radius: 8px;
  font-weight: 700;
}

.skip-link:focus {
  top: 8px;
}

.noscript {
  margin: 16px;
  padding: 12px;
  border: 2px solid var(--error);
  border-radius: var(--radius);
  background: #fff;
}

/* ---------- レイアウト ---------- */

.shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-size: 1.25rem;
  line-height: 1.4;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--green-dark);
}

main {
  flex: 1 1 auto;
  padding: 16px 16px 28px;
  padding-left: calc(16px + env(safe-area-inset-left, 0px));
  padding-right: calc(16px + env(safe-area-inset-right, 0px));
}

.view > * + * {
  margin-top: 16px;
}

h2 {
  font-size: 1.375rem;
  line-height: 1.4;
  font-weight: 800;
}

h3 {
  font-size: 0.9375rem;
  font-weight: 700;
}

/* ---------- 下部ナビ ---------- */

.bottom-nav {
  position: sticky;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.nav-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--nav-h);
  padding: 6px 4px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 700;
  line-height: 1.3;
}

.nav-btn:focus-visible {
  outline-offset: -4px;
  border-radius: 10px;
}

.nav-btn[aria-current="page"] {
  color: var(--green);
}

.nav-btn[aria-current="page"]::before {
  content: "";
  position: absolute;
  top: 0;
  left: 22%;
  right: 22%;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--green);
}

/* ---------- バッジ ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 9px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.6;
  white-space: nowrap;
}

.badge-warn {
  background: var(--amber-tint);
  border-color: var(--amber-line);
  color: var(--amber-text);
}

.badge-off {
  background: var(--gray-tint);
  border-color: var(--line-strong);
  color: var(--gray-text);
}

.badge-ok {
  background: var(--green-tint);
  border-color: var(--green);
  color: var(--green-dark);
}

/* ---------- カード・注意書き ---------- */

.card {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.card > * + * {
  margin-top: 10px;
}

.card-label {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--muted);
}

.notice {
  padding: 12px 14px;
  background: var(--amber-tint);
  border: 1px solid var(--amber-line);
  border-radius: var(--radius);
  color: var(--amber-text);
  font-size: 0.875rem;
}

.notice-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
  font-weight: 800;
}

.notice-info {
  background: var(--green-tint);
  border-color: var(--green);
  color: var(--green-dark);
  font-weight: 600;
}

.notice-sub {
  margin-top: 4px;
  font-size: 0.8125rem;
  font-weight: 500;
}

.empty {
  text-align: center;
}

.loading-text {
  font-weight: 700;
  color: var(--green-dark);
}

.empty > * + * {
  margin-top: 14px;
}

/* ---------- フォーム ---------- */

form > * + * {
  margin-top: 18px;
}

.field > label,
.field > legend {
  display: block;
  margin-bottom: 6px;
  font-weight: 700;
}

.hint-inline {
  margin-left: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}

.hint {
  margin-top: 6px;
  font-size: 0.8125rem;
  color: var(--muted);
}

.error {
  margin-top: 6px;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--error);
}

.status {
  min-height: 1.6em;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--green-dark);
  text-align: center;
}

.status.is-error {
  color: var(--error);
}

form > .status,
.card > .status {
  margin-top: 8px;
}

input[type="text"],
input[type="date"],
select,
textarea {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  background: var(--surface);
  border: 1.5px solid var(--line-strong);
  border-radius: 12px;
  font-size: 1rem;
  line-height: 1.6;
}

textarea {
  resize: vertical;
}

select {
  cursor: pointer;
  text-overflow: ellipsis;
}

input[type="text"]:focus-visible,
input[type="date"]:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline-offset: 1px;
  border-color: var(--green);
}

input[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--error);
}

.input-suffix {
  display: flex;
  align-items: center;
  gap: 8px;
}

.input-suffix input {
  width: 7em;
  font-size: 1.125rem;
  font-weight: 700;
}

/* 年齢（生年月日／だいたいの年齢）の入力欄 */
.subfield {
  margin-top: 12px;
}

.subfield > label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9375rem;
  font-weight: 700;
}

.input-date {
  max-width: 15em;
  font-size: 1.125rem;
  font-weight: 700;
  text-align: left;
}

.age-preview {
  margin-top: 6px;
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--green-dark);
}

/* ラジオを3分割のボタン風に */
.seg {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.seg-item {
  position: relative;
}

.seg-item input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.seg-item label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: var(--tap);
  padding: 6px 4px;
  background: var(--surface);
  border: 1.5px solid var(--line-strong);
  border-radius: 12px;
  font-size: 0.9375rem;
  font-weight: 700;
  text-align: center;
}

.seg-item input:checked + label {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.seg-item input:checked + label::before {
  content: "✓";
  font-size: 0.875rem;
}

.seg-item input:focus-visible + label {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* 加入中の商品・コース（「加入中」のときだけ表示。商品は複数選択） */
.product-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
}

.product-item {
  min-width: 0;
}

/* 選んだ商品のすぐ下に出るコース・保障額の選択欄 */
.course-fields {
  margin: 6px 0 4px 12px;
  padding: 10px 0 10px 12px;
  border-left: 3px solid var(--green);
}

.course-fields > * + * {
  margin-top: 10px;
}

.course-field > label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--green-dark);
}

.course-fields > .hint {
  margin-top: 8px;
}

.check-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 6px 10px;
  background: var(--surface);
  border: 1.5px solid var(--line-strong);
  border-radius: 12px;
  font-size: 0.9375rem;
  font-weight: 700;
  line-height: 1.4;
  cursor: pointer;
}

.check-item input {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--green);
  cursor: pointer;
}

.check-item:has(input:checked) {
  background: var(--green-tint);
  border-color: var(--green);
  color: var(--green-dark);
}

/* ---------- ボタン ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 10px 18px;
  border: 1.5px solid transparent;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn-primary {
  min-height: 54px;
  background: var(--green);
  color: #fff;
  font-size: 1.0625rem;
}

.btn-primary:hover,
.btn-primary:active {
  background: var(--green-dark);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--green);
  color: var(--green-dark);
}

.btn-secondary:hover,
.btn-secondary:active {
  background: var(--green-tint);
}

.btn-quiet {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--text);
}

.btn-quiet:hover,
.btn-quiet:active {
  background: var(--gray-tint);
}

.btn:disabled {
  background: var(--gray-tint);
  border-color: var(--line-strong);
  border-style: dashed;
  color: var(--gray-text);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ---------- 案内画面 ---------- */

#result-body > * + * {
  margin-top: 14px;
}

.summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  font-size: 0.9375rem;
  font-weight: 700;
}

.summary-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
}

#result-body > .summary-note {
  margin-top: 4px;
  font-size: 0.8125rem;
  color: var(--muted);
}

.status-message {
  font-size: 1.0625rem;
  font-weight: 800;
  line-height: 1.6;
}

.status-message,
.candidate-reason,
.conditional-condition-text,
.conditional-reason,
.script-text p,
.next-text,
.bullet-list li {
  white-space: pre-wrap;
}

.branch-area > * + * {
  margin-top: 10px;
}

.evidence-note {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--muted);
}

.candidate-name {
  font-size: 1.375rem;
  font-weight: 800;
  line-height: 1.45;
  color: var(--green-dark);
}

.candidate-qualifier {
  display: inline-block;
  padding: 3px 10px;
  background: var(--gray-tint);
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--gray-text);
}

.candidate-reason {
  font-size: 0.9375rem;
}

/* 条件に合う場合の候補（主の候補より控えめに。条件を目立たせる） */
.conditional-card {
  margin-top: 16px;
}

.conditional-note {
  font-size: 0.8125rem;
  color: var(--muted);
}

.conditional-list {
  list-style: none;
}

.conditional-item {
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.conditional-item + .conditional-item {
  margin-top: 10px;
}

.conditional-item > * + * {
  margin-top: 6px;
}

.conditional-name {
  font-size: 1.0625rem;
  font-weight: 800;
  line-height: 1.5;
}

.conditional-condition {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  background: var(--amber-tint);
  border: 1px solid var(--amber-line);
  border-radius: 10px;
  color: var(--amber-text);
  font-size: 0.9375rem;
  font-weight: 700;
}

.conditional-tag {
  flex: 0 0 auto;
  padding: 0 8px;
  background: var(--surface);
  border: 1px solid var(--amber-line);
  border-radius: 999px;
  font-size: 0.75rem;
  line-height: 1.8;
}

.conditional-condition-text {
  min-width: 0;
}

.conditional-reason {
  font-size: 0.875rem;
  color: var(--muted);
}

.script-card {
  border-color: var(--green);
  border-width: 1.5px;
}

.script-text {
  padding: 14px;
  background: var(--green-tint);
  border-radius: 12px;
}

.script-text p {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.85;
}

.script-text p + p {
  margin-top: 8px;
}

.branch-label {
  margin-top: 16px;
  font-weight: 700;
}

.seg-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.branch-btn {
  min-height: 52px;
  padding: 6px 4px;
  background: var(--surface);
  border: 1.5px solid var(--line-strong);
  border-radius: 12px;
  font-size: 0.9375rem;
  font-weight: 700;
  line-height: 1.35;
}

.branch-btn[aria-pressed="true"] {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.next-box {
  padding: 12px 14px;
  border-left: 4px solid var(--green);
  background: var(--bg);
  border-radius: 0 12px 12px 0;
}

.next-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
}

.next-text {
  font-size: 1.1875rem;
  font-weight: 700;
  line-height: 1.75;
}

.next-text.next-empty {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--muted);
}

/* 根拠・確認事項 */
.evidence {
  padding: 0;
}

.evidence summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 52px;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}

.evidence summary::-webkit-details-marker {
  display: none;
}

.evidence summary::after {
  content: "";
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  margin-right: 4px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
}

.evidence[open] summary::after {
  transform: rotate(-135deg);
}

.evidence-body {
  margin: 0;
  padding: 0 16px 16px;
  font-size: 0.9375rem;
}

.evidence-body > * + * {
  margin-top: 14px;
}

.evidence-body h3 {
  margin-bottom: 4px;
  color: var(--muted);
}

.evidence-disclaimer {
  padding: 10px 12px;
  background: var(--amber-tint);
  border: 1px solid var(--amber-line);
  border-radius: 10px;
  color: var(--amber-text);
  font-weight: 800;
}

.plain-list {
  list-style: none;
}

.plain-list li + li {
  margin-top: 10px;
}

.bullet-list {
  padding-left: 1.3em;
}

a {
  color: var(--green-dark);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.source-link {
  display: inline-block;
  padding: 10px 0;
}

.source-title {
  display: block;
  font-weight: 700;
}

.source-url,
.source-locator,
.source-date {
  display: block;
  font-size: 0.8125rem;
  color: var(--muted);
}

/* ---------- 質問画面 ---------- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.chip {
  min-height: 44px;
  padding: 8px 16px;
  background: var(--surface);
  border: 1.5px solid var(--green);
  border-radius: 999px;
  color: var(--green-dark);
  font-size: 0.9375rem;
  font-weight: 700;
}

.chip:hover,
.chip:active {
  background: var(--green-tint);
}

.ask-question {
  font-weight: 700;
}

.ask-question,
.ask-answer,
.ask-message {
  white-space: pre-wrap;
}

.ask-answer {
  font-size: 1.0625rem;
  font-weight: 700;
  line-height: 1.75;
}

.ask-message {
  font-size: 0.9375rem;
  color: var(--muted);
}

.ask-result h3 {
  margin-bottom: 4px;
  color: var(--muted);
}

/* ---------- 幅の狭い端末（320px 前後） ---------- */

@media (max-width: 359px) {
  main {
    padding-left: 12px;
    padding-right: 12px;
  }

  .card {
    padding: 14px 12px;
  }

  .seg,
  .seg-buttons {
    gap: 6px;
  }

  .seg-item label,
  .branch-btn,
  .check-item {
    font-size: 0.875rem;
  }

  .check-item {
    padding: 6px 8px;
  }

  .course-fields {
    margin-left: 6px;
    padding-left: 10px;
  }

  .conditional-item {
    padding: 10px;
  }

  .script-text {
    padding: 12px;
  }

  .script-text p {
    font-size: 1.125rem;
  }

  .next-text {
    font-size: 1.0625rem;
  }

  .candidate-name {
    font-size: 1.25rem;
  }
}

/* ---------- デスクトップ ---------- */

@media (min-width: 600px) {
  body {
    background: var(--bg-outer);
  }

  .shell {
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
    box-shadow: 0 0 32px rgba(34, 48, 42, 0.08);
  }

  main {
    padding: 24px 24px 36px;
  }

  .app-header {
    padding-left: 24px;
    padding-right: 24px;
  }
}

/* ---------- 動きを減らす設定 ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- ハイコントラスト（Windows など） ---------- */

@media (forced-colors: active) {
  .seg-item input:checked + label,
  .branch-btn[aria-pressed="true"],
  .check-item:has(input:checked) {
    border: 3px solid Highlight;
  }

  .nav-btn[aria-current="page"]::before {
    background: Highlight;
  }
}
