:root {
  --bg: #0f1216; --panel: #171b21; --fg: #e8e9ec; --fg-muted: #9aa3ad; --line: #2a313a;
  --accent: #ffd54a; --accent-2: #7fb3ff; --danger: #ff5c5c; --ok: #6fd58a;
  --ecg-bg: #fff8f5; --ecg-grid-minor: #f6d9d4; --ecg-grid-major: #eeb3aa; --ecg-trace: #111; --ecg-ref: #6b7c93;
  --cursor: #1f6fff; --mark-p: #b0651c; --mark-qrs: #1d4ed8; --mark-blocked: #c62828;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.5 system-ui, -apple-system, "Noto Sans TC", sans-serif; }
button { font: inherit; color: var(--fg); background: #232a33; border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; cursor: pointer; }
button:hover { background: #2c3541; }
button.active, button.primary { background: var(--accent); color: #1a1500; border-color: transparent; font-weight: 600; }
button.ghost { background: transparent; }
button.tiny { padding: 2px 8px; font-size: 12px; }
select, input[type=number] { font: inherit; background: #10141a; color: var(--fg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; width: 100%; }

.top { display: flex; align-items: center; gap: 16px; padding: 8px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 18px; }
.brand .sub { font-weight: 400; color: var(--fg-muted); margin-left: 8px; font-size: 13px; }
.banner { background: #3a2f10; color: #ffe9a8; border: 1px solid #7a6320; border-radius: 6px; padding: 4px 10px; font-size: 13px; }

.layout { display: grid; grid-template-columns: 1fr 340px; gap: 12px; padding: 12px 16px; min-height: calc(100vh - 100px); }
.stage { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.heart-wrap { position: relative; height: 46vh; min-height: 300px; background: radial-gradient(ellipse at 50% 40%, #1b222c, #0f1216 70%); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
#heart, #heart canvas { width: 100%; height: 100%; display: block; }
.nogl { padding: 40px; color: var(--fg-muted); text-align: center; }
.veil { position: absolute; inset: 0; background: #0a0c10; display: flex; align-items: center; justify-content: center; text-align: center; font-size: 20px; color: var(--fg-muted); z-index: 3; }
.veil small { font-size: 13px; }
.phase-box { position: absolute; left: 12px; top: 10px; background: rgba(0,0,0,.55); padding: 6px 10px; border-radius: 6px; max-width: 70%; }
.phase-label { color: var(--fg-muted); font-size: 12px; margin-right: 6px; }
#phase[data-key="p"] { color: #ffd166; } #phase[data-key^="qrs"] { color: #ffe14d; } #phase[data-key="pr"], #phase[data-key="his"] { color: #9be7ff; }
#phase[data-key="blocked"] { color: var(--danger); } #phase[data-key="t"] { color: var(--accent-2); }
.legend { position: absolute; left: 12px; bottom: 10px; display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--fg-muted); background: rgba(0,0,0,.45); padding: 6px 8px; border-radius: 6px; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.sw-elec { background: linear-gradient(90deg, #ffe14d, #7fb3ff); } .sw-mech { background: #c96a6a; border: 1px dashed #fff; } .sw-path { background: #9be7ff; }
#reset-view { position: absolute; right: 10px; top: 10px; }

.mech { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--fg-muted); }
.mech-row { display: flex; align-items: center; gap: 8px; }
.bar { width: 120px; height: 8px; background: #232a33; border-radius: 4px; overflow: hidden; }
.bar div { height: 100%; width: 0; background: #c96a6a; }
.mech-note { flex-basis: 100%; }

.ecg-wrap { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--ecg-bg); }
.ecg-head { display: flex; justify-content: space-between; gap: 8px; padding: 4px 10px; font-size: 12px; color: #5a3d38; background: #fbe9e4; flex-wrap: wrap; }
#ecg { width: 100%; height: 200px; display: block; cursor: col-resize; touch-action: none; }
body:not([data-mode="quiz"]) #ecg.two { height: 320px; }
.ecg-hint { padding: 4px 10px; font-size: 12px; color: #6b4e49; background: #fbe9e4; }

.controls { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.speed { margin-left: auto; color: var(--fg-muted); font-size: 12px; display: flex; gap: 4px; align-items: center; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; overflow: auto; }
.mode-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.mode-tabs button { flex: 1; }
.field { display: block; color: var(--fg-muted); font-size: 12px; margin-bottom: 8px; }
.panel h2 { font-size: 17px; margin: 6px 0 4px; }
.panel h3 { font-size: 13px; color: var(--fg-muted); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .04em; }
.vignette { margin: 0 0 4px; }
.source { color: var(--fg-muted); font-size: 12px; margin: 4px 0; }
.check, .radio { display: block; margin: 4px 0; }
.steps { padding-left: 18px; margin: 0; color: #cfd5dc; }
.steps li { margin: 4px 0; }
.q { margin: 10px 0; } .q label { display: block; } .q input[type=number] { margin-top: 4px; }
.q-title { margin-bottom: 4px; }
.hint { color: var(--fg-muted); font-size: 12px; }
form button.primary { width: 100%; margin-top: 8px; }
.score { font-size: 20px; font-weight: 700; margin: 6px 0; }
table.result { width: 100%; border-collapse: collapse; font-size: 13px; }
table.result th, table.result td { border-bottom: 1px solid var(--line); padding: 4px 6px; text-align: left; vertical-align: top; }
table.result td small { display: block; color: var(--fg-muted); }
tr.ok td:first-child::before { content: "✓ "; color: var(--ok); } tr.bad td:first-child::before { content: "✗ "; color: var(--danger); }
.explain { padding-left: 18px; }
.explain li { margin: 6px 0; }
.foot { display: flex; justify-content: space-between; gap: 12px; padding: 8px 16px; color: var(--fg-muted); font-size: 12px; border-top: 1px solid var(--line); flex-wrap: wrap; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .heart-wrap { height: 40vh; }
  .legend { display: none; }
}

/* 3D teaching stage: the model is the visual anchor. */
.heart-wrap { height: 58vh; min-height: 480px; background: radial-gradient(ellipse at 48% 42%, #27313e 0%, #131b26 45%, #0b111a 85%); }
#heart { position: relative; }
.heart-toolbar { position: absolute; top: 54px; left: 18px; display: flex; gap: 4px; padding: 3px; border: 1px solid #344353; border-radius: 8px; background: #111b28df; }
.heart-toolbar button { padding: 5px 12px; font-size: 12px; background: transparent; border: 0; color: #a8b6c7; }
.heart-toolbar button.active { background: #dce6ed; color: #172330; }
.heart-caption { position: absolute; right: 18px; bottom: 18px; text-align: right; font-size: 11px; color: #aab9c9; pointer-events: none; letter-spacing: .04em; }
.heart-caption span { color: #6f8298; }
.anatomy-label { position: absolute; padding: 3px 9px; transform: translate(12px,-50%); border-left: 1px solid #9ab4c3; color: #e3eaf1; background: #101923bb; font-size: 11px; white-space: nowrap; pointer-events: none; }
.anatomy-label::before { content: ''; position: absolute; top: 50%; right: 100%; width: 12px; height: 1px; background: #9ab4c3; }
.phase-box { left: 18px; top: 14px; background: transparent; padding: 0; max-width: calc(100% - 130px); font-size: 12px; }
.legend { left: 18px; bottom: 15px; background: transparent; font-size: 11px; max-width: 64%; }
#reset-view { right: 16px; top: 14px; }
@media (max-width: 600px) {
  .heart-wrap { min-height: 430px; height: 58vh; }
  .heart-caption { font-size: 10px; bottom: 10px; }
  .anatomy-label { font-size: 10px; padding: 2px 5px; }
  .heart-toolbar { top: 66px; }
}
