/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    background: #0a0a0a;
}

:root {
    --primary-color: #00f5ff;
    --secondary-color: #ff6b6b;
    --accent-color: #4ecdc4;
    --bg-dark: #0a0a0a;
    --bg-darker: #050505;
    --glass-bg: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.2);
    --text-primary: #ffffff;
    --text-secondary: #b3b3b3;
    --success-color: #2ecc71;
    --danger-color: #e74c3c;
    --warning-color: #f39c12;
    
    --shadow-glow: 0 0 20px rgba(0, 245, 255, 0.3);
    --shadow-subtle: 0 4px 20px rgba(0, 0, 0, 0.3);
    --border-radius: 12px;
    --border-radius-lg: 20px;
}

body {
    font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-darker) 100%);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh; /* 动态视口高度，支持Safari */
    overflow: hidden;
    margin: 0;
    padding: 0;
    position: fixed;
    width: 100%;
    /* Safari安全区域支持 */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* 背景动画 */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 20% 80%, rgba(0, 245, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(255, 107, 107, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 40% 40%, rgba(78, 205, 196, 0.1) 0%, transparent 50%);
    z-index: -1;
    animation: backgroundShift 20s ease-in-out infinite;
}

@keyframes backgroundShift {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* 容器布局 */
.container {
    height: 100vh;
    height: 100dvh; /* 动态视口高度 */
    padding: 0;
    margin: 0;
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-darker) 100%);
    overflow: hidden;
}

/* 游戏头部 */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
    padding: 8px 12px;
    margin-bottom: 10px;
    flex-shrink: 0;
    height: 60px;
    box-sizing: border-box;
}

.game-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.4rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    flex-shrink: 1;
    min-width: 0;
}

.game-title .icon {
    font-size: 1.2rem;
    filter: drop-shadow(0 0 10px var(--primary-color));
    flex-shrink: 0;
}

.game-stats {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

.stat-item {
    text-align: center;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
    padding: 6px 10px;
    min-width: 50px;
    box-sizing: border-box;
    height: 44px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.stat-label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-bottom: 2px;
    line-height: 1;
}

.stat-value {
    display: block;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-color);
    text-shadow: 0 0 10px var(--primary-color);
    line-height: 1;
}

/* 主要内容区域 */
.game-main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    height: 100vh;
    height: 100dvh; /* 动态视口高度 */
    overflow: hidden;
}

/* 游戏区域 */
.game-area {
    display: flex;
    flex-direction: column;
    padding: 10px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--glass-border);
    height: 100vh;
    height: 100dvh; /* 动态视口高度 */
    overflow: hidden;
    resize: none;
    box-sizing: border-box;
}

#gameCanvas {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 2px solid var(--glass-border);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-glow);
    width: calc(100% - 20px);
    height: calc(100vh - 140px);
    height: calc(100dvh - 140px);
    max-width: calc(100vh - 140px);
    max-width: calc(100dvh - 140px);
    margin: 0 auto;
    cursor: crosshair;
    transition: all 0.3s ease;
    resize: none;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    flex: 1;
    object-fit: contain;
}

#gameCanvas:hover,
#gameCanvas:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 30px rgba(0, 245, 255, 0.5);
    outline: none;
}

.game-controls {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 10px;
    height: 50px;
    align-items: center;
}

/* 代码区域 */
.code-area {
    display: flex;
    flex-direction: column;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: none;
    border-radius: 0;
    overflow: hidden;
    height: 100vh;
    height: 100dvh; /* 动态视口高度 */
    resize: none;
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.2);
}

.editor-header h3 {
    font-size: 1.2rem;
    color: var(--text-primary);
}

.code-editor {
    flex: 1;
    min-height: 500px;
    border-radius: 0;
    resize: none;
    overflow: hidden;
}

.editor-footer {
    height: 200px;
    border-top: 1px solid var(--glass-border);
    resize: none;
    overflow: hidden;
}

/* 控制台 */
.console {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.console-header {
    padding: 10px 20px;
    background: rgba(0, 0, 0, 0.3);
    color: var(--text-secondary);
    font-size: 0.9rem;
    border-bottom: 1px solid var(--glass-border);
}

.console-content {
    flex: 1;
    padding: 15px 20px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9rem;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.2);
}

.console-line {
    margin-bottom: 5px;
    padding: 2px 0;
}

.console-line.error {
    color: var(--danger-color);
}

.console-line.success {
    color: var(--success-color);
}

.console-line.info {
    color: var(--primary-color);
}

/* 按钮样式 */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    backdrop-filter: blur(10px);
    position: relative;
    overflow: hidden;
    height: 36px;
    box-sizing: border-box;
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.btn:hover::before {
    left: 100%;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    color: var(--bg-dark);
    box-shadow: 0 0 20px rgba(0, 245, 255, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 25px rgba(0, 245, 255, 0.5);
}

.btn-secondary {
    background: var(--glass-bg);
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger-color), #c0392b);
    color: white;
    box-shadow: 0 0 20px rgba(231, 76, 60, 0.3);
}

.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 25px rgba(231, 76, 60, 0.5);
}

.btn-info {
    background: linear-gradient(135deg, var(--accent-color), #2ecc71);
    color: white;
    box-shadow: 0 0 20px rgba(78, 205, 196, 0.3);
}

.btn-info:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 25px rgba(78, 205, 196, 0.5);
}

/* 教程面板 */
.tutorial-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 500px;
    max-height: 80vh;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-glow);
    z-index: 1000;
    display: none;
    flex-direction: column;
}

.tutorial-panel.active {
    display: flex;
}

.tutorial-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--glass-border);
}

.tutorial-header h3 {
    font-size: 1.3rem;
    color: var(--primary-color);
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.close-btn:hover {
    background: var(--glass-bg);
    color: var(--text-primary);
}

.tutorial-content {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

.tutorial-step {
    display: none;
}

.tutorial-step.active {
    display: block;
}

.tutorial-step h4 {
    color: var(--accent-color);
    margin-bottom: 10px;
    font-size: 1.1rem;
}

.tutorial-step p {
    margin-bottom: 15px;
    line-height: 1.6;
    color: var(--text-secondary);
}

.tutorial-step ul {
    margin-left: 20px;
    margin-bottom: 15px;
}

.tutorial-step li {
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.tutorial-step code {
    background: rgba(0, 0, 0, 0.4);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--primary-color);
    font-family: 'Monaco', 'Menlo', monospace;
}

.tutorial-navigation {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-top: 1px solid var(--glass-border);
}

#stepIndicator {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* 关卡选择面板 */
.level-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 50%;
    height: 100vh;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border-left: 1px solid var(--glass-border);
    box-shadow: -5px 0 20px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    display: none;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s ease;
}

.level-panel.active {
    display: flex;
    transform: translateX(0);
}

.level-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--glass-border);
}

.level-panel-header h3 {
    font-size: 1.5rem;
    color: var(--primary-color);
    margin: 0;
}

.level-panel-content {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
}

.level-stages {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.stage-section {
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--border-radius);
    padding: 15px;
    border: 1px solid var(--glass-border);
}

.stage-section h4 {
    color: var(--accent-color);
    margin: 0 0 10px 0;
    font-size: 1.2rem;
}

.stage-section p {
    color: var(--text-secondary);
    margin: 0 0 15px 0;
    font-size: 0.85rem;
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(35px, 1fr));
    gap: 6px;
}

.level-item {
    aspect-ratio: 1;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
    font-size: 0.8rem;
    position: relative;
}

.level-item:hover {
    background: var(--primary-color);
    color: var(--bg-dark);
    transform: scale(1.05);
    box-shadow: 0 0 10px rgba(0, 245, 255, 0.5);
}

.level-item.completed {
    background: var(--success-color);
    color: white;
}

.level-item.current {
    background: var(--warning-color);
    color: var(--bg-dark);
    animation: pulse 2s infinite;
}

.level-panel-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-top: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.2);
}

/* 关卡信息显示 */
.level-info {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
    padding: 8px 12px;
    margin-top: 10px;
    flex-shrink: 0;
    height: auto;
    min-height: 40px;
}

.level-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 10px;
}

.level-progress {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.level-progress span {
    display: flex;
    align-items: center;
    gap: 5px;
}

/* 响应式设计 */
@media (max-width: 1200px) {
    .game-main {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        height: auto;
        min-height: 100vh;
    }
    
    .game-area {
        order: 1;
        height: auto;
        min-height: 500px;
    }
    
    .code-area {
        order: 2;
        height: auto;
        min-height: 500px;
    }
    
    .level-panel {
        width: 60%;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    .game-header {
        flex-direction: column;
        gap: 20px;
        text-align: center;
    }
    
    .game-title {
        font-size: 2rem;
    }
    
    .game-stats {
        justify-content: center;
    }
    
    .tutorial-panel {
        width: 90%;
        max-width: 400px;
    }
    
    .game-controls {
        flex-wrap: wrap;
    }
    
    .level-panel {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--glass-border);
    }
    
    .level-grid {
        grid-template-columns: repeat(auto-fill, minmax(30px, 1fr));
        gap: 4px;
    }
    
    .level-panel-footer {
        flex-direction: column;
        gap: 10px;
    }
    
    .level-item {
        font-size: 0.7rem;
    }
}

/* 动画效果 */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.loading {
    animation: pulse 1.5s ease-in-out infinite;
}

/* 滚动条样式 */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}