:root {
  --ink: #e8ecf4;
  --ink-dim: #9aa7bd;
  --panel: rgba(13, 19, 32, 0.82);
  --line: rgba(140, 165, 200, 0.22);
  --accent: #6db3ff;
  --accent-warm: #ffb25e;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: #111826;
  color: var(--ink);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

#scene { position: fixed; inset: 0; touch-action: none; }
#scene canvas { display: block; }

.panel {
  position: fixed;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

/* Title block, top left */
#title {
  top: 18px; left: 18px;
  padding: 14px 18px;
  max-width: 340px;
}
#title h1 { font-size: 17px; font-weight: 650; letter-spacing: 0.2px; }
#title p { margin-top: 4px; font-size: 12.5px; color: var(--ink-dim); }

/* The two buttons, bottom center */
#controls {
  bottom: 20px; left: 50%;
  transform: translateX(-50%);
  display: flex; gap: 10px;
  padding: 10px;
  border-radius: 18px;
}
#controls button {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(38, 54, 82, 0.65);
  color: var(--ink);
  font: 600 14px/1 system-ui, sans-serif;
  padding: 13px 20px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
#controls button:hover { background: rgba(62, 88, 132, 0.8); }
#controls button:active { transform: scale(0.97); }
#controls button.primary {
  background: var(--accent);
  border-color: transparent;
  color: #08101f;
}
#controls button.primary:hover { background: #8cc4ff; }

/* Color selector button + pop-out grid (avatar-shirt style) */
#color-btn { display: inline-flex; align-items: center; gap: 9px; }
#color-chip {
  width: 16px; height: 16px;
  border-radius: 5px;
  background: linear-gradient(135deg, #3a6ea8 50%, #d7a13b 50%);
  border: 1px solid rgba(255,255,255,0.35);
  flex: none;
}
#color-pop {
  bottom: 88px; left: 50%;
  transform: translateX(-50%) translateY(6px);
  padding: 14px 14px 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 20;
}
#color-pop.open { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
#color-grid {
  display: grid;
  grid-template-columns: repeat(4, 44px);
  gap: 9px;
}
.swatch {
  width: 44px; height: 44px;
  border-radius: 11px;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  background: none;
  position: relative;
  transition: transform 0.1s;
}
.swatch:hover { transform: scale(1.1); }
.swatch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatch .a, .swatch .b {
  position: absolute; inset: 0; border-radius: 9px; overflow: hidden;
}
.swatch .b { clip-path: polygon(0 100%, 100% 0, 100% 100%); }
.swatch.active { border-color: var(--accent-warm); }
#color-name {
  margin-top: 10px;
  text-align: center;
  font-size: 12.5px;
  color: var(--ink);
  letter-spacing: 0.2px;
}

/* Hint, bottom right */
#hint {
  bottom: 26px; right: 18px;
  padding: 9px 14px;
  font-size: 12px; color: var(--ink-dim);
}

/* The part card, bottom left */
#part-label {
  left: 18px; bottom: 20px;
  max-width: 350px;
  padding: 14px 16px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.22s, transform 0.22s;
  pointer-events: none;
}
#part-label.visible { opacity: 1; transform: none; pointer-events: auto; }
#part-label strong { display: block; font-size: 15px; color: var(--accent-warm); margin-bottom: 5px; }
#part-label span { font-size: 13px; color: var(--ink); }

/* Loading veil */
#loading {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: #111826;
  z-index: 30;
  color: var(--ink-dim);
  font-size: 14px;
  flex-direction: column; gap: 14px;
  transition: opacity 0.5s;
}
#loading.hidden { opacity: 0; pointer-events: none; }
#loading .ring {
  width: 34px; height: 34px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 720px) {
  #title { max-width: 250px; padding: 10px 14px; }
  #title h1 { font-size: 15px; }
  #title p { font-size: 11.5px; }
  #hint { display: none; }
  #part-label { max-width: 270px; bottom: 92px; }
  #controls { bottom: 14px; }
  #controls button { padding: 12px 15px; font-size: 13px; }
  #color-grid { grid-template-columns: repeat(4, 40px); gap: 8px; }
  .swatch { width: 40px; height: 40px; }
  #color-pop { bottom: 78px; }
}
