.papier-werkstatt [hidden] { display:none !important; }
.papier-layout { display:grid; grid-template-columns:minmax(0,1fr) minmax(150px,.35fr); gap:16px; align-items:start; }
.papier-auswahl fieldset { border:0; padding:0; margin:0; }
.papier-auswahl legend { font-weight:700; margin-bottom:6px; }
.papier-gruppe { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:8px; }
.papier-vorschau canvas { display:block; width:100%; max-height:40vh; object-fit:contain; }
.papier-seiten { display:flex; flex-wrap:wrap; align-items:center; gap:8px; margin-top:8px; }
.papier-seiten span { min-width:100px; text-align:center; }
.papier-knopf:disabled { opacity:.55; cursor:default; }
@media (max-width:700px) { .papier-layout { grid-template-columns:1fr; } .papier-vorschau canvas { max-height:22vh; } .papier-gruppe { grid-template-columns:repeat(2,minmax(0,1fr)); } }
/* Niedrig: kompakt nebeneinander, Knöpfe bleiben ≥ 120 × 96 */
@media (max-height:420px) {
  .papier-werkstatt .papier-layout { grid-template-columns:minmax(0,1fr) minmax(180px,.4fr); align-items:center; gap:8px; }
  .papier-werkstatt .papier-knopf { min-width:120px; min-height:96px; padding:6px; font-size:1rem; }
  .papier-vorschau canvas { max-height:42vh; }
}
/* Die Navigation liegt neben der Auswahl, damit das Blatt die verfügbare Höhe
   nutzen kann. Die Regeln sind auf diese Werkstatt beschränkt und übersteuern
   die später geladenen allgemeinen Bühnenregeln. */
@media screen and (min-width:701px) and (min-height:651px) {
  html body #app .papier-werkstatt .papier-layout {grid-template-columns:minmax(0,1fr) minmax(250px,.65fr);align-items:center}
  html body #app .papier-werkstatt .papier-vorschau canvas {width:auto;max-width:100%;height:min(56vh,560px);max-height:none}
}
@media screen and (min-width:701px) and (min-height:451px) and (max-height:650px) {
  html body #app .papier-werkstatt .papier-layout {grid-template-columns:minmax(0,1fr) minmax(185px,.42fr);align-items:center}
  html body #app .papier-werkstatt .papier-vorschau canvas {width:auto;max-width:100%;height:min(52vh,320px);max-height:none}
}
@media screen and (max-width:700px) and (min-height:451px) {
  html body #app .papier-werkstatt .papier-vorschau {order:-1}
  html body #app .papier-werkstatt .papier-vorschau canvas {width:auto;max-width:100%;height:min(26vh,220px)!important;max-height:none}
}
@media print {
  body.papier-drucken { background:white !important; }
  body.papier-drucken main > :not(.papier-werkstatt), body.papier-drucken .papier-werkstatt > :not(.papier-layout), body.papier-drucken .papier-auswahl, body.papier-drucken .papier-vorschau > :not(canvas) { display:none !important; }
  body.papier-drucken main { padding:0; margin:0; max-width:none; }
  body.papier-drucken .papier-layout { display:block; }
  body.papier-drucken .papier-vorschau canvas { display:block; width:210mm; height:297mm; max-height:none; }
  body.papier-drucken .papier-3d-scene { display: none !important; }
}

/* 3D-Geschenkbox; Canvas bleibt für Speichern/Drucken. */
#app:has(> .papier-werkstatt.papier-3d) { max-width: none; padding: 0 !important; }
.papier-werkstatt.papier-3d, .papier-werkstatt.papier-laedt {
  position: fixed; inset: 0; overflow: hidden; box-sizing: border-box;
  padding: 12px 16px 10px; background: #1c3044; color: #fff8e8;
  --pp-leiste: var(--zurueck-h, 112px);
}
.papier-werkstatt.papier-3d { --buehne-links: min(420px, 42vw); }
.papier-werkstatt.papier-3d > .papier-3d-scene {
  position: absolute;
  top: calc(var(--oben, 10px) + 5.2rem);
  right: var(--rechts, 12px);
  bottom: calc(var(--pp-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;
}
.papier-3d-scene > canvas { width: 100%; height: 100%; display: block; }
.papier-3d > h1, .papier-3d > p, .papier-3d .papier-layout, .papier-3d .papier-aktionen {
  position: relative; z-index: 2;
}
.papier-3d > h1, .papier-3d > p { max-width: calc(var(--buehne-links) - 8px); }
.papier-3d .papier-layout {
  grid-template-columns: 1fr;
  width: calc(var(--buehne-links) - 8px);
  max-height: calc(100dvh - var(--pp-leiste) - 13rem); overflow: auto;
}
.papier-3d .papier-auswahl, .papier-3d .papier-vorschau { background: #0b1622d8; border-radius: 16px; padding: 10px; }
.papier-3d .papier-gruppe { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
.papier-3d .papier-vorschau {
  position: fixed; left: calc(var(--buehne-links) + 64px); right: auto; top: auto;
  bottom: calc(var(--pp-leiste) + var(--unten, 10px) + 48px);
  width: min(132px, 16vw); z-index: 3;
}
.papier-3d .papier-vorschau canvas { max-height: min(22vh, 180px); }
.papier-3d .papier-aktionen {
  position: absolute; left: var(--links, 10px); right: var(--rechts, 10px); bottom: var(--unten, 10px);
  z-index: 4; margin: 0;
}
.papier-3d .papier-aktionen .knopf[data-wert="zurueck"] {
  min-width: var(--zurueck-b, 220px); min-height: var(--zurueck-h, 112px);
}
.papier-3d .papier-knopf { min-width: var(--knopf-b, 120px); min-height: var(--knopf-min-h, 96px); }
@media screen and (min-width: 701px) {
  html body #app .papier-werkstatt.papier-3d .papier-layout {
    grid-template-columns: 1fr;
    width: calc(var(--buehne-links) - 8px);
    align-items: start;
    max-height: calc(100dvh - var(--pp-leiste) - 13rem) !important;
    overflow: auto !important;
  }
  html body #app .papier-werkstatt.papier-3d .papier-vorschau canvas {
    width: 100%; height: auto; max-height: min(22vh, 180px);
  }
}
@media screen {
  html body #app > section.papier-werkstatt.papier-3d:not([hidden]) {
    position: relative; inset: auto; display: grid; overflow: visible; width: 100%;
    padding: 16px; gap: 10px; grid-template-columns: minmax(300px, 34%) minmax(0, 1fr);
    grid-template-rows: auto auto minmax(max-content, 1fr) auto;
    grid-template-areas: "titel szene" "hilfe szene" "wahl szene" "fuss fuss";
  }
  #app .papier-3d > h1 { grid-area: titel; margin: 0; max-width: none; }
  #app .papier-3d > p { grid-area: hilfe; margin: 0; max-width: none; }
  html body #app .papier-werkstatt.papier-3d .papier-layout { display: contents; }
  #app .papier-3d .papier-auswahl { grid-area: wahl; align-self: center; }
  #app .papier-werkstatt.papier-3d > .papier-3d-scene {
    grid-area: szene; position: relative; inset: auto; min-height: 280px;
  }
  #app .papier-3d-scene > canvas { position: absolute; inset: 0; }
  #app .papier-3d .papier-vorschau {
    grid-area: szene; position: relative; inset: auto; justify-self: start; align-self: end;
    width: clamp(58px, 7vw, 96px); margin: 10px; padding: 4px;
  }
  html body #app .papier-werkstatt.papier-3d .papier-vorschau canvas {
    width: 100%; height: auto !important; max-height: none;
  }
  #app .papier-3d .papier-vorschau p { margin: 0; }
  #app .papier-3d .papier-vorschau p:not(:empty) {
    position: absolute; left: 100%; bottom: 0; width: min(40vw, 260px);
    background: #0b1622ed; padding: 8px; border-radius: 8px;
  }
  #app .papier-3d .papier-aktionen { position: static; inset: auto; grid-area: fuss; }
}
@media screen and (orientation: portrait), screen and (max-width: 640px) {
  html body #app > section.papier-werkstatt.papier-3d:not([hidden]) {
    grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto auto auto auto;
    grid-template-areas: "titel" "hilfe" "szene" "wahl" "fuss";
  }
  #app .papier-werkstatt.papier-3d > .papier-3d-scene { height: clamp(230px, 35dvh, 420px); min-height: 0; }
  #app .papier-3d .papier-seiten { display: grid; grid-template-columns: 1fr 1fr; }
  #app .papier-3d .papier-seiten span { grid-row: 2; grid-column: 1 / -1; }
}
@media screen and (orientation: portrait), screen and (max-width: 640px) {
  html body #app > section.papier-werkstatt.papier-3d:not([hidden]) {
    grid-template-rows: auto auto auto auto auto auto;
    grid-template-areas: "titel" "hilfe" "szene" "status" "wahl" "fuss";
  }
  #app .papier-3d .papier-vorschau { display: contents; }
  html body #app .papier-werkstatt.papier-3d .papier-vorschau canvas {
    grid-area: szene; align-self: end; justify-self: start; z-index: 2;
    width: 52px; margin: 8px; border: 2px solid #e0a84a; border-radius: 4px;
  }
  #app .papier-3d .papier-vorschau p:not(:empty) {
    grid-area: status; position: static; width: auto; margin: 0;
  }
  #app .papier-3d .papier-vorschau p:empty { display: none; }
  #app .papier-3d .papier-gruppe { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
