:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --panel-2: #f6f8fb;
  --border: #dde3ea;
  --text: #17202b;
  --muted: #647183;
  --grid: #e8edf2;
  --zero: #b9c3cf;
  --accent: #0b7a5a;
  --paw: #b86e00;
  --flow: #0a8a55;
  --vol: #0a6fb0;
  --pmus: #c2346b;
  --ref: #7a5ad6;
  --trigger: #c2346b;
  --seg-mand: #8a97a8;
  --seg-assist: #0a6fb0;
  --seg-spont: #0a8a55;
  --warn: #b86e00;
  --alarm: #c62828;
  --async: #b0368a;
  --alarm-bg: #fdecec;
  --warn-bg: #fff4dc;
  --lung: #f2b8b5;
  --lung-stroke: #c9716c;
  --lung-warn: #f0a070;
  --lung-over: #e5534b;
  --chest: #c9d2dc;
  --shadow: 0 1px 2px rgba(20, 30, 45, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #070b10; --panel: #0e141c; --panel-2: #121a24; --border: #1f2a37; --text: #e6edf5; --muted: #8796a8;
    --grid: #17212c; --zero: #34414f; --accent: #3ddc97;
    --paw: #ffc53d; --flow: #3ddc97; --vol: #4cc9f0; --pmus: #ff6b9a; --ref: #b39dff; --trigger: #ff6b9a;
    --seg-mand: #6b7a8c; --seg-assist: #4cc9f0; --seg-spont: #3ddc97; --warn: #ffc53d; --alarm: #ff5c5c; --async: #f08fd8; --alarm-bg: #3a1216; --warn-bg: #33280c;
    --lung: #6e3a44; --lung-stroke: #d88a90; --lung-warn: #9a5a2c; --lung-over: #b5312f; --chest: #2c3845;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #070b10; --panel: #0e141c; --panel-2: #121a24; --border: #1f2a37; --text: #e6edf5; --muted: #8796a8;
  --grid: #17212c; --zero: #34414f; --accent: #3ddc97;
  --paw: #ffc53d; --flow: #3ddc97; --vol: #4cc9f0; --pmus: #ff6b9a; --ref: #b39dff; --trigger: #ff6b9a;
  --seg-mand: #6b7a8c; --seg-assist: #4cc9f0; --seg-spont: #3ddc97; --warn: #ffc53d; --alarm: #ff5c5c; --async: #f08fd8; --alarm-bg: #3a1216; --warn-bg: #33280c;
  --lung: #6e3a44; --lung-stroke: #d88a90; --lung-warn: #9a5a2c; --lung-over: #b5312f; --chest: #2c3845;
  --shadow: none; color-scheme: dark;
}

/* Hamilton 表示の配色（HAMILTON-C3 の公開画像に寄せた近似）
   ダーク = 実機に近い濃紺の画面・水色のボタン・Paw 黄 / Flow マゼンタ / Volume 緑。ライトは同じ色相の明るい版 */
:root[data-vendor="hamilton"] {
  --bg: #e6eaf7; --panel: #ffffff; --panel-2: #eef1fa; --border: #cbd2ec; --text: #121a4a; --muted: #586090;
  --grid: #e3e7f4; --zero: #98a1c6; --accent: #1689b8;
  --paw: #977a00; --flow: #b02a96; --vol: #1d9440; --pmus: #d9661a; --trigger: #d9661a;
  --seg-mand: #8a91b8; --seg-assist: #1689b8; --seg-spont: #1d9440;
  --mmp: #121a4a; --mmp-bg: #eef1fa;
  --ctl: #55c8ee; --ctl-text: #0b1846; --ctl-select: #e8c900; --ctl-active: #ff9a1f; --ctl-active-text: #1a0e00;
  --msg-yellow: #ffd83a; --dl-bg: #2456b8;
}
@media (prefers-color-scheme: dark) {
  :root[data-vendor="hamilton"]:not([data-theme="light"]) {
    --bg: #0b1036; --panel: #181f66; --panel-2: #10164e; --border: #36428f; --text: #ffffff; --muted: #aab3e4;
    --grid: #242d78; --zero: #cdd3f3; --accent: #55c8ee;
    --paw: #f2ecaa; --flow: #ec5fd0; --vol: #72e08a; --pmus: #ff9a3c; --trigger: #ff9a3c;
    --seg-mand: #8d95c8; --seg-assist: #55c8ee; --seg-spont: #72e08a;
    --warn: #ffd23f; --alarm: #ff4d4d; --warn-bg: #3a3410; --alarm-bg: #4a1020;
    --mmp: #ffffff; --mmp-bg: #0e1446;
    --ctl-select: #ffe94a; --dl-bg: #2251b5;
  }
}
:root[data-vendor="hamilton"][data-theme="dark"] {
  --bg: #0b1036; --panel: #181f66; --panel-2: #10164e; --border: #36428f; --text: #ffffff; --muted: #aab3e4;
  --grid: #242d78; --zero: #cdd3f3; --accent: #55c8ee;
  --paw: #f2ecaa; --flow: #ec5fd0; --vol: #72e08a; --pmus: #ff9a3c; --trigger: #ff9a3c;
  --seg-mand: #8d95c8; --seg-assist: #55c8ee; --seg-spont: #72e08a;
  --warn: #ffd23f; --alarm: #ff4d4d; --warn-bg: #3a3410; --alarm-bg: #4a1020;
  --mmp: #ffffff; --mmp-bg: #0e1446;
  --ctl-select: #ffe94a; --dl-bg: #2251b5;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, select, input { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand svg { width: 28px; height: 28px; color: var(--accent); }
.brand-title { font-weight: 700; letter-spacing: .02em; }
.brand-sub { font-size: 11px; color: var(--muted); }
.mode-chip {
  padding: 4px 10px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--border);
  font-weight: 700; color: var(--accent); cursor: help; white-space: nowrap;
}
.mode-chip small { font-weight: 400; color: var(--muted); margin-left: 6px; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sel { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.sel select { background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 4px 6px; }

.btn {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 7px;
  padding: 6px 12px; cursor: pointer; min-height: 34px; touch-action: manipulation;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn.icon { width: 36px; padding: 0; }
.btn.small { min-height: 28px; padding: 3px 10px; font-size: 12px; }
.btn.toggle[aria-pressed="true"], .btn.on { background: var(--accent); border-color: var(--accent); color: var(--panel); font-weight: 600; }
.btn.pending { border-color: var(--warn); color: var(--warn); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---- layout ---- */
.layout {
  display: grid; gap: 10px; padding: 10px 16px;
  grid-template-columns: minmax(0, 1fr) 330px;
  align-items: start;
}
.col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); min-width: 0; }
.panel-h { font-weight: 700; font-size: 13px; padding: 8px 12px 4px; }
.panel-h small { color: var(--muted); font-weight: 400; margin-left: 4px; }
.waves { grid-area: waves; padding: 6px 6px 4px; display: flex; flex-direction: column; }
.meas { grid-area: meas; display: flex; flex-direction: column; }
.lower { grid-area: lower; display: grid; grid-template-columns: 1fr 1fr 210px; gap: 4px; padding: 6px 6px 38px; position: relative; }
.patient { grid-area: patient; }
.settings { grid-area: settings; padding-bottom: 8px; }
.scenario { grid-area: scenario; }
.bga { grid-area: bga; }

.wave { height: 150px; }
.wave canvas, .loop canvas { width: 100%; height: 100%; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 11px; color: var(--muted); padding: 4px 8px 2px 36px; cursor: help; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.sw { display: inline-block; width: 16px; height: 4px; border-radius: 2px; }
.sw.mand { background: var(--seg-mand); } .sw.assist { background: var(--seg-assist); } .sw.spont { background: var(--seg-spont); }
.sw.pmus { background: repeating-linear-gradient(90deg, var(--pmus) 0 4px, transparent 4px 7px); }
.tri { color: var(--trigger); font-style: normal; font-size: 9px; }
.pmus-legend { display: none !important; }
body.show-pmus .pmus-legend { display: inline-flex !important; }

.loop { height: 230px; min-width: 0; }
.lungbox { display: flex; align-items: center; justify-content: center; min-width: 0; }
.lungbox svg { width: 100%; max-height: 230px; }
.loop-actions { position: absolute; right: 10px; bottom: 6px; display: flex; gap: 6px; }

/* ---- monitoring tiles ---- */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 4px 10px 8px; }
.tile { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 5px 8px 6px; cursor: help; min-width: 0; }
.tile .k { font-size: 11px; color: var(--muted); display: flex; justify-content: space-between; gap: 4px; white-space: nowrap; }
.tile .k b { color: var(--text); font-weight: 600; }
.tile .v { font-size: 22px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.tile.big .v { font-size: 26px; }
.tile.paw .v { color: var(--paw); } .tile.vol .v { color: var(--vol); } .tile.flow .v { color: var(--flow); }
.tile.warn .v { color: var(--warn); } .tile.alarm .v { color: var(--alarm); }
.tile .v.stale { opacity: .45; }
.maneuvers { display: flex; gap: 8px; padding: 0 10px; }
.maneuvers .btn { flex: 1; }
.status { font-size: 12px; color: var(--muted); padding: 6px 12px 10px; min-height: 2.6em; }

/* ---- patient sliders ---- */
.sliders { padding: 2px 12px 10px; display: grid; gap: 6px; }
.srow { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0 8px; }
.srow .lbl { font-size: 12px; cursor: help; }
.srow .lbl b { font-weight: 600; }
.srow .lbl small { color: var(--muted); margin-left: 4px; }
.srow .val { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; min-width: 70px; }
.srow .val small { font-weight: 400; color: var(--muted); font-size: 11px; margin-left: 2px; }
.srow input[type=range] { grid-column: 1 / -1; }
input[type=range] { width: 100%; accent-color: var(--accent); height: 22px; margin: 0; }

/* ---- vent settings ---- */
.settings-h { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 14px; padding-right: 12px; }
.modes { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 0; }
.modes .btn { min-width: 92px; font-weight: 600; }
.params { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; padding: 6px 12px 4px; }
.pcard { background: var(--panel-2); border: 1px solid var(--border); border-radius: 9px; padding: 6px 8px 6px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.pcard .lbl { display: flex; align-items: baseline; gap: 6px; cursor: help; white-space: nowrap; overflow: hidden; }
.pcard .lbl b { font-size: 14px; }
.pcard .lbl small { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.pcard .row { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.pcard .val { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; text-align: center; flex: 1; line-height: 1.1; }
.pcard .val small { font-size: 11px; font-weight: 400; color: var(--muted); margin-left: 3px; }
.pcard .pm { width: 38px; height: 38px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel); cursor: pointer; font-size: 20px; line-height: 1; touch-action: manipulation; user-select: none; }
.pcard .pm:active { background: var(--border); }
.pcard .seg { display: flex; gap: 4px; }
.pcard .seg .btn { flex: 1; min-height: 30px; padding: 2px 4px; font-size: 12px; }
.derived { font-size: 12px; color: var(--muted); padding: 4px 14px 0; display: flex; flex-wrap: wrap; gap: 4px 16px; }
.derived b { color: var(--text); font-variant-numeric: tabular-nums; }
.derived .warn { color: var(--warn); }

/* ---- lung svg ---- */
.lv-chest { fill: none; stroke: var(--chest); stroke-width: 3; }
.lv-rib { fill: none; stroke: var(--chest); stroke-width: 2; opacity: .6; }
.lv-lung { fill: var(--lung); stroke: var(--lung-stroke); stroke-width: 1.5; transition: fill .3s; }
.lv-lung.warn { fill: var(--lung-warn); }
.lv-lung.over { fill: var(--lung-over); }
.lv-airway { fill: none; stroke: var(--lung-stroke); stroke-width: 3; stroke-linecap: round; }
.lv-tube { fill: var(--panel-2); stroke: var(--muted); stroke-width: 1; }
.lv-dot { fill: var(--vol); }
.lv-dia { fill: none; stroke: var(--muted); stroke-width: 3; stroke-linecap: round; }
.lv-dia.active { stroke: var(--pmus); }
.lv-text { fill: var(--muted); font-size: 11px; font-family: inherit; }

/* ---- tooltip ---- */
.tooltip {
  position: fixed; z-index: 100; max-width: 320px; padding: 8px 10px; border-radius: 8px;
  background: var(--text); color: var(--bg); font-size: 12px; line-height: 1.55;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); pointer-events: none;
}

.foot { font-size: 11px; color: var(--muted); padding: 4px 16px 18px; }

/* ---- alarms ---- */
.alarmbar { display: flex; align-items: center; gap: 8px; padding: 2px 4px 6px 34px; min-height: 40px; flex-wrap: wrap; }
.alarm-list { flex: 1; display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.alarm-list .ok { font-size: 12px; color: var(--muted); padding: 4px 0; }
.alarm-actions { display: flex; gap: 6px; }
.al { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 6px; border: 1px solid; cursor: help; white-space: nowrap; }
.al.high { background: var(--alarm); border-color: var(--alarm); color: #fff; }
.al.high.active { animation: blink 1s steps(2, start) infinite; }
.al.medium { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); }
.al.low { background: var(--panel-2); border-color: var(--border); color: var(--muted); }
.al.latched { background: transparent; border-style: dashed; color: var(--muted); border-color: var(--muted); font-weight: 500; animation: none; }
@keyframes blink { to { opacity: .55; } }
@media (prefers-reduced-motion: reduce) { .al.high.active { animation: none; } }
.amk { font-style: normal; font-size: 9px; font-weight: 700; color: var(--async); border: 1px solid var(--async); border-radius: 3px; padding: 0 3px; }

/* ---- async panel ---- */
.async { padding: 2px 10px 12px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.async .ai { grid-column: 1 / -1; display: flex; align-items: baseline; gap: 8px; font-size: 12px; color: var(--muted); cursor: help; }
.async .ai b { font-size: 20px; color: var(--text); font-variant-numeric: tabular-nums; }
.async .ai.warn b { color: var(--warn); }
.async .ac { background: var(--panel-2); border: 1px solid var(--border); border-radius: 7px; padding: 3px 7px; font-size: 11px; color: var(--muted); cursor: help; display: flex; justify-content: space-between; gap: 4px; }
.async .ac b { color: var(--text); font-variant-numeric: tabular-nums; }
.async .ac.hit { border-color: var(--async); }
.async .ac.hit b { color: var(--async); }

/* ---- tabs ---- */
.tabs { display: flex; gap: 2px; padding: 6px 10px 0; border-bottom: 1px solid var(--border); }
.tab { background: none; border: none; border-bottom: 2px solid transparent; padding: 6px 12px; font-weight: 700; cursor: pointer; color: var(--muted); }
.tab small { font-weight: 400; margin-left: 4px; }
.tab.on { color: var(--text); border-bottom-color: var(--accent); }
.tabpane .modes { padding: 8px 12px 0; }

/* ---- patient extras ---- */
.subh { font-size: 11px; color: var(--muted); font-weight: 600; padding: 8px 12px 4px; display: flex; align-items: center; gap: 8px; }
.subh .btn { margin-left: auto; }
.pbw { font-weight: 400; }
.pbw b { color: var(--text); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px; }
.chips .btn { min-height: 30px; padding: 3px 10px; font-size: 12px; }
.chips.events .btn.on { background: var(--alarm); border-color: var(--alarm); color: #fff; }
.chips.events { padding-bottom: 12px; }
.body-row { display: flex; gap: 8px; padding: 0 12px; align-items: center; flex-wrap: wrap; }
.body-row label { font-size: 12px; display: flex; align-items: center; gap: 6px; }
.body-row input[type=number] { width: 72px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 4px 6px; }
.body-row .seg { display: flex; gap: 4px; }
.body-row .seg .btn { min-height: 30px; padding: 2px 10px; font-size: 12px; }
.srow .eff { font-size: 11px; color: var(--alarm); font-weight: 600; margin-left: 4px; }


/* ---- blood gas ---- */
.bga-live { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 2px 10px 6px; }
.bga-live .tile .v.ok { color: var(--flow); }
.bga-actions { padding: 0 10px 6px; display: flex; }
.bga-actions .btn { flex: 1; }
.bga-table { padding: 0 10px 10px; overflow-x: auto; }
.bga-table table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
.bga-table th, .bga-table td { padding: 3px 4px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
.bga-table th { color: var(--muted); font-weight: 500; font-size: 11px; }
.bga-table td:first-child, .bga-table th:first-child { text-align: left; }
.bga-table .lo { color: var(--vol); font-weight: 700; } .bga-table .hi { color: var(--alarm); font-weight: 700; }
.bga-table .empty { color: var(--muted); font-size: 12px; padding: 4px 0; }

/* ---- patient mask ---- */
.patient { position: relative; }
.mask { position: absolute; inset: 34px 0 0; background: color-mix(in srgb, var(--panel) 88%, transparent); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; text-align: center; color: var(--muted); font-size: 13px; border-radius: 0 0 10px 10px; z-index: 2; }
.mask b { color: var(--text); font-size: 15px; }

/* ---- scenario panel ---- */
.scenario { padding: 10px 14px 12px; border-color: var(--accent); }
.sc-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.sc-cat { font-size: 11px; color: var(--accent); border: 1px solid var(--accent); border-radius: 4px; padding: 1px 6px; margin-right: 8px; }
.sc-title { font-size: 16px; }
.sc-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.sc-brief { margin: 8px 0; font-size: 13px; line-height: 1.7; }
.sc-hint { background: var(--warn-bg); border-left: 3px solid var(--warn); padding: 6px 10px; font-size: 13px; margin-bottom: 8px; border-radius: 4px; }
.task { margin: 8px 0; }
.tq { font-weight: 700; font-size: 13px; margin-bottom: 6px; }
.opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 6px; }
.opt { text-align: left; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; cursor: pointer; font-size: 13px; line-height: 1.45; }
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt:disabled { cursor: default; }
.opt.right { border-color: var(--flow); background: color-mix(in srgb, var(--flow) 14%, var(--panel)); font-weight: 600; }
.opt.wrong { border-color: var(--alarm); background: var(--alarm-bg); }
.opt.dim { opacity: .5; }
.explain { margin-top: 6px; font-size: 13px; line-height: 1.65; padding: 6px 10px; border-radius: 6px; background: var(--panel-2); }
.explain.ok b { color: var(--flow); } .explain.ng b { color: var(--alarm); }
.explain b { margin-right: 6px; }
.goals, .rlist { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.goals li, .rlist li { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 4px 8px; border-radius: 6px; background: var(--panel-2); }
.goals .gl { flex: 1; }
.goals .gv { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; text-align: right; }
.gi { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--muted); flex: none; position: relative; }
.goals li.ok .gi, .rlist li.ok .gi { border-color: var(--flow); background: var(--flow); }
.goals li.ok .gi::after, .rlist li.ok .gi::after { content: ''; position: absolute; left: 4px; top: 1px; width: 4px; height: 8px; border: solid var(--panel); border-width: 0 2px 2px 0; transform: rotate(45deg); }
.rlist li.ng .gi { border-color: var(--alarm); }
.goals li.ok .gv { color: var(--flow); }
.sc-foot { display: flex; align-items: center; gap: 10px; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 8px; flex-wrap: wrap; }
.sc-foot .btn { min-width: 110px; }
.result { margin-top: 10px; }
.score { font-size: 13px; margin-bottom: 6px; }
.score b { font-size: 32px; color: var(--accent); margin-right: 2px; }
.debrief { margin-top: 8px; font-size: 13px; line-height: 1.7; padding: 8px 10px; border-left: 3px solid var(--accent); background: var(--panel-2); border-radius: 4px; }
.debrief b { margin-right: 6px; }

/* ---- scenario dialog ---- */
.scen-dialog { width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.scen-dialog::backdrop { background: rgba(0,0,0,.45); }
.sd-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 16px; }
.sd-sum { font-size: 12px; color: var(--muted); margin-left: 8px; }
.sd-list { padding: 12px 16px; display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); overflow-y: auto; max-height: calc(100vh - 170px); }
.sd-card { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--panel-2); display: flex; flex-direction: column; gap: 6px; }
.sd-card .t { font-weight: 700; }
.sd-card .d { font-size: 12px; color: var(--muted); line-height: 1.55; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.sd-card .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sd-card .rec { font-size: 12px; color: var(--muted); }
.sd-card .rec b { color: var(--accent); font-size: 14px; }
.sd-card .rec.none { opacity: .7; }
.sd-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }
@media (max-width: 520px) { .sd-list { grid-template-columns: 1fr; } .opts { grid-template-columns: 1fr; } }

/* ---- monitor (waveforms + main monitoring parameters) ---- */
.mmp, .mainctl, .dl-info { display: none; }

/* ---- Hamilton display style ---- */
:root[data-vendor="hamilton"] .monitor { display: grid; grid-template-columns: 150px minmax(0, 1fr) 100px; gap: 6px; }
:root[data-vendor="hamilton"] .wavecol { min-width: 0; }
:root[data-vendor="hamilton"] .legend { padding-left: 190px; }
:root[data-vendor="hamilton"] .alarmbar { padding-left: 4px; }

/* MMP：左に アラーム上限／下限、右に 大きな値と 名前・単位 */
:root[data-vendor="hamilton"] .mmp { display: flex; flex-direction: column; background: var(--mmp-bg); border-radius: 6px; overflow: hidden; }
.mmp-item { flex: 1; display: grid; grid-template-columns: auto 1fr; gap: 4px; padding: 4px 8px; border-bottom: 1px solid var(--border); min-height: 0; }
.mmp-item:last-child { border-bottom: none; }
.mmp-item .lim { display: flex; flex-direction: column; justify-content: space-between; font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; padding: 2px 0; }
.mmp-item .main { display: flex; flex-direction: column; justify-content: center; align-items: flex-end; min-width: 0; }
.mmp-item .v { font-size: 30px; font-weight: 700; line-height: 1.05; font-variant-numeric: tabular-nums; color: var(--mmp); }
.mmp-item .k { font-size: 11px; font-weight: 600; line-height: 1.2; text-align: right; color: var(--text); }
.mmp-item .k span { font-weight: 400; color: var(--muted); font-size: 10px; }
.mmp-item.warn .v { color: var(--warn); }
.mmp-item.alarm .v { color: var(--alarm); }

/* 主要設定：丸いボタン（タップで選択 → オレンジで調整中） */
:root[data-vendor="hamilton"] .mainctl { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 4px 0; }
.rc { background: none; border: none; padding: 0; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--text); touch-action: manipulation; }
.rc-dial { width: 64px; height: 64px; border-radius: 50%; background: var(--ctl); color: var(--ctl-text); display: flex; flex-direction: column; align-items: center; justify-content: center; border: 3px solid transparent; transition: background .15s; }
.rc-dial b { font-size: 20px; line-height: 1; font-variant-numeric: tabular-nums; }
.rc-dial small { font-size: 9px; }
.rc-l { font-size: 11px; font-weight: 700; white-space: nowrap; }
.rc:hover .rc-dial, .rc:focus-visible .rc-dial { border-color: var(--ctl-select); }
.rc.active .rc-dial { background: var(--ctl-active); color: var(--ctl-active-text); border-color: var(--ctl-select); }
.rc-adj { display: flex; gap: 6px; }
.rc-adj[hidden] { display: none; }
.rc-adj .pm { width: 40px; height: 34px; border-radius: 8px; border: 1px solid var(--ctl-active); background: var(--panel); font-size: 18px; cursor: pointer; touch-action: manipulation; user-select: none; }
.rc-nav { display: flex; flex-direction: column; gap: 6px; width: 100%; margin-top: auto; }
.rc-nav .btn { background: var(--ctl); border-color: var(--ctl); color: var(--ctl-text); font-weight: 700; }

/* 設定パネル・ボタン */
:root[data-vendor="hamilton"] .btn.on, :root[data-vendor="hamilton"] .btn.toggle[aria-pressed="true"] { color: var(--ctl-text); }
:root[data-vendor="hamilton"] .pcard .lbl b { color: var(--accent); }

/* メッセージバー：高優先度 赤、中・低優先度 黄 */
:root[data-vendor="hamilton"] .al.medium, :root[data-vendor="hamilton"] .al.low { background: var(--msg-yellow); border-color: var(--msg-yellow); color: #1a1600; }
:root[data-vendor="hamilton"] .al.latched { background: transparent; color: var(--muted); border-color: var(--muted); }

/* Dynamic Lung：青いパネルに白い肺、左に Rinsp / Cstat / RCexp */
@media (min-width: 1181px) { :root[data-vendor="hamilton"] .lower { grid-template-columns: 1fr 1fr 300px; } }
:root[data-vendor="hamilton"] .lungbox {
  display: grid; grid-template-columns: 104px minmax(0, 1fr); align-items: center; gap: 4px;
  background: var(--dl-bg); border-radius: 8px; padding: 6px; color: #fff;
  --lung: #f3f6ff; --lung-stroke: #b9c8f5; --lung-warn: #ffd9a8; --lung-over: #ff9b9b; --chest: rgba(255,255,255,.35); --muted: #d4ddff; --vol: #ffe066; --panel-2: rgba(255,255,255,.12);
}
:root[data-vendor="hamilton"] .lungbox svg { grid-column: 2; grid-row: 1; max-height: 200px; }
:root[data-vendor="hamilton"] .dl-info { display: flex; flex-direction: column; gap: 6px; grid-column: 1; grid-row: 1; }
.dl-info .dl-h { font-size: 11px; font-weight: 700; }
.dl-info > div:not(.dl-h) { display: flex; flex-direction: column; cursor: help; min-width: 0; line-height: 1.15; }
.dl-info b { font-size: 20px; font-variant-numeric: tabular-nums; order: -1; }
.dl-info span { font-size: 11px; font-weight: 600; }
.dl-info small { font-size: 9px; opacity: .8; white-space: nowrap; }

/* ---- responsive ---- */
@media (max-width: 860px) { .col { display: contents; } }
@media (max-width: 1180px) {
  .layout { grid-template-columns: minmax(0, 1fr) 300px; }
  .lower { grid-template-columns: 1fr 1fr; }
  .lungbox { grid-column: 1 / -1; height: 200px; }
  .lungbox svg { max-height: 200px; }
  .loop-actions { position: static; grid-column: 1 / -1; justify-content: flex-end; }
  .lower { padding-bottom: 6px; }
}
@media (max-width: 860px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "scenario" "waves" "meas" "bga" "settings" "lower" "patient";
    align-items: stretch;
    padding: 8px;
  }
  .topbar { padding: 8px 16px; position: static; }
  .top-actions { margin-left: 0; }
  .wave { height: 120px; }
  .loop { height: 200px; }
  .tiles { grid-template-columns: repeat(4, 1fr); }
  .params { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}
@media (max-width: 520px) {
  .layout { padding: 8px 6px; }
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .lower { grid-template-columns: 1fr; }
  .brand-sub { display: none; }
  .modes .btn { min-width: 0; flex: 1 1 30%; }
}
@media (max-width: 620px) {
  /* 狭い画面では MMP を波形の上、主要設定を波形の下に横並び */
  :root[data-vendor="hamilton"] .monitor { grid-template-columns: minmax(0, 1fr); }
  :root[data-vendor="hamilton"] .mmp { display: grid; grid-template-columns: repeat(3, 1fr); }
  :root[data-vendor="hamilton"] .mmp-item { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); }
  :root[data-vendor="hamilton"] .mmp-item .v { font-size: 22px; }
  :root[data-vendor="hamilton"] .mainctl { flex-direction: row; flex-wrap: wrap; justify-content: center; }
  :root[data-vendor="hamilton"] .rc-nav { flex-direction: row; width: auto; margin-top: 0; }
  :root[data-vendor="hamilton"] .legend { padding-left: 36px; }
}
