/* 3D-factory -- Bedienplattform (computer/trackpad-first).
   Design-Token-System, helles Mint-Marken-Theme, ohne Framework. */

:root {
  /* Marke / Farbtoken */
  --mint:        #C9EBD2;
  --mint-soft:   #e2f4e8;
  --mint-deep:   #9cc7ac;
  --ink:         #263029;
  --ink-soft:    #47604d;  /* WCAG AA: 6.6:1 auf dem transluzenten Panel (vorher #5f7a66 = 4.50:1, Grenzwert) */
  --warm:        #b8541c;
  --warm-soft:   #ffd9b0;
  --warm-hi:     #ffc890;
  --danger:      #ffc0b0;
  --danger-hi:   #ff9f88;
  --danger-ink:  #8a2a1a;

  --panel-bg:    rgba(255,255,255,0.82);
  --panel-brd:   rgba(120,150,130,0.28);
  --card-bg:     rgba(255,255,255,0.72);
  --line:        rgba(120,150,130,0.22);

  --r-sm: 8px;  --r-md: 10px;  --r-lg: 12px;
  --shadow: 0 6px 20px rgba(40,70,50,0.12);
  --shadow-sm: 0 2px 8px rgba(40,70,50,0.10);

  --tb-h: 50px;
  --sb-h: 30px;
  --panel-w: 300px;

  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --focus: 0 0 0 3px rgba(184,84,28,0.45);
}

* { box-sizing: border-box; }

/* [hidden]-Attribut IMMER durchsetzen. Komponenten-Klassen mit eigenem display
   (z.B. .ff-ctx/.ff-edit -> display:flex) haben dieselbe Spezifitaet wie die UA-Regel
   [hidden]{display:none} und gewinnen ueber die Quell-Reihenfolge -> das Element
   blieb trotz hidden=true SICHTBAR (Bug: Freiform-Kontext-Leiste #ffCtx schwebte auf
   dem Fuchs-Screen und ueberlappte den Gesten-Hinweis). Alle Sichtbarkeits-Toggles
   laufen ueber die .hidden-Property (platform.js) -> dieses !important ist die korrekte
   Single Source of Truth: hidden=true => nie gerendert, hidden=false => Klasse greift. */
[hidden] { display: none !important; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--mint);
  font-family: var(--font); color: var(--ink);
  -webkit-user-select: none; user-select: none;
  overflow: hidden;
  /* Doppeltipp-Zoom global aus (manipulation deaktiviert double-tap-zoom, laesst Klicks/
     Buttons intakt). Pinch-Page-Zoom unterdrueckt platform.js zusaetzlich per Event
     (iOS gesture* + 2-Finger-touchmove). Canvas #c hat weiterhin touch-action:none. */
  touch-action: manipulation;
  -ms-touch-action: manipulation;
  /* Kein grauer/blauer iOS-Tap-Blitz-Kasten beim Antippen von Buttons/Select
     ("Kinderfehler" mobil). Wir zeichnen eigene :active/:hover-Zustaende. */
  -webkit-tap-highlight-color: transparent;
  /* Kein Rubber-Band / Pull-to-Refresh, wenn Panel/Command-Bar am Rand weitergezogen
     wird -> die ganze Seite darf nicht mitfedern ("Menue wackelt" beim Scrollen). */
  overscroll-behavior: none;
}
/* 100dvh statt 100vh: iOS/Android blenden die URL-Leiste dynamisch ein/aus. Mit 100vh
   (= Viewport OHNE Leiste) springt die untere Command-Bar/Statusbar, sobald die Leiste
   auf-/zuklappt ("Topbar/Menue wackelt" beim Scrollen). dvh folgt dem sichtbaren Viewport.
   Reihenfolge = progressive Fallback-Kette: aeltere Engines nehmen 100vh, iOS<15.4 die
   -webkit-fill-available-Zeile, moderne Browser das finale 100dvh. */
body {
  display: flex; flex-direction: column;
  height: 100vh;
  height: -webkit-fill-available;
  height: 100dvh;
}
body.loading #viewport { opacity: 0; }

kbd {
  font: 600 10px var(--font); color: var(--ink-soft);
  background: rgba(255,255,255,0.7); border: 1px solid var(--line);
  border-radius: 4px; padding: 0 4px; margin-left: 4px; line-height: 1.4;
}

/* ===================== Topbar ===================== */
#topbar {
  height: calc(var(--tb-h) + env(safe-area-inset-top, 0px)); flex: none; z-index: 30;
  padding-top: env(safe-area-inset-top, 0px);
  display: flex; align-items: center; justify-content: space-between;
  padding-left: max(10px, env(safe-area-inset-left, 0px));
  padding-right: max(10px, env(safe-area-inset-right, 0px));
  gap: 8px;
  background: linear-gradient(#ffffffe6, #ffffffb0);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--panel-brd);
}
/* Essentielle Bedien-Cluster schrumpfen NIE (Zurueck/Panel links, Modell/Schliessen
   rechts bleiben auf jeder Breite sichtbar); nur der Titel gibt Platz her. */
.tb-left, .tb-right { display: flex; align-items: center; gap: 8px; flex: none; }
#title {
  flex: 1 1 auto; min-width: 0; text-align: center;
  font-weight: 700; color: var(--warm); letter-spacing: .3px; font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tb-btn {
  border: none; border-radius: var(--r-md); padding: 9px 13px;
  font: 600 14px var(--font); color: #7a3d12; background: var(--warm-soft);
  cursor: pointer; min-height: 36px; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: 3px;
}
.tb-ico { font-size: 17px; line-height: 1; }
.tb-btn:hover { background: var(--warm-hi); }
.tb-btn.ghost { background: rgba(255,255,255,0.6); color: var(--ink-soft); min-width: 40px; }
.tb-btn.ghost:hover { background: #fff; }
.tb-btn.danger { background: var(--danger); color: var(--danger-ink); min-width: 40px; }
.tb-btn.danger:hover { background: var(--danger-hi); }
.tb-btn:focus-visible { outline: none; box-shadow: var(--focus); }
/* Subject-Umschalter (Modell-Auswahl) */
.tb-sel {
  border: 1px solid var(--panel-brd); border-radius: var(--r-md);
  padding: 8px 10px; min-height: 36px; margin-right: 8px;
  font: 600 13px var(--font); color: var(--ink); background: rgba(255,255,255,0.72);
  cursor: pointer;
}
.tb-sel:hover { background: #fff; }
.tb-sel:focus-visible { outline: none; box-shadow: var(--focus); }

/* ===================== Stage (panel + viewport) ===================== */
#stage { flex: 1 1 auto; display: flex; min-height: 0; position: relative; }

/* ===================== Left panel ===================== */
#panel {
  width: var(--panel-w); flex: none; z-index: 20;
  background: var(--panel-bg); backdrop-filter: blur(8px);
  border-right: 1px solid var(--panel-brd);
  overflow-y: auto; overflow-x: hidden;
  overscroll-behavior: contain;   /* Panel-Scroll kettet nicht auf die Seite -> kein Wackeln am Rand */
  padding: 10px; display: flex; flex-direction: column; gap: 8px;
  transition: width .18s ease, transform .18s ease;
}
body.panel-collapsed #panel { width: 0; padding: 0; border-right: 0; }

.grp {
  flex: 0 0 auto;   /* Karten behalten ihre natuerliche Hoehe -> Panel SCROLLT (statt
                       Flex-Shrink, das den Karteninhalt clippte: "Messung abgeschnitten"). */
  background: var(--card-bg); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-sm); overflow: hidden;
}
.grp-h {
  width: 100%; text-align: left; border: none; background: transparent;
  font: 700 13px var(--font); color: var(--ink);
  padding: 11px 12px; cursor: pointer; display: flex; align-items: center; gap: 8px;
}
.grp-h::before {
  content: "▸"; color: var(--mint-deep); font-size: 11px;
  transition: transform .15s ease; display: inline-block;
}
.grp.open .grp-h::before { transform: rotate(90deg); }
.grp-h:hover { color: var(--warm); }
.grp-h:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-md); }
.grp-b { padding: 0 12px 12px; display: none; flex-direction: column; gap: 8px; }
.grp.open .grp-b { display: flex; }

/* controls */
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.row { display: flex; gap: 6px; align-items: center; }
.grow { flex: 1; }

.tool {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: var(--r-md); padding: 8px 10px; min-height: 36px;
  font: 600 13px var(--font); cursor: pointer; flex: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  transition: background .12s, border-color .12s, transform .05s;
}
.tool:hover { background: var(--mint-soft); border-color: var(--mint-deep); }
.tool:active { transform: translateY(1px); }
.tool:focus-visible { outline: none; box-shadow: var(--focus); }
.tool.wide { width: 100%; flex: none; }
.tool.primary { background: var(--warm-soft); color: #7a3d12; border-color: var(--warm-hi); }
.tool.primary:hover { background: var(--warm-hi); }
.tool.primary.is-paused { background: #cfe6d6; color: #2c6a41; border-color: var(--mint-deep); }

.slabel { font: 600 12px var(--font); color: var(--ink-soft); display: flex; justify-content: space-between; }
.slabel span { color: var(--warm); }
input[type=range] { width: 100%; accent-color: var(--warm); height: 22px; }
select, input[type=number] {
  font: 500 13px var(--font); padding: 7px 8px; border-radius: var(--r-md);
  border: 1px solid var(--line); background: #fff; color: var(--ink); min-height: 36px;
}
input[type=number] { flex: 1; width: 100%; }
select:focus-visible, input:focus-visible { outline: none; box-shadow: var(--focus); }

.radios, .checks { display: flex; flex-direction: column; gap: 6px; }
.radios label, .checks label {
  display: flex; align-items: center; gap: 8px; font: 500 13px var(--font);
  color: var(--ink); cursor: pointer; padding: 4px 2px; min-height: 28px;
}
.radios input, .checks input { accent-color: var(--warm); width: 16px; height: 16px; }

.measure-line { font: 600 11px var(--font); color: var(--ink-soft); }
.measure-val {
  font: 700 13px var(--font); color: var(--ink);
  background: var(--mint-soft); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 7px 9px; letter-spacing: .2px;
}

/* ===================== Freiform-Baukasten ===================== */
.ff-list {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 4px;
  max-height: 200px; overflow-y: auto;
}
.ff-list li {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px;
  border: 1px solid var(--line); border-radius: var(--r-md); background: #fff;
  font: 600 12px var(--font); color: var(--ink); cursor: pointer; min-height: 32px;
}
.ff-list li:hover { background: var(--mint-soft); }
.ff-list li.sel { border-color: var(--warm); background: var(--warm-soft); color: #7a3d12; }
.ff-list li.empty { justify-content: center; color: var(--ink-soft); font-weight: 500; cursor: default; }
.ff-list li.empty:hover { background: #fff; }
.ff-sw {
  width: 16px; height: 16px; border-radius: 4px; flex: 0 0 auto;
  border: 1px solid rgba(0,0,0,.18);
}
.ff-hint { font: 500 12px var(--font); color: var(--ink-soft); padding: 2px 0; }
.ff-edit {
  display: flex; flex-direction: column; gap: 8px;
  padding-top: 8px; border-top: 1px dashed var(--line);
}
.ff-color {
  width: 100%; height: 34px; padding: 2px; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--r-md); background: #fff;
}
.ff-palette { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; }
.ff-palette .p {
  height: 22px; border-radius: var(--r-sm); cursor: pointer;
  border: 2px solid transparent; box-shadow: 0 0 0 1px rgba(0,0,0,.12) inset;
}
.ff-palette .p:hover { box-shadow: 0 0 0 1px rgba(0,0,0,.28) inset; }
.ff-palette .p.on { border-color: var(--ink); }

/* ===================== Viewport ===================== */
#viewport { flex: 1 1 auto; position: relative; min-width: 0; overflow: hidden; transition: opacity .2s; }
#c { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#c:active { cursor: grabbing; }

/* Dezente Vignette: sanfte Abdunklung der Bildraender fuer Fokus auf den Fuchs.
   LIVE-ONLY -- erscheint NICHT im PNG-Export (dieser rendert nur das WebGL-Canvas
   via toDataURL, CSS-Overlays werden dabei nicht erfasst; das ist gewollt).
   z-index 3 liegt UEBER dem Canvas, aber UNTER Overlays (z4) und HUD/Controls (z5),
   sodass Bedienelemente unbeeintraechtigt hell bleiben. pointer-events:none ->
   Drag/Zoom auf dem Canvas werden nicht blockiert. */
#viewport::after {
  content: ""; position: absolute; inset: 0; z-index: 3; pointer-events: none;
  background: radial-gradient(ellipse 118% 118% at 50% 46%,
    rgba(0,0,0,0) 58%, rgba(28,42,32,0.13) 100%);
}
#viewport.checker {
  background-color: #e9e9e9;
  background-image:
    linear-gradient(45deg, #cfcfcf 25%, transparent 25%, transparent 75%, #cfcfcf 75%),
    linear-gradient(45deg, #cfcfcf 25%, transparent 25%, transparent 75%, #cfcfcf 75%);
  background-size: 22px 22px; background-position: 0 0, 11px 11px;
}

/* HUD */
.hud { position: absolute; z-index: 5; pointer-events: none; }
#hudHint {
  bottom: calc(12px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%);
  font: 500 12px var(--font); color: var(--ink-soft);
  background: rgba(255,255,255,0.72); padding: 6px 13px; border-radius: 20px;
  white-space: nowrap; box-shadow: var(--shadow-sm); max-width: 92vw;
}
/* Geraetegerechte Hinweis-Umschaltung: Default (Maus/Trackpad) zeigt Pointer-Gesten. */
.hint-touch { display: none; }
.hint-pointer { display: inline; }
#hudCam {
  top: 10px; right: 12px;
  font: 600 11px ui-monospace, "Consolas", monospace; color: var(--ink-soft);
  background: rgba(255,255,255,0.72); padding: 5px 10px; border-radius: var(--r-md);
  box-shadow: var(--shadow-sm); letter-spacing: .3px;
}
#navCluster {
  right: calc(12px + env(safe-area-inset-right, 0px));
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 6px;
  pointer-events: auto;
}
.nav-btn {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--panel-brd); background: rgba(255,255,255,0.9);
  color: var(--ink); font: 700 17px var(--font); cursor: pointer;
  box-shadow: var(--shadow-sm); display: flex; align-items: center; justify-content: center;
}
.nav-btn:hover { background: #fff; border-color: var(--mint-deep); }
.nav-btn:active { transform: translateY(1px); }
.nav-btn:focus-visible { outline: none; box-shadow: var(--focus); }

/* compositing overlays */
.overlay { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.tl { position: absolute; background: rgba(255,255,255,0.55); box-shadow: 0 0 0 0.5px rgba(0,0,0,0.18); }
.tl.v { top: 0; bottom: 0; width: 1px; }
.tl.h { left: 0; right: 0; height: 1px; }
/* Drittel-Raster-Positionen (aus frueheren Inline-style= externalisiert -> strikte CSP). */
.tl-x1 { left: 33.33%; }
.tl-x2 { left: 66.66%; }
.tl-y1 { top: 33.33%; }
.tl-y2 { top: 66.66%; }
.safebox {
  position: absolute; top: 10%; left: 10%; right: 10%; bottom: 10%;
  border: 1px dashed rgba(184,84,28,0.6); border-radius: 4px;
}

/* ===================== Referenz-Overlay (Vergleich) =====================
   Halbtransparentes Vergleichsbild UEBER dem Canvas. z-index 4 = ueber Canvas/
   Vignette, aber UNTER HUD/Nav (z5) -> Nav-Buttons bleiben klickbar. Positionierung
   (translate + scale) und Deckkraft setzt reference.js via CSSOM (el.style.*),
   NICHT per HTML-style= (strikte CSP). pointer-events:none -> Orbit laeuft durch
   das Bild; erst .editing schaltet die Zeiger-Events fuer das Bild ein. */
.ref-overlay {
  position: absolute; z-index: 4; left: 50%; top: 50%;
  max-width: 92%; max-height: 92%; width: auto; height: auto;
  transform: translate(-50%, -50%); transform-origin: center center;
  pointer-events: none; -webkit-user-select: none; user-select: none;
  will-change: transform, opacity;
}
.ref-overlay.editing {
  pointer-events: auto; cursor: move;
  outline: 2px dashed var(--warm); outline-offset: 3px;
}
.ref-hint { margin: 0; font: 500 11px var(--font); color: var(--ink-soft); }
/* Versions-/Intro-Zeile am Panel-Fuss (feedback_app_standard_intro_version_prefs). */
.app-ver { margin: 4px 0 2px; padding: 8px 4px 2px; font: 500 11px var(--font);
  color: var(--ink-soft); text-align: center; opacity: .75; }
/* dragover-Rueckmeldung: dezenter Rahmen im Viewport, wenn eine Datei schwebt. */
#viewport.ref-dragover::before {
  content: ""; position: absolute; inset: 6px; z-index: 6; pointer-events: none;
  border: 2px dashed var(--warm); border-radius: var(--r-lg);
  background: rgba(184,84,28,0.06);
}

#err {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); z-index: 6;
  color: var(--danger-ink); font-weight: 600; background: #fff;
  padding: 14px 18px; border-radius: var(--r-lg); box-shadow: var(--shadow);
}

/* ===================== Statusbar ===================== */
#statusbar {
  height: calc(var(--sb-h) + env(safe-area-inset-bottom, 0px)); flex: none; z-index: 30;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex; align-items: center; gap: 18px;
  padding-left: max(14px, env(safe-area-inset-left, 0px));
  padding-right: max(14px, env(safe-area-inset-right, 0px));
  background: linear-gradient(#ffffffcc, #ffffff99);
  border-top: 1px solid var(--panel-brd);
  font: 600 11px ui-monospace, "Consolas", monospace; color: var(--ink-soft);
}
#statusbar span { white-space: nowrap; }
#stMeasure { margin-left: auto; color: var(--warm); }

/* ===================== Scrim (mobile drawer) ===================== */
#scrim { position: fixed; inset: 0; z-index: 15; background: rgba(30,45,35,0.35); }

/* =====================================================================
   RESPONSIVE  --  Mobile-first-Verfeinerung in 3 Stufen.
   Desktop  (>900px)  : Panel als angedockte Seitenleiste (Basisregeln oben).
   Tablet   (<=900px) : schmaleres angedocktes Panel, groessere Touch-Ziele.
   Drawer   (<=720px) : Panel wird zum Overlay-Drawer (deckt sich mit
                        platform.js narrow()==720 -> Scrim/Initial-Collapse).
   Phone    (<=600px) : maximale Topbar-Verdichtung, Schliessen IMMER sichtbar.
   ===================================================================== */

/* ---- Tablet: angedockt, aber kompakter + fingerfreundlich ---------- */
@media (max-width: 900px) {
  :root { --panel-w: 264px; }
  /* Touch-Ziele >= 44px (WCAG 2.5.5 / Apple HIG). */
  .tb-btn, .tool, select, input[type=number] { min-height: 44px; }
  .tb-btn { padding: 10px 14px; }
  .nav-btn { width: 46px; height: 46px; }
  .radios label, .checks label { min-height: 40px; }
  .grp-h { padding: 13px 12px; }
  .tb-sel { max-width: 40vw; }
}

/* ---- Drawer: Panel als seitliches Overlay ------------------------- */
@media (max-width: 720px) {
  #panel {
    position: absolute; z-index: 20;
    /* top:0 -- der Drawer fuellt #stage, das bereits UNTER der Topbar beginnt (stage ist
       der positionierte Container). Frueher top:calc(--tb-h+safe) -> der Offset wurde
       DOPPELT gezaehlt (Topbar-Hoehe + nochmal in stage) -> 50px-Spalt: das Panel
       schwebte losgeloest unter der Topbar ("2 Fenster ueberlappen/schweben"). */
    top: 0; bottom: 0; left: 0;
    width: min(86vw, 320px);
    padding-left: max(10px, env(safe-area-inset-left, 0px));
    padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
    border-right: 1px solid var(--panel-brd);
    border-radius: 0 var(--r-lg) var(--r-lg) 0;
    box-shadow: var(--shadow); transform: translateX(0);
    -webkit-overflow-scrolling: touch;
  }
  body.panel-collapsed #panel {
    width: min(86vw, 320px); padding: 10px; transform: translateX(-102%);
  }
  #scrim {
    top: calc(var(--tb-h) + env(safe-area-inset-top, 0px));
  }
  /* Touch-Hinweis statt Maus/Trackpad-Gesten. */
  .hint-pointer { display: none; }
  .hint-touch { display: inline; }
  #hudHint {
    font-size: 11.5px; max-width: 90vw; white-space: normal; text-align: center;
    line-height: 1.35; bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }
}

/* ---- Phone: Topbar maximal verdichten ---------------------------- */
@media (max-width: 600px) {
  /* Titel weicht, damit Zurueck (links) UND Schliessen (rechts) garantiert passen. */
  #title { display: none; }
  /* Zurueck = reines Chevron-Icon (Text via aria-label erhalten). */
  #btnBack .tb-lbl { display: none; }
  #btnBack { padding: 10px 12px; }
  .tb-btn.ghost, .tb-btn.danger { min-width: 44px; }
  #topbar { gap: 6px; }
  /* Modell-Auswahl kompakt, aber lesbar. */
  .tb-sel { max-width: 118px; margin-right: 4px; padding: 8px; font-size: 12.5px; }
  /* Kamera-HUD auf sehr schmal ausblenden (Platz + Ueberlagerung). */
  #hudCam { display: none; }
  /* Nav-Cluster etwas kleiner, damit er den Hinweis nicht bedraengt. */
  .nav-btn { width: 44px; height: 44px; }
}

/* ---- Sehr niedrig (Landscape-Phone): Statusbar-Text kuerzen -------- */
@media (max-height: 430px) and (max-width: 900px) {
  #stView { display: none; }
}

/* ===================== Reduced motion ===================== */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ===================== Touch-Geraete: iOS-Fokus-Zoom aus =====================
   iOS Safari zoomt die GANZE Seite beim Fokussieren eines Formularfelds mit
   Schriftgroesse < 16px (dokumentiertes WebKit-Verhalten). Genau das erzeugt das
   "Menue/Topbar wackelt bei Fokus/Tastatur": Antippen von Modell-Select,
   Massstab-/FOV-Zahl -> Auto-Zoom + Layout-Sprung. 16px auf Touch-Geraeten
   (pointer:coarse) verhindert den Zoom OHNE die Desktop-Dichte (13px) zu aendern.
   Bewusst NUR auf coarse-Pointer: Maus/Trackpad behalten die kompakte Groesse. */
@media (pointer: coarse) {
  select, input[type="number"], input[type="text"], input[type="search"],
  .tb-sel, .cb-pnum, .cmdpal-input, #massScale {
    font-size: 16px;
  }
}

/* ===================== Bottom-Command-Bar ===================== */
#cmdbar {
  flex: none; background: var(--panel-bg); border-top: 1px solid var(--panel-brd);
  box-shadow: 0 -2px 10px rgba(40,70,50,0.08); z-index: 12;
  padding: 6px calc(8px + env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) calc(8px + env(safe-area-inset-left));
  -webkit-backdrop-filter: saturate(1.4) blur(8px); backdrop-filter: saturate(1.4) blur(8px);
}
.cb-row { display: flex; align-items: center; gap: 6px; overflow-x: auto; overflow-y: hidden; overscroll-behavior: contain; scrollbar-width: thin; }
.cb-row::-webkit-scrollbar { height: 5px; }
.cb-row::-webkit-scrollbar-thumb { background: var(--mint-deep); border-radius: 3px; }
.cb-btn {
  flex: 0 0 auto; min-width: 46px; min-height: 46px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; padding: 4px 8px; border: 0; border-radius: var(--r-md);
  background: transparent; color: var(--ink); font: 600 11px var(--font); cursor: pointer; touch-action: manipulation;
}
.cb-btn:hover { background: var(--mint-soft); }
.cb-btn:active { transform: scale(0.94); }
.cb-btn:focus-visible { outline: none; box-shadow: var(--focus); }
.cb-btn.is-active { background: var(--mint-deep); color: #123a22; }
.cb-ico { font-size: 18px; line-height: 1; }
.cb-lbl { white-space: nowrap; }
.cb-sub { min-width: 44px; font-size: 20px; padding: 4px 6px; }
.cb-seg { display: flex; gap: 2px; background: var(--card-bg); border-radius: var(--r-lg); padding: 2px; flex: 0 0 auto; }
.cb-sep { flex: 0 0 auto; width: 1px; align-self: stretch; margin: 7px 2px; background: var(--line); }
.cb-spacer { flex: 1 1 auto; min-width: 4px; }
.cb-param { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; padding: 0 4px; }
.cb-plbl { font: 600 11px var(--font); color: var(--ink-soft); white-space: nowrap; }
.cb-prange { width: 96px; touch-action: none; }
.cb-pnum {
  width: 52px; min-height: 40px; border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 4px 6px; font: 600 13px var(--font); text-align: center; background: #fff; color: var(--ink);
}
.cb-pnum:focus-visible, .cb-prange:focus-visible { outline: none; box-shadow: var(--focus); }
.cb-pal { color: var(--warm); }
@media (max-width: 640px) {
  .cb-lbl { display: none; }
  .cb-plbl { display: none; }
  .cb-prange { width: 66px; }
  .cb-btn { min-width: 44px; padding: 4px 6px; }
  .cb-spacer { display: none; }   /* Items links packen + natuerlich scrollen statt Spacer */
  .cb-pnum { width: 46px; }
}

/* ===================== Command-Palette ===================== */
.cmdpal {
  position: fixed; inset: 0; z-index: 30; background: rgba(30,45,35,0.35);
  display: flex; align-items: flex-start; justify-content: center; padding: 11vh 16px 16px;
}
.cmdpal[hidden] { display: none; }
.cmdpal-box {
  width: min(560px, 100%); background: #fff; border-radius: var(--r-lg); box-shadow: var(--shadow);
  overflow: hidden; display: flex; flex-direction: column; max-height: 72vh;
}
.cmdpal-input {
  border: 0; border-bottom: 1px solid var(--line); padding: 15px 18px; font: 500 16px var(--font);
  outline: none; color: var(--ink);
}
.cmdpal-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; }
.cmdpal-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--r-sm);
  cursor: pointer; font: 500 14px var(--font); color: var(--ink);
}
.cmdpal-item .ci-grp { margin-left: auto; font-size: 11px; color: var(--ink-soft); }
.cmdpal-item.sel, .cmdpal-item:hover { background: var(--mint-soft); }
.cmdpal-empty { padding: 16px 18px; color: var(--ink-soft); font: 500 14px var(--font); }

/* ============ Freiform-Kontext-Leiste (schwebt ueber dem Canvas bei Auswahl) ============ */
.ff-ctx {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center;
  max-width: min(94%, 620px); padding: 8px 10px;
  background: var(--panel-bg); border: 1px solid var(--panel-brd);
  border-radius: var(--r-lg); box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); z-index: 6;
}
.ff-ctx-name { font: 600 12px var(--font); color: var(--ink-soft); padding: 0 4px; white-space: nowrap; }
.ff-ctx-colors { display: flex; gap: 5px; }
.ff-ctx-colors .p {
  width: 24px; height: 24px; border-radius: 6px; cursor: pointer;
  border: 2px solid rgba(255,255,255,0.85); box-shadow: 0 1px 3px rgba(40,70,50,0.25);
}
.ff-ctx-colors .p.on { outline: 2px solid var(--ink); outline-offset: 1px; }
.ff-ctx-sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 2px; }
.ff-ctx-btn {
  min-width: 40px; height: 40px; padding: 0 10px; border: 1px solid var(--line);
  background: var(--card-bg); border-radius: var(--r-md); cursor: pointer;
  font-size: 18px; color: var(--ink); display: inline-flex; align-items: center; justify-content: center;
}
.ff-ctx-btn:hover { background: var(--mint-soft); }
.ff-ctx-btn:focus-visible { outline: none; box-shadow: var(--focus); }
.ff-ctx-btn[aria-pressed="true"] { background: var(--warm-soft); border-color: var(--warm); color: var(--warm); }
.ff-ctx-btn.danger:hover { background: var(--danger); color: var(--danger-ink); }
@media (max-width: 640px) {
  .ff-ctx { bottom: calc(var(--sb-h) + 8px); gap: 6px; padding: 7px 8px; }
  .ff-ctx-name { display: none; }
  .ff-ctx-colors .p { width: 26px; height: 26px; }   /* Touch-Ziele etwas groesser */
}
