/* ============================================================
 * style.css — 数字电路实验室
 * ============================================================ */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0f1620;
  --panel: #16202d;
  --panel2: #1c2735;
  --border: #2a3a4d;
  --text: #c8d6e5;
  --text-dim: #6b7f93;
  --accent: #5db0ff;
  --accent2: #ffe066;
  --danger: #ff6b6b;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app {
  display: flex;
  flex-direction: column;   /* 纵向：Tab 栏在上，内容在下 */
  height: 100vh;
}

#app-body {
  flex: 1;
  display: flex;
  min-height: 0;            /* 允许内容区收缩 */
}

/* ---------- 侧栏 ---------- */
#sidebar {
  width: 230px;
  min-width: 230px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.logo {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 14px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, #1a2c42, #16202d);
}
.logo-ic { font-size: 26px; }
.logo-title { font-weight: 700; font-size: 15px; color: #fff; }
.logo-sub { font-size: 11px; color: var(--text-dim); }

.lib { padding: 10px; flex: 1; }
.cat {
  font-size: 12px; color: var(--accent);
  margin: 12px 0 6px;
  font-weight: 600;
  letter-spacing: 0.5px;
}
.lib-item {
  display: flex; flex-direction: column; align-items: flex-start;
  width: 100%; padding: 7px 10px; margin-bottom: 5px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: all .15s;
}
.lib-item:hover { border-color: var(--accent); background: #21324a; transform: translateX(2px); }
.lib-name { font-family: monospace; font-weight: 700; font-size: 13px; }
.lib-desc { font-size: 11px; color: var(--text-dim); }

.hint {
  padding: 10px 14px 16px;
  font-size: 11px; color: var(--text-dim);
  border-top: 1px solid var(--border);
}
.hint p { color: var(--text); font-weight: 600; margin-bottom: 6px; }
.hint ul { padding-left: 16px; }
.hint li { margin: 3px 0; }

/* ---------- 主区 ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#toolbar {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.tb-btn {
  padding: 6px 12px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.tb-btn:hover { border-color: var(--accent); }
.tb-btn.primary { background: #1e5aa8; border-color: #2f7bd6; font-weight: 700; }
.tb-btn.primary.active { background: #b3541e; border-color: #e67e22; }
.tb-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

.sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }

.sel {
  padding: 6px 8px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.speed-label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }
.speed-label input[type=range] { width: 90px; accent-color: var(--accent); }

.sim-time { font-family: monospace; font-size: 12px; color: var(--accent2); }

.status { font-size: 12px; color: var(--text-dim); margin-left: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 380px; }
.status.warn { color: var(--danger); font-weight: 600; }

/* ---------- 画布 ---------- */
#canvasWrap { flex: 1; position: relative; min-height: 0; }
#canvas { width: 100%; height: 100%; display: block; cursor: crosshair; background: #101823; }

/* ---------- 波形面板（可拖拽调高） ---------- */
#wavePanel {
  height: 220px;
  min-height: 100px;
  max-height: 70vh;
  background: var(--panel);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
}
#waveDrag {
  position: absolute;
  top: -5px;
  left: 0;
  right: 0;
  height: 10px;
  cursor: ns-resize;
  z-index: 10;
}
#waveDrag:hover { background: rgba(93, 176, 255, 0.25); }
.wave-head {
  padding: 5px 12px;
  font-size: 12px; font-weight: 700;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.wave-tip { font-weight: 400; font-size: 11px; color: var(--text-dim); }
#wave { flex: 1; width: 100%; display: block; background: #121b28; }

/* ---------- 时钟频率设置弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(8, 12, 18, 0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 999;
}
.modal-box {
  background: #1a2432;
  border: 1px solid #3f5b7a;
  border-radius: 10px;
  padding: 18px 22px;
  width: 320px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}
.modal-title {
  font-size: 14px; font-weight: 700; color: #e8eef5;
  margin-bottom: 14px;
}
.modal-row {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 8px;
}
.modal-row label { color: #9db1c7; font-size: 12px; flex: 1; }
.modal-row input {
  width: 90px;
  background: #0f1824;
  border: 1px solid #3f5b7a;
  border-radius: 6px;
  color: #e8eef5;
  padding: 6px 8px;
  font-size: 13px;
  text-align: center;
}
.modal-row input:focus { outline: none; border-color: #5db0ff; }
.modal-unit { color: #6b7f93; font-size: 12px; }
.modal-hint {
  font-size: 11px; color: #7d93a9;
  background: #101a27;
  border-radius: 6px;
  padding: 8px 10px;
  margin: 8px 0 14px;
  line-height: 1.7;
}
.modal-actions {
  display: flex; justify-content: flex-end; gap: 10px;
}

/* ---------- 示例教学说明条 ---------- */
.explain-bar {
  position: absolute;
  left: 12px; right: 12px; bottom: 12px;
  background: rgba(15, 24, 38, 0.95);
  border: 1px solid #5db0ff;
  border-left: 4px solid #5db0ff;
  border-radius: 8px;
  color: #dbe7f3;
  font-size: 12px;
  line-height: 1.7;
  padding: 10px 38px 10px 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
  white-space: pre-line;
  z-index: 20;
}
.explain-close {
  position: absolute;
  top: 6px; right: 8px;
  background: none;
  border: none;
  color: #8aa0b5;
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
}
.explain-close:hover { color: #fff; }
