/* Model Studio layout */
html, body { height: 100%; }
.ms { height: 100vh; display: flex; flex-direction: column; }
.ms-top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #141922, #0e1116);
}
.ms-title { font-weight: 700; font-size: 16px; color: var(--text); }
.ms-sub { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 6px; }
.ms-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ms-field { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.ms-field select {
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 8px; font-size: 13px;
}
.mini-btn.active { border-color: var(--accent); color: var(--accent); }

.ms-body { flex: 1; min-height: 0; display: flex; }
.ms-outliner, .ms-props {
  width: 240px; flex: none; border-right: 1px solid var(--line);
  padding: 12px; overflow-y: auto; background: var(--panel);
}
.ms-props { border-right: none; border-left: 1px solid var(--line); }
.ms-outliner h3, .ms-props h3 {
  margin: 0 0 10px; font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.6px; color: var(--muted);
}
.ms-viewport { flex: 1; min-width: 0; position: relative; background: #0b0e13; }
#msCanvas { display: block; width: 100%; height: 100%; }
.ms-hint {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  color: var(--muted); font-size: 12px; background: rgba(14,17,22,0.7);
  padding: 4px 10px; border-radius: 20px; pointer-events: none;
}

/* outliner tree */
.ms-tree { font-size: 13px; }
.tree-bone { margin-bottom: 6px; }
.tree-bone > .tree-row { color: var(--text); font-weight: 600; }
.tree-cube { margin-left: 16px; }
.tree-row {
  display: flex; align-items: center; gap: 6px; padding: 3px 6px;
  border-radius: 5px; cursor: pointer; color: var(--muted);
}
.tree-row:hover { background: var(--panel-2); }
.tree-row.sel { background: rgba(78,161,255,0.18); color: var(--text); }
.tree-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-del {
  flex: none; opacity: 0; color: var(--muted); font-size: 12px;
  width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 4px;
}
.tree-row:hover .tree-del { opacity: 0.75; }
.tree-del:hover { opacity: 1 !important; color: #fff; background: var(--red); }

/* delete button emphasis */
.mini-btn.danger { border-color: rgba(248,81,73,0.5); color: #f2a6a1; }
.mini-btn.danger:hover { border-color: var(--red); color: #fff; background: rgba(248,81,73,0.15); }

/* properties */
.ms-propbody { display: flex; flex-direction: column; gap: 12px; }
.ms-empty { color: var(--muted); font-size: 13px; }
.prop-group { border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.prop-group h4 { margin: 0 0 8px; font-size: 12px; color: var(--muted); }
.prop-name {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 8px; font-size: 13px; margin-bottom: 8px;
}
.vec { display: grid; grid-template-columns: 14px 1fr; gap: 4px 6px; align-items: center; }
.vec label { font-size: 11px; color: var(--muted); }
.vec input {
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 5px; padding: 5px 6px; font-size: 12px; width: 100%;
  font-family: ui-monospace, monospace;
}
.vec input:focus { outline: none; border-color: var(--accent); }
.vec-row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.vec-lab { font-size: 11px; color: var(--muted); margin-bottom: 3px; }

/* model name + save/paint */
.ms-name-field .ms-name {
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 8px; font-size: 13px; width: 120px;
}
.ms-name-field .ms-name:focus { outline: none; border-color: var(--accent); }
.savepaint-btn { font-weight: 700; box-shadow: 0 0 0 1px rgba(78,161,255,0.4); }

/* paint bar */
.ms-paintbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 9px 16px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #16202b, #10161d);
}
.ms-paintbar[hidden] { display: none; }
.paint-step { color: var(--text); font-size: 13px; }
.paint-step strong { color: var(--accent); }
#paintColor { width: 40px; height: 30px; padding: 0; border: 1px solid var(--line);
  border-radius: 6px; background: var(--bg); cursor: pointer; }
.paint-palette { display: flex; gap: 5px; flex-wrap: wrap; }
.paint-swatch {
  width: 22px; height: 22px; border-radius: 5px; border: 1px solid rgba(255,255,255,0.25);
  cursor: pointer; padding: 0;
}
.paint-swatch:hover { transform: scale(1.12); border-color: #fff; }

/* per-cube color row in properties */
.prop-color { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.prop-color input[type="color"] { width: 40px; height: 28px; padding: 0;
  border: 1px solid var(--line); border-radius: 6px; background: var(--bg); cursor: pointer; }

/* while painting: crosshair cursor over the model */
body.paint-mode .ms-viewport { cursor: crosshair; }

/* 2D texture paint panel */
.tex-panel {
  position: absolute; left: 12px; bottom: 12px; z-index: 15;
  background: rgba(14,17,22,0.94); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 8px 10px;
}
.tex-panel[hidden] { display: none; }
.tex-panel-head { font-size: 11px; color: var(--muted); margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.tex-panel-head strong { color: var(--accent); }
.tex-dims { color: var(--muted); opacity: 0.7; }
.tex-gridtog { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.tex-wrap { position: relative; display: inline-block; line-height: 0; }
.tex-paint {
  display: block; width: 300px; height: auto; max-height: 340px;
  image-rendering: pixelated; cursor: crosshair; touch-action: none;
  background: #0b0e13; border: 1px solid var(--line); border-radius: 4px;
}
/* pixel grid overlay — one cell per texel, sized in JS via background-size */
.tex-grid {
  position: absolute; inset: 0; pointer-events: none; border-radius: 4px;
  background-image:
    linear-gradient(to right, rgba(255,255,255,0.22) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255,255,255,0.22) 1px, transparent 1px);
}
.tex-grid.off { display: none; }
@media (max-width: 620px) { .tex-paint { width: 200px; } .tex-panel { left: 8px; bottom: 8px; } }

/* ---- mobile ---- */
@media (max-width: 820px) {
  .ms-top { flex-direction: column; align-items: stretch; gap: 8px; }
  .ms-tools { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .ms-outliner, .ms-props { width: 168px; }
}
@media (max-width: 620px) {
  .ms-body { position: relative; }
  /* outliner + props become slide-in drawers, off by default */
  .ms-outliner, .ms-props {
    position: absolute; top: 0; bottom: 0; z-index: 20; width: 76%; max-width: 300px;
    transition: transform 0.2s ease; box-shadow: 0 0 24px rgba(0,0,0,0.5);
  }
  .ms-outliner { left: 0; transform: translateX(-102%); }
  .ms-props { right: 0; left: auto; transform: translateX(102%); }
  body.show-outliner .ms-outliner { transform: translateX(0); }
  body.show-props .ms-props { transform: translateX(0); }
  .ms-drawer-toggle { display: inline-flex !important; }
}
.ms-drawer-toggle {
  display: none; position: absolute; top: 10px; z-index: 25;
  width: 40px; height: 40px; border-radius: 9px; font-size: 18px;
  background: rgba(20,26,34,0.9); color: var(--text); border: 1px solid var(--line); cursor: pointer;
}
.ms-dt-left { left: 10px; }
.ms-dt-right { right: 10px; }
