/* ==========================================================================
   YB STUDIO 3D PAINTER — Substance-style PBR texture painter (/#starter-template)
   ========================================================================== */
.yb3d {
  --bg0: #141416;
  --bg1: #1c1c1f;
  --bg2: #232327;
  --bg3: #2c2c31;
  --line: #34343a;
  --line2: #44444c;
  --txt: #e9e9ee;
  --mut: #9a9aa6;
  --dim: #6d6d78;
  --acc: #7c5cff;
  --acc2: #a78bfa;
  --ok: #22c55e;
  --warn: #f59e0b;
  position: fixed;
  inset: 0;
  z-index: 9800;
  display: none;
  flex-direction: column;
  background: var(--bg0);
  color: var(--txt);
  font: 13px/1.4 'Plus Jakarta Sans', Inter, system-ui, sans-serif;
  user-select: none;
  overflow: hidden;
}
.yb3d.open { display: flex; }
.yb3d * { box-sizing: border-box; }
.yb3d button { font: inherit; color: inherit; cursor: pointer; }
.yb3d input, .yb3d select { font: inherit; color: var(--txt); }

/* auth / checkout modals must appear above the full-screen studio */
.modal-backdrop.open { z-index: 10050 !important; }

/* ---------- Top bar ---------- */
.yb3d-top {
  height: 52px;
  flex: 0 0 52px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  background: var(--bg1);
  border-bottom: 1px solid var(--line);
}
.yb3d-top-left, .yb3d-top-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.yb3d-top-right { justify-content: flex-end; }
.yb3d-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.yb3d-brand img { width: 28px; height: 28px; border-radius: 7px; object-fit: cover; }
.yb3d-brand b { display: block; font-size: 13px; font-weight: 800; letter-spacing: .2px; white-space: nowrap; }
.yb3d-brand span { display: block; font-size: 11px; color: var(--mut); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.yb3d-btn {
  height: 32px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--line2);
  background: var(--bg3);
  font-weight: 700;
  font-size: 12.5px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  transition: background .15s, border-color .15s, transform .1s;
}
.yb3d-btn:hover { background: #36363c; }
.yb3d-btn:active { transform: translateY(1px); }
.yb3d-btn.ghost { background: transparent; }
.yb3d-btn.ghost:hover { background: var(--bg3); }
.yb3d-btn.on { border-color: var(--acc); color: #fff; background: rgba(124, 92, 255, .18); }
.yb3d-btn.primary { background: linear-gradient(135deg, #7c5cff, #5b3df5); border-color: transparent; color: #fff; box-shadow: 0 6px 18px rgba(124, 92, 255, .35); }
.yb3d-btn.primary:hover { filter: brightness(1.08); }
.yb3d-btn.block { width: 100%; justify-content: center; height: 40px; font-size: 13.5px; }
.yb3d-btn.sm { height: 28px; padding: 0 10px; font-size: 12px; }
.yb3d-btn.danger { color: #fca5a5; border-color: rgba(239, 68, 68, .4); background: rgba(239, 68, 68, .08); }

.yb3d-channels {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--bg0);
  border: 1px solid var(--line);
  border-radius: 9px;
}
.yb3d-channels button {
  border: 0;
  background: transparent;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--mut);
  white-space: nowrap;
}
.yb3d-channels button:hover { color: var(--txt); }
.yb3d-channels button.active { background: var(--bg3); color: #fff; box-shadow: inset 0 0 0 1px var(--line2); }

/* ---------- Body layout ---------- */
.yb3d-body { flex: 1 1 auto; display: flex; min-height: 0; }

.yb3d-tools {
  width: 52px;
  flex: 0 0 52px;
  background: var(--bg1);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 0;
  overflow-y: auto;
}
.yb3d-tools .sep { width: 28px; height: 1px; background: var(--line); margin: 6px 0; }
.yb3d-tool {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  display: grid;
  place-items: center;
  font-size: 16px;
  position: relative;
  color: var(--mut);
}
.yb3d-tool small { position: absolute; bottom: 2px; font-size: 8.5px; font-weight: 800; letter-spacing: .3px; }
.yb3d-tool:hover { background: var(--bg3); color: var(--txt); }
.yb3d-tool.active { background: rgba(124, 92, 255, .2); border-color: var(--acc); color: #fff; }

/* ---------- Stage ---------- */
.yb3d-stage { flex: 1 1 auto; display: flex; min-width: 0; position: relative; }
.yb3d-viewport {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  background: radial-gradient(ellipse at 50% 40%, #3a3a40 0%, #26262a 55%, #18181b 100%);
}
.yb3d-viewport.light { background: radial-gradient(ellipse at 50% 40%, #ffffff 0%, #e6e7ec 60%, #cfd1d8 100%); }
.yb3d-viewport canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; touch-action: none; }
.yb3d-viewport.move-tool canvas { cursor: crosshair; }

.yb3d-vp-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  gap: 6px;
  pointer-events: none;
}
.yb3d-vp-badge span {
  background: rgba(10, 10, 12, .6);
  border: 1px solid rgba(255, 255, 255, .08);
  backdrop-filter: blur(6px);
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  color: #d4d4dc;
}
.yb3d-vp-views {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(12, 12, 14, .7);
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 10px;
  backdrop-filter: blur(8px);
}
.yb3d-vp-views button {
  border: 0;
  background: transparent;
  padding: 6px 11px;
  border-radius: 7px;
  font-size: 11.5px;
  font-weight: 700;
  color: #c8c8d0;
}
.yb3d-vp-views button:hover { background: rgba(255, 255, 255, .08); color: #fff; }

.yb3d-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(20, 20, 22, .85);
  z-index: 5;
  font-weight: 700;
  color: var(--mut);
}
.yb3d-loading.hide { display: none; }
.yb3d-spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line2); border-top-color: var(--acc); animation: yb3dspin .8s linear infinite; margin: 0 auto 12px; }
@keyframes yb3dspin { to { transform: rotate(360deg); } }

.yb3d-uvpane {
  display: none;
  flex: 0 0 42%;
  max-width: 620px;
  min-width: 280px;
  border-left: 1px solid var(--line);
  background: #111113;
  flex-direction: column;
}
.yb3d-uvpane.show { display: flex; }
.yb3d-pane-title {
  height: 34px;
  flex: 0 0 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .6px;
  color: var(--mut);
  text-transform: uppercase;
  border-bottom: 1px solid var(--line);
}
.yb3d-uvwrap { flex: 1 1 auto; display: grid; place-items: center; padding: 14px; min-height: 0; }
.yb3d-uvwrap canvas {
  width: 100%;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  border-radius: 6px;
  background:
    repeating-conic-gradient(#202024 0% 25%, #1a1a1d 0% 50%) 50% / 20px 20px;
  box-shadow: 0 0 0 1px var(--line);
}

/* ---------- Right panel ---------- */
.yb3d-panel {
  width: 340px;
  flex: 0 0 340px;
  background: var(--bg1);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.yb3d-panel-scroll { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; }
.yb3d-panel-scroll::-webkit-scrollbar { width: 8px; }
.yb3d-panel-scroll::-webkit-scrollbar-thumb { background: #3a3a42; border-radius: 8px; }
.yb3d-panel-foot { flex: 0 0 auto; padding: 12px; border-top: 1px solid var(--line); background: var(--bg1); display: grid; gap: 8px; }
.yb3d-panel-foot .note { font-size: 11px; color: var(--mut); text-align: center; }

.yb3d-sec { border-bottom: 1px solid var(--line); }
.yb3d-sec-head {
  width: 100%;
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .7px;
  text-transform: uppercase;
  color: #cfcfd8;
  text-align: left;
}
.yb3d-sec-head:hover { background: var(--bg2); }
.yb3d-sec-head .chev { transition: transform .15s; color: var(--dim); }
.yb3d-sec.closed .chev { transform: rotate(-90deg); }
.yb3d-sec.closed .yb3d-sec-body { display: none; }
.yb3d-sec-body { padding: 2px 14px 14px; display: grid; gap: 10px; }
.yb3d-sec-head .tag { font-size: 10px; letter-spacing: .3px; color: var(--acc2); background: rgba(124, 92, 255, .14); padding: 2px 7px; border-radius: 999px; text-transform: none; }

.yb3d-row { display: grid; grid-template-columns: 92px 1fr 54px; align-items: center; gap: 10px; }
.yb3d-row > label { font-size: 12px; color: var(--mut); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.yb3d-row input[type=number] {
  width: 54px;
  height: 26px;
  padding: 0 6px;
  background: var(--bg0);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
  text-align: right;
}
.yb3d-row2 { display: grid; grid-template-columns: 92px 1fr; align-items: center; gap: 10px; }
.yb3d-row2 > label { font-size: 12px; color: var(--mut); }

.yb3d input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 4px;
  background: #3a3a42;
  outline: none;
}
.yb3d input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--acc);
  cursor: pointer;
}
.yb3d input[type=range]::-moz-range-thumb { width: 10px; height: 10px; border-radius: 50%; background: #fff; border: 3px solid var(--acc); cursor: pointer; }

.yb3d-seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; padding: 3px; background: var(--bg0); border: 1px solid var(--line); border-radius: 8px; }
.yb3d-seg button { border: 0; background: transparent; padding: 6px 4px; border-radius: 6px; font-size: 11.5px; font-weight: 700; color: var(--mut); white-space: nowrap; }
.yb3d-seg button.active { background: var(--bg3); color: #fff; box-shadow: inset 0 0 0 1px var(--line2); }

.yb3d-select, .yb3d-text {
  width: 100%;
  height: 30px;
  padding: 0 9px;
  background: var(--bg0);
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 12.5px;
  outline: none;
}
.yb3d-select:focus, .yb3d-text:focus { border-color: var(--acc); }
.yb3d-check { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--mut); cursor: pointer; }
.yb3d-check input { accent-color: var(--acc); }

/* layers */
.yb3d-layer-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.yb3d-layers { display: grid; gap: 4px; }
.yb3d-layer {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  align-items: center;
  gap: 9px;
  padding: 5px 6px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--bg2);
  cursor: pointer;
}
.yb3d-layer:hover { border-color: var(--line2); }
.yb3d-layer.sel { border-color: var(--acc); background: rgba(124, 92, 255, .12); }
.yb3d-layer.hidden-layer { opacity: .45; }
.yb3d-layer .thumb {
  width: 38px;
  height: 38px;
  border-radius: 6px;
  object-fit: contain;
  background: repeating-conic-gradient(#2e2e34 0% 25%, #26262b 0% 50%) 50% / 10px 10px;
  border: 1px solid var(--line);
}
.yb3d-layer .meta { min-width: 0; }
.yb3d-layer .meta b { display: block; font-size: 12.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.yb3d-layer .meta span { font-size: 10.5px; color: var(--mut); }
.yb3d-layer .ops { display: flex; gap: 2px; }
.yb3d-layer .ops button { width: 24px; height: 24px; border: 0; border-radius: 6px; background: transparent; color: var(--mut); font-size: 12px; display: grid; place-items: center; }
.yb3d-layer .ops button:hover { background: var(--bg3); color: #fff; }
.yb3d-empty { padding: 14px; border: 1px dashed var(--line2); border-radius: 9px; color: var(--mut); font-size: 12px; text-align: center; line-height: 1.5; }

/* colors */
.yb3d-color-row { display: grid; grid-template-columns: 30px 1fr 82px; align-items: center; gap: 10px; }
.yb3d-swatch { position: relative; width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line2); overflow: hidden; }
.yb3d-swatch input { position: absolute; inset: -6px; width: 44px; height: 44px; border: 0; padding: 0; cursor: pointer; background: transparent; }
.yb3d-color-row label { font-size: 12.5px; color: #d6d6de; }
.yb3d-color-row input.hex { width: 82px; height: 28px; padding: 0 8px; background: var(--bg0); border: 1px solid var(--line); border-radius: 6px; font: 600 12px ui-monospace, Menlo, monospace; text-transform: uppercase; }
.yb3d-presets { display: flex; flex-wrap: wrap; gap: 6px; }
.yb3d-presets button { width: 22px; height: 22px; border-radius: 6px; border: 1px solid rgba(255, 255, 255, .15); }
.yb3d-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.yb3d-chips button { border: 1px solid var(--line2); background: var(--bg2); padding: 5px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; color: var(--mut); }
.yb3d-chips button.active { border-color: var(--acc); color: #fff; background: rgba(124, 92, 255, .16); }

/* ---------- Status bar ---------- */
.yb3d-status {
  height: 26px;
  flex: 0 0 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 12px;
  background: var(--bg1);
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
}
.yb3d-status b { color: var(--mut); font-weight: 700; }

/* ---------- Generate modal ---------- */
.yb3d-modal {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(6, 6, 8, .72);
  backdrop-filter: blur(6px);
}
.yb3d-modal.open { display: flex; }
.yb3d-modal-box {
  width: min(860px, 100%);
  max-height: 100%;
  overflow-y: auto;
  background: var(--bg1);
  border: 1px solid var(--line2);
  border-radius: 14px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6);
}
.yb3d-modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.yb3d-modal-head h3 { margin: 0; font-size: 16px; font-weight: 800; }
.yb3d-modal-head p { margin: 2px 0 0; font-size: 12px; color: var(--mut); }
.yb3d-modal-body { padding: 18px 20px; display: grid; gap: 16px; }
.yb3d-maps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.yb3d-map { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.yb3d-map img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; display: block; background: #0d0d0f; }
.yb3d-map b { display: block; margin-top: 7px; font-size: 12px; }
.yb3d-map span { display: block; font-size: 10.5px; color: var(--mut); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.yb3d-zip { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.yb3d-tree, .yb3d-howto { background: var(--bg0); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; font-size: 12px; }
.yb3d-tree { font-family: ui-monospace, Menlo, monospace; line-height: 1.7; color: #cfcfd8; }
.yb3d-tree .z { color: var(--acc2); font-weight: 700; }
.yb3d-howto ol { margin: 6px 0 0; padding-left: 18px; color: #cfcfd8; line-height: 1.6; }
.yb3d-howto b { font-size: 12px; }
.yb3d-modal-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-top: 1px solid var(--line); }
.yb3d-progress { flex: 1; height: 6px; border-radius: 6px; background: var(--bg3); overflow: hidden; display: none; }
.yb3d-progress.show { display: block; }
.yb3d-progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #7c5cff, #22d3ee); transition: width .2s; }
.yb3d-modal-msg { font-size: 12px; color: var(--mut); }
.yb3d-lock { color: #fbbf24; font-weight: 700; }

.yb3d-toast {
  position: absolute;
  top: 64px;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  background: #26262b;
  border: 1px solid var(--line2);
  padding: 9px 16px;
  border-radius: 9px;
  font-size: 12.5px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 60;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
}
.yb3d-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .yb3d-channels button { padding: 6px 8px; }
  .yb3d-brand span { display: none; }
}
@media (max-width: 860px) {
  .yb3d-top { grid-template-columns: auto 1fr auto; }
  .yb3d-channels { overflow-x: auto; }
  .yb3d-brand div { display: none; }
  .yb3d-body { flex-direction: column; }
  .yb3d-tools { width: 100%; flex: 0 0 auto; flex-direction: row; height: 48px; padding: 0 8px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .yb3d-tools .sep { width: 1px; height: 24px; margin: 0 4px; }
  .yb3d-stage { flex: 1 1 50%; min-height: 0; }
  .yb3d-uvpane { display: none !important; }
  .yb3d-panel { width: 100%; flex: 1 1 50%; border-left: 0; border-top: 1px solid var(--line); }
  .yb3d-maps { grid-template-columns: repeat(2, 1fr); }
  .yb3d-zip { grid-template-columns: 1fr; }
  .yb3d-status { display: none; }
}
