:root {
  --bg: #f4f6f9;
  --stage: #e9eef4;
  --panel: #ffffff;
  --text: #1f2a37;
  --muted: #5b6776;
  --line: #d9e0e8;
  --accent: #1f5f9e;
  --accent-soft: #e6f0fa;
  --hl: #f2b705;
  --radius: 12px;
  --gutter: 16px;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
  color: var(--text);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111821; --stage: #18212c; --panel: #1b2430; --text: #e8edf3;
    --muted: #9aa7b6; --line: #2c3846; --accent: #7fb4ea; --accent-soft: #233447;
  }
}
:root[data-theme="dark"] {
  --bg: #111821; --stage: #18212c; --panel: #1b2430; --text: #e8edf3;
  --muted: #9aa7b6; --line: #2c3846; --accent: #7fb4ea; --accent-soft: #233447;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { display: flex; flex-direction: column; min-height: 100dvh; }
button { font: inherit; color: inherit; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px var(--gutter); padding-top: max(10px, env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: .02em; }
.link-btn { background: none; border: 0; color: var(--accent); font-size: 14px; padding: 6px 0; cursor: pointer; text-decoration: underline; }

.layout { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.stage { position: relative; flex: 1 1 auto; min-height: 52dvh; background: var(--stage); touch-action: none; }
#viewer { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 14px; }
.loading[hidden] { display: none; }
.hint { position: absolute; left: var(--gutter); right: var(--gutter); top: 10px; margin: 0; text-align: center; font-size: 12px; color: var(--muted); pointer-events: none; }
.views { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); display: flex; gap: 6px; background: color-mix(in srgb, var(--panel) 88%, transparent); padding: 6px; border-radius: 999px; border: 1px solid var(--line); }
.views button { white-space: nowrap; border: 0; background: transparent; padding: 6px 12px; border-radius: 999px; font-size: 13px; cursor: pointer; min-width: 44px; min-height: 32px; }
.views button:hover { background: var(--accent-soft); }

.panel { background: var(--panel); border-top: 1px solid var(--line); padding: 14px var(--gutter) max(16px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.panel > * { flex-shrink: 0; }
.block h2 { font-size: 13px; color: var(--muted); font-weight: 600; margin: 0 0 8px; }
.vessel-buttons { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.vessel-buttons button {
  border: 1.5px solid var(--line); background: var(--panel); border-radius: 10px; padding: 8px 4px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 52px;
}
.vessel-buttons button b { font-size: 16px; letter-spacing: .03em; }
.vessel-buttons button span { font-size: 11px; color: var(--muted); }
.vessel-buttons button[aria-pressed="true"] { border-color: var(--hl); background: color-mix(in srgb, var(--hl) 18%, var(--panel)); }
.vessel-buttons .clear { grid-column: 1 / -1; min-height: 36px; flex-direction: row; justify-content: center; font-size: 13px; color: var(--muted); }

.info { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; min-height: 64px; }
.info .name { font-size: 20px; font-weight: 700; margin: 0; }
.info .abbr { color: var(--muted); font-size: 14px; margin-left: 4px; font-weight: 600; }
.info p { margin: 8px 0 0; font-size: 14px; line-height: 1.7; }
.info ul { margin: 8px 0 0; padding-left: 1.2em; font-size: 14px; line-height: 1.7; }
.info .caution { font-size: 12.5px; color: var(--muted); background: var(--accent-soft); padding: 8px 10px; border-radius: 8px; }
.info details { margin-top: 10px; font-size: 12.5px; }
.info details summary { cursor: pointer; color: var(--accent); }
.info table { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 12px; }
.info td, .info th { border-bottom: 1px solid var(--line); padding: 4px 4px; text-align: left; vertical-align: top; }
.muted { color: var(--muted); font-size: 14px; margin: 0; }

.toggles { display: flex; flex-direction: column; gap: 10px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 6px 12px; font-size: 13px; cursor: pointer; min-height: 32px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }

/* 心筋梗塞シミュレーション */
:root { --bull-normal: #f1e9e6; --bull-line: #ffffff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --bull-normal: #3a3236; --bull-line: #1b2430; } }
:root[data-theme="dark"] { --bull-normal: #3a3236; --bull-line: #1b2430; }
.sim { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.sim h2 { color: var(--text); font-size: 15px; font-weight: 700; }
.sim-target { margin: 0 0 8px; font-size: 14px; }
.sim-sub { margin: 0 0 4px; font-size: 12.5px; color: var(--muted); }
.tree-wrap { margin: 0 -4px; }
.tree { width: 100%; max-width: 420px; height: auto; display: block; margin: 0 auto; }
.tree .ao { fill: #f3e3e1; stroke: #c6564d; stroke-width: 2; }
.tree .cut { stroke: #e0201b; stroke-width: 1.6; stroke-dasharray: 3 2; }
.tree .tname { font-size: 10.5px; font-weight: 700; fill: #2f5fa0; }
.tree .tlab { font-size: 10px; fill: var(--muted); }
.tree .minor { stroke: #c9a7a2; stroke-width: 2.5; fill: none; stroke-linecap: round; }
.tree .tseg { cursor: pointer; outline: none; }
.tree .tseg .hit { stroke: transparent; stroke-width: 18; fill: none; stroke-linecap: round; }
.tree .tseg .line { stroke: #9e2a2b; stroke-width: 5; fill: none; stroke-linecap: round; }
.tree .tseg .tnum { font-size: 12px; font-weight: 700; fill: var(--text); }
.tree .tseg:hover .line, .tree .tseg:focus-visible .line { stroke: #c0392b; stroke-width: 7; }
.tree .tseg.sel .line { stroke: #e0201b; stroke-width: 8; }
.tree .tseg.sel .tnum { fill: #e0201b; }
.tree .tseg.absent .line { stroke: #b9b9b9; stroke-width: 3; stroke-dasharray: 4 3; }
.tree .tseg.absent .tnum { fill: #a0a0a0; font-weight: 400; }
.tree-cap { font-size: 11.5px; color: var(--muted); margin: 0 0 6px; }
.sim-occ { margin: 4px 0 8px; font-size: 14px; line-height: 1.6; }
.tree .ao-t { fill: #a03a33; font-size: 11px; font-weight: 700; }
.absent-msg { display: block; margin-top: 6px; font-size: 12.5px; background: var(--accent-soft); padding: 6px 8px; border-radius: 8px; }
.sim-check { display: flex; align-items: center; gap: 6px; font-size: 13px; margin-top: 8px; }
.occ-notes { margin: 6px 0; padding-left: 1.2em; font-size: 13px; line-height: 1.7; }
.rv-line { font-size: 12.5px; margin: 6px 0 0; text-align: center; }
.rv-line i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; border: 1px solid rgb(0 0 0 / .15); }
.num3d { position: absolute; transform: translate(-50%, -50%); font: 700 12px/1 system-ui, sans-serif; color: #fff; background: rgb(60 20 20 / .78); border: 0; border-radius: 9px; padding: 3px 6px; cursor: pointer; }
.num3d.on { background: #e0201b; }
.num3d.seglabel { background: rgb(0 0 0 / .65); pointer-events: none; }
.muted-s { color: var(--muted); font-size: 12px; margin-left: 4px; }
.sim-seg { display: flex; width: 100%; }
.sim-seg button { flex: 1; min-height: 36px; }
.sim-lead { font-size: 13.5px; line-height: 1.7; margin: 10px 0 6px; }
.sim-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; margin: 4px 0 6px; }
.sim-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; border: 1px solid rgb(0 0 0 / .15); }
.bull-wrap { display: flex; flex-direction: column; align-items: center; margin-top: 4px; }
.bull { width: min(220px, 70vw); height: auto; }
.bull-n { font-size: 11px; font-weight: 700; fill: #3b2f2f; pointer-events: none; }
.bull-n.on-dark { fill: #fff; }
.bull-dir { font-size: 9px; fill: var(--muted); }
.bull-cap { font-size: 11.5px; color: var(--muted); margin: 2px 0 0; text-align: center; }
.sim-notes { margin-top: 8px; font-size: 12.5px; }
.sim-notes summary { cursor: pointer; color: var(--accent); }
.sim-notes ul { margin: 6px 0 0; padding-left: 1.2em; line-height: 1.7; }

.note { font-size: 12px; color: var(--muted); line-height: 1.6; margin: 0; }

.dialog { border: 0; border-radius: var(--radius); padding: 18px var(--gutter); width: min(720px, calc(100vw - 2 * var(--gutter))); max-height: 85dvh; background: var(--panel); color: var(--text); }
.dialog::backdrop { background: rgb(0 0 0 / .4); }
.dialog-close { position: sticky; top: 0; display: flex; justify-content: flex-end; }
.dialog-close button { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 4px 14px; cursor: pointer; }
.dialog h2 { font-size: 18px; margin: 4px 0 12px; }
.dialog h3 { font-size: 15px; margin: 18px 0 6px; }
.dialog p, .dialog li { font-size: 14px; line-height: 1.7; }
.dialog .credit { background: var(--accent-soft); padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.dialog table { width: 100%; border-collapse: collapse; font-size: 12px; }
.dialog td, .dialog th { border-bottom: 1px solid var(--line); padding: 4px; text-align: left; vertical-align: top; }
.dialog a { color: var(--accent); }

@media (min-width: 900px) {
  .layout { flex-direction: row; }
  .stage { min-height: 0; }
  .panel { width: 360px; flex: 0 0 360px; border-top: 0; border-left: 1px solid var(--line); }
}

/* 位置合わせモード（?pos） */
.pos-box { border: 2px dashed #e0201b; border-radius: 10px; padding: 10px 12px; margin: 0 0 10px; font-size: 13px; line-height: 1.6; }
.pos-box p { margin: 0 0 6px; }
.pos-title { font-weight: 700; color: #e0201b; }
.pos-help { color: var(--muted); font-size: 12.5px; }
.pos-msg { background: var(--accent-soft); padding: 4px 8px; border-radius: 6px; }
.pos-memo { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; margin: 4px 0 8px; }
.pos-memo input { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--text); }
.pos-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.pos-btns button { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 6px 12px; font-size: 12.5px; cursor: pointer; min-height: 32px; }
.pos-btns button:disabled { opacity: .45; cursor: default; }
.pos-out { width: 100%; margin-top: 8px; font: 12px/1.5 ui-monospace, monospace; padding: 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); resize: vertical; }
.pos-out[hidden] { display: none; }

/* ---- 12誘導心電図（静止画）2026-11-10〜 ---- */
.ecg { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.ecg h2 { color: var(--text); font-size: 15px; font-weight: 700; }
.ecg-lead { font-size: 13.5px; line-height: 1.7; margin: 0; color: var(--muted); }
.ecg-target { margin: 0 0 8px; font-size: 14px; }
.ecg-kind { display: flex; width: 100%; margin-bottom: 8px; }
.ecg-kind button { flex: 1; min-height: 36px; }
.ecg-kind-label { margin: 0 0 6px; font-size: 12.5px; font-weight: 700; color: var(--muted); }
.ecg-empty { margin: 4px 0; padding: 22px 12px; text-align: center; font-size: 14px; font-weight: 700; color: var(--muted); border: 1px dashed var(--line); border-radius: 8px; }
.ecg-nav { display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 13px; margin-bottom: 6px; }
.ecg-nav button { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; min-width: 36px; min-height: 32px; font-size: 18px; line-height: 1; cursor: pointer; }
.ecg-nav button:disabled { opacity: .4; cursor: default; }
.ecg-fig { margin: 0; }
.ecg-open { display: block; width: 100%; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: zoom-in; overflow: hidden; }
.ecg-open img { display: block; width: 100%; height: auto; }
.ecg-imgerr { font-size: 13px; color: var(--muted); margin: 6px 0; }
.ecg-title { font-size: 14px; font-weight: 700; margin: 8px 0 4px; }
.ecg-findings { margin: 4px 0; padding-left: 1.2em; font-size: 13px; line-height: 1.7; }
.ecg-note { font-size: 12.5px; line-height: 1.6; margin: 4px 0; }
.ecg-meta { font-size: 11.5px; color: var(--muted); margin: 6px 0 0; line-height: 1.6; }
.ecg-caution { font-size: 12px; color: var(--muted); background: var(--accent-soft); padding: 8px 10px; border-radius: 8px; margin: 10px 0 0; line-height: 1.6; }
.ecg-dialog { width: min(1100px, calc(100vw - 2 * var(--gutter))); }
.ecg-dialog h2 { font-size: 16px; margin: 0 0 8px; }
.ecg-large { display: block; width: 100%; height: auto; background: #fff; border-radius: 6px; }

/* ---- CAG（冠動脈造影）の撮影方向 2026-11-11〜 ---- */
.cag { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.cag h2 { color: var(--text); font-size: 15px; font-weight: 700; }
.cag-lead { font-size: 13px; line-height: 1.7; margin: 0 0 6px; color: var(--muted); }
.cag-for { font-size: 13px; line-height: 1.7; margin: 0 0 8px; background: var(--accent-soft); padding: 6px 8px; border-radius: 8px; }
.cag-views { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.cag-views button { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 7px 9px; cursor: pointer; min-height: 44px; }
.cag-views button b { font-size: 13.5px; }
.cag-views button b i { font-style: normal; color: #c0392b; margin-right: 4px; }
.cag-views button span { font-size: 11.5px; color: var(--muted); }
.cag-views button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.cag-note { display: block; margin: 4px 0 0; }
.cag-info { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; }
.cag-name { margin: 0 0 6px; font-size: 14px; }
.cag-row { margin: 4px 0; font-size: 12.5px; line-height: 1.8; display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: baseline; }
.cag-k { font-weight: 700; margin-right: 2px; }
.cag-part { background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 0 8px; }
.cag-part.on { border-color: #c0392b; color: #c0392b; font-weight: 700; }
.cag-desc { font-size: 12.5px; line-height: 1.7; margin: 6px 0 0; }
.cag-caution { font-size: 12px; color: var(--muted); background: var(--accent-soft); padding: 8px 10px; border-radius: 8px; margin: 10px 0 0; line-height: 1.6; }
.cag-src { font-size: 11.5px; color: var(--muted); margin: 6px 0 0; line-height: 1.6; }
.cag-side { display: flex; width: 100%; margin-top: 6px; }
.cag-side button { flex: 1; min-height: 36px; }
