/* まるっとヘルスラボ — 色と共通の部品（DESIGN.md §6） */
:root {
  --bg: #fff7ea;
  --paper: #ffffff;
  --paper-2: #fff1dc;
  --ink: #4a3526;
  --ink-2: #7a6657;
  --line: #ecdcc6;
  --fumi: #f08a24;
  --fumi-soft: #ffe7cc;
  --miso: #3f7fc4;
  --miso-soft: #dcebfa;
  --keika: #e2678d;
  --keika-soft: #fde0ea;
  --ok: #3d9a5f;
  --ok-soft: #dff3e6;
  --warn: #b4571b;
  --warn-soft: #fff0d9;
  --danger: #c2413a;
  /* ボタンの地・オレンジの字。白い字とで 5.1:1・地のクリームの上の字で 4.8:1（WCAG AA）。ふみまるの色 --fumi は飾り用 */
  --primary: #b05408;
  --primary-ink: #ffffff;
  --primary-shadow: #7f3c05;
  --fumi-ink: #b05408;      /* オレンジの字に使う（--fumi のままだと白・クリームの上で 2.5:1 しかない） */
  --radius: 16px;
  --radius-s: 10px;
  --shadow: 0 2px 10px rgba(110, 70, 20, .10);
  --tab-h: 64px;
  --top-h: 52px;
  --col: 520px;
  --font: "Hiragino Maru Gothic ProN", "Hiragino Kaku Gothic ProN", "BIZ UDPGothic", "Yu Gothic UI", "Yu Gothic", "Meiryo", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.7;
  -webkit-tap-highlight-color: transparent;
  overflow-wrap: anywhere;
}
body.has-sheet { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }
[hidden] { display: none !important; }
a { color: var(--miso); }
p { margin: 0 0 .6em; }
:focus-visible { outline: 3px solid var(--miso); outline-offset: 2px; }

/* ---------- 骨組み ---------- */
.dl-app { max-width: var(--col); margin: 0 auto; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.dl-top {
  position: sticky; top: 0; z-index: 20;
  height: calc(var(--top-h) + env(safe-area-inset-top, 0px)); padding-top: env(safe-area-inset-top, 0px);
  display: flex; align-items: center; gap: 4px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.top-title { flex: 1; margin: 0; font-size: 18px; font-weight: 700; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-btn { width: 48px; height: 48px; border: 0; background: transparent; border-radius: 50%; font-size: 28px; line-height: 1; display: grid; place-items: center; color: var(--ink-2); }
.top-btn:active { background: var(--paper-2); }
.dl-top .top-btn[hidden] { display: block !important; visibility: hidden; }
.dl-main { flex: 1; padding: 14px 14px calc(var(--tab-h) + 28px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 14px; }
body[data-route="onboard"] .dl-main { padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px)); }
.dl-tabs {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); z-index: 30;
  width: 100%; max-width: var(--col);
  height: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px)); padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex; background: var(--paper); border-top: 1px solid var(--line); box-shadow: 0 -2px 10px rgba(110, 70, 20, .06);
}
.dl-tabs button { flex: 1; min-width: 0; border: 0; background: transparent; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; color: var(--ink-2); padding: 4px 0; }
.dl-tabs .tab-ico { font-size: 22px; line-height: 1.2; filter: grayscale(.7); opacity: .75; }
.dl-tabs .tab-label { font-size: 14px; font-weight: 700; letter-spacing: -.02em; white-space: nowrap; line-height: 1.3; }
.dl-tabs [data-tab="train"] .tab-label { font-size: 13px; letter-spacing: -.06em; }   /* 6文字。幅390でタブ1つ78px */
@media (max-width: 380px) { .dl-tabs [data-tab="train"] .tab-label { font-size: 12px; } }   /* 幅360でタブ1つ72px */
.dl-tabs button.is-on { color: var(--primary); }
.dl-tabs button.is-on .tab-ico { filter: none; opacity: 1; }
.dl-layer { position: relative; z-index: 50; }
/* 消えない知らせの帯（保存できていない など） */
.dl-alert { position: sticky; top: calc(var(--top-h) + env(safe-area-inset-top, 0px)); z-index: 19; display: flex; flex-direction: column; gap: 6px; padding: 8px 12px 0; }
body[data-route="onboard"] .dl-alert { top: env(safe-area-inset-top, 0px); }
.dl-alert-item { background: var(--warn-soft); border: 2px solid #e9b77a; border-radius: var(--radius-s); padding: 10px 12px; color: #6a330c; font-size: 15px; font-weight: 700; line-height: 1.6; box-shadow: var(--shadow); }
.dl-alert-acts { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.dl-alert-acts .btn-small { min-height: 44px; }
.dl-toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + 18px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 12px);
  max-width: min(92vw, 480px); padding: 10px 18px; border-radius: 999px; background: rgba(60, 40, 25, .92); color: #fff; font-size: 15px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 80; text-align: center;
}
.dl-toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 文字 ---------- */
.h1 { font-size: 22px; font-weight: 800; line-height: 1.4; margin: 0; }
.h2 { font-size: 18px; font-weight: 800; line-height: 1.4; margin: 0; }
.h3 { font-size: 16px; font-weight: 800; margin: 0; }
.muted { color: var(--ink-2); font-size: 14px; }
.small { font-size: 13px; }
.big-num { font-size: 34px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums; }
.center { text-align: center; }

/* ---------- 並べ方 ---------- */
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-s { display: flex; flex-direction: column; gap: 6px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; }

/* ---------- カード・ボタン ---------- */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card-flat { box-shadow: none; }
.card-soft { background: var(--paper-2); border-color: transparent; box-shadow: none; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 10px 20px; border-radius: 999px; border: 2px solid transparent;
  font-weight: 800; font-size: 16px; line-height: 1.3; text-align: center; text-decoration: none;
  background: var(--paper-2); color: var(--ink); transition: transform .08s, filter .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--primary); color: var(--primary-ink); box-shadow: 0 3px 0 var(--primary-shadow); }
.btn-primary:active { box-shadow: 0 1px 0 var(--primary-shadow); transform: translateY(2px); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-small { min-height: 40px; padding: 6px 14px; font-size: 14px; }
.btn-block { display: flex; width: 100%; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; background: var(--paper-2); font-size: 13px; font-weight: 700; color: var(--ink-2); white-space: nowrap; }
.chip-cardio { background: var(--fumi-soft); color: #9a5208; }
.chip-strength { background: var(--keika-soft); color: #a3355a; }
.chip-stretch, .chip-posture { background: var(--miso-soft); color: #245a94; }
.chip-balance { background: var(--ok-soft); color: #256b40; }
.chip-habit { background: #f1ecf9; color: #5c4a8a; }
.badge { display: inline-block; min-width: 22px; padding: 1px 7px; border-radius: 999px; background: var(--primary); color: #fff; font-size: 12px; font-weight: 800; text-align: center; }
.note-warn { background: var(--warn-soft); border: 1px solid #f3d3a4; border-radius: var(--radius-s); padding: 12px 14px; color: #7a3d10; font-size: 15px; }
.note-info { background: var(--miso-soft); border-radius: var(--radius-s); padding: 12px 14px; color: #1f4f85; font-size: 15px; }
.note-ok { background: var(--ok-soft); border-radius: var(--radius-s); padding: 12px 14px; color: #1f5c38; font-size: 15px; }
.divider { height: 1px; background: var(--line); border: 0; margin: 4px 0; }

/* ---------- 入力 ---------- */
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-weight: 800; font-size: 15px; }
.field-box { display: flex; align-items: center; gap: 8px; }
.field-input {
  flex: 1; min-width: 0; min-height: 50px; padding: 10px 14px; border-radius: var(--radius-s);
  border: 2px solid var(--line); background: var(--paper); font-size: 18px;
}
textarea.field-input { font-size: 16px; line-height: 1.6; resize: vertical; }
.field-input:focus { outline: none; border-color: var(--primary); }
.field-unit { font-weight: 700; color: var(--ink-2); min-width: 2.2em; }
.field-err { color: var(--danger); font-size: 14px; font-weight: 700; min-height: 0; }
.field.is-error .field-input { border-color: var(--danger); }
.choices { display: grid; gap: 8px; }
.choices-cols-2 { grid-template-columns: 1fr 1fr; }
.choices-cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.choice {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 52px; padding: 10px 14px; text-align: left;
  border-radius: var(--radius-s); border: 2px solid var(--line); background: var(--paper); font-weight: 700; line-height: 1.4;
}
.choice.is-on { border-color: var(--primary); background: var(--fumi-soft); }
.choice-icon { font-size: 22px; }
.choice-text { display: flex; flex-direction: column; min-width: 0; }
.choice-sub { font-weight: 400; font-size: 13px; }

/* ---------- 進みぐあい ---------- */
.progress { position: relative; height: 14px; border-radius: 999px; background: var(--paper-2); overflow: hidden; }
.progress-bar { height: 100%; border-radius: 999px; background: linear-gradient(90deg, #ffb45c, var(--fumi)); transition: width .4s ease; }
.progress-bar.is-over { background: linear-gradient(90deg, #f3a25e, var(--warn)); }
.progress-label { position: absolute; inset: 0; display: grid; place-items: center; font-size: 11px; font-weight: 800; color: var(--ink); }

/* ---------- キャラ・ふきだし ---------- */
.chr { display: block; width: 100%; height: auto; user-select: none; -webkit-user-drag: none; }
.say { display: flex; align-items: flex-end; gap: 8px; }
.say-chr { flex: 0 0 76px; width: 76px; }
.say-s .say-chr { flex-basis: 56px; width: 56px; }
.say-l .say-chr { flex-basis: 110px; width: 110px; }
.bubble { position: relative; flex: 1; min-width: 0; padding: 10px 14px; border-radius: 16px; background: var(--fumi-soft); border: 2px solid transparent; }
.bubble::before { content: ""; position: absolute; left: -9px; bottom: 16px; border: 6px solid transparent; border-right-color: var(--fumi-soft); border-left-width: 4px; }
.bubble-misomaru { background: var(--miso-soft); } .bubble-misomaru::before { border-right-color: var(--miso-soft); }
.bubble-keika { background: var(--keika-soft); } .bubble-keika::before { border-right-color: var(--keika-soft); }
.bubble-name { font-size: 12px; font-weight: 800; color: var(--ink-2); line-height: 1.3; }
.bubble-text { font-size: 16px; font-weight: 700; line-height: 1.55; }
.empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 22px 12px; text-align: center; }
.empty-chr { width: 96px; opacity: .92; }

/* ---------- 下からの窓 ---------- */
.sheet { position: fixed; inset: 0; z-index: 60; background: rgba(50, 32, 18, .45); display: flex; align-items: flex-end; justify-content: center; animation: dl-fade .18s ease; }
.sheet-panel {
  width: 100%; max-width: var(--col); max-height: 92vh; max-height: 92dvh; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 20px 20px 0 0; animation: dl-up .22s ease; padding-bottom: env(safe-area-inset-bottom, 0px);
}
.sheet-full { height: 92vh; height: 92dvh; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 12px 8px 8px 18px; }
.sheet-title { flex: 1; font-size: 18px; font-weight: 800; }
.sheet-x { width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; font-size: 26px; line-height: 1; color: var(--ink-2); }
.sheet-body { padding: 4px 18px 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 12px; }
.sheet-actions { display: flex; gap: 10px; padding: 10px 18px 16px; border-top: 1px solid var(--line); }
.sheet-actions .btn { flex: 1; }
.confirm-text { font-size: 17px; font-weight: 700; margin: 4px 0; white-space: pre-line; }
@media (min-width: 560px) {
  .sheet { align-items: center; }
  .sheet-panel { border-radius: 20px; max-height: 88vh; }
}
@keyframes dl-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes dl-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes dl-pop { 0% { transform: scale(.6); opacity: 0; } 70% { transform: scale(1.08); opacity: 1; } 100% { transform: scale(1); } }

/* ---------- 根拠 ---------- */
.ref-btn { position: relative; border: 0; background: transparent; color: #2f6aa8; font-size: 14px; font-weight: 700; text-decoration: underline; padding: 6px 6px; min-height: 40px; min-width: 44px; }
/* 見た目は小さいまま、押せる所だけ上下左右に広げる（44px以上） */
.ref-btn::after { content: ""; position: absolute; left: -2px; right: -2px; top: -5px; bottom: -5px; }
.ref-list { display: flex; flex-direction: column; gap: 12px; }
.ref-item { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 12px; }
.ref-ja { font-weight: 700; font-size: 15px; }
.ref-cite { font-size: 12.5px; line-height: 1.5; margin-top: 4px; }
.ref-link { display: inline-block; margin-top: 4px; font-size: 14px; font-weight: 700; }

/* ---------- チェックの丸 ---------- */
.checkbtn {
  flex: 0 0 44px; width: 44px; height: 44px; border-radius: 50%; border: 3px solid var(--line); background: var(--paper);
  display: grid; place-items: center; font-size: 22px; font-weight: 900; color: transparent; transition: background .15s, border-color .15s;
}
.checkbtn.is-on { background: var(--ok); border-color: var(--ok); color: #fff; animation: dl-pop .28s ease; }

/* ---------- 図（SVG） ---------- */
.illust { display: block; width: 100%; max-width: 320px; height: auto; margin: 0 auto; }
.illust-box { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 8px; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
@media (min-width: 560px) {
  body { background: #f6ead6; }
  .dl-app { background: var(--bg); box-shadow: 0 0 0 1px var(--line); }
}
@media print {
  .dl-top, .dl-tabs, .dl-toast { display: none !important; }
}
