/* style.css  */
:root {
    --bg-dark: #1a1a1a;
    --panel-bg: #2d2d2d;
    --header-bg: #3c3c3c;
    --editor-bg: #1e1e1e;
    --text-color: #d4d4d4;
    --success: #28a745;
    --info: #17a2b8;
    --error: #dc3545;
    --output-bg: #1a0f0f;
    --output-text: #e0e0e0;

    /* 尺寸变量 */
    --simulator-width: 720px;
    --simulator-height: 500px;
    --canvas-width: 480px;
    --canvas-height: 240px;
    --header-height: 60px;
    --footer-height: 105px;
    --simulator-header-height: 40px;

    /* 位置比例 */
    --canvas-top-ratio: 0.31;
    /* 135/510 ≈ 0.265 */
    --canvas-left-ratio: 0.123;
    /* 115/710 ≈ 0.162 */
    --canvas-width-ratio: 0.676;
    /* 480/710 ≈ 0.676 */
    --canvas-height-ratio: 0.471;
    /* 240/510 ≈ 0.471 */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background: var(--bg-dark);
    color: white;
    height: 100vh;
    display: flex;
    overflow: hidden;
}

.container {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0;
    /* max-width: 100%; */
    max-width: 100vw;
    /* 限制最大宽度不超过视口 */
    overflow-x: hidden;
    /* 禁止水平滚动 */
}

header {
    background: linear-gradient(135deg, #2c3e50, #1a2a3a);
    padding: 1rem;
    text-align: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    height: var(--header-height);
    flex-shrink: 0;
}

header h1 {
    font-size: 1.8rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

main {
    flex: 1;
    display: flex;
    gap: 1.5rem;
    padding: 1.5rem;
    overflow-x: hidden;
    overflow-y: auto;
}

/* 屏幕模拟区域 */
.screen-simulator {
    border-radius: 10px;
    overflow: hidden;
    background: var(--panel-bg);
    display: flex;
    flex-direction: column;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s ease;
    width: var(--simulator-width);
    height: calc(var(--simulator-height) + var(--simulator-header-height) + var(--footer-height));
    flex-shrink: 0;
}

.simulator-header {
    position: relative;
    background: linear-gradient(135deg, #3a506b, #1c2541);
    padding: 0.4rem 1.2rem;
    display: flex;
    justify-content: space-between;
    font-size: 0.95rem;
    font-weight: 500;
    height: var(--simulator-header-height);
    flex-shrink: 0;
}

.brain-container {
    position: relative;
    width: 100%;
    height: var(--simulator-height);
    background: url('./assets/brain.svg') center/cover;
    flex-shrink: 0;
}


#run-time-container {
    position: absolute;
    top: 25%;
    left: 45%;
    transform: translateX(-50%);
    z-index: 10;
    /* 确保在画布上方 */
    display: none; 
}

#run-time {
    color: white;
    background-color: rgba(0, 0, 0, 0);
    pointer-events: none; 
    font-family: 'Consolas', monospace;
    font-size: 22px;
    text-align: center;

}

/* 画布位置和比例 - 关键优化 */
#screenCanvas {
    position: absolute;
    top: calc(var(--canvas-top-ratio) * 100%);
    /* 26.5% */
    left: calc(var(--canvas-left-ratio) * 100%);
    /* 16.2% */
    width: calc(var(--canvas-width-ratio) * 100%);
    /* 67.6% */
    height: calc(var(--canvas-height-ratio) * 100%);
    /* 47.1% */
    background: #000;
}

/* 代码编辑器区域 */
.code-editor {
    border-radius: 10px;
    flex: 1;
    background: var(--editor-bg);
    display: flex;
    flex-direction: column;
    min-height: 500px;
    min-width: 0;
    overflow-x: hidden;

}

.editor-header {
    border-radius: 10px;
    background: linear-gradient(135deg, #3a506b, #1c2541);
    padding: 0.8rem 1.2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.95rem;
    font-weight: 500;
    flex-shrink: 0;
}

#status {
    color: #a5d6a7;
    font-weight: 500;
    min-width: 120px;
    text-align: center;
}

.editor-body {
    flex: 1;
    position: relative;
    overflow: hidden;


    display: flex;
    flex-direction: column;
    min-width: 0;
    /* 防止内容撑开容器 */
}

/* CodeMirror样式覆盖 */
.CodeMirror {
    border-radius: 10px;
    height: 100% !important;
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 15px;
    background: var(--editor-bg);
    color: white;


}

.CodeMirror-scroll {
    height: 100% !important;
    overflow: auto;
}



.btn {
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    color: white;
    cursor: pointer;
    margin-left: 10px;
    font-weight: 600;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.run-btn {
    background: linear-gradient(to right, var(--success), #1e7e34);
}

.reset-btn {
    background: linear-gradient(to right, var(--error), #8b1111);
}

.run-btn:hover {
    background: linear-gradient(to right, #218838, #1c7430);
}

.reset-btn:hover {
    background: linear-gradient(to right, #961313, #7f1111);
}

/* 输出控制台 */
footer {
    background: linear-gradient(135deg, #3a506b, #1c2541);
    height: var(--footer-height);
    display: flex;
    flex-shrink: 0;
}

.output-console {

    background: var(--output-bg);
    color: var(--output-text);
    flex: 1;
    padding: 0.8rem;
    font-family: 'Consolas', monospace;
    font-size: 14px;
    overflow-y: auto;
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.3);
    max-width: var(--simulator-width);
    min-height: 100px;
}

.output-line {
    padding: 4px 0;
    line-height: 1.1;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.output-line:last-child {
    border-bottom: none;
}

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

.output-console::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
}

.output-console::-webkit-scrollbar-thumb {
    background: #4a5568;
    border-radius: 4px;
}

.output-console::-webkit-scrollbar-thumb:hover {
    background: #2d3748;
}

.example-selector {
    background: var(--panel-bg);
    border: none;
    color: var(--text-color);
    padding: 8px 12px 8px 16px;
    font-size: 0.95rem;
    border-radius: 6px;
    outline: none;
    cursor: pointer;
    width: auto;
    min-width: 160px;
    transition: all 0.2s ease;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--text-color) 50%),
        linear-gradient(135deg, var(--text-color) 50%, transparent 50%);
    background-position: right 10px top 50%;
    background-size: 8px 8px;
    background-repeat: no-repeat;
    appearance: none;
    -webkit-appearance: none;
}

.example-selector:hover {
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.1);
}

.example-selector:focus {
    border: 1px solid var(--info);
    box-shadow: 0 0 0 2px rgba(23, 162, 184, 0.3);
}

/* 选项样式 */
.example-selector option {
    background: var(--bg-dark);
    color: var(--text-color);
    padding: 6px 12px;
    transition: background 0.2s;
}

.example-selector option:hover,
.example-selector option:focus {
    background: var(--header-bg);
}

/* 响应式布局 - 切换为上下结构 */
@media (max-width: 1200px) {
    main {
        flex-direction: column;
        padding: 1rem;
        gap: 1rem;
    }

    .screen-simulator,
    .code-editor {
        width: 100%;
        max-width: 100%;
        height: auto;
    }

    .screen-simulator {
        height: auto;
        flex: 0 0 auto;
    }

    .brain-container {
        width: 100%;
        height: auto;
        aspect-ratio: 710/510;
        /* 保持原始宽高比 */
    }

    /* 响应式画布位置保持比例 */
    #screenCanvas {
        /* 使用相同的比例变量 */
        top: calc(var(--canvas-top-ratio) * 100%);
        left: calc(var(--canvas-left-ratio) * 100%);
        width: calc(var(--canvas-width-ratio) * 100%);
        height: calc(var(--canvas-height-ratio) * 100%);
    }

    .code-editor {
        min-height: 400px;
        flex: 1;
    }

    .output-console {
        max-width: 100%;
    }
}

/* 小屏幕优化 */
@media (max-width: 768px) {
    header h1 {
        font-size: 1.5rem;
    }

    .editor-header {
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.5rem;
    }

    .example-selector {
        min-width: 140px;
        order: 1;
        flex: 1;
    }

    #status {
        order: 2;
        text-align: right;
        flex: 1;
    }

    .editor-buttons {
        order: 3;
        display: flex;
        width: 100%;
        justify-content: flex-end;
        margin-top: 0.5rem;
    }

    .brain-container {
        aspect-ratio: 16/9;
    }
}