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

html { font-size: var(--theme-font-base); }

body {
  background: var(--theme-bg);
  color: var(--theme-ink);
  font-family: var(--theme-font-family);
  line-height: var(--theme-line-height);
  overflow-wrap: anywhere;
}

#app { display: flex; flex-direction: column; min-height: 100vh; }
[hidden] { display: none !important; }

h1 { font-size: var(--theme-font-h1); }
h2 { font-size: var(--theme-font-h2); }
h3 { font-size: var(--theme-font-h3); }
/* 見出し・段落・リストの余白は文書の流れの余白として margin で扱う */
h1, h2, h3 { color: var(--theme-primary); line-height: 1.4; margin: var(--space-3) 0 var(--space-1); }
p, ul, ol, dl { margin: var(--space-1) 0; }
ul, ol { padding-left: var(--space-3); }
dd { margin: 0 0 var(--space-1); }
dt { color: var(--theme-ink-sub); font-size: 0.875rem; }

a { color: var(--theme-primary); }
a:focus-visible, button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--theme-primary);
  outline-offset: 2px;
}
/* 画面の移動後に本文へ移すフォーカスは、全体を枠で囲まず、見出しの下線で示す */
.screen:focus, .screen:focus-visible { outline: none; }
.screen:focus-visible > h1, .screen-memo:focus-visible h1 { text-decoration: underline; text-underline-offset: var(--space-1); }

.boot { padding: var(--space-3); }

/* 固定帯：スクロールしても残る */
.banner {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--theme-banner-bg);
  color: var(--theme-banner-ink);
  border-bottom: 1px solid var(--theme-surface-border);
  padding: var(--space-1) var(--space-2);
  font-size: 0.875rem;
  line-height: 1.5;
  text-align: center;
}
.banner p { margin: 0; }
.banner { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 0 var(--space-2); }
.banner .connection-status { border: 1px solid currentColor; border-radius: var(--theme-radius); padding: 0 var(--space-1); font-weight: bold; white-space: nowrap; }

.site-nav { padding: var(--space-1) var(--space-2); }
.site-nav ul {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-1);
  list-style: none;
  margin: 0 auto;
  max-width: var(--theme-max-width);
  padding: 0;
}
.site-nav a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap-size);
  min-width: var(--tap-size);
  background: var(--theme-surface);
  border: 1px solid var(--theme-ink-sub);
  border-radius: var(--theme-radius);
  font-size: 0.875rem;
  text-align: center;
  text-decoration: none;
}
.site-nav a[aria-current="page"] {
  background: var(--theme-primary);
  border-color: var(--theme-primary);
  color: var(--theme-surface);
  font-weight: bold;
  text-decoration: underline;
}

.screen, .site-footer {
  width: 100%;
  max-width: var(--theme-max-width);
  margin-inline: auto;
  padding: 0 var(--space-2) var(--space-3);
}
.screen { flex: 1 0 auto; }
.site-footer {
  border-top: 1px solid var(--theme-surface-border);
  padding-top: var(--space-2);
  font-size: 0.875rem;
  color: var(--theme-ink-sub);
}

/* 押す範囲は 44px 四方以上 */
.button-primary, .button-link, .button-danger, .toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap-size);
  min-width: var(--tap-size);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--theme-radius);
  border: 1px solid var(--theme-primary);
  background: var(--theme-surface);
  color: var(--theme-primary);
  cursor: pointer;
  text-decoration: none;
}
.button-primary { background: var(--theme-primary); color: var(--theme-surface); }
.button-danger { border: 2px solid var(--theme-conf-low); color: var(--theme-conf-low); }
.toggle[aria-pressed="true"] {
  background: var(--theme-primary);
  color: var(--theme-surface);
  font-weight: bold;
  text-decoration: underline;
}
.view-toggle { display: flex; flex-wrap: wrap; gap: var(--space-1); }

summary {
  min-height: var(--tap-size);
  padding: var(--space-1) 0;
  cursor: pointer;
  color: var(--theme-primary);
}

.item-ref, .ext-link, .card-title a {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 var(--space-1);
  min-height: var(--tap-size);
  min-width: var(--tap-size);
}
span.item-ref { color: var(--theme-ink); }

.unread {
  display: inline-block;
  border: 1px solid var(--theme-ink-sub);
  border-radius: var(--theme-radius);
  color: var(--theme-ink-sub);
  font-size: 0.75rem;
  line-height: 1.5;
  padding: 0 var(--space-1);
}
.url-text { display: block; color: var(--theme-ink-sub); font-size: 0.75rem; }
.link-list li { margin-bottom: var(--space-1); }

/* バッジ：文字と記号で区別し、色は補助にする */
.badges { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1); }
.badge {
  display: inline-block;
  border: 1px solid currentColor;
  border-radius: var(--theme-radius);
  padding: 0 var(--space-1);
  font-size: 0.875rem;
  line-height: 1.6;
}
.conf-high { color: var(--theme-conf-high); background: var(--theme-surface); }
.conf-mid { color: var(--theme-conf-mid); background: var(--theme-surface); }
.conf-low { color: var(--theme-conf-low); background: var(--theme-surface); }
.conf-unknown { color: var(--theme-ink-sub); }
.badge-check { color: var(--theme-check-ink); background: var(--theme-check-bg); border-width: 2px; }
.badge-local { color: var(--theme-ink); background: var(--theme-surface); border-style: dashed; }
.status-applies { color: var(--theme-status-applies-ink); background: var(--theme-status-applies-bg); }
.status-optional { color: var(--theme-status-optional-ink); background: var(--theme-status-optional-bg); }
.status-pending { color: var(--theme-status-pending-ink); background: var(--theme-status-pending-bg); }
.status-undetermined { color: var(--theme-status-undetermined-ink); background: var(--theme-status-undetermined-bg); }
.status-not_applicable { color: var(--theme-status-not-applicable-ink); background: var(--theme-status-not-applicable-bg); }

.card, .legend details {
  background: var(--theme-surface);
  border: 1px solid var(--theme-surface-border);
  border-radius: var(--theme-radius);
  padding: var(--space-2);
}
.panel {
  background: var(--theme-surface);
  border: 1px solid var(--theme-surface-border);
  border-radius: var(--theme-radius);
  padding: var(--space-2);
}
.card-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-2); }
.card-title { margin-top: 0; }
.card-no { font-size: 0.875rem; color: var(--theme-ink-sub); }
.retrieved { color: var(--theme-ink-sub); font-size: 0.875rem; }
.legend h2 { font-size: 1rem; }

/* ホームの画面の案内：名前と用途を1行ずつ並べる */
.screen-guide { margin: var(--space-2) 0; }
.screen-guide h2 { font-size: 1rem; margin-top: 0; }
.screen-guide dl { margin-bottom: 0; }
.screen-guide-row { display: grid; grid-template-columns: 7em minmax(0, 1fr); column-gap: var(--space-1); }
.screen-guide dt { color: var(--theme-primary); font-weight: bold; }
.screen-guide dd { margin: 0 0 var(--space-1); font-size: 0.875rem; }

.summary-list { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-3); list-style: none; padding: 0; }

.target-date { margin: var(--space-1) 0; }
.target-date-value { display: inline-block; font-size: var(--theme-font-h3); white-space: nowrap; }
.target-date.is-large .target-date-value { font-size: var(--theme-font-h2); }
.target-date.is-check { color: var(--theme-ink-sub); }
.date-note-past, .date-note-weekend, .input-warning, .notice {
  color: var(--theme-check-ink);
  background: var(--theme-check-bg);
  border-left: 8px solid var(--theme-check-ink);
  padding: var(--space-1) var(--space-2);
}
.notice a.button-primary { color: var(--theme-surface); }
.date-rule, .status-hint, .date-missing { color: var(--theme-ink-sub); font-size: 0.875rem; }
.error-box {
  border: 2px solid var(--theme-conf-low);
  border-radius: var(--theme-radius);
  padding: var(--space-2);
}

.question { display: block; border: 0; margin: 0 0 var(--space-2); padding: 0; min-width: 0; }
.question legend, .question > label:not(.choice) { display: block; padding: 0; font-weight: bold; }
.choice { display: flex; align-items: center; gap: var(--space-1); min-height: var(--tap-size); cursor: pointer; }
.choice input { flex: none; width: var(--space-3); height: var(--space-3); accent-color: var(--theme-primary); }
input[type="date"] {
  width: 100%;
  max-width: 16rem;
  min-height: var(--tap-size);
  padding: var(--space-1);
  border: 1px solid var(--theme-ink-sub);
  border-radius: var(--theme-radius);
  background: var(--theme-surface);
  color: var(--theme-ink);
}

/* 一列が基本。左右2カラムは、画面幅が theme.json の desktop_min 以上の時だけ */
.split { display: flex; flex-direction: column; gap: var(--space-2); }
.split-home .side { display: none; }
[data-layout="desktop"] .screen-home,
[data-layout="desktop"] .screen-situation { max-width: calc(var(--theme-max-width) + var(--space-4) * 8); }
[data-layout="desktop"] .split { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 7fr); align-items: start; }
[data-layout="desktop"] .side {
  display: block;
  grid-column: 1;
  grid-row: 1;
  position: sticky;
  top: calc(var(--space-4) * 2);
  max-height: calc(100vh - var(--space-4) * 3);
  overflow-y: auto;
}
[data-layout="desktop"] .content { grid-column: 2; grid-row: 1; }
[data-layout="desktop"] .home-quick { display: none; }
[data-layout="desktop"] .site-nav ul { grid-template-columns: repeat(8, minmax(0, 1fr)); }

.deadline-list, .flow-list, .memo-list { list-style: none; padding: 0; }
.deadline-row, .flow-row, .memo-item { border-bottom: 1px solid var(--theme-surface-border); padding: var(--space-1) 0; }
.row-title { margin: 0; }
.strength { font-weight: bold; font-size: 0.875rem; }
.relation-note { display: block; font-size: 0.875rem; color: var(--theme-ink-sub); }
/* 順序どおりに読むと誤解になる関係の補足。文字で示し、左の線は目印 */
.relation-caution {
  display: block;
  font-weight: bold;
  border-left: var(--space-1) solid var(--theme-primary);
  padding-left: var(--space-1);
}
.arrow { font-weight: bold; }
.sub-heading { font-weight: bold; margin-bottom: 0; }
.variant.is-current { border: 2px solid var(--theme-primary); border-radius: var(--theme-radius); padding: var(--space-1); }

.print-frame { width: 100%; border-collapse: collapse; table-layout: fixed; }
.print-frame td { padding: 0; vertical-align: top; }
.print-disclaimer { display: none; }

/* 印刷用：確認メモは、表の見出しと末尾の行が各ページにくり返される */
@media print {
  @page { margin: 16mm 12mm; }
  html { font-size: 11px; }
  body { background: transparent; }
  #app { display: block; min-height: 0; }
  .site-nav, .no-print, .button-link, .button-primary { display: none; }
  .banner { position: static; border: 0; }
  .screen, .site-footer { max-width: none; padding: 0; }
  .screen-memo ~ .site-footer, .banner:has(~ .screen-memo) { display: none; }
  .print-frame thead { display: table-header-group; }
  .print-frame tfoot { display: table-footer-group; }
  .print-disclaimer { display: block; font-weight: bold; text-align: center; padding: var(--space-1) 0; }
  /* 紙の枚数を抑える：見出しと値を横に並べ、行の間隔を詰める */
  body { line-height: 1.4; }
  .memo-item { break-inside: avoid; padding: 0; }
  .screen-memo .fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 3fr); column-gap: var(--space-1); margin: 0; }
  .screen-memo .fields dt, .screen-memo .fields dd { font-size: 1rem; margin: 0; }
  .screen-memo p, .screen-memo ul, .screen-memo ol { margin: 0; }
  .screen-memo .link-list li { margin: 0; }
  .screen-memo h3, .screen-memo .sub-heading { font-size: 1rem; }
  .screen-memo .url-text { display: inline; }
  .date-note-past, .date-note-weekend, .notice { padding: 0 var(--space-1); }
  h1, h2, h3 { break-after: avoid; margin-top: var(--space-1); }
  .item-ref, .ext-link { min-height: 0; }
}
