/* =========================================================================
   安否確認 / 回答画面・ルート共通スタイル
   - モバイル優先。CSP: self のみ（外部フォント/CDN不使用、インラインstyle不可）。
   - アイコンはHTML内インラインSVG、装飾はCSSのみ。
   ========================================================================= */
:root {
  color-scheme: light dark;
  --bg: #eceff5;
  --bg-top: #eef2f8;
  --bg-bottom: #e4e9f1;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #64748b;
  --line: #e6eaf1;
  --line-strong: #d4dbe6;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --primary-ink: #ffffff;
  --primary-tint: #eef4ff;
  --ok: #15a34a;
  --ok-tint: #e8f7ee;
  --warn: #d97706;
  --warn-tint: #fdf0dd;
  --danger: #dc2626;
  --danger-tint: #fdeceb;
  --ring: rgba(37, 99, 235, .32);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow-md: 0 6px 18px -6px rgba(15, 23, 42, .14), 0 2px 6px -2px rgba(15, 23, 42, .08);
  --shadow-lg: 0 24px 48px -16px rgba(15, 23, 42, .26);
  --radius: 18px;
  --radius-sm: 13px;
  --radius-xs: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  background: var(--bg);
  background-image: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  background-attachment: fixed;
  font-family: system-ui, -apple-system, "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.wrap {
  max-width: 540px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 18px calc(40px + env(safe-area-inset-bottom));
}

/* ---------- ヘッダー / ブランド ---------- */
.head { padding: 14px 4px 4px; }
.brand { display: flex; align-items: center; gap: 13px; }
.brand-mark {
  flex: 0 0 auto;
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(145deg, #3b82f6 0%, var(--primary-strong) 100%);
  box-shadow: 0 6px 16px -4px var(--ring), inset 0 1px 0 rgba(255, 255, 255, .25);
}
.brand-mark svg { width: 26px; height: 26px; display: block; }
.brand-text { min-width: 0; }
h1 { font-size: 1.4rem; font-weight: 700; letter-spacing: .01em; margin: 0; line-height: 1.25; }
.muted { color: var(--muted); font-size: .9rem; margin: 2px 0; }

/* ---------- カード ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 20px;
  margin-top: 16px;
  box-shadow: var(--shadow-md);
  animation: rise .36s cubic-bezier(.2, .7, .3, 1) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .card { animation: none; } }

.hidden { display: none !important; }

/* ---------- 状態カード（読込/エラー/完了） ---------- */
.state { text-align: center; padding: 34px 22px; }
.state p { margin: 0; color: var(--ink-soft); }
.spinner {
  width: 34px; height: 34px; display: inline-block; margin-bottom: 14px;
  border: 3px solid var(--line-strong); border-top-color: var(--primary);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.state-ico {
  width: 54px; height: 54px; margin: 0 auto 14px; border-radius: 50%;
  display: grid; place-items: center; font-size: 1.7rem; font-weight: 700;
}
.state-ico--err { background: var(--danger-tint); color: var(--danger); }

/* ---------- フォーム ---------- */
.greeting { font-size: 1.15rem; font-weight: 700; margin: 0 0 18px; color: var(--ink); }
.group { border: 0; padding: 0; margin: 0 0 22px; }
.group:last-of-type { margin-bottom: 8px; }
.group legend {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 1.02rem; margin-bottom: 11px; padding: 0; color: var(--ink);
}
.req {
  color: var(--danger); background: var(--danger-tint);
  font-size: .68rem; font-weight: 700; letter-spacing: .04em;
  padding: 2px 7px; border-radius: 6px; line-height: 1.6;
}
.opt-note {
  color: var(--muted); background: var(--surface-2); border: 1px solid var(--line);
  font-size: .68rem; font-weight: 600; padding: 2px 7px; border-radius: 6px;
}

/* 選択肢タイル */
.opt {
  --accent: var(--primary);
  --accent-tint: var(--primary-tint);
  position: relative;
  display: flex; align-items: center; gap: 13px;
  padding: 15px 16px; margin-bottom: 10px;
  border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer; font-size: 1.05rem; font-weight: 500;
  transition: border-color .16s, background .16s, box-shadow .16s, transform .08s;
}
.opt:last-child { margin-bottom: 0; }
.opt:hover { border-color: var(--accent); }
.opt:active { transform: scale(.992); }
.opt:focus-within { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--ring); }
.opt input {
  position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none;
}
.opt-dot { flex: 0 0 auto; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); opacity: .55; transition: opacity .16s, transform .16s; }
.opt-label { flex: 1 1 auto; }
.opt-check {
  flex: 0 0 auto; width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--line-strong); background: var(--surface);
  position: relative; transition: border-color .16s, background .16s;
}
.opt-check::after {
  content: ""; position: absolute; left: 7px; top: 3px; width: 6px; height: 11px;
  border: solid #fff; border-width: 0 2.5px 2.5px 0; transform: rotate(45deg) scale(0);
  transition: transform .16s cubic-bezier(.2, .8, .3, 1.4);
}
/* 選択状態 */
.opt:has(input:checked) {
  border-color: var(--accent); background: var(--accent-tint);
  box-shadow: 0 4px 14px -6px var(--accent);
}
.opt:has(input:checked) .opt-dot { opacity: 1; transform: scale(1.1); }
.opt:has(input:checked) .opt-check { border-color: var(--accent); background: var(--accent); }
.opt:has(input:checked) .opt-check::after { transform: rotate(45deg) scale(1); }
/* 意味に応じたアクセント色 */
.opt:has(input[value="SAFE"])       { --accent: var(--ok);      --accent-tint: var(--ok-tint); }
.opt:has(input[value="INJURED"])    { --accent: var(--warn);    --accent-tint: var(--warn-tint); }
.opt:has(input[value="NEEDS_HELP"]) { --accent: var(--danger);  --accent-tint: var(--danger-tint); }

/* 位置情報の注記 */
.geo-note {
  margin: 4px 0 0; padding: 11px 13px; border-radius: var(--radius-sm);
  background: var(--primary-tint); color: var(--ink-soft);
  font-size: .85rem; line-height: 1.55; border: 1px solid var(--line);
}
.geo-note strong { color: var(--ink); }

/* テキストエリア */
textarea {
  width: 100%; border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 13px 14px; font: inherit; color: var(--ink); background: var(--surface);
  resize: vertical; min-height: 84px; transition: border-color .16s, box-shadow .16s;
}
textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--ring); }
.counter { text-align: right; color: var(--muted); font-size: .78rem; margin-top: 6px; }

/* ---------- ボタン ---------- */
button, .primary { font: inherit; }
.primary, .ghost {
  width: 100%; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: var(--radius-sm); padding: 15px 18px; font-size: 1.06rem; font-weight: 700;
  cursor: pointer; border: 1.5px solid transparent; text-decoration: none;
  transition: transform .08s, box-shadow .16s, background .16s, border-color .16s, opacity .16s;
}
.primary {
  color: var(--primary-ink);
  background: linear-gradient(145deg, #3b82f6 0%, var(--primary-strong) 100%);
  box-shadow: 0 10px 22px -10px var(--ring), inset 0 1px 0 rgba(255, 255, 255, .22);
}
.primary:hover { box-shadow: 0 14px 26px -10px var(--ring); }
.primary:active { transform: translateY(1px); }
.primary:disabled { opacity: .6; cursor: default; box-shadow: none; }
.primary:focus-visible, .ghost:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--ring); }
.btn-lg { margin-top: 6px; padding: 16px 18px; }
.ghost {
  background: var(--surface); color: var(--primary); border-color: var(--line-strong); margin-top: 14px;
}
.ghost:hover { border-color: var(--primary); background: var(--primary-tint); }

.err { color: var(--danger); background: var(--danger-tint); border-radius: var(--radius-xs);
  font-size: .9rem; font-weight: 500; margin: 12px 0 0; padding: 10px 12px; }

/* ---------- 完了画面 ---------- */
.done-mark {
  width: 76px; height: 76px; border-radius: 50%; margin: 2px auto 14px;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(145deg, #22c55e 0%, var(--ok) 100%);
  box-shadow: 0 12px 26px -10px rgba(21, 163, 74, .6);
  animation: pop .4s cubic-bezier(.2, .8, .3, 1.4) both;
}
.done-mark svg { width: 38px; height: 38px; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.done-title { text-align: center; font-size: 1.25rem; font-weight: 700; margin: 0 0 6px; }
#done .muted { text-align: center; }

/* ---------- ルート(index) 用の補助 ---------- */
.card p { margin: 0 0 10px; }
.card p:last-child { margin-bottom: 0; }
.foot { text-align: center; margin-top: 26px; font-size: .78rem; opacity: .8; }

/* ---------- ダークモード ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120; --bg-top: #0e1627; --bg-bottom: #0a0f1c;
    --surface: #151d2e; --surface-2: #1b2437;
    --ink: #e8eef6; --ink-soft: #c2cdda; --muted: #93a1b5;
    --line: #26314a; --line-strong: #33415e;
    --primary: #4f8cf7; --primary-strong: #3b74e0; --primary-tint: #16233c;
    --ok: #34c77b; --ok-tint: #10261c; --warn: #e0a640; --warn-tint: #2a2112;
    --danger: #f06a63; --danger-tint: #2c1718;
    --ring: rgba(79, 140, 247, .4);
    --shadow-md: 0 6px 18px -6px rgba(0, 0, 0, .5), 0 2px 6px -2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 24px 48px -16px rgba(0, 0, 0, .6);
  }
  .primary { color: #fff; }
}
