:root {
  color-scheme: dark;
  --bg: #121316;
  --panel: #1b1e24;
  --panel-2: #232832;
  --text: #f3f5f7;
  --muted: #9aa4b2;
  --line: #343b47;
  --accent: #36c4a1;
  --accent-2: #f5b14c;
  --danger: #ff6f91;
  --scene-bg: #121316;
  --dof-blur: 8px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: #272d37;
  color: var(--text);
  min-height: 38px;
  border-radius: 7px;
  padding: 0 12px;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

button:hover {
  border-color: #526072;
  transform: translateY(-1px);
}

button.active,
button.primary {
  border-color: transparent;
  background: var(--accent);
  color: #071411;
  font-weight: 750;
}

button.primary {
  background: var(--accent-2);
  color: #181006;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(240px, 300px) minmax(420px, 1fr) minmax(190px, 230px);
  height: 100vh;
}

.panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px;
  overflow: auto;
}

.right-panel {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 18px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  aspect-ratio: 1;
  border-radius: 7px;
  background: linear-gradient(145deg, var(--accent), #8ed7cc);
  color: #06130f;
  font-size: 24px;
  font-weight: 900;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 17px;
  line-height: 1.15;
}

.brand p {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.control-group {
  border-top: 1px solid var(--line);
  padding: 18px 0;
}

.control-group h2 {
  font-size: 13px;
  text-transform: uppercase;
  color: #c9d0d9;
  letter-spacing: 0;
  margin-bottom: 12px;
}

.section-toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  text-transform: uppercase;
  font-size: 13px;
}

.collapsible-group.collapsed > :not(.section-toggle),
.collapsible-group.collapsed .template-grid {
  display: none;
}

.collapsible-group.collapsed .section-toggle strong {
  transform: rotate(180deg);
}

.template-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.template-card {
  min-height: 84px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 7px;
  padding: 10px;
}

.template-icon {
  width: 34px;
  height: 46px;
  border-radius: 50% 50% 32% 32%;
  background: linear-gradient(180deg, #f7b4c2, #c86a83);
  clip-path: polygon(50% 0, 84% 18%, 78% 76%, 61% 100%, 39% 100%, 22% 76%, 16% 18%);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.tool {
  font-size: 22px;
  font-weight: 800;
}

label {
  color: var(--muted);
  display: block;
  font-size: 13px;
  margin: 14px 0;
}

input[type="range"] {
  display: block;
  width: 100%;
  margin-top: 8px;
  accent-color: var(--accent);
}

input[type="color"] {
  display: block;
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
  margin-top: 8px;
  padding: 4px;
}

.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.toggle-row input {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}

.measurements dl {
  margin: 0;
  display: grid;
  gap: 9px;
}

.measurements div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 10px;
  background: var(--panel-2);
  border-radius: 7px;
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
  font-weight: 750;
}

.workspace {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.05) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255,255,255,0.05) 1px, transparent 1px),
    radial-gradient(circle at 50% 35%, color-mix(in srgb, var(--scene-bg) 62%, white), var(--scene-bg) 68%);
  background-size: 42px 42px, 42px 42px, auto;
}

.workspace::before {
  content: "";
  position: absolute;
  inset: -10%;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 18% 24%, rgba(255,255,255,0.12), transparent 18%),
    radial-gradient(circle at 86% 66%, rgba(157,230,255,0.10), transparent 20%),
    radial-gradient(circle at 52% 88%, rgba(255,215,240,0.08), transparent 22%);
  filter: blur(var(--dof-blur));
  opacity: 0.7;
  transition: filter 160ms ease, opacity 160ms ease;
}

.topbar {
  position: absolute;
  z-index: 5;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.topbar button {
  pointer-events: auto;
}

.view-controls,
.file-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.topbar-slider {
  pointer-events: auto;
  display: grid;
  grid-template-columns: auto minmax(78px, 120px);
  align-items: center;
  gap: 8px;
  min-height: 38px;
  margin: 0;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(39, 45, 55, 0.92);
  color: var(--text);
}

.interaction-softness-control {
  display: none;
}

body.interaction-mode .interaction-softness-control {
  display: grid;
}

.topbar-slider span {
  font-size: 12px;
  color: var(--muted);
}

.topbar-slider input {
  margin: 0;
}

.language-toggle {
  min-width: 46px;
  font-weight: 800;
}

#scene {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: block;
}

.status-line {
  position: absolute;
  z-index: 5;
  left: 16px;
  bottom: 16px;
  max-width: calc(100% - 32px);
  border: 1px solid var(--line);
  background: rgba(18, 19, 22, 0.78);
  color: #dce3eb;
  padding: 8px 11px;
  border-radius: 7px;
  font-size: 13px;
  backdrop-filter: blur(10px);
}

.library-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(4, 6, 10, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.library-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.library-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 21;
  width: min(560px, 100vw);
  height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(360px, 1fr) auto auto;
  gap: 14px;
  padding: 18px;
  background: #181c23;
  border-left: 1px solid var(--line);
  box-shadow: -24px 0 60px rgba(0, 0, 0, 0.38);
  transform: translateX(102%);
  transition: transform 220ms ease;
}

.library-drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
}

.drawer-header h2 {
  margin: 0;
  font-size: 18px;
}

.drawer-header p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

#libraryCloseBtn {
  width: 38px;
  padding: 0;
  font-weight: 900;
}

.library-viewport {
  position: relative;
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.05) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255,255,255,0.05) 1px, transparent 1px),
    radial-gradient(circle at 50% 35%, #303947, #12161d 70%);
  background-size: 34px 34px, 34px 34px, auto;
}

#libraryScene {
  width: 100%;
  height: 100%;
  display: block;
}

.library-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  pointer-events: none;
}

.library-empty[hidden] {
  display: none;
}

.library-belt-controls {
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  gap: 10px;
  align-items: center;
}

.library-belt-controls button {
  padding: 0;
  font-size: 18px;
  font-weight: 900;
}

.library-load {
  width: 100%;
  min-height: 42px;
  background: var(--accent);
  color: #071411;
  font-weight: 800;
}

.palette-list {
  display: grid;
  gap: 8px;
}

.palette-option {
  display: grid;
  grid-template-columns: 58px 1fr;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  text-align: left;
}

.palette-option span {
  display: block;
  height: 26px;
  border-radius: 7px;
  background: linear-gradient(90deg, var(--p1), var(--p2), var(--p3), var(--p4), var(--p5));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.24);
}

.palette-option strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact button {
  width: 100%;
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }

  .panel {
    border: 0;
  }

  .workspace {
    height: 68vh;
    min-height: 520px;
    order: -1;
  }

  .topbar {
    flex-direction: column;
  }
}

@media (max-width: 1320px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .file-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 560px) {
  .workspace {
    min-height: 560px;
  }

  .file-actions,
  .view-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  button {
    padding: 0 8px;
    min-width: 0;
  }
}
