/* Nigin 3D Studio -- 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; }
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;
}
body { display: flex; flex-direction: column; height: 100vh; }
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;
  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;
}

/* ===================== 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;
}

#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: calc(var(--tb-h) + env(safe-area-inset-top, 0px)); 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; }
}
