* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; background: #f9f9f9; color: #575e75; }
#app { display: flex; flex-direction: column; height: 100vh; }

/* Scratch Topbar */
.scratch-topbar { display: flex; align-items: center; padding: 0 16px; background: #4c97ff; height: 48px; border-bottom: 1px solid rgba(0,0,0,0.15); gap: 16px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); z-index: 100; }
.scratch-brand { display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 700; font-size: 16px; }
.sb-logo { font-size: 20px; background: rgba(255,255,255,0.2); width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: 8px; }
.sb-edition { font-size: 10px; background: #ffab19; color: #fff; padding: 2px 6px; border-radius: 10px; font-weight: 600; text-transform: uppercase; }

.scratch-menu { display: flex; gap: 8px; align-items: center; }
.sm-btn { background: rgba(255,255,255,0.2); color: #fff; border: none; border-radius: 16px; padding: 5px 14px; font-size: 13px; font-weight: 600; cursor: pointer; transition: background 0.15s; }
.sm-btn:hover { background: rgba(255,255,255,0.3); }
.sm-select { background: rgba(255,255,255,0.2); color: #fff; border: none; border-radius: 16px; padding: 5px 10px; font-size: 13px; font-weight: 600; outline: none; cursor: pointer; }
.sm-select option { color: #333; background: #fff; }

.scratch-controls { display: flex; gap: 8px; align-items: center; margin-left: auto; }
.sc-btn { background: rgba(255,255,255,0.2); color: #fff; border: none; border-radius: 16px; padding: 6px 14px; font-size: 13px; font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 4px; }
.sc-btn:hover { background: rgba(255,255,255,0.3); }
.sc-btn.primary { background: #4caf50; }
.sc-btn.primary:hover { background: #43a047; }
.sc-select { background: rgba(255,255,255,0.2); color: #fff; border: none; border-radius: 16px; padding: 5px 10px; font-size: 13px; font-weight: 600; outline: none; }
.sc-select option { color: #333; }

/* Scratch Workspace Layout */
.scratch-workspace { display: flex; flex: 1; overflow: hidden; background: #f0f2f5; }

/* Palette Panel */
.palette-panel { width: 220px; background: #fff; border-right: 1px solid #e0e0e0; display: flex; flex-direction: column; overflow-y: auto; padding: 10px; box-shadow: inset -2px 0 5px rgba(0,0,0,0.02); }
.pal-cat { margin-bottom: 12px; }
.pal-cat-title { font-size: 12px; font-weight: 700; margin-bottom: 6px; padding: 2px 6px; text-transform: uppercase; letter-spacing: 0.5px; border-radius: 4px; display: inline-block; }
.pal-block { margin: 4px 0; padding: 9px 12px 10px 14px; cursor: pointer; font-size: 13px; font-weight: 600; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.3); border-radius: 6px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); transition: transform 0.1s, filter 0.1s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pal-block:hover { filter: brightness(1.1); transform: translateY(-1px); }
.pal-block:active { transform: translateY(1px); }

/* Center Workspace (Block Canvas) */
.workspace-col { flex: 1; display: flex; flex-direction: column; background: #f9f9f9; position: relative; overflow: hidden; border-right: 1px solid #e0e0e0; }
.block-workspace-container { flex: 1; position: relative; overflow: auto; background-image: radial-gradient(#d0d5dd 1px, transparent 1px); background-size: 20px 20px; background-color: #f8f9fa; }
.block-workspace-container canvas { display: block; cursor: default; }
.workspace-toolbar { height: 36px; background: #fff; border-top: 1px solid #e0e0e0; display: flex; align-items: center; padding: 0 16px; font-size: 12px; font-weight: 600; color: #666; gap: 16px; }

/* Right Stage (3D Viewport) */
.stage-col { width: 420px; background: #fff; display: flex; flex-direction: column; border-left: 1px solid #e0e0e0; box-shadow: -2px 0 10px rgba(0,0,0,0.03); }
.stage-header { padding: 10px 16px; font-size: 13px; font-weight: 700; color: #333; background: #f4f5f7; border-bottom: 1px solid #e0e0e0; display: flex; align-items: center; justify-content: space-between; }
.stage-viewport { flex: 1; position: relative; background: #e8f0fe; overflow: hidden; }
.stage-viewport canvas { display: block; width: 100% !important; height: 100% !important; cursor: crosshair; }
.stage-hint { padding: 8px 16px; font-size: 11px; color: #888; text-align: center; background: #fafbfc; border-top: 1px solid #eee; }

/* Code Modal */
.code-modal { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 1000; backdrop-filter: blur(2px); }
.code-modal-content { background: #fff; width: 600px; height: 450px; border-radius: 12px; display: flex; flex-direction: column; box-shadow: 0 10px 30px rgba(0,0,0,0.25); overflow: hidden; }
.cm-header { padding: 14px 20px; background: #4c97ff; color: #fff; font-weight: 700; font-size: 15px; display: flex; align-items: center; justify-content: space-between; }
.cm-close { background: none; border: none; color: #fff; font-size: 20px; cursor: pointer; }
.code-modal-content textarea { flex: 1; border: none; padding: 16px; font-family: 'Fira Code', Consolas, monospace; font-size: 13px; line-height: 1.5; resize: none; outline: none; background: #fafbfc; color: #24292e; }
.cm-footer { padding: 12px 20px; background: #f6f8fa; border-top: 1px solid #e1e4e8; display: flex; justify-content: flex-end; }
.be-btn.primary { background: #4c97ff; color: #fff; border: none; padding: 8px 18px; border-radius: 6px; font-weight: 600; cursor: pointer; }
.be-btn.primary:hover { background: #3b82f6; }

/* Responsive */
@media (max-width: 1200px) {
  .stage-col { width: 320px; }
  .palette-panel { width: 180px; }
}
