/* PatternMaster UI */
:root {
  --bg: #14171c;
  --panel: #1c2128;
  --panel2: #232a33;
  --line: #2e3742;
  --fg: #d6dde6;
  --muted: #8a96a6;
  --accent: #f0a54a;
  --accent2: #4a9ff0;
  --warn: #e0574b;
  --ok: #4fbf7b;
  --ctl-w: 150px;   /* uniform width of the value-control column in .field rows */
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--fg);
  display: flex; flex-direction: column; height: 100vh; overflow: hidden;
}
#app { flex: 1; display: grid; grid-template-columns: 360px 1fr; min-height: 0; overflow: hidden; }

/* Sidebar */
#sidebar { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 12px; }
#sidebar h1 { font-size: 15px; margin: 4px 0 2px; letter-spacing: .5px; }
#sidebar .sub { color: var(--muted); font-size: 11px; margin-bottom: 12px; }

/* Tier = Obergruppe (SETUP / DESIGN / EXPORT). Ein randloser Balken, der aus dem 12px-Padding
   der Sidebar ausbricht. Genau dieser Ausbruch lässt die Karten darunter eingerückt wirken,
   ohne sie einzurücken — die Feldbreite bleibt exakt wie vorher. Dunkler als die Sidebar, die
   Karten heller: Balken < Sidebar < Karte ergibt die Tiefenstaffelung.
   Kein ▸/▾ — der offene Tier ist farblich markiert, und die Chevrons bleiben den Karten. */
.tier { margin: 0 -12px; }
#sidebar { counter-reset: tier; }
.tier > summary {
  cursor: pointer; list-style: none; user-select: none;
  padding: 7px 12px; background: var(--bg); border-bottom: 1px solid var(--line);
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px;
  color: var(--muted);
}
.tier > summary::-webkit-details-marker { display: none; }
/* Durchnummeriert (1 Setup · 2 Design · 3 Export): die Tiers bilden die Abfolge vom Einrichten
   übers Gestalten zum Export. Counter statt Zahlen im Markup, damit die Reihenfolge sich beim
   Umsortieren von selbst korrigiert. */
.tier > summary::before {
  counter-increment: tier; content: counter(tier);
  display: inline-block; width: 15px; margin-right: 8px;
  color: var(--line); font-variant-numeric: tabular-nums;
}
.tier:first-of-type > summary { border-top: 1px solid var(--line); }
.tier > summary:hover { color: var(--fg); }
.tier[open] > summary { color: var(--accent); }
.tier[open] > summary::before { color: var(--accent); }
/* Holt die Karten auf ihre ursprüngliche Position zurück (siehe margin oben). */
.tier-body { padding: 10px 12px 4px; }

/* Karte = Untergruppe. Geometrie unverändert; nur die Typo tritt einen Schritt zurück,
   damit sie nicht mit dem Balken konkurriert (Normalschreibung statt Versalien/Akzent). */
.group { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; background: var(--panel2); }
.group > summary {
  cursor: pointer; padding: 8px 10px; font-weight: 600; font-size: 12px;
  letter-spacing: .2px; color: var(--fg); list-style: none; user-select: none;
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary::before { content: "▸ "; color: var(--muted); }
.group[open] > summary::before { content: "▾ "; }
.group .body { padding: 6px 10px 10px; }

.field { display: grid; grid-template-columns: 1fr var(--ctl-w); align-items: center; gap: 6px; margin: 7px 0; }
.field label { color: var(--muted); font-size: 12px; }
.field .val { color: var(--fg); font-variant-numeric: tabular-nums; font-size: 12px; min-width: 46px; text-align: right; }
.field input[type=number], .field select, .field input[type=text] {
  width: 100%; min-width: 0; background: var(--bg); color: var(--fg); border: 1px solid var(--line);
  border-radius: 5px; padding: 4px 6px; font: inherit;
}
.field input[type=range] { grid-column: 1 / 2; width: 100%; accent-color: var(--accent); }
.field.range { grid-template-columns: 1fr 48px; }
.field.full { grid-template-columns: 1fr; }
.field.full button { width: 100%; }
.field input[type=color] { width: 100%; height: 26px; border: 1px solid var(--line); border-radius: 5px; background: var(--bg); }
.inline { display: flex; gap: 5px; align-items: center; width: 100%; }
.inline input { flex: 1 1 0; min-width: 0; }
.inline button { flex: 0 0 auto; }

button {
  background: var(--panel2); color: var(--fg); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 10px; font: inherit; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #201400; border-color: var(--accent); font-weight: 600; }
button.dice { padding: 4px 8px; }

/* App toolbar (full width) */
#toolbar {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  border-bottom: 1px solid var(--line); background: var(--panel); flex: 0 0 auto;
}
#toolbar .app-title { font-size: 15px; font-weight: 700; letter-spacing: .5px; }
#toolbar .app-sub { color: var(--muted); font-size: 11px; margin-right: 8px; }
#toolbar .spacer { flex: 1; }
#toolbar .stat { color: var(--muted); font-size: 12px; }
#toolbar .stat b { color: var(--fg); font-variant-numeric: tabular-nums; }
#toolbar .tb-sep { width: 1px; align-self: stretch; background: var(--line); margin: 4px 4px; }

/* Main */
#main { display: flex; flex-direction: column; min-width: 0; }

#stage {
  flex: 1; display: flex; align-items: center; justify-content: center; position: relative;
  padding: 18px; overflow: hidden; min-height: 0;
  background:
    linear-gradient(45deg, #171b21 25%, transparent 25%) 0 0/20px 20px,
    linear-gradient(-45deg, #171b21 25%, transparent 25%) 0 0/20px 20px,
    linear-gradient(45deg, transparent 75%, #171b21 75%) 0 0/20px 20px,
    linear-gradient(-45deg, transparent 75%, #171b21 75%) 0 0/20px 20px,
    var(--bg);
}
#viewWrap { position: relative; box-shadow: 0 6px 30px rgba(0,0,0,.5); line-height: 0; }
#view { display: block; border-radius: 2px; }
#axis { position: absolute; left: 6px; bottom: 6px; color: var(--accent2); font-size: 11px; pointer-events: none; text-shadow: 0 1px 2px #000; }
#viewTime { position: absolute; left: 6px; bottom: 24px; color: var(--muted); font-size: 11px; pointer-events: none; text-shadow: 0 1px 2px #000; font-variant-numeric: tabular-nums; }

/* Overlay-Leiste oben rechts: Reset + 2D/3D/CAM-Umschalter */
#viewCtl {
  position: absolute; top: 12px; right: 12px; z-index: 10;
  display: flex; align-items: stretch; gap: 8px;
}
#btnResetView {
  background: rgba(20,23,28,.85); border: 1px solid var(--line); border-radius: 8px;
  color: var(--muted); padding: 6px 12px; font: inherit; font-weight: 600;
  cursor: pointer; backdrop-filter: blur(4px); white-space: nowrap;
}
#btnResetView:hover { color: var(--fg); border-color: var(--accent); }
#btnResetView[hidden] { display: none; }

#viewToggle {
  display: flex; background: rgba(20,23,28,.85); border: 1px solid var(--line);
  border-radius: 8px; overflow: hidden; backdrop-filter: blur(4px);
}
#viewToggle button {
  border: 0; border-radius: 0; background: transparent; color: var(--muted);
  padding: 6px 14px; font-weight: 600; cursor: pointer;
}
#viewToggle button:hover { color: var(--fg); }
#viewToggle button.active { background: var(--accent); color: #201400; }

/* 3D control hint (bottom-right, only shown in 3D) */
#viewHint {
  position: absolute; right: 12px; bottom: 10px; z-index: 10;
  color: var(--muted); font-size: 11px; pointer-events: none;
  background: rgba(20,23,28,.7); border: 1px solid var(--line);
  border-radius: 6px; padding: 4px 9px; backdrop-filter: blur(4px); display: none;
}

/* toggle switch */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; cursor: pointer; background: var(--bg);
  border: 1px solid var(--line); border-radius: 22px; transition: .15s;
}
.switch .slider::before {
  content: ""; position: absolute; height: 16px; width: 16px; left: 2px; top: 2px;
  background: var(--muted); border-radius: 50%; transition: .15s;
}
.switch input:checked + .slider { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); background: #201400; }

#metrics {
  border-top: 1px solid transparent; background: transparent;
  padding: 0 14px; display: flex; gap: 20px; flex-wrap: wrap; font-size: 12px;
  min-height: 0; transition: padding .1s;
}
#metrics:has(#mErrWrap:not([style*="display:none"])):not(:empty) {
  border-top-color: var(--line); background: var(--panel); padding: 6px 14px;
}
/* range2 (from–to): two inputs sharing the same control column as a single field */
.r2wrap { display: flex; align-items: center; gap: 5px; width: 100%; }
.r2wrap input {
  flex: 1 1 0; min-width: 0; background: var(--bg); color: var(--fg);
  border: 1px solid var(--line); border-radius: 5px; padding: 4px 5px; font: inherit;
}
.r2wrap .r2sep { color: var(--muted); font-size: 12px; user-select: none; flex: 0 0 auto; }

/* Vertical path scrubber — own column beside the preview, never overlapping it */
#stageRow { flex: 1; display: flex; min-height: 0; min-width: 0; }
#pathSliderWrap {
  flex: 0 0 38px; display: flex; flex-direction: column; align-items: center;
  gap: 6px; padding: 10px 0; background: var(--panel);
  border-left: 1px solid var(--line);
}
#pathSliderWrap .ps-cap { color: var(--muted); font-size: 10px; flex: 0 0 auto; }
#pathSlider {
  /* Senkrechter Regler: writing-mode ist der standardisierte Weg. Das frühere
     appearance:slider-vertical ist abgekündigt und hier nicht mehr nötig.
     direction:rtl dreht die Skala um -> oben = alle Bahnen, unten = die erste. */
  writing-mode: vertical-lr; direction: rtl;
  width: 6px; flex: 1 1 auto; min-height: 0;
  cursor: ns-resize; accent-color: var(--accent); margin: 0; padding: 0;
}

/* (?) help badge next to every adjustable-value label */
/* Center the badge with the label text via flex — reliable regardless of font metrics. */
.field label:has(.helpico), label:has(.helpico) { display: inline-flex; align-items: center; gap: 5px; }
.helpico {
  display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; margin-left: 0; padding: 0;
  border: 1px solid var(--line); border-radius: 50%; background: transparent;
  color: var(--muted); font-size: 9px; font-weight: 700; line-height: 1;
  cursor: help; flex: 0 0 auto;
}
.helpico:hover, .helpico.open { border-color: var(--accent); color: var(--accent); }

/* Help popover */
#helpPop {
  position: fixed; z-index: 200; width: 310px; max-width: calc(100vw - 24px);
  max-height: 70vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 9px;
  box-shadow: 0 12px 38px rgba(0,0,0,.6); padding: 12px 14px;
  font-size: 12px; line-height: 1.55; color: var(--fg);
}
#helpPop[hidden] { display: none; }
#helpPop h4 { margin: 0 0 8px; font-size: 12px; color: var(--accent); letter-spacing: .4px; text-transform: uppercase; }
#helpPop p { margin: 0 0 8px; }
#helpPop p:last-child { margin-bottom: 0; }
#helpPop ul { margin: 0 0 8px; padding-left: 16px; }
#helpPop li { margin: 2px 0; }
#helpPop code {
  background: var(--bg); border: 1px solid var(--line); border-radius: 3px;
  padding: 1px 4px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px;
}
#helpPop b { color: #fff; }
#helpPop .hint { color: var(--muted); }
#helpPop .warn { color: var(--warn); }

#metrics .m { color: var(--muted); }
#metrics .m b { color: var(--fg); font-variant-numeric: tabular-nums; }
#metrics .warn b { color: var(--warn); }
#busy { color: var(--accent); font-size: 12px; }
