:root {
  color-scheme: light dark;
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1a2330;
  --muted: #5a6675;
  --line: #d5dbe3;
  --accent: #0a6a8f;
  --accent-text: #ffffff;
  --accent-soft: #e2f1f7;
  --warn-bg: #fff4e0;
  --warn-text: #7a4a00;
  --bad: #b3261e;
  --bad-bg: #fdecea;
  --new-bg: #e6f4e6;
  --new-text: #1f6b2a;
  --prev-bg: #ecebfa;
  --prev-text: #45409a;
  --track: #e3e8ee;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12171d;
    --card: #1c232c;
    --text: #e8edf2;
    --muted: #a3afbd;
    --line: #36414e;
    --accent: #5fbfe6;
    --accent-text: #06202c;
    --accent-soft: #163645;
    --warn-bg: #3d2f12;
    --warn-text: #ffd590;
    --bad: #ff8a80;
    --bad-bg: #40201e;
    --new-bg: #1b3a20;
    --new-text: #9ddfa6;
    --prev-bg: #2b2a52;
    --prev-text: #c3c0ff;
    --track: #2a333e;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", Meiryo, sans-serif;
  font-size: 16px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}
.wrap { max-width: 680px; margin: 0 auto; padding: 0 16px; }
.wrap-wide { max-width: 960px; }
main.wrap { padding-top: 16px; padding-bottom: 48px; }
h1, h2, h3, p { margin: 0; }
h1:focus, h2:focus { outline: none; }
[hidden] { display: none !important; }

.demo-banner {
  background: var(--warn-bg);
  color: var(--warn-text);
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  padding: 4px 12px;
}

/* ---- 上の帯（施設名と進み具合） ---- */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}
.survey-name { font-size: 12px; color: var(--muted); }
.facility { font-size: 17px; font-weight: 700; min-height: 1.7em; }
.progress { margin-top: 6px; }
.progress-track { height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 4px; transition: width .2s; }
.progress-text { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---- 共通の部品 ---- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  margin: 0 0 16px;
}
.step-count { font-size: 13px; color: var(--muted); }
.section-title { font-size: 22px; margin-bottom: 12px; }
.lead { margin-bottom: 16px; }
.muted { color: var(--muted); }
.pre { white-space: pre-wrap; }
.loading { color: var(--muted); padding: 32px 0; text-align: center; }

.btn {
  appearance: none;
  min-height: 52px;
  padding: 10px 20px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.link {
  appearance: none;
  border: 0;
  background: none;
  padding: 6px 0;
  color: var(--accent);
  font: inherit;
  font-size: 14px;
  text-decoration: underline;
  text-align: left;
  cursor: pointer;
}
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 8px; }
.nav .btn-primary { flex: 1; max-width: 60%; margin-left: auto; }

.notice {
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 14px;
}
.alert {
  background: var(--bad-bg);
  color: var(--bad);
  border: 1px solid var(--bad);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 16px;
}
.alert-title { font-weight: 700; }
.alert ul { margin: 6px 0 0; padding-left: 1.2em; }
.alert .link { color: inherit; font-size: 15px; }
.alert-reason { display: block; font-size: 13px; }

.gate { text-align: center; padding: 32px 16px; margin-top: 24px; }
.gate h1 { font-size: 20px; margin-bottom: 12px; }
.gate .btn { margin-top: 20px; }

/* ---- 設問 ---- */
fieldset.q { min-width: 0; scroll-margin-top: 120px; }
.q-highlight { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.q-legend { padding: 0; float: left; width: 100%; font-weight: 700; font-size: 17px; line-height: 1.5; }
.q-legend + * { clear: both; }
.q-number {
  display: inline-block;
  margin-right: 8px;
  padding: 0 8px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  vertical-align: 2px;
}
.q-cond { font-size: 13px; color: var(--muted); margin-top: 2px; }
.q-hint { font-size: 13px; color: var(--muted); margin-top: 4px; }
.tags { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin: 6px 0 2px; min-height: 4px; }
.tag { font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 999px; white-space: nowrap; }
.tag-required { background: var(--bad-bg); color: var(--bad); }
.tag-new { background: var(--new-bg); color: var(--new-text); }
.tag-prev { background: var(--prev-bg); color: var(--prev-text); }
.tag-changed { background: var(--warn-bg); color: var(--warn-text); }

.choices { display: grid; gap: 8px; margin-top: 10px; }
.choice {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 10px 14px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  line-height: 1.45;
}
.choice input { flex: none; width: 22px; height: 22px; margin: 0; accent-color: var(--accent); }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.choice:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }
.choice input:focus-visible { outline: none; }

textarea, input[type="text"], input[type="password"] {
  width: 100%;
  padding: 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* iOS で拡大されない大きさ */
}
textarea { display: block; resize: vertical; min-height: 84px; }
.text { margin-top: 10px; }
.other { display: block; margin-top: 4px; }
.other-label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.number { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.number input { width: 7.5em; text-align: right; font-size: 20px; font-variant-numeric: tabular-nums; }
.unit { color: var(--muted); font-size: 14px; }
.field-error { color: var(--bad); font-size: 14px; }
.field-error:empty { display: none; }

/* ---- 確認画面 ---- */
.summary h3 { font-size: 16px; margin-bottom: 4px; }
.summary dl { margin: 0; }
.summary-row { padding: 10px 0; border-top: 1px solid var(--line); }
.summary-row dt { font-size: 14px; color: var(--muted); }
.summary-row dd { margin: 2px 0 0; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.summary-row dd .link { flex: none; padding: 2px 0; }
.summary-bad { background: var(--bad-bg); margin: 0 -8px; padding-left: 8px; padding-right: 8px; border-radius: 6px; }
.bad-text { color: var(--bad); font-weight: 700; }

/* ---- 集計・QR（合言葉で守る画面） ---- */
.admin-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 8px 16px; margin-bottom: 16px; }
.admin-head h1 { font-size: 22px; }
.admin-links { display: flex; gap: 16px; font-size: 14px; }
.admin-links a { color: var(--accent); }
.key-form { display: grid; gap: 12px; max-width: 420px; margin: 24px auto; }
.key-form label { font-weight: 600; }

.kpi { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.tile { flex: 1 1 140px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; }
.tile-label { font-size: 13px; color: var(--muted); }
.tile-value { font-size: 28px; font-weight: 700; line-height: 1.3; font-variant-numeric: tabular-nums; }
.tile-value small { font-size: 14px; font-weight: 400; color: var(--muted); }
.tiles-small .tile { padding: 8px 12px; }
.tiles-small .tile-value { font-size: 20px; }

.stat-section { font-size: 18px; margin: 24px 0 10px; }
.stat h3 { font-size: 16px; line-height: 1.5; }
.stat-meta { font-size: 13px; color: var(--muted); margin: 2px 0 10px; }
.bars { display: grid; gap: 10px; }
.bar-label { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; line-height: 1.45; }
.bar-count { flex: none; font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.bar-track { height: 14px; background: var(--track); border-radius: 4px; overflow: hidden; margin-top: 3px; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 4px; min-width: 0; }
.text-list { margin: 8px 0 0; padding-left: 1.2em; font-size: 14px; }
.text-list li { margin-bottom: 4px; white-space: pre-wrap; }
.sub-title { font-size: 13px; font-weight: 700; color: var(--muted); margin-top: 12px; }

.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.tab {
  appearance: none;
  min-height: 44px;
  padding: 6px 16px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.tab-on { border-color: var(--accent); background: var(--accent-soft); font-weight: 700; }
.record dl { margin: 0; }
.record dd { margin: 0 0 4px; font-size: 14px; }
.qr-kind { font-size: 13px; font-weight: 700; color: var(--accent); }

.qr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.qr-card { text-align: center; margin: 0; break-inside: avoid; }
.qr-card img { width: 100%; max-width: 220px; height: auto; background: #fff; border-radius: 6px; }
.qr-facility { font-size: 18px; font-weight: 700; }
.qr-sub { font-size: 12px; color: var(--muted); }
.qr-url { font-size: 11px; color: var(--muted); word-break: break-all; line-height: 1.4; margin-top: 4px; }
.qr-url a { color: inherit; }

@media print {
  :root { color-scheme: light; --bg: #fff; --card: #fff; --text: #000; --muted: #444; --line: #999; }
  .no-print { display: none !important; }
  .qr-grid { grid-template-columns: repeat(2, 1fr); gap: 8mm; }
  .qr-card { border: 1px dashed #999; }
  .wrap-wide { max-width: none; }
}
