/* ───────────────────────────────────────────────────────────────
   Clay Studio 2.0 (owned by clay3d.js)
   ─────────────────────────────────────────────────────────────── */
#clay-sculpt-view {
  --clay-surface: rgba(255, 255, 255, 0.03);
  --clay-btn: rgba(255, 255, 255, 0.045);
  --clay-hover: rgba(255, 255, 255, 0.09);
  --clay-overlay: rgba(10, 14, 28, 0.62);
  --clay-view-h: 640px;
}
[data-theme="light"] #clay-sculpt-view {
  --clay-surface: rgba(15, 23, 42, 0.025);
  --clay-btn: #ffffff;
  --clay-hover: rgba(99, 102, 241, 0.08);
}

#clay-sculpt-view .clay-studio {
  padding: 16px;
  gap: 14px;
  align-items: stretch;
}

/* ── Buttons ─────────────────────────────────────────────────── */
.clay-studio button { font-family: var(--font-display); -webkit-tap-highlight-color: transparent; }
.clay-studio button:focus-visible { outline: 3px solid var(--secondary); outline-offset: 2px; }
.clay-emo { line-height: 1; }

.clay-chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 7px 12px;
  border-radius: 12px; border: 1px solid transparent;
  background: transparent; color: var(--text-main);
  font-weight: 600; font-size: 0.92rem; cursor: pointer; white-space: nowrap;
  transition: background 0.2s, transform 0.15s, color 0.2s;
}
.clay-chip .clay-emo { font-size: 1.1rem; }
.clay-chip:hover:not(:disabled) { background: var(--clay-hover); }
.clay-chip:active:not(:disabled) { transform: scale(0.96); }
.clay-chip.active { background: var(--primary); color: #fff; }
.clay-chip:disabled { opacity: 0.38; cursor: not-allowed; }
.clay-chip-danger { color: var(--danger); }
.clay-chip-danger:hover:not(:disabled) { background: rgba(239, 68, 68, 0.12); }

/* ── Top bar ─────────────────────────────────────────────────── */
.clay-topbar {
  display: flex; flex-wrap: wrap; gap: 10px;
  align-items: center; justify-content: space-between;
}
.clay-group {
  display: flex; align-items: center; gap: 4px;
  background: var(--clay-surface);
  border: 1px solid var(--border-color);
  border-radius: 16px; padding: 4px;
}
.clay-slider { padding: 4px 12px; gap: 10px; flex: 1 1 180px; min-height: 50px; min-width: 0; }
.clay-slider label {
  font-family: var(--font-display); font-weight: 700; font-size: 0.92rem;
  color: var(--text-muted); white-space: nowrap; cursor: help;
}
.clay-slider input[type="range"] {
  flex: 1 1 60px; width: 0; min-width: 60px; accent-color: var(--primary); cursor: pointer; height: 24px;
}
.clay-slider output {
  min-width: 3.2ch; text-align: right;
  font-family: var(--font-display); font-weight: 700; font-size: 0.9rem; color: var(--primary);
}

/* ── Main 3-column layout ────────────────────────────────────── */
.clay-main {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr) 250px;
  gap: 14px;
  align-items: start;
}
.clay-tools, .clay-side {
  background: var(--clay-surface);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 12px;
  display: flex; flex-direction: column; gap: 12px;
  max-height: var(--clay-view-h);
  overflow-y: auto;
  scrollbar-width: thin;
}
.clay-section { display: flex; flex-direction: column; gap: 8px; }
.clay-panel-title {
  font-family: var(--font-display); font-weight: 700;
  font-size: 0.88rem; color: var(--text-muted); letter-spacing: 0.01em;
}

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

.clay-tool {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 52px; padding: 6px 2px;
  border-radius: 14px; border: 1px solid var(--border-color);
  background: var(--clay-btn); color: var(--text-main);
  font-weight: 600; font-size: 0.8rem; line-height: 1.1; text-align: center;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
.clay-tool .clay-emo { font-size: 1.35rem; }
.clay-tool:hover { transform: translateY(-1px); border-color: var(--primary); }
.clay-tool:active { transform: scale(0.95); }
.clay-tool.active {
  background: var(--grad-main); color: #fff; border-color: transparent;
  box-shadow: 0 6px 16px var(--primary-glow);
}
.clay-tool-small { min-height: 48px; font-size: 0.7rem; }
.clay-tool-small .clay-emo { font-size: 1.15rem; }
.clay-shape-grid .clay-tool { min-height: 54px; font-size: 0.72rem; }
.clay-tool-star { border-style: dashed; border-color: var(--secondary); }

/* ── Viewport ────────────────────────────────────────────────── */
#clay-sculpt-view #clay-canvas-container {
  position: relative;
  width: 100% !important;
  max-width: none !important;
  height: var(--clay-view-h) !important;
  border-radius: 24px !important;
  border: 2px solid var(--border-color) !important;
  overflow: hidden;
  background: radial-gradient(circle at 50% 42%, #3d4a6b 0%, #0e1322 100%);
  touch-action: none !important;
  user-select: none; -webkit-user-select: none;
  transition: background 0.4s ease;
}
#clay-canvas-container canvas.clay-canvas {
  display: block; width: 100% !important; height: 100% !important;
  touch-action: none !important; outline: none;
}
#clay-instructions {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  max-width: calc(100% - 150px);
  background: var(--clay-overlay); color: #fff;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  padding: 8px 16px; border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  font-family: var(--font-display); font-weight: 600; font-size: 0.85rem; line-height: 1.25;
  text-align: center; pointer-events: none; z-index: 5;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}
#btn-clay-popout {
  position: absolute; top: 12px; right: 12px; z-index: 6;
  background: var(--clay-overlay); color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  padding: 8px 12px; border-radius: 12px;
  font-weight: 700; font-size: 0.85rem; cursor: pointer;
}
#btn-clay-popout.active { background: rgba(239, 68, 68, 0.8); }
.clay-viewbar {
  position: absolute; right: 12px; bottom: 12px; z-index: 6;
  display: flex; gap: 6px;
  background: var(--clay-overlay);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 5px; border-radius: 16px;
}
.clay-view-btn {
  width: 42px; height: 42px; border-radius: 12px;
  border: none; background: transparent; font-size: 1.2rem; cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}
.clay-view-btn:hover { background: rgba(255, 255, 255, 0.14); }
.clay-view-btn:active { transform: scale(0.92); }
.clay-view-btn.active { background: var(--primary); box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5) inset; }
.clay-stats {
  position: absolute; left: 12px; bottom: 14px; z-index: 5;
  font-family: var(--font-display); font-size: 0.75rem; font-weight: 600;
  color: rgba(255, 255, 255, 0.75);
  background: rgba(0, 0, 0, 0.28); padding: 4px 10px; border-radius: 999px;
  pointer-events: none;
}
.clay-stats:empty { display: none; }
#clay-canvas-container.clay-bg-light .clay-stats { color: rgba(15, 23, 42, 0.7); background: rgba(255, 255, 255, 0.55); }
.clay-loading {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #fff; font-family: var(--font-display); font-weight: 700; font-size: 1.1rem; pointer-events: none;
}

/* ── Parts list ──────────────────────────────────────────────── */
.clay-object-list {
  display: flex; flex-direction: column; gap: 4px;
  max-height: 176px; overflow-y: auto; scrollbar-width: thin;
}
.clay-obj-empty { font-size: 0.85rem; color: var(--text-faint); padding: 6px 4px; }
.clay-obj-row {
  display: flex; align-items: stretch; gap: 4px;
  border-radius: 12px; border: 1px solid var(--border-color); background: var(--clay-btn);
  transition: border-color 0.2s, background 0.2s;
}
.clay-obj-row.selected { border-color: var(--primary); background: var(--clay-hover); box-shadow: 0 0 0 1px var(--primary) inset; }
.clay-obj-row.hidden-part { opacity: 0.55; }
.clay-obj-main {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px;
  background: none; border: none; color: var(--text-main); cursor: pointer;
  padding: 7px 8px; font-size: 0.86rem; font-weight: 600; text-align: left;
}
.clay-obj-emoji { font-size: 1.05rem; }
.clay-obj-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clay-obj-verts { font-size: 0.7rem; color: var(--text-faint); font-weight: 600; }
.clay-obj-eye {
  width: 36px; background: none; border: none; border-left: 1px solid var(--border-color);
  cursor: pointer; font-size: 0.95rem; border-radius: 0 12px 12px 0;
}
.clay-obj-eye:hover { background: var(--clay-hover); }
.clay-obj-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.clay-mini {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 44px; padding: 4px 2px; border-radius: 10px;
  border: 1px solid var(--border-color); background: var(--clay-btn); color: var(--text-main);
  font-weight: 600; font-size: 0.7rem; cursor: pointer; white-space: nowrap;
  transition: border-color 0.2s, transform 0.15s;
}
.clay-mini .clay-emo { font-size: 1.05rem; }
.clay-mini:hover { border-color: var(--primary); }
.clay-mini:active { transform: scale(0.95); }
.clay-mini-danger { color: var(--danger); }
.clay-combine {
  width: 100%; min-height: 40px; padding: 8px 10px; border-radius: 12px; cursor: pointer;
  border: 1px dashed var(--primary); background: var(--primary-glow, rgba(139, 92, 246, 0.15));
  color: var(--text-main); font-weight: 700; font-size: 0.85rem;
  transition: transform 0.15s, background 0.2s;
}
.clay-combine:hover { background: var(--primary); color: #fff; }
.clay-combine:active { transform: scale(0.97); }
.clay-mini-danger:hover { border-color: var(--danger); }

/* ── Looks ───────────────────────────────────────────────────── */
.clay-look-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.clay-look {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 6px 2px; border-radius: 12px;
  border: 1px solid var(--border-color); background: var(--clay-btn); color: var(--text-main);
  font-size: 0.7rem; font-weight: 600; cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
}
.clay-look:hover { border-color: var(--primary); }
.clay-look.active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary) inset; }
.clay-look-ball { width: 24px; height: 24px; border-radius: 50%; display: block; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25); }
.look-clay { background: radial-gradient(circle at 35% 30%, #f7cfa6 0%, #d99a63 60%, #a86b3c 100%); }
.look-plastic { background: radial-gradient(circle at 32% 28%, #ffffff 0%, #ff7b7b 14%, #e0413f 60%, #8f1d1d 100%); }
.look-porcelain { background: radial-gradient(circle at 32% 28%, #ffffff 0%, #f4f6fb 25%, #cfd8e8 75%, #9aa7bf 100%); }
.look-metal { background: radial-gradient(circle at 32% 28%, #ffffff 0%, #b8c2d0 25%, #5f6b7d 60%, #d9e0ea 85%, #3c4452 100%); }
.look-gold { background: radial-gradient(circle at 32% 28%, #fff7d1 0%, #ffd35a 25%, #c48a12 65%, #fbe38a 85%, #7a5200 100%); }
.look-jelly { background: radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.95) 0%, rgba(120, 220, 255, 0.55) 25%, rgba(40, 150, 255, 0.45) 70%, rgba(20, 80, 200, 0.7) 100%); }
.look-toon { background: linear-gradient(135deg, #ffd166 0 45%, #f4a93b 45% 75%, #c9781a 75%); border: 2px solid #151528; }

/* ── Colors & backgrounds ────────────────────────────────────── */
.clay-swatches { display: flex; flex-wrap: wrap; gap: 5px; }
.clay-swatch {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid rgba(127, 127, 127, 0.35); cursor: pointer; padding: 0;
  transition: transform 0.15s, box-shadow 0.2s;
}
.clay-swatch:hover { transform: scale(1.12); }
.clay-swatch.active { box-shadow: 0 0 0 3px var(--bg-app, #0f111a), 0 0 0 5px var(--primary); transform: scale(1.08); }
.clay-swatch-custom {
  position: relative; overflow: hidden; display: inline-block;
  background: conic-gradient(#ff6b6b, #feca57, #1dd1a1, #48dbfb, #8e7dff, #ff9ff3, #ff6b6b);
}
.clay-swatch-custom.active { background: var(--clay-custom, #fff); }
.clay-swatch-custom input {
  position: absolute; inset: -6px; width: calc(100% + 12px); height: calc(100% + 12px);
  opacity: 0; cursor: pointer; border: none; padding: 0;
}
.clay-bgs { display: flex; flex-wrap: wrap; gap: 8px; }
.clay-bg {
  width: 30px; height: 30px; border-radius: 10px; cursor: pointer;
  border: 2px solid rgba(127, 127, 127, 0.35); padding: 0;
  transition: transform 0.15s, box-shadow 0.2s;
}
.clay-bg:hover { transform: scale(1.1); }
.clay-bg.active { box-shadow: 0 0 0 3px var(--primary); }
.clay-bg[data-bg="night"]  { background: radial-gradient(circle, #3d4a6b, #0e1322); }
.clay-bg[data-bg="studio"] { background: radial-gradient(circle, #ffffff, #c9d1de); }
.clay-bg[data-bg="sunset"] { background: linear-gradient(#ffd3a5, #fd6585); }
.clay-bg[data-bg="sky"]    { background: linear-gradient(#e0f2ff, #8ec5fc); }
.clay-bg[data-bg="mint"]   { background: linear-gradient(#f1ffe0, #96e6a1); }
.clay-bg[data-bg="galaxy"] { background: radial-gradient(circle, #5b2bb5, #0b0620); }

/* ── Bottom bar + submit ─────────────────────────────────────── */
.clay-bottombar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  background: var(--clay-surface); border: 1px solid var(--border-color);
  border-radius: 16px; padding: 6px 8px;
}
.clay-bottom-label { font-family: var(--font-display); font-weight: 700; font-size: 0.9rem; color: var(--text-muted); padding: 0 6px; }
.clay-bottombar .clay-chip-danger { margin-left: auto; }

#clay-sculpt-view .clay-submit-bar {
  display: flex; gap: 8px; flex-wrap: wrap; width: 100%;
  border-top: 1px dashed var(--border-color); padding-top: 14px; margin-top: 2px;
}
#clay-sculpt-view .clay-submit-bar button {
  flex: 1 1 160px; margin: 0; height: 46px; padding: 10px 16px;
  border-radius: 14px; font-size: 1rem; font-weight: 700; cursor: pointer;
}
#clay-sculpt-view .clay-submit-bar .btn-gate { width: auto; background: var(--grad-main); border: none; color: #fff; }

/* ── Pop-out (full screen) ───────────────────────────────────── */
body.clay-popout-open { overflow: hidden; }
#clay-sculpt-view .clay-studio.clay-popout {
  position: fixed; inset: 0; z-index: 1000;
  width: 100vw; height: 100vh; height: 100dvh;
  border-radius: 0; margin: 0;
  background: var(--bg-app, #0f111a);
  padding: 12px !important; gap: 10px !important;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto; align-content: stretch;
  animation: clay-pop 0.25s ease-out;
}
@keyframes clay-pop { from { transform: scale(0.97); opacity: 0; } to { transform: none; opacity: 1; } }
#clay-sculpt-view .clay-popout .clay-main { min-height: 0; height: 100%; align-items: stretch; }
#clay-sculpt-view .clay-popout .clay-tools, #clay-sculpt-view .clay-popout .clay-side { max-height: 100%; }
#clay-sculpt-view .clay-popout #clay-canvas-container { height: 100% !important; }
#clay-sculpt-view .clay-popout .clay-submit-bar { display: none !important; }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 1280px) {
  #clay-sculpt-view { --clay-view-h: 540px; }
  .clay-main { grid-template-columns: 172px minmax(0, 1fr); }
  .clay-side {
    grid-column: 1 / -1; max-height: none;
    display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px 18px;
  }
  #clay-sculpt-view .clay-popout .clay-main { grid-template-columns: 172px minmax(0, 1fr) 240px; }
  #clay-sculpt-view .clay-popout .clay-side { grid-column: auto; display: flex; overflow-y: auto; }
}

@media (max-width: 820px) {
  #clay-sculpt-view { --clay-view-h: min(62vh, 480px); }
  .clay-main { grid-template-columns: minmax(0, 1fr); }
  #clay-canvas-container { order: -1; }
  .clay-tools {
    max-height: none;
    display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px;
  }
  .clay-tool-grid { grid-template-columns: repeat(5, 1fr); }
  .clay-tool-grid-3 { grid-template-columns: repeat(3, 1fr); }
  .clay-section:nth-child(2) .clay-tool-grid { grid-template-columns: repeat(3, 1fr); }
  .clay-slider { flex-basis: 100%; }
  .clay-topbar .clay-group:not(.clay-slider) { flex: 1 1 auto; justify-content: center; }

  #clay-sculpt-view .clay-popout .clay-main { grid-template-columns: minmax(0, 1fr); overflow-y: auto; align-content: start; }
  #clay-sculpt-view .clay-popout #clay-canvas-container { height: 58vh !important; height: 58dvh !important; }
  #clay-sculpt-view .clay-popout .clay-side { display: grid; }
  #clay-sculpt-view .clay-popout .clay-topbar .clay-slider { flex-basis: 40%; }
}

@media (max-width: 520px) {
  #clay-sculpt-view .clay-studio { padding: 10px !important; }
  #clay-sculpt-view { --clay-view-h: min(58vh, 420px); }
  .clay-tool-grid { grid-template-columns: repeat(4, 1fr); }
  .clay-section:nth-child(2) .clay-tool-grid { grid-template-columns: repeat(3, 1fr); }
  .clay-tool { min-height: 54px; font-size: 0.72rem; }
  .clay-chip { padding: 6px 9px; font-size: 0.82rem; }
  .clay-topbar .clay-chip span:not(.clay-emo) { font-size: 0.78rem; }
  #clay-instructions { top: 10px; left: 10px; transform: none; text-align: left; font-size: 0.72rem; max-width: calc(100% - 128px); padding: 6px 12px; border-radius: 14px; }
  .clay-stats { display: none; }
  .clay-view-btn { width: 38px; height: 38px; font-size: 1.05rem; }
  .clay-bottombar .clay-chip-danger { margin-left: 0; }
  .clay-look-grid { grid-template-columns: repeat(4, 1fr); }
}
