/* xv6 实验练习室 全局样式 */
:root {
  --bg: #0f1419;
  --bg-soft: #161d24;
  --bg-panel: #1a232c;
  --bg-hover: #22303b;
  --border: #2a3a47;
  --text: #d8e1e8;
  --text-dim: #8a9aa8;
  --accent: #4da3ff;
  --accent-soft: #4da3ff22;
  --green: #3fd08f;
  --red: #ff6b6b;
  --yellow: #ffc857;
  --radius: 10px;
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.65;
}
#app { display: flex; flex-direction: column; min-height: 100vh; }
main#main { flex: 1; padding: 0 clamp(12px, 4vw, 48px); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 clamp(12px, 4vw, 48px); height: 54px;
  background: var(--bg-soft); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.brand { font-weight: 700; font-size: 1.05rem; color: var(--text); }
.brand:hover { text-decoration: none; color: var(--accent); }
.topnav a { margin-left: 22px; color: var(--text-dim); font-size: .95rem; }
.topnav a:hover, .topnav a.active { color: var(--accent); text-decoration: none; }

.footer {
  text-align: center; color: var(--text-dim); font-size: .82rem;
  padding: 18px; border-top: 1px solid var(--border); margin-top: 40px;
}

/* ---------- 首页 ---------- */
.hero { padding: 44px 0 10px; }
.hero h1 { font-size: 1.7rem; margin: 0 0 8px; }
.hero p { color: var(--text-dim); max-width: 760px; margin: 4px 0; }
.section-title {
  display: flex; align-items: baseline; gap: 12px;
  margin: 34px 0 14px; font-size: 1.15rem; font-weight: 700;
}
.section-title small { color: var(--text-dim); font-weight: 400; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.card {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 6px;
  transition: border-color .15s, transform .15s; cursor: pointer; position: relative;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); text-decoration: none; }
.card .lab-no { font-size: .78rem; color: var(--text-dim); letter-spacing: .5px; }
.card h3 { margin: 0; font-size: 1.02rem; color: var(--text); }
.card .topic { color: var(--text-dim); font-size: .87rem; }
.card .meta { display: flex; gap: 10px; align-items: center; font-size: .8rem; color: var(--text-dim); margin-top: 4px; flex-wrap: wrap; }
.badge { padding: 2px 9px; border-radius: 20px; font-size: .75rem; border: 1px solid var(--border); }
.badge.pass { color: var(--green); border-color: var(--green); }
.badge.score { color: var(--yellow); border-color: var(--yellow); }
.badge.running { color: var(--accent); border-color: var(--accent); animation: pulse 1.2s infinite; }
.badge.done-soon { color: var(--text-dim); }
@keyframes pulse { 50% { opacity: .45; } }
.diff-dots { color: var(--yellow); letter-spacing: 2px; font-size: .7rem; }

.kcard {
  background: linear-gradient(135deg, var(--bg-panel), #1c2733);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 18px;
  cursor: pointer; transition: border-color .15s, transform .15s;
}
.kcard:hover { border-color: var(--accent); transform: translateY(-2px); text-decoration: none; }
.kcard h3 { margin: 0 0 6px; font-size: 1rem; color: var(--text); }
.kcard p { margin: 0; color: var(--text-dim); font-size: .86rem; }

/* ---------- 实验页 ---------- */
.labhead {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 18px 0 14px; border-bottom: 1px solid var(--border); margin-bottom: 0;
}
.labhead .back { color: var(--text-dim); font-size: .9rem; }
.labhead h1 { font-size: 1.25rem; margin: 0; flex: 1; }
.labhead h1 .branch { color: var(--text-dim); font-weight: 400; font-size: .85rem; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  background: var(--bg-panel); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 14px; font-size: .88rem; cursor: pointer;
  transition: background .12s, border-color .12s; font-family: inherit;
}
.btn:hover { background: var(--bg-hover); border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06121f; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--red); }
.btn.danger:hover { border-color: var(--red); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.running { border-color: var(--yellow); color: var(--yellow); }

/* 标签页 */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 14px 0 0; }
.tab {
  padding: 10px 18px; cursor: pointer; color: var(--text-dim); font-size: .95rem;
  border-bottom: 2px solid transparent; user-select: none; position: relative;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab .dot { position: absolute; top: 8px; right: 6px; width: 7px; height: 7px; border-radius: 50%; background: var(--yellow); }
.tabpane { display: none; }
.tabpane.active { display: block; }

/* ---------- 讲解（markdown） ---------- */
.md-body { max-width: 880px; padding: 24px 4px 60px; }
.md-body h1 { font-size: 1.45rem; border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.md-body h2 { font-size: 1.2rem; margin-top: 2.2em; border-left: 3px solid var(--accent); padding-left: 10px; }
.md-body h3 { font-size: 1.05rem; margin-top: 1.8em; color: #bcd0e0; }
.md-body code {
  background: #0c1116; border: 1px solid var(--border); border-radius: 4px;
  padding: 1px 6px; font-size: .86em;
  font-family: "JetBrains Mono", "Fira Code", Consolas, monospace;
}
.md-body pre {
  background: #0c1116; border: 1px solid var(--border); border-radius: 8px;
  padding: 14px 16px; overflow-x: auto; line-height: 1.5;
}
.md-body pre code { background: none; border: none; padding: 0; font-size: .84rem; }
.md-body blockquote {
  margin: 1em 0; padding: 8px 16px; border-left: 3px solid var(--accent);
  background: var(--accent-soft); border-radius: 0 8px 8px 0; color: #c6d8e8;
}
.md-body table { border-collapse: collapse; width: 100%; margin: 1em 0; font-size: .9rem; }
.md-body th, .md-body td { border: 1px solid var(--border); padding: 7px 12px; text-align: left; }
.md-body th { background: var(--bg-soft); }
.md-body li { margin: .3em 0; }
.md-body img { max-width: 100%; }

/* ---------- 代码编辑区 ---------- */
.code-wrap { display: flex; gap: 0; height: calc(100vh - 230px); min-height: 420px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-top: 16px; }
.filetree {
  width: 260px; min-width: 200px; background: var(--bg-soft); border-right: 1px solid var(--border);
  overflow-y: auto; padding: 8px 0; font-size: .84rem; flex-shrink: 0;
}
.filetree .search { width: calc(100% - 16px); margin: 0 8px 8px; padding: 6px 10px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: .84rem; outline: none; }
.filetree .search:focus { border-color: var(--accent); }
.tree-item { padding: 3px 12px; cursor: pointer; white-space: nowrap; color: var(--text-dim); display: flex; align-items: center; gap: 6px; }
.tree-item:hover { background: var(--bg-hover); color: var(--text); }
.tree-item.active { background: var(--accent-soft); color: var(--accent); }
.tree-item.dir { color: #7fa3c0; }
.tree-item .mod { width: 6px; height: 6px; border-radius: 50%; background: var(--yellow); display: inline-block; }
.editor-side { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.filetabs { display: flex; background: var(--bg-soft); border-bottom: 1px solid var(--border); overflow-x: auto; }
.filetab {
  padding: 8px 14px; font-size: .82rem; color: var(--text-dim); cursor: pointer;
  border-right: 1px solid var(--border); white-space: nowrap; display: flex; gap: 6px; align-items: center;
}
.filetab.active { color: var(--text); background: var(--bg-panel); box-shadow: inset 0 2px 0 var(--accent); }
.filetab .dirty { color: var(--yellow); }
.filetab .close { opacity: .5; }
.filetab .close:hover { opacity: 1; color: var(--red); }
#monaco-host { flex: 1; min-height: 0; }
.edit-hint { padding: 10px 16px; background: var(--bg-soft); border-top: 1px solid var(--border); color: var(--text-dim); font-size: .8rem; display: flex; justify-content: space-between; }

/* ---------- 运行/判分 ---------- */
.run-wrap { margin-top: 16px; }
.result-panel { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 14px; overflow: hidden; }
.result-head {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px;
  padding: 12px 18px; background: var(--bg-soft); border-bottom: 1px solid var(--border);
}
.result-head .score { font-size: 1.3rem; font-weight: 700; }
.score.ok { color: var(--green); }
.score.partial { color: var(--yellow); }
.score.zero { color: var(--red); }
.tests-table { width: 100%; border-collapse: collapse; font-size: .87rem; }
.tests-table td { padding: 7px 18px; border-top: 1px solid var(--border); }
.tests-table .st { width: 90px; font-weight: 600; }
.st.ok { color: var(--green); } .st.fail { color: var(--red); } .st.na { color: var(--text-dim); }
.tests-table .detail { color: var(--text-dim); font-size: .8rem; font-family: monospace; white-space: pre-wrap; }

.console {
  background: #0a0f14; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 18px; font-family: "JetBrains Mono", Consolas, monospace;
  font-size: .8rem; line-height: 1.55; white-space: pre-wrap; word-break: break-all;
  max-height: 480px; overflow-y: auto; min-height: 120px;
}
.console .line-ok { color: var(--green); }
.console .line-err { color: var(--red); }
.console .line-dim { color: var(--text-dim); }
.console-banner {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px;
  padding: 10px 18px; background: var(--bg-soft); border: 1px solid var(--border); border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0; color: var(--text-dim); font-size: .85rem;
}
.console-banner + .console { border-radius: 0 0 var(--radius) var(--radius); }

/* ---------- xterm ---------- */
.xterm-wrap { margin-top: 16px; }
.xterm-box { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; background: #000; min-height: 380px; }
.xterm .xterm-viewport { background-color: #000 !important; }

/* 弹窗（diff） */
.modal-mask { position: fixed; inset: 0; background: #000a; z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius);
  width: min(860px, 92vw); max-height: 84vh; display: flex; flex-direction: column;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 1.02rem; }
.modal-body { overflow: auto; padding: 4px 0; }
.modal-body pre { margin: 0; padding: 14px 20px; font-size: .8rem; font-family: monospace; white-space: pre-wrap; }

/* toast */
.toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--bg-panel); border: 1px solid var(--accent); color: var(--text);
  padding: 10px 22px; border-radius: 8px; font-size: .9rem; opacity: 0;
  transition: opacity .25s, transform .25s; pointer-events: none; z-index: 300;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: var(--red); }

.spin {
  display: inline-block; width: 12px; height: 12px; border: 2px solid var(--text-dim);
  border-top-color: var(--accent); border-radius: 50%; animation: rot .8s linear infinite; vertical-align: -2px;
}
@keyframes rot { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
  .code-wrap { flex-direction: column; height: auto; }
  .filetree { width: 100%; max-height: 200px; }
  #monaco-host { height: 60vh; }
}
