:root {
  --primary: #409eff;
  --primary-dark: #2b7cd6;
  --primary-light: #79bbff;
  --primary-lighter: #ecf5ff;
  --navy: #0b2545;
  --navy-2: #123a6b;
  --bg: #eef2f7;
  --card: #ffffff;
  --border: #e4e7ed;
  --text-1: #303133;
  --text-2: #606266;
  --text-3: #909399;
  --high: #ff4d4f;
  --low: #52c41a;
  --off: #c0c4cc;
  --shadow: 0 2px 12px rgba(11, 37, 69, 0.08);
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  color: var(--text-1);
  background: var(--bg);
}

/* ============ 顶部导航 ============ */
.topbar {
  height: 64px;
  background: linear-gradient(90deg, var(--navy) 0%, var(--navy-2) 60%, #1a4d8f 100%);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  position: relative;
  z-index: 10;
}
.topbar-inner {
  height: 100%;
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 32px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon { filter: drop-shadow(0 0 6px rgba(64,158,255,0.5)); }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-title {
  font-size: 20px; font-weight: 700; color: #fff; letter-spacing: 0.5px;
}
.brand-sub { font-size: 11px; color: #8fb8e8; margin-top: 3px; letter-spacing: 1px; }

.tabs { display: flex; gap: 4px; height: 100%; align-items: center; margin-left: 8px; }
.tab-btn {
  position: relative;
  height: 100%;
  padding: 0 22px;
  border: none;
  background: transparent;
  color: #a8c6e8;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  letter-spacing: 1px;
  transition: color 0.2s;
}
.tab-btn:hover { color: #fff; }
.tab-btn.active { color: #fff; }
.tab-btn.active::after {
  content: "";
  position: absolute;
  left: 50%; transform: translateX(-50%);
  bottom: 0;
  width: 60%;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--primary);
  box-shadow: 0 0 10px var(--primary);
}

.topbar-right { margin-left: auto; display: flex; align-items: center; }
.run-state {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 20px;
  color: #d8e7f8;
  font-size: 13px;
}
.state-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #52c41a; box-shadow: 0 0 6px #52c41a;
  transition: background 0.3s, box-shadow 0.3s;
}
.run-state.running .state-dot { background: #409eff; box-shadow: 0 0 8px #409eff; }
.run-state.halted .state-dot { background: #e6a23c; box-shadow: 0 0 6px #e6a23c; }
.run-state.error .state-dot { background: #f56c6c; box-shadow: 0 0 6px #f56c6c; }

/* ============ 主区域 ============ */
.main { height: calc(100vh - 64px); }
.page { display: none; height: 100%; }
.page.active { display: block; }

/* ============ 教程页 ============ */
.tutorial-layout { display: flex; height: 100%; }

.tutorial-side {
  width: 300px;
  min-width: 300px;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.side-search { padding: 14px; border-bottom: 1px solid var(--border); }
.side-search input {
  width: 100%; height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}
.side-search input:focus { border-color: var(--primary); }

.side-cats {
  padding: 10px 12px 6px;
  display: flex; flex-wrap: wrap; gap: 6px;
}
.cat-chip {
  padding: 3px 10px;
  font-size: 12px;
  border-radius: 12px;
  background: var(--primary-lighter);
  color: var(--primary-dark);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
}
.cat-chip:hover { border-color: var(--primary-light); }
.cat-chip.active { background: var(--primary); color: #fff; }

.side-list { flex: 1; overflow-y: auto; padding: 6px 8px 14px; }
.instr-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 2px;
}
.instr-item:hover { background: var(--primary-lighter); }
.instr-item.active { background: var(--primary-lighter); box-shadow: inset 3px 0 0 var(--primary); }
.instr-item .mn {
  font-family: "SF Mono", Consolas, "Courier New", monospace;
  font-weight: 700;
  color: var(--primary-dark);
  font-size: 14px;
  min-width: 56px;
}
.instr-item .cn { font-size: 13px; color: var(--text-2); flex: 1; }
.instr-item .type-badge {
  font-size: 11px; padding: 1px 7px; border-radius: 4px;
  background: #f0f2f5; color: var(--text-3);
  font-family: monospace;
}

.tutorial-content { flex: 1; overflow-y: auto; padding: 28px 36px; }
.instr-detail { max-width: 960px; }
.placeholder-tip { color: var(--text-3); font-size: 15px; margin-top: 80px; text-align: center; }

.detail-header {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin-bottom: 18px;
}
.detail-mn {
  font-family: "SF Mono", Consolas, monospace;
  font-size: 32px; font-weight: 700; color: var(--navy);
}
.detail-badges { display: flex; gap: 8px; }
.badge {
  font-size: 12px; padding: 3px 12px; border-radius: 12px; font-weight: 500;
}
.badge-type { background: var(--primary-lighter); color: var(--primary-dark); }
.badge-cat { background: #f0f9eb; color: #67c23a; }

.detail-desc {
  font-size: 14.5px; color: var(--text-2); line-height: 1.8;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 18px;
}
.detail-syntax {
  font-family: "SF Mono", Consolas, monospace;
  font-size: 15px;
  color: var(--navy);
  background: #f7f9fc;
  border-left: 3px solid var(--primary);
  padding: 12px 16px;
  border-radius: 0 8px 8px 0;
  margin-bottom: 22px;
}

.code-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.code-card { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--card); }
.code-card-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  font-size: 13px; font-weight: 600;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
}
.code-card-head .lang {
  font-size: 11px; padding: 1px 8px; border-radius: 4px;
  color: #fff; font-weight: 500;
}
.code-card-head .lang.c { background: #a0cfff; color: #1d4e89; }
.code-card-head .lang.asm { background: #5c6bc0; color: #fff; }
.code-card pre {
  padding: 14px 16px;
  font-family: "SF Mono", Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.7;
  overflow-x: auto;
  color: #2c3e50;
  background: #fff;
}
.code-card pre .cmt { color: #67a06b; }
.code-card pre .key { color: #c7254e; }
.code-card pre .reg { color: #795da3; }
.code-card pre .num { color: #1f6fb2; }

@media (max-width: 900px) {
  .code-cards { grid-template-columns: 1fr; }
}

/* ============ 通用按钮 / 选择器 ============ */
.el-btn {
  height: 34px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text-1);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.el-btn:hover { border-color: var(--primary-light); color: var(--primary); }
.el-btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.el-btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }
.el-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.el-btn.warn { background: #f56c6c; border-color: #f56c6c; color: #fff; }

.el-select {
  height: 34px;
  padding: 0 28px 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
  color: var(--text-1);
  outline: none;
  cursor: pointer;
}
.el-select:focus { border-color: var(--primary); }
.el-select.small { height: 30px; }

/* ============ 练习页 ============ */
.practice-toolbar {
  height: 52px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.toolbar-left { display: flex; align-items: center; gap: 8px; }
.toolbar-right { display: flex; align-items: center; gap: 8px; }
.toolbar-label { font-size: 13px; color: var(--text-2); }

.practice-layout {
  display: grid;
  grid-template-columns: 1fr 360px 320px;
  gap: 0;
  height: calc(100% - 52px);
}
.panel { display: flex; flex-direction: column; border-right: 1px solid var(--border); background: var(--card); }
.panel:last-child { border-right: none; }

.panel-tabs {
  display: flex; gap: 2px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
}
.panel-tab {
  padding: 5px 14px;
  border: none; border-radius: 6px;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
}
.panel-tab:hover { color: var(--primary); }
.panel-tab.active { background: var(--primary); color: #fff; }

.panel-head {
  padding: 12px 16px;
  font-size: 14px; font-weight: 600;
  color: var(--text-1);
  border-bottom: 1px solid var(--border);
}

.editor-wrap { flex: 1; position: relative; overflow: hidden; }
.editor-wrap .CodeMirror {
  height: 100%;
  font-family: "SF Mono", Consolas, "Courier New", monospace;
  font-size: 13.5px;
  line-height: 1.6;
}
.c-viewer {
  position: absolute; inset: 0;
  padding: 14px 16px;
  margin: 0;
  overflow: auto;
  font-family: "SF Mono", Consolas, monospace;
  font-size: 13px; line-height: 1.7;
  color: #2c3e50; background: #fbfcfe;
  white-space: pre;
}

/* 调试面板 */
.debug-body { flex: 1; overflow: hidden; position: relative; }
.debug-view { height: 100%; overflow-y: auto; padding: 8px; }

.reg-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; }
.reg-cell {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  font-family: "SF Mono", Consolas, monospace;
  font-size: 12px;
  cursor: default;
  border: 1px solid transparent;
}
.reg-cell:hover { background: var(--primary-lighter); }
.reg-cell.changed { background: #fff7e6; border-color: #ffd591; }
.reg-cell .rn { color: var(--primary-dark); font-weight: 600; min-width: 30px; }
.reg-cell .rv { color: var(--text-1); flex: 1; text-align: right; }
.reg-cell.pc { grid-column: 1 / -1; background: var(--primary-lighter); }

.mem-info { font-size: 12px; color: var(--text-3); padding: 4px 8px 8px; font-family: monospace; }
.mem-grid { font-family: "SF Mono", Consolas, monospace; font-size: 12px; }
.mem-row { display: flex; gap: 10px; padding: 2px 8px; }
.mem-row:hover { background: var(--primary-lighter); }
.mem-addr { color: var(--text-3); min-width: 72px; }
.mem-bytes { color: var(--text-1); letter-spacing: 1px; }

.io-box { padding: 6px 10px; font-family: monospace; font-size: 13px; line-height: 1.7; color: #d8e7f8; }
.io-line { white-space: pre-wrap; word-break: break-all; }
.io-line.error { color: #ff8585; }
.io-line.info { color: #7fb8ff; }

/* 芯片缩略 */
.chip-mini { padding: 14px; display: flex; justify-content: center; }
.gpio-regs { padding: 0 14px 14px; font-family: monospace; font-size: 12px; color: var(--text-2); }
.gpio-regs .gr { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dashed var(--border); }
.gpio-regs .gr span:first-child { color: var(--text-3); }

/* ============ 模拟器页 ============ */
.sim-layout {
  display: grid;
  grid-template-columns: 1fr 420px;
  height: 100%;
  gap: 0;
}
.sim-left {
  display: flex; flex-direction: column;
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 16px;
  overflow: auto;
}
.sim-left .panel-head { padding: 0 0 14px; border: none; }
.chip-big { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; }
.chip-legend {
  display: flex; gap: 22px; justify-content: center;
  padding: 12px; font-size: 13px; color: var(--text-2);
}
.chip-legend span { display: flex; align-items: center; gap: 7px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.dot.high { background: var(--high); box-shadow: 0 0 8px var(--high); }
.dot.low { background: var(--low); box-shadow: 0 0 8px var(--low); }
.dot.off { background: var(--off); }

.sim-right { display: flex; flex-direction: column; overflow: hidden; }
.sim-right .panel { border-right: none; border-bottom: 1px solid var(--border); }
.sim-right .panel:last-child { border-bottom: none; flex: 1; min-height: 0; }

.reg-table { padding: 8px 16px 14px; font-family: monospace; font-size: 12.5px; }
.reg-table .rt-row {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 6px 0; border-bottom: 1px dashed var(--border);
}
.reg-table .rt-row .k { color: var(--text-3); }
.reg-table .rt-row .v { color: var(--text-1); font-weight: 600; }
.reg-table .rt-row .v.hi { color: var(--high); }
.reg-table .rt-row .v.lo { color: var(--low); }

.log-box {
  flex: 1; overflow-y: auto;
  padding: 12px 16px;
  background: #0b2545;
  font-family: monospace; font-size: 12.5px; line-height: 1.7;
  color: #b8d4f0;
}

/* ============ 芯片 SVG ============ */
.chip-svg { max-width: 100%; max-height: 100%; }
.pin-rect { transition: fill 0.15s, opacity 0.15s; }
.pin-rect.high { fill: var(--high); filter: drop-shadow(0 0 5px var(--high)); }
.pin-rect.low { fill: var(--low); filter: drop-shadow(0 0 5px var(--low)); }
.pin-rect.off { fill: var(--off); }
.pin-rect.selected { stroke: #fff; stroke-width: 2; }

/* 滚动条 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #c8d0dc; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #a8b2c0; }
::-webkit-scrollbar-track { background: transparent; }

/* ============ CodeMirror 语法高亮 ============ */
.cm-s-default .cm-keyword { color: #c7254e; font-weight: 600; }
.cm-s-default .cm-comment { color: #67a06b; font-style: italic; }
.cm-s-default .cm-variable-2 { color: #795da3; font-weight: 500; }
.cm-s-default .cm-number { color: #1f6fb2; }
.cm-s-default .cm-string { color: #c7254e; }
.cm-s-default .cm-label { color: #d97706; font-weight: 600; }
.cm-s-default .cm-builtin { color: #00838f; }
.cm-s-default.CodeMirror { background: #fbfcfe; }

/* 断点 gutter */
.CodeMirror-breakpoints { width: 14px; }
.breakpoint-marker {
  width: 9px; height: 9px;
  background: #f56c6c;
  border-radius: 50%;
  margin: 4px auto;
  box-shadow: 0 0 4px rgba(245, 108, 108, 0.8);
  cursor: pointer;
}

/* 响应式 */
@media (max-width: 1100px) {
  .practice-layout { grid-template-columns: 1fr 300px; }
  .chip-panel { display: none; }
}
