:root {
    --orange: #f59e0b;
    --orange2: #f4a422;
    --orange-deep: #e58e00;
    --panel: #1f2937;
    --panel-deep: #111827;
    --border: #e5e7eb;
}

html, body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    font-family: "Microsoft YaHei", "Segoe UI", sans-serif;
    background: #f7f7fb;
}

/* 顶栏 */
#topbar {
    height: 64px;
    background: linear-gradient(90deg, var(--orange), var(--orange2));
    color: #fff;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 18px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .12);
}

#brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

#brand img {
    height: 38px;
    object-fit: contain;
    display: block
}

#brand .title {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: .3px
}

#filenameWrap {
    flex: 1;
    display: flex;
    justify-content: center
}

#filename {
    min-width: 220px;
    max-width: 420px;
    background: #fff;
    color: #333;
    border-radius: 999px;
    padding: 8px 16px;
    outline: none;
    border: 1px solid #ffd79a;
    text-align: center;
    box-shadow: inset 0 1px 0 rgba(0, 0, 0, .04);
}

#filename:focus {
    border-color: #ffc76a;
    box-shadow: 0 0 0 3px rgba(255, 193, 7, .25);
}

#topActions {
    display: flex;
    gap: 10px;
}

.tbtn {
    background: #fff;
    color: #a75300;
    border: none;
    border-radius: 10px;
    width: 100px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    cursor: pointer;
    transition: .18s;
    box-shadow: 0 2px 0 rgba(0, 0, 0, .06);
}

.tbtn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, .12);
}

/* 主体：左侧图标栏 + 中间 blockly + 右侧 python */
#main {
    height: calc(100vh - 64px);
    display: flex;
    overflow: hidden;
}

/* 顶部按钮图标样式 */
.btn-icon {
    width: 24px;
    height: 24px;
    object-fit: contain;
    margin-right: 6px;
    vertical-align: middle;
    filter: brightness(1);
}

.tbtn:hover .btn-icon {
    filter: brightness(1);
}

/* 左侧导航图标 + 文字 */
#nav {
    width: 84px;
    box-sizing: border-box;
    background: #fff;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 6px;
    gap: 12px;
    /* 新增滚动样式 */
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
}

/* 导航滚动条样式 */
#nav::-webkit-scrollbar {
    width: 2px;
}

#nav::-webkit-scrollbar-track {
    background: transparent;
}

#nav::-webkit-scrollbar-thumb {
    background: #e5e7eb;
    border-radius: 4px;
}

#nav::-webkit-scrollbar-thumb:hover {
    background: #d1d5db;
}

.nav-item {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    user-select: none;
    transition: 0.18s;
    transform-origin: center;
    /* 确保每个项目不被压缩 */
    flex-shrink: 0;
    width: 60px;
    height: 60px;
    border-radius: 8px;
}

.nav-btn{
    padding: 4px;
    border-radius: 5px;
    font-size: 12px;
}

.nav-btn img {
    width: 18px;
    height: 18px;
}

.nav-item:hover .nav-btn {
    /*transform: scale(1.08);*/
    /*box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);*/
}

.nav-item.active .nav-btn {
    border-width: 0px;
}

.nav-item.active {
    border-width: 0px;
    /*border-color: #ffcf8a;*/
    /*box-shadow: 0 0 0 2px #ffe7bf inset;*/
    /*transform: scale(1.1);*/
    background: #ebebeb;
}

.nav-item .nav-btn {
    /*border: 1px solid #f1f1f1;*/
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    transition: 0.18s;
}

.nav-item .nav-label {
    font-size: 12px;
    color: #555;
    margin-top: 4px;
    font-weight: 500;
    text-align: center;
    line-height: 1.2;
}

.nav-item.active .nav-label {
    /*color: var(--orange-deep);*/
    font-weight: 600;
}

.nav-spacer {
    flex: 1;
}

/* ========== 新增：导航图标样式 ========== */
.nav-icon {
    width: 24px;
    height: 24px;
    object-fit: contain;
    /*filter: brightness(0.7);*/
    transition: all 0.18s ease;
}

.nav-item:hover .nav-btn {
    /*filter: brightness(0.9);*/
    transform: scale(1.1);
}

.nav-item.active .nav-icon {
    /*filter: brightness(1) sepia(1) hue-rotate(15deg) saturate(3);*/
    transform: scale(1.15);
}

/* 隐藏原来的emoji图标 */
.nav-btn {
    font-size: 0 !important;
}

/* 中部：Blockly + 动画 */
#codePanel {
    width: 520px;
    display: flex;
    flex-direction: column;
    /*background: var(--panel);*/
    color: #fff;
    max-width: 1200px;
    height: 100%;
    box-shadow: -4px 0 14px rgba(0, 0, 0, .18);
    transition: width .25s ease;
    position: relative;
}

#center {
    flex: 1;
    display: flex;
    overflow: hidden;
    background: #fff;
    position: relative;
}

#blocklyDiv {
    flex: 1;
    height: 100%;
    background: #fdfdfd;
    border-right: 1px solid var(--border);
    opacity: 1;
    transition: opacity .2s ease;
}

/* 右侧 Python 面板 - 修改为始终显示 */

/* 折叠态：将右侧面板宽度收为 0，隐藏其内容，但保留位置以便 resizer 可见 */
#codePanel.collapsed {
    width: 0 !important;
    transition: width .25s ease;
}

#codePanel.collapsed ~ .resizer {
    /*right: 0 !important;*/
}

#codePanel.collapsed #codeHeader,
#codePanel.collapsed #pythonContainer {
    display: none; /* 隐藏内容但保留元素，便于视觉过渡 */
}

#codePanelResizer {
    position: absolute;
    top: 0;
    left: 0;
    width: 40px;
    transform: translateX(-50%);
}

#codePanelResizer:hover, #codePanelResizer.dragging {
    background: transparent;
}

#toggleCodePanelBtn {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%) translateX(-100%);
    width: 34px;
    height: 60px;
    border-radius: 8px 0px 0px 8px;
    background: var(--orange);
    border: none;
    color: #fff;
    font-size: 14px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.12);
    transition: transform .12s ease, background .12s ease;
    z-index: 14; /* 确保按钮在顶部，便于点击 */
}


#codePanel.fullscreen {
    flex: 1;
    width: 100%;
    max-width: none;
    min-width: 0;
}

#codeHeader {
    background: #eceaea;
    padding: 10px 14px;
    font-size: 15px;
    font-weight: 700;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 0px solid #303646;
}

#codeHeader .actions {
    display: flex;
    gap: 8px;
}

#codeHeader .actions .cbtn {
    background: #3b82f6;
    border: none;
    color: #fff;
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    transition: .18s;
}

#codeHeader .actions .cbtn:hover {
    background: #5aa0ff;
}

#pythonContainer {
    flex: 1;
    display: flex;
    overflow: hidden;
}

#lineNumbers {
    width: 52px;
    background: #2b2b2b;
    color: #9a9a9a;
    text-align: right;
    padding: 10px 6px 0 0;
    font: 14px/1.6 Consolas, monospace;
    user-select: none;
    overflow: hidden;
}

#pythonCode {
    flex: 1;
    background: #1e1e1e;
    color: #ddd;
    border: none;
    outline: none;
    padding: 12px 14px;
    font: 15px/1.6 Consolas, monospace;
    overflow: auto;
    resize: none;
    white-space: pre;
}

#pythonCode::-webkit-scrollbar {
    width: 8px
}

#pythonCode::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 8px
}

#pythonContainer {
    display: flex;
    height: 100%;
    font-family: Consolas, monospace;
    font-size: 14px;
    line-height: 1.4; /* ✅ 改为统一的行高 */
}

#lineNumbers {
    width: 48px;
    background: #eceaea;
    color: #000000;
    text-align: right;
    padding: 8px 6px 0 0; /* ✅ 行距更贴近代码 */
    font-family: Consolas, monospace;
    font-size: 14px;
    line-height: 1.4;
    user-select: none;
    overflow: hidden;
    white-space: pre;
}

#pythonCode {
    flex: 1;
    background: #ffffff;
    color: #ddd;
    border: none;
    outline: none;
    padding: 8px 14px 0 10px;
    font-family: Consolas, monospace;
    font-size: 14px;
    line-height: 1.4;
    overflow: auto;
    resize: none;
    white-space: pre;
}

/* 工具箱美化 */
.blocklyToolboxDiv {
    width: 0px !important;
    background: #fffaf1 !important;
    border-right: 1px solid #ffe2b5 !important;
    transition: all 0.3s ease !important;
    display: none !important;
}

.blocklyToolboxDiv.hidden {
    width: 0 !important;
    overflow: hidden !important;
    border-right: none !important;
}

.blocklyMainBackground {
    stroke: transparent;
}

.blocklyHtmlInput {
    border-radius: 999px !important;
}

.blocklyEditableText {
    border-radius: 999px !important;
}

.blocklyDropdownRect {
    stroke-width: 0.5 !important;
}

.blocklyDropDownDiv {
    border-radius: 20px;
    padding-left: 8px;
    padding-right: 8px;
}

.blocklyMenuItem {
    border-radius: 20px;
}

.blocklyTreeLabel {
    font-size: 15px !important;
    font-weight: 600 !important;
}

.blocklyTreeRow {
    height: 34px !important;
    border-radius: 6px !important;
}

.blocklyTreeRow:hover {
    background: rgba(245, 158, 11, .12) !important;
}

/* ===== 文件下拉菜单样式 ===== */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropbtn {
    background: #fff;
    color: #a75300;
    border: none;
    border-radius: 10px;
    padding: 8px 14px;
    font-weight: 700;
    cursor: pointer;
    transition: .18s;
    box-shadow: 0 2px 0 rgba(0, 0, 0, .06);
}

.dropbtn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, .12);
}

/* 下拉框内容 */
.dropdown-content {
    display: none;
    position: absolute;
    top: 110%;
    left: 0;
    background: linear-gradient(180deg, #ffffff, #ffffff);
    border-radius: 8px;
    min-width: 160px;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    overflow: hidden;
}

.dropdown-content a {
    color: rgb(0, 0, 0);
    padding: 10px 14px;
    text-decoration: none;
    display: block;
    font-size: 14px;
}

.dropdown-content a:hover {
    background-color: rgba(255, 255, 255, 0.15);
}

.dropdown-content.show {
    display: block;
}

/* 工具箱切换按钮样式 */
.toolbox-toggle {
    position: absolute;
    left: 84px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 60px;
    background: var(--orange);
    border: none;
    border-radius: 0 8px 8px 0;
    color: white;
    font-size: 14px;
    cursor: pointer;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.2);
}

.toolbox-toggle:hover {
    background: var(--orange-deep);
    width: 24px;
}

.toolbox-toggle.collapsed {
    left: 84px;
}

.toolbox-toggle:not(.collapsed) {
    left: 344px; /* 84px (nav) + 260px (toolbox) */
}

/* ===== 新增：分隔条样式 ===== */
.resizer {
    position: absolute;
    /* 默认放置在 center 区域与 codePanel 之间，右侧偏移等于 codePanel 默认宽度（与 CSS 中的 520px 保持一致） */
    right: 520px;
    top: 0;
    width: 40px;
    height: 100%;
    cursor: col-resize;
    z-index: 12;
    display: block;
    /* 保持为容器（不居中），按钮将绝对定位在右侧 */
    background: transparent;
}

.resizer:hover, .resizer.dragging {
    background: rgba(245, 158, 11, 0.06);
}

.resizer.dragging {
    cursor: col-resize;
}

/* 中间按钮样式 */
.resizer .toggle-btn {
    position: absolute;
    right: -18px; /* 把按钮放到分隔条的右侧 */
    top: 50%;
    transform: translateY(-50%);
    width: 34px;
    height: 60px;
    border-radius: 8px;
    background: var(--orange);
    border: none;
    color: #fff;
    font-size: 14px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.12);
    transition: transform .12s ease, background .12s ease;
    z-index: 14; /* 确保按钮在顶部，便于点击 */
}

.resizer .toggle-btn:hover {
    transform: translateY(-50%) translateY(-2px) scale(1.02);
}

/* 全局顶端按钮样式 */
.toggle-btn-top {
    display: none;
}

/* ===== Blockly 选中积木高亮样式 ===== */
.blocklyBlockBackground.custom-highlight {
    stroke: #ffd54f !important;
    stroke-width: 4px !important;
    stroke-linejoin: round !important;
    filter: drop-shadow(0 0 8px rgba(255, 213, 79, 0.9));
}

/* 当块整体需要更强的高亮（备用） */
.blocklySelectedHighlight > .blocklyBlockBackground {
    stroke: #ffd54f !important;
    stroke-width: 4px !important;
}

/* 整个堆栈光环覆盖层 */
.stack-halo-overlay {
    position: absolute;
    pointer-events: none;
    background: transparent;
    border-radius: 12px;
    box-shadow: 0 0 22px 8px rgba(255, 213, 79, 0.85); /* 光环效果 */
    transition: all 120ms ease-out;
    will-change: left, top, width, height, box-shadow;
}
