* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0b0d12;
  --panel: rgba(20, 24, 33, 0.78);
  --panel-border: rgba(120, 140, 180, 0.15);
  --text: #e6edf5;
  --muted: #8a95a8;
  --accent: #c84269;
  --accent-ho: #db5a80;
  --ok: #4ecdc4;
}

html,
body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
}

#canvas-container {
  position: fixed;
  inset: 0;
  z-index: 0;
}

#canvas-container canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.top-bar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  background: linear-gradient(180deg, rgba(11, 13, 18, 0.75), transparent);
  pointer-events: none;
}

.top-bar h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 1px;
  background: linear-gradient(135deg, #fff, #c84269);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.top-bar .hint {
  font-size: 12px;
  color: var(--muted);
  background: rgba(20, 24, 33, 0.55);
  padding: 6px 12px;
  border-radius: 999px;
  pointer-events: auto;
}

.side-panel {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 5;
  width: 280px;
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  padding: 18px;
  color: var(--text);
}

.side-panel::-webkit-scrollbar {
  width: 6px;
}
.side-panel::-webkit-scrollbar-thumb {
  background: rgba(200, 66, 105, 0.4);
  border-radius: 3px;
}

.panel-section {
  margin-bottom: 18px;
}

.panel-section h2 {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1.2px;
  margin-bottom: 10px;
}

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

.garment-card {
  aspect-ratio: 1 / 1;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all 0.2s ease;
  color: var(--muted);
  font-size: 11px;
  position: relative;
}

.garment-card:hover {
  background: rgba(200, 66, 105, 0.08);
  border-color: rgba(200, 66, 105, 0.4);
  transform: translateY(-1px);
}

.garment-card.active {
  background: rgba(200, 66, 105, 0.18);
  border-color: var(--accent);
  color: var(--accent-ho);
  box-shadow: 0 0 0 3px rgba(200, 66, 105, 0.18);
}

.garment-card .emoji {
  font-size: 26px;
  line-height: 1;
}

.garment-card .name {
  font-size: 11px;
  margin-top: 2px;
}

.color-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.color-row input[type="color"] {
  width: 38px;
  height: 38px;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
}

.color-row input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-row input[type="color"]::-webkit-color-swatch {
  border: 1px solid var(--panel-border);
  border-radius: 8px;
}

#fabric-color-label {
  font-family: "SF Mono", "JetBrains Mono", Menlo, monospace;
  font-size: 12px;
  color: var(--muted);
  flex: 1;
}

.toggle-row label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  padding: 4px 0;
}

.toggle-row input[type="checkbox"] {
  appearance: none;
  width: 32px;
  height: 18px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}

.toggle-row input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle-row input[type="checkbox"]:checked {
  background: var(--accent);
}

.toggle-row input[type="checkbox"]:checked::after {
  transform: translateX(14px);
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12px;
}

.slider-row label {
  flex: 0 0 60px;
  color: var(--muted);
}

.slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  height: 4px;
}

.slider-row .val {
  flex: 0 0 38px;
  text-align: right;
  font-family: "SF Mono", monospace;
  font-size: 11px;
  color: var(--muted);
}

.action-btn {
  width: 100%;
  padding: 10px;
  margin-bottom: 8px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.action-btn:hover {
  background: rgba(200, 66, 105, 0.15);
  border-color: rgba(200, 66, 105, 0.5);
}

.action-btn:active {
  transform: scale(0.98);
}

#loading {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  transition: opacity 0.4s ease;
}

#loading.hide {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(200, 66, 105, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

#loading p {
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 1px;
}

.threejs-credit {
  position: fixed;
  bottom: 12px;
  right: 14px;
  z-index: 5;
  font-size: 10px;
  color: var(--muted);
  text-decoration: none;
  opacity: 0.4;
}

.threejs-credit:hover {
  opacity: 0.8;
}

@media (max-width: 760px) {
  .side-panel {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-height: 50vh;
    border-radius: 16px 16px 0 0;
    border-bottom: none;
  }

  .top-bar h1 {
    font-size: 18px;
  }

  .top-bar .hint {
    display: none;
  }
}
