/* ============ 基础 ============ */
* { box-sizing: border-box; }
:root {
  --bg: #0d1117;
  --bg-2: #141b24;
  --bg-3: #1b2531;
  --line: #26303d;
  --fg: #d5dde7;
  --fg-dim: #8494a6;
  --accent: #2f9e6b;
  --accent-2: #3ba9f4;
  --warn: #e0a52e;
  --err: #e05c5c;
  --ok: #41c07a;
  --mono: "Cascadia Mono", "Consolas", "JetBrains Mono", "Sarasa Mono SC", "Microsoft YaHei Mono", monospace;
  --ui: "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--ui);
  font-size: 14px;
  overflow: hidden;
}
button { font-family: var(--ui); cursor: pointer; }
h2 { font-size: 13px; margin: 0; font-weight: 600; letter-spacing: .5px; }

#app { display: flex; flex-direction: column; height: 100vh; }

/* ============ 顶栏 ============ */
.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 8px 14px;
  background: linear-gradient(180deg, #182230, #131a23);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 250px; }
.logo {
  width: 34px; height: 34px; border-radius: 8px;
  background: linear-gradient(135deg, #2f9e6b, #1d6e4a);
  color: #fff; font-weight: 800; font-size: 19px;
  display: grid; place-items: center;
  box-shadow: 0 2px 8px rgba(47,158,107,.35);
}
.brand-text strong { display: block; font-size: 15px; }
.brand-text small { color: var(--fg-dim); font-size: 11.5px; }

.mode-switch { display: flex; background: #0f1620; border: 1px solid var(--line); border-radius: 8px; padding: 3px; }
.mode-btn {
  background: transparent; border: 0; color: var(--fg-dim);
  padding: 6px 14px; border-radius: 6px; font-size: 13px;
}
.mode-btn.is-active { background: var(--accent); color: #fff; font-weight: 600; }

.topbar-actions { margin-left: auto; display: flex; gap: 8px; }
.btn {
  background: #1e2836; color: var(--fg); border: 1px solid var(--line);
  padding: 7px 13px; border-radius: 7px; font-size: 13px;
}
.btn:hover { background: #26323f; border-color: #37475a; }
.btn-primary { background: var(--accent); border-color: #2b8f60; color: #fff; font-weight: 600; }
.btn-primary:hover { background: #37b47c; }
.btn-warn { background: #3a2a20; border-color: #5b3d28; color: #e6b17a; }
.btn-warn:hover { background: #4a3426; }

/* ============ 布局 ============ */
.layout { flex: 1 1 auto; display: flex; min-height: 0; }
.panel { background: var(--bg-2); display: flex; flex-direction: column; min-height: 0; }
.panel-left { width: 310px; flex: 0 0 310px; border-right: 1px solid var(--line); }
.panel-right { width: 320px; flex: 0 0 320px; border-left: 1px solid var(--line); overflow-y: auto; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 12px; border-bottom: 1px solid var(--line);
  background: #101822; flex: 0 0 auto; position: sticky; top: 0; z-index: 2;
}
.progress-wrap { font-size: 12px; color: var(--fg-dim); font-family: var(--mono); }
.progress-bar { height: 4px; background: #0e1520; flex: 0 0 auto; }
.progress-bar > div { height: 100%; width: 0; background: linear-gradient(90deg, #2f9e6b, #3ba9f4); transition: width .35s ease; }

/* 任务清单 */
.task-list { overflow-y: auto; padding: 6px; flex: 1 1 auto; }
.task {
  display: flex; gap: 9px; padding: 8px 9px; border-radius: 8px;
  border: 1px solid transparent; margin-bottom: 3px; cursor: pointer;
}
.task:hover { background: #1a2331; }
.task.is-active { background: #17212e; border-color: #2c3c4e; }
.task.is-done .task-title { color: var(--fg-dim); text-decoration: line-through; }
.task-check {
  width: 17px; height: 17px; border-radius: 5px; flex: 0 0 auto; margin-top: 1px;
  border: 1.5px solid #3a4a5c; display: grid; place-items: center;
  font-size: 11px; color: transparent; background: #131b25;
}
.task.is-done .task-check { background: var(--ok); border-color: var(--ok); color: #06210f; }
.task-step { color: var(--fg-dim); font-size: 11px; font-family: var(--mono); }
.task-title { font-size: 13px; line-height: 1.45; }
/* 任务描述：默认只显示第一句，点开这一项才展开全文 */
.task-desc { font-size: 11.5px; color: #93a6b8; margin-top: 3px; line-height: 1.65; }
.task-desc-rest { display: none; }
.task.is-active .task-desc { color: #b9cbd9; }
.task.is-active .task-desc-rest { display: inline; }
.task.is-done .task-desc { color: #5c6b7c; }
.task-meta { font-size: 11px; color: #6f8092; margin-top: 3px; }
.task-group { padding: 9px 10px 4px; font-size: 11.5px; color: #6f8092; letter-spacing: 1px; }

/* ============ 终端 ============ */
.center { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; background: #0a0e14; }
.host-tabs { display: flex; gap: 4px; padding: 6px 8px 0; background: #101822; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.host-tab {
  background: #16202b; border: 1px solid var(--line); border-bottom: 0;
  color: var(--fg-dim); padding: 7px 13px; border-radius: 8px 8px 0 0;
  font-size: 12.5px; font-family: var(--mono); display: flex; align-items: center; gap: 7px;
}
.host-tab.is-active { background: #0a0e14; color: #e8f0f8; border-color: #2f9e6b; box-shadow: inset 0 2px 0 var(--accent); }
.host-tab .led { width: 7px; height: 7px; border-radius: 50%; background: #3d4a5a; }
.host-tab .led.on { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.host-tab .led.sshed { background: var(--accent-2); box-shadow: 0 0 6px var(--accent-2); }

.terminal-frame { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; padding: 8px 8px 0; }
.terminal-title {
  display: flex; align-items: center; gap: 6px; padding: 5px 10px;
  background: #131b25; border: 1px solid var(--line); border-bottom: 0;
  border-radius: 8px 8px 0 0; font-size: 12px; color: #93a3b5; font-family: var(--mono);
}
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-r { background: #e05c5c; } .dot-y { background: #e0a52e; } .dot-g { background: #41c07a; }
.terminal-title > #terminalTitle { margin-left: 8px; }
.terminal-hint { margin-left: auto; color: #55677c; font-size: 11px; font-family: var(--ui); }

.terminal {
  flex: 1 1 auto; overflow-y: auto; background: #0a0e14;
  border: 1px solid var(--line); border-radius: 0 0 8px 8px;
  padding: 10px 12px 14px; outline: none; min-height: 0;
  position: relative; /* 隐形输入框按它定位 */
}
/* 隐形输入框：看不见，但接收所有键盘输入（保证"点到终端就能打字"） */
#terminalInput {
  position: absolute; left: 0; right: 0; bottom: 0; height: 1.6em;
  opacity: 0.01; border: 0; outline: 0; background: transparent;
  color: transparent; caret-color: transparent; font: inherit;
  padding: 0; margin: 0; z-index: 1; cursor: text;
}
.terminal:focus-within { border-color: #2f9e6b; box-shadow: inset 0 0 0 1px rgba(47,158,107,.25); }
.screen { font-family: var(--mono); font-size: 13.5px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; }
.screen[hidden] { display: none; }
.line { white-space: pre-wrap; }
.c-prompt { color: #41c07a; }
.c-prompt-root { color: #e05c5c; }
.c-path { color: #3ba9f4; }
.c-cmd { color: #e8f0f8; }
.c-dim { color: #6f8092; }
.c-warn { color: #e0a52e; }
.c-err { color: #e05c5c; }
.c-ok { color: #41c07a; }
.c-info { color: #3ba9f4; }
.c-bold { font-weight: 700; }
/* 老师给的诊断提示：和"真实报错原文"分开显示，方便学生先读报错、再看提示 */
.line.c-tip {
  color: #dcc79a; border-left: 3px solid var(--warn); padding-left: 8px;
  margin: 2px 0 4px; background: #1a1710;
}
.cinput { display: flex; align-items: baseline; flex-wrap: wrap; }
.caret { display: inline-block; width: 8px; height: 16px; background: #d5dde7; vertical-align: -3px; animation: blink 1.05s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.vi-status { display: inline-block; padding: 1px 8px; border-radius: 4px; font-weight: 700; }
.vi-insert { background: var(--ok); color: #06210f; }
.vi-command { background: var(--warn); color: #2a1d02; }

.quickbar { display: flex; flex-wrap: wrap; gap: 6px; padding: 7px 8px 9px; background: #101822; }
.chip {
  background: #16202b; border: 1px solid var(--line); color: #a9b8c9;
  border-radius: 14px; padding: 4px 10px; font-size: 11.5px; font-family: var(--mono);
}
.chip:hover { border-color: var(--accent); color: #d9e6f2; }

/* ============ 右侧 ============ */
.topo-wrap { padding: 4px 6px 0; }
#topo { width: 100%; height: auto; display: block; }
.host-cards { padding: 4px 10px 10px; display: flex; flex-direction: column; gap: 6px; }
.hcard { background: #131b25; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; }
.hcard-top { display: flex; align-items: center; justify-content: space-between; font-family: var(--mono); font-size: 12.5px; }
.hcard-ip { color: var(--fg-dim); font-size: 11px; font-family: var(--mono); }
.roles { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.role { font-size: 10.5px; padding: 1px 6px; border-radius: 10px; border: 1px solid #34424f; color: #8fa0b2; background: #101822; font-family: var(--mono); }
.role.on { background: #123726; border-color: #2f9e6b; color: #7fe0ad; }
.role.dead { background: #3a1f1f; border-color: #7c3a3a; color: #e39a9a; }
.detail { padding: 10px 12px 18px; font-size: 12.5px; line-height: 1.7; font-family: var(--mono); color: #9fb0c2; }
.detail b { color: #d5dde7; }
.detail .kv { display: flex; gap: 8px; }
.detail .kv span:first-child { color: #6f8092; min-width: 84px; display: inline-block; }

/* ============ 状态栏 ============ */
.statusbar {
  flex: 0 0 auto; display: flex; align-items: center; gap: 10px;
  padding: 5px 12px; background: #101822; border-top: 1px solid var(--line);
  font-size: 11.5px; color: var(--fg-dim); font-family: var(--mono);
}
.status-sep { color: #2c3a48; }
.status-tip { margin-left: auto; color: #55677c; font-family: var(--ui); }

/* ============ 对话框 ============ */
.modal { position: fixed; inset: 0; background: rgba(4,8,12,.7); display: grid; place-items: center; z-index: 50; }
.modal[hidden] { display: none; }
.modal-box {
  width: min(920px, 94vw); max-height: 88vh; background: var(--bg-2);
  border: 1px solid #33414f; border-radius: 12px; display: flex; flex-direction: column;
  box-shadow: 0 18px 50px rgba(0,0,0,.6);
}
.modal-box.narrow { width: min(680px, 92vw); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 14px; }
.modal-close { background: transparent; border: 0; color: var(--fg-dim); font-size: 22px; line-height: 1; }
.modal-close:hover { color: #fff; }
.modal-body { padding: 13px 15px; overflow-y: auto; flex: 1 1 auto; }
.modal-foot { padding: 10px 14px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

.editor-note { font-size: 12px; color: var(--fg-dim); margin-bottom: 8px; line-height: 1.75; }
.editor-area {
  width: 100%; min-height: 380px; background: #0a0e14; color: #cfe3d8;
  border: 1px solid var(--line); border-left: 4px solid var(--ok); border-radius: 8px; padding: 10px;
  font-family: var(--mono); font-size: 13.5px; line-height: 1.55; resize: vertical; outline: none;
  white-space: pre; overflow: auto; tab-size: 4;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.editor-area:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(47,158,107,.18); }
.editor-area.is-command { border-left-color: var(--warn); background: #140f07; color: #e6d6b0; }
.editor-area.is-command:focus { border-color: var(--warn); box-shadow: 0 0 0 2px rgba(224,165,46,.22); }
.editor-status { margin-top: 7px; font-size: 12px; font-family: var(--mono); min-height: 18px; }
.editor-status.bad { color: var(--err); }
.editor-status.good { color: var(--ok); }
kbd {
  background: #1b2531; border: 1px solid #33414f; border-bottom-width: 2px;
  border-radius: 4px; padding: 0 5px; font-family: var(--mono); font-size: 11.5px; color: #cfe3d8;
}

/* 指导手册 */
.guide h4 { color: #7fd6ab; margin: 16px 0 6px; font-size: 13.5px; }
.guide h4:first-child { margin-top: 0; }
.guide table { width: 100%; border-collapse: collapse; font-size: 12.5px; font-family: var(--mono); }
.guide th, .guide td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; }
.guide th { background: #16202b; color: #a9b8c9; }
.guide code { background: #101822; padding: 1px 5px; border-radius: 4px; color: #8fd6b4; font-family: var(--mono); }
.guide pre { background: #0a0e14; border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow-x: auto; font-size: 12.5px; line-height: 1.5; color: #b9cbd9; }
.guide .tip { border-left: 3px solid var(--warn); background: #1c1a12; padding: 8px 11px; border-radius: 0 6px 6px 0; font-size: 12.5px; color: #dcc79a; margin: 8px 0; }
.guide .tip.ok { border-color: var(--ok); background: #10201a; color: #a7dcc2; }

/* 评分 */
.score-hero { display: flex; align-items: center; gap: 18px; padding: 6px 4px 14px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.score-num { font-size: 46px; font-weight: 800; font-family: var(--mono); line-height: 1; }
.score-num.good { color: var(--ok); } .score-num.mid { color: var(--warn); } .score-num.bad { color: var(--err); }
.score-sub { color: var(--fg-dim); font-size: 12.5px; line-height: 1.7; }
.score-tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.score-tbl th, .score-tbl td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.score-tbl th { color: #93a3b5; background: #16202b; }
.badge { font-family: var(--mono); font-size: 11px; padding: 1px 7px; border-radius: 10px; }
.badge.ok { background: #123726; color: #7fe0ad; border: 1px solid #2f9e6b; }
.badge.no { background: #3a1f1f; color: #e39a9a; border: 1px solid #7c3a3a; }
.fix { color: #dcc79a; }

/* 提示条 */
.toast {
  position: fixed; left: 50%; top: 84px; transform: translateX(-50%);
  background: #1d2733; border: 1px solid #3a4a5c; color: #dbe6f0;
  padding: 10px 18px; border-radius: 9px; font-size: 13px; z-index: 80;
  box-shadow: 0 10px 30px rgba(0,0,0,.5); max-width: 70vw;
  pointer-events: none;
}
.toast[hidden] { display: none; }
.toast.err { border-color: #7c3a3a; background: #2a1a1a; color: #f0c0c0; }
.toast.ok { border-color: #2f9e6b; background: #14261d; color: #b6e8cd; }

/* 滚动条 */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: #0d1117; }
::-webkit-scrollbar-thumb { background: #2b3746; border-radius: 6px; border: 2px solid #0d1117; }
::-webkit-scrollbar-thumb:hover { background: #3a4a5c; }

@media (max-width: 1400px) {
  .panel-left { width: 268px; flex-basis: 268px; }
  .panel-right { width: 286px; flex-basis: 286px; }
}

/* Render task commands one instruction per source line, including teacher text. */
.task > div:last-child{min-width:0}
.task-meta{white-space:pre-wrap;overflow-wrap:anywhere;word-break:normal;line-height:1.65;font-family:var(--ui)}
.task-desc{overflow-wrap:anywhere}

/* 手机竖屏：三栏改成上下堆叠，任务清单、终端、拓扑各自内部滚动。
   原来固定 310 + 320 的左右栏在 390px 宽下会把页面撑到 580px 以上。 */
@media (max-width: 820px) {
  body { overflow: auto; }
  #app { height: auto; min-height: 100vh; }
  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 10px; }
  .brand { min-width: 0; }
  .brand-text small { display: none; }
  .topbar-actions { margin-left: 0; flex-wrap: wrap; }
  .layout { flex-direction: column; min-height: 0; }
  .panel-left, .panel-right { width: auto; flex: 0 0 auto; max-height: 46vh; }
  .panel-left { border-right: 0; border-bottom: 1px solid var(--line); }
  .panel-right { border-left: 0; border-top: 1px solid var(--line); }
  .center { min-height: 58vh; }
  .host-tabs { flex-wrap: wrap; }
  .terminal-frame { min-height: 46vh; }
  .terminal { min-height: 34vh; }
  .statusbar { flex-wrap: wrap; gap: 4px 10px; }
  .status-tip { margin-left: 0; }
  .modal-body { overflow-x: auto; }
  .guide table, .guide pre { max-width: 100%; }
  .guide th, .guide td { padding: 4px 6px; }
}
