/* CareGeno 画面デザイン（白基調・落ち着いたグリーン） */
:root {
  --green: #2f7d5b;
  --green-dark: #1f5a40;
  --green-light: #e8f4ed;
  --green-mid: #cfe6d8;
  --text: #1d2621;
  --muted: #55615a;
  --line: #cfd8d3;
  --bg: #ffffff;
  --bg-soft: #f5f8f6;
  --danger: #b3261e;
  --danger-light: #fdecea;
  --focus: #f0b400;
  --radius: 12px;
  --bar-h: 72px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; font-size: 18px; }
body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "BIZ UDPGothic", "Meiryo", "Yu Gothic", "Noto Sans JP", sans-serif;
  color: var(--text);
  background: var(--bg-soft);
  line-height: 1.65;
  padding-bottom: calc(var(--bar-h) + 16px + env(safe-area-inset-bottom));
}
body.modal-open { overflow: hidden; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
h2, h3 { line-height: 1.35; }
p { margin: .4em 0; }

.skip { position: absolute; left: -9999px; }
.skip:focus { left: 8px; top: 8px; z-index: 200; background: #fff; padding: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.small { font-size: .82rem; font-weight: normal; }
.center { text-align: center; }

/* ヘッダー */
.app-header {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px;
  padding: 10px 16px 8px; background: #fff;
  padding-top: calc(10px + env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-icon { border-radius: 8px; }
.brand-name { font-size: 1.35rem; font-weight: 700; color: var(--green-dark); letter-spacing: .02em; }
.brand-kana { font-size: .9rem; color: var(--green-dark); font-weight: 700; }
.brand-sub { margin: 0; font-size: .78rem; color: var(--muted); flex-basis: 100%; }
#btn-help { margin-left: auto; }

.update-bar {
  display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap;
  background: #fff8e1; border-bottom: 1px solid #e8c766; padding: 8px 16px;
}

/* 切り替えボタン */
.tabs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  padding: 8px 16px 10px; position: sticky; top: 0; z-index: 20;
  background: #fff; border-bottom: 1px solid var(--line);
}
.tab {
  min-height: 58px; border: 2px solid var(--green); background: #fff; color: var(--green-dark);
  border-radius: var(--radius); font-weight: 700; font-size: 1.05rem; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.25;
}
.tab small { font-weight: normal; font-size: .74rem; }
.tab[aria-selected="true"] { background: var(--green); color: #fff; }

/* レイアウト（スマホ：縦一列／PC：左右） */
.layout {
  display: grid; gap: 14px; padding: 14px 12px; max-width: 1440px; margin: 0 auto;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "person" "viewer" "actions";
}
.area-person { grid-area: person; }
.area-viewer { grid-area: viewer; }
.area-actions { grid-area: actions; display: flex; flex-direction: column; gap: 12px; }
#geno-panel, #eco-panel { display: flex; flex-direction: column; gap: 12px; }

@media (min-width: 960px) {
  .layout {
    grid-template-columns: 410px minmax(0, 1fr);
    grid-template-areas: "person viewer" "actions viewer";
    align-items: start; padding: 16px 20px;
  }
  .area-viewer { position: sticky; top: 92px; }
  .canvas-wrap { height: calc(100vh - 300px) !important; min-height: 380px; }
}

.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card-title { font-size: 1.05rem; margin: 0 0 6px; }
.person-row { display: flex; align-items: center; gap: 10px; }
.person-text { flex: 1; min-width: 0; }
.person-summary { margin: 0; font-size: 1.1rem; font-weight: 700; overflow-wrap: anywhere; }
.start-card { border: 2px solid var(--green); background: var(--green-light); }

/* ボタン */
.btn {
  min-height: 48px; padding: 8px 16px; border-radius: 10px;
  border: 2px solid var(--green); background: #fff; color: var(--green-dark);
  font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; text-align: center; text-decoration: none; line-height: 1.3; touch-action: manipulation;
}
.btn:hover { background: var(--green-light); }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dark); }
.btn-big { width: 100%; min-height: 62px; font-size: 1.15rem; }
.btn-block { width: 100%; }
.btn-small { min-height: 44px; padding: 6px 12px; font-size: .92rem; }
.btn-ghost { border-color: var(--line); color: var(--text); }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger-light); }
.btn-danger.btn-primary { background: var(--danger); color: #fff; }
.btn:disabled { opacity: .38; cursor: not-allowed; }
.btn:focus-visible, .tab:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible, .node:focus-visible, a:focus-visible {
  outline: 3px solid var(--focus); outline-offset: 2px;
}
.stack { display: flex; flex-direction: column; gap: 8px; }
.row-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* 図の表示 */
.viewer { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.viewer-title { font-size: 1.05rem; margin: 0 0 8px; }
.viewer-toolbar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px; }
.canvas-wrap {
  height: 58vh; min-height: 300px; max-height: 720px; overflow: auto; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; -webkit-overflow-scrolling: touch; position: relative;
}
.canvas-wrap svg.diagram { display: block; margin: 8px auto; }
.canvas-wrap .node { cursor: pointer; }
.canvas-wrap.drag-mode { border: 2px dashed var(--green); touch-action: none; }
.canvas-wrap.drag-mode .node { cursor: grab; }
.drag-hint { background: var(--green-light); border-radius: 8px; padding: 8px 10px; font-size: .9rem; margin: 0 0 8px; }
.viewer-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; }
.legend-box { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 4px; }
.legend-box summary, .guide-sec summary {
  cursor: pointer; min-height: 48px; display: flex; align-items: center; font-weight: 700; color: var(--green-dark);
}
.legend-svg { width: 100%; height: auto; max-width: 560px; display: block; margin: 6px 0; }

/* 一覧 */
.list { display: flex; flex-direction: column; gap: 8px; margin: 6px 0 10px; }
.item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.item-icon { width: 30px; text-align: center; font-size: 1.3rem; color: var(--green-dark); flex: none; }
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 700; overflow-wrap: anywhere; }
.item-sub { font-size: .82rem; color: var(--muted); overflow-wrap: anywhere; }

/* 下部の操作バー */
.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: 1fr 1fr 1.25fr; gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: #fff; border-top: 1px solid var(--line); box-shadow: 0 -2px 8px rgba(0,0,0,.06);
}
.bottom-bar .btn { min-height: 54px; padding: 6px 8px; font-size: .98rem; }

/* 小窓 */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 30, 25, .5); z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: #fff; width: 100%; max-width: 640px; max-height: 94vh; max-height: 94dvh;
  border-radius: 16px 16px 0 0; display: flex; flex-direction: column; box-shadow: 0 -4px 24px rgba(0,0,0,.2);
}
.modal-wide { max-width: 820px; }
@media (min-width: 700px) {
  .modal-backdrop { align-items: center; padding: 20px; }
  .modal { border-radius: 16px; }
}
.modal-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px 10px 16px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 1.15rem; margin: 0; flex: 1; outline: none; }
.modal-close { flex: none; min-height: 44px; padding: 4px 12px; font-size: .9rem; }
.modal-body { padding: 8px 16px 18px; overflow: auto; flex: 1; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.modal-foot {
  display: flex; gap: 8px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: #fff; border-radius: 0 0 16px 16px;
}
.modal-foot .btn { flex: 1; min-height: 54px; }
.confirm-msg p { margin: .5em 0; overflow-wrap: anywhere; }
.lead { margin: 8px 0 12px; }

/* 入力欄 */
.field { margin: 16px 0; }
.field > .label { display: block; font-weight: 700; margin-bottom: 6px; }
.hint { font-size: .84rem; color: var(--muted); margin-top: 4px; }
input[type="text"], select {
  width: 100%; min-height: 50px; padding: 8px 12px; font-size: 1rem;
  border: 2px solid var(--line); border-radius: 10px; background: #fff;
}
input[type="text"]:focus, select:focus { border-color: var(--green); }
.inline { display: flex; align-items: center; gap: 8px; }
.age-input { max-width: 120px; }
.unit { font-weight: 700; }

.choice { display: flex; flex-wrap: wrap; gap: 8px; }
.choice-cols-2 { display: grid; grid-template-columns: 1fr 1fr; }
.choice-cols-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; }
.choice label { position: relative; display: flex; }
.choice input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.choice span {
  display: flex; flex-wrap: wrap; align-items: center; align-content: center; flex: 1;
  min-height: 50px; min-width: 64px; padding: 6px 14px; border: 2px solid var(--line); border-radius: 10px;
  cursor: pointer; background: #fff; line-height: 1.3;
}
.choice span small { font-size: .76rem; color: var(--muted); flex-basis: 100%; }
.choice input:checked + span { border-color: var(--green); background: var(--green-light); font-weight: 700; }
.choice input:checked + span::before { content: "✓ "; color: var(--green-dark); }
.choice input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

.checks { display: flex; flex-direction: column; gap: 8px; }
.check {
  display: flex; align-items: center; gap: 12px; min-height: 50px; padding: 6px 12px;
  border: 2px solid var(--line); border-radius: 10px; cursor: pointer; background: #fff;
}
.check input { width: 26px; height: 26px; flex: none; accent-color: var(--green); }
.check span { display: flex; flex-direction: column; }
.check small { font-size: .78rem; color: var(--muted); }
.check:has(input:checked) { border-color: var(--green); background: var(--green-light); }
.check.is-disabled { opacity: .55; }

.grid-buttons { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.btn-choice { flex-direction: column; min-height: 62px; padding: 6px 8px; }
.btn-choice .big { font-size: 1.05rem; }
.btn-choice small { font-weight: normal; font-size: .74rem; color: var(--muted); }
.template-list { display: flex; flex-direction: column; gap: 8px; }
.template { align-items: flex-start; text-align: left; }
.group-title { font-size: 1rem; margin: 18px 0 8px; padding-left: 8px; border-left: 5px solid var(--green); }
.danger-zone { margin-top: 26px; padding-top: 14px; border-top: 1px dashed var(--line); }

.notice { background: #fff8e1; border: 1px solid #e8c766; border-radius: 10px; padding: 10px 12px; }
.notice.small { font-size: .86rem; }
.notice.warn { background: #fdf1ec; border-color: #e3a487; }
.preview-img { max-width: 100%; height: auto; border: 1px solid var(--line); display: block; margin: 8px auto; }
.export .stack { margin: 10px 0; }

.guide .steps { padding-left: 1.4em; }
.guide .steps li { margin-bottom: 12px; }
.guide-sec { border-top: 1px solid var(--line); }
.guide-body { padding-bottom: 10px; }
ul.plain { padding-left: 1.2em; }
ul.plain li { margin-bottom: 6px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--bar-h) + 20px + env(safe-area-inset-bottom)); z-index: 150;
  background: #1f2a24; color: #fff; padding: 10px 18px; border-radius: 24px; max-width: 92vw;
  font-size: .95rem; box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.noscript { padding: 16px; background: #fff8e1; }

/* 小さな画面向けの調整 */
@media (max-width: 480px) {
  .app-header { padding-left: 12px; padding-right: 12px; }
  .brand-name { font-size: 1.2rem; }
  .brand-kana { font-size: .8rem; }
  .brand-icon { width: 28px; height: 28px; }
  #btn-help { min-height: 44px; padding: 4px 10px; font-size: .85rem; }
  .brand-sub { font-size: .72rem; }
  .tabs { padding: 6px 12px 8px; }
  .viewer-toolbar .btn { padding: 4px 6px; font-size: .86rem; }
  .bottom-bar { gap: 6px; padding-left: 8px; padding-right: 8px; }
  .bottom-bar .btn { font-size: .86rem; padding: 4px; }
  .person-text .small { display: block; }
}

#print-area { display: none; }
@media print {
  body { background: #fff; padding: 0; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; }
  #print-area img { display: block; object-fit: contain; }
  #print-area.print-portrait img { width: 210mm; height: 296mm; }
  #print-area.print-landscape img { width: 297mm; height: 209mm; }
}
