.malen-layout { display: grid; grid-template-columns: minmax(220px, .9fr) minmax(310px, 1.2fr); gap: 20px; align-items: center; }
.malen [hidden] { display: none !important; }
.malen-seiten { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-block-start: 6px; }
.malen-seiten span { min-width: 80px; text-align: center; }
.malen-kopf { display:flex; gap:14px; align-items:center; }
.malen-kapitel { display:grid; place-items:center; flex:none; width:64px; height:64px; border:1px solid #e0a84a; border-radius:20px; background:#0c1d38; color:#ffe4bd; font-size:2rem; }
.malen-kopf p { margin-block:5px 12px; }
.malen-bild { background: #0c1d38; border:7px solid #ffe4bd; border-radius:16px; overflow:hidden; max-width:520px; box-shadow:0 14px 35px #0005, 0 0 0 1px #e0a84a; }
.malen-werkzeug { padding:14px; border:1px solid #ffffff28; border-radius:20px; background:#ffffff0d; }
body:not(.bf-cvi) .malen .malen-knopf[aria-pressed="true"] { background:#4a3224; border-color:#e0a84a; box-shadow:0 0 0 3px #e0a84a66; }
body.bf-cvi .malen-bild { background:#000; border-color:var(--bf-cvi-farbe,#ffd400); box-shadow:none; }
body.bf-cvi .malen-bild svg > rect:first-of-type { fill:#000; }
body.bf-cvi .malen-bild svg [data-deko] { display:none; }
body.bf-cvi .malen-kapitel { display:none; }
.malen-bild svg { display: block; width: 100%; max-height: 48vh; }
.malen-farben, .malen-flaechen { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-block: 10px; }
.malen-fuss { display: flex; flex-wrap: wrap; gap: 10px; }
.malen-farbpunkt { display:inline-block; width:1.5em; height:1.5em; border:3px solid #fff; border-radius:50%; margin-inline-end:.5em; vertical-align:middle; box-shadow:0 2px 8px #0006; }
.malen-status { min-height: 1.5em; }
.malen-fertig .malen-status { color: #ffe4bd; font-weight: 800; }
.malen-fertig .malen-bild { border-color: #ffe9a8; box-shadow: 0 0 0 3px #ffd27a55, 0 14px 35px #0005; }
.malen .knopf, .malen-farben .knopf, .malen-flaechen .knopf { min-width: 120px; min-height: 96px; }
@media (max-width: 600px) { .malen-layout { grid-template-columns: 1fr; } .malen-bild { margin: auto; width: min(70%, 320px); } .malen-bild svg { max-height: 28vh; } }
@media (max-height: 650px) and (min-width: 601px) {
  .malen-kapitel { width:42px; height:42px; font-size:1.4rem; border-radius:12px; }
  .malen-werkzeug { padding:6px; }
  .malen-layout { gap: 10px; }
  .malen-bild svg { max-height: 38vh; }
  .malen-farben, .malen-flaechen { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
  .malen-farben, .malen-flaechen { margin-block: 4px; }
  .malen-status { margin-block: 4px; }
}
@media (max-width: 600px) {
  .malen-kapitel { width:40px; height:40px; font-size:1.3rem; border-radius:12px; }
  .malen-werkzeug { padding:6px; }
  .malen-bild { width: min(55%, 220px); }
  .malen-bild svg { max-height: min(22vh, 200px); }
  .malen-farben, .malen-flaechen { gap: 6px; margin-block: 6px; }
  .malen-fuss { gap: 3px; }
  .malen-fuss .knopf { flex: 1 1 120px; min-width: 120px; min-height: 96px; }
  .malen-seiten { display: grid; grid-template-columns: repeat(2, minmax(120px,1fr)); gap: 3px; }
  .malen-seiten span { grid-column: 1 / -1; grid-row: 2; }
  .malen p { margin-block: 5px; }
}
/* Niedrig: Farben/Flächen in Reihen, Knöpfe bleiben ≥ 120 × 96 */
@media (max-height: 420px) {
  .malen .knopf { min-width: 120px; min-height: 96px; padding: 6px; font-size: 1rem; }
  .malen-layout { grid-template-columns: minmax(180px,.85fr) minmax(0,1.2fr); gap: 8px; }
  .malen-bild svg { max-height: 36vh; }
  .malen p { margin-block: 3px; }
  .malen-farben, .malen-flaechen { gap: 4px; margin-block: 2px; }
  .malen-seiten { margin-block-start: 2px; }
}
@media (max-height: 420px) and (min-width: 701px) {
  .malen-farben { grid-template-columns: repeat(4, minmax(120px, 1fr)); }
  .malen-flaechen { grid-template-columns: repeat(3, minmax(120px, 1fr)); }
}
/* Platz für das Bild gewinnen: die Schrittwahl sitzt direkt beim Werkzeug. */
@media (min-width: 1200px) and (min-height: 700px) {
  #app > section.malen > :is(.malen-kopf,.malen-layout,.malen-status) {max-width:min(92vw,1500px)}
  #app .malen .malen-bild {width:100%;max-width:calc(58vh + 14px)}
  #app .malen .malen-bild svg {max-height:min(54vh,560px)}
}
@media (min-width: 850px) and (max-height: 650px) and (min-height: 451px) {
  #app .malen .malen-bild {width:100%;max-width:calc(52vh + 14px)}
  #app .malen .malen-bild svg {max-height:min(46vh,300px)}
}

/* 3D-Staffelei: Farbe/Fläche bleiben DOM; Bildfläche = Canvas-Textur. */
#app:has(> .malen.malen-3d) { max-width: none; padding: 0 !important; }
.malen.malen-3d, .malen.malen-laedt {
  position: fixed; inset: 0; overflow: hidden; box-sizing: border-box;
  padding: 12px 16px 10px; background: #243848; color: #fff8e8;
  --ml-leiste: var(--zurueck-h, 112px);
  --buehne-links: min(460px, 46vw);
}
.malen.malen-3d > .malen-3d-scene {
  position: absolute;
  top: var(--oben, 12px);
  right: var(--rechts, 12px);
  bottom: calc(var(--ml-leiste) + var(--unten, 10px) + var(--luecke, 8px));
  left: calc(var(--links, 10px) + var(--buehne-links) + 14px);
  z-index: 0; overflow: hidden; pointer-events: none;
  border-radius: 18px; box-shadow: 0 0 0 2px #e0a84a;
}
.malen-3d-scene > canvas { width: 100%; height: 100%; display: block; }
html body #app .malen.malen-3d .malen-kopf p { display: none; }
html body #app .malen.malen-3d .malen-kopf {
  position: absolute; z-index: 2; top: var(--oben, 10px); left: var(--links, 10px); right: auto;
  width: calc(var(--buehne-links) - 12px) !important; max-width: calc(var(--buehne-links) - 12px) !important;
  overflow: hidden; pointer-events: none; text-shadow: 0 2px 8px #000c;
}
@media (max-height: 700px) { .malen-3d .malen-kopf p { display: none; } }
.malen-3d .malen-bild { display: none; }
.malen-3d .malen-layout {
  position: absolute; z-index: 2; left: var(--links, 10px); right: auto;
  top: calc(var(--s-titel, 32px) + var(--s-text, 16px) * 2.2 + var(--oben, 10px));
  grid-template-columns: minmax(0, 1fr); width: calc(var(--buehne-links) - 8px); max-width: calc(var(--buehne-links) - 8px);
  bottom: calc(var(--ml-leiste) + var(--unten, 10px) + 56px); overflow: auto;
}
@media (max-width: 820px) {
  .malen.malen-3d { --buehne-links: min(92vw, 640px); }
  .malen.malen-3d > .malen-3d-scene {
    left: var(--links, 10px); right: var(--rechts, 10px);
    top: calc(var(--oben, 10px) + 4.2rem); height: 32vh; bottom: auto;
  }
  .malen-3d .malen-layout { top: calc(32vh + 5.2rem); width: min(92vw, 640px); max-width: min(92vw, 640px); }
}
.malen-3d .malen-werkzeug { background: #0b1622d8; border-radius: 12px; }
.malen-3d .malen-status {
  position: absolute; z-index: 2; left: var(--links, 10px); right: auto;
  bottom: calc(var(--ml-leiste) + var(--unten, 10px) + 8px);
  width: calc(var(--buehne-links) - 12px) !important; max-width: calc(var(--buehne-links) - 12px) !important; margin: 0;
  padding: 6px 12px; border-radius: 12px; background: #0b1622d8; pointer-events: none;
}
.malen-3d .malen-fuss {
  position: absolute; left: var(--links, 10px); right: var(--rechts, 10px); bottom: var(--unten, 10px);
  z-index: 4; margin: 0;
}
.malen-3d .malen-fuss .knopf[data-malen="zurueck"] {
  min-width: var(--zurueck-b, 220px); min-height: var(--zurueck-h, 112px);
}
.malen-3d .malen-knopf { min-width: var(--knopf-b, 120px); min-height: var(--knopf-min-h, 96px); }
/* Staffelei und Werkzeuge teilen sich die Fläche entsprechend ihrer tatsächlichen Höhe. */
#app > .malen.malen-3d {
  position: relative; inset: auto; display: grid; min-height: 100dvh; width: 100%; max-width: none; overflow: visible;
  grid-template-columns: minmax(270px, 32%) minmax(0, 1fr);
  grid-template-rows: auto minmax(max-content, 1fr) auto auto; gap: 10px;
}
html body #app .malen.malen-3d > :is(.malen-kopf, .malen-layout, .malen-status, .malen-fuss) {
  position: static; inset: auto; width: 100% !important; max-width: none !important;
  min-width: 0; box-sizing: border-box; margin: 0;
}
#app .malen-3d .malen-kopf { grid-area: 1 / 1; }
#app .malen-3d .malen-layout { grid-area: 2 / 1; align-self: center; }
#app .malen-3d .malen-status { grid-area: 3 / 1; }
#app .malen-3d .malen-fuss { grid-area: 4 / 1 / 5 / 3; }
#app .malen.malen-3d > .malen-3d-scene {
  grid-area: 1 / 2 / 4 / 3; position: relative; inset: auto; width: 100%; height: auto; min-height: 270px;
}
#app .malen-3d-scene canvas { position: absolute; inset: 0; }
@media (orientation: portrait), (max-width: 640px) {
  #app > .malen.malen-3d { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(max-content, 1fr) auto auto; }
  #app .malen.malen-3d > .malen-3d-scene { grid-area: 2 / 1; min-height: 0; height: clamp(220px, 33dvh, 430px); }
  #app .malen-3d .malen-layout { grid-area: 3 / 1; }
  #app .malen-3d .malen-status { grid-area: 4 / 1; }
  #app .malen-3d .malen-fuss { grid-area: 5 / 1; }
}
