/* EKG Studio app styles. Tokens, fonts, element defaults, the platform header
   and the settings sidebar come from kardio-tokens.css / kardio-fonts.css /
   kardio-base.css / kardio-header.css / kardio-sidebar.css (generated from
   packages/design — shared with EchoSchema and the course). Signal paper is
   independent. */
button { box-shadow:none; }
/* Platform links only exist when served inside the Kardio platform (/ekg/):
   js/kardio-platform.js marks <html> before first paint, so nothing shifts. */
html:not(.kardio-platform) .platform-nav { display:none; }
/* In the platform, Elektrophysiologie is a top-level item ("EP" in the
   platform switch, /ep/ → ./?mode=ep), so its mode tab goes. Standalone
   builds have no platform switch and keep the tab. */
html.kardio-platform .mode-tab[data-mode="ep"] { display:none; }
/* html.ekg-ep (js/kardio-platform.js, kept in sync by switchMode): "EP" is
   current from the first frame, before app.js moves aria-current, and the
   Studio does not flash before the EP workspace opens. */
html.ekg-ep .platform-nav a[data-nav="ekg"][aria-current] { color:var(--muted); background:transparent; }
html.ekg-ep .platform-nav a[data-nav="ep"] { color:var(--accent-ink); background:var(--accent-soft); }
/* The same for the bottom tab bar (phones; kardio-tabbar.css). */
html.ekg-ep #platform-tabbar a[data-nav="ekg"][aria-current] { color:var(--muted); }
html.ekg-ep #platform-tabbar a[data-nav="ekg"][aria-current] .tabbar-icon { background:transparent; }
html.ekg-ep #platform-tabbar a[data-nav="ep"] { color:var(--accent-ink); }
html.ekg-ep #platform-tabbar a[data-nav="ep"] .tabbar-icon { background:var(--accent-soft); }
html.ekg-ep #view-generator { visibility:hidden; }
/* EP mode in the platform (EKG-W2 / EP-12): the header slot holds the EP areas
   (Bildatlas · Grundlagen) instead of the ECG modes; the in-page area tabs go.
   Standalone builds keep the ECG mode tabs and the in-page tabs. */
#ep-area-nav { display:none; }
html.kardio-platform.ekg-ep .header-app > .mode-tabs:not(#ep-area-nav) { display:none; }
html.kardio-platform.ekg-ep #ep-area-nav { display:flex; }
html.kardio-platform #view-ep .ep-area-tabs { display:none; }
@media (min-width:961px), (min-width:901px) and (min-height:501px) { html.kardio-platform #view-ep .ep-subarea>.controls { padding-top:var(--sidebar-pad); } }
.control-group select,.control-group input[type="number"],.control-group input[type="text"] { background:var(--surface); color:var(--ink); border:1px solid var(--line); border-radius:var(--radius-input); padding:10px 11px; min-height:40px; max-width:100%; }
.container { grid-template-columns:310px minmax(0,1fr); gap:0; padding:0; }
.controls h2 { text-transform:none; letter-spacing:-.25px; color:var(--ink); font-size:15px; margin:0 0 16px; }
.panel-heading h2 { font-size:19px; line-height:1.4; margin-top:9px; }
.compose-button { display:flex; justify-content:space-between; width:100%; margin:20px 0; color:var(--accent-ink); background:var(--accent-soft); border:1px solid var(--line); font-size:12px; }
.compose-button:hover { background:var(--surface-soft); }
#pathology-search { width:100%; }
.form-field>label { color:var(--muted); font-size:12px; font-weight:500; margin-bottom:8px; }
.pathology-description,.layout-description { background:none; border:0; color:var(--muted); font-size:12px; line-height:1.65; padding:0; }
.pathology-explanation { background:var(--surface-soft); border:0; color:var(--ink); font-size:12px; margin:16px 0 22px; }
.pathology-explanation summary { color:var(--accent); font-weight:600; }
.pathology-explanation-text { color:var(--muted); line-height:1.7; }
.sidebar-footer { padding-top:18px; border-top:1px solid var(--line); font-size:10px; color:var(--muted); line-height:1.6; }
.studio-viewport { border:0; border-radius:0; padding:30px 32px; overflow:hidden; min-width:0; background:var(--bg); }
.workspace-heading { display:flex; justify-content:space-between; align-items:center; gap:24px; margin-bottom:26px; }
.workspace-heading h1 { font-size:clamp(23px,2.1vw,33px); font-weight:500; letter-spacing:-1.1px; margin:9px 0 0; line-height:1.25; }
.workspace-heading p { color:var(--muted); margin-bottom:0; }
.workspace-heading>button { width:auto; flex:none; font-size:12px; white-space:nowrap; }
.studio-toolbar { display:flex; justify-content:space-between; align-items:center; gap:10px; flex-wrap:wrap; padding:10px; border:1px solid var(--line); border-radius:13px; background:var(--surface); margin-bottom:20px; }
.toolbar-group { display:flex; align-items:center; gap:6px; flex-wrap:wrap; }
.studio-toolbar button,.studio-toolbar select { font-size:12px; min-height:36px; padding:8px 10px; }
.toolbar-divider { width:1px; height:18px; background:var(--line); margin:0 3px; }
.info { color:var(--muted); background:transparent; border:0; line-height:1.9; margin:0 0 18px; padding:0; font-size:11px; }
.info strong { color:var(--ink); font-size:14px; font-weight:600; }
.ecg-sheets { overflow-x:auto; padding:5px 3px 20px; gap:24px; }
.ecg-sheet-wrapper { max-width:100%; margin:0 0 22px; }
.ecg-sheet-frame { width:fit-content; max-width:100%; border-radius:5px; box-shadow:var(--shadow); background:white; }
canvas.ecg-sheet { border:1px solid #e2dcd8; border-radius:4px; box-shadow:none; }
.ecg-sheet-header { color:var(--muted); font-size:11px; }
.legend { color:var(--muted); font-size:10px; padding:0; gap:20px; }
.seed-row { flex-wrap:wrap; }
.seed-row input[type="number"] { width:135px; }
.check-row { display:flex; align-items:center; gap:9px; color:var(--muted); font-size:12px; line-height:1.5; margin:12px 0; }
.muted { color:var(--muted); line-height:1.65; font-size:12px; }
.help-text { color:var(--muted); font-size:11px; line-height:1.6; }
.studio-warnings { border:1px solid #dcc083; background:#fff7e1; color:#775320; padding:12px 16px; border-radius:10px; margin-bottom:16px; font-size:12px; line-height:1.7; }
.sequence-overview { display:flex; gap:4px; margin-bottom:18px; }
.sequence-chip { min-width:0; border-top:3px solid var(--accent); padding:8px 10px; background:var(--accent-soft); font-size:10px; color:var(--ink); }
.sequence-chip strong { display:block; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.sequence-row { background:var(--surface-soft); border:1px solid var(--line); padding:10px; border-radius:9px; margin-bottom:8px; }
.sequence-row select { width:100%; font-size:11px; }
.sequence-values { display:flex; flex-wrap:wrap; align-items:end; gap:6px; margin-top:8px; }
.sequence-values label { flex:1; color:var(--muted); font-size:10px; }
.sequence-values input { width:100%; margin-top:4px; padding:7px; min-height:32px; }
.sequence-values button { padding:6px; min-width:28px; }
.library-view { max-width:1600px; margin:auto; padding:36px; }
.library-filters { display:flex; align-items:center; gap:12px; margin:28px 0 12px; flex-wrap:wrap; }
.library-filters input { margin-left:auto; }
.segmented { display:flex; padding:4px; border:1px solid var(--line); border-radius:12px; background:var(--surface); }
.segmented button { background:transparent; color:var(--muted); font-size:12px; }
.segmented button.active { background:var(--accent-soft); color:var(--accent-ink); }
.library-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(265px,1fr)); gap:20px; }
.library-card { border:1px solid var(--line); border-radius:14px; overflow:hidden; background:var(--surface); display:flex; flex-direction:column; }
.library-card canvas { width:100%; height:100px; background:#fcfaf8; }
.card-body { padding:19px; flex:1; display:flex; flex-direction:column; }
.card-body .eyebrow { font-size:9px; }
.card-body h3 { margin:9px 0; font-weight:550; letter-spacing:-.3px; font-size:16px; }
.card-body p { color:var(--muted); font-size:12px; line-height:1.65; flex:1; }
.card-actions { display:flex; gap:5px; flex-wrap:wrap; margin-top:12px; }
.card-actions button { font-size:11px; padding:8px 10px; }
.empty-state { grid-column:1/-1; padding:70px 20px; text-align:center; border:1px dashed var(--line); border-radius:16px; color:var(--muted); }
dialog { border:1px solid var(--line); border-radius:18px; padding:28px; background:var(--surface); color:var(--ink); width:min(640px,calc(100vw - 32px)); max-height:90vh; box-shadow:0 25px 100px #0003; }
dialog::backdrop { background:#142b2866; backdrop-filter:blur(4px); }
.dialog-heading { display:flex; align-items:start; justify-content:space-between; gap:20px; margin-bottom:15px; }
.dialog-heading h2 { margin:8px 0 0; font-size:25px; font-weight:500; letter-spacing:-.7px; }
.dialog-heading>button { font-size:22px; padding:2px 10px; }
.dialog-actions { display:flex; justify-content:flex-end; gap:8px; margin-top:22px; flex-wrap:wrap; }
.form-field { display:flex; flex-direction:column; margin:15px 0; }
.form-row { display:grid; grid-template-columns:1fr 1fr; gap:12px; }
.export-grid { display:grid; grid-template-columns:repeat(3,1fr); gap:12px; margin:24px 0; }
.export-grid button { text-align:left; padding:18px; background:var(--surface-soft); color:var(--ink); border:1px solid var(--line); }
.export-grid button:hover { border-color:var(--accent); }
.export-grid strong { display:block; font-size:20px; margin-bottom:8px; }
.export-grid span { font-size:10px; color:var(--muted); font-weight:400; }
.toast { position:fixed; bottom:24px; left:50%; transform:translateX(-50%); z-index:50; background:var(--ink); color:var(--surface); border-radius:12px; box-shadow:var(--shadow); padding:12px 22px; max-width:90vw; font-size:13px; pointer-events:none; opacity:0; }
.toast.visible { opacity:1; }
.focus-mode #view-generator { grid-template-columns:1fr; }
.focus-mode #view-generator>.controls,.focus-mode .workspace-heading { display:none; }
.zoomed .ecg-sheet-wrapper,.zoomed .ecg-sheet-frame { max-width:none; }
.zoomed canvas.ecg-sheet { max-width:none; }
.quiz-score { background:var(--accent-soft); color:var(--accent-ink); border-radius:9px; }
.quiz-instruction,.quiz-tip { color:var(--muted); background:none; line-height:1.7; }
.quiz-option { background:var(--surface); border-color:var(--line); color:var(--ink); text-align:left; }
.quiz-option:hover { background:var(--surface-soft); border-color:var(--accent); }
.quiz-option.correct { background:var(--accent-soft); color:var(--accent-ink); border-color:var(--accent); }
.quiz-option:disabled { opacity:1; }
.quiz-option.incorrect { background:#fce8e5; color:#94362d; border-color:#e9aaa2; }
.quiz-result { background:var(--surface-soft); color:var(--ink); border-color:var(--line); line-height:1.8; }
.quiz-result span[style] { color:var(--accent)!important; }
.monitor-viewport { padding:30px; }
.monitor-screen { border-radius:16px; overflow:hidden; border-color:#25403b; }
.monitor-screen .info { padding:16px; color:#a1b9b0; }
.monitor-screen .info strong { color:#e7f2ed; }
#presentation-dialog { width:min(1220px,96vw); padding:24px; }
.presentation-canvas { max-height:52vh; overflow:auto; }
.presentation-canvas .ecg-sheet-wrapper { margin-bottom:15px; }
.presentation-canvas canvas { max-width:100%; height:auto; }
.presentation-question { font-size:18px; line-height:1.6; max-width:85ch; }
.presentation-answer { background:var(--accent-soft); border-radius:10px; padding:16px; line-height:1.6; }
.presenter-notes { margin:16px 0; font-size:12px; color:var(--muted); white-space:pre-wrap; }
.stage-list { display:flex; gap:6px; flex-wrap:wrap; margin:12px 0; }
.stage-list button { font-size:11px; }
.stage-list .active { background:var(--accent); color:var(--on-accent); }
.sr-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0; }
.skip-link { position:fixed; top:-80px; left:16px; z-index:100; background:var(--surface); padding:12px; }
.skip-link:focus { top:12px; }
[hidden] { display:none!important; }
@media (max-width:1200px) { .studio-viewport { padding:24px; } .workspace-heading { align-items:start; } .workspace-heading>button { max-width:150px; white-space:normal; } }
@media (max-width:900px), (max-width:960px) and (max-height:500px) { .container { grid-template-columns:1fr; } .sidebar-footer { display:none; } .panel-heading h2 { margin-bottom:12px; } .compose-button { margin:12px 0; } .workspace-heading { flex-wrap:wrap; gap:14px; } .workspace-heading>button { max-width:none; } .library-view { padding:24px; } .library-filters input { margin-left:0; flex:1; min-width:150px; } }
@media (max-width:767px) { .studio-viewport { padding:20px 14px; } .studio-toolbar { gap:5px; } .workspace-heading h1 { font-size:26px; } .workspace-heading .eyebrow { font-size:9px; } .ecg-mobile-host { width:100%; } .mobile-lead-labels { color:#273c35; } .library-view { padding:22px 16px; } .library-grid { grid-template-columns:1fr; } .segmented { width:100%; } .segmented button { flex:1; padding:10px 7px; } .export-grid { grid-template-columns:repeat(2,1fr); } .form-row { grid-template-columns:1fr; gap:0; } dialog { padding:20px; } .legend { line-height:1.6; } .monitor-viewport { padding:14px; } }
@media (hover:none) and (pointer:coarse) { button,select,input:not([type="range"]):not([type="checkbox"]) { min-height:44px; } input,select,textarea { font-size:16px; } }
@media (prefers-reduced-motion:reduce) { * { transition:none!important; scroll-behavior:auto!important; } }
@media print { .app-header,.disclaimer,.controls,.studio-toolbar,.workspace-heading,.legend,.studio-warnings,.sequence-overview,.info,.toast,.skip-link,dialog,.library-view { display:none!important; } body { background:white; } .container { display:block; } .studio-viewport { padding:0; overflow:visible; } .ecg-sheets { overflow:visible; padding:0; } .ecg-sheet-wrapper { box-shadow:none; margin:0; break-after:page; } .ecg-sheet-frame { box-shadow:none; } canvas.ecg-sheet { border:0; border-radius:0; } }
.embed .app-header,.embed .disclaimer,.embed .workspace-heading,.embed .studio-toolbar,.embed .studio-warnings,.embed .sequence-overview,.embed .controls { display:none!important; }
.embed #view-generator { grid-template-columns:1fr; }
.embed .studio-viewport { padding:0; }

#view-quiz>.viewport { background:var(--bg); border:0; border-radius:0; padding:28px; }

/* A laptop workspace: fit the page in both dimensions, keep tools within reach. */
#advanced-settings { width:100%; margin-top:14px; font-size:12px; }
.settings-pane { display:flex; flex-direction:column; gap:10px; height:100%; min-height:0; }
.settings-pane>button { align-self:flex-start; padding:6px 0; font-size:11px; }
.settings-pane h2 { margin:4px 0 0; font-size:19px; }
.settings-pane>.help-text { margin:0 0 4px; }
.settings-content { flex:1; min-width:0; min-height:0; overflow:auto; padding:8px 2px 4px; }
.settings-content .settings-panel { border:0; border-bottom:1px solid var(--line); }
.settings-content .settings-panel>summary { display:flex; padding:13px 0; }
.settings-content .settings-panel[open]>summary { color:var(--accent); }
.settings-content .settings-body { padding:4px 0 14px; }
.settings-content select,.settings-content input[type="text"] { width:100%; }
.sheet-navigation { display:flex; align-items:center; justify-content:center; gap:12px; font-size:11px; color:var(--muted); }
.sheet-navigation button { padding:5px 12px; }
@media screen and (min-width:961px), screen and (min-width:901px) and (min-height:501px) {
  body:not(.embed) { height:100dvh; min-height:0; display:flex; flex-direction:column; overflow:hidden; }
  body:not(.embed)>.container { flex:1; min-height:0; grid-template-columns:var(--sidebar-w) minmax(0,1fr); }
  body:not(.embed) .controls { height:100%; }
  .panel-heading h2 { font-size:17px; margin:7px 0 12px; }
  .compose-button { margin:12px 0; padding:10px; }
  #view-generator .pathology-explanation { margin:10px 0; padding:10px; }
  .sidebar-footer { margin-top:16px; padding-top:12px; }
  .studio-viewport { display:flex; flex-direction:column; padding:22px 24px 14px; min-height:0; }
  .studio-viewport>* { flex-shrink:0; }
  .workspace-heading { margin-bottom:18px; gap:12px; }
  .workspace-heading h1 { font-size:25px; margin-top:6px; }
  .studio-toolbar { margin-bottom:12px; padding:7px; gap:5px; }
  .studio-toolbar button,.studio-toolbar select { padding:7px; font-size:11px; }
  .toolbar-group { gap:3px; }
  .studio-viewport .info { margin-bottom:10px; line-height:1.7; }
  .studio-viewport .ecg-sheets { flex:1; min-height:0; padding:4px; overflow:auto; }
  /* auto margins centre a sheet that fits; a zoomed (overflowing) sheet starts at the left edge, so all of it can be scrolled to (EKG-10) */
  .studio-viewport .ecg-sheet-wrapper { margin:0 auto; align-self:flex-start; flex-shrink:0; }
  .studio-viewport .legend { margin-top:8px; gap:14px; font-size:9px; }
  .studio-warnings { margin-bottom:10px; padding:8px 12px; font-size:11px; }
  .sequence-overview { margin-bottom:8px; }
  .library-view { flex:1; min-height:0; overflow:auto; width:100%; }
  #view-quiz>.viewport { min-height:0; }
  #quiz-canvas { max-height:calc(100dvh - 220px); width:auto; object-fit:contain; }
  .focus-mode #view-generator { grid-template-columns:1fr!important; }
}
@media print { .sheet-navigation { display:none!important; } .ecg-sheet-wrapper[hidden] { display:flex!important; } }
@media screen and (min-width:961px) and (max-height:780px), screen and (min-width:901px) and (min-height:501px) and (max-height:780px) {
  #view-generator .controls { padding:16px 18px; }
  #view-generator .settings-body { display:grid; grid-template-columns:1fr 1fr; gap:8px 16px; }
  #view-generator .settings-body .control-group { margin:0; }
  #view-generator .settings-body label { min-height:30px; display:flex; flex-direction:column; gap:3px; font-size:11px; }
  #view-generator .settings-body input[type="range"] { width:100%; }
  .sidebar-footer { margin-top:12px; }
}

/* Put the signal first: a compact heading and a preview without unused A4 paper. */
@media screen and (min-width:961px), screen and (min-width:901px) and (min-height:501px) {
  .studio-viewport { padding:12px 18px 12px; }
  .studio-viewport .studio-toolbar { margin-bottom:8px; }
  .studio-viewport .ecg-sheets { justify-content:flex-start; }
}

/* Advanced tools replace the base controls, keeping the ECG alongside them. */
#view-generator .settings-content .settings-body { display:block; }
#view-generator .settings-content .control-group { margin:0 0 14px; }
#view-generator .settings-content .control-group label { display:block; min-height:0; margin-bottom:6px; font-size:12px; }
#view-generator .settings-content .settings-body>button { width:100%; margin:6px 0; }
@media screen and (min-width:961px), screen and (min-width:901px) and (min-height:501px) {
  body.studio-editing #view-generator { grid-template-columns:320px minmax(0,1fr); }
}
@media screen and (max-width:900px), screen and (max-width:960px) and (max-height:500px) {
  .settings-pane { height:auto; }
  .settings-content { max-height:45dvh; }
}

/* One command bar, then the useful recording information directly above the ECG. */
.studio-viewport #info { display:flex; flex-wrap:wrap; align-items:baseline; gap:2px 16px; }
.studio-viewport #info .ecg-measurements { font-size:11px; }
.studio-viewport .ecg-sheet-wrapper:only-child>.ecg-sheet-header { display:none; }
@media screen and (min-width:961px), screen and (min-width:901px) and (min-height:501px) {
  .studio-viewport { padding-top:10px; }
  .studio-viewport .studio-toolbar { margin-bottom:7px; }
  .studio-viewport #info { margin-bottom:5px; line-height:1.6; }
}

/* Categorized finding menu: navigation stays within the sidebar. */
.preset-selection-row { display:flex; align-items:stretch; gap:6px; position:relative; margin:14px 0; }
.preset-picker { flex:1; min-width:0; }
.preset-trigger { width:100%; min-height:42px; text-align:left; font-weight:500; line-height:1.45; padding:9px 25px 9px 10px; position:relative; font-size:12px; }
.preset-trigger::after { content:'⌄'; position:absolute; right:9px; top:10px; color:var(--muted); }
.preset-menu { position:absolute; z-index:15; left:0; right:0; top:calc(100% + 6px); padding:10px; background:var(--surface); border:1px solid var(--line); border-radius:12px; box-shadow:0 12px 28px #183e3026; }
.preset-menu input { width:100%; font-size:12px; margin-bottom:8px; }
.preset-menu-list { max-height:min(380px,calc(100dvh - 335px)); overflow:auto; overscroll-behavior:contain; }
.preset-menu-item { display:flex; align-items:center; justify-content:space-between; gap:7px; width:100%; border-radius:7px; padding:10px 8px; font-size:12px; font-weight:500; text-align:left; color:var(--ink); background:transparent; line-height:1.4; }
.preset-menu-item:hover,.preset-menu-item:focus-visible { background:var(--surface-soft); color:var(--accent); }
.preset-menu-item[aria-pressed="true"],.preset-menu-item.selected-category { color:var(--accent-ink); background:var(--accent-soft); }
.preset-count { color:var(--muted); font-size:10px; flex-shrink:0; }
.preset-back { width:100%; text-align:left; padding:7px 5px; font-size:11px; }
.preset-category-title { color:var(--muted); padding:8px 7px; font-size:10px; line-height:1.5; }
.preset-choice { display:block; }
.preset-choice small { display:block; color:var(--muted); font-size:9px; margin-top:3px; }
.finding-help { display:flex; align-items:stretch; }
#finding-help { width:32px; padding:6px; font-size:18px; font-weight:400; color:var(--accent); }
#view-generator .finding-tooltip { position:absolute; left:0; right:0; top:calc(100% + 6px); z-index:16; margin:0; padding:15px; border:1px solid var(--line); border-radius:12px; background:var(--surface); box-shadow:0 12px 28px #183e3026; max-height:min(380px,calc(100dvh - 290px)); overflow:auto; }
.finding-tooltip>strong { display:block; font-size:12px; margin-bottom:9px; color:var(--accent); }
.finding-tooltip .pathology-description { margin-bottom:10px; }
.studio-footer { display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:8px 16px; margin-top:8px; }
.studio-footer .legend { margin:0; flex:1; }
.layout-control { display:flex; align-items:center; gap:8px; flex-shrink:0; }
.layout-control label { color:var(--muted); font-size:11px; }
.layout-control select { max-width:205px; min-height:32px; padding:6px 9px; font-size:11px; }
@media (max-width:767px) { .layout-control { width:100%; justify-content:space-between; }.layout-control select { max-width:75%; flex:1; } }
@media print { .studio-footer { display:none!important; } }
.embed .studio-footer { display:none!important; }

/* Readable answer summary above the tracing; longer reasoning is optional. */
#quiz-result { background:var(--surface); color:var(--ink); border:1px solid var(--line); border-left:4px solid var(--accent); border-radius:10px; padding:14px 18px; font-size:14px; line-height:1.6; }
#quiz-result strong { color:var(--ink); font-size:16px; }
#quiz-result p { margin:7px 0 0; }
.quiz-answer-heading { display:flex; align-items:baseline; gap:9px 16px; flex-wrap:wrap; }
.quiz-answer-status { color:var(--accent); font-size:12px; font-weight:650; white-space:nowrap; }
#quiz-result[data-correct="false"] { border-left-color:var(--danger); }
#quiz-result[data-correct="false"] .quiz-answer-status { color:var(--danger); }
.quiz-answer-details { margin-top:8px; }
.quiz-answer-details summary { cursor:pointer; color:var(--accent); font-size:12px; padding:4px 0; }
.quiz-answer-details p { color:var(--ink); }
.quiz-tracing { position:relative; min-width:0; }
@media screen and (min-width:961px), screen and (min-width:901px) and (min-height:501px) {
  #view-quiz>.viewport { display:flex; flex-direction:column; padding:18px; overflow:hidden; }
  #view-quiz .info,#quiz-result,#view-quiz .legend { flex-shrink:0; }
  #quiz-result { max-height:38vh; overflow:auto; }
  .quiz-tracing { flex:1; min-height:0; overflow:auto; }
  #quiz-canvas { max-height:none; max-width:100%; object-fit:fill; }
}

/* ── Kardio mobile shell (M0): compact tier = (max-width:900px), (max-width:960px) and (max-height:500px) ──
   kardio-sidebar.css stacks the sidebar only up to 900 px; landscape phones from
   901 to 960 px wide (915×412 … 956×440) are compact too, so its stacked rules
   are repeated here for the short tier (identical values; the ≤ 900 px ones
   simply apply twice). Shared candidate for packages/design (M0 PR 6). */
@media (max-width:960px) and (max-height:500px) {
  .kardio-shell .controls { min-height:0; overflow:visible; border-right:0; border-bottom:1px solid var(--line); }
  .kardio-shell .controls.collapsed .controls-collapsible { display:none; }
  .kardio-shell .settings-panel > summary { padding:17px 0; }
  .kardio-shell .settings-body { padding:3px 0 16px; }
  .kardio-shell .control-group { margin-bottom:17px; }
  .kardio-shell .control-group > label,.kardio-shell .control-label { margin-bottom:8px; }
}

/* ── EKG Studio on phones, tablets and landscape phones (M0 EKG-W3/W4/W11–W15) ── */
#settings-open,#compose-open-toolbar,.caliper-done,.dialog-close-footer { display:none; }
/* EKG-W15 / EKG-24: token colours, readable in dark mode */
.studio-warnings { border-color:var(--warn); background:var(--warn-soft); color:var(--warn-ink); }
.quiz-option.incorrect { background:var(--danger-soft); color:var(--danger-ink); border-color:var(--danger); }
/* EKG-W13: the layout select keeps its rendered width, so nothing moves when its options arrive */
.layout-control select#layout { width:137px; }
@media (hover:none) and (pointer:coarse) { .layout-control select#layout { width:181px; } }
.studio-viewport #info:empty { min-height:22px; }
/* An embed shows nothing until app.js has switched it to the chromeless layout (no flash, no shift). */
html[data-embed] body:not(.embed) { visibility:hidden; }
/* EKG-W12 / EKG-03: the toast clears the tab bar and the home indicator */
.toast { bottom:calc(24px + max(var(--tabbar-offset), env(safe-area-inset-bottom, 0px))); z-index:var(--z-toast); }
/* EKG-W11: dialogs keep their heading in view, contain their scroll and lock the page */
dialog { overscroll-behavior:contain; }
html:has(dialog[open]) { overflow:hidden; }
.dialog-heading { position:sticky; top:0; background:var(--surface); z-index:1; }
.export-grid { align-content:start; }
.export-actions { justify-content:flex-start; margin-top:0; }
/* EKG-W4: the finding menu as a sheet (preset-menu.js SHEET_QUERY) */
.sheet-dialog[open] { display:flex; flex-direction:column; height:min(85dvh,640px); padding:0 16px calc(12px + env(safe-area-inset-bottom, 0px)); overflow:hidden; }
.sheet-dialog-head { display:flex; align-items:center; justify-content:space-between; gap:8px; flex:0 0 52px; }
.sheet-dialog-head h2 { margin:0; font-size:var(--text-md); font-weight:600; }
.sheet-dialog-close { min-width:44px; min-height:44px; padding:0; font-size:22px; font-weight:400; }
.preset-dialog .preset-menu { position:static; display:flex; flex-direction:column; flex:1; min-height:0; padding:0; border:0; border-radius:0; box-shadow:none; background:none; }
.preset-dialog .preset-menu input { flex:0 0 auto; }
.preset-dialog .preset-menu-list { flex:1; min-height:0; max-height:none; }
/* Elsewhere the dropdown keeps a usable floor on short windows */
.preset-menu-list { max-height:max(220px,min(380px,calc(100dvh - 335px))); }
#view-generator .finding-tooltip { max-height:max(220px,min(380px,calc(100dvh - 290px))); }
/* EKG-W14 / EKG-20: touch targets in the studio toolbar and footer */
@media (pointer:coarse) {
  .studio-toolbar button,.studio-toolbar select,.layout-control select { min-height:44px; }
  .dialog-heading>button { min-width:44px; min-height:44px; }
}
/* 44 px wide boxes in the compact tier only. Touch tablets in the desktop tier (1024 × 768) keep the
   desktop width of ↶ ↷ ↻ — 44 px boxes there wrap the toolbar to two rows — and get a 44 × 44 hit
   area from a transparent ::after instead (as the header's controls, kardio-header.css). The areas sit
   under every button (z-index -1 in their group's own stacking context, so the group's box does not
   cover them): where one reaches over the 3–6 px gap onto a neighbour, the neighbour's box still
   takes its own taps. A disabled ↶ / ↷ has none: its opacity makes it a stacking context of its
   own, whose area would cover the neighbour. */
@media (pointer:coarse) and (max-width:900px), (pointer:coarse) and (max-width:960px) and (max-height:500px) {
  .studio-toolbar button,.studio-toolbar select,.layout-control select { min-width:44px; }
}
@media (pointer:coarse) and (min-width:961px), (pointer:coarse) and (min-width:901px) and (min-height:501px) {
  .studio-toolbar .toolbar-group { isolation:isolate; }
  #undo,#redo,#generate { position:relative; }
  #undo:enabled::after,#redo:enabled::after,#generate::after { content:""; position:absolute; z-index:-1; inset:min(0px,calc(50% - 22px)); }
}
@media (hover:none) and (pointer:coarse) { .keyboard-help { display:none; } }
/* EKG-W14 / EKG-21: short desktop windows (1024×768): number input under its slider, so the slider keeps its width */
@media screen and (min-width:961px) and (max-height:780px), screen and (min-width:901px) and (min-height:501px) and (max-height:780px) {
  #view-generator .controls { padding-left:12px; padding-right:12px; }
  #view-generator .settings-body { column-gap:10px; }
  #view-generator .settings-body .range-exact { flex-wrap:wrap; gap:4px; }
  #view-generator .settings-body .range-exact > input[type="range"] { flex:1 0 100%; }
}

@media (max-width:900px), (max-width:960px) and (max-height:500px) {
  /* EKG-W12: content clears the landscape safe areas (the header and tab bar pad their own) */
  .kardio-shell .container { padding:0 env(safe-area-inset-right, 0px) 0 env(safe-area-inset-left, 0px); }
  .kardio-shell .container > .controls { padding-left:22px; padding-right:22px; }
  .kardio-shell .library-view { padding-left:calc(24px + env(safe-area-inset-left, 0px)); padding-right:calc(24px + env(safe-area-inset-right, 0px)); }
  /* EKG-W3: one head row (finding + ⓘ); the settings open from the toolbar */
  #view-generator > .controls { padding:8px 16px; }
  #view-generator .panel-heading,#view-generator .compose-button,#view-generator .controls-toggle { display:none; }
  #view-generator .preset-selection-row { margin:0; }
  #view-generator #finding-help { width:44px; flex:0 0 44px; }
  #settings-open,#compose-open-toolbar { display:inline-flex; align-items:center; justify-content:center; gap:6px; }
  .studio-viewport { padding:8px 16px 12px; }
  .studio-viewport .studio-toolbar { margin-bottom:8px; }
  .studio-viewport #info { margin-bottom:8px; line-height:1.5; }
  /* Fokus: only the toolbar and the ECG */
  .focus-mode #view-generator > .controls { display:block; padding:0; border:0; }
  .focus-mode #view-generator .preset-selection-row,.focus-mode .studio-viewport #info { display:none; }
  /* EKG-W4: the settings sheet (kardio-sidebar.css .has-sheet, for this sidebar's nesting) */
  #view-generator > .controls.has-sheet:not(.collapsed) .controls-collapsible,
  #view-generator > .controls.has-sheet:not(.collapsed) > .settings-pane:not([hidden]) {
    position:fixed; z-index:var(--z-sheet); top:auto; left:0; right:0; bottom:0;
    max-height:var(--sheet-max-h); overflow:auto; overscroll-behavior:contain; scroll-padding-top:60px;
    padding:0 calc(16px + env(safe-area-inset-right, 0px)) calc(16px + env(safe-area-inset-bottom, 0px)) calc(16px + env(safe-area-inset-left, 0px));
    background:var(--surface); border-top:1px solid var(--line);
    border-radius:var(--radius-panel) var(--radius-panel) 0 0; box-shadow:var(--shadow-sheet);
  }
  /* "Weitere Einstellungen": the head row stays, the advanced pane takes the sheet */
  #view-generator > .controls.has-sheet > .basic-controls[hidden] { display:block!important; }
  #view-generator > .controls.has-sheet > .basic-controls[hidden] .controls-collapsible { display:none!important; }
  #view-generator > .controls.has-sheet.collapsed > .settings-pane { display:none!important; }
  #view-generator > .controls.has-sheet > .settings-pane > .settings-back,
  #view-generator > .controls.has-sheet > .settings-pane > #settings-title { display:none; }
  #view-generator > .controls.has-sheet > .settings-pane { gap:8px; }
  #view-generator > .controls.has-sheet .sheet-head { gap:4px; }
  #view-generator > .controls.has-sheet .sheet-head + .settings-panel { border-top:0; }
  #view-generator > .controls.has-sheet .sheet-head .sheet-title { flex:1; min-width:0; }
  #view-generator > .controls.has-sheet .sheet-back { min-width:44px; min-height:44px; padding:0; font-size:18px; }
  #view-generator .settings-content { max-height:none; overflow:visible; padding:0; }
  #advanced-settings { margin-top:8px; }
  /* EKG-W13: placeholder while #ecg-sheets is still empty — compact above 767 px: the A4 preview scaled to the width */
  body:not(.embed) #ecg-sheets:empty::before { content:""; display:block; padding-top:calc((100% - 2px) * 136 / 277 + 2px); margin-bottom:22px; }   /* compactPreview: 277 × 136 mm, 1 px border */
}
/* Phones (≤ 767) and landscape phones: one toolbar row that scrolls sideways (shell.js data-overflow fade) */
@media (max-width:767px), (max-width:960px) and (max-height:500px) {
  .studio-toolbar { flex-wrap:nowrap; justify-content:flex-start; gap:6px; padding:0; border:0; border-radius:0; background:transparent; overflow-x:auto; overscroll-behavior-x:contain; scrollbar-width:none; }
  .studio-toolbar::-webkit-scrollbar { display:none; }
  .studio-toolbar .toolbar-group { display:contents; }
  .studio-toolbar .toolbar-divider,#studio-zoom,#generate { display:none; }
  /* Same order as on desktop (the DOM order): no CSS `order`, so Tab walks the row left to right (WCAG 2.4.3) */
  .studio-toolbar button { flex:0 0 auto; white-space:nowrap; }
  .studio-toolbar[data-overflow="end"] { mask-image:linear-gradient(to right,#000 calc(100% - 24px),transparent); }
  .studio-toolbar[data-overflow="start"] { mask-image:linear-gradient(to left,#000 calc(100% - 24px),transparent); }
  .studio-toolbar[data-overflow="both"] { mask-image:linear-gradient(to right,transparent,#000 24px,#000 calc(100% - 24px),transparent); }
}
@media (max-width:767px) {
  /* EKG-W13: the info line reserves its height; the empty strip reserves the unscaled single-column sheet (348 mm) */
  .studio-viewport #info,.studio-viewport #info:empty { min-height:60px; }   /* finding + two lines of measurements at 328–398 px */
  .studio-viewport #info .ecg-measurements { font-size:11px; }
  body:not(.embed) #ecg-sheets:empty::before { padding-top:0; height:1392px; }
  /* EKG-W11: dialogs as bottom sheets with a footer button */
  dialog { margin:auto 0 0; width:100%; max-width:100%; max-height:92dvh; border-radius:18px 18px 0 0; padding:20px 16px calc(16px + env(safe-area-inset-bottom, 0px)); }
  #presentation-dialog { width:100%; padding:20px 16px calc(16px + env(safe-area-inset-bottom, 0px)); }
  .dialog-close-footer { display:block; width:100%; min-height:44px; margin-top:16px; }
  /* EKG-W5: measuring — the chip ends it from anywhere on the strip, above the tab bar */
  body.caliper-active .caliper-done {
    display:block; position:fixed; z-index:calc(var(--z-tabbar) + 1); left:50%; transform:translateX(-50%);
    bottom:calc(12px + max(var(--tabbar-offset), env(safe-area-inset-bottom, 0px)));
    min-height:44px; padding:10px 20px; border-radius:var(--radius-pill); box-shadow:var(--shadow);
  }
}
/* Landscape phones: the info is one line; the settings sheet docks right, the ECG stays visible on the left */
@media (max-width:960px) and (max-height:500px) {
  .studio-viewport #info { display:block; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
  .studio-viewport #info .ecg-measurements { margin-left:12px; }
  #view-generator > .controls.has-sheet:not(.collapsed) .controls-collapsible,
  #view-generator > .controls.has-sheet:not(.collapsed) > .settings-pane:not([hidden]) {
    top:var(--header-total); left:auto; width:min(360px,45vw); max-height:none;
    border-top:0; border-left:1px solid var(--line); border-radius:var(--radius-panel) 0 0 var(--radius-panel);
  }
}
/* Embeds (KURS-W4 / EKG-W7): sized from the width only — fixed spacing, never the short-tier rules;
   the body is as tall as its content (app.js posts that height to the course page) */
body.embed { min-height:0; }
body.embed .studio-viewport { display:block; padding:0; }
body.embed .ecg-sheets { padding:0; overflow:visible; }
body.embed .ecg-sheet-wrapper { margin:0; }
/* narrow embeds: the single-column strip scaled to the width (aspect from the permalink, js/kardio-platform.js) */
@media (max-width:767px) { body.embed #ecg-sheets:empty::before { content:""; display:block; padding-top:min(calc(100% * var(--ekg-embed-strip, 2)), var(--ekg-embed-strip-max, 1392px)); } }
@media (min-width:768px) { body.embed #ecg-sheets:empty::before { content:""; display:block; padding-top:calc(100% * 136 / 277); } }

/* ── Monitor, Üben, Bibliothek on phones (M0 EKG-W8/W9/W10) ── */
.quiz-instruction-short,.library-more { display:none; }
.library-top { position:fixed; z-index:calc(var(--z-tabbar) + 1); right:calc(16px + env(safe-area-inset-right, 0px)); bottom:calc(16px + max(var(--tabbar-offset), env(safe-area-inset-bottom, 0px))); min-height:44px; border-radius:var(--radius-pill); box-shadow:var(--shadow); }
.library-group { border-top:1px solid var(--line); }
.library-grid:has(> .library-group) { gap:0; }
.library-group > summary { display:flex; align-items:center; justify-content:space-between; gap:12px; min-height:52px; padding:4px 0; font-size:var(--text-md); font-weight:600; list-style:none; cursor:pointer; }
.library-group > summary::-webkit-details-marker { display:none; }
.library-group > summary::after { content:'+'; color:var(--muted); font-weight:400; font-size:18px; }
.library-group[open] > summary::after { content:'−'; }
.library-group > summary .muted { margin-left:auto; font-weight:500; }
.library-group-cards { display:grid; grid-template-columns:1fr; gap:16px; padding:4px 0 20px; }
/* EKG-W10 / EKG-25: thumbnails keep their 3 : 1 drawing, sharp at any width */
.library-card canvas { height:auto; aspect-ratio:3/1; }
@media (max-width:640px) {
  /* EKG-W8: the readout goes under the trace instead of over it; the alarm chips stay on top */
  .monitor-trace { display:flex; flex-direction:column; }
  .monitor-viewport .info { position:static; order:1; border-radius:0; }
}
/* Phones, and landscape phones (EKG-27, EKG-14: the screen and the ECG before the controls there too) */
@media (max-width:767px), (max-width:960px) and (max-height:500px) {
  /* EKG-W8: the screen first (no controls in it), then the controls in a compact grid in their
     DOM order — the desktop column's order, so Tab follows the grid (WCAG 2.4.3):
       Studio-EKG verwenden | Pathologie | Ableitung · Geschwindigkeit · ▶ · ⏸ */
  #view-monitor > .monitor-viewport { order:-1; }
  #view-monitor > .monitor-sidebar { display:grid; grid-template-columns:minmax(0,1fr) minmax(0,1fr) 44px 44px; align-items:end; gap:10px 8px; padding:12px 16px 8px; border-bottom:0; }
  #view-monitor > .monitor-sidebar > h2,#view-monitor > .monitor-sidebar > .quiz-tip { display:none; }
  #view-monitor > .monitor-sidebar > .control-group { margin:0; }
  #view-monitor > .monitor-sidebar > .control-group:has(#monitor-pathology) { grid-column:1/-1; }
  #view-monitor > .monitor-sidebar > .button-row { display:contents; }
  #view-monitor > .monitor-sidebar > .check-row { grid-column:1/-1; min-height:44px; margin:0; }
  #monitor-play,#monitor-pause { width:44px; min-width:44px; min-height:44px; height:44px; padding:0; font-size:17px; }
  #monitor-play .btn-text,#monitor-pause .btn-text { position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; }
  .check-row { min-height:44px; }

  /* EKG-W9 / EKG-14: Üben — instruction, ECG, then the options in two columns, then the answer.
     The focusable parts (caliper, options, answer, actions) are also in this order in the DOM
     on this tier (js/app.js placeQuizControls), so `order` never splits screen and Tab order. */
  #view-quiz { display:flex; flex-direction:column; gap:10px; padding:12px calc(16px + env(safe-area-inset-right, 0px)) 16px calc(16px + env(safe-area-inset-left, 0px)); }
  #view-quiz > .quiz-sidebar,#view-quiz > .viewport { display:contents; }
  #view-quiz .quiz-sidebar > h2,#quiz-info,.quiz-instruction-long { display:none; }
  .quiz-instruction-short { display:inline; }
  #view-quiz .quiz-instruction { order:1; margin:0; }
  #quiz-tracing { order:2; }
  #view-quiz .quiz-caliper-row { order:3; margin:0; }
  #view-quiz .viewport > .legend { order:4; margin:0; }
  #quiz-options { order:5; display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; margin:0; }
  #quiz-options .quiz-option { min-height:44px; padding:10px; }
  #quiz-result { order:6; margin:0; scroll-margin-bottom:calc(var(--tabbar-offset) + 40px); }
  #view-quiz .quiz-actions { order:7; margin:0; }
  #view-quiz .quiz-score { order:8; margin:0; padding:8px 12px; }
  #view-quiz .quiz-tip { order:9; margin:0; }

  /* EKG-W10 / EKG-19: Bibliothek — one hero line, actions behind "Mehr ⋯", sticky filters, grouped cards */
  .kardio-shell .library-view { padding-left:calc(16px + env(safe-area-inset-left, 0px)); padding-right:calc(16px + env(safe-area-inset-right, 0px)); }
  #view-library .workspace-heading { flex-wrap:nowrap; align-items:center; gap:12px; margin-bottom:0; position:relative; }
  #view-library .workspace-heading > div:first-child { min-width:0; flex:1; }
  #view-library .workspace-heading .eyebrow,#view-library .workspace-heading p { display:none; }
  #view-library .workspace-heading h1 { margin:0; font-size:17px; letter-spacing:-.2px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
  .library-more { display:inline-flex; align-items:center; gap:6px; min-height:44px; flex:0 0 auto; }
  #library-actions { display:none; }
  #library-actions.open { display:flex; flex-wrap:wrap; gap:8px; position:absolute; z-index:6; top:calc(100% + 6px); right:0; width:min(280px,calc(100vw - 32px)); padding:8px; background:var(--surface); border:1px solid var(--line); border-radius:var(--radius-panel); box-shadow:var(--shadow); }
  #library-actions.open button { flex:1 1 100%; min-height:44px; }
  #view-library .library-filters { position:sticky; top:var(--header-total); z-index:5; margin:12px -16px 8px; padding:8px 16px; background:var(--bg); border-bottom:1px solid var(--line); }
  #view-library .library-filters .segmented button { min-height:40px; }
}
@media (max-width:767px), (max-width:960px) and (max-height:500px) {
  /* EKG-W10 / EKG-26: no nested 52vh scroller in the presentation on phones */
  .presentation-canvas { max-height:none; overflow:visible; }
}
