:root {
    /* 默认主题变量（糖果主题） */
    --primary: #FF6B9D;
    --secondary: #4ECDC4;
    --background: #FFF5F7;
    --surface: #FFFFFF;
    --text: #333333;
    --text-light: #666666;
    --grid: #FFE4EC;
    --obstacle: #C44569;
    --shadow: rgba(0, 0, 0, 0.1);
    --border-radius: 16px;
    --block-size: 60px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: var(--background);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* ========== 头部导航 ========== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: var(--surface);
    box-shadow: 0 2px 8px var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 28px;
}

.logo-text {
    font-size: 20px;
    font-weight: bold;
    color: var(--primary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.stars {
    font-size: 18px;
    font-weight: bold;
    color: #FFB800;
}

.version-badge {
    font-size: 12px;
    font-weight: 600;
    color: #999;
    background: var(--background);
    padding: 4px 8px;
    border-radius: 10px;
    margin-left: 4px;
}

.btn-theme, .btn-settings {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--background);
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
}

.btn-theme:hover, .btn-settings:hover {
    transform: scale(1.1);
    background: var(--grid);
}

/* ========== 主游戏区 - PC端布局 ========== */
.game-container {
    display: grid;
    grid-template-columns: 180px 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 20px;
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
    min-height: calc(100vh - 80px);
}

/* 积木面板 - 左侧纵向排列，占满两行 */
.panel-blocks {
    grid-row: 1 / 3;
    display: flex;
    flex-direction: column;
}

.blocks-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    max-height: calc(100vh - 200px);
}

.block-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* 游戏舞台 - 右侧上方 */
.panel-stage {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.stage-container {
    display: flex;
    justify-content: center;
}

#game-canvas {
    max-width: 100%;
    height: auto;
}

/* 编程区 - 右侧下方 */
.panel-code {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.code-area {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
}

/* ========== 平板适配 (1024px以下) ========== */
@media (max-width: 1024px) {
    .game-container {
        display: flex;
        flex-direction: column;
        padding: 12px;
        gap: 12px;
        max-width: 100%;
        min-height: auto;
    }

    .panel-blocks {
        grid-row: auto;
        display: flex;
        flex-direction: column;
    }

    .blocks-container {
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        max-height: none;
        padding-bottom: 8px;
        gap: 10px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .blocks-container::-webkit-scrollbar {
        display: none;
    }

    .block {
        min-width: 80px;
        padding: 10px 12px;
        font-size: 13px;
        flex-shrink: 0;
    }

    .block-group {
        flex-direction: row;
        gap: 10px;
    }

    .panel-stage {
        display: flex;
        flex-direction: column;
    }

    .stage-container {
        display: flex;
        justify-content: center;
    }

    #game-canvas {
        max-width: 100%;
        height: auto;
    }

    .stage-controls {
        margin-top: 10px;
    }

    .level-info {
        margin-top: 10px;
    }

    .panel-code {
        min-height: auto;
    }

    .code-area {
        min-height: 120px;
        max-height: 300px;
        overflow-y: auto;
    }
}

/* ========== 面板通用样式 ========== */
.panel {
    background: var(--surface);
    border-radius: var(--border-radius);
    padding: 16px;
    box-shadow: 0 4px 12px var(--shadow);
}

.panel-title {
    font-size: 16px;
    color: var(--text-light);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--grid);
}

/* ========== 指令积木区 ========== */
/* 积木面板样式已在上方统一定义 */

.block {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--primary);
    color: white;
    border-radius: 12px;
    cursor: grab;
    font-size: 14px;
    font-weight: 500;
    transition: transform 0.2s, box-shadow 0.2s;
    user-select: none;
    box-shadow: 0 4px 0 rgba(0,0,0,0.1);
}

.block:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 rgba(0,0,0,0.1);
}

.block:active {
    cursor: grabbing;
    transform: translateY(2px);
    box-shadow: 0 2px 0 rgba(0,0,0,0.1);
}

.block-icon {
    font-size: 20px;
}

.block-up { background: #4CAF50; }
.block-down { background: #2196F3; }
.block-left { background: #FF9800; }
.block-right { background: #FF9800; }
.block-jump { background: #9C27B0; }
.block-repeat { background: #E91E63; }
.block-if { background: #00BCD4; }
.block-function {
    background: #795548;
    border: 2px dashed rgba(255,255,255,0.3);
}

/* ========== 编程区 ========== */
.panel-code {
    display: flex;
    flex-direction: column;
    min-height: 500px;
}

.code-area {
    flex: 1;
    background: var(--background);
    border-radius: 12px;
    padding: 16px;
    min-height: 300px;
    position: relative;
    border: 2px dashed var(--grid);
}

.code-area.drag-over {
    background: var(--grid);
    border-color: var(--primary);
}

.code-placeholder {
    color: var(--text-light);
    text-align: center;
    padding: 40px;
    opacity: 0.6;
}

.code-block {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    margin: 4px;
    border-radius: 10px;
    color: white;
    font-size: 14px;
    position: relative;
    animation: slideIn 0.3s ease;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.code-block.running {
    box-shadow: 0 0 0 4px #FFD700, 0 4px 0 rgba(0,0,0,0.1);
    transform: scale(1.02);
    z-index: 10;
}

.code-block .remove-btn {
    margin-left: auto;
    width: 24px;
    height: 24px;
    border: none;
    background: rgba(255,255,255,0.3);
    border-radius: 50%;
    color: white;
    cursor: pointer;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.2s;
}

.code-block:hover .remove-btn {
    opacity: 1;
}

.code-block .remove-btn:hover {
    background: rgba(255,255,255,0.5);
}

.code-actions {
    display: flex;
    gap: 12px;
    margin-top: 12px;
}

/* ========== 游戏舞台 ========== */
.panel-stage {
    display: flex;
    flex-direction: column;
}

.stage-container {
    position: relative;
    background: var(--background);
    border-radius: 12px;
    overflow: hidden;
}

#game-canvas {
    display: block;
    width: 100%;
    height: auto;
    max-width: 400px;
    margin: 0 auto;
}

.stage-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.stage-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-top: 16px;
}

.btn-play {
    padding: 12px 32px;
    font-size: 18px;
    font-weight: bold;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 30px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 0 rgba(0,0,0,0.1);
}

.btn-play:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 rgba(0,0,0,0.1);
}

.btn-play:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 rgba(0,0,0,0.1);
}

.btn-play:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-speed {
    width: 44px;
    height: 44px;
    border: 2px solid var(--grid);
    background: var(--surface);
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-speed.active {
    background: var(--secondary);
    border-color: var(--secondary);
}

.level-info {
    margin-top: 16px;
    text-align: center;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--grid);
    border-radius: 4px;
    margin-top: 8px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    transition: width 0.3s ease;
    width: 3.33%;
}

/* ========== 按钮通用样式 ========== */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.btn-clear, .btn-undo {
    background: var(--background);
    color: var(--text);
    flex: 1;
}

.btn-clear:hover, .btn-undo:hover {
    background: var(--grid);
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-secondary {
    background: var(--background);
    color: var(--text);
}

/* ========== 弹窗 ========== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface);
    border-radius: var(--border-radius);
    padding: 24px;
    max-width: 500px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h3 {
    font-size: 20px;
    color: var(--text);
}

.btn-close {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--background);
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-light);
    transition: all 0.2s;
}

.btn-close:hover {
    background: var(--grid);
    color: var(--text);
}

/* ========== 角色选择 ========== */
.character-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.character-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px;
    background: var(--background);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    border: 3px solid transparent;
}

.character-item:hover {
    background: var(--grid);
    transform: translateY(-4px);
}

.character-item.selected {
    border-color: var(--primary);
    background: var(--grid);
}

.character-item.locked {
    opacity: 0.5;
    cursor: not-allowed;
}

.character-avatar {
    font-size: 48px;
    margin-bottom: 8px;
}

.character-name {
    font-size: 14px;
    color: var(--text);
}

.character-lock {
    font-size: 20px;
    position: absolute;
}

/* ========== 主题选择 ========== */
.theme-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.theme-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    border: 3px solid transparent;
}

.theme-item:hover {
    transform: translateY(-4px);
}

.theme-item.selected {
    border-color: var(--primary);
}

.theme-preview {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    margin-bottom: 8px;
}

.theme-name {
    font-size: 14px;
    color: var(--text);
}

/* ========== 关卡完成弹窗 ========== */
.modal-celebrate {
    text-align: center;
    padding: 40px;
}

.celebrate-animation {
    font-size: 80px;
    animation: bounce 0.6s ease infinite alternate;
}

@keyframes bounce {
    from { transform: scale(1); }
    to { transform: scale(1.2); }
}

.modal-celebrate h2 {
    font-size: 28px;
    color: var(--primary);
    margin: 20px 0 12px;
}

.modal-celebrate p {
    color: var(--text-light);
    margin-bottom: 20px;
}

.star-rating {
    font-size: 40px;
    margin-bottom: 24px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.modal-actions .btn {
    padding: 12px 24px;
    font-size: 16px;
}

/* ========== 粒子效果 ========== */
.particle {
    position: fixed;
    pointer-events: none;
    animation: particleFall 1s ease-out forwards;
}

@keyframes particleFall {
    0% {
        opacity: 1;
        transform: translateY(0) rotate(0deg);
    }
    100% {
        opacity: 0;
        transform: translateY(100px) rotate(360deg);
    }
}

/* ========== 解锁通知 ========== */
.unlock-notification {
    animation: slideInRight 0.5s ease;
}

.unlock-content {
    display: flex;
    align-items: center;
    gap: 16px;
}

.unlock-avatar {
    font-size: 48px;
    animation: bounce 0.6s ease infinite alternate;
}

.unlock-text h3 {
    font-size: 18px;
    color: #333;
    margin: 0;
}

.unlock-text p {
    font-size: 14px;
    color: #666;
    margin: 4px 0 0;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideOutRight {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100px);
    }
}

/* ========== 关卡地图 ========== */
.level-map-modal .modal-content {
    max-width: 900px;
    width: 95%;
    max-height: 85vh;
    padding: 0;
    overflow: hidden;
}

.level-map-body {
    display: flex;
    flex-direction: column;
    height: 600px;
    max-height: 60vh;
}

/* 世界导航 */
.worlds-nav {
    display: flex;
    gap: 8px;
    padding: 16px;
    overflow-x: auto;
    background: var(--background);
    border-bottom: 2px solid var(--grid);
}

.world-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 16px;
    background: var(--surface);
    border: 2px solid var(--grid);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
    min-width: 80px;
    position: relative;
    overflow: hidden;
}

.world-tab:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.world-tab.active {
    border-color: var(--world-color);
    background: linear-gradient(135deg, var(--world-color)20, var(--world-color)40);
    box-shadow: 0 4px 16px var(--world-color)40;
}

.world-icon {
    font-size: 28px;
    margin-bottom: 4px;
}

.world-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
}

.world-progress {
    width: 100%;
    height: 4px;
    background: var(--grid);
    border-radius: 2px;
    margin-top: 6px;
    overflow: hidden;
}

.world-progress-fill {
    height: 100%;
    background: var(--world-color);
    border-radius: 2px;
    transition: width 0.5s ease;
    width: 0%;
}

/* 世界内容 */
.worlds-container {
    flex: 1;
    overflow-y: auto;
    position: relative;
}

.world-section {
    display: none;
    padding: 20px;
    height: 100%;
}

.world-section.active {
    display: block;
}

.world-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    border-radius: 16px;
    margin-bottom: 20px;
    border: 2px solid;
}

.world-big-icon {
    font-size: 48px;
}

.world-info h4 {
    font-size: 20px;
    margin-bottom: 4px;
}

.world-info p {
    font-size: 14px;
    color: var(--text-light);
}

/* 关卡路径 */
.levels-path {
    position: relative;
    height: 400px;
    background: linear-gradient(to bottom, var(--surface), var(--background));
    border-radius: 16px;
    border: 2px dashed var(--grid);
}

.level-node {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: transform 0.3s;
    z-index: 10;
}

.level-node:hover {
    transform: scale(1.1);
}

.level-node.locked {
    opacity: 0.5;
    cursor: not-allowed;
}

.level-node.locked:hover {
    transform: none;
}

.level-dot {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--dot-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: bold;
    color: white;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    border: 3px solid white;
    transition: all 0.3s;
}

.level-node.unlocked .level-dot {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
    50% { box-shadow: 0 4px 20px var(--dot-color)80, 0 0 30px var(--dot-color)40; }
}

.level-stars {
    margin-top: 8px;
    font-size: 12px;
    background: rgba(255,255,255,0.9);
    padding: 2px 6px;
    border-radius: 10px;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* 地图底部 */
.level-map-footer {
    padding: 16px 20px;
    background: var(--background);
    border-top: 2px solid var(--grid);
}

.total-progress {
    display: flex;
    align-items: center;
    gap: 12px;
}

.total-progress span {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.total-progress .progress-bar {
    flex: 1;
    height: 12px;
}

/* 地图按钮样式 */
.btn-map {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--background);
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
}

.btn-map:hover {
    transform: scale(1.1);
    background: var(--grid);
}

/* ========== 关卡编辑器 ========== */
.level-editor-modal .modal-content {
    max-width: 1000px;
    width: 95%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    padding: 0;
}

.level-editor-body {
    display: flex;
    flex-direction: row;
    gap: 20px;
    padding: 20px;
    flex: 1;
    overflow: hidden;
}

.editor-toolbar {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 200px;
}

.tool-group {
    background: var(--background);
    border-radius: 12px;
    padding: 12px;
}

.tool-label {
    font-size: 12px;
    color: var(--text-light);
    font-weight: 600;
    display: block;
    margin-bottom: 8px;
}

.tools {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.tool-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 8px;
    border: 2px solid var(--grid);
    background: var(--surface);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.tool-btn:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}

.tool-btn.active {
    border-color: var(--primary);
    background: var(--primary)20;
    box-shadow: 0 4px 12px var(--primary)40;
}

.tool-icon {
    font-size: 24px;
    margin-bottom: 4px;
}

.tool-btn span:last-child {
    font-size: 11px;
    color: var(--text);
}

.size-selector {
    display: flex;
    gap: 8px;
}

.size-btn {
    flex: 1;
    padding: 8px;
    border: 2px solid var(--grid);
    background: var(--surface);
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.2s;
}

.size-btn:hover {
    border-color: var(--primary);
}

.size-btn.active {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
}

.editor-canvas-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

#editor-canvas {
    background: var(--surface);
    border-radius: 12px;
    border: 2px solid var(--grid);
    cursor: crosshair;
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
}

.canvas-hint {
    font-size: 12px;
    color: var(--text-light);
}

.editor-actions {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}

.editor-actions .btn {
    padding: 12px 24px;
    font-size: 14px;
}

.editor-sidebar {
    width: 220px;
    background: var(--background);
    border-radius: 12px;
    padding: 16px;
    overflow-y: auto;
}

.saved-levels h4 {
    margin-bottom: 12px;
    font-size: 14px;
    color: var(--text);
}

.empty-levels {
    text-align: center;
    padding: 20px;
    color: var(--text-light);
    font-size: 12px;
}

.saved-level-item {
    background: var(--surface);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 8px;
    border: 2px solid var(--grid);
    transition: all 0.2s;
}

.saved-level-item:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}

.saved-level-item .level-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.saved-level-item .level-name {
    font-weight: 600;
    font-size: 13px;
    color: var(--text);
}

.saved-level-item .level-size {
    font-size: 11px;
    color: var(--text-light);
    background: var(--background);
    padding: 2px 6px;
    border-radius: 4px;
}

.saved-level-item .level-actions {
    display: flex;
    gap: 8px;
}

.saved-level-item button {
    padding: 6px 10px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    background: var(--background);
    transition: all 0.2s;
}

.saved-level-item button:hover {
    background: var(--grid);
    transform: scale(1.1);
}

/* 创建按钮样式 */
.btn-create {
    background: linear-gradient(135deg, #4CAF50, #45a049);
    color: white;
    font-weight: 600;
}

.btn-create:hover {
    background: linear-gradient(135deg, #45a049, #3d8b40);
}

/* ========== 响应式 ========== */
@media (max-width: 768px) {
    .header {
        padding: 8px 12px;
    }

    .logo-text {
        font-size: 14px;
    }

    .header-actions {
        gap: 8px;
    }

    .stars {
        font-size: 14px;
    }

    .btn-theme, .btn-settings, .btn-map, .btn-audio, .btn-voice, .btn-create-level {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }

    .game-container {
        padding: 8px;
        gap: 10px;
    }

    .panel {
        padding: 10px;
        border-radius: 12px;
    }

    .panel-title {
        font-size: 14px;
        margin-bottom: 8px;
    }

    /* 积木区 - 更适合小屏幕 */
    .blocks-container {
        gap: 8px;
        padding-bottom: 4px;
    }

    .block {
        min-width: 80px;
        padding: 8px 12px;
        font-size: 12px;
        border-radius: 10px;
    }

    .block-icon {
        font-size: 18px;
    }

    /* 编程区 */
    .panel-code {
        min-height: 120px;
    }

    .code-area {
        min-height: 100px;
        padding: 10px;
    }

    .code-placeholder {
        font-size: 14px;
    }

    .code-block {
        padding: 8px 10px;
        font-size: 12px;
    }

    .code-actions {
        gap: 8px;
    }

    .code-actions .btn {
        padding: 8px 12px;
        font-size: 12px;
    }

    /* 舞台区 */
    .stage-container {
        padding: 8px;
    }

    #game-canvas {
        max-width: 100%;
        max-height: 280px;
    }

    .stage-controls {
        gap: 8px;
    }

    .btn-play {
        padding: 10px 24px;
        font-size: 14px;
    }

    .btn-speed {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }

    .level-info {
        font-size: 12px;
    }

    .progress-bar {
        height: 6px;
    }

    /* 弹窗 */
    .modal-content {
        max-width: 95%;
        max-height: 90vh;
        padding: 16px;
    }

    .character-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 12px;
    }

    .character-item {
        padding: 12px 8px;
    }

    .character-avatar {
        width: 48px;
        height: 48px;
        font-size: 32px;
    }

    .theme-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .unlock-notification {
        left: 16px;
        right: 16px;
        top: 70px;
        padding: 12px 16px;
    }

    /* 关卡地图 */
    .level-map-body {
        height: 400px;
    }

    .worlds-nav {
        gap: 8px;
    }

    .world-tab {
        min-width: 50px;
        padding: 6px 8px;
    }

    .world-icon {
        font-size: 20px;
    }

    .world-name {
        font-size: 9px;
    }

    .levels-path {
        height: 280px;
    }

    .level-dot {
        width: 36px;
        height: 36px;
        font-size: 12px;
    }

    .level-stars {
        font-size: 9px;
    }

    /* 编辑器 */
    .level-editor-body {
        flex-direction: column;
        padding: 10px;
    }

    .editor-toolbar {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 12px;
    }

    .tool-group {
        flex: 1;
        min-width: 120px;
    }

    .tools {
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
    }

    .tool-btn {
        padding: 6px 4px;
        font-size: 11px;
    }

    .editor-sidebar {
        width: 100%;
        max-height: 180px;
    }

    #editor-canvas {
        max-width: 100%;
        max-height: 250px;
    }

    /* 触摸优化 */
    .block:active,
    .code-block:active,
    .btn:active,
    .tool-btn:active {
        transform: scale(0.95);
    }

    /* 移除hover效果（触摸设备不需要） */
    .block:hover,
    .btn:hover {
        transform: none;
    }

    .block:active {
        transform: scale(0.95);
    }
}

/* ========== 舞台拖放提示动画 ========== */
@keyframes fadeInOut {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
    20% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
}

/* 舞台拖放时的视觉反馈 */
#game-canvas {
    transition: transform 0.2s, box-shadow 0.2s;
}

/* ========== 抖动动画 ========== */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-5px); }
    40%, 80% { transform: translateX(5px); }
}

/* ========== 手机专用适配 (480px以下) ========== */
@media (max-width: 480px) {
    /* 头部压缩 */
    .header {
        padding: 6px 8px;
        flex-wrap: wrap;
        gap: 6px;
        position: relative;
    }

    .logo {
        gap: 6px;
    }

    .logo-icon {
        font-size: 22px;
    }

    .logo-text {
        font-size: 12px;
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .stars {
        font-size: 12px;
    }

    .version-badge {
        font-size: 10px;
        padding: 3px 6px;
    }

    .btn-theme, .btn-settings, .btn-map {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }

    /* 游戏容器 - 让内容决定高度，整个页面可滚动 */
    .game-container {
        padding: 6px;
        gap: 8px;
        min-height: auto;
        height: auto;
    }

    .panel {
        padding: 8px;
        border-radius: 10px;
    }

    .panel-title {
        font-size: 12px;
        margin-bottom: 6px;
        padding-bottom: 4px;
    }

    /* 游戏舞台 - 紧凑显示 */
    .panel-stage {
        /* 保持flex纵向布局 */
    }

    .stage-container {
        padding: 4px;
    }

    #game-canvas {
        max-height: 220px;
    }

    .stage-controls {
        margin-top: 8px;
    }

    .btn-play {
        padding: 8px 20px;
        font-size: 13px;
    }

    .btn-speed {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }

    .level-info {
        font-size: 11px;
        margin-top: 8px;
    }

    /* 积木区 - 横向滚动，紧凑显示 */
    .panel-blocks {
        /* 保持flex纵向布局 */
    }

    .blocks-container {
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        max-height: none;
        padding-bottom: 6px;
        gap: 8px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .blocks-container::-webkit-scrollbar {
        display: none;
    }

    .block {
        min-width: 65px;
        padding: 6px 8px;
        font-size: 11px;
        border-radius: 8px;
        flex-shrink: 0;
    }

    .block-icon {
        font-size: 16px;
    }

    .block-group {
        flex-direction: row;
        gap: 8px;
    }

    /* 编程区 - 底部展开，支持滚动 */
    .panel-code {
        min-height: 100px;
    }

    .code-area {
        min-height: 100px;
        max-height: 250px;
        overflow-y: auto;
        padding: 8px;
    }

    .code-placeholder {
        font-size: 12px;
        padding: 16px;
    }

    .code-block {
        padding: 6px 8px;
        font-size: 11px;
        margin-bottom: 6px;
        border-radius: 8px;
    }

    .code-block .remove-btn {
        width: 20px;
        height: 20px;
        font-size: 10px;
        opacity: 1;
        background: rgba(0,0,0,0.2);
    }

    .code-actions {
        gap: 6px;
        margin-top: 8px;
    }

    .code-actions .btn {
        padding: 6px 10px;
        font-size: 11px;
        border-radius: 6px;
    }

    .progress-bar {
        height: 5px;
        margin-top: 6px;
    }

    /* 弹窗 */
    .modal-content {
        max-width: 98%;
        max-height: 88vh;
        padding: 12px;
        border-radius: 12px;
    }

    .modal-header h3 {
        font-size: 16px;
    }

    .btn-close {
        width: 28px;
        height: 28px;
        font-size: 20px;
    }

    .character-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    .character-item {
        padding: 10px 6px;
    }

    .character-avatar {
        width: 40px;
        height: 40px;
        font-size: 28px;
    }

    .character-name {
        font-size: 11px;
    }

    .theme-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .theme-preview {
        width: 50px;
        height: 50px;
    }

    .theme-name {
        font-size: 12px;
    }

    /* 关卡完成弹窗 */
    .modal-celebrate {
        padding: 24px 16px;
    }

    .celebrate-animation {
        font-size: 60px;
    }

    .modal-celebrate h2 {
        font-size: 22px;
    }

    .modal-celebrate p {
        font-size: 13px;
    }

    .star-rating {
        font-size: 32px;
    }

    .modal-actions {
        flex-direction: column;
        gap: 8px;
    }

    .modal-actions .btn {
        padding: 10px 20px;
        font-size: 14px;
        width: 100%;
    }

    /* 关卡地图 */
    .level-map-body {
        height: 350px;
    }

    .worlds-nav {
        padding: 10px;
        gap: 6px;
    }

    .world-tab {
        min-width: 45px;
        padding: 6px 6px;
    }

    .world-icon {
        font-size: 18px;
    }

    .world-name {
        font-size: 8px;
    }

    .world-progress {
        height: 3px;
    }

    .levels-path {
        height: 220px;
    }

    .level-dot {
        width: 30px;
        height: 30px;
        font-size: 11px;
    }

    .level-stars {
        font-size: 8px;
        padding: 1px 4px;
    }

    /* 编辑器 */
    .level-editor-body {
        padding: 8px;
        gap: 10px;
    }

    .editor-toolbar {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
    }

    .tool-group {
        min-width: 100px;
        padding: 8px;
    }

    .tools {
        grid-template-columns: repeat(4, 1fr);
        gap: 4px;
    }

    .tool-btn {
        padding: 6px 4px;
        font-size: 10px;
    }

    .tool-icon {
        font-size: 18px;
    }

    .editor-sidebar {
        width: 100%;
        max-height: 140px;
        padding: 10px;
    }

    #editor-canvas {
        max-height: 200px;
    }

    /* 通知 */
    .unlock-notification {
        left: 10px;
        right: 10px;
        top: 60px;
        padding: 10px 12px;
    }

    .unlock-avatar {
        font-size: 36px;
    }

    .unlock-text h3 {
        font-size: 14px;
    }

    .unlock-text p {
        font-size: 12px;
    }

    /* 触摸友好 - 增大所有可点击元素的最小尺寸 */
    button, .btn, .block, .code-block, .character-item, .theme-item, .tool-btn, .level-node, .world-tab {
        min-height: 44px;
        min-width: 44px;
        touch-action: manipulation;
    }

    /* 触摸反馈 */
    .block:active, .code-block:active, .btn:active, .tool-btn:active, .character-item:active, .theme-item:active {
        transform: scale(0.95);
        opacity: 0.8;
    }

    /* 禁用hover效果（触摸设备） */
    *:hover {
        transition: none;
    }
}

/* ========== 超小屏幕适配 (360px以下) ========== */
@media (max-width: 360px) {
    .logo-text {
        display: none;
    }

    .logo-icon {
        font-size: 26px;
    }

    #game-canvas {
        max-height: 200px;
    }

    .block {
        min-width: 60px;
        padding: 6px 8px;
        font-size: 10px;
    }

    .block-icon {
        font-size: 14px;
    }

    .btn-play {
        padding: 6px 16px;
        font-size: 12px;
    }

    .character-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .modal-actions {
        flex-direction: column;
    }
}
