/* 基础样式重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --bg-panel: #1e2a4a;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --accent-primary: #e94560;
    --accent-secondary: #533483;
    --border-color: #2d3a5c;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    --radius: 12px;
    
    /* 积木颜色 */
    --motion-color: #4C97FF;
    --looks-color: #9966FF;
    --sound-color: #CF63CF;
    --event-color: #FFBF00;
    --control-color: #FFAB19;
    --sensing-color: #59C059;
    --operators-color: #FF8C1A;
    --data-color: #FF6619;
    --custom-color: #0FBD8C;
    --extension-color: #5C4EFF;
}

body {
    font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
}

/* 应用容器 */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* 头部 */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow);
}

.app-header h1 {
    font-size: 20px;
    font-weight: 600;
    color: white;
}

.header-actions {
    display: flex;
    gap: 10px;
}

/* 按钮样式 */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(233, 69, 96, 0.4);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
}

/* 主内容区 */
.main-content {
    display: flex;
    flex: 1;
    gap: 16px;
    padding: 16px;
    overflow: hidden;
}

/* 面板通用样式 */
.panel {
    background: var(--bg-panel);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.panel-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.panel-actions {
    display: flex;
    gap: 8px;
}

.panel-content {
    flex: 1;
    overflow: auto;
    padding: 12px;
}

/* 左侧区域 */
.left-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
    flex: 1.2;
    min-width: 0;
}

/* 积木预览区 */
.block-preview-panel {
    height: 180px;
    min-height: 180px;
}

.block-preview-panel .panel-content {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
}

.preview-placeholder {
    color: var(--text-secondary);
    font-size: 14px;
}

#blockPreview {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100%;
}

/* 下方区域 */
.bottom-section {
    display: flex;
    gap: 16px;
    flex: 1;
    min-height: 0;
}

/* 扩展代码区（积木面板） */
.block-palette-panel {
    width: 260px;
    min-width: 260px;
}

.block-palette-panel .panel-content {
    padding: 0;
    overflow-y: auto;
}

/* 分类 */
.category {
    border-bottom: 1px solid var(--border-color);
}

.category:last-child {
    border-bottom: none;
}

.category-header {
    padding: 10px 12px;
    background: var(--bg-tertiary);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.2s;
}

.category-header:hover {
    background: var(--border-color);
}

.category-blocks {
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* 积木项 */
.block-item {
    cursor: grab;
    transition: transform 0.2s;
}

.block-item:hover {
    transform: scale(1.02);
}

.block-item:active {
    cursor: grabbing;
}

/* 积木样式 */
.block {
    display: inline-flex;
    align-items: center;
    padding: 8px 14px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
    color: white;
    white-space: nowrap;
    user-select: none;
    position: relative;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    gap: 4px;
}

.block span {
    position: relative;
    z-index: 1;
}

/* 命令积木（矩形） */
.command-block {
    border-radius: 4px;
    min-height: 32px;
}

/* 数据积木（圆形） */
.reporter-block {
    border-radius: 16px;
    min-height: 32px;
}

/* 布尔积木（六边形） */
.boolean-block {
    border-radius: 4px;
    min-height: 32px;
    clip-path: polygon(12% 0%, 88% 0%, 100% 50%, 88% 100%, 12% 100%, 0% 50%);
    padding: 8px 24px;
}

/* 启动积木（帽子） */
.hat-block {
    border-radius: 4px 4px 4px 4px;
    min-height: 36px;
    position: relative;
    padding-top: 10px;
}

.hat-block::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 10px;
    width: 60px;
    height: 16px;
    background: inherit;
    border-radius: 8px 8px 0 0;
}

/* 结束积木（盖子） */
.cap-block {
    border-radius: 4px 4px 16px 16px;
    min-height: 32px;
}

/* C形积木 */
.c-block {
    border-radius: 4px;
    min-height: 48px;
    min-width: 100px;
    position: relative;
}

.c-block::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 20px;
    width: 16px;
    height: 8px;
    background: inherit;
    border-radius: 0 0 4px 4px;
}

/* 积木颜色 */
.motion-color { background: var(--motion-color); }
.looks-color { background: var(--looks-color); }
.sound-color { background: var(--sound-color); }
.event-color { background: var(--event-color); }
.control-color { background: var(--control-color); }
.sensing-color { background: var(--sensing-color); }
.operators-color { background: var(--operators-color); }
.data-color { background: var(--data-color); }
.custom-color { background: var(--custom-color); }
.extension-color { background: var(--extension-color); }

/* 工作区 */
.workspace-panel {
    flex: 1;
    min-width: 0;
}

.workspace {
    background: var(--bg-secondary);
    background-image: 
        radial-gradient(circle at 10px 10px, var(--border-color) 1px, transparent 1px);
    background-size: 20px 20px;
    min-height: 100%;
    position: relative;
}

.workspace-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-secondary);
    font-size: 14px;
    pointer-events: none;
}

.workspace.drag-over {
    background-color: rgba(233, 69, 96, 0.1);
}

/* 工作区中的积木 */
.workspace .block-wrapper {
    position: absolute;
    cursor: grab;
}

.workspace .block-wrapper.dragging {
    cursor: grabbing;
    z-index: 1000;
}

.workspace .block {
    cursor: grab;
}

/* 积木内的输入框 - 圆形数据格子 */
.block-input {
    background: white;
    border: none;
    border-radius: 12px;
    padding: 2px 10px;
    font-size: 12px;
    color: #333;
    min-width: 24px;
    text-align: center;
    outline: none;
    cursor: text;
}

.block-input:focus {
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5);
}

/* 积木内的下拉框 */
.block-dropdown {
    background: rgba(255, 255, 255, 0.3);
    border: none;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 12px;
    color: white;
    cursor: pointer;
    outline: none;
}

.block-dropdown option {
    background: var(--bg-panel);
    color: var(--text-primary);
}

/* 积木文本容器 */
.block-text {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* 设置面板 */
.settings-panel {
    width: 300px;
    min-width: 300px;
}

.settings-panel .panel-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.settings-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.settings-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.settings-group input[type="text"],
.settings-group select,
.settings-group textarea {
    padding: 10px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    transition: border-color 0.2s;
}

.settings-group input[type="text"]:focus,
.settings-group select:focus,
.settings-group textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.settings-group textarea {
    resize: vertical;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 13px;
    line-height: 1.5;
}

/* 颜色选择器 */
.color-picker {
    display: flex;
    align-items: center;
    gap: 12px;
}

.color-picker input[type="color"] {
    width: 50px;
    height: 40px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    background: none;
}

.color-value {
    font-family: 'Consolas', monospace;
    font-size: 13px;
    color: var(--text-secondary);
}

/* 预设颜色 */
.preset-colors {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
}

.preset-color {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 2px solid transparent;
    margin: 0 auto;
}

.preset-color:hover {
    transform: scale(1.1);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
}

.preset-color.selected {
    border-color: white;
    box-shadow: 0 0 0 2px var(--accent-primary);
}

/* 参数设置 */
.params-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.param-item {
    display: flex;
    gap: 8px;
    align-items: center;
}

.param-item input[type="text"] {
    flex: 1;
}

.param-item select {
    width: 100px;
}

.btn-remove-param {
    width: 28px;
    height: 28px;
    border: none;
    background: rgba(233, 69, 96, 0.2);
    color: var(--accent-primary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s;
}

.btn-remove-param:hover {
    background: var(--accent-primary);
    color: white;
}

.settings-actions {
    display: flex;
    gap: 10px;
    margin-top: auto;
}

.settings-actions .btn {
    flex: 1;
}

/* 代码输出区 */
.code-output-panel {
    flex: 1;
    min-width: 0;
}

.code-output-panel .panel-content {
    padding: 0;
}

#codeOutput {
    width: 100%;
    height: 100%;
    min-height: 400px;
    padding: 16px;
    background: var(--bg-secondary);
    border: none;
    color: var(--text-primary);
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    resize: none;
    outline: none;
}

#codeOutput::placeholder {
    color: var(--text-secondary);
}

/* 拖拽幽灵元素 */
.drag-ghost {
    position: fixed;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.9;
    transform: rotate(3deg);
    display: none;
}

.drag-ghost.active {
    display: block;
}

/* 滚动条样式 */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-secondary);
}

/* 工作区积木堆叠 */
.block-stack {
    display: flex;
    flex-direction: column;
    gap: 2px;
    position: absolute;
}

.block-stack .block {
    position: relative;
}

.block-stack .block::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 10px;
    width: 16px;
    height: 6px;
    background: inherit;
    border-radius: 0 0 4px 4px;
}

.block-stack .block:last-child::after {
    display: none;
}

/* 选中状态 */
.block.selected {
    box-shadow: 0 0 0 3px white, 0 0 0 5px var(--accent-primary);
}

/* 响应式 */
@media (max-width: 1400px) {
    .main-content {
        flex-wrap: wrap;
    }
    
    .settings-panel {
        width: 100%;
        order: -1;
    }
}

/* 输入提示 */
.input-hint {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* 变量管理 */
.variables-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.variable-item {
    display: flex;
    gap: 8px;
    align-items: center;
}

.variable-item input[type="text"] {
    flex: 1;
    padding: 8px 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 13px;
}

.variable-item input[type="text"]:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.variable-item .variable-name {
    flex: 1.2;
}

.variable-item .variable-value {
    flex: 0.8;
}

.btn-remove-variable {
    width: 28px;
    height: 28px;
    border: none;
    background: rgba(233, 69, 96, 0.2);
    color: var(--accent-primary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s;
}

.btn-remove-variable:hover {
    background: var(--accent-primary);
    color: white;
}

.variable-actions {
    margin-top: 8px;
}

/* 动画 */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.panel {
    animation: fadeIn 0.3s ease;
}
