
:root{
  --bg: #0b1020;
  --panel: #0f172a;
  --panel2: #0b1226;
  --text: #e5e7eb;
  --muted:#9ca3af;
  --border: rgba(255,255,255,.08);
  --accent:#60a5fa;
  --accent2:#34d399;
  --danger:#fb7185;
  --shadow: 0 12px 32px rgba(0,0,0,.35);
  --radius: 16px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
}

*{ box-sizing:border-box; }
html, body { height: 100%; }
body{
  margin:0;
  font-family: var(--sans);
  color: var(--text);
  background: radial-gradient(1200px 700px at 20% 0%, rgba(96,165,250,.12), transparent 50%),
              radial-gradient(1100px 700px at 80% 30%, rgba(52,211,153,.10), transparent 55%),
              var(--bg);
}

.topbar{
  position: sticky;
  top: 0;
  z-index: 10;
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(11,16,32,.75);
  backdrop-filter: blur(10px);
}

.brand{
  display:flex;
  align-items:center;
  gap: 12px;
  min-width: 220px;
}
.logo{
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background:
    linear-gradient(135deg, rgba(96,165,250,.9), rgba(52,211,153,.85));
  box-shadow: 0 10px 24px rgba(0,0,0,.25);
}
.brand-title{ font-weight: 700; letter-spacing:.2px; }
.brand-subtitle{ font-size: 12px; color: var(--muted); margin-top:2px; }

.top-actions{
  display:flex;
  align-items:center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn{
  appearance:none;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.06);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 12px;
  cursor:pointer;
  font-weight: 600;
  transition: transform .06s ease, background .12s ease, border-color .12s ease;
  user-select:none;
}
.btn:hover{ background: rgba(255,255,255,.10); border-color: rgba(255,255,255,.14); }
.btn:active{ transform: translateY(1px); }
.btn.secondary{ background: rgba(96,165,250,.10); border-color: rgba(96,165,250,.18); }
.btn.danger{ background: rgba(251,113,133,.12); border-color: rgba(251,113,133,.24); }
.sep{ width:1px; height: 28px; background: var(--border); margin: 0 4px; }

.file-btn{ position:relative; overflow:hidden; }
.file-btn input[type="file"]{
  position:absolute;
  inset:0;
  opacity:0;
  cursor:pointer;
}

.layout{
  display:grid;
  grid-template-columns: 280px 1fr 360px;
  gap: 14px;
  padding: 14px;
  height: calc(100vh - 70px);
}

.panel{
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.03));
  box-shadow: var(--shadow);
  overflow:hidden;
  display:flex;
  flex-direction: column;
  min-height: 0;
}

.panel-title{
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 800;
  letter-spacing: .2px;
  background: rgba(15,23,42,.35);
}

.panel.left{ padding-bottom: 10px; }
.panel.left .section{ padding: 12px 14px; border-bottom: 1px solid var(--border); }
.panel.left .section:last-child{ border-bottom: none; }

.section-title{
  font-size: 12px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

.toolgrid{
  padding: 12px 14px;
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}

.tool{
  border: 1px solid var(--border);
  background: rgba(255,255,255,.06);
  color: var(--text);
  padding: 10px 10px;
  border-radius: 14px;
  cursor:pointer;
  font-weight: 700;
  transition: background .12s ease, border-color .12s ease, transform .06s ease;
}
.tool:hover{ background: rgba(255,255,255,.10); border-color: rgba(255,255,255,.14); }
.tool:active{ transform: translateY(1px); }
.tool.active{
  background: rgba(96,165,250,.18);
  border-color: rgba(96,165,250,.28);
}

.color-row{
  display:flex;
  align-items:center;
  gap: 10px;
}
#colorPicker{
  width: 56px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: transparent;
  padding:0;
}
.swatch{
  flex: 1;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #3b82f6;
}

.palette{
  margin-top: 10px;
  display:grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 8px;
}
.pal{
  height: 22px;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor:pointer;
}
.pal:hover{ outline: 2px solid rgba(255,255,255,.12); outline-offset: 2px; }

.row{
  display:flex;
  align-items:center;
  gap: 10px;
  margin-top: 10px;
}
.row:first-of-type{ margin-top: 0; }
.label{ color: var(--muted); font-weight: 700; font-size: 13px; width: 120px; }
.pill{
  min-width: 44px;
  text-align:center;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.06);
  font-family: var(--mono);
  font-size: 12px;
}
.hint{
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.keys{
  margin: 8px 0 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.8;
}
kbd{
  font-family: var(--mono);
  border: 1px solid var(--border);
  background: rgba(255,255,255,.06);
  padding: 2px 6px;
  border-radius: 8px;
  color: var(--text);
  font-weight: 700;
}

.panel.center{ min-width: 0; }
.viewer-wrap{
  padding: 14px;
  display:flex;
  height: 100%;
  min-height: 0;
  flex-direction: column;
}
.viewer{
  touch-action: none;

  position: relative;
  flex: 1;
  min-height: 320px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: radial-gradient(900px 500px at 50% 20%, rgba(96,165,250,.10), transparent 55%),
              radial-gradient(900px 500px at 60% 70%, rgba(52,211,153,.08), transparent 60%),
              rgba(11,18,38,.6);
  overflow: hidden;
}

.viewer-hud{
  position:absolute;
  left: 12px;
  bottom: 12px;
  display:flex;
  gap: 8px;
  flex-wrap: wrap;
  z-index: 5;
}
.hud-pill{
  padding: 7px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,.24);
  font-size: 12px;
  color: var(--text);
}

.statusbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}
.mono{ font-family: var(--mono); }

.panel.right{ min-width: 0; }
.canvas-wrap{
  padding: 14px;
  display:flex;
  justify-content:flex-start;
  align-items:flex-start;
  flex: 1;
  min-height: 0;
  overflow: auto;
}
#canvas2d{
  flex: 0 0 auto;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,.24);
  image-rendering: pixelated;
  touch-action: none;
  max-width: none;
  max-height: none;
}
.right-controls{
  border-top: 1px solid var(--border);
  padding: 12px 14px;
}

/* CSS 3D model */
.stage{
  position:absolute;
  inset: 0;
  display:flex;
  align-items:center;
  justify-content:center;
  perspective: 900px;
  transform-style: preserve-3d;
}
.model{
  position: relative;
  transform-style: preserve-3d;
  transform: translateZ(0) rotateX(var(--rx, -18deg)) rotateY(var(--ry, 28deg)) scale3d(var(--s, 1), var(--s, 1), var(--s, 1));
  will-change: transform;
}
.part{
  position:absolute;
  left: 50%;
  top: 50%;
  transform-style: preserve-3d;
  transform-origin: 0 0;
}
.cube{
  position: relative;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
}
.face{
  position:absolute;
  left: 0;
  top: 0;
  image-rendering: pixelated;
  background: transparent;
  outline: none;
  cursor: crosshair;
  backface-visibility: hidden;
  transform-style: preserve-3d;
  transform-origin: 0 0;
  touch-action: none;
}
.face[data-layer="base"]{
  outline: 1px solid rgba(12,24,48,.38);
  outline-offset: -1px;
}
.face[data-layer="base"][data-face="front"]{  background: rgba(156,184,230,.24); }
.face[data-layer="base"][data-face="right"]{  background: rgba(132,160,206,.24); }
.face[data-layer="base"][data-face="left"]{   background: rgba(110,138,184,.24); }
.face[data-layer="base"][data-face="top"]{    background: rgba(180,208,255,.26); }
.face[data-layer="base"][data-face="bottom"]{ background: rgba(72,96,140,.28); }
.face[data-layer="base"][data-face="back"]{   background: rgba(58,80,120,.30); }
.face[data-layer="overlay"]{
  background: transparent;
  outline: none;
}

.modal{
  width: min(820px, 92vw);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 0;
  color: var(--text);
  background: rgba(15,23,42,.92);
  box-shadow: 0 24px 80px rgba(0,0,0,.5);
}
.modal::backdrop{
  background: rgba(0,0,0,.55);
}
.modal-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-title{
  font-weight: 900;
  letter-spacing:.2px;
}
.modal-body{
  padding: 14px 16px 18px 16px;
  color: var(--text);
}
.modal-body h3{
  margin: 14px 0 8px 0;
}
.modal-body ul{
  margin: 8px 0 0 0;
  padding-left: 18px;
  line-height: 1.7;
  color: var(--muted);
}
.code{
  margin: 10px 0 0 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(0,0,0,.25);
  overflow:auto;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
}

/* Responsive */
@media (max-width: 1100px){
  .layout{
    grid-template-columns: 280px 1fr;
    grid-template-rows: auto auto;
    height: auto;
  }
  .panel.right{
    grid-column: 1 / -1;
    height: 520px;
  }
}
@media (max-width: 820px){
  .topbar{
    flex-wrap: wrap;
    gap: 10px;
  }
  .top-actions{
    width: 100%;
    justify-content: flex-start;
  }
  .layout{
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 10px;
  }
  .panel.left{ order: 2; }
  .panel.center{ order: 1; }
  .panel.right{ order: 3; height: 420px; }
  .viewer{ min-height: 420px; }
  .label{ width: 96px; }
  .brand-subtitle{ display:none; }
}
