/* ─── Reset & Variables ──────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0b0b10;
  --sidebar-bg: #0f0f17;
  --surface: #16161f;
  --surface-2: #1c1c28;
  --border: rgba(255, 255, 255, 0.07);
  --accent: #6366f1;
  --accent-dim: rgba(99, 102, 241, 0.18);
  --accent-h: #818cf8;
  --text: #e2e2ee;
  --muted: #6b6b88;
  --sidebar-w: 272px;
}

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  overflow: hidden;
}

/* ─── Layout ─────────────────────────────────────────────────── */

#app {
  display: flex;
  height: 100vh;
}

/* ─── Sidebar ────────────────────────────────────────────────── */

#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text);
}

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-2) transparent;
}

.sidebar-body::-webkit-scrollbar {
  width: 4px;
}

.sidebar-body::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-body::-webkit-scrollbar-thumb {
  background: var(--surface-2);
  border-radius: 4px;
}

/* ─── Sections ───────────────────────────────────────────────── */

.section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

/* ─── Shape Grid ─────────────────────────────────────────────── */

.shape-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}

.shape-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 4px 6px;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.shape-btn .sicon {
  width: 22px;
  height: 22px;
}

.shape-btn:hover {
  border-color: rgba(99, 102, 241, 0.5);
  color: var(--text);
}

.shape-btn.active {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
}

/* ─── Material Grid ──────────────────────────────────────────── */

.mat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 5px;
}

.mat-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 6px;
  color: var(--muted);
  cursor: pointer;
  font-size: 11.5px;
  font-family: inherit;
  text-align: center;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.mat-btn:hover {
  border-color: rgba(99, 102, 241, 0.5);
  color: var(--text);
}

.mat-btn.active {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
}

/* ─── Color ──────────────────────────────────────────────────── */

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 10px;
}

.swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

.swatch:hover {
  transform: scale(1.18);
}

.swatch.active {
  border-color: #fff;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.3);
  transform: scale(1.18);
}

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

.label {
  color: var(--muted);
  font-size: 12px;
}

input[type="color"] {
  width: 38px;
  height: 26px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  padding: 2px 3px;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
  border-radius: 4px;
}

input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 4px;
}

/* ─── Sliders ────────────────────────────────────────────────── */

.slider-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.slider-item {
  display: grid;
  grid-template-columns: 70px 1fr 38px;
  align-items: center;
  gap: 8px;
}

.val {
  color: var(--accent);
  font-size: 11px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 3px;
  border-radius: 2px;
  background: var(--surface-2);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.25);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}

/* ─── Toggle ─────────────────────────────────────────────────── */

.toggle-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.tog {
  position: relative;
  display: inline-flex;
  cursor: pointer;
}

.tog input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.tog-track {
  width: 34px;
  height: 18px;
  border-radius: 9px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: background 0.2s, border-color 0.2s;
  position: relative;
}

.tog-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.2s, background 0.2s;
}

.tog input:checked~.tog-track {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.tog input:checked~.tog-track .tog-thumb {
  background: var(--accent);
  transform: translateX(16px);
}

/* ─── Reset Button ───────────────────────────────────────────── */

.reset-btn {
  width: 100%;
  padding: 9px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-family: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.reset-btn:hover {
  border-color: rgba(99, 102, 241, 0.5);
  color: var(--text);
  background: var(--surface-2);
}

/* ─── Viewport ───────────────────────────────────────────────── */

#viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #0d1117;
}

#canvas {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
}

#hint {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 18px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
}

/* ─── Assembly UI ────────────────────────────────────────────────────────────── */

.action-btn {
  width: 100%;
  padding: 9px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  display: block;
}

.action-btn:hover {
  border-color: var(--accent);
  background: var(--surface-2);
}

.action-btn.danger {
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.3);
}

.action-btn.danger:hover {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

.hint-text {
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 8px;
  line-height: 1.5;
}

.assembly-item {
  display: flex;
  flex-direction: column;
  padding: 7px 8px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  margin-bottom: 5px;
  font-size: 12px;
}

.assembly-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.assembly-item-name {
  color: var(--text);
  font-size: 11px;
}

.assembly-item-snap {
  color: var(--muted);
  font-size: 10px;
  margin-top: 2px;
}

.assembly-item-remove {
  background: none;
  border: none;
  color: #ef4444;
  cursor: pointer;
  font-size: 14px;
  padding: 0 4px;
  line-height: 1;
}

.assembly-item-remove:hover {
  color: #ff6b6b;
}

.assembly-item-rot {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
}

.zrot-label {
  color: var(--muted);
  font-size: 10px;
  margin-right: 2px;
  white-space: nowrap;
}

.zrot-btn {
  flex: 1;
  padding: 2px 0;
  font-size: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.zrot-btn:hover {
  background: var(--border);
  color: var(--text);
}

.zrot-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}