/* 値は data/theme.json から実行時に上書きする。ここの :root は読み込み前の既定値。 */
:root {
  --bg: #FAFAF7;
  --surface: #FFFFFF;
  --border: #D9DDE3;
  --ink: #1F2933;
  --ink_sub: #52606D;
  --primary: #1F3A5F;
  --check_ink: #8A4B08;
  --check_bg: #FEF3C7;
  --conf_high: #166534;
  --conf_mid: #334E68;
  --conf_low: #9B2C2C;
  --banner_bg: #EEF2F7;
  --banner_ink: #1F2933;
  --danger: #9B2C2C;
  --radius: 8px;
  --space_unit: 8px;
  --font_family: "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  --font_base: 16px;
  --line_height: 1.8;
  --h1_size: 1.875rem;
  --h2_size: 1.5rem;
  --h3_size: 1.25rem;
  --max_width: 960px;
  --print_font_size: 8pt;
  --print_line_height: 1.35;
  --print_h1_size: 13pt;
  --print_h2_size: 10pt;
  --print_small_size: 7pt;
  --print_date_size: 8pt;
  --print_banner_size: 8pt;
  --print_banner_space: 5mm;
  --memo_print_size: 6pt;
  --memo_line_height: 1.15;
  --memo_h1_size: 11pt;
  --memo_h2_size: 8pt;
  --memo_heading_line_height: 1.2;
  --memo_columns: 3;
  --memo_col1: 19%;
  --memo_col2: 12.5%;
  --memo_col3: 19%;
  --memo_col4: 23%;
  --memo_col5: 20.5%;
  --memo_col6: 6%;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
button, input, select, textarea { font: inherit; }

html { font-size: var(--font_base); scroll-padding-top: calc(var(--space_unit) * 12); }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font_family);
  line-height: var(--line_height);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

/* 見出しと段落の標準の余白を打ち消し、間隔は gap でそろえる */
h1, h2, h3, p, ul, ol, dl, dd, fieldset { margin: 0; }
h1 { font-size: var(--h1_size); line-height: 1.4; color: var(--primary); }
h2 { font-size: var(--h2_size); line-height: 1.5; color: var(--primary); }
h3 { font-size: var(--h3_size); line-height: 1.5; }

.page, .main, .block, .home-main, .question-panel, .question-section, .question,
.notices, .global-notices, .deadline, .event, .memo, .site-footer, .item-head, .judgement, .check-box, .check-field {
  display: flex;
  flex-direction: column;
  gap: var(--space_unit);
  min-width: 0;
}

.main {
  width: 100%;
  max-width: var(--max_width);
  margin-inline: auto; /* 本文を中央に置く */
  padding: calc(var(--space_unit) * 3) calc(var(--space_unit) * 2);
  gap: calc(var(--space_unit) * 3);
}

.block { gap: calc(var(--space_unit) * 1.5); }
.block > h2, .stage h2, .card h2 { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space_unit); }

/* 固定帯（一文） */
.banner {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--banner_bg);
  color: var(--banner_ink);
  border-bottom: 1px solid var(--border);
  padding: var(--space_unit) calc(var(--space_unit) * 2);
  text-align: center;
}
.banner-text { font-size: 0.875rem; font-weight: 700; line-height: 1.6; overflow-wrap: anywhere; }

/* 見出し部と画面の移動 */
.site-header {
  width: 100%;
  max-width: var(--max_width);
  margin-inline: auto; /* 中央寄せ */
  padding: var(--space_unit) calc(var(--space_unit) * 2) 0;
}
.app-title { font-weight: 700; font-size: var(--h3_size); text-decoration: none; }
.site-nav ul { display: flex; flex-wrap: wrap; gap: var(--space_unit); list-style: none; padding: 0; }
.nav-link { padding: 0 var(--space_unit); border-bottom: 2px solid transparent; text-decoration: none; }
.nav-link[aria-current="page"] { border-bottom-color: var(--primary); font-weight: 700; }

/* リンク・ボタン・入力（押す範囲は44px四方以上） */
a {
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  min-width: 44px;
}
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: flex-start;
  min-height: 44px;
  min-width: 44px;
  padding: var(--space_unit) calc(var(--space_unit) * 2);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--primary);
  text-decoration: none;
  font-weight: 700;
  cursor: pointer;
}
.button-primary, .button[aria-pressed="true"] { background: var(--primary); color: var(--surface); }
/* 取り消せない操作（回答を消す）は、通常のボタンと色を分ける */
.button-danger { border-color: var(--danger); color: var(--danger); }
summary { min-height: 44px; min-width: 44px; padding: var(--space_unit) 0; cursor: pointer; font-weight: 700; }
a:focus-visible, button:focus-visible, input:focus-visible, summary:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}
.button-primary:focus-visible { outline-offset: 3px; }

input[type="date"] {
  min-height: 44px;
  min-width: 44px;
  max-width: 100%;
  align-self: flex-start;
  padding: var(--space_unit);
  font-size: max(16px, 1rem);
  font-family: var(--font_family);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--ink_sub);
  border-radius: var(--radius);
}
input[type="radio"] { width: 20px; height: 20px; accent-color: var(--primary); flex: none; font-size: max(16px, 1rem); }

/* 文章の要素 */
.lead { font-size: 1rem; }
.sub { color: var(--ink_sub); font-size: 0.875rem; }
.plain-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: var(--space_unit); }
.plain-list > li { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space_unit); }
.strength { font-size: 0.875rem; }
.count { font-size: 1rem; color: var(--ink_sub); }
.date-note { color: var(--ink_sub); font-size: 0.875rem; }

.notice {
  background: var(--banner_bg);
  color: var(--banner_ink);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: calc(var(--space_unit) * 1.5) calc(var(--space_unit) * 2);
}
.notice-warning { background: var(--check_bg); color: var(--check_ink); border-color: var(--check_ink); }
.notices:empty, .global-notices:empty, .invalid-slot:empty { display: none; }

/* 読み込み中（文言を読む前なので、図形だけで示す） */
.loading { display: flex; justify-content: center; padding: calc(var(--space_unit) * 8) var(--space_unit); }
.loading-mark {
  width: calc(var(--space_unit) * 5);
  height: calc(var(--space_unit) * 5);
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: loading-turn 1s linear infinite;
}
@keyframes loading-turn { to { transform: rotate(360deg); } }

/* バッジ（記号と文字） */
.badges { display: flex; flex-wrap: wrap; gap: var(--space_unit); }
.badge {
  display: inline-flex;
  align-items: center;
  gap: calc(var(--space_unit) / 2);
  padding: 0 var(--space_unit);
  border: 1px solid var(--ink_sub);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.875rem;
  font-weight: 700;
}
.badge-conf-high { color: var(--conf_high); border-color: var(--conf_high); }
.badge-conf-mid { color: var(--conf_mid); border-color: var(--conf_mid); }
.badge-conf-low { color: var(--conf_low); border-color: var(--conf_low); }
.badge-check { color: var(--check_ink); background: var(--check_bg); border-color: var(--check_ink); }
.badge-status-pending, .badge-status-undetermined { border-style: dashed; }
.badge-status-not_applicable { color: var(--ink_sub); }
.badge-read { font-weight: 400; }
/* 狭い表の列では、記号（●●○）と文字をそれぞれ途中で折らず、記号の下に文字を回す。印刷では @media print の中で元に戻す */
.badge { flex-wrap: wrap; }
.badge-mark, .badge-label { white-space: nowrap; }

/* 件数サマリー */
.summary-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space_unit); list-style: none; padding: 0; }
.summary-item {
  display: flex;
  gap: var(--space_unit);
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space_unit);
  font-weight: 700;
}
html[data-layout="tablet"] .summary-list, html[data-layout="desktop"] .summary-list { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.legend ul { list-style: none; padding: 0; display: flex; flex-direction: column; gap: var(--space_unit); }
.legend li { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space_unit); }
.sort-switch { display: flex; flex-wrap: wrap; gap: var(--space_unit); }

/* ホーム：幅が広いときだけ、左に状況の入力を並べる */
.home-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: calc(var(--space_unit) * 3); }
.side-panel { display: none; }
html[data-layout="desktop"] .home-layout { grid-template-columns: 30% minmax(0, 1fr); align-items: start; }
html[data-layout="desktop"] .side-panel {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: calc(var(--space_unit) * 2);
}
html[data-layout="desktop"] .home-main .ask-link { display: none; }
.home-main { gap: calc(var(--space_unit) * 2); }
.date-view { display: flex; flex-direction: column; gap: calc(var(--space_unit) * 3); }
.date-view section, .stage section, .reference, .broken { display: flex; flex-direction: column; gap: calc(var(--space_unit) * 1.5); }

/* 段階表示（グループを上から順に並べる） */
.stages { list-style: none; padding: 0; counter-reset: stage; display: flex; flex-direction: column; gap: calc(var(--space_unit) * 3); }
.stage { counter-increment: stage; border-left: 3px solid var(--primary); padding-left: calc(var(--space_unit) * 2); min-width: 0; }
.stage h2::before { content: counter(stage) "."; }
.group-note { font-size: 0.875rem; }

/* カード */
.card-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: calc(var(--space_unit) * 1.5); }
.card {
  display: flex;
  flex-direction: column;
  gap: var(--space_unit);
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: calc(var(--space_unit) * 2);
}
.card-link { align-items: stretch; width: 100%; color: var(--ink); text-decoration: none; }
.card-link:hover { border-color: var(--primary); }
.card-link h3 { color: var(--primary); text-decoration: underline; }
.card-number { color: var(--ink_sub); font-size: 0.875rem; }
.card-line { font-size: 0.875rem; }
.row-title { font-weight: 700; align-self: flex-start; }
.card-broken { border-style: dashed; border-color: var(--check_ink); }

/* 目安日 */
.deadline { gap: calc(var(--space_unit) / 2); }
.deadline-main { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space_unit); font-weight: 700; }
.deadline-date { font-size: var(--h3_size); }
.deadline-unsure { color: var(--ink_sub); }
.deadline-low { color: var(--conf_low); font-size: 0.875rem; font-weight: 700; }
.deadline-past, .deadline-invalid {
  background: var(--check_bg);
  color: var(--check_ink);
  border-radius: var(--radius);
  padding: calc(var(--space_unit) / 2) var(--space_unit);
}

/* 状況の入力 */
.question-section { gap: calc(var(--space_unit) * 2); }
.question { border: 0; padding: 0; }
fieldset.question { display: block; min-width: 0; }
.question legend, .question-label { font-weight: 700; padding: 0; }
.question-label { display: flex; flex-wrap: wrap; gap: var(--space_unit); align-items: center; min-height: 44px; }
.options { display: flex; flex-wrap: wrap; gap: var(--space_unit); }
.option {
  display: inline-flex;
  align-items: center;
  gap: var(--space_unit);
  min-height: 44px;
  min-width: 44px;
  padding: var(--space_unit) calc(var(--space_unit) * 1.5);
  background: var(--surface);
  border: 1px solid var(--ink_sub);
  border-radius: var(--radius);
  cursor: pointer;
}
.invalid-text { color: var(--check_ink); background: var(--check_bg); border-radius: var(--radius); padding: var(--space_unit); }

.check-box { background: var(--surface); border: 1px solid var(--check_ink); border-radius: var(--radius); padding: calc(var(--space_unit) * 2); }
.flow-row { display: flex; flex-direction: column; gap: calc(var(--space_unit) / 2); }
.flow-title { color: var(--ink_sub); font-size: 0.875rem; font-weight: 700; }
.flow-arrow { color: var(--ink_sub); }

/* 表（役割分担表・相談メモ） */
table { width: 100%; border-collapse: collapse; background: var(--surface); table-layout: fixed; }
th, td { border: 1px solid var(--border); padding: var(--space_unit); text-align: left; vertical-align: top; font-size: 0.875rem; }
html[data-layout="mobile"] table,
html[data-layout="mobile"] tbody,
html[data-layout="mobile"] tr,
html[data-layout="mobile"] th,
html[data-layout="mobile"] td { display: block; width: 100%; }
html[data-layout="mobile"] thead { display: none; }
html[data-layout="mobile"] table { background: transparent; }
html[data-layout="mobile"] tr {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space_unit);
  margin: 0 0 calc(var(--space_unit) * 2); /* 縦に積んだカードの間隔 */
}
html[data-layout="mobile"] th, html[data-layout="mobile"] td { border: 0; }
html[data-layout="mobile"] th::before,
html[data-layout="mobile"] td::before { content: attr(data-label); display: block; color: var(--ink_sub); font-size: 0.875rem; font-weight: 700; }

.memo-answers { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space_unit); }
.memo-answer { border-bottom: 1px solid var(--border); }
.memo-answers dt { font-size: 0.875rem; color: var(--ink_sub); }
html[data-layout="tablet"] .memo-answers, html[data-layout="desktop"] .memo-answers { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.site-footer {
  width: 100%;
  max-width: var(--max_width);
  margin-inline: auto; /* 中央寄せ */
  padding: calc(var(--space_unit) * 3) calc(var(--space_unit) * 2);
  border-top: 1px solid var(--border);
  color: var(--ink_sub);
  font-size: 0.875rem;
}
.print-tail { display: none; }

/* 印刷（相談メモはA4縦1ページを想定）。白黒でも記号と文字で区別できる。 */
@media print {
  /* 寸法は data/theme.json の print から実行時に上書きする。@page の余白は読み込み前の既定値。 */
  @page { size: A4 portrait; margin: 10mm; }
  /* 画面用の高さ100%を外す。本文の後ろに空きが残ると、白紙のページが足される */
  html, body { min-height: 0; }
  html { font-size: var(--print_font_size); }
  body { background: var(--surface); line-height: var(--print_line_height); }
  .site-header, .site-footer, .button, button, .ask-link, .nav-link { display: none; }
  /* 画面の幅の区分の指定より後ろで、同じかそれ以上の詳細度にして上書きする */
  html[data-layout] .side-panel { display: none; }
  html[data-layout] .home-layout { grid-template-columns: minmax(0, 1fr); }
  .banner, .print-tail {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    background: var(--surface);
    text-align: center;
    padding: 0;
  }
  .banner { top: 0; }
  .print-tail { bottom: 0; border-top: 1px solid var(--ink); font-weight: 700; }
  .banner-text, .print-tail p { font-size: var(--print_banner_size); }
  /* 固定の一文は各ページの上下に重ねて出るので、同じ高さの空きの行を各ページで繰り返して本文を避ける */
  .page { display: table; width: 100%; table-layout: fixed; }
  .page::before, .page::after { content: "\00a0"; line-height: var(--print_banner_space); break-inside: avoid; }
  .page::before { display: table-header-group; }
  .page::after { display: table-footer-group; }
  .main { max-width: none; padding: 0; gap: var(--space_unit); }
  .block, .memo { gap: calc(var(--space_unit) / 2); }
  h1 { font-size: var(--print_h1_size); }
  h2 { font-size: var(--print_h2_size); }
  a { display: inline; min-height: 0; min-width: 0; color: var(--ink); text-decoration: none; }
  .badge { border-color: var(--ink); padding: 0 2px; font-size: var(--print_small_size); }
  /* 画面用の「記号と文字を折らない」を外し、印刷は従来どおりバッジ側の指定に従わせる */
  .badge { flex-wrap: nowrap; }
  .badge-mark, .badge-label { white-space: inherit; }
  .plain-list, .badges { gap: 0; }
  .date-note, .sub, th, td { font-size: var(--print_small_size); }
  .deadline-date { font-size: var(--print_date_size); }
  html[data-layout] table { display: table; }
  html[data-layout] thead { display: table-header-group; }
  html[data-layout] tbody { display: table-row-group; }
  html[data-layout] tr { display: table-row; margin: 0; padding: 0; break-inside: avoid; }
  html[data-layout] th, html[data-layout] td { display: table-cell; width: auto; padding: 1px 2px; border: 1px solid var(--ink); }
  html[data-layout] th::before, html[data-layout] td::before { content: none; }

  /* ここから相談メモ（S9）だけの指定。全30項目が該当しても A4縦1ページに収める。 */
  @page memo { size: A4 portrait; margin: 7mm; }
  /* 相談メモの表示中は文書全体を memo の用紙にする。外枠だけに付けると、外枠の外に残った物が
     ふつうの用紙（余白10mm）の白紙ページとして足される */
  html:has(.page[data-screen="S9"]) { page: memo; }
  /* 本文の文字（--memo_print_size）を大きくすると2ページになる */
  .page[data-screen="S9"] {
    page: memo;
    font-size: var(--memo_print_size);
    line-height: var(--memo_line_height);
  }
  [data-screen="S9"] .main { gap: 0; }
  [data-screen="S9"] .memo, [data-screen="S9"] .block { gap: 1px; }
  [data-screen="S9"] h1 { font-size: var(--memo_h1_size); line-height: var(--memo_heading_line_height); }
  [data-screen="S9"] h2 { font-size: var(--memo_h2_size); line-height: var(--memo_heading_line_height); }
  [data-screen="S9"] :is(.date-note, .sub, th, td, .memo-answers dt, .badge, .deadline-date) { font-size: var(--memo_print_size); }
  /* 回答は3段に流し、質問と回答を同じ行に続ける */
  html[data-layout] [data-screen="S9"] .memo-answers { display: block; columns: var(--memo_columns); column-gap: var(--space_unit); }
  [data-screen="S9"] .memo-answer { break-inside: avoid; }
  [data-screen="S9"] .memo-answers :is(dt, dd) { display: inline; }
  [data-screen="S9"] .memo-answers dd { font-weight: 700; padding-inline-start: 3pt; }
  /* バッジは枠と地の色を外して文中に置く（行が詰まると、隣の行の文字や罫線に重なる）。記号と文字で区別する */
  [data-screen="S9"] .badge { display: inline; border: 0; background: transparent; padding: 0; padding-inline-start: 2pt; font-weight: 400; white-space: nowrap; }
  [data-screen="S9"] .badge-mark { padding-inline-end: 1px; }
  [data-screen="S9"] .badge-check { font-weight: 700; white-space: normal; } /* 列が足りないときは折り返す */
  [data-screen="S9"] .deadline { gap: 0; }
  [data-screen="S9"] .deadline-main { display: block; }
  [data-screen="S9"] .deadline-main > span { padding-inline-end: 2pt; }
  [data-screen="S9"] :is(.deadline-past, .deadline-invalid) { padding: 0; }
  [data-screen="S9"] .memo-names { columns: var(--memo_columns); }
  html[data-layout] [data-screen="S9"] :is(th, td) { padding: 0 1.5px; }
  /* 相談メモの表の列幅 */
  [data-screen="S9"] .memo-table th:nth-child(1) { width: var(--memo_col1); }
  [data-screen="S9"] .memo-table th:nth-child(2) { width: var(--memo_col2); }
  [data-screen="S9"] .memo-table th:nth-child(3) { width: var(--memo_col3); }
  [data-screen="S9"] .memo-table th:nth-child(4) { width: var(--memo_col4); }
  [data-screen="S9"] .memo-table th:nth-child(5) { width: var(--memo_col5); }
  [data-screen="S9"] .memo-table th:nth-child(6) { width: var(--memo_col6); }
  /* 出典は、名前と読んだ範囲のバッジを同じ行に続ける */
  .memo-table .plain-list > li { display: inline; }
}
