:root {
    /* 桌面端（大屏）默认值：左右分栏结构 */
    --shell-padding: 16px 24px;
    --pane-columns: 1fr 1fr;
    --pane-gap: 12px;
    --pane-min-height: 0;

    --border-color: #dee2e6;
    --bg-soft: #f8f9fa;
    --accent: #0d6efd;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: #eef1f5; }

/* 整页左右留白 */
.page-shell {
    /*max-width: 1600px;*/
    margin: 0 auto;
    padding: var(--shell-padding);
    height: 90vh;
    display: flex;
    flex-direction: column;
}

/* 顶栏 */
.topbar {
    flex: 0 0 auto;
    background: #1f2328;
    color: #fff;
    border-radius: 8px;
    padding: 10px 18px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
.topbar .brand { font-size: 1.05rem; font-weight: 600; }
.topbar .brand small { font-weight: 400; opacity: .7; font-size: .78rem; margin-left: 8px; }
.status-badge {
    font-size: .78rem;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255,255,255,.1);
    padding: 4px 12px;
    border-radius: 20px;
    white-space: nowrap;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: #adb5bd; flex: 0 0 auto; }
.dot.loading { background: #ffc107; animation: pulse 1s infinite; }
.dot.ready   { background: #198754; }
.dot.error   { background: #dc3545; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }

/* 主体：桌面端左右分栏 / 移动端上下堆叠 */
.workspace {
    flex: 1 1 auto;
    display: grid;
    grid-template-columns: var(--pane-columns);
    gap: var(--pane-gap);
    min-height: 0;
}
.pane {
    min-width: 0;
    min-height: var(--pane-min-height);
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,.04);
}

/* 左栏：工具栏（顶部） */
.toolbar {
    padding: 8px 10px;
    background: var(--bg-soft);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}
.toolbar .btn { font-size: .78rem; padding: .28rem .62rem; display: inline-flex; align-items: center; gap: 4px; }
.toolbar .group-sep { width: 1px; height: 22px; background: #ced4da; margin: 0 2px; }
.toolbar .vlabel { font-size: .76rem; color: #6c757d; margin-left: 4px; }
.toolbar select { font-size: .78rem; padding: .27rem .5rem; width: auto; }

/* 文件树 */
.file-tree {
    max-height: 132px;
    overflow-y: auto;
    border-bottom: 1px solid var(--border-color);
    background: #fcfcfd;
    font-size: .82rem;
}
.file-tree-head {
    padding: 5px 12px;
    font-size: .74rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: #868e96;
    background: #f1f3f5;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.file-tree-item {
    padding: 5px 12px 5px 26px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    user-select: none;
}
.file-tree-item::before {
    content: '📄';
    position: absolute;
    left: 8px;
    font-size: .8rem;
}
.file-tree-item:hover { background: #eef4ff; }
.file-tree-item.active { background: #d0ebff; color: #0b5ed7; font-weight: 500; }
.file-tree-item .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-tree-item .fops { display: none; gap: 2px; flex: 0 0 auto; }
.file-tree-item:hover .fops, .file-tree-item.active .fops { display: inline-flex; }
.fops .iconbtn {
    border: none; background: transparent; cursor: pointer;
    font-size: .78rem; line-height: 1; padding: 2px 5px; border-radius: 3px;
    color: #495057;
}
.fops .iconbtn:hover { background: rgba(0,0,0,.08); }
.fops .iconbtn.del:hover { background: #dc3545; color: #fff; }

/* 编辑器 */
#editor { flex: 1 1 auto; width: 100%; min-height: 0; }

/* 编辑器底部：文件名 + 行列 */
.editor-statusbar {
    flex: 0 0 auto;
    padding: 4px 14px;
    font-size: .75rem;
    background: var(--bg-soft);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    gap: 8px;
    color: #6c757d;
    overflow: hidden;
}
.editor-statusbar span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-statusbar span b { color: #495057; font-weight: 600; }

/* 右栏：输出区 */
.pane-head {
    padding: 8px 14px;
    font-size: .85rem;
    font-weight: 600;
    background: var(--bg-soft);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.pane-head .hint { font-weight: 400; font-size: .75rem; color: #868e96; }
#output {
    flex: 1 1 auto;
    margin: 0;
    padding: 14px 16px;
    background: #1e1e1e;
    color: #d4d4d4;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 13px;
    line-height: 1.6;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
}
#output .err  { color: #f48771; }
#output .warn { color: #cca700; }
#output .meta { color: #6a9955; }
#output .sys  { color: #4fc1ff; }
#output .divider { color: #404040; }

/* 底部说明 */
.foot-doc {
    flex: 0 0 auto;
    margin-top: 12px;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 18px;
    font-size: .8rem;
    color: #4a5158;
    /*max-height: 132px;*/
    /*overflow-y: auto;*/
    line-height: 1.85;
    margin: var(--shell-padding);
}
.foot-doc code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.foot-doc kbd { background: #eef1f5; border: 1px solid #d0d5dd; border-radius: 3px; padding: 0 4px; font-size: .9em; }
.foot-doc summary { cursor: pointer; font-weight: 600; color: #212529; }
.foot-doc summary::marker { color: var(--accent); }

/* =========================================================
   响应式断点
   - 桌面（>768px）：左右分栏
   - 平板/手机（≤768px）：上下堆叠，输出区默认收起可切换
   ========================================================= */
@media (max-width: 768px) {
    :root {
        --shell-padding: 10px;
        --pane-gap: 10px;
        --pane-columns: 1fr;
        --pane-min-height: 0;
    }
    .page-shell { padding: var(--shell-padding); }

    /* 顶栏纵向排列，避免品牌文字挤压状态灯 */
    .topbar { flex-wrap: wrap; row-gap: 8px; }
    .topbar .brand { font-size: .95rem; }
    .topbar .brand small { display: none; }  /* 小屏隐藏副标题，省空间 */

    /* 工具栏：按钮放大到触控友好尺寸，允许横向滚动 */
    .toolbar { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
    .toolbar .btn { font-size: .8rem; padding: .4rem .7rem; white-space: nowrap; flex: 0 0 auto; }
    .toolbar select { font-size: .8rem; padding: .38rem .5rem; }
    .toolbar .group-sep { height: 26px; }

    /* 编辑器区：移动端高度偏矮，保证键盘弹起后仍可见 */
    #editor { min-height: 180px; }

    /* 输出区默认收起为一行标题，点击展开 */
    #output { display: none; }
    #output.mobile-open { display: block; }
    .pane-head .hint { display: none; }  /* 小屏隐藏 "Ctrl+Enter" 提示 */

    /* 文件树压矮 */
    .file-tree { max-height: 96px; }
}

/* 超窄屏（≤480px）：进一步压缩 */
@media (max-width: 480px) {
    .topbar .brand { font-size: .86rem; }
    .status-badge { font-size: .72rem; padding: 4px 9px; }
    .foot-doc { font-size: .74rem; }
}

/* 横屏手机：给键盘留出足够空间，避免编辑器被挤没 */
@media (max-height: 480px) and (orientation: landscape) {
    #editor { min-height: 120px; }
    .file-tree { max-height: 64px; }
}

/* 移动端专属：折叠标签、输出区高度、键盘避让 */
.mobile-only-label { display: none; }
@media (max-width: 768px) {
    .mobile-only-label { display: inline; }
    /* 输出区展开后占半屏，收起时标题栏仍可见 */
    #output.mobile-open { min-height: 45vh; max-height: 55vh; }
    /* 移动端运行后自动展开输出区 */
    #output.has-output { display: block; }
    #output.has-output.mobile-open { display: block; }
    /* 移动端顶栏状态文字缩短 */
    .status-badge .status-text-long { display: none; }
}
/* 当虚拟键盘弹出时（视口高度骤降），压缩文件树把空间让给编辑器 */
@media (max-width: 768px) and (max-height: 520px) {
    .file-tree { max-height: 56px; }
    #editor { min-height: 120px; }
}
/* 触控设备：文件操作按钮常驻显示，避免 hover 无法触发 */
@media (hover: none) and (pointer: coarse) {
    .file-tree-item .fops { display: inline-flex; }
    .fops .iconbtn { padding: 5px 8px; }  /* 加大触控热区 */
}

.hidden { display: none !important; }
.toast-msg {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    background: #333; color: #fff; padding: 8px 20px; border-radius: 24px;
    font-size: .85rem; opacity: 0; transition: opacity .25s; pointer-events: none;
    z-index: 9999;
    max-width: 90vw;
}
.toast-msg.show { opacity: 1; }
