/* 3D-Druck-Werkzeuge – shared layout, theme and controls */

:root {
  color-scheme: dark;
  --bg: #0e0f12;
  --stage-bg: #131519;
  --panel: #191b20;
  --panel-2: #1f2228;
  --card: #22262d;
  --line: #2c3038;
  --line-strong: #3a3f49;
  --text: #e7e9ec;
  --text-muted: #9aa1ab;
  --text-faint: #6b727d;
  --accent: #ff9f43;
  --accent-ink: #1a1206;
  --accent-soft: rgba(255, 159, 67, 0.14);
  --focus: #ffb870;
  --warn: #ffb020;
  --danger: #ff5a5f;
  --ok: #4cc38a;
  --plate: #2a2e36;
  --plate-edge: #4d535e;
  --canvas-edge: rgba(255, 255, 255, 0.16);
  --margin-line: rgba(255, 255, 255, 0.28);
  --gizmo: #eef0f3;
  --gizmo-ink: #121418;
  --logo-ink: #1a1206;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --radius: 10px;
  --radius-sm: 7px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef0f3;
  --stage-bg: #e6e9ee;
  --panel: #fbfbfc;
  --panel-2: #f2f4f7;
  --card: #ffffff;
  --line: #e1e4e9;
  --line-strong: #cfd4db;
  --text: #1c1f24;
  --text-muted: #5d6570;
  --text-faint: #8a929c;
  --accent: #f28c1b;
  --accent-ink: #ffffff;
  --accent-soft: rgba(242, 140, 27, 0.12);
  --focus: #f28c1b;
  --warn: #e39100;
  --danger: #e5484d;
  --ok: #1f9d63;
  --plate: #fdfdfe;
  --plate-edge: #9aa3ae;
  --canvas-edge: rgba(0, 0, 0, 0.18);
  --margin-line: rgba(0, 0, 0, 0.3);
  --gizmo: #2b3038;
  --gizmo-ink: #ffffff;
  --logo-ink: #ffffff;
  --shadow: 0 10px 30px rgba(20, 30, 50, 0.18);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #eef0f3;
    --stage-bg: #e6e9ee;
    --panel: #fbfbfc;
    --panel-2: #f2f4f7;
    --card: #ffffff;
    --line: #e1e4e9;
    --line-strong: #cfd4db;
    --text: #1c1f24;
    --text-muted: #5d6570;
    --text-faint: #8a929c;
    --accent: #f28c1b;
    --accent-ink: #ffffff;
    --accent-soft: rgba(242, 140, 27, 0.12);
    --focus: #f28c1b;
    --warn: #e39100;
    --danger: #e5484d;
    --ok: #1f9d63;
    --plate: #fdfdfe;
    --plate-edge: #9aa3ae;
    --canvas-edge: rgba(0, 0, 0, 0.18);
    --margin-line: rgba(0, 0, 0, 0.3);
    --gizmo: #2b3038;
    --gizmo-ink: #ffffff;
    --logo-ink: #ffffff;
    --shadow: 0 10px 30px rgba(20, 30, 50, 0.18);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.icon { width: 18px; height: 18px; flex: none; }

/* ---------- layout ---------- */

.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr) 312px;
  grid-template-rows: 52px minmax(0, 1fr);
  grid-template-areas:
    "top top top"
    "left stage right";
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.brand { display: flex; align-items: center; gap: 9px; min-width: 0; color: inherit; text-decoration: none; border-radius: var(--radius-sm); }
.brand:hover .brand-name { color: var(--accent); }
.brand .logo { width: 28px; height: 28px; display: block; }
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: 0.1px; white-space: nowrap; }
.brand-sub { color: var(--text-muted); font-size: 12px; white-space: nowrap; }

.toolbar { display: flex; align-items: center; gap: 4px; margin: 0 auto; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 6px; }

.tool {
  display: inline-grid;
  place-items: center;
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
}
.tool:hover:not(:disabled) { background: var(--panel-2); color: var(--text); }
.tool:disabled { opacity: 0.35; cursor: default; }
.tool.active { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.tool.small { min-width: 30px; height: 30px; font-size: 17px; line-height: 1; }

.view-switch { display: flex; gap: 2px; padding: 2px; border-radius: 9px; background: var(--panel-2); margin-left: 4px; }
.view-switch .tool { height: 30px; min-width: 32px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--panel-2);
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
}
.btn:hover { border-color: var(--text-faint); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.small { height: 30px; padding: 0 10px; font-weight: 500; font-size: 12.5px; }
.btn.small .icon { width: 15px; height: 15px; }
.btn.ghost { background: transparent; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

/* ---------- panels ---------- */

.panel {
  background: var(--panel);
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
  padding: 6px 0 24px;
}
.panel-left { grid-area: left; border-right: 1px solid var(--line); }
.panel-right { grid-area: right; border-left: 1px solid var(--line); }

.section { border-bottom: 1px solid var(--line); }
.section-header { display: flex; align-items: center; padding-right: 8px; }
.section-head {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 12px 11px 14px;
  background: none;
  border: 0;
  text-align: left;
  font-weight: 650;
  font-size: 12.5px;
  letter-spacing: 0.2px;
  min-width: 0;
}
.section-icon { color: var(--text-muted); display: inline-flex; }
.section-icon .icon { width: 16px; height: 16px; }
.section-title { flex: 1; }
.chevron { color: var(--text-faint); display: inline-flex; transition: transform 0.15s; transform: rotate(-90deg); }
.chevron .icon { width: 16px; height: 16px; }
.section.open .chevron { transform: none; }
.section-body { display: none; padding: 0 14px 14px; }
.section.open .section-body { display: grid; gap: 10px; }
.section-body > *, .mod-body > *, .ctl-grid > * { min-width: 0; }

.subhead {
  margin: 6px 0 -2px;
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-faint);
}

/* ---------- controls ---------- */

.ctl { display: grid; gap: 5px; min-width: 0; }
.ctl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ctl-grid > .wide { grid-column: 1 / -1; }
/* All fields hidden: no empty gap in the section. */
.ctl-grid:not(:has(> :not([hidden]))) { display: none; }
.ctl-label {
  font-size: 11.5px;
  color: var(--text-muted);
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ctl-label.scrub { cursor: ew-resize; }
.ctl-label.scrub:hover { color: var(--text); }

.ctl-field {
  position: relative;
  display: flex;
  align-items: center;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  min-width: 0;
}
.ctl-field:focus-within { border-color: var(--accent); }
.ctl-field input, .ctl-field select {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  background: transparent;
  padding: 0 8px;
  outline: none;
  font-variant-numeric: tabular-nums;
}
.ctl-field select { padding-right: 4px; cursor: pointer; }
.ctl-field select option { background: var(--panel); color: var(--text); }
.ctl-field .unit { padding-right: 8px; color: var(--text-faint); font-size: 11.5px; pointer-events: none; }
.ctl-field input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.ctl-field input::-webkit-outer-spin-button, .ctl-field input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.ctl-slider {
  width: 100%;
  margin: 2px 0 0;
  accent-color: var(--accent);
  height: 18px;
}

.segmented {
  display: flex;
  gap: 2px;
  padding: 2px;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.segmented.grid-seg { display: grid; }
.seg-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 26px;
  padding: 3px 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.15;
  text-align: center;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25), inset 0 0 0 1px var(--line-strong); }
.seg-btn .icon { width: 15px; height: 15px; }

.ctl-toggle { display: flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; min-height: 24px; }
.ctl-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch {
  position: relative;
  width: 30px;
  height: 17px;
  flex: none;
  border-radius: 20px;
  background: var(--line-strong);
  transition: background 0.15s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
.ctl-toggle input:checked + .switch { background: var(--accent); }
.ctl-toggle input:checked + .switch::after { transform: translateX(13px); }
.ctl-toggle input:focus-visible + .switch { outline: 2px solid var(--focus); outline-offset: 2px; }
.ctl-text { font-size: 12.5px; color: var(--text); }

.ctl-color .color-field { padding-left: 4px; gap: 6px; }
.ctl-color input[type="color"] {
  flex: none;
  width: 26px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: none;
  cursor: pointer;
}
.ctl-color input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.ctl-color input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 5px; }
.ctl-color .hex { font-family: var(--mono); font-size: 11.5px; color: var(--text-muted); }

.ctl-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.ctl-inline { display: flex; gap: 6px; }
.ctl-inline input[type="text"] {
  flex: 1;
  min-width: 0;
  height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  outline: none;
}
.ctl-inline input[type="text"]:focus { border-color: var(--accent); }
.ctl-dice { align-content: end; }
.ctl-dice .btn { width: 100%; }

.ctl-note { margin: 0; font-size: 12px; color: var(--text-muted); line-height: 1.45; }
.ctl-note b { color: var(--text); font-weight: 600; }
.ctl-note.warn, .ctl-note .warn, .warn { color: var(--warn); }
.ctl-note .danger, .danger { color: var(--danger); }
.ctl-note .ok, .ok { color: var(--ok); }

/* ---------- presets ---------- */

.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 8px; }
.preset-grid .ctl-note { grid-column: 1 / -1; }
.preset-wrap { position: relative; display: grid; }
.preset {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 6px 4px 5px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel-2);
  min-width: 0;
}
.preset:hover { border-color: var(--accent); }
.preset-thumb { width: 56px; height: 56px; display: block; }
.preset-name { font-size: 11px; color: var(--text-muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preset-del {
  position: absolute;
  top: -6px;
  right: -6px;
  display: none;
  place-items: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--card);
  color: var(--text-muted);
}
.preset-del .icon { width: 12px; height: 12px; }
.preset-wrap:hover .preset-del, .preset-del:focus-visible { display: grid; }

/* ---------- small buttons ---------- */

.spacer { flex: 1; }
.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 25px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-faint);
}
.icon-btn:hover:not(:disabled) { background: var(--card); color: var(--text); }
.icon-btn:disabled { opacity: 0.3; cursor: default; }
.icon-btn .icon { width: 15px; height: 15px; }

/* ---------- stage ---------- */

.stage { grid-area: stage; position: relative; overflow: hidden; background: var(--stage-bg); min-width: 0; min-height: 0; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.view3d { position: absolute; inset: 0; }
.view3d canvas { display: block; width: 100%; height: 100%; }
.view3d .msg {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  padding: 20px;
  text-align: center;
}

.hint {
  position: absolute;
  top: 12px;
  left: 12px;
  max-width: calc(100% - 24px);
  padding: 6px 11px;
  border-radius: 20px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--line);
  color: var(--text-muted);
  font-size: 12px;
  pointer-events: none;
  backdrop-filter: blur(6px);
}
.hint b { color: var(--accent); font-weight: 600; }

.zoom-tools {
  position: absolute;
  right: 12px;
  top: 12px;
  display: grid;
  gap: 4px;
  padding: 3px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--line);
}

.statusbar {
  position: absolute;
  right: 12px;
  bottom: 12px;
  max-width: calc(100% - 180px);
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px 14px;
  padding: 7px 12px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--panel) 90%, transparent);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--text-muted);
  backdrop-filter: blur(6px);
  font-variant-numeric: tabular-nums;
}
.statusbar b { color: var(--text); font-weight: 600; }
.statusbar .warn b, .statusbar .warn { color: var(--warn); }
.statusbar .danger b, .statusbar .danger { color: var(--danger); }
.statusbar .ok b { color: var(--ok); }

.mobile-tabs { display: none; }
.mode-3d .zoom-tools { display: none; }

/* ---------- dialogs ---------- */

.dialog {
  width: min(720px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(5, 6, 8, 0.55); backdrop-filter: blur(2px); }
.dialog-inner { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; max-height: calc(100dvh - 26px); }
.dialog-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; font-size: 16px; flex: 1; }
.dialog-body { overflow-y: auto; padding: 16px; display: grid; gap: 14px; }
.dialog-foot { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.dialog-foot .summary { margin-right: auto; color: var(--text-muted); font-size: 12px; }

.formats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.format {
  display: grid;
  gap: 3px;
  align-content: start;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  text-align: left;
}
.format:hover { border-color: var(--line-strong); }
.format.active { border-color: var(--accent); background: var(--accent-soft); }
.format b { font-size: 14px; }
.format span { font-size: 11.5px; color: var(--text-muted); }
.format .tag { justify-self: start; margin-top: 3px; padding: 1px 6px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); font-size: 10.5px; }
.export-options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.export-options .wide { grid-column: 1 / -1; }
.info-box {
  padding: 11px 13px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.5;
}
.info-box b { color: var(--text); }
.info-box ol { margin: 6px 0 0; padding-left: 18px; }
.info-box a { color: var(--accent); }

.help .dialog-body { font-size: 13px; line-height: 1.55; color: var(--text-muted); }
.help h3 { margin: 6px 0 2px; color: var(--text); font-size: 13.5px; }
.help p, .help ul { margin: 0; }
.help ul { padding-left: 18px; }
.help kbd {
  font-family: var(--mono);
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--line-strong);
  background: var(--panel-2);
  color: var(--text);
}
.help a { color: var(--accent); }
.inline-icon .icon { width: 14px; height: 14px; vertical-align: -2px; }

.toast {
  position: fixed;
  left: 50%;
  top: 64px;
  transform: translate(-50%, -12px);
  padding: 9px 14px;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
  font-size: 12.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.noscript { padding: 24px; }

/* ---------- responsive ---------- */

@media (max-width: 1100px) {
  .app { grid-template-columns: 244px minmax(0, 1fr) 288px; }
  .brand-sub { display: none; }
}

@media (max-width: 860px) {
  html, body { height: auto; }
  .app {
    height: auto;
    min-height: 100dvh;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 58vh auto auto;
    grid-template-areas:
      "top"
      "stage"
      "tabs"
      "panel";
  }
  .topbar { flex-wrap: wrap; gap: 6px; padding: 6px 10px; position: sticky; top: 0; z-index: 5; }
  .toolbar { order: 3; width: 100%; justify-content: center; margin: 0; }
  .top-actions { margin-left: auto; }
  .panel { grid-area: panel; border: 0; overflow: visible; padding-bottom: 40px; }
  .panel:not(.mobile-active) { display: none; }
  .mobile-tabs {
    grid-area: tabs;
    display: flex;
    gap: 4px;
    padding: 6px 10px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    border-top: 1px solid var(--line);
  }
  .mobile-tabs button {
    flex: 1;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-2);
    color: var(--text-muted);
    font-weight: 600;
  }
  .mobile-tabs button.active { border-color: var(--accent); color: var(--text); background: var(--accent-soft); }
  .statusbar { left: 10px; right: 10px; bottom: 10px; max-width: none; justify-content: flex-start; }
  .hint, .zoom-tools { display: none; }
  .formats { grid-template-columns: 1fr 1fr; }
  .export-options { grid-template-columns: 1fr; }
}

@media (max-width: 420px) {
  .brand-name { font-size: 14px; }
  .btn#btn-export span { display: none; }
}
