/*
 * 学生端在线编程环境独立样式文件。
 * 仅包含语言选择、代码编辑器与运行结果控制台样式。
 */

/* ---- 编辑器工作区 ---- */
.prog-root { min-width: 0; }

.prog-main { min-width: 0; display: flex; flex-direction: column; gap: 16px; }

/* ---- 顶部工具栏 ---- */
.prog-toolbar {
    padding: 14px 16px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px 16px;
    border: 1px solid rgba(226, 227, 238, .9);
    border-radius: var(--radius);
    background: linear-gradient(180deg, #ffffff 0%, #fafaff 100%);
    box-shadow: var(--shadow);
}
.prog-toolbar-left,
.prog-toolbar-right { display: flex; align-items: center; gap: 12px; min-width: 0; }
.prog-toolbar-right { margin-left: auto; gap: 10px; }

.prog-toolbar-icon {
    width: 38px;
    height: 38px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 11px;
    color: #fff;
    font-size: 17px;
    background: linear-gradient(140deg, #7a6cf3 0%, #5a49d8 100%);
    box-shadow: 0 8px 18px rgba(90, 73, 216, .26);
}

.prog-field { display: flex; flex-direction: row; align-items: center; gap: 10px; min-width: 0; }
.prog-field-label { color: #5a6280; font-size: 13px; font-weight: 700; white-space: nowrap; }
.prog-select-wrap { position: relative; display: inline-flex; align-items: center; }
.prog-field select {
    appearance: none;
    -webkit-appearance: none;
    height: 42px;
    min-width: 152px;
    padding: 0 38px 0 14px;
    border: 1px solid #dfe0ea;
    border-radius: 11px;
    color: var(--ink);
    background: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    outline: none;
    transition: border-color .18s ease, box-shadow .18s ease;
}
.prog-field select:hover { border-color: #c8c2f1; }
.prog-field select:focus { border-color: #a99ef2; box-shadow: 0 0 0 4px rgba(102, 86, 232, .12); }
.prog-select-arrow {
    position: absolute;
    right: 14px;
    color: #8b93ad;
    font-size: 11px;
    pointer-events: none;
}

/* ---- 运行按钮 ---- */
.prog-btn {
    height: 42px;
    padding: 0 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 0;
    border-radius: 11px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
    transition: transform .16s ease, box-shadow .16s ease, background .16s ease, opacity .16s ease;
}
.prog-btn:disabled { opacity: .6; cursor: not-allowed; }
.prog-btn-run {
    color: #fff;
    background: linear-gradient(135deg, #7a6cf3 0%, #5a49d8 100%);
    box-shadow: 0 10px 22px rgba(83, 68, 201, .28);
}
.prog-btn-run:hover:not(:disabled) {
    background: linear-gradient(135deg, #6d5ef0 0%, #4b3bc9 100%);
    box-shadow: 0 12px 26px rgba(83, 68, 201, .34);
    transform: translateY(-1px);
}
.prog-btn-run:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 6px 14px rgba(83, 68, 201, .3);
}
.prog-btn-run:focus-visible { outline: 3px solid rgba(102, 86, 232, .35); outline-offset: 2px; }
.prog-run-icon { font-size: 11px; line-height: 1; }

/* ---- 代码编辑器（透明 textarea + 语法高亮层） ---- */
.prog-editor-panel {
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .07);
    border-radius: var(--radius);
    background: linear-gradient(180deg, #171d34 0%, #111729 100%);
    box-shadow: 0 18px 40px rgba(16, 21, 39, .22);
    transition: border-color .2s ease, box-shadow .2s ease;
}
.prog-editor-panel:focus-within {
    border-color: rgba(122, 108, 243, .5);
    box-shadow: 0 0 0 3px rgba(102, 86, 232, .18), 0 18px 40px rgba(16, 21, 39, .24);
}
.prog-editor-head {
    height: 42px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    gap: 7px;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
    background: rgba(255, 255, 255, .025);
}
.prog-dot { width: 10px; height: 10px; flex: none; border-radius: 50%; opacity: .92; }
.prog-dot-red { background: #ff5f57; }
.prog-dot-yellow { background: #febc2e; }
.prog-dot-green { background: #28c840; }
.prog-file-badge {
    margin-left: auto;
    padding: 4px 11px;
    border: 1px solid rgba(122, 108, 243, .35);
    border-radius: 999px;
    background: rgba(122, 108, 243, .16);
    color: #bdb4ff;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .02em;
}
.prog-editor-wrap {
    position: relative;
    height: 330px;
    overflow: hidden;
}
.prog-code,
.prog-highlight {
    margin: 0;
    padding: 16px 18px 26px;
    font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Consolas, "Cascadia Mono", monospace;
    font-size: 13.5px;
    line-height: 1.7;
    tab-size: 4;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: break-word;
}
.prog-highlight {
    position: absolute;
    inset: 0;
    overflow: hidden;
    color: #cdd6f4;
    pointer-events: none;
}
.prog-code {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    resize: none;
    border: 0;
    outline: 0;
    background: transparent;
    color: transparent;
    caret-color: #9db8ff;
    -webkit-text-fill-color: transparent;
}
.prog-code::selection,
.prog-code::-moz-selection { background: rgba(122, 108, 243, .42); }
.prog-code::placeholder { color: #4d5878; -webkit-text-fill-color: #4d5878; }
.prog-code:focus-visible { outline: 0; }

/* 深色滚动条 */
.prog-code::-webkit-scrollbar,
.prog-highlight::-webkit-scrollbar,
.prog-output::-webkit-scrollbar { width: 10px; height: 10px; }
.prog-code::-webkit-scrollbar-thumb,
.prog-highlight::-webkit-scrollbar-thumb,
.prog-output::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, .16);
    border: 3px solid transparent;
    border-radius: 999px;
    background-clip: content-box;
}
.prog-code::-webkit-scrollbar-thumb:hover,
.prog-output::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, .28); background-clip: content-box; }
.prog-code::-webkit-scrollbar-corner,
.prog-output::-webkit-scrollbar-corner { background: transparent; }

/* 语法高亮 token 颜色 */
.tok-kw { color: #c4a7ff; font-weight: 600; }
.tok-str { color: #a5e075; }
.tok-num { color: #ffab70; }
.tok-comment { color: #5f6a8f; font-style: italic; }
.tok-pre { color: #7fd9f0; }
.tok-fn { color: #8ab4ff; }
.tok-builtin { color: #ffc777; }

/* ---- 运行结果控制台 ---- */
.prog-console {
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .07);
    border-radius: var(--radius);
    background: #0e1322;
    box-shadow: 0 18px 40px rgba(16, 21, 39, .18);
}
.prog-console-head {
    min-height: 46px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
}
.prog-console-title {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    color: #cfd6ee;
    font-size: 12.5px;
    font-weight: 700;
    letter-spacing: .02em;
}
.prog-console-title::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #5cdbca;
    box-shadow: 0 0 0 4px rgba(92, 219, 202, .14);
}
.prog-console-status {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 5px 12px;
    border: 1px solid rgba(255, 255, 255, .09);
    border-radius: 999px;
    background: rgba(255, 255, 255, .05);
    color: #97a0bf;
    font-size: 12px;
    font-weight: 600;
    transition: color .18s ease, background .18s ease, border-color .18s ease;
}
.prog-console-status::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, .06);
}
.prog-console-status.running { color: #5cdbca; border-color: rgba(92, 219, 202, .32); background: rgba(92, 219, 202, .1); }
.prog-console-status.running::before { animation: progPulse 1.1s ease-in-out infinite; }
.prog-console-status.ok { color: #63e0c4; border-color: rgba(99, 224, 196, .32); background: rgba(99, 224, 196, .1); }
.prog-console-status.error { color: #ff8a97; border-color: rgba(255, 138, 151, .32); background: rgba(255, 138, 151, .1); }

@keyframes progPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: .4; transform: scale(.75); }
}

.prog-output {
    min-height: 160px;
    max-height: 320px;
    margin: 0;
    padding: 15px 18px 18px;
    overflow: auto;
    color: #cdd6f4;
    font: 13px/1.75 ui-monospace, "JetBrains Mono", Consolas, "Cascadia Mono", monospace;
    white-space: pre-wrap;
    word-break: break-word;
}
.prog-output > div + div { margin-top: 4px; }
.prog-output:empty::before { content: '点击「运行」查看程序输出'; color: #7b86a8; }
.prog-output.is-running:empty::before { content: '程序正在运行…'; color: #5cdbca; }
.prog-output .prog-out-stdout { color: #cdd6f4; }
.prog-output .prog-out-stderr { color: #ff8a97; }
.prog-output .prog-out-meta { color: #6b7494; font-size: 11.5px; }
.prog-output .prog-out-tip { color: #f7d98b; font-size: 11.5px; }
.prog-output .prog-out-error { color: #ff8a97; }

/* ---- 课程模块内的在线编程布局 ---- */
.student-course-module[data-course-module-panel="programming"] .prog-editor-wrap { height: 360px; }

/* ---- 窄屏适配 ---- */
@media (max-width: 720px) {
    .prog-toolbar { padding: 12px; }
    .prog-btn { padding: 0 18px; }
    .prog-field select { min-width: 128px; }
    .prog-editor-wrap { height: 280px; }
    .student-course-module[data-course-module-panel="programming"] .prog-editor-wrap { height: 300px; }
}

@media (prefers-reduced-motion: reduce) {
    .prog-btn,
    .prog-editor-panel,
    .prog-console-status,
    .prog-field select { transition: none; }
    .prog-console-status.running::before { animation: none; }
}
